Page 1 of 1

Triggering projectiles from a non-player source

Posted: Sun Jul 27, 2014 6:47 pm
by Razakai
I have a spell where the design is intended to fire a slow moving orb, and each turn the orb will in turn fire out multiple projectiles. Currently it almost works, but the projectiles originate from the player, rather than the orb itself. Is this possible to do? I've included my draft code below.

Code: Select all

newTalent{
	name = "Cold Flames", short_name = "COLD_FLAMES_2",
	type = {"spell/grave",3},
	require = spells_req3,
	points = 5,
	random_ego = "attack",
	mana = 18,
	cooldown = 6,
	tactical = { ATTACKAREA = { COLD = 2 } },
	range = 10,
	proj_speed = 2,
	getDamage = function(self, t) return self:combatTalentSpellDamage(t, 12, 100) end,
	on_learn = function(self, t)
		self:learnTalent(self.T_COLD_FLAMES_DETONATE, nil, nil, {no_unlearn=true})
	end,
 	on_unlearn = function(self, t)
		self:unlearnTalent(self.T_COLD_FLAMES_DETONATE)
 	end,
	action = function(self, t)
		local tg = {type="beam", range=self:getTalentRange(t), talent=t, display={particle="bolt_ice"}}
		local x, y = self:getTarget(tg)
		if not x or not y then return nil end
		local _ _, x, y = self:canProject(tg, x, y)
		local dam = self:spellCrit(t.getDamage(self,t))
		self:projectile(tg, x, y, function(px, py, tg, self)
			name = "Frozen Orb"
			local tgts = {}
			local grids = core.fov.circle_grids(self.x, self.y, self:getTalentRange(t), true)
			for x, yy in pairs(grids) do for y, _ in pairs(grids[x]) do
			local a = game.level.map(x, y, Map.ACTOR)
			if a and self:reactionToward(a) < 0 then
				tgts[#tgts+1] = a
			end
			end end
			

			local tg = {type="bolt", range=self:getTalentRange(t), talent=t, friendlyfire=false, display={particle="bolt_ice"}}
			for i = 1, 5 do
			if #tgts <= 0 then break end
			local a, id = rng.table(tgts)
			table.remove(tgts, id)

			self:projectile(table.clone(tg), a.x, a.y, DamageType.COLD, self:spellCrit(t.getDamage(self, t)), {type="freeze"})
			end			
		end)
		return true
	end,
	info = function(self, t)
	local dam = t.getDamage(self, t)
		return ([[Conjure a sphere of cold fire that slowly drifts outwards, dealing %0.2f cold damage to adjacent targets each turn. While the sphere is active, you gain the ability to detonate it.
		The damage will increase with your Spellpower.]]):format(damDesc(self, DamageType.COLD, dam))
	end,
}

Re: Triggering projectiles from a non-player source

Posted: Sun Jul 27, 2014 6:53 pm
by edge2054
the target table can accept start_x, start_y parameters

Here's an example from a talent I did recently,

Code: Select all

{type="cone", range=0, radius=self:getTalentRadius(t), start_x=a.x, start_y=a.y, selffire=false, talent=t}
Hopefully that will help :)

Re: Triggering projectiles from a non-player source

Posted: Sun Jul 27, 2014 6:54 pm
by grayswandir
Try this for the tg in the middle.

Code: Select all

local tg = {type="bolt", range=self:getTalentRange(t), talent=t, friendlyfire=false, display={particle="bolt_ice"}, start_x = px, start_y = py,}

Re: Triggering projectiles from a non-player source

Posted: Sun Jul 27, 2014 7:04 pm
by Razakai
Awesome, that line did exactly what I wanted. Thanks guys.