From 18397fa306f403a7d84a30ef8cb760a6d281f72f Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Mon, 6 Jun 2011 07:37:53 +0000 Subject: [PATCH] New feature: automatic talents. Any talents can be setup to automatic cast, which means they will be used as soon as off cooldown. THe UI will warn you if the talent requires a turn or a target. Check out the 'm' menu or right click on the hotkeys list to configure git-svn-id: http://svn.net-core.org/repos/t-engine4@3597 51575b47-30f0-44d4-a5cc-537603b46e54 --- .../engines/default/engine/HotkeysDisplay.lua | 5 ++- game/modules/tome/class/Actor.lua | 31 +++++++++++++++++++ game/modules/tome/class/Game.lua | 15 ++++++++- game/modules/tome/class/Player.lua | 6 +++- .../tome/data/talents/misc/inscriptions.lua | 1 + game/modules/tome/dialogs/UseTalents.lua | 14 ++++----- 6 files changed, 61 insertions(+), 11 deletions(-) diff --git a/game/engines/default/engine/HotkeysDisplay.lua b/game/engines/default/engine/HotkeysDisplay.lua index e6102f0bcd..4aa713b32f 100644 --- a/game/engines/default/engine/HotkeysDisplay.lua +++ b/game/engines/default/engine/HotkeysDisplay.lua @@ -159,7 +159,7 @@ end --- Call when a mouse event arrives in this zone -- This is optional, only if you need mouse support -function _M:onMouse(button, mx, my, click, on_over) +function _M:onMouse(button, mx, my, click, on_over, on_click) local a = self.actor if button == "wheelup" and click then @@ -173,6 +173,9 @@ function _M:onMouse(button, mx, my, click, on_over) mx, my = mx - self.display_x, my - self.display_y for i, zone in pairs(self.clics) do if mx >= zone[1] and mx < zone[1] + zone[3] and my >= zone[2] and my < zone[2] + zone[4] then + if on_click and click then + if on_click(i, a.hotkey[i]) then click = false end + end if button == "left" and click then a:activateHotkey(i) elseif button == "right" and click then diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index d51f000edd..014add0e35 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -35,6 +35,7 @@ require "mod.class.interface.Combat" require "mod.class.interface.Archery" require "mod.class.interface.ActorInscriptions" local Faction = require "engine.Faction" +local Dialog = require "engine.ui.Dialog" local Map = require "engine.Map" local DamageType = require "engine.DamageType" @@ -420,6 +421,9 @@ function _M:act() end end + -- Still enough energy to act ? + if self.energy.value < game.energy_to_act then return false end + return true end @@ -2329,6 +2333,33 @@ function _M:startTalentCooldown(t) self.changed = true end +--- Setups a talent automatic use +function _M:checkSetTalentAuto(tid, v) + local t = self:getTalentFromId(tid) + if v then + local doit = function() + self:setTalentAuto(tid, true) + Dialog:simplePopup("Automatic use enabled", t.name:capitalize().." will now be used as often as possible automatically.") + end + + local list = {} + if t.no_energy ~= true then list[#list+1] = "- requires a turn to use" end + if t.requires_target then list[#list+1] = "- requires a target, your last hostile one will be automatically used" end + if t.auto_use_warning then list[#list+1] = t.auto_use_warning end + + if #list == 0 then + doit() + else + Dialog:yesnoLongPopup("Automatic use", t.name:capitalize()..":\n"..table.concat(list, "\n").."\n Are you sure?", 500, function(ret) + if ret then doit() end + end) + end + else + self:setTalentAuto(tid, false) + Dialog:simplePopup("Automatic use disabled", t.name:capitalize().." will not be automatically used.") + end +end + --- How much experience is this actor worth -- @param target to whom is the exp rewarded -- @return the experience rewarded diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua index 7c15873a28..17ce00e48c 100644 --- a/game/modules/tome/class/Game.lua +++ b/game/modules/tome/class/Game.lua @@ -1267,7 +1267,20 @@ function _M:setupMouse(reset) -- Use hotkeys with mouse self.mouse:registerZone(self.hotkeys_display.display_x, self.hotkeys_display.display_y, self.w, self.h, function(button, mx, my, xrel, yrel, bx, by, event) if event == "button" and button == "left" and self.zone and self.zone.wilderness then return end - self.hotkeys_display:onMouse(button, mx, my, event == "button", function(text) self.tooltip:displayAtMap(nil, nil, self.w, self.h, text) end) + self.hotkeys_display:onMouse(button, mx, my, event == "button", + function(text) + text = text:toTString() + text:add(true, "---", true, {"font","italic"}, {"color","GOLD"}, "Left click to use", true, "Right click to configure", true, "Press 'm' to setup", {"color","LAST"}, {"font","normal"}) + self.tooltip:displayAtMap(nil, nil, self.w, self.h, text) + end, + function(i, hk) + if button == "right" and hk[1] == "talent" then + local d = require("mod.dialogs.UseTalents").new(self.player) + d:use({talent=hk[2], name=self.player:getTalentFromId(hk[2]).name}, "right") + return true + end + end + ) end) -- Use icons self.mouse:registerZone(self.icons.display_x, self.icons.display_y, self.icons.w, self.icons.h, function(button, mx, my, xrel, yrel, bx, by) diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua index 5e787b7231..5e71ed3b4e 100644 --- a/game/modules/tome/class/Player.lua +++ b/game/modules/tome/class/Player.lua @@ -523,7 +523,11 @@ function _M:restCheck() if self.resting.wait_cooldowns then for tid, cd in pairs(self.talents_cd) do - if not self:isTalentActive(self.T_CONDUIT) or (tid ~= self.T_KINETIC_AURA and tid ~= self.T_CHARGED_AURA and tid ~= self.T_THERMAL_AURA) then + if self:isTalentActive(self.T_CONDUIT) and (tid == self.T_KINETIC_AURA or tid == self.T_CHARGED_AURA or tid == self.T_THERMAL_AURA) then + -- nothing + elseif self.talents_auto[tid] then + -- nothing + else if cd > 0 then return true end end end diff --git a/game/modules/tome/data/talents/misc/inscriptions.lua b/game/modules/tome/data/talents/misc/inscriptions.lua index d2e4d03d43..5f2914a821 100644 --- a/game/modules/tome/data/talents/misc/inscriptions.lua +++ b/game/modules/tome/data/talents/misc/inscriptions.lua @@ -37,6 +37,7 @@ local newInscription = function(t) elseif tt.type[1] == "inscriptions/runes" then tt.auto_use_check = function(self, t) return not self:hasEffect(self.EFF_RUNE_COOLDOWN) end elseif tt.type[1] == "inscriptions/taints" then tt.auto_use_check = function(self, t) return not self:hasEffect(self.EFF_TAINT_COOLDOWN) end end + tt.auto_use_warning = "- will only auto use when no saturation effect exists" tt.cooldown = function(self, t) local data = self:getInscriptionData(t.short_name) return data.cooldown diff --git a/game/modules/tome/dialogs/UseTalents.lua b/game/modules/tome/dialogs/UseTalents.lua index d980c07e47..02135d16b8 100644 --- a/game/modules/tome/dialogs/UseTalents.lua +++ b/game/modules/tome/dialogs/UseTalents.lua @@ -35,6 +35,7 @@ function _M:init(actor) self.c_tut = Textzone.new{width=math.floor(self.iw / 2 - 10), height=1, auto_height=true, no_color_bleed=true, text=[[ You can bind a talent to a hotkey by pressing the corresponding hotkey while selecting a talent or by right-clicking on the talent. Check out the keybinding screen in the game menu to bind hotkeys to a key (default is 1-0 plus control or shift). +Right click or press '*' to configure. ]]} self.c_desc = TextzoneList.new{width=math.floor(self.iw / 2 - 10), height=self.ih - self.c_tut.h - 20, scrollbar=true, no_color_bleed=true} @@ -67,6 +68,7 @@ Check out the keybinding screen in the game menu to bind hotkeys to a key (defau self:use(self.list.chars[c]) end end, + _ASTERISK = function() self:use(self.cur_item, "right") end, } self.key:addBinds{ HOTKEY_1 = function() self:defineHotkey(1) end, @@ -142,10 +144,8 @@ function _M:use(item, button) } local t = self.actor:getTalentFromId(item.talent) - if t.allow_autocast then - if self.actor:isTalentAuto(t) then table.insert(list, 1, {name="Disable automatic use", what="auto-dis"}) - else table.insert(list, 1, {name="Enable automatic use", what="auto-en"}) - end + if self.actor:isTalentAuto(t) then table.insert(list, 1, {name="Disable automatic use", what="auto-dis"}) + else table.insert(list, 1, {name="Enable automatic use", what="auto-en"}) end for i = 1, 36 do list[#list+1] = {name="Hotkey "..i, what=i} end @@ -170,11 +170,9 @@ function _M:use(item, button) if self.actor.hotkey[i] and self.actor.hotkey[i][1] == "talent" and self.actor.hotkey[i][2] == item.talent then self.actor.hotkey[i] = nil end end elseif b.what == "auto-en" then - self.actor:setTalentAuto(item.talent, true) - self:simplePopup("Automatic use enabled", self.actor:getTalentFromId(item.talent).name:capitalize().." will now be used as often as possible automatically.") + self.actor:checkSetTalentAuto(item.talent, true) elseif b.what == "auto-dis" then - self.actor:setTalentAuto(item.talent, false) - self:simplePopup("Automatic use disabled", self.actor:getTalentFromId(item.talent).name:capitalize().." will not be used automatically.") + self.actor:checkSetTalentAuto(item.talent, false) end self.c_list:drawTree() self.actor.changed = true -- GitLab