Combat:attackTarget & Cancelling Attacks

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Razakai
Uruivellas
Posts: 889
Joined: Tue May 14, 2013 3:45 pm

Combat:attackTarget & Cancelling Attacks

#1 Post by Razakai »

I'm working on some archer tweaks, and duplicated Intuitive Shots while shuffling trees around. I'm trying to replicate the cancellation of attacks from it proccing, but I can't seem to get it to work. Also, Intuitive Shots itself doesn't seem to be cancelling attacks when it procs. Not sure if it's a main game bug or just me breaking stuff. Code below:

Code: Select all

newTalent{
	name = "Intuitive Shots", short_name = "INTUITIVE_SHOTS_RAZ",
	type = {"technique/reflexes_raz", 2},
	mode = "sustained",
	points = 5,
	cooldown = 10,
	sustain_stamina = 30,
	no_energy = true,
	require = techs_dex_req2,
	tactical = { BUFF = 2 },
	getChance = function(self, t) return math.floor(self:combatTalentLimit(t, 50, 5, 40)) end,
	getDamage = function(self, t) return self:combatTalentWeaponDamage(t, 0.4, 0.9) end,
	-- called by _M:attackTarget in mod.class.interface.Combat.lua
	proc = function(self, t, target)
		local weapon, ammo = self:hasArcheryWeapon()
		if not weapon then return end
		if self.turn_procs.intuitive_shots and self.turn_procs.intuitive_shots ~= target then return end
		if self.turn_procs.intuitive_shots == target then return true end
		local targets = self:archeryAcquireTargets(nil, {one_shot=true, x=target.x, y=target.y}) --Ammo check done here
		if not targets then return end 
		self.turn_procs.intuitive_shots = target
		local xatk, ret = 1e6, true
		--Precheck hit chance so a miss doesn't stop the melee attack
		if not self:checkHit(self:combatAttackRanged(weapon, ammo), target:combatDefenseRanged()) or target:checkEvasion(self) then 
			xatk, ret = -1e6, false
		end
		game.logSeen(self, "%s %s the attack!", self.name:capitalize(), ret and "intercepts" or "fails to intercept")
		self:archeryShoot(targets, t, nil, {atk = xatk, mult=self:combatTalentWeaponDamage(t, 0.4, 0.9)})
		return ret
	end,
	on_pre_use = function(self, t, silent) return archerPreUse(self, t, silent) end,
	activate = function(self, t)
		return {}
	end,
	deactivate = function(self, t, p)
		return true
	end,
	info = function(self, t)
		local chance = t.getChance(self,t)
		local dam = t.getDamage(self,t)*100
		return ([[Activating this talent enhances your reflexes to incredible levels.  Each time you are attacked in melee, you have a %d%% chance get a defensive shot off in time to intercept the attack, fully disrupting it (including extra blows from certain talents) and dealing %d%% archery damage.
		This cannot damage the same target more than once per turn.]])
		:format(chance, dam)
	end,
}

Code: Select all

class:bindHook("Combat:attackTarget", function(self, data)
	data.mult = data.mult or 1
	local speed, hit, damtype, mult, target = data.speed, data.hit, data.damtype, data.mult, data.target
	local sound, sound_miss

	if target:isTalentActive(target.T_INTUITIVE_SHOTS_RAZ) and rng.percent(target:callTalent(target.T_INTUITIVE_SHOTS_RAZ, "getChance")) then
		local ret = target:callTalent(target.T_INTUITIVE_SHOTS_RAZ, "proc", self)
		if ret then return false end
	end
	
	data.speed, data.hit, data.damtype, data.mult = speed, hit, damtype, mult
	return data
end)

Post Reply