Skip to content

Commit

Permalink
fix: bag you desire drop
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Sep 10, 2024
1 parent 2df6ace commit b5a9e79
Show file tree
Hide file tree
Showing 37 changed files with 51 additions and 43 deletions.
26 changes: 10 additions & 16 deletions data-otservbr-global/lib/quests/soul_war.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ SoulWarQuest = {

timeToReturnImmuneMegalomania = 70, -- In seconds

baseBagYouDesireChance = 500, -- 1000 = 1% chance, 500 = 0.5% chance
bagYouDesireChancePerTaint = 1, -- Increases 1% per taint
bagYouDesireChancePerTaint = 10, -- Increases % per taint
bagYouDesireMonsters = {
"Bony Sea Devil",
"Brachiodemon",
Expand Down Expand Up @@ -1089,7 +1088,7 @@ function Monster:createSoulWarWhiteTiles(centerRoomPosition, zonePositions, exec
addEvent(revertTilesAndApplyDamage, executeInterval or 3000, zonePositions)
end

function Monster:generateBagYouDesireLoot(player)
function MonsterType:calculateBagYouDesireChance(player, itemChance)
local playerTaintLevel = player:getTaintLevel()
if not playerTaintLevel or playerTaintLevel == 0 then
return {}
Expand All @@ -1102,29 +1101,24 @@ function Monster:generateBagYouDesireLoot(player)
end

local loot = {}
local totalChance = SoulWarQuest.baseBagYouDesireChance
local soulWarQuest = player:soulWarQuestKV()
local megalomaniaKills = soulWarQuest:scoped("megalomania-kills"):get("count") or 0

if monsterName == "Goshnar's Megalomania" then
-- Special handling for Goshnar's Megalomania
totalChance = totalChance + megalomaniaKills * SoulWarQuest.bagYouDesireChancePerTaint
itemChance = itemChance + megalomaniaKills * SoulWarQuest.bagYouDesireChancePerTaint
else
-- General handling for other monsters (bosses and non-bosses)
totalChance = totalChance + (playerTaintLevel * SoulWarQuest.bagYouDesireChancePerTaint)
itemChance = itemChance + (playerTaintLevel * SoulWarQuest.bagYouDesireChancePerTaint)
end

logger.trace("Player {} killed {} with {} taints, loot chance {}", player:getName(), monsterName, playerTaintLevel, totalChance)
logger.info("Player {} killed {} with {} taints, loot chance {}", player:getName(), monsterName, playerTaintLevel, itemChance)

if math.random(1, 100000) <= totalChance then
local itemType = ItemType(SoulWarQuest.bagYouDesireItemId)
if itemType then
loot[itemType:getId()] = { count = 1 }
logger.debug("Player {} killed {} and got a bag you desire with drop chance {}", player:getName(), monsterName, totalChance)
if monsterName == "Goshnar's Megalomania" then
-- Reset kill count on successful drop
soulWarQuest:scoped("megalomania-kills"):set("count", 0)
end
logger.debug("Player {} killed {} and got a bag you desire with drop chance {}", player:getName(), monsterName, itemChance)
if monsterName == "Goshnar's Megalomania" then
-- Reset kill count on successful drop
soulWarQuest:scoped("megalomania-kills"):set("count", 0)
end
else
if monsterName == "Goshnar's Megalomania" then
Expand All @@ -1133,7 +1127,7 @@ function Monster:generateBagYouDesireLoot(player)
end
end

return loot
return itemChance
end

local intervalBetweenExecutions = 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ monster.loot = {
{ name = "figurine of megalomania", chance = 400 },
{ name = "megalomania's skull", chance = 400 },
{ name = "megalomania's essence", chance = 400 },
{ name = "bag you desire", chance = 100 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ monster.loot = {
{ name = "figurine of megalomania", chance = 400 },
{ name = "megalomania's skull", chance = 400 },
{ name = "megalomania's essence", chance = 400 },
{ name = "bag you desire", chance = 100 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ monster.loot = {
{ name = "figurine of cruelty", chance = 400 },
{ name = "spectral saddle", chance = 400 },
{ name = "spectral horse tack", chance = 400 },
{ name = "bag you desire", chance = 100 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ monster.loot = {
{ name = "greed's arm", chance = 25000, maxCount = 1 },
{ name = "figurine of greed", chance = 400 },
{ name = "the skull of a beast", chance = 400 },
{ name = "bag you desire", chance = 100 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ monster.loot = {
{ name = "spectral horseshoe", chance = 400 },
{ name = "spectral horse tack", chance = 400 },
{ name = "bracelet of strengthening", chance = 400 },
{ name = "bag you desire", chance = 100 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ monster.loot = {
{ name = "spectral horseshoe", chance = 400 },
{ name = "the skull of a beast", chance = 400 },
{ name = "figurine of malice", chance = 400 },
{ name = "bag you desire", chance = 100 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ monster.loot = {
{ name = "the skull of a beast", chance = 400 },
{ name = "figurine of spite", chance = 400 },
{ name = "spite's spirit", chance = 400 },
{ name = "bag you desire", chance = 100 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ monster.loot = {
{ name = "goblet of gloom", chance = 880 },
{ name = "glacier kilt", chance = 880 },
{ name = "glacial rod", chance = 1210 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ monster.loot = {
{ name = "mastermind shield", chance = 420 },
{ name = "assassin dagger", chance = 340 },
{ name = "alloy legs", chance = 170 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ monster.loot = {
{ name = "twiceslicer", chance = 420 },
{ name = "crystalline sword", chance = 390 },
{ name = "ruthless axe", chance = 330 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ monster.loot = {
{ id = 23542, chance = 1180 }, -- collar of blue plasma
{ name = "glacial rod", chance = 940 },
{ name = "ornate crossbow", chance = 940 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ monster.loot = {
{ name = "spellbook of warding", chance = 2890 },
{ id = 23531, chance = 1930 }, -- ring of green plasma
{ name = "glacial rod", chance = 1290 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ monster.loot = {
{ name = "platinum amulet", chance = 1750 },
{ name = "glacier robe", chance = 880 },
{ id = 23544, chance = 440 }, -- collar of red plasma
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ monster.loot = {
{ name = "blue gem", chance = 1490 },
{ name = "brooch of embracement", chance = 1490 },
{ name = "wand of defiance", chance = 990 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ monster.loot = {
{ name = "stone skin amulet", chance = 910 },
{ name = "nightmare blade", chance = 1190 },
{ name = "demonrage sword", chance = 600 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ monster.loot = {
{ id = 33932, chance = 3520 }, -- head
{ name = "glacial rod", chance = 620 },
{ id = 34024, chance = 650 }, -- gruesome fan
{ id = 34109, chance = 1 }, -- bag you desire
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ monster.loot = {
{ name = "violet crystal shard", chance = 1080 },
{ id = 23529, chance = 1080 }, -- ring of blue plasma
{ name = "green gem", chance = 1080 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ monster.loot = {
{ name = "giant sword", chance = 2860 },
{ name = "magma boots", chance = 2290 },
{ name = "stone skin amulet", chance = 570 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ monster.loot = {
{ name = "crystal mace", chance = 1610 },
{ name = "war axe", chance = 1410 },
{ name = "warrior's axe", chance = 1410 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ monster.loot = {
{ name = "giant sword", chance = 1720 },
{ name = "stone skin amulet", chance = 1500 },
{ name = "crown shield", chance = 640 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ monster.loot = {
{ name = "glacier robe", chance = 2130 },
{ name = "gruesome fan", chance = 610 },
{ name = "glacial rod", chance = 610 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ monster.loot = {
{ id = 23529, chance = 1040 }, -- ring of blue plasma
{ name = "ornate crossbow", chance = 840 },
{ name = "crystal crossbow", chance = 620 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ monster.loot = {
{ name = "stone skin amulet", chance = 1560 },
{ id = 23542, chance = 1250 }, -- collar of blue plasma
{ id = 23529, chance = 1250 }, -- ring of blue plasma
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ monster.loot = {
{ name = "stone skin amulet", chance = 740 },
{ name = "terra mantle", chance = 510 },
{ name = "rubber cap", chance = 430 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ monster.loot = {
{ name = "wand of starstorm", chance = 1310 },
{ name = "stone skin amulet", chance = 1310 },
{ name = "alloy legs", chance = 440 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ monster.loot = {
{ name = "crystalline armor", chance = 710 },
{ name = "rubber cap", chance = 710 },
{ name = "stone skin amulet", chance = 470 },
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down
1 change: 1 addition & 0 deletions data-otservbr-global/monster/undeads/hazardous_phantom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ monster.loot = {
{ id = 282, chance = 1570 }, -- giant shimmering pearl
{ name = "wand of everblazing", chance = 790 },
{ id = 23542, chance = 790 }, -- collar of blue plasma
{ name = "bag you desire", chance = 15 },
}

monster.attacks = {
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions data/libs/functions/monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ do
return table.contains(equipmentTypes, t)
end

function MonsterType.getBossReward(self, lootFactor, topScore, equipmentOnly, lootTable)
function MonsterType.getBossReward(self, lootFactor, topScore, equipmentOnly, lootTable, player)
if configManager.getNumber(configKeys.RATE_LOOT) <= 0 then
return lootTable or {}
end
Expand All @@ -221,6 +221,6 @@ do
end
return true
end,
}, lootTable)
}, lootTable, player)
end
end
7 changes: 6 additions & 1 deletion data/libs/functions/monstertype.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- return a dictionary of itemId => { count, gut }
---@param config { factor: number, gut: boolean, filter?: fun(itemType: ItemType, unique: boolean): boolean }
---@return LootItems
function MonsterType:generateLootRoll(config, resultTable)
function MonsterType:generateLootRoll(config, resultTable, player)
if configManager.getNumber(configKeys.RATE_LOOT) <= 0 then
return resultTable or {}
end
Expand All @@ -28,6 +28,11 @@ function MonsterType:generateLootRoll(config, resultTable)
end

local chance = item.chance
if iType:getId() == SoulWarQuest.bagYouDesireItemId then
result[item.itemId].chance = self:calculateBagYouDesireChance(player, chance)
logger.debug("Final chance for bag you desire: {}, original chance: {}", result[item.itemId].chance, chance)
end

if config.gut and iType:getType() == ITEM_TYPE_CREATUREPRODUCT then
chance = math.ceil((chance * GLOBAL_CHARM_GUT) / 100)
end
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/eventcallbacks/monster/ondroploot__base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function callback.monsterOnDropLoot(monster, corpse)
local charm = player and player:getCharmMonsterType(CHARM_GUT)
local gut = charm and charm:raceId() == mType:raceId()

local lootTable = mType:generateLootRoll({ factor = factor, gut = gut }, {})
local lootTable = mType:generateLootRoll({ factor = factor, gut = gut }, {}, player)
corpse:addLoot(lootTable)
for _, item in ipairs(lootTable) do
if item.gut then
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/eventcallbacks/monster/ondroploot_boosted.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function callback.monsterOnDropLoot(monster, corpse)

local factor = 1.0
local msgSuffix = " (boosted loot)"
corpse:addLoot(mType:generateLootRoll({ factor = factor, gut = false }, {}))
corpse:addLoot(mType:generateLootRoll({ factor = factor, gut = false }, {}, player))

local existingSuffix = corpse:getAttribute(ITEM_ATTRIBUTE_LOOTMESSAGE_SUFFIX) or ""
corpse:setAttribute(ITEM_ATTRIBUTE_LOOTMESSAGE_SUFFIX, existingSuffix .. msgSuffix)
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/eventcallbacks/monster/ondroploot_hazard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function callback.monsterOnDropLoot(monster, corpse)

local lootTable = {}
for _ = 1, rolls do
lootTable = mType:generateLootRoll({ factor = factor, gut = false }, lootTable)
lootTable = mType:generateLootRoll({ factor = factor, gut = false }, lootTable, player)
end
corpse:addLoot(lootTable)

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/eventcallbacks/monster/ondroploot_prey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function callback.monsterOnDropLoot(monster, corpse)
msgSuffix = msgSuffix .. " (active prey bonus)"
end

corpse:addLoot(mType:generateLootRoll({ factor = factor, gut = false }, {}))
corpse:addLoot(mType:generateLootRoll({ factor = factor, gut = false }, {}, player))
local existingSuffix = corpse:getAttribute(ITEM_ATTRIBUTE_LOOTMESSAGE_SUFFIX) or ""
corpse:setAttribute(ITEM_ATTRIBUTE_LOOTMESSAGE_SUFFIX, existingSuffix .. msgSuffix)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function callback.monsterOnDropLoot(monster, corpse)

local lootTable = {}
for _ = 1, rolls do
lootTable = mType:generateLootRoll({ factor = factor, gut = false }, lootTable)
lootTable = mType:generateLootRoll({ factor = factor, gut = false }, lootTable, player)
end
corpse:addLoot(lootTable)

Expand Down
4 changes: 2 additions & 2 deletions data/scripts/systems/reward_chest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ function bossDeath.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUn
end

local playerLoot = creature:generateGemAtelierLoot()
playerLoot = monsterType:getBossReward(lootFactor, _ == 1, false, playerLoot)
playerLoot = monsterType:getBossReward(lootFactor, _ == 1, false, playerLoot, player)
for _ = 2, rolls do
playerLoot = monsterType:getBossReward(lootFactor, false, true, playerLoot)
playerLoot = monsterType:getBossReward(lootFactor, false, true, playerLoot, player)
end

-- Add droped items to reward container
Expand Down

0 comments on commit b5a9e79

Please sign in to comment.