diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index d32a8596d317b0e55185d4c43c6153ef2d841849..43e819962d8958bcb2599a04f75096d2cead0c71 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -357,6 +357,18 @@ function _M:magicMap(radius, x, y) end end +function _M:incMoney(v) + self.money = self.money + v + if self.money < 0 then self.money = 0 end + self.changed = true + + if self.player then + world:gainAchievement("TREASURE_HUNTER", self) + world:gainAchievement("TREASURE_HOARDER", self) + world:gainAchievement("DRAGON_GREED", self) + end +end + function _M:getRankStatAdjust() if self.rank == 1 then return -1 elseif self.rank == 2 then return -0.5 diff --git a/game/modules/tome/class/Store.lua b/game/modules/tome/class/Store.lua index 02aab50dcd4bfe371b2fb1fa5555868d272e4a8a..09daded689066bdc165f961686d58fb1a208b203 100644 --- a/game/modules/tome/class/Store.lua +++ b/game/modules/tome/class/Store.lua @@ -73,7 +73,7 @@ end function _M:onBuy(who, o, item, nb) local price = o:getPrice() * self.sell_percent / 100 if who.money >= price * nb then - who.money = who.money - price * nb + who:incMoney(- price * nb) end end @@ -86,7 +86,7 @@ end function _M:onSell(who, o, item, nb) local price = o:getPrice() * self.buy_percent / 100 if price <= 0 or nb <= 0 then return end - who.money = who.money + price * nb + who:incMoney(price * nb) o:identify(true) end diff --git a/game/modules/tome/data/chats/jewelry-store.lua b/game/modules/tome/data/chats/jewelry-store.lua index 4308163e1a7a364acaf51ccc892af040d52f62ad..6d6316b2c585fa5f40888c9ecf5d9171d9bd85aa 100644 --- a/game/modules/tome/data/chats/jewelry-store.lua +++ b/game/modules/tome/data/chats/jewelry-store.lua @@ -24,7 +24,7 @@ local imbue_ring = function(npc, player) if price > player.money then require("engine.Dialog"):simplePopup("Not enough money", "This costs "..price.." gold, you need more gold.") return end require("engine.Dialog"):yesnoPopup("Imbue cost", "This will cost you "..price.." gold, do you accept?", function(ret) if ret then - player.money = player.money - price + player:incMoney(-price) player:removeObject(player:getInven("INVEN"), gem_item) ring.wielder = ring.wielder or {} table.mergeAdd(ring.wielder, gem.imbue_powers, true) @@ -45,7 +45,7 @@ local artifact_imbue_ring = function(npc, player) if price > player.money then require("engine.Dialog"):simplePopup("Not enough money", "Limmir needs more gold for the magical plating.") return end require("engine.Dialog"):yesnoPopup("Imbue cost", "You need to use "..price.." gold for the plating, do you accept?", function(ret) if ret then - player.money = player.money - price + player:incMoney(-price) local gem3 = game.zone:makeEntity(game.level, "object", {type="gem"}, nil, true) print("Imbue third gem", gem3.name) diff --git a/game/modules/tome/data/chats/magic-store.lua b/game/modules/tome/data/chats/magic-store.lua index 992e61a4495aa67526d8060d0921b1956c8f1517..1119ebd37b4fb46506f71886b98acb8ea490b861 100644 --- a/game/modules/tome/data/chats/magic-store.lua +++ b/game/modules/tome/data/chats/magic-store.lua @@ -23,7 +23,7 @@ local function recharge(npc, player) if cost > player.money then require("engine.Dialog"):simplePopup("Not enough money", "This costs "..cost.." gold.") return true end require("engine.Dialog"):yesnoPopup("Recharge?", "This will cost you "..cost.." gold.", function(ok) if ok then o.power = o.max_power - player.money = player.money - cost + player:incMoney(-cost) player.changed = true end end) return true diff --git a/game/modules/tome/data/chats/minas-tirith-weapon-store.lua b/game/modules/tome/data/chats/minas-tirith-weapon-store.lua index 98222e38a49048d84030271ba7b1ae0f9409961d..db5834e822f522d22242a6fef8adb01d8f843682 100644 --- a/game/modules/tome/data/chats/minas-tirith-weapon-store.lua +++ b/game/modules/tome/data/chats/minas-tirith-weapon-store.lua @@ -34,7 +34,7 @@ newChat{ id="training", answers = { {"Please train me in generic weapons and armour usage.", action=function(npc, player) game.logPlayer(player, "The smith spends some time with you, teaching you the basics of armour and weapon usage.") - player.money = player.money - 50 + player:incMoney(-50) player:learnTalentType("technique/combat-training", true) player.changed = true end, cond=function(npc, player) @@ -44,7 +44,7 @@ newChat{ id="training", end}, {"Please train me in the basic usage of bows and slings.", action=function(npc, player) game.logPlayer(player, "The smith spends some time with you, teaching you the basics of bows and slings.") - player.money = player.money - 8 + player:incMoney(-8) player:learnTalent(player.T_SHOOT, true) player.changed = true end, cond=function(npc, player) diff --git a/game/modules/tome/data/general/objects/money.lua b/game/modules/tome/data/general/objects/money.lua index c742152a381c2ccb314c9983233d43bac8397d34..ed48c2be6615cae946dd102a4264b9b15e3a5bff 100644 --- a/game/modules/tome/data/general/objects/money.lua +++ b/game/modules/tome/data/general/objects/money.lua @@ -26,15 +26,10 @@ newEntity{ identified = true, desc = [[All that glitters is not gold, all that is gold does not glitter.]], on_prepickup = function(self, who, id) - who.money = who.money + self.money_value / 10 + who:incMoney(self.money_value / 10) game.logPlayer(who, "You pickup %0.2f gold pieces.", self.money_value / 10) -- Remove from the map game.level.map:removeObject(who.x, who.y, id) - if who.player then - world:gainAchievement("TREASURE_HUNTER", who) - world:gainAchievement("TREASURE_HOARDER", who) - world:gainAchievement("DRAGON_GREED", who) - end return true end, auto_pickup = true, diff --git a/game/modules/tome/data/quests/lost-merchant.lua b/game/modules/tome/data/quests/lost-merchant.lua index 727485ffbe4b2db36ec7c30b59847d334f38a1c2..c914c87b342f522a8a6b35b0ea5f1d9360294164 100644 --- a/game/modules/tome/data/quests/lost-merchant.lua +++ b/game/modules/tome/data/quests/lost-merchant.lua @@ -47,7 +47,7 @@ leave_zone = function(self, who) end if merchant_alive then game.logPlayer(who, "#LIGHT_BLUE#The merchant thanks you for saving his life. He gives you 8 gold and asks you to meet him again in Minas Tirith.") - who.money = who.money + 8 + player:incMoney(8) who.changed = true who:setQuestStatus(self.id, engine.Quest.COMPLETED, "saved") world:gainAchievement("LOST_MERCHANT_RESCUE", game.player)