From ddfb110472c3682fa4f4f046e45799740670dd38 Mon Sep 17 00:00:00 2001 From: Hachem_Muche <Hachem_Muche@stanfordalumni.org> Date: Thu, 8 Dec 2016 18:15:29 -0800 Subject: [PATCH] Removed keybinding and Map Menu command to disarm traps. Added a new talent "Disarm Trap" automatically learned with Heightened Senses at TL 3. This allows for actively disarming traps without moving over them, with the normal chance of triggering. Automatic trap detection will not trigger on forced moves. --- game/modules/tome/class/Actor.lua | 2 +- game/modules/tome/class/Game.lua | 3 - game/modules/tome/class/Player.lua | 45 -------------- game/modules/tome/data/keybinds/tome.lua | 7 --- .../tome/data/talents/cunning/survival.lua | 58 +++++++++++++++++++ game/modules/tome/dialogs/MapMenu.lua | 3 - 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index 121cee5d6d..a1b5182e03 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -1324,7 +1324,7 @@ function _M:move(x, y, force) self.did_energy = nil -- Try to detect traps - if self:knowTalent(self.T_HEIGHTENED_SENSES) then + if not force and self:knowTalent(self.T_HEIGHTENED_SENSES) then local power = self:callTalent(self.T_HEIGHTENED_SENSES,"trapPower") local grids = core.fov.circle_grids(self.x, self.y, 1, true) for x, yy in pairs(grids) do for y, _ in pairs(yy) do diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua index 5e425e7804..5b749f1954 100644 --- a/game/modules/tome/class/Game.lua +++ b/game/modules/tome/class/Game.lua @@ -2000,9 +2000,6 @@ do return end REST = function() self.player:restInit() end, - DISARM_TRAP = function() - self.player:playerDisarmTrap() - end, PICKUP_FLOOR = not_wild(function() if self.player.no_inventory_access then return end self.player:playerPickup() diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua index 0433618017..bc745f0119 100644 --- a/game/modules/tome/class/Player.lua +++ b/game/modules/tome/class/Player.lua @@ -1248,51 +1248,6 @@ function _M:hotkeyInventory(name) end end ---- Player specifically requests disarming a trap -function _M:playerDisarmTrap(tx, ty) - if self:attr("sleep") and not self:attr("lucid_dreamer") then - game.log("You can not disarm traps while asleep!") return - elseif self:getTalentLevel(self.T_HEIGHTENED_SENSES) < 3 and not self:attr("can_disarm") then - game.log("You don't know how to disarm traps!") return - end - core.mouse.set(game.level.map:getTileToScreen(self.x, self.y, true)) - local function do_disarm(x, y) - if x and y then - local dir = util.getDir(x, y, self.x, self.y) - x, y = util.coordAddDir(self.x, self.y, dir) - print("Disarm trap command", x, y) - if (x == self.x and y == self.y) or self:canMove(x, y) then - local trap = self:detectTrap(nil, x, y) - if trap then - print("Attempting to disarm trap", trap.name, x, y) - game.log("#CADET_BLUE#You attempt to disarm a trap (%s).", trap:getName()) - local px, py = self.x, self.y - self:move(x, y, true) -- temporarily move the player to make sure trap can trigger properly - -- attempt to disarm the trap, may trigger it - trap:trigger(self.x, self.y, self) -- try to disarm, or trigger the trap - if not self.dead then self:move(px, py, true) end - else - game.log("#CADET_BLUE#You don't see a trap there.") - end - self:useEnergy() - else - game.log("#CADET_BLUE#You cannot disarm traps in grids you cannot enter.") - end - end - end - if tx and ty then - do_disarm(tx, ty) - else - local co = coroutine.create(function() - game.log("Disarm A Trap: (direction keys to select where to disarm, shift+direction keys to move freely)") - local x, y, dir = self:getTarget({type="hit", range=1, nowarning=true, immediate_keys=true, no_lock=false}) - do_disarm(x, y) - end) - local ok, err = coroutine.resume(co) - if not ok and err then print(debug.traceback(co)) error(err) end - 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 diff --git a/game/modules/tome/data/keybinds/tome.lua b/game/modules/tome/data/keybinds/tome.lua index 4f1bbed67e..a70d12d3fa 100644 --- a/game/modules/tome/data/keybinds/tome.lua +++ b/game/modules/tome/data/keybinds/tome.lua @@ -31,13 +31,6 @@ defineAction{ name = "Show character sheet (actor @ cursor)", } -defineAction{ - default = { "sym:=d:false:true:false:false" }, - type = "DISARM_TRAP", - group = "actions", - name = "Disarm a trap", -} - defineAction{ default = { "sym:_TAB:true:false:false:false" }, type = "SWITCH_PARTY", diff --git a/game/modules/tome/data/talents/cunning/survival.lua b/game/modules/tome/data/talents/cunning/survival.lua index 5e8bffdca6..3cad0d8de5 100644 --- a/game/modules/tome/data/talents/cunning/survival.lua +++ b/game/modules/tome/data/talents/cunning/survival.lua @@ -28,6 +28,16 @@ newTalent{ passives = function(self, t, p) self:talentTemporaryValue(p, "heightened_senses", t.sense(self, t)) end, + on_learn = function(self, t) + if self:getTalentLevel(t) >= 3 and not self:knowTalent(self.T_DISARM_TRAP) then + self:learnTalent(self.T_DISARM_TRAP, true, 1) + end + end, + on_unlearn = function(self, t) + if self:getTalentLevel(t) < 3 and self:knowTalent(self.T_DISARM_TRAP) then + self:unlearnTalent(self.T_DISARM_TRAP, 1) + end + end, info = function(self, t) return ([[You notice the small things others do not notice, allowing you to "see" creatures in a %d radius even outside of light radius. This is not telepathy, however, and it is still limited to line of sight. @@ -38,6 +48,54 @@ newTalent{ end, } +newTalent{ + name = "Disarm Trap", + type = {"base/class", 1}, + no_npc_use = true, + innate = true, + points = 1, + range = 1, + message = false, + image = "talents/trap_priming.png", + target = {type="hit", range=1, nowarning=true, immediate_keys=true, no_lock=false}, + action = function(self, t) + if self.player then + core.mouse.set(game.level.map:getTileToScreen(self.x, self.y, true)) + game.log("#CADET_BLUE#Disarm A Trap: (direction keys to select where to disarm, shift+direction keys to move freely)") + end + local tg = self:getTalentTarget(t) + local x, y, dir = self:getTarget(tg) + if not (x and y) then return end + + dir = util.getDir(x, y, self.x, self.y) + x, y = util.coordAddDir(self.x, self.y, dir) + print("Requesting disarm trap", self.name, t.id, x, y) + local trap = self:detectTrap(nil, x, y) + if trap then + print("Found trap", trap.name, x, y) + if (x == self.x and y == self.y) or self:canMove(x, y) then + local px, py = self.x, self.y + self:move(x, y, true) -- temporarily move to make sure trap can trigger properly + trap:trigger(self.x, self.y, self) -- then attempt to disarm the trap, which may trigger it + self:move(px, py, true) + else + game.logPlayer(self, "#CADET_BLUE#You cannot disarm traps in grids you cannot enter.") + end + else + game.logPlayer(self, "#CADET_BLUE#You don't see a trap there.") + end + + return true + end, + info = function(self, t) + local ths = self:getTalentFromId(self.T_HEIGHTENED_SENSES) + local power = ths.trapPower(self,ths) + return ([[You search an adjacent grid for a hidden trap (%d detection 'power') and attempt to disarm it (%d disarm 'power'). + To disarm a trap, you must be able to enter its grid to manipulate it, even though you stay in your current location. + Success depends on your skill in the %s talent and your Cunning, and failing to disarm a trap may trigger it.]]):format(power, power + (self:attr("disarm_bonus") or 0), ths.name) + end, +} + newTalent{ name = "Charm Mastery", type = {"cunning/survival", 2}, diff --git a/game/modules/tome/dialogs/MapMenu.lua b/game/modules/tome/dialogs/MapMenu.lua index ff92ff66ef..8182d087f2 100644 --- a/game/modules/tome/dialogs/MapMenu.lua +++ b/game/modules/tome/dialogs/MapMenu.lua @@ -75,7 +75,6 @@ function _M:use(item) elseif act == "change_level" then game.key:triggerVirtual("CHANGE_LEVEL") elseif act == "pickup" then game.key:triggerVirtual("PICKUP_FLOOR") elseif act == "character_sheet" then game:registerDialog(require("mod.dialogs.CharacterSheet").new(item.actor)) - elseif act == "disarm_trap" then game.player:playerDisarmTrap(self.tmx, self.tmy) elseif act == "quests" then game.key:triggerVirtual("SHOW_QUESTS") elseif act == "levelup" then game.key:triggerVirtual("LEVELUP") elseif act == "inventory" then game.key:triggerVirtual("SHOW_INVENTORY") @@ -153,8 +152,6 @@ function _M:generateList() if self.on_player then list[#list+1] = {name="Inventory", action="inventory", color=colors.simple(colors.ANTIQUE_WHITE)} end if self.on_player then list[#list+1] = {name="Quest Log", action="quests", color=colors.simple(colors.ANTIQUE_WHITE)} end if a then list[#list+1] = {name="Inspect Creature", action="character_sheet", color=colors.simple(colors.ANTIQUE_WHITE), actor=a} end - -- check distance? - if core.fov.distance(self.tmx, self.tmy, player.x, player.y) <= 1 and player:getTalentLevel(player.T_HEIGHTENED_SENSES) >= 3 or player:attr("can_disarm") then list[#list+1] = {name="Find/Disarm Trap", action="disarm_trap", color=colors.simple(colors.ANTIQUE_WHITE), actor=t} end -- can add extended inspection commands here by including the start tab with the dialog -- space separating inspect from active actions list[#list+1] = {name=" ", action=nil, color=colors.simple(colors.ANTIQUE_WHITE)} -- GitLab