Page 1 of 1

Modifying damage based on presence of a map effect

Posted: Sat Aug 01, 2015 12:44 pm
by Razakai
I have a talent that has a similar effect to to Cursed/Darkness, e.g. creates a damaging field effect which also causes your attacks to deal additional damage among other things to those within. I can't seem to actually get the bonus damage to apply though. Is this the right way to do it, and would it also be possible to grant resist penetration via the same method?

Code snippet from the talent that creates the dark cloud, for now I've just set the damage boost to 100% for testing:

Code: Select all

	createDark = function(summoner, x, y, damage, duration)
		local e = Object.new{
			name = summoner.name:capitalize() .. "'s dark cloud",
			canAct = false,
			x = x, y = y,
			damage = damage,
			originalDuration = duration,
			duration = duration,
			summoner = summoner,
			summoner_gain_exp = true,
			damageIncrease = 100,
			act = function(self)
				local Map = require "engine.Map"

				self:useEnergy()

				-- apply damage to anything inside the darkness
				local actor = game.level.map(self.x, self.y, Map.ACTOR)
				if actor and actor ~= self.summoner and (not actor.summoner or actor.summoner ~= self.summoner) then
					self.projecting = true
					self.summoner.__project_source = self
					self.summoner:project({type="hit", range=10, talent=self.summoner:getTalentFromId(self.summoner.T_ENSHROUD)}, actor.x, actor.y, engine.DamageType.DARKNESS, self.damage)
					self.summoner.__project_source = nil
					self.projecting = false
				end

				if self.duration <= 0 then
					-- remove
					if self.particles then game.level.map:removeParticleEmitter(self.particles) end
					game.level.map:remove(self.x, self.y, Map.TERRAIN+3)
					game.level:removeEntity(self, true)
					self.darkCloud = nil
					game.level.map:scheduleRedisplay()
				else
					self.duration = self.duration - 1

					local tDarkCloud = self.summoner:getTalentFromId(self.summoner.T_ENSHROUD)

				end
			end,
		}
		e.darkCloud = e -- used for checkAllEntities to return the dark Object itself
		game.level:addEntity(e)
		game.level.map(x, y, Map.TERRAIN+3, e)

		-- add particles
		e.particles = Particles.new("creeping_dark", 1, { })
		e.particles.x = x
		e.particles.y = y
		game.level.map:addParticleEmitter(e.particles)

	end,
	activate = function(self, t)
		local ret = {}
		self:talentTemporaryValue(ret, "combat_physcrit", t.getCrit(self, t))
		self:talentTemporaryValue(ret, "combat_spellcrit", t.getCrit(self, t))
		self:talentTemporaryValue(ret, "combat_apr", t.getDamageIncrease(self, t))
		self:talentTemporaryValue(ret, "inc_damage", {[DamageType.DARKNESS] = t.getDamageIncrease(self, t)})
		return ret
	end,
	deactivate = function(self, t, p)
		return true
	end,
	callbackOnCrit = function(self, t, kind, dam, chance, target)
		if not self:hasTwoHandedWeapon() then return end
		if not target then return end
		if self.turn_procs.enshroud then return end
		self.turn_procs.enshroud = true
		t.createDark(self, target.x, target.y, t.getDamage(self,t), 5)
	end,
Code in load.lua:

Code: Select all

class:bindHook("DamageProjector:final", function(self, data)
	local target = game.level.map(data.x, data.y, Map.ACTOR)
	local source_talent = data.src.__projecting_for and data.src.__projecting_for.project_type and (data.src.__projecting_for.project_type.talent_id or data.src.__projecting_for.project_type.talent) and data.src.getTalentFromId and data.src:getTalentFromId(data.src.__projecting_for.project_type.talent or data.src.__projecting_for.project_type.talent_id)

	if not target then return end

...
	
	if data.src and data.src ~= target and game.level.map:checkAllEntities(x, y, "darkCloud") then
			local dark = game.level.map:checkAllEntities(x, y, "darkCloud")
			if dark.summoner == data.src and dark.damageIncrease > 0 then
				local source = data.src.__project_source or data.src
				inc = inc + dark.damageIncrease
				data.dam = data.dam + (data.dam * inc / 100)
			end
	end
	
	return data
end)
I'm probably missing something very obvious!

Re: Modifying damage based on presence of a map effect

Posted: Sat Aug 01, 2015 9:51 pm
by stinkstink
Dunno about the Afflicted-based code, but if you're looking for an alternate approach you may want to try something zone effect based, similar to Path of Light (check Actor.lua for "walk_sun_path" to see how to detect if a location is in a given zone effect) or the Boreal Arts tree in my Stoic addon.

Re: Modifying damage based on presence of a map effect

Posted: Sun Aug 02, 2015 11:15 am
by HousePet
Wouldn't it be easier to apply a status effect to afflicted targets?

Re: Modifying damage based on presence of a map effect

Posted: Tue Aug 04, 2015 8:26 am
by Razakai
I think applying a one turn status effect will sort out my problems, as it's very easy to say 'if target is affected by x do y' rather than checking map effects. Although I do have a talent that's effectively a passive, weaker Hoarfrost Blade so I might take a look at the Stoic code to see if my implementation can be made better.

Thanks for the help.