Skip to content
Snippets Groups Projects
Commit f0af9952 authored by dg's avatar dg
Browse files

max encumberance

git-svn-id: http://svn.net-core.org/repos/t-engine4@370 51575b47-30f0-44d4-a5cc-537603b46e54
parent 6dc1cb58
No related branches found
No related tags found
No related merge requests found
......@@ -122,6 +122,7 @@ end
--- Applies a function to all items of the stack
function _M:forAllStack(fct)
fct(self)
if not self.stacked then return end
for i, so in ipairs(self.stacked) do
fct(so)
end
......
......@@ -8,7 +8,7 @@ function _M:init(title, inven, filter, action, actor)
self.filter = filter
self.action = action
self.actor = actor
engine.Dialog.init(self, title or "Inventory", game.w * 0.8, game.h * 0.8, nil, nil, nil, core.display.newFont("/data/font/VeraMono.ttf", 10))
engine.Dialog.init(self, title or "Inventory", game.w * 0.8, game.h * 0.8, nil, nil, nil, core.display.newFont("/data/font/VeraMono.ttf", 12))
self:generateList()
......
......@@ -77,9 +77,15 @@ function _M:addObject(inven_id, o)
self:onWear(o)
end
self:onAddObject(o)
return true
end
--- Called upon adding an object
function _M:onAddObject(o)
end
--- Picks an object from the floor
function _M:pickupFloor(i, vocal)
local o = game.level.map:getObject(self.x, self.y, i)
......@@ -118,9 +124,15 @@ function _M:removeObject(inven, item, no_unstack)
self:onTakeoff(o)
end
self:onRemoveObject(o)
return o
end
--- Called upon removing an object
function _M:onRemoveObject(o)
end
--- Drop an object on the floor
-- @param inven the inventory to drop from
-- @param item the item id to drop
......
......@@ -330,6 +330,46 @@ function _M:attack(target)
self:bumpInto(target)
end
function _M:getMaxEncumberance()
return math.floor(40 + self:getStr() * 1.8)
end
function _M:checkEncumberance()
-- Compute encumberance
local enc, max = 0, self:getMaxEncumberance()
for inven_id, inven in pairs(self.inven) do
for item, o in ipairs(inven) do
o:forAllStack(function(so) enc = enc + so.encumber end)
end
end
print("Total encumberance", enc, max)
-- We are pinned to the ground if we carry too much
if not self.encumbered and enc > max then
game.logPlayer(self, "#FF0000#You carry too much, you are encumbered!")
game.logPlayer(self, "#FF0000#Drop some of your items.")
self.encumbered = self:addTemporaryValue("never_move", 1)
elseif self.encumbered and enc <= max then
self:removeTemporaryValue("never_move", self.encumbered)
self.encumbered = nil
game.logPlayer(self, "#00FF00#You are no longer encumbered.")
end
end
--- Call when an object is added
function _M:onAddObject(o)
engine.interface.ActorInventory.onAddObject(self, o)
self:checkEncumberance()
end
--- Call when an object is removed
function _M:onRemoveObject(o)
engine.interface.ActorInventory.onRemoveObject(self, o)
self:checkEncumberance()
end
--- Actor learns a talent
-- @param t_id the id of the talent to learn
-- @return true if the talent was learnt, nil and an error message otherwise
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment