From a913d23e4631730f30b31d215b8b5c28af39e20a Mon Sep 17 00:00:00 2001 From: m Date: Mon, 23 Sep 2013 11:41:10 +0930 Subject: [PATCH] updated dumb ai to improve its healing and use of talents --- game/engines/default/engine/ai/talented.lua | 64 ++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/game/engines/default/engine/ai/talented.lua b/game/engines/default/engine/ai/talented.lua index 934c706..69e1ada 100644 --- a/game/engines/default/engine/ai/talented.lua +++ b/game/engines/default/engine/ai/talented.lua @@ -25,6 +25,21 @@ newAI("dumb_talented", function(self) local avail = {} local tx, ty = self:aiSeeTargetPos(self.ai_target.actor) local target_dist = core.fov.distance(self.x, self.y, tx, ty) + local canAttack = 0 + local canShoot = 0 + local canHeal = 0 + local healing_talents = {} + healing_talents["Infusion: Regeneration"] = true + healing_talents["Infusion: Wild"] = true + healing_talents["Conversion"] = true + healing_talents["Infusion: Heroism"] = true + healing_talents["Skeleton Reassemble"] = true + healing_talents["Infusion: Healing"] = true + healing_talents["Sudden Growth"] = true + healing_talents["Providence"] = true + healing_talents["Nature's Pride"] = true + healing_talents["Leaves Tide"] = true + healing_talents["Nourishing Moss"] = true for tid, _ in pairs(self.talents) do local t = self:getTalentFromId(tid) -- print(self.name, self.uid, "dumb ai talents can try use", t.name, tid, "::", t.mode, not self:isTalentCoolingDown(t), target_dist <= self:getTalentRange(t), self:preUseTalent(t, true), self:canProject({type="bolt"}, self.ai_target.actor.x, self.ai_target.actor.y)) @@ -36,8 +51,34 @@ newAI("dumb_talented", function(self) not self:isTalentCoolingDown(t) and self:preUseTalent(t, true, true) and (not self:getTalentRequiresTarget(t) or self:canProject(tg, tx, ty)) then - avail[#avail+1] = tid - print(self.name, self.uid, "dumb ai talents can use", t.name, tid) + +-- JENX ADDED: only use regen infusion or healing if life < 80% max life. 80% scales down by max life / 100, so at 2000 hp, it is < 60% etc. +-- JENX ADDED: ai ALWAYS uses a helaing talent if it is available + if healing_talents[t.name] then + local life = 100 * self.life / self.max_life + if life < (80 - self.max_life / 100) then + avail[#avail+1] = tid + print(self.name, self.uid, "dumb ai talents can use", t.name, tid) + canHeal = #avail + end + elseif t.name == "Reload" then + local a = self:hasAmmo() + if a then + if a.combat.shots_left == 0 then + avail[#avail+1] = tid + print(self.name, self.uid, "dumb ai talents can use", t.name, tid) + end + end + else + avail[#avail+1] = tid + print(self.name, self.uid, "dumb ai talents can use", t.name, tid) + if t.name == "Attack" then + canAttack = #avail + end + if t.name == "Shoot" then + canShoot = #avail + end + end elseif t.mode == "sustained" and not t.no_npc_use and not self:isTalentCoolingDown(t) and not self:isTalentActive(t.id) and self:preUseTalent(t, true, true) @@ -46,6 +87,25 @@ newAI("dumb_talented", function(self) print(self.name, self.uid, "dumb ai talents can activate", t.name, tid) end end + + if canHeal > 0 then + local tid = avail[canHeal] + print("dumb ai uses", tid) +-- print(self.name, self.uid, "Healing talent forced use <<<<<<<<<<<<", canHeal) + self:useTalent(tid) + return true + end + +-- JENX ADDED - if more than one talent and attack or shoot is available, do the talent rather than attack + if #avail > 1 and canAttack > 0 then + table.remove(avail,canAttack) + end + + if #avail > 1 and canShoot > 0 then + table.remove(avail,canShoot) + end +--JENX end + if #avail > 0 then local tid = avail[rng.range(1, #avail)] print("dumb ai uses", tid) -- 1.8.4.msysgit.0