diff --git a/game/engines/default/engine/interface/ActorInventory.lua b/game/engines/default/engine/interface/ActorInventory.lua index 14f5af430f0be38b27be572d6245426aa8827c5e..befce03e8b7e486020412b843ebe384e832a5aee 100644 --- a/game/engines/default/engine/interface/ActorInventory.lua +++ b/game/engines/default/engine/interface/ActorInventory.lua @@ -330,6 +330,10 @@ function _M:canWearObject(o, try_slot) end end + -- Any custom checks + local err = self:check("canWearObjectCustom", o, try_slot) + if err then return nil, err end + return true end diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index 3520a133dc6beb298f28a47fdca1d8228bd42b9b..638889f718d5f06e9b6703b8d9253f316340aa89 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -4973,6 +4973,95 @@ function _M:onDropObject(o) elseif game.level.map.attrs(self.x, self.y, "obj_seen") then game.level.map.attrs(self.x, self.y, "obj_seen", false) end end +function _M:doDrop(inven, item, on_done, nb) + if self.no_inventory_access then return end + + local o = self:getInven(inven) and self:getInven(inven)[item] + if o and o.plot then + game.logPlayer(self, "You can not drop %s (plot item).", o:getName{do_colour=true}) + return + end + + if o and o.__tagged then + game.logPlayer(self, "You can not drop %s (tagged).", o:getName{do_colour=true}) + return + end + + if game.zone.wilderness then + Dialog:yesnoLongPopup("Warning", "You cannot drop items on the world map.\nIf you drop it, it will be lost forever.", 300, function(ret) + -- The test is reversed because the buttons are reversed, to prevent mistakes + if not ret then + local o = self:getInven(inven) and self:getInven(inven)[item] + if o and not o.plot then + if o:check("on_drop", self) then return end + local o = self:removeObject(inven, item, true) + game.logPlayer(self, "You destroy %s.", o:getName{do_colour=true, do_count=true}) + self:sortInven() + self:useEnergy() + if on_done then on_done() end + elseif o then + game.logPlayer(self, "You can not destroy %s.", o:getName{do_colour=true}) + end + end + end, "Cancel", "Destroy", true) + return + end + if nb == nil or nb >= self:getInven(inven)[item]:getNumber() then + self:dropFloor(inven, item, true, true) + else + for i = 1, nb do self:dropFloor(inven, item, true) end + end + self:sortInven(inven) + self:useEnergy() + self.changed = true + game:playSound("actions/drop") + if on_done then on_done() end +end + +function _M:doWear(inven, item, o, dst) + if self.no_inventory_access then return end + dst = dst or self + dst:removeObject(inven, item, true) + local ro = self:wearObject(o, true, true) + if ro then + if not self:attr("quick_wear_takeoff") or self:attr("quick_wear_takeoff_disable") then self:useEnergy() end + if self:attr("quick_wear_takeoff") then self:setEffect(self.EFF_SWIFT_HANDS_CD, 1, {}) self.tmp[self.EFF_SWIFT_HANDS_CD].dur = 0 end + if type(ro) == "table" then dst:addObject(inven, ro) end + elseif not ro then + dst:addObject(inven, o) + end + dst:sortInven() + if self.playerCheckSustains then self:playerCheckSustains() end + self.changed = true +end + +function _M:doTakeoff(inven, item, o, simple, dst) + if self.no_inventory_access then return end + dst = dst or self + if self:takeoffObject(inven, item) then + dst:addObject(self.INVEN_INVEN, o) + end + if not simple then + dst:sortInven() + if not self:attr("quick_wear_takeoff") or self:attr("quick_wear_takeoff_disable") then self:useEnergy() end + if self:attr("quick_wear_takeoff") then self:setEffect(self.EFF_SWIFT_HANDS_CD, 1, {}) self.tmp[self.EFF_SWIFT_HANDS_CD].dur = 0 end + end + if self.playerCheckSustains then self:playerCheckSustains() end + self.changed = true +end + +function _M:getEncumberTitleUpdator(title) + return function() + local enc, max = self:getEncumbrance(), self:getMaxEncumbrance() + local color = "#00ff00#" + if enc > max then color = "#ff0000#" + elseif enc > max * 0.9 then color = "#ff8a00#" + elseif enc > max * 0.75 then color = "#fcff00#" + end + return ("%s - %sEncumbrance %d/%d"):format(title, color, enc, max) + end +end + function _M:transmoPricemod(o) if o.type == "gem" then return 0.40 else return 0.05 end end function _M:transmoFilter(o) if o:getPrice() <= 0 or o.quest then return false end return true end function _M:transmoInven(inven, idx, o) diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua index ae50a6fa8e6a5d404b5eadddcaaab65d00126aa4..cc4ceac28881eaf4c57d717610fa3fbc6bf06c94 100644 --- a/game/modules/tome/class/Player.lua +++ b/game/modules/tome/class/Player.lua @@ -1057,93 +1057,6 @@ function _M:hotkeyInventory(name) end end -function _M:doDrop(inven, item, on_done, nb) - if self.no_inventory_access then return end - - local o = self:getInven(inven) and self:getInven(inven)[item] - if o and o.plot then - game.logPlayer(self, "You can not drop %s (plot item).", o:getName{do_colour=true}) - return - end - - if o and o.__tagged then - game.logPlayer(self, "You can not drop %s (tagged).", o:getName{do_colour=true}) - return - end - - if game.zone.wilderness then - Dialog:yesnoLongPopup("Warning", "You cannot drop items on the world map.\nIf you drop it, it will be lost forever.", 300, function(ret) - -- The test is reversed because the buttons are reversed, to prevent mistakes - if not ret then - local o = self:getInven(inven) and self:getInven(inven)[item] - if o and not o.plot then - if o:check("on_drop", self) then return end - local o = self:removeObject(inven, item, true) - game.logPlayer(self, "You destroy %s.", o:getName{do_colour=true, do_count=true}) - self:sortInven() - self:useEnergy() - if on_done then on_done() end - elseif o then - game.logPlayer(self, "You can not destroy %s.", o:getName{do_colour=true}) - end - end - end, "Cancel", "Destroy", true) - return - end - if nb == nil or nb >= self:getInven(inven)[item]:getNumber() then - self:dropFloor(inven, item, true, true) - else - for i = 1, nb do self:dropFloor(inven, item, true) end - end - self:sortInven(inven) - self:useEnergy() - self.changed = true - game:playSound("actions/drop") - if on_done then on_done() end -end - -function _M:doWear(inven, item, o) - if self.no_inventory_access then return end - self:removeObject(inven, item, true) - local ro = self:wearObject(o, true, true) - if ro then - if not self:attr("quick_wear_takeoff") or self:attr("quick_wear_takeoff_disable") then self:useEnergy() end - if self:attr("quick_wear_takeoff") then self:setEffect(self.EFF_SWIFT_HANDS_CD, 1, {}) self.tmp[self.EFF_SWIFT_HANDS_CD].dur = 0 end - if type(ro) == "table" then self:addObject(inven, ro) end - elseif not ro then - self:addObject(inven, o) - end - self:sortInven() - self:playerCheckSustains() - self.changed = true -end - -function _M:doTakeoff(inven, item, o, simple) - if self.no_inventory_access then return end - if self:takeoffObject(inven, item) then - self:addObject(self.INVEN_INVEN, o) - end - if not simple then - self:sortInven() - if not self:attr("quick_wear_takeoff") or self:attr("quick_wear_takeoff_disable") then self:useEnergy() end - if self:attr("quick_wear_takeoff") then self:setEffect(self.EFF_SWIFT_HANDS_CD, 1, {}) self.tmp[self.EFF_SWIFT_HANDS_CD].dur = 0 end - end - self:playerCheckSustains() - self.changed = true -end - -function _M:getEncumberTitleUpdator(title) - return function() - local enc, max = self:getEncumbrance(), self:getMaxEncumbrance() - local color = "#00ff00#" - if enc > max then color = "#ff0000#" - elseif enc > max * 0.9 then color = "#ff8a00#" - elseif enc > max * 0.75 then color = "#fcff00#" - end - return ("%s - %sEncumbrance %d/%d"):format(title, color, enc, max) - end -end - function _M:playerPickup() -- If 2 or more objects, display a pickup dialog, otherwise just picks up if game.level.map:getObject(self.x, self.y, 2) then @@ -1427,8 +1340,6 @@ function _M:playerCheckSustains() end function _M:playerLevelup(on_finish, on_birth) - package.loaded["mod.dialogs.LevelupDialog"] = nil - package.loaded["mod.dialogs.elements.TalentTrees"] = nil local LevelupDialog = require "mod.dialogs.LevelupDialog" local ds = LevelupDialog.new(self, on_finish, on_birth) game:registerDialog(ds) diff --git a/game/modules/tome/data/chats/alchemist-golem.lua b/game/modules/tome/data/chats/alchemist-golem.lua index 30288ba154f0445b6f2cb556b9a9ac39dc9cc0c5..0157b54a365e192aba2ad2c63b6e82817c111e3b 100644 --- a/game/modules/tome/data/chats/alchemist-golem.lua +++ b/game/modules/tome/data/chats/alchemist-golem.lua @@ -17,61 +17,31 @@ -- Nicolas Casalini "DarkGod" -- darkgod@te4.org -local change_weapon = function(npc, player) - local inven = player:getInven("INVEN") - player:showInventory("Select a two-handed weapon for your golem.", inven, function(o) return o.type == "weapon" and o.twohanded end, function(o, item) - player:removeObject(inven, item, true) - local ro = npc:wearObject(o, true, true) - if ro then - if type(ro) == "table" then player:addObject(inven, ro) end - elseif not ro then - player:addObject(inven, o) - else - game.logPlayer(player, "Your golem equips: %s.", o:getName{do_color=true, no_count=true}) - end - player:sortInven() - player:useEnergy() - return true - end) +local change_inven = function(npc, player) + local d + local titleupdator = player:getEncumberTitleUpdator(("Equipment(%s) <=> Inventory(%s)"):format(npc.name:capitalize(), player.name:capitalize())) + d = require("mod.dialogs.ShowEquipInven").new(titleupdator(), npc, nil, function(o, inven, item, button, event) + if not o then return end + local ud = require("mod.dialogs.UseItemDialog").new(event == "button", npc, o, item, inven, function(_, _, _, stop) + d:generate() + d:generateList() + d:updateTitle(titleupdator()) + if stop then game:unregisterDialog(d) end + end, true, player) + game:registerDialog(ud) + end, nil, player) + game:registerDialog(d) end -local change_armour = function(npc, player) - local inven = player:getInven("INVEN") - player:showInventory("Select an armour (of any kind) for your golem.", inven, function(o) return o.type == "armor" and o.slot == "BODY" end, function(o, item) - player:removeObject(inven, item, true) - local ro = npc:wearObject(o, true, true) - if ro then - if type(ro) == "table" then player:addObject(inven, ro) end - elseif not ro then - player:addObject(inven, o) - else - game.logPlayer(player, "Your golem equips: %s.", o:getName{do_color=true, no_count=true}) - end - player:sortInven() - player:useEnergy() - return true - end) +local change_talents = function(npc, player) + local LevelupDialog = require "mod.dialogs.LevelupDialog" + local ds = LevelupDialog.new(npc, nil, nil) + game:registerDialog(ds) end -local change_gem = function(npc, player, gemid) - local inven = player:getInven("INVEN") - player:showInventory("Select a gem for your golem.", inven, function(o) return o.type == "gem" and o.material_level and o.material_level <= player:getTalentLevelRaw(player.T_GEM_GOLEM) end, function(o, item) - o = player:removeObject(inven, item) - local gems = golem:getInven("GEM") - local old = golem:removeObject(gems, gemid) - if old then player:addObject(inven, old) end - - -- Force "wield" - golem:addObject(gems, o) - game.logSeen(player, "%s sockets %s with %s.", player.name:capitalize(), golem.name, o:getName{do_color=true}:a_an()) - - player:sortInven() - player:useEnergy() - return true - end) +local change_tactics = function(npc, player) + game.party:giveOrders(npc) end -local change_gem1 = function(npc, player) return change_gem(npc, player, 1) end -local change_gem2 = function(npc, player) return change_gem(npc, player, 2) end local change_name = function(npc, player) local d = require("engine.dialogs.GetText").new("Change your golem's name", "Name", 2, 25, function(name) @@ -84,19 +54,13 @@ local change_name = function(npc, player) end local ans = { - {"I want to change your weapon.", action=change_weapon}, - {"I want to change your armour.", action=change_armour}, + {"I want to change your equipment.", action=change_inven}, + {"I want to change your talents.", action=change_talents}, + {"I want to change your tactics.", action=change_tactics}, {"I want to change your name.", action=change_name}, {"Nothing, let's go."}, } -if player:knowTalent(player.T_GEM_GOLEM) then - local gem1 = golem:getInven("GEM")[1] - local gem2 = golem:getInven("GEM")[2] - table.insert(ans, 3, {("I want to change your first gem%s."):format(gem1 and "(currently: "..gem1:getName{}..")" or ""), action=change_gem1}) - table.insert(ans, 4, {("I want to change your second gem%s."):format(gem2 and "(currently: "..gem2:getName{}..")" or ""), action=change_gem2}) -end - newChat{ id="welcome", text = [[#LIGHT_GREEN#*The golem talks in a monotonous voice*#WHITE# Yes master.]], diff --git a/game/modules/tome/data/general/objects/gem.lua b/game/modules/tome/data/general/objects/gem.lua index 961828d955704adc7fd7e94de44cce13a7019052..02204e940f82ec956e018b6b0f5230e92d11128e 100644 --- a/game/modules/tome/data/general/objects/gem.lua +++ b/game/modules/tome/data/general/objects/gem.lua @@ -43,7 +43,7 @@ local colors_attacks = { local function newGem(name, image, cost, rarity, color, min_level, max_level, tier, power, imbue, bomb) -- Gems, randomly lootable newEntity{ base = "BASE_GEM", define_as = "GEM_"..name:gsub(" ", "_"):upper(), - name = name:lower(), subtype = color, + name = name:lower(), subtype = color, slot = "GEM", color = colors[color:upper()], image=image, level_range = {min_level, max_level}, rarity = rarity, cost = cost * 10, diff --git a/game/modules/tome/data/gfx/talents/interact_golem.png b/game/modules/tome/data/gfx/talents/interact_golem.png new file mode 100644 index 0000000000000000000000000000000000000000..07485ea7465be4b5d62f60918498f8110269b98a Binary files /dev/null and b/game/modules/tome/data/gfx/talents/interact_golem.png differ diff --git a/game/modules/tome/data/talents/spells/advanced-golemancy.lua b/game/modules/tome/data/talents/spells/advanced-golemancy.lua index af6974753f4656d52a882849c77c0408957b5029..61f1f4e9a68d28c9e92363dea4e2e8b9e2e8e087 100644 --- a/game/modules/tome/data/talents/spells/advanced-golemancy.lua +++ b/game/modules/tome/data/talents/spells/advanced-golemancy.lua @@ -69,7 +69,7 @@ newTalent{ info = function(self, t) return ([[Insert a pair of gems into your golem, providing it with the gem bonuses and changing its melee attack damage type. You may remove the gems and insert different ones; this does not destroy the gems you remove. Gem level usable: %d - Gem changing is done when refitting your golem (use Refit Golem at full life).]]):format(self:getTalentLevelRaw(t)) + Gem changing is done in the golem's inventory.]]):format(self:getTalentLevelRaw(t)) end, } diff --git a/game/modules/tome/data/talents/spells/golemancy.lua b/game/modules/tome/data/talents/spells/golemancy.lua index 91d757426e88a81b53bcb5a3417b4b4c904dce7e..c42b027a20112cbb0fcc093931082127cc8a4485 100644 --- a/game/modules/tome/data/talents/spells/golemancy.lua +++ b/game/modules/tome/data/talents/spells/golemancy.lua @@ -43,6 +43,13 @@ local function makeGolem(self) combat = { dam=10, atk=10, apr=0, dammod={str=1} }, body = { INVEN = 1000, QS_MAINHAND = 1, QS_OFFHAND = 1, MAINHAND = 1, OFFHAND = 1, BODY=1, GEM=2 }, + canWearObjectCustom = function(self, o) + if o.type ~= "gem" then return end + if not self.summoner then return "Golem has no master" end + if not self.summoner:knowTalent(self.summoner.T_GEM_GOLEM) then return "Runic Golem talent required" end + if not o.material_level then return "impossible to use this gem" end + if o.material_level > self.summoner:getTalentLevelRaw(self.summoner.T_GEM_GOLEM) then return "Runic Golem talent too low for this gem" end + end, equipdoll = "alchemist_golem", infravision = 10, rank = 3, @@ -150,9 +157,42 @@ local function makeGolem(self) return g end +newTalent{ + name = "Interact with the Golem", short_name = "INTERACT_GOLEM", + type = {"spell/golemancy-base", 1}, + require = spells_req1, + points = 1, + mana = 10, + no_energy = true, + no_npc_use = true, + no_unlearn_last = true, + action = function(self, t) + if not self.alchemy_golem then return end + + local on_level = false + for x = 0, game.level.map.w - 1 do for y = 0, game.level.map.h - 1 do + local act = game.level.map(x, y, Map.ACTOR) + if act and act == self.alchemy_golem then on_level = true break end + end end + + -- talk to the golem + if game.level:hasEntity(self.alchemy_golem) and on_level then + local chat = Chat.new("alchemist-golem", self.alchemy_golem, self, {golem=self.alchemy_golem, player=self}) + chat:invoke() + end + return true + end, + info = function(self, t) + return ([[Interact with your golem to check its inventory, talents, ... + Note: You can also do that while taking direct control of the golem.]]): + format() + end, +} + newTalent{ name = "Refit Golem", type = {"spell/golemancy-base", 1}, + autolearn_talent = "T_INTERACT_GOLEM", require = spells_req1, points = 1, cooldown = 20, @@ -230,11 +270,9 @@ newTalent{ if act and act == self.alchemy_golem then on_level = true break end end end - -- talk to the golem if game.level:hasEntity(self.alchemy_golem) and on_level and self.alchemy_golem.life >= self.alchemy_golem.max_life then - local chat = Chat.new("alchemist-golem", self.alchemy_golem, self, {golem=self.alchemy_golem, player=self}) - chat:invoke() - + -- nothing + return nil -- heal the golem elseif ((game.level:hasEntity(self.alchemy_golem) and on_level) or self:hasEffect(self.EFF_GOLEM_MOUNT)) and self.alchemy_golem.life < self.alchemy_golem.max_life then if not ammo or ammo:getNumber() < 2 then @@ -279,10 +317,9 @@ newTalent{ end, info = function(self, t) local heal = t.getHeal(self, t) - return ([[Interact with your golem! - - If it is destroyed, you will take some time to reconstruct it (this takes 15 alchemist gems). - - If it is alive but hurt, you will be able to repair it for %d (takes 2 alchemist gems). Spellpower, alchemist gem and Golem Power talent all influence the healing done. - - If it is alive and unhurt, you can rename it, or adjust its equipment or gems.]]): + return ([[Take care of your golem: + - If it is destroyed, you will take some time to reconstruct it (this takes 15 alchemist gems and 20 turns). + - If it is alive but hurt, you will be able to repair it for %d (takes 2 alchemist gems). Spellpower, alchemist gem and Golem Power talent all influence the healing done.]]): format(heal) end, } diff --git a/game/modules/tome/dialogs/LevelupDialog.lua b/game/modules/tome/dialogs/LevelupDialog.lua index ca5f7042d664252ee1c47363ec7b9cf944e231a8..adcc6eb3e8064d5938604797aa0c493425854e7f 100644 --- a/game/modules/tome/dialogs/LevelupDialog.lua +++ b/game/modules/tome/dialogs/LevelupDialog.lua @@ -71,11 +71,14 @@ function _M:init(actor, on_finish, on_birth) self.actor.__hidden_talent_types = self.actor.__hidden_talent_types or {} self.actor.__increased_talent_types = self.actor.__increased_talent_types or {} + actor.last_learnt_talents = actor.last_learnt_talents or { class={}, generic={} } self.actor_dup = backup(actor) if actor.alchemy_golem then self.golem_dup = backup(actor.alchemy_golem) end - for _, v in pairs(game.engine.Birther.birth_descriptor_def) do - if v.type == "subclass" and v.name == actor.descriptor.subclass then self.desc_def = v break end + if actor.descriptor then + for _, v in pairs(game.engine.Birther.birth_descriptor_def) do + if v.type == "subclass" and v.name == actor.descriptor.subclass then self.desc_def = v break end + end end Dialog.init(self, "Levelup: "..actor.name, game.w * 0.9, game.h * 0.9, game.w * 0.05, game.h * 0.05) diff --git a/game/modules/tome/dialogs/ShowEquipInven.lua b/game/modules/tome/dialogs/ShowEquipInven.lua index 39e5b4aae5b20b9b16c7332eaa314b6ff1112b6e..13a0a8d76905ec5bd5e04c0cdcc1ceb7d429912c 100644 --- a/game/modules/tome/dialogs/ShowEquipInven.lua +++ b/game/modules/tome/dialogs/ShowEquipInven.lua @@ -27,47 +27,49 @@ local Tab = require "engine.ui.Tab" module(..., package.seeall, class.inherit(Dialog)) -function _M:init(title, actor, filter, action, on_select) +function _M:init(title, equip_actor, filter, action, on_select, inven_actor) self.action = action self.filter = filter - self.actor = actor - + inven_actor = inven_actor or equip_actor + self.equip_actor = equip_actor + self.inven_actor = inven_actor + game.tooltip.add_map_str = nil Dialog.init(self, title or "Inventory", math.max(800, game.w * 0.8), math.max(600, game.h * 0.8)) - self.c_main_set = Tab.new{title="Main Set", default=not actor.off_weapon_slots, fct=function() end, on_change=function(s) if s then self:switchSets("main") end end} - self.c_off_set = Tab.new{title="Off Set", default=actor.off_weapon_slots, fct=function() end, on_change=function(s) if s then self:switchSets("off") end end} + self.c_main_set = Tab.new{title="Main Set", default=not equip_actor.off_weapon_slots, fct=function() end, on_change=function(s) if s then self:switchSets("main") end end} + self.c_off_set = Tab.new{title="Off Set", default=equip_actor.off_weapon_slots, fct=function() end, on_change=function(s) if s then self:switchSets("off") end end} -- Add tooltips self.on_select = function(item) if item.last_display_x and item.object then local x if self.focus_ui and self.focus_ui.ui == self.c_inven then x = self.c_inven._last_ox - game.tooltip.w end - game:tooltipDisplayAtMap(x or item.last_display_x, item.last_display_y, item.object:getDesc({do_color=true}, self.actor:getInven(item.object:wornInven()))) + game:tooltipDisplayAtMap(x or item.last_display_x, item.last_display_y, item.object:getDesc({do_color=true}, self.equip_actor:getInven(item.object:wornInven()))) elseif item.last_display_x and item.data and item.data.desc then game:tooltipDisplayAtMap(item.last_display_x, item.last_display_y, item.data.desc, {up=true}) end end - self.c_doll = EquipDoll.new{actor=actor, drag_enable=true, filter=filter, + self.c_doll = EquipDoll.new{actor=equip_actor, drag_enable=true, filter=filter, fct = function(item, button, event) self:use(item, button, event) end, on_select = function(ui, inven, item, o) if ui.ui.last_display_x then self:select{last_display_x=ui.ui.last_display_x+ui.ui.w, last_display_y=ui.ui.last_display_y, object=o} end end, actorWear = function(ui, wear_inven, wear_item, wear_o) if ui:getItem() then - local bi = self.actor:getInven(ui.inven) - local ws = self.actor:getInven(wear_o:wornInven()) - local os = self.actor:getObjectOffslot(wear_o) - if bi and ((ws and ws.id == bi.id) or (os and self.actor:getInven(os).id == bi.id)) then - self.actor:doTakeoff(ui.inven, ui.item, ui:getItem(), true) + local bi = self.equip_actor:getInven(ui.inven) + local ws = self.equip_actor:getInven(wear_o:wornInven()) + local os = self.equip_actor:getObjectOffslot(wear_o) + if bi and ((ws and ws.id == bi.id) or (os and self.equip_actor:getInven(os).id == bi.id)) then + self.equip_actor:doTakeoff(ui.inven, ui.item, ui:getItem(), true, self.inven_actor) end end - self.actor:doWear(wear_inven, wear_item, wear_o) + self.equip_actor:doWear(wear_inven, wear_item, wear_o, self.inven_actor) self.c_inven:generateList() end } - self.c_inven = Inventory.new{actor=actor, inven=actor:getInven("INVEN"), width=self.iw - 20 - self.c_doll.w, height=self.ih - 10, filter=filter, + self.c_inven = Inventory.new{actor=inven_actor, inven=inven_actor:getInven("INVEN"), width=self.iw - 20 - self.c_doll.w, height=self.ih - 10, filter=filter, default_last_tabs = "all", fct=function(item, sel, button, event) self:use(item, button, event) end, select=function(item, sel) self:select(item) end, @@ -92,6 +94,11 @@ function _M:init(title, actor, filter, action, on_select) self:loadUI(uis) self:setFocus(self.c_inven) self:setupUI() + + if not self.equip_actor.quickSwitchWeapons then + self:toggleDisplay(self.c_main_set, false) + self:toggleDisplay(self.c_off_set, false) + end local lock_tooltip = function() if not game.tooltip.empty then @@ -155,13 +162,14 @@ function _M:init(title, actor, filter, action, on_select) end function _M:switchSets(which) - if which == "main" and not self.actor.off_weapon_slots then return end - if which == "off" and self.actor.off_weapon_slots then return end + if not self.equip_actor.quickSwitchWeapons then return end + if which == "main" and not self.equip_actor.off_weapon_slots then return end + if which == "off" and self.equip_actor.off_weapon_slots then return end - self.actor:quickSwitchWeapons() + self.equip_actor:quickSwitchWeapons() - self.c_main_set.selected = not self.actor.off_weapon_slots - self.c_off_set.selected = self.actor.off_weapon_slots + self.c_main_set.selected = not self.equip_actor.off_weapon_slots + self.c_off_set.selected = self.equip_actor.off_weapon_slots end function _M:firstDisplay() @@ -174,7 +182,8 @@ function _M:on_register() end function _M:defineHotkey(id) - if not self.actor or not self.actor.hotkey then return end + if self.equip_actor ~= self.inven_actor then return end + if not self.equip_actor or not self.equip_actor.hotkey then return end local item = nil if self.focus_ui and self.focus_ui.ui == self.c_inven then item = self.c_inven.c_inven.list[self.c_inven.c_inven.sel] @@ -182,9 +191,9 @@ function _M:defineHotkey(id) end if not item or not item.object then return end - self.actor.hotkey[id] = {"inventory", item.object:getName{no_add_name=true, no_count=true}} + self.equip_actor.hotkey[id] = {"inventory", item.object:getName{no_add_name=true, no_count=true}} self:simplePopup("Hotkey "..id.." assigned", item.object:getName{no_add_name=true, no_count=true}:capitalize().." assigned to hotkey "..id) - self.actor.changed = true + self.equip_actor.changed = true end function _M:select(item, force) @@ -202,7 +211,7 @@ function _M:use(item, button, event) end function _M:unload() - for inven_id = 1, #self.actor.inven_def do if self.actor.inven[inven_id] then for item, o in ipairs(self.actor.inven[inven_id]) do o.__new_pickup = nil end end end + for inven_id = 1, #self.inven_actor.inven_def do if self.inven_actor.inven[inven_id] then for item, o in ipairs(self.inven_actor.inven[inven_id]) do o.__new_pickup = nil end end end end function _M:updateTitle(title) @@ -211,7 +220,7 @@ function _M:updateTitle(title) local green = colors.LIGHT_GREEN local red = colors.LIGHT_RED - local enc, max = self.actor:getEncumbrance(), self.actor:getMaxEncumbrance() + local enc, max = self.equip_actor:getEncumbrance(), self.equip_actor:getMaxEncumbrance() local v = math.min(enc, max) / max self.title_fill = self.iw * v self.title_fill_color = { @@ -236,8 +245,8 @@ end function _M:onDragTakeoff() local drag = game.mouse.dragged.payload - if drag.kind == "inventory" and drag.inven and self.actor:getInven(drag.inven) and self.actor:getInven(drag.inven).worn then - self.actor:doTakeoff(drag.inven, drag.item_idx, drag.object) + if drag.kind == "inventory" and drag.inven and self.equip_actor:getInven(drag.inven) and self.equip_actor:getInven(drag.inven).worn then + self.equip_actor:doTakeoff(drag.inven, drag.item_idx, drag.object, nil, self.inven_actor) self.c_inven:generateList() game.mouse:usedDrag() end diff --git a/game/modules/tome/dialogs/UseItemDialog.lua b/game/modules/tome/dialogs/UseItemDialog.lua index 9949d65ecfe4ee91ae37fa5378e2f799c80edb28..dbcbbd58900ee3481986009fcc6746d6ce1a5216 100644 --- a/game/modules/tome/dialogs/UseItemDialog.lua +++ b/game/modules/tome/dialogs/UseItemDialog.lua @@ -27,8 +27,9 @@ local PartySendItem = require "mod.dialogs.PartySendItem" module(..., package.seeall, class.inherit(engine.ui.Dialog)) -function _M:init(center_mouse, actor, object, item, inven, onuse, no_use) +function _M:init(center_mouse, actor, object, item, inven, onuse, no_use, dst_actor) self.actor = actor + self.dst_actor = dst_actor self.object = object self.inven = inven self.item = item @@ -82,10 +83,10 @@ function _M:use(item) self.actor:doDrop(self.inven, self.item, function() self.onuse(self.inven, self.item, self.object, false) end) end elseif act == "wear" then - self.actor:doWear(self.inven, self.item, self.object) + self.actor:doWear(self.inven, self.item, self.object, self.dst_actor) self.onuse(self.inven, self.item, self.object, false) elseif act == "takeoff" then - self.actor:doTakeoff(self.inven, self.item, self.object) + self.actor:doTakeoff(self.inven, self.item, self.object, nil, self.dst_actor) self.onuse(self.inven, self.item, self.object, false) elseif act == "transfer" then game:registerDialog(PartySendItem.new(self.actor, self.object, self.inven, self.item, function() @@ -130,13 +131,13 @@ function _M:generateList() local transmo_chest = self.actor:attr("has_transmo") if not self.object:isIdentified() and self.actor:attr("auto_id") and self.actor:attr("auto_id") >= 2 then list[#list+1] = {name="Identify", action="identify"} end - if self.object.__transmo then list[#list+1] = {name="Move to normal inventory", action="toinven"} end - if not self.object.__transmo and not self.no_use_allowed then if self.object:canUseObject() then list[#list+1] = {name="Use", action="use"} end end + if not self.dst_actor and self.object.__transmo then list[#list+1] = {name="Move to normal inventory", action="toinven"} end + if not self.dst_actor and not self.object.__transmo and not self.no_use_allowed then if self.object:canUseObject() then list[#list+1] = {name="Use", action="use"} end end if self.inven == self.actor.INVEN_INVEN and self.object:wornInven() and self.actor:getInven(self.object:wornInven()) then list[#list+1] = {name="Wield/Wear", action="wear"} end if not self.object.__transmo then if self.inven ~= self.actor.INVEN_INVEN and self.object:wornInven() then list[#list+1] = {name="Take off", action="takeoff"} end end - if not self.object.__tagged and self.inven == self.actor.INVEN_INVEN then list[#list+1] = {name="Drop", action="drop"} end - if self.inven == self.actor.INVEN_INVEN and game.party:countInventoryAble() >= 2 then list[#list+1] = {name="Transfer to party", action="transfer"} end - if not self.object.__tagged and self.inven == self.actor.INVEN_INVEN and transmo_chest and self.actor:transmoFilter(self.object) then list[#list+1] = {name=self.actor:transmoGetWord():capitalize().." now", action="transmo"} end + if not self.dst_actor and not self.object.__tagged and self.inven == self.actor.INVEN_INVEN then list[#list+1] = {name="Drop", action="drop"} end + if not self.dst_actor and self.inven == self.actor.INVEN_INVEN and game.party:countInventoryAble() >= 2 then list[#list+1] = {name="Transfer to party", action="transfer"} end + if not self.dst_actor and not self.object.__tagged and self.inven == self.actor.INVEN_INVEN and transmo_chest and self.actor:transmoFilter(self.object) then list[#list+1] = {name=self.actor:transmoGetWord():capitalize().." now", action="transmo"} end if profile.auth and profile.hash_valid then list[#list+1] = {name="Link item in chat", action="chat-link"} end if config.settings.cheat then list[#list+1] = {name="Lua inspect", action="debug-inspect", color=colors.simple(colors.LIGHT_BLUE)} end if not self.object.__tagged then list[#list+1] = {name="Tag", action="tag"} end