on_die function in timed effect causing loot displacement

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

on_die function in timed effect causing loot displacement

#1 Post by Razakai »

I have a talent that causes mobs under a timed effect to spawn an allied ghost on death. This appears to be causing their loot drops to displace, similar to when you kill a mob stuck inside a wall. Any ideas what's causing this? Code below:

Code: Select all

...
	on_die = function(self, eff)
		if eff.src.knowTalent and eff.src:knowTalent(eff.src.T_SHACKLE_SOUL) then
			local t = eff.src:getTalentFromId(eff.src.T_SHACKLE_SOUL)
			if rng.percent(t.getChance(eff.src, t)) then
				t.spawn_ghost(eff.src, self, t)
			end
		end
	end,
}

Code: Select all

newTalent{
	name = "Shackle Soul",
	type = {"spell/dread", 2},
	require = spells_req2,
	points = 5,
	mode = "passive",
	getChance = function(self, t) return self:combatTalentLimit(t, 100, 20, 70) end,
	getDuration = function(self, t) return (self:combatTalentScale(t, 3, 7)) end,
	spawn_ghost = function (self, target, t)
		local x, y = util.findFreeGrid(target.x, target.y, 10, true, {[Map.ACTOR]=true})
		if not x then return nil end
		
		local nb = 0

		if game.level then
			for _, act in pairs(game.level.entities) do
				if act.summoner and act.summoner == self and act.wraith_summon then nb = nb + 1 end
			end
		end
		
		if nb >= 4 then return nil end
		
		local m = ghost(self, target, t.getDuration(self,t), x, y)
		if not m then return nil end

		m:logCombat(target, "A #WHITE##Source##LAST# rises from the corpse of #Target#!")
	end,
	info = function(self, t)
	local chance = t.getChance(self,t)
	local dur = t.getDuration(self,t)
		return ([[Your enervate shackles the souls of your enemies, giving a %d%% chance on death for them to rise as a wraith under your control for %d turns. Wraiths assault your enemies with blasts of cold that deal increased damage with each point invested in this talent.
		You cannot have more than 4 wraiths active at a time.
		The first point in this talent increases the range of your Necrotic Aura by 1.]]):
		format(chance, dur)
	end,
}

Code: Select all

ghost = function(self, target, duration, x, y)
	local m = mod.class.NPC.new{
			type = "undead", subtype = "ghost",
			display = "G", color=colors.WHITE, image = "npc/shackled_soul.png",
			name = "wraith", faction = self.faction,
			desc = [[]],
			autolevel = "caster",
			ai = "summoned", ai_real = "tactical",
			ai_state = { talent_in=1, },
			ai_tactic = resolvers.tactic"ranged",
			stats = { str=14, dex=18, mag=20, con=12 },
			stats = { mag=self:getMag(), wil=self:getWil(), cun=self:getCun()},
			rank = 2,
			size_category = 3,
			infravision = 10,
		
			can_pass = {pass_wall=70},
			resists = {all = 35, [DamageType.LIGHT] = -70, [DamageType.DARKNESS] = 65},
		
			no_breath = 1,
			stone_immune = 1,
			confusion_immune = 1,
			fear_immune = 1,
			teleport_immune = 0.5,
			disease_immune = 1,
			poison_immune = 1,
			stun_immune = 1,
			blind_immune = 1,
			cut_immune = 1,
			see_invisible = 80,
			undead = 1,
			resolvers.sustains_at_birth(),
			not_power_source = {nature=true},
		
			max_life = resolvers.rngavg(5,9),
			life_rating= 6,
			combat_armor = 7, combat_def = 6,
			resolvers.talents{ 
				[Talents.T_FROSTBLAST]=math.floor(self:getTalentLevel(self.T_SHACKLE_SOUL)),
			},
			combat_spellpower = self:combatSpellpower(),

			summoner = self, summoner_gain_exp=true, wraith_summon=true,
			summon_time = duration,
			ai_target = {actor=target}
			


	}

	m.unused_stats = 0
	m.unused_talents = 0
	m.unused_generics = 0
	m.unused_talents_types = 0
	m.no_inventory_access = true
	m.no_points_on_levelup = true
	m.save_hotkeys = true
	m.ai_state = m.ai_state or {}
	m.ai_state.tactic_leash = 100
	-- Try to use stored AI talents to preserve tweaking over multiple summons
	m.ai_talents = self.stored_ai_talents and self.stored_ai_talents[m.name] or {}
	m:resolve() m:resolve(nil, true)
	m:forceLevelup(self.level)
	game.zone:addEntity(game.level, m, "actor", x, y)
	game.level.map:particleEmitter(x, y, 1, "summon")
	m.inc_damage = table.clone(self.inc_damage, true)

	-- Summons never flee
	m.ai_tactic.escape = 0
	m.summon_time = duration

	mod.class.NPC.castAs(m)
	engine.interface.ActorAI.init(m, m)

	return m
end

grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Re: on_die function in timed effect causing loot displacemen

#2 Post by grayswandir »

Have you tried delaying the spawn with onTickEnd ?
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

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

Re: on_die function in timed effect causing loot displacemen

#3 Post by Razakai »

grayswandir wrote:Have you tried delaying the spawn with onTickEnd ?
That did it, thanks.

Post Reply