Talent: Mark a summon to block hits for a single turn

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

Talent: Mark a summon to block hits for a single turn

#1 Post by Razakai »

I have a talent that has a fairly simple concept. If one of your ghouls is active and you take a hit greater than x% of your life, it will absorb x% of damage taken for a single turn (along with some other unimportant details). While getting it to absorb damage from the single hit is easy enough, I can't seem to find a way to make the 'whole turn' part work. My idea was to apply a 1 turn buff similar to the Link of Pain talent that would handle the absorb, but I can't seem to pass in the chosen minion as a value, as it returns an error that blocker is null. Here's the code below, does anyone know either how to fix this or a better way to handle this idea?

Code: Select all

newTalent{
	name = "Meat Shield",
	type = {"spell/undeath", 2},
	require = techs_req2,
	points = 5,
	mode = "passive",
	getLifeTrigger = function(self, t) return self:combatTalentLimit(t, 10, 30, 15)	end,
	getDamageSplit = function(self, t) return self:combatTalentLimit(t, 80, 20, 60)/100 end, -- Limit < 80%
	callbackOnHit = function(self, t, cb, src)
		local split = cb.value * t.getDamageSplit(self, t)

		if self.max_life and not self.turn_procs.ghoulblock then --and cb.value >= self.max_life * (t.getLifeTrigger(self, t)/100) then
			-- Look for space for the ghoul to jump
			local tx, ty = util.findFreeGrid(self.x, self.y, 1, true, {[Map.ACTOR]=true})
			if tx and ty then
			local acts = {}
				for uid, act in pairs(game.level.entities) do
					if act.summoner and act.summoner == self and act.ms then
						acts[#acts+1] = act
					end
				end


			for i = 1, 1 do
				if #acts <= 0 then
				break end
				local m, id = rng.table(acts)
				table.remove(acts, id)
				self.turn_procs.ghoulblock = true
				m.ms = 0
				cb.value = cb.value - (split)
				-- split the damage
--				m:takeHit(split, src)
--				m:setTarget(src or nil)
--				game:delayedLogMessage(self, nil, "ghoul_damage", "#DARK_GREEN##Source# shares damage with %s ghoul!", string.his_her(self))
--				game:delayedLogDamage(src or self, self, 0, ("#DARK_GREEN#(%d shared)#LAST#"):format(split), nil)
				self:setEffect(self.EFF_LIFELINK, 1, {power= t.getDamageSplit(self, t), blocker=m, src=self})
			end

			else
				game.logPlayer(self, "Not enough space for the ghoul to block!")
			end
		end
		
		return cb.value
	end,
	info = function(self, t)
		local trigger = t.getLifeTrigger(self, t)
		local split = t.getDamageSplit(self, t) * 100
		return ([[When a single hit deals more than %d%% of your maximum life one of your ghouls will leap to your side, absorbing %d%% of the damage and all further damage in the same turn.
		This can only occur once per ghoul.]]):format(trigger, split, split, duration)
	end,
}

Code: Select all

newEffect{
	name = "LIFELINK",
	desc = "Lifelink",
	long_desc = function(self, eff) return ("%d%% of all damage you take is taken by a ghoul."):format(eff.power) end,
	type = "magical",
	subtype = { darkness=true },
	status = "beneficial",
	parameters = { power=40 },
	callbackOnHit = function(self, eff, value, src)
		if value.value <= 0 then return end
		if eff.blocker.dead then return end
		
		local split = value.value * eff.power
		
		value.value = value.value - (split)
		-- split the damage
		blocker:takeHit(split, src)
		blocker:setTarget(src or nil)
		game:delayedLogMessage(self, nil, "ghoul_damage", "#DARK_GREEN##Source# shares damage with %s ghoul!", string.his_her(self))
		game:delayedLogDamage(src or self, self, 0, ("#DARK_GREEN#(%d shared)#LAST#"):format(split), nil)
		return value.value

	end,
}

stinkstink
Spiderkin
Posts: 543
Joined: Sat Feb 11, 2012 1:12 am

Re: Talent: Mark a summon to block hits for a single turn

#2 Post by stinkstink »

You're calling blocker:takeHit(split, src) when you should be using eff.blocker:takeHit(split, src) ?

Razakai
Uruivellas
Posts: 889
Joined: Tue May 14, 2013 3:45 pm

Re: Talent: Mark a summon to block hits for a single turn

#3 Post by Razakai »

stinkstink wrote:You're calling blocker:takeHit(split, src) when you should be using eff.blocker:takeHit(split, src) ?
Well, this shows how long a break I took from Tome coding. Duh, thanks!

Post Reply