diff --git a/game/engines/default/engine/interface/ObjectActivable.lua b/game/engines/default/engine/interface/ObjectActivable.lua index 729e4de18bebe1d9ae0878df1e6977fce13f8107..37f190759f4e0580e0cfb31c6e9b6a7b165fcfba 100644 --- a/game/engines/default/engine/interface/ObjectActivable.lua +++ b/game/engines/default/engine/interface/ObjectActivable.lua @@ -59,9 +59,7 @@ end function _M:useObject(who) if self.use_power then if self.power >= self.use_power.power then - local co = coroutine.create(function() return self.use_power.use(self, who) end) - local ok, ret, no_power = coroutine.resume(co) - if not ok and ret then print(debug.traceback(co)) error(ret) end + local ret, no_power = self.use_power.use(self, who) if not no_power then self.power = self.power - self.use_power.power end return ret else @@ -72,9 +70,7 @@ function _M:useObject(who) end end elseif self.use_simple then - local co = coroutine.create(function() return self.use_simple.use(self, who) end) - local ok, ret = coroutine.resume(co) - if not ok and ret then print(debug.traceback(co)) error(ret) end + local ret = self.use_simple.use(self, who) return ret elseif self.use_talent then if not self.use_talent.power or self.power >= self.use_talent.power then diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua index edbcdb7b64bade36ae9c54c4b3067ef52deab6f3..bff5aef4b5f6f0d2fe3afaa907c93366163c1c46 100644 --- a/game/modules/tome/class/Game.lua +++ b/game/modules/tome/class/Game.lua @@ -624,9 +624,10 @@ function _M:setupCommands() local d local titleupdator = self.player:getEncumberTitleUpdator("Inventory") d = self.player:showEquipInven(titleupdator(), nil, function(o, inven, item) - local ud = require("mod.dialogs.UseItemDialog").new(self.player, o, item, inven, function() + local ud = require("mod.dialogs.UseItemDialog").new(self.player, o, item, inven, function(_, _, _, stop) d:generateList() d.title = titleupdator() + if stop then self:unregisterDialog(d) end end) self:registerDialog(ud) end) diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua index 8400b41d285bba3fa0550f255bb4cfec671058db..cb98633bef897d4b1b7a139ab1a729f5b20afd26 100644 --- a/game/modules/tome/class/Player.lua +++ b/game/modules/tome/class/Player.lua @@ -519,27 +519,33 @@ function _M:playerUseItem(object, item, inven) if game.zone.wilderness then game.logPlayer(self, "You can not use items on the world map.") return end local use_fct = function(o, inven, item) - self.changed = true - local ret, no_id = o:use(self) - if not no_id then - o:identify(true) - end - if ret and ret == "destroy" then - if o.multicharge and o.multicharge > 1 then - o.multicharge = o.multicharge - 1 - else - local _, del = self:removeObject(self:getInven(inven), item) - if del then - game.log("You have no more %s.", o:getName{no_count=true, do_color=true}) + local co = coroutine.create(function() + self.changed = true + local ret, no_id = o:use(self) + print(ret,no_id) + if not no_id then + o:identify(true) + end + if ret and ret == "destroy" then + if o.multicharge and o.multicharge > 1 then + o.multicharge = o.multicharge - 1 else - game.log("You have %s.", o:getName{do_color=true}) + local _, del = self:removeObject(self:getInven(inven), item) + if del then + game.log("You have no more %s.", o:getName{no_count=true, do_color=true}) + else + game.log("You have %s.", o:getName{do_color=true}) + end + self:sortInven(self:getInven(inven)) end - self:sortInven(self:getInven(inven)) + return true end - return true - end - self:breakStealth() - self.changed = true + self:breakStealth() + self.changed = true + end) + local ok, ret = coroutine.resume(co) + if not ok and ret then print(debug.traceback(co)) error(ret) end + return true end if object and item then return use_fct(object, inven, item) end diff --git a/game/modules/tome/dialogs/UseItemDialog.lua b/game/modules/tome/dialogs/UseItemDialog.lua index e9f1a73d98c53b2e204f01041a48ac75fd84e97a..03b95f0239394865ad6f249611215fe9ffcbdce7 100644 --- a/game/modules/tome/dialogs/UseItemDialog.lua +++ b/game/modules/tome/dialogs/UseItemDialog.lua @@ -63,13 +63,14 @@ function _M:use() local act = self.list[self.sel].action - if act == "use" then self.actor:playerUseItem(self.object, self.item, self.inven, self.onuse) + local stop = false + if act == "use" then self.actor:playerUseItem(self.object, self.item, self.inven, self.onuse) stop = true elseif act == "drop" then self.actor:doDrop(self.inven, self.item) elseif act == "wear" then self.actor:doWear(self.inven, self.item, self.object) elseif act == "takeoff" then self.actor:doTakeoff(self.inven, self.item, self.object) end - self.onuse(self.inven, self.item, self.object) + self.onuse(self.inven, self.item, self.object, stop) end function _M:generateList()