-
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add upgrade soul prism mechanic
- Loading branch information
1 parent
89efd86
commit dd2f967
Showing
6 changed files
with
184 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
local soulPrism = Action() | ||
|
||
local function getNextDifficultyLevel(currentLevel) | ||
for level, value in pairs(SoulPit.SoulCoresConfiguration.monstersDifficulties) do | ||
if value == currentLevel + 1 then | ||
return level | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
local function getPreviousDifficultyLevel(currentLevel) | ||
for level, value in pairs(SoulPit.SoulCoresConfiguration.monstersDifficulties) do | ||
if value == currentLevel - 1 then | ||
return level | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
local function getSoulCoreItemForMonster(monsterName) | ||
local lowerMonsterName = monsterName:lower() | ||
local soulCoreName = SoulPit.SoulCoresConfiguration.monsterVariationsSoulCore[monsterName] | ||
|
||
if soulCoreName then | ||
local newSoulCoreId = getItemIdByName(soulCoreName) | ||
if newSoulCoreId then | ||
return newSoulCoreId | ||
end | ||
else | ||
local newMonsterSoulCore = monsterName .. " soul core" | ||
local newSoulCoreId = getItemIdByName(newMonsterSoulCore) | ||
if newSoulCoreId then | ||
return newSoulCoreId | ||
end | ||
end | ||
|
||
return false | ||
end | ||
|
||
function soulPrism.onUse(player, item, fromPosition, target, toPosition, isHotkey) | ||
local itemName = target:getName() | ||
local monsterName = itemName:match("^(.-) soul core") | ||
|
||
if not monsterName then | ||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only use Soul Prism with a Soul Core.") | ||
player:getPosition():sendMagicEffect(CONST_ME_POFF) | ||
return false | ||
end | ||
|
||
local monsterType = MonsterType(monsterName) | ||
if not monsterType then | ||
player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "Invalid monster type. Please contact an administrator.") | ||
player:getPosition():sendMagicEffect(CONST_ME_POFF) | ||
return false | ||
end | ||
|
||
local currentDifficulty = monsterType:getBestiaryStars() | ||
local nextDifficultyLevel = getNextDifficultyLevel(currentDifficulty) | ||
local nextDifficultyMonsters = nil | ||
|
||
if nextDifficultyLevel then | ||
nextDifficultyMonsters = monsterType:getMonstersByBestiaryStars(SoulPit.SoulCoresConfiguration.monstersDifficulties[nextDifficultyLevel]) | ||
else | ||
nextDifficultyLevel = currentDifficulty | ||
nextDifficultyMonsters = monsterType:getMonstersByBestiaryStars(SoulPit.SoulCoresConfiguration.monstersDifficulties[currentDifficulty]) | ||
end | ||
|
||
if #nextDifficultyMonsters == 0 then | ||
player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "No monsters available for the next difficulty level. Please contact an administrator.") | ||
player:getPosition():sendMagicEffect(CONST_ME_POFF) | ||
return false | ||
end | ||
|
||
local newMonsterType = nextDifficultyMonsters[math.random(#nextDifficultyMonsters)] | ||
local newSoulCoreItem = getSoulCoreItemForMonster(newMonsterType:getName()) | ||
if not newSoulCoreItem then -- Retry a second time. | ||
newSoulCoreItem = getSoulCoreItemForMonster(newMonsterType:getName()) | ||
if not newSoulCoreItem then | ||
player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "Failed to generate a Soul Core. Please contact an administrator.") | ||
player:getPosition():sendMagicEffect(CONST_ME_POFF) | ||
return false | ||
end | ||
end | ||
|
||
if player:getFreeCapacity() < ItemType(newSoulCoreItem):getWeight() then | ||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have enough capacity.") | ||
player:getPosition():sendMagicEffect(CONST_ME_POFF) | ||
return false | ||
end | ||
|
||
if math.random(100) <= SoulPit.SoulCoresConfiguration.chanceToGetOminousSoulCore then | ||
player:addItem(49163, 1) | ||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have received an Ominous Soul Core.") | ||
else | ||
player:addItem(newSoulCoreItem, 1) | ||
player:removeItem(target:getId(), 1) | ||
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have received a " .. newMonsterType:getName() .. " soul core.") | ||
end | ||
player:removeItem(item:getId(), 1) | ||
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE) | ||
return true | ||
end | ||
|
||
soulPrism:id(49164) | ||
soulPrism:register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters