Page 1 of 1

Altering projectile particles mid-flight

Posted: Tue May 12, 2015 12:58 am
by stinkstink
I've been working on a talent that causes projectiles to bounce off the user, and I've got it working with one minor issue - projectiles that use a tile as their graphic (arrows, earthen missiles and the like) don't have their facing updated, so they fly backwards toward the attacker, which makes it difficult to tell the difference between incoming and outgoing attacks. Is there a way to update the rotation of a projectile's graphic after it's been reflected? I've tried messing around with the projectile.__particles table a bit but haven't had any success.

Re: Altering projectile particles mid-flight

Posted: Tue May 12, 2015 4:30 am
by HousePet
Despite having talents which redirect projectiles, I hadn't noticed any backwards flying arrows, so I don't know.

Re: Altering projectile particles mid-flight

Posted: Tue May 12, 2015 5:03 am
by stinkstink
I'm not talking about the built-in projectile_evasion attribute, which hijacks the target as it's fired, but a talent that causes projectiles that strike the user to be reflected. Maybe I should post the code, from superload\engine\interface\ActorProject.lua

Code: Select all

local base_projectDoMove = _M.projectDoMove
function _M:projectDoMove(typ, tgtx, tgty, x, y, srcx, srcy)
	--reference our projectile from its location
	local projectile = game.level.map(x, y, game.level.map.PROJECTILE)
	local src = projectile.src
	--call the original function to see where we're going
	local retx, rety, retact, retstop = base_projectDoMove(self, typ, tgtx, tgty, x, y, srcx, srcy)
	
	--look for an actor in the space we're about to move, and deflect the projectile
	local actor = game.level.map(retx, rety, game.level.map.ACTOR)
	if actor and actor:attr("stoic_deflection") and src ~= actor then
		game.logSeen(actor, "%s deflects the %s from %s!", actor.name:capitalize(), projectile.name:capitalize(), src.name:capitalize())
		
		--update the projectile's source/actor coordinates and overwrite its line_function to match, so it flies in the correct direction
		projectile.project.def.tg.act_exclude = {[actor.uid]=true} --make sure deflected aoes never hit the actor
		projectile.project.def.x, projectile.project.def.y = src.x, src.y
		projectile.project.def.start_x, projectile.project.def.start_y = actor.x, actor.y
		if actor.lineFOV then
			projectile.project.def.typ.line_function = actor:lineFOV(src.x, src.y, nil, nil, actor.x, actor.y)	
		else
			projectile.project.def.typ.line_function = core.fov.line(actor.x, actor.y, src.x, src.y)
		end
		--actor still gets hit if they walk into it, this is covered in superload\engine\Projectile.lua on_move()

		--send our new direction to the old function to get which way to move
		retx, rety, retact, retstop = base_projectDoMove(self, projectile.project.def.typ, src.x, src.y, x, y, actor.x, actor.y)
	end

	return retx, rety, retact, retstop
end

Re: Altering projectile particles mid-flight

Posted: Tue May 12, 2015 6:35 am
by HousePet
Yeah, I've got a talent that makes all nearby projectiles fly towards their source instead.
And then there is the Deflect Projectiles spike.

Re: Altering projectile particles mid-flight

Posted: Wed May 13, 2015 1:29 am
by Atarlost
This issue also crops up with homing projectiles if they're slow enough. Temporal Bolt makes this obvious because it has a directional effect, can both be turned as much as 180 degrees by the caster teleporting, and can be slow enough to make it very obvious what's happening by stacking "slows incoming projectiles" effects.

Re: Altering projectile particles mid-flight

Posted: Wed May 13, 2015 2:25 am
by stinkstink
HousePet wrote:Yeah, I've got a talent that makes all nearby projectiles fly towards their source instead.
And then there is the Deflect Projectiles spike.
I tested both Deflect Projectiles and your Rebound talent, they both cause projectiles to keep their original facing after being redirected, at least on my system.

Re: Altering projectile particles mid-flight

Posted: Thu May 14, 2015 7:00 pm
by Zireael
Facing is a graphical issue not a code issue, I think?