From 80ad6379e87a4c288d98f4b4d7f33473d2af9ef7 Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Sun, 28 Feb 2010 22:45:36 +0000 Subject: [PATCH] add money git-svn-id: http://svn.net-core.org/repos/t-engine4@371 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engine/interface/ActorInventory.lua | 2 +- game/modules/tome/class/Actor.lua | 2 ++ game/modules/tome/class/Object.lua | 2 ++ game/modules/tome/class/PlayerDisplay.lua | 1 + game/modules/tome/data/birth/archer.lua | 8 +++---- game/modules/tome/data/birth/descriptors.lua | 1 + game/modules/tome/data/birth/mage.lua | 14 ++++++------ game/modules/tome/data/birth/rogue.lua | 6 ++--- game/modules/tome/data/birth/warrior.lua | 4 ++-- .../tome/data/general/objects/money.lua | 22 +++++++++++++++++++ .../tome/data/general/objects/objects.lua | 1 + 11 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 game/modules/tome/data/general/objects/money.lua diff --git a/game/engine/interface/ActorInventory.lua b/game/engine/interface/ActorInventory.lua index 9884d67efa..47f83ac4bb 100644 --- a/game/engine/interface/ActorInventory.lua +++ b/game/engine/interface/ActorInventory.lua @@ -90,7 +90,7 @@ end function _M:pickupFloor(i, vocal) local o = game.level.map:getObject(self.x, self.y, i) if o then - if self:addObject(self.INVEN_INVEN, o) then + if not o:check("on_prepickup", self, i) and self:addObject(self.INVEN_INVEN, o) then game.level.map:removeObject(self.x, self.y, i) o:check("on_pickup", self) diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index 7932ae2716..1bb70afa66 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -73,6 +73,8 @@ function _M:init(t, no_default) t.max_equilibrium = t.max_equilibrium or 100000 t.equilibrium = t.equilibrium or 0 + t.money = t.money or 0 + -- Default melee barehanded damage self.combat = { dam=1, atk=1, apr=0, dammod={str=1} } diff --git a/game/modules/tome/class/Object.lua b/game/modules/tome/class/Object.lua index 1064159cab..d6a5bc06e6 100644 --- a/game/modules/tome/class/Object.lua +++ b/game/modules/tome/class/Object.lua @@ -69,6 +69,8 @@ function _M:descAttribute(attr) elseif attr == "COMBAT" then local c = self.combat return c.dam.."-"..(c.dam*(c.damrange or 1.1)).." dam, "..(c.apr or 0).." apr" + elseif attr == "MONEY" then + return ("worth %0.2f"):format(self.money_value / 10) end end diff --git a/game/modules/tome/class/PlayerDisplay.lua b/game/modules/tome/class/PlayerDisplay.lua index c465cd154e..e056b03150 100644 --- a/game/modules/tome/class/PlayerDisplay.lua +++ b/game/modules/tome/class/PlayerDisplay.lua @@ -32,6 +32,7 @@ function _M:display() h = h + self.font_h self.surface:drawColorString(self.font, "Level: #00ff00#"..game.player.level, 0, h, 255, 255, 255) h = h + self.font_h self.surface:drawColorString(self.font, ("Exp: #00ff00#%2d%%"):format(100 * cur_exp / max_exp), 0, h, 255, 255, 255) h = h + self.font_h + self.surface:drawColorString(self.font, ("Gold: #00ff00#%0.2f"):format(game.player.money), 0, h, 255, 255, 255) h = h + self.font_h h = h + self.font_h diff --git a/game/modules/tome/data/birth/archer.lua b/game/modules/tome/data/birth/archer.lua index 0162945c19..d6fb48b869 100644 --- a/game/modules/tome/data/birth/archer.lua +++ b/game/modules/tome/data/birth/archer.lua @@ -46,8 +46,8 @@ newBirthDescriptor{ }, copy = { equipment = resolvers.equip{ id=true, - {type="weapon", subtype="longbow", name="elm longbow"}, - {type="ammo", subtype="arrow", name="elm arrow"}, + {type="weapon", subtype="longbow", name="elm longbow", autoreq=true}, + {type="ammo", subtype="arrow", name="elm arrow", autoreq=true}, }, }, } @@ -79,8 +79,8 @@ newBirthDescriptor{ }, copy = { equipment = resolvers.equip{ id=true, - {type="weapon", subtype="sling", name="elm sling"}, - {type="ammo", subtype="shot", name="iron shot"}, + {type="weapon", subtype="sling", name="elm sling", autoreq=true}, + {type="ammo", subtype="shot", name="iron shot", autoreq=true}, }, }, } diff --git a/game/modules/tome/data/birth/descriptors.lua b/game/modules/tome/data/birth/descriptors.lua index 47ffbcb15c..70682e5ef1 100644 --- a/game/modules/tome/data/birth/descriptors.lua +++ b/game/modules/tome/data/birth/descriptors.lua @@ -8,6 +8,7 @@ newBirthDescriptor{ body = { INVEN = 1000, MAINHAND=1, OFFHAND=1, BODY=1, QUIVER=1 }, copy = { + money = 10, resolvers.equip{ id=true, {type="lite", subtype="lite", name="brass lantern"}, }, diff --git a/game/modules/tome/data/birth/mage.lua b/game/modules/tome/data/birth/mage.lua index 23c55cd849..ed14d425cb 100644 --- a/game/modules/tome/data/birth/mage.lua +++ b/game/modules/tome/data/birth/mage.lua @@ -55,8 +55,8 @@ newBirthDescriptor{ max_life = 80, life_rating = 7, resolvers.equip{ id=true, - {type="weapon", subtype="staff", name="elm staff"}, - {type="armor", subtype="cloth", name="robe"} + {type="weapon", subtype="staff", name="elm staff", autoreq=true}, + {type="armor", subtype="cloth", name="robe", autoreq=true} }, resolvers.inventory{ id=true, {type="potion", subtype="potion", name="potion of lesser mana"}, @@ -103,9 +103,9 @@ newBirthDescriptor{ mana_rating = 8, stamina_rating = 8, resolvers.equip{ id=true, - {type="weapon", subtype="staff", name="elm staff"}, - {type="armor", subtype="shield", name="iron shield"}, - {type="armor", subtype="cloth", name="robe"}, + {type="weapon", subtype="staff", name="elm staff", autoreq=true}, + {type="armor", subtype="shield", name="iron shield", autoreq=true}, + {type="armor", subtype="cloth", name="robe", autoreq=true}, }, resolvers.inventory{ id=true, {type="potion", subtype="potion", name="potion of lesser mana"}, @@ -146,8 +146,8 @@ newBirthDescriptor{ max_life = 80, life_rating = 7, resolvers.equip{ id=true, - {type="weapon", subtype="staff", name="elm staff"}, - {type="armor", subtype="cloth", name="robe"} + {type="weapon", subtype="staff", name="elm staff", autoreq=true}, + {type="armor", subtype="cloth", name="robe", autoreq=true} }, resolvers.inventory{ id=true, {type="potion", subtype="potion", name="potion of lesser mana"}, diff --git a/game/modules/tome/data/birth/rogue.lua b/game/modules/tome/data/birth/rogue.lua index 9cfde48774..9076cf9d37 100644 --- a/game/modules/tome/data/birth/rogue.lua +++ b/game/modules/tome/data/birth/rogue.lua @@ -18,9 +18,9 @@ newBirthDescriptor{ max_life = 100, life_rating = 9, equipment = resolvers.equip{ id=true, - {type="weapon", subtype="dagger", name="iron dagger"}, - {type="weapon", subtype="dagger", name="iron dagger"}, - {type="armor", subtype="light", name="rough leather armour"} + {type="weapon", subtype="dagger", name="iron dagger", autoreq=true}, + {type="weapon", subtype="dagger", name="iron dagger", autoreq=true}, + {type="armor", subtype="light", name="rough leather armour", autoreq=true} }, }, } diff --git a/game/modules/tome/data/birth/warrior.lua b/game/modules/tome/data/birth/warrior.lua index 7d05df482b..652cb6a785 100644 --- a/game/modules/tome/data/birth/warrior.lua +++ b/game/modules/tome/data/birth/warrior.lua @@ -86,8 +86,8 @@ newBirthDescriptor{ }, copy = { resolvers.equip{ id=true, - {type="weapon", subtype="greatsword", name="iron greatsword"}, - {type="armor", subtype="heavy", name="iron mail armour"} + {type="weapon", subtype="greatsword", name="iron greatsword", autoreq=true}, + {type="armor", subtype="heavy", name="iron mail armour", autoreq=true}, }, }, } diff --git a/game/modules/tome/data/general/objects/money.lua b/game/modules/tome/data/general/objects/money.lua new file mode 100644 index 0000000000..26f658b3ca --- /dev/null +++ b/game/modules/tome/data/general/objects/money.lua @@ -0,0 +1,22 @@ +newEntity{ + define_as = "BASE_MONEY", + type = "money", subtype="money", + display = "$", color=colors.YELLOW, + encumber = 0, + rarity = 5, + identified = true, + desc = [[All that glisters is not gold, all that is gold does not glitter.]], + on_prepickup = function(self, who, id) + who.money = who.money + self.money_value / 10 + -- Remove from the map + game.level.map:removeObject(who.x, who.y, id) + return true + end, +} + +newEntity{ base = "BASE_MONEY", + name = "gold pieces", + add_name = " (#MONEY#)", + level_range = {1, 50}, + money_value = resolvers.rngavg(1, 20), +} diff --git a/game/modules/tome/data/general/objects/objects.lua b/game/modules/tome/data/general/objects/objects.lua index f164d38faf..e8c603b110 100644 --- a/game/modules/tome/data/general/objects/objects.lua +++ b/game/modules/tome/data/general/objects/objects.lua @@ -1,4 +1,5 @@ -- Misc +load("/data/general/objects/money.lua") load("/data/general/objects/lites.lua") -- Usable stuff -- GitLab