Checking if multiple targets are the same actor?

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
lukep
Sher'Tul Godslayer
Posts: 1712
Joined: Mon Mar 14, 2011 10:32 am
Location: Canada

Checking if multiple targets are the same actor?

#1 Post by lukep »

I'm refining a talent that lets you target multiple times independently (like Turn Back the Clock or Earthen Missiles), and trying to find a way to test if the projectiles are targeting the same actor. I haven't had any luck so far, but might be making a silly mistake again. Code (from my Magebow class's Area Shot, while Elemental Arrows is active)


Code: Select all

			local tg = {type="bolt", selffire=false, talent=t}

			local old = self.energy.value
		
			self.energy.value = self.energy.value + game.energy_to_act * 10
			
			local reset = function(self)
				self.energy.value = old
			end

			game.logPlayer(self, "Targeting fire arrow.")
			local targets1 = self:archeryAcquireTargets(tg)
			if not targets1 then reset(self) return end
			
			game.logPlayer(self, "Targeting acid arrow.")
			local targets2 = self:archeryAcquireTargets(tg)
			if not targets2 then 
				reset(self) 
				local weapon, ammo = self:hasArcheryWeapon()
				ammo.combat.shots_left = ammo.combat.shots_left + 1
			return end
						
			game.logPlayer(self, "Targeting cold arrow.")
			local targets3 = self:archeryAcquireTargets(tg)
			if not targets3 then 
				reset(self) 
				local weapon, ammo = self:hasArcheryWeapon()
				ammo.combat.shots_left = ammo.combat.shots_left + 2
			return end
						
			game.logPlayer(self, "Targeting lightning arrow.")
			local targets4 = self:archeryAcquireTargets(tg)
			if not targets4 then 
				reset(self) 
				local weapon, ammo = self:hasArcheryWeapon()
				ammo.combat.shots_left = ammo.combat.shots_left + 3
			return end

			reset(self)

			local firemult = t.getDamageElemental(self, t)
			local acidmult = t.getDamageElemental(self, t)
			local coldmult = t.getDamageElemental(self, t)
			local lightningmult = t.getDamageElemental(self, t)

			--[[if targets1 == targets2 then
				firemult = firemult - 0.1
				acidmult = acidmult - 0.1
				game.logPlayer(self, "It's the same!.")
			end
			if targets1 == targets3 then
				firemult = firemult - 0.1
				coldmult = coldmult - 0.1
				game.logPlayer(self, "It's the same!.")
			end
			if targets1 == targets4 then
				firemult = firemult - 0.1
				lightningmult = lightningmult - 0.1
				game.logPlayer(self, "It's the same!.")
			end
			if targets2 == targets3 then
				acidmult = acidmult - 0.1
				coldmult = coldmult - 0.1
				game.logPlayer(self, "It's the same!.")
			end
			if targets2 == targets4 then
				acidmult = acidmult - 0.1
				lightningmult = lightningmult - 0.1
				game.logPlayer(self, "It's the same!.")
			end
			if targets3 == targets4 then
				coldmult = coldmult - 0.1
				lightningmult = lightningmult - 0.1
				game.logPlayer(self, "It's the same!.")
			end]]

			self:archeryShoot(targets1, t, tg, {mult=firemult, damtype=DamageType.FIRE})
			self:archeryShoot(targets2, t, tg, {mult=acidmult, damtype=DamageType.ACID})
			self:archeryShoot(targets3, t, tg, {mult=coldmult, damtype=DamageType.COLD})
			self:archeryShoot(targets4, t, tg, {mult=lightningmult, damtype=DamageType.LIGHTNING})

			-- HACK
			self.energy.value = old - game.energy_to_act
			
			return true
Some of my tools for helping make talents:
Melee Talent Creator
Annotated Talent Code (incomplete)

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

Re: Checking if multiple targets are the same actor?

#2 Post by stinkstink »

Use if targets1[1].x == targets2[1].x and targets1[1].y == targets2[1].y then instead.

Castler
Thalore
Posts: 153
Joined: Mon Mar 25, 2013 10:09 pm

Re: Checking if multiple targets are the same actor?

#3 Post by Castler »

If I understand archeryAcquireTargets correctly, it returns an array (i.e., a numerically indexed table) of {x, y, ammo} tables.

Two tables in Lua will be equal only if they refer to the exact same table. See http://www.lua.org/pil/3.2.html. These tables aren't the same; each us generated separately by calls to archeryAcquireTargets, even if their contents are the same.

Instead, try iterating over table elements and comparing their x, y members.

archeryAcquireTargets takes a param parameter that allows x, y members. Rather than calling archeryAcquireTargets to get targets 4 times and having to roll back its effects on cancel and having to iterate over its results to check x and y, it might be easier to call getTarget 4 times yourself and check its results directly and pass its x, y to archeryAcquireTargets.

archeryAcquireTargets does other stuff, too, like checking for ammo and resources and triggering hooks and two-weapon firing. I'm not sure how you'll want to handle all those cases if it fails halfway through.

I haven't worked with archery code and haven't tested any of the above, so I could be wrong.
Qi Daozei (QDZ) - an Oriental-themed fantasy game for T-Engine. ToME Tips - auto-generated spoilers for ToME.

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Checking if multiple targets are the same actor?

#4 Post by HousePet »

Yeah, it does return something arrayish, so a direct compare won't make sense.
My feedback meter decays into coding. Give me feedback and I make mods.

lukep
Sher'Tul Godslayer
Posts: 1712
Joined: Mon Mar 14, 2011 10:32 am
Location: Canada

Re: Checking if multiple targets are the same actor?

#5 Post by lukep »

stinkstink wrote:Use if targets1[1].x == targets2[1].x and targets1[1].y == targets2[1].y then instead.
Thanks, that worked!
Castler wrote:archeryAcquireTargets does other stuff, too, like checking for ammo and resources and triggering hooks and two-weapon firing. I'm not sure how you'll want to handle all those cases if it fails halfway through.
I think I have everything covered (except dualwielding, which I have yet to see). archeryAcquireTargets spends ammo and energy, and I have both covered. Now I just have to worry about esoteric effects I haven't considered.
Some of my tools for helping make talents:
Melee Talent Creator
Annotated Talent Code (incomplete)

Sradac
Sher'Tul
Posts: 1081
Joined: Fri Sep 21, 2007 3:18 am
Location: Angolwen

Re: Checking if multiple targets are the same actor?

#6 Post by Sradac »

All I know is don't nerf that talent, shooting 4 elemental arrows at an enemy is so much fun. Burnt down the sandworm queen in 3 turns!

lukep
Sher'Tul Godslayer
Posts: 1712
Joined: Mon Mar 14, 2011 10:32 am
Location: Canada

Re: Checking if multiple targets are the same actor?

#7 Post by lukep »

Sradac wrote:All I know is don't nerf that talent, shooting 4 elemental arrows at an enemy is so much fun. Burnt down the sandworm queen in 3 turns!
I think I'll buff it in general, but it loses 20% of the (new, higher) damage for each extra arrow on one target.

(also working on making Special Shot more special, keep your eyes peeled for a new version...)
Some of my tools for helping make talents:
Melee Talent Creator
Annotated Talent Code (incomplete)

Post Reply