[1.0.4] tactical ai never uses Mindlash...
Posted: Mon Sep 02, 2013 12:09 pm
...but I can't figure out why. I only know that my tactical addon ai spits out to the log every talent that is available *and* can be used. Mindlash is available, but can't be used, because it never retrieves a tactic from the talent.
The problem is that this code from tactical.lua:
never returns a tactic from the talent:
The problem is that this code from tactical.lua:
Code: Select all
if t_avail then
-- Project the talent if possible, counting foes and allies hit
local foes_hit = {}
local allies_hit = {}
local self_hit = {}
local typ = engine.Target:getType(tg or default_tg)
if tg or self:getTalentRequiresTarget(t) then
local target_actor = self.ai_target.actor or self
self:project(typ, ax, ay, function(px, py)
local act = game.level.map(px, py, engine.Map.ACTOR)
if act and not act.dead then
if self:reactionToward(act) < 0 then
print("[DEBUG] hit a foe!")
foes_hit[#foes_hit+1] = act
elseif (typ.selffire) and (act == self) then
print("[DEBUG] hit self!")
self_hit[#self_hit+1] = act
elseif typ.friendlyfire then
print("[DEBUG] hit an ally!")
allies_hit[#allies_hit+1] = act
end
end
end)
end
-- Evaluate the tactical weights and weight functions
for tact, val in pairs(t.tactical) do
if type(val) == "function" then val = val(self, t, self.ai_target.actor) or 0 end
-- Handle damage_types and resistances
local nb_foes_hit, nb_allies_hit, nb_self_hit = 0, 0, 0
if type(val) == "table" then
for damtype, damweight in pairs(val) do
-- Allows a shortcut to just say FIRE instead of DamageType.FIRE in talent's tactical table
damtype = DamageType[damtype] or damtype
-- Checks a weapon's damtype
if damtype == "weapon" then
damtype = (weapon and weapon.damtype) or DamageType.PHYSICAL
end
local pen = 0
if self.resists_pen then pen = (self.resists_pen.all or 0) + (self.resists_pen[damtype] or 0) end
local check_resistance = function(actor_list)
local weighted_sum = 0
for i, act in ipairs(actor_list) do
local res = math.min((act.resists.all or 0) + (act.resists[damtype] or 0), (act.resists_cap.all or 0) + (act.resists_cap[damtype] or 0))
res = res * (100 - pen) / 100
local damweight = damweight
if type(damweight) == "function" then damweight = damweight(self, t, act) or 0 end
-- Handles status effect immunity
damweight = damweight * (act:canBe(damtype) and 1 or 0)
weighted_sum = weighted_sum + damweight * (100 - res) / 100
end
return weighted_sum
end
nb_foes_hit = check_resistance(foes_hit)
nb_self_hit = check_resistance(self_hit)
nb_allies_hit = check_resistance(allies_hit)
end
val = 1
-- Or assume no resistances
else
nb_foes_hit = #foes_hit
nb_self_hit = #self_hit
nb_allies_hit = #allies_hit
end
-- Apply the selffire and friendlyfire options
nb_self_hit = nb_self_hit * (type(typ.selffire) == "number" and typ.selffire / 100 or 1)
nb_allies_hit = nb_allies_hit * (type(typ.friendlyfire) == "number" and typ.friendlyfire / 100 or 1)
-- Use the player set ai_talents weights
val = val * (self.ai_talents and self.ai_talents[t.id] or 1) * (1 + lvl / 5)
-- Update the weight by the dummy projection data
-- Also force scaling if the talent requires a target (stand-in for canProject)
if self:getTalentRequiresTarget(t) or nb_foes_hit > 0 or nb_allies_hit > 0 or nb_self_hit > 0 then
val = val * (nb_foes_hit - ally_compassion * nb_allies_hit - self_compassion * nb_self_hit)
end
-- Only take values greater than 0... allows the ai_talents to turn talents off
if val > 0 and not self:hasEffect(self.EFF_RELOADING) then
if not avail[tact] then avail[tact] = {} end
-- Save the tactic, if the talent is instant it gets a huge bonus
-- Note the addition of a less than one random value, this means the sorting will randomly shift equal values
val = ((t.no_energy==true) and val * 10 or val) + rng.float(0, 0.9)
avail[tact][#avail[tact]+1] = {val=val, tid=tid, nb_foes_hit=nb_foes_hit, nb_allies_hit=nb_allies_hit, nb_self_hit=nb_self_hit}
print(self.name, self.uid, "tactical ai talents can use", t.name, tid, tact, "weight", val)
ok = true
end
end
Code: Select all
newTalent{
name = "Mindlash",
type = {"psionic/focus", 1},
require = psi_wil_req1,
points = 5,
random_ego = "attack",
cooldown = function(self, t)
local c = 5
local gem_level = getGemLevel(self)
return math.max(c - gem_level, 0)
end,
psi = 10,
tactical = { ATTACK = function(self, t, target)
local val = { PHYSICAL = 2}
local gem_level = getGemLevel(self)
if gem_level > 0 and not target.dead and self:knowTalent(self.T_CONDUIT) and self:isTalentActive(self.T_CONDUIT) then
local c = self:getTalentFromId(self.T_CONDUIT)
local auras = self:isTalentActive(c.id)
if auras.k_aura_on then
val.PHYSICAL = val.PHYSICAL + 1
end
if auras.t_aura_on then
val.FIRE = 1
end
if auras.c_aura_on then
val.LIGHTNING = 1
end
return val
end
return 0
end },