-- Persona Support --
if not srb2p return end

-- Stats
charStats["ember"] = {
	-- GENERAL
	name = "Ember", -- Only for bots/enemies
	basehp = 65, -- Base HP/SP at level 1
	basesp = 35,
	persona = "scathach", -- Determines actual stats
	melee_natk = "ember_atk1", -- Normal melee attack
	melee_satk = "ember_atk2", -- Super melee attack
	wep = "ember_weapon1", -- Default weapon
	weptype = WPT_GENERICRANGED, -- Equippable weapon type(s)
	atk = 35, -- Attack power of physical attacks
	acc = 90, -- Accuracy of physical attacks
	crit = 9, -- Critical rate of physical attacks
	supercolor_start = SKINCOLOR_BLAZING1, -- If Super Form is applicable, will use this flash
	-- ANIMS
	anim_stand = {SPR_PLAY, A, 8, "SPR2_STND"}, -- Standing
	anim_stand_hurt = {SPR_PLAY, A, 1, "SPR2_STND"}, -- Standing (Low HP)
	anim_stand_bored = {SPR_PLAY, A, B, A, B, A, B, A, B, 10, "SPR2_WAIT"}, -- Standing (Rare)
	anim_guard = {SPR_PLAY, A, 1, "SPR2_WALK"}, -- Guarding
	anim_move = {SPR_PLAY, A, B, C, D, 2, "SPR2_WALK"}, -- Moving
	anim_run = {SPR_PLAY, A, B, C, D, 2, "SPR2_RUN_"}, -- Running
	anim_atk = {SPR_PLAY, A, B, C, D, 1, "SPR2_ROLL"}, -- Attacking
	anim_aoa_end = {SPR_PLAY, D, C, B, A, 1, "SPR2_ROLL"}, -- Jumping out from All Out Attack
	anim_hurt = {SPR_PLAY, A, 35, "SPR2_PAIN"}, -- Taking damage
	anim_getdown = {SPR_PLAY, A, 1, "SPR2_PAIN"}, -- Knocked down from weakness/crit
	anim_downloop = {SPR_PLAY, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, 2, "SPR2_CNT1"}, -- Is down
	anim_getup = {SPR_PLAY, A, B, C, D, 1, "SPR2_ROLL"}, -- Gets up from down
	anim_death = {SPR_PLAY, A, 30, "SPR2_DEAD"}, -- Dies
	anim_revive = {SPR_PLAY, A, B, C, D, 1, "SPR2_ROLL"}, -- Gets revived
	anim_evoker = {SPR_PLAY, A, 8, "SPR2_MLEE"}, -- Uses evoker
	anim_evoker_shoot = {SPR_PLAY, A, B, C, 8, "SPR2_MLEE"},
	anim_special1 = {SPR_PLAY, A, 1, "SPR2_FIRE"}, -- Custom stuff. Can have up to 32
	anim_special2 = {SPR_PLAY, A, B, C, 2, "SPR2_FIRE"},
	anim_special3 = {SPR_PLAY, A, 1, "SPR2_BNCE"},
	anim_special4 = {SPR_PLAY, A, 1, "SPR2_BNCE"},
	-- SUPER ANIMS
	anim_stand_super = {SPR_PLAY, A, B, 8, "SPR2_STND"},
	anim_guard_super = {SPR_PLAY, A, 1, "SPR2_RUN_"},
	anim_move_super = {SPR_PLAY, A, 2, "SPR2_WALK"},
	anim_run_super = {SPR_PLAY, A, 2, "SPR2_RUN_"},
	anim_atk_super = {SPR_PLAY, A, B, C, D, E, F, 1, "SPR2_ROLL"},
	anim_aoa_end_super = {SPR_PLAY, F, E, D, C, B, A, 1, "SPR2_ROLL"},
	anim_hurt_super = {SPR_PLAY, A, 35, "SPR2_PAIN"},
	anim_getup_super = {SPR_PLAY, A, B, 8, "SPR2_STND"},
	anim_evoker_super = {SPR_PLAY, A, 8, "SPR2_MLEE"},
	anim_evoker_shoot_super = {SPR_PLAY, B, 8, "SPR2_MLEE"},
	anim_special1_super = {SPR_PLAY, A, 1, "SPR2_WALK"},
	anim_special2_super = {SPR_PLAY, A, 1, "SPR2_JUMP"},
	anim_special3_super = {SPR_PLAY, A, 1, "SPR2_FIRE"},
	anim_special4_super = {SPR_PLAY, B, 1, "SPR2_FIRE"},
	-- VOICES
	vfx_summon = {"sfx_emsum1", "sfx_emsum2", "sfx_emsum3"},
    vfx_skill = {"sfx_emskl1", "sfx_emskl2", "sfx_emskl3"},
    vfx_item = {"sfx_emitm1", "sfx_emitm2", "sfx_emitm3"},
    vfx_hurt = {"sfx_emhrt1", "sfx_emhrt2", "sfx_emhrt3"},
    vfx_hurtx = {"sfx_emxht1", "sfx_emxht2", "sfx_emxht3"},
    vfx_die = {"sfx_emdie1", "sfx_emdie2", "sfx_emdie3"},
    vfx_heal = {"sfx_emhel1", "sfx_emhel2", "sfx_emhel3"},
    vfx_healself = {"sfx_emhel4", "sfx_emhel5"},
    vfx_kill = {"sfx_emkll1", "sfx_emkll2", "sfx_emkll3"},
    vfx_1more = {"sfx_em1mor", "sfx_em2mor", "sfx_em3mor"},
    vfx_crit = {"sfx_emcrt1", "sfx_emcrt2", "sfx_emcrt3"},
    vfx_aoaask = {"sfx_emask1", "sfx_emask2", "sfx_emask3"},
    vfx_aoado = {"sfx_emdo1", "sfx_emdo2", "sfx_emdo3"},
    vfx_aoarelent = {"sfx_emrlt1", "sfx_emrlt2", "sfx_emrlt3"},
    vfx_miss = {"sfx_emmss1", "sfx_emmss2", "sfx_emmss3"},
    vfx_dodge = {"sfx_emdod1", "sfx_emdod2", "sfx_emdod3"},
    vfx_win = {"sfx_emwin1", "sfx_emwin2", "sfx_emwin3"},
    vfx_levelup = {"sfx_emlvl1", "sfx_emlvl2", "sfx_emlvl3"},
	-- HUD/UI
	hudaoa = "H_EMBAOA", -- Patch for All Out Attack hud
	hudbust = "H_EMBBAR", -- Patch to draw on the stat hud
	icon = "ICO_EMBR", -- Icon for net select and other menus
	hudcutin = "EMBR_A", -- Cut in
	hudsaoa = "H_BEMBAO",
	hudsbust = "H_BEMBBA",
	hudscutin = "BEMB_A",
	aoa_quote = "Float like a butterfly, \nsting like a bee!", -- Something to say when in a Hold-Up
	tip = "Learns Ice, Pierce, Death, and HP drains. Her high Luck allows her to land criticals, Freeze, and instant kills often, but Attack and Crit Rate buffs are the best use for her low SP as they'll boost her offensive power." -- A brief description of how the character generally plays in battle
}

VFX_freeslotC("ember")

-- Persona
personaList["scathach"] = {
	-- GENERAL
	name = "Scathach",
	arcana = ARCANA_STRENGTH,
	sprite = SPR_SCAT,
	startframe = 0,
	anim_idle = {SPR_SCAT, A, B, C, D, E, F, G, H, G, F, E, D, C, B, A, 8},
	anim_atk = {SPR_SCAT, I, J, K, L, M, N, O, P, Q, R, S, T, 2},
	-- STATS (At level 10)
	strength = 9,
	magic = 6,
	endurance = 7,
	luck = 10,
	agility = 8,
	-- AFFINITIES
	resist = bionis and ATK_ICE|ATK_CURSE|ATK_FOREST or ATK_ICE|ATK_CURSE,
	weak = bionis and ATK_ELEC|ATK_GRAVITY or ATK_ELEC,
	-- SKILLSET
	skills = {
		{"bufu", 1}, {"skewer", 4},
		{"tarukaja", 12}, {"rebellion", 16},
		{"cruel attack", 21}, {"em_arrow rain", 25},
		{"bufula", 28}, {"em_auto-rebellion", 32},
		
		{"matarukaja", 35, "skewer"}, {"mudoon", 39, "bufu"},
		{"life drain", 42, "tarukaja"}, {"revolution", 45, "rebellion"},
		{"em_javelin hail", 49, "em_arrow rain"}, {"vile assault", 53, "cruel attack"},
		{"em_auto-brave", 56, "em_auto-rebellion"}, {"life leech", 59, "life drain"},
		
		{"bufudyne", 62, "bufula"}, {"em_brave step", 65, "revolution"},
		{"triple down", 68, "em_javelin hail"}, {"life siphon", 72, "life leech"},
		{"em_one shot kill", 77, "vile assault"},
		
		// Bufu > Bufula > Bufudyne
		// Skewer > Cruel Attack > Vile Assault > One-Shot Kill
		// Tarukaja > Matarukaja
		// Rebellion > Revolution > Brave Step
		// Mudoon
		// Arrow Rain > Javelin Hail > Triple Down
		// Life Drain > Life Leech > Life Siphon
		// Auto-Rebellion > Auto-Brave
	},
}

-- Weapons
weaponsList["ember_weapon1"] = {
	name = "Judgement Pyre",
	type = WPT_GENERICRANGED,
	rarity = 1,
	element = nil,
	atk = 350,
	acc = 90,
	crit = 9,
	desc = "Ember's starting weapon. \nA magic spell involving a holy variant of \nfire that burns evil and cleanses sin.",
	slot = "might 1",
}

weaponsList["ember_weapon2"] = {
	name = "Diamond Kiss",
	type = WPT_GENERICRANGED,
	rarity = 3,
	element = ATK_ICE,
	atk = 1050,
	acc = 90,
	crit = 9,
	desc = "Ember's 2nd tier weapon. \nA magic spell in which creates frigid air \nfrom the user's breath, freezing everything \nthat it comes into contact with.",
	st = 1,
	lu = 1,
	slot = "freeze boost",
}

weaponsList["ember_weapon3"] = {
	name = "Spectral Order",
	type = WPT_GENERICRANGED,
	rarity = 5,
	element = ATK_CURSE,
	atk = 1750,
	acc = 90,
	crit = 9,
	desc = "Ember's 3rd tier weapon. \nA magic spell that allows the user to \ncommunicate with ghostly spirits as well as \nbeing able to command them.",
	st = 3,
	lu = 3,
	slot = "death boost",
}

-- Velvet Shop
table.insert(shopList["velvet_shop_mp1"].weapons, {makeWeapon("ember_weapon1", 10), 800, nil, 4})
table.insert(shopList["velvet_shop_mp1"].weapons, {makeWeapon("ember_weapon2"), 4000, 3})
table.insert(shopList["velvet_shop_mp1"].weapons, {makeWeapon("ember_weapon3"), 12500, 6})

-- Void Shop
table.insert(shopList["void_shop"].weapons, {makeWeapon("ember_weapon1", 10), 700, nil, 6})
table.insert(shopList["void_shop"].weapons, {makeWeapon("ember_weapon2"), 1500, 6, 12})
table.insert(shopList["void_shop"].weapons, {makeWeapon("ember_weapon3"), 2000, 12})

-- Bionis Shop
if bionis
	table.insert(shopList["shop_bionis"].weapons, {makeWeapon("ember_weapon1", 10), 800, nil, 4})
	table.insert(shopList["shop_bionis"].weapons, {makeWeapon("ember_weapon2"), 4000, 3})
	table.insert(shopList["shop_bionis"].weapons, {makeWeapon("ember_weapon3"), 12500, 6})
	table.insert(shopList["shop_ameno"].weapons, {makeWeapon("ember_weapon2", 10), 8000, 3})
	table.insert(shopList["shop_ameno"].weapons, {makeWeapon("ember_weapon3", 10), 25000, 6})
end

-- Skills
attackDefs["ember_atk1"] = {
	name = "Flame Stinger",
	type = ATK_PIERCE,
	power = 35,
	accuracy = 90,
	critical = 9,
	target = TGT_ENEMY,
	costtype = CST_HP,
	cost = 0,
	desc = "Miniscule Pierce damage to one enemy. \nHigh critical rate.",
	physical = true,
	norandom = true,
	anim = function(mo, targets, hittargets, timer)
		local target = targets[1]
		local btl = server.P_BattleStatus[mo.battlen]
		local cam = btl.cam
		if timer == 1
			ANIM_set(mo, mo.anim_special1)
			mo.oldangle = mo.angle
			mo.angle = R_PointToAngle2(mo.x, mo.y, target.x, target.y)
			cam.angle = R_PointToAngle2(cam.x, cam.y, target.x, target.y)
			mo.stinger = {}
		elseif timer == 5*TICRATE/8
			local cx = target.x + 168*cos(target.angle + ANG1*20)
			local cy = target.y + 168*sin(target.angle + ANG1*20)
			CAM_goto(server.P_BattleStatus[mo.battlen].cam, cx, cy, target.z + FRACUNIT*30, 70*FRACUNIT)
			CAM_angle(server.P_BattleStatus[mo.battlen].cam, R_PointToAngle2(cx, cy, target.x, target.y))
		end
		if timer >= 1*TICRATE/2 and timer < 3*TICRATE/4
			if timer == 1*TICRATE/2	
				ANIM_set(mo, mo.anim_special2)
				playSound(mo.battlen, sfx_fire)
				playSound(mo.battlen, sfx_s1ae)
				local cx = mo.x + 1*cos(mo.angle + ANG1*90)
				local cy = mo.y + 1*sin(mo.angle + ANG1*90)
				mo.stinger = P_SpawnMobj(cx, cy, mo.z+(32*FRACUNIT), MT_FLAMESTINGER)    
				mo.stinger.momx = (target.x - mo.stinger.x)/3
				mo.stinger.momy = (target.y - mo.stinger.y)/3
				mo.stinger.momz = (target.z - mo.stinger.z)/3
				mo.stinger.tics = 5
			elseif timer > 1*TICRATE/2
				if mo.stinger and mo.stinger.valid	
					local trail = P_SpawnMobj(mo.stinger.x, mo.stinger.y, mo.stinger.z, MT_FIREBALLTRAIL)
					trail.scale = FRACUNIT*2
					trail.destscale = FRACUNIT/6
					trail.scalespeed = FRACUNIT*1/4
					trail.tics = 3
				end
			end
		end
		if timer == 3*TICRATE/4
			damageObject(hittargets[1])
			local boom = P_SpawnMobj(target.x+P_RandomRange(-20, 20)*FRACUNIT, target.y+P_RandomRange(-20, 20)*FRACUNIT, target.z+P_RandomRange(-20, 20)*FRACUNIT, MT_BOSSEXPLODE)
			boom.scale = FRACUNIT*3/2
			boom.state = S_QUICKBOOM1
			playSound(mo.battlen, sfx_fire1)
			P_StartQuake(FRACUNIT*7, 4)
			for i = 1, 2
				createSplat(mo)
			end
		end
		if timer == 3*TICRATE/2
			return true
		end
	end,
}

attackDefs["ember_atk2"] = {
	name = "Super Flame Stinger",
	type = ATK_FIRE,
	power = 410,
	accuracy = 100,
	critical = 999,
	target = TGT_ENEMY,
	costtype = CST_HP,
	cost = 0,
	desc = "Heavy Fire damage to one enemy. \nAlways lands critical hits.",
	norogue = true,
	norandom = true,
	nometronome = true,
	anim_norepel = true,
	norepel = true,
	anim = function(mo, targets, hittargets, timer)
		local target = targets[1]
		local btl = server.P_BattleStatus[mo.battlen]
		local cam = btl.cam
		if timer == 1
			ANIM_set(mo, mo.anim_special1)
			S_StartSound(mo, sfx_embsa1)
			mo.oldangle = mo.angle
			mo.angle = R_PointToAngle2(mo.x, mo.y, target.x, target.y)
			cam.angle = R_PointToAngle2(cam.x, cam.y, target.x, target.y)
			mo.stinger = {}
		end
		if timer >= 1*TICRATE/2 and timer < 250
			if timer >= 1*TICRATE/2 and timer < 50
				ANIM_set(mo, mo.anim_special2)
				if timer == 1*TICRATE/2
					S_StartSound(mo, sfx_belnch)
				end
				P_SetObjectMomZ(mo, 20*FRACUNIT)
				local tg = P_SpawnGhostMobj(mo)
				tg.fuse = 10
				mo.flags = $|MF_NOGRAVITY
			elseif timer == 50
				P_SetObjectMomZ(mo, 0*FRACUNIT)
			elseif timer > 50 and timer < 80
				ANIM_set(mo, mo.anim_special3)
				if timer == 51
					local cam = server.P_BattleStatus[mo.battlen].cam
					local cx = mo.x + 128*cos(mo.angle - ANG1*25)
					local cy = mo.y + 128*sin(mo.angle - ANG1*25)
					P_TeleportMove(cam, cx, cy, mo.z + FRACUNIT*16)
					server.P_BattleStatus[mo.battlen].cam.angle = R_PointToAngle2(cam.x, cam.y, mo.x, mo.y)
					CAM_goto(cam, cam.x-24*cos(cam.angle), cam.y-24*sin(cam.angle), cam.z-FRACUNIT*4, 1*FRACUNIT)
				end
			elseif timer >= 80
				ANIM_set(mo, mo.anim_special4)
				local cx = mo.x + 1*cos(mo.angle + ANG1*90)
				local cy = mo.y + 1*sin(mo.angle + ANG1*90)
				if timer == 80	
					S_StartSound(mo, sfx_embsa2)
					S_StartSound(mo, sfx_bechrg)
					mo.stinger = P_SpawnMobj(cx, cy, mo.z + 15*FRACUNIT, MT_THOK)
					mo.stinger.sprite = SPR_CHFS
					mo.stinger.frame = A|FF_FULLBRIGHT
					mo.stinger.scale = FRACUNIT*1/7
					mo.stinger.destscale = FRACUNIT*9/10
					mo.stinger.scalespeed = 15*TICRATE
					mo.stinger.tics = 300
				end
				if mo.stinger and mo.stinger.valid and mo.stinger.scale > FRACUNIT*1/7 and mo.stinger.scale < FRACUNIT*9/10
					mo.stinger.z = $ - FRACUNIT*1/5
				end
				if timer == 180
					S_StopSoundByID(mo, sfx_bechrg)
					P_InstaThrust(mo, mo.angle, -5*FRACUNIT)
					mo.stinger.momx = (target.x - mo.stinger.x)/30
					mo.stinger.momy = (target.y - mo.stinger.y)/30
					mo.stinger.momz = (target.z - mo.stinger.z)/30
					S_StartSound(mo, sfx_s3ka0)
					S_StartSound(mo, sfx_koopfr)
				end
				if timer == 190
					local cx = target.x + 168*cos(target.angle + ANG1*20)
					local cy = target.y + 168*sin(target.angle + ANG1*20)
					CAM_goto(server.P_BattleStatus[mo.battlen].cam, cx, cy, target.z + FRACUNIT*30, 70*FRACUNIT)
					CAM_angle(server.P_BattleStatus[mo.battlen].cam, R_PointToAngle2(cx, cy, target.x, target.y))
					mo.flags = $ & ~MF_NOGRAVITY
				end
				if timer == 210
					damageObject(hittargets[1])
					if target.damagestate ~= DMG_MISS 
					or target.damagestate ~= DMG_BLOCK 
					or target.damagestate ~= DMG_DRAIN
						P_StartQuake(FRACUNIT*70, TICRATE*1/2)
						for i = 1, 2
							createSplat(mo)
						end
					end
				end
			end
		end
		if timer == 250
			return true
		end
	end,
}

attackDefs["em_arrow rain"] = {
	name = "Arrow Rain",
	type = ATK_PIERCE,
	power = 120,
	accuracy = 80,
	costtype = CST_HPPERCENT,
	technical = COND_FREEZE,
	cost = 11,
	critical = 2,
	desc = "Light Pierce damage to \nall enemies.",
	target = TGT_ALLENEMIES,
	norogue = true,
	norandom = true,
	anim = function(mo, targets, hittargets, timer)
		for k,v in ipairs(hittargets)
			local target = v
			local time = timer - 6*(k-1)
			if time == 20
				target.hand = P_SpawnMobj(target.x, target.y, target.z + 500*FRACUNIT, MT_DUMMY)
				target.hand.momz = -50*FRACUNIT
				target.hand.tics = -1
				target.hand.sprite = SPR_ARRO
				target.hand.frame = A
				target.hand.scale = FRACUNIT*1
				target.hand.fuse = TICRATE*2
				playSound(mo.battlen, sfx_hamas1)
			end
			if time == 30
				local shot = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
				shot.state = S_STAB_1_1
				shot.color = SKINCOLOR_ORANGE
				shot.scale = FRACUNIT*3
				playSound(mo.battlen, sfx_hit)
				local d = P_SpawnMobj(target.x, target.y, target.z+128*FRACUNIT, MT_THOK)
				d.sprite = SPR_THMP
				d.frame = A|FF_FULLBRIGHT
				d.scale = FRACUNIT/4
				d.destscale = FRACUNIT*4
				d.scalespeed = FRACUNIT/8
				d.fuse = TICRATE-10
				d.tics = d.fuse
				d.momz = FRACUNIT*2
				d.momx = P_RandomRange(0, FRACUNIT-1)*P_RandomRange(-8, 8)
				d.momy = P_RandomRange(0, FRACUNIT-1)*P_RandomRange(-8, 8)
				d.color = SKINCOLOR_ORANGE
			end
			if time == 31
				playSound(mo.battlen, sfx_rail1)
				createSplat(mo)
				createSplat(mo)
				localquake(mo.battlen, FRACUNIT*10, 10)
				damageObject(target)
			end
		end
		if timer == 60 + 6*(#hittargets-1)
			return true
		end
	end,
}

attackDefs["em_auto-rebellion"] = {
	name = "Auto-Rebellion",
	type = ATK_PASSIVE,
	desc = "Start battles with \na Crit Rate buff.",
	passive = PSV_STARTBATTLE,
	norogue = true,
	norandom = true,
	anim = function(mo, targets, hittargets, timer)
			local target = hittargets[1]
			buffStat(target, "crit")
		end,
}

attackDefs["em_javelin hail"] = {
	name = "Javelin Hail",
	type = ATK_PIERCE,
	power = 270,
	accuracy = 85,
	costtype = CST_HPPERCENT,
	technical = COND_FREEZE,
	cost = 17,
	critical = 5,
	desc = "Medium Pierce damage to \nall enemies.",
	target = TGT_ALLENEMIES,
	norogue = true,
	norandom = true,
	anim = function(mo, targets, hittargets, timer)
		for k,v in ipairs(hittargets)
			local target = v
			local time = timer - 6*(k-1)
			if time == 20
				target.hand = P_SpawnMobj(target.x, target.y, target.z + 500*FRACUNIT, MT_DUMMY)
				target.hand.momz = -50*FRACUNIT
				target.hand.tics = -1
				target.hand.sprite = SPR_JAVE
				target.hand.frame = A
				target.hand.scale = FRACUNIT*2
				target.hand.fuse = TICRATE*2
				playSound(mo.battlen, sfx_s3k51)
			end
			if time == 30
				local shot = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
				shot.state = S_STAB_1_1
				shot.color = SKINCOLOR_ORANGE
				shot.scale = FRACUNIT*3
				playSound(mo.battlen, sfx_hit)
				DoExplosion(target)
			end
			if time == 31
				playSound(mo.battlen, sfx_rail1)
				createSplat(mo)
				createSplat(mo)
				localquake(mo.battlen, FRACUNIT*10, 10)
				damageObject(target)
			end
		end
		if timer == 60 + 6*(#hittargets-1)
			return true
		end
	end,
}

attackDefs["em_auto-brave"] = {
	name = "Auto-Brave",
	type = ATK_PASSIVE,
	target = TGT_ALLALLIES,
	desc = "Party starts battles \nwith a Crit Rate buff.",
	passive = PSV_STARTBATTLE,
	norogue = true,
	norandom = true,
	anim = function(mo, targets, hittargets, timer)
			for i = 1, #mo.allies do
				local target = mo.allies[i]
				buffStat(target, "crit")
			end
		end,
}

attackDefs["em_brave step"] = {
	name = "Brave Step",
	type = ATK_SUPPORT,
	costtype = CST_SP,
	cost = 16,
	desc = "Raise Party's Critical \nhit rate by 1 stage.",
	target = TGT_ALLALLIES,
	buff = true,
	norogue = true,
	norandom = true,
	anim = function(mo, targets, hittargets, timer)
		for i = 1, #targets do
			local target = targets[i]
			if timer == 20 + (i-1)*8
				playSound(mo.battlen, sfx_buff)
				playSound(mo.battlen, sfx_hamas1)
				buffStat(target, "crit")
				for i = 1,16
					local dust = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
					dust.angle = ANGLE_90 + ANG1* (22*(i-1))
					dust.state = S_CDUST1
					P_InstaThrust(dust, dust.angle, 30*FRACUNIT)
					dust.color = SKINCOLOR_YELLOW
					dust.scale = FRACUNIT*2
				end
			elseif timer > 20 + (i-1)*8 and timer <= 50 + (i-1)*8
				if leveltime%2 == 0
					for i = 1,16
						local thok = P_SpawnMobj(target.x+P_RandomRange(-70, 70)*FRACUNIT, target.y+P_RandomRange(-70, 70)*FRACUNIT, target.z+P_RandomRange(0, 50)*FRACUNIT, MT_DUMMY)
						thok.state = S_CDUST1
						thok.momz = P_RandomRange(3, 10)*FRACUNIT
						thok.color = SKINCOLOR_YELLOW
						thok.tics = P_RandomRange(10, 35)
						thok.scale = FRACUNIT*3/2
					end
				end
				for i = 1, 8
					local thok = P_SpawnMobj(target.x+P_RandomRange(-70, 70)*FRACUNIT, target.y+P_RandomRange(-70, 70)*FRACUNIT, target.z+P_RandomRange(0, 50)*FRACUNIT, MT_DUMMY)
					thok.sprite = SPR_SUMN
					thok.frame = F|FF_FULLBRIGHT|TR_TRANS50
					thok.momz = P_RandomRange(6, 16)*FRACUNIT
					thok.color = SKINCOLOR_YELLOW
					thok.tics = P_RandomRange(10, 35)
				end
			end
		end
		if timer == 60 + (#targets-1)*16
			return true
		end
	end,
}

attackDefs["em_one shot kill"] = {
	name = "One-Shot Kill",
	type = ATK_PIERCE,
	power = 740,
	accuracy = 90,
	costtype = CST_HPPERCENT,
	technical = COND_FREEZE,
	cost = 17,
	critical = 40,
	desc = "Severe Pierce damage to \none enemy. Very high \ncritical rate.",
	target = TGT_ENEMY,
	norogue = true,
	norandom = true,
	anim = function(mo, targets, hittargets, timer)
		local target = hittargets[1]
		if timer >= 18 and timer <= 70 and timer%2 == 0
			local shot = P_SpawnMobj(target.x, target.y, target.z+50*FRACUNIT, MT_THOK)
			shot.sprite = SPR_STAB
			shot.frame = A|FF_FULLBRIGHT|TR_TRANS50
			if timer%4 == 0 shot.color = SKINCOLOR_ORANGE else shot.color = SKINCOLOR_COPPER end
			shot.destscale = FRACUNIT*2
			shot.scalespeed = FRACUNIT/2
			playSound(mo.battlen,sfx_gun)
			local ang = R_PointToAngle(target.x, target.y) + ANG1*120
			for j = 1, 16
				local boom = P_SpawnMobj(target.x + P_RandomRange(-20,20)*FRACUNIT, target.y + P_RandomRange(-20,20)*FRACUNIT, target.z + 64*mo.scale + P_RandomRange(-20,20)*FRACUNIT, MT_DUMMY)
				boom.state = S_SSHOT1
				boom.color = SKINCOLOR_GOLD
				boom.angle = ang
				P_InstaThrust(boom, boom.angle, P_RandomRange(16, 64)*FRACUNIT)
				boom.momz = P_RandomRange(6, 16)*FRACUNIT
				boom.scale = FRACUNIT*3/2
				P_StartQuake(FRACUNIT*3,5)
			end
			if timer == 66
				damageObject(target)
				playSound(mo.battlen, sfx_megi6)
			end
		elseif timer == 100
			return true
		end
	end,
}

-- Fusion Skills
local EmberFusions_BTL_splitSkills = BTL_splitSkills
BTL_splitSkills = function(v)
	if server.gamemode ~= GM_PVP 
	and server.gamemode ~= GM_VOIDRUN
		if v.skin == "ember" 
		and #v.allies_noupdate
			if bionis and v.level >= 28
				for i = 1, #v.allies_noupdate
					if not v.allies_noupdate[i] or not v.allies_noupdate[i].valid then continue end
					if v.allies_noupdate[i].skin == "pmorshu"
						table.insert(v.skills, "slush fund e")
					end
				end
			end
			if v.level >= 68
				for i = 1, #v.allies_noupdate
					if not v.allies_noupdate[i] or not v.allies_noupdate[i].valid then continue end
					if v.allies_noupdate[i].skin == "shin"
						table.insert(v.skills, "fighting spirit e")
					end
				end
			end
			if v.level >= 77
				for i = 1, #v.allies_noupdate
					if not v.allies_noupdate[i] or not v.allies_noupdate[i].valid then continue end
					if v.allies_noupdate[i].skin == "voidy"
						table.insert(v.skills, "freikugel e")
					end
				end
			end
		end
		if v.skin == "shin" 
		and #v.allies_noupdate
			if v.level >= 68
				for i = 1, #v.allies_noupdate
					if not v.allies_noupdate[i] or not v.allies_noupdate[i].valid then continue end
					if v.allies_noupdate[i].skin == "ember"
						table.insert(v.skills, "fighting spirit s")
					end
				end
			end
		end
	end
	EmberFusions_BTL_splitSkills(v)
end

attackDefs["slush fund e"] = {
	name = "Slush Fund",
	type = ATK_SUPPORT,
	power = 0,
	accuracy = 999,
	statuschance = 999,
	status = COND_FREEZE,
	costtype = CST_SP,
	luckbased = true,
	cost = 24,
	desc = "Fusion (w/ Morshu) - \nInflicts Freeze on all enemies. \nDeploys Agiverse field.",
	target = TGT_ALLENEMIES,
	norogue = true,
	norandom = true,
	nometronome = true,
	norepel = true,
	nocast = function(targets, n, mo)
		local tgt = targets[n]
		local battlen = tgt.battlen
		local skincheck = "pmorshu"
		local checkteam = tgt.enemies
		local found
		mo.fusionpartner = false
		local fusioncost = ATK_getSkillCost(mo, attackDefs["slush fund e"])
		local can_afford
		local incapacitated
		for i = 1, #checkteam do
			if checkteam[i].skin == skincheck
				found = true
				mo.fusionpartner = checkteam[i]
				if mo.fusionpartner.sp and mo.fusionpartner.sp >= fusioncost
					can_afford = true
				end
				if mo.fusionpartner.down 
				or mo.fusionpartner.status_condition == COND_SHOCK 
				or mo.fusionpartner.status_condition == COND_BRAINWASH 
				or mo.fusionpartner.status_condition == COND_SLEEP 
				or mo.fusionpartner.status_condition == COND_RAGE
					incapacitated = true
					break
				end
			end
		end
		if not found
			BTL_logMessage(battlen, "Morshu is not alive.")
			playSound(battlen, sfx_not)
			return true
		elseif not can_afford
			BTL_logMessage(battlen, mo.fusionpartner.name.." has insufficient SP.")
			playSound(battlen, sfx_not)
			return true
		elseif incapacitated
			BTL_logMessage(battlen, mo.fusionpartner.name.." can't think for themselves right now.")
			playSound(battlen, sfx_not)
			return true
		end
	end,
	hudfunc = function(v, mo, timer)
		for i = 1, #mo.allies do
			local target = mo.allies[i]
			local firstt = TICRATE - timer
			local t = (TICRATE - (firstt*2))
			local t2 = (t<<FRACBITS)/3
			local t3 = t2
			local scale = t*FRACUNIT/6
			local trflag = V_70TRANS
			if firstt < 15
				trflag = V_90TRANS - (V_10TRANS)
			end
			if scale > 0
			and timer < TICRATE
				v.drawScaled(160<<FRACBITS, 100<<FRACBITS, scale, v.cachePatch("H_1M_B"), trflag)
				v.drawScaled(160<<FRACBITS, 100<<FRACBITS, scale, v.cachePatch("H_1M_C"))
			end
			t3 = FixedMul(t3, t3)
			t3 = $+ FixedMul(t3, t2)
			local pp = v.cachePatch(charStats[mo.skin] and charStats[mo.skin].hudaoa or "")
			if mo.status_condition == COND_SUPER
			and charStats[mo.skin] and charStats[mo.skin].hudsaoa
				pp = v.cachePatch(charStats[mo.skin].hudsaoa)
			end
			if timer <100
				v.drawScaled((150)<<FRACBITS + t3/3, (80)<<FRACBITS +t3/8, FRACUNIT/2, pp, V_SNAPTOLEFT, v.getColormap(TC_DEFAULT, mo.color))
				pp = v.cachePatch(charStats["pmorshu"] and charStats["pmorshu"].hudaoa or "ember")
				if target.skin == "pmorshu"
					v.drawScaled((150)<<FRACBITS - t3/3, (80)<<FRACBITS -t3/7, FRACUNIT/2, pp, V_SNAPTOLEFT, v.getColormap(TC_DEFAULT, target.color))
				end
			end
		end
	end,
	anim = function(mo, targets, hittargets, timer)
			for i = 1, #mo.allies do
				local target = mo.allies[i]
				if timer == 1
					if target.skin == "pmorshu"
						VFX_Play(target, VFX_AOADO)
						local fusioncost = ATK_getSkillCost(mo, attackDefs["slush fund e"])
						damageSP(target, fusioncost)
					end
				elseif timer >= 1
					if target.skin == "ember"
						summonAura(target, SKINCOLOR_TEAL)
					end
					if target.skin == "pmorshu"
						summonAura(target, SKINCOLOR_TEAL)
					end
				end
			end
			if timer == 1
				mo.fangle = 0
				mo.fdist = 400
				mo.columns = {}
				playSound(mo.battlen, sfx_aoado)
				VFX_Play(target, VFX_AOADO)
			end
			for i = 1, #hittargets
				local target = hittargets[i]
				local t = timer - (i-1)*6
				if t == 10
					playSound(mo.battlen, sfx_absorb)
				end
				if t <= 30
					local thok = P_SpawnMobj(target.x+P_RandomRange(-70, 70)*FRACUNIT, target.y+P_RandomRange(-70, 70)*FRACUNIT, target.z+P_RandomRange(0, 50)*FRACUNIT, MT_DUMMY)
					thok.state = S_CDUST1
					thok.momz = P_RandomRange(3, 10)*FRACUNIT
					thok.color = SKINCOLOR_ICY
					thok.tics = P_RandomRange(10, 35)
					thok.scale = FRACUNIT*3/2
				end
				if t == 20
					damageObject(target)
					startField(target, FLD_AGIVERSE, 4)
				end
			end
			if timer == 42 + (#hittargets-1)*6
				return true
			end
		end,
}

attackDefs["fighting spirit e"] = {
	name = "Fighting Spirit",
	type = ATK_SUPPORT,
	costtype = CST_SP,
	cost = 80,
	desc = "Fusion (w/ Shin) - \nGives Power Charge to \nall allies.",
	target = TGT_ALLALLIES,
	superbuff = true,
	powercharge = true,
	norogue = true,
	norandom = true,
	nometronome = true,
	nocast = function(targets, n, mo)
		local tgt = targets[n]
		local battlen = tgt.battlen
		local skincheck = "shin"
		local checkteam = tgt.allies
		local found
		mo.fusionpartner = false
		local fusioncost = ATK_getSkillCost(mo, attackDefs["fighting spirit e"])
		local can_afford
		local incapacitated
		for i = 1, #checkteam do
			if checkteam[i].skin == skincheck
				found = true
				mo.fusionpartner = checkteam[i]
				if mo.fusionpartner.sp and mo.fusionpartner.sp >= fusioncost
					can_afford = true
				end
				if mo.fusionpartner.down 
				or mo.fusionpartner.status_condition == COND_SHOCK 
				or mo.fusionpartner.status_condition == COND_BRAINWASH 
				or mo.fusionpartner.status_condition == COND_SLEEP 
				or mo.fusionpartner.status_condition == COND_RAGE
					incapacitated = true
					break
				end
			end
		end
		if not found
			BTL_logMessage(battlen, "Shin is not alive.")
			playSound(battlen, sfx_not)
			return true
		elseif not can_afford
			BTL_logMessage(battlen, mo.fusionpartner.name.." has insufficient SP.")
			playSound(battlen, sfx_not)
			return true
		elseif incapacitated
			BTL_logMessage(battlen, mo.fusionpartner.name.." can't think for themselves right now.")
			playSound(battlen, sfx_not)
			return true
		elseif mo.powercharge
			BTL_logMessage(battlen, "Maybe use your Power Charge first.")
			playSound(battlen, sfx_not)
			return true
		end
	end,
	hudfunc = function(v, mo, timer)
		for i = 1, #mo.allies do
			local target = mo.allies[i]
			local firstt = TICRATE - timer
			local t = (TICRATE - (firstt*2))
			local t2 = (t<<FRACBITS)/3
			local t3 = t2
			local scale = t*FRACUNIT/6
			local trflag = V_70TRANS
			if firstt < 15
				trflag = V_90TRANS - (V_10TRANS)
			end
			if scale > 0
			and timer < TICRATE
				v.drawScaled(160<<FRACBITS, 100<<FRACBITS, scale, v.cachePatch("H_1M_B"), trflag)
				v.drawScaled(160<<FRACBITS, 100<<FRACBITS, scale, v.cachePatch("H_1M_C"))
			end
			t3 = FixedMul(t3, t3)
			t3 = $+ FixedMul(t3, t2)
			local pp = v.cachePatch(charStats[mo.skin] and charStats[mo.skin].hudaoa or "")
			if mo.status_condition == COND_SUPER
			and charStats[mo.skin] and charStats[mo.skin].hudsaoa
				pp = v.cachePatch(charStats[mo.skin].hudsaoa)
			end
			if timer <100
				v.drawScaled((150)<<FRACBITS + t3/3, (80)<<FRACBITS +t3/8, FRACUNIT/2, pp, V_SNAPTOLEFT, v.getColormap(TC_DEFAULT, mo.color))
				pp = v.cachePatch(charStats["shin"] and charStats["shin"].hudaoa or "ember")
				if target.skin == "shin"
					v.drawScaled((150)<<FRACBITS - t3/3, (80)<<FRACBITS -t3/7, FRACUNIT/2, pp, V_SNAPTOLEFT, v.getColormap(TC_DEFAULT, target.color))
				end
			end
		end
	end,
	anim = function(mo, targets, hittargets, timer)
		for i = 1, #mo.allies do
			local target = mo.allies[i]
			if timer == 1
				if target.skin == "shin"
					VFX_Play(target, VFX_AOADO)
					local fusioncost = ATK_getSkillCost(mo, attackDefs["fighting spirit e"])
					damageSP(target, fusioncost)
				end
			elseif timer >= 1
				if target.skin == "ember"
					summonAura(target, SKINCOLOR_TEAL)
				end
				if target.skin == "shin"
					summonAura(target, SKINCOLOR_TEAL)
				end
			end
		end
		if timer == 1
			mo.fangle = 0
			mo.fdist = 400
			mo.columns = {}
			playSound(mo.battlen, sfx_aoado)
			VFX_Play(target, VFX_AOADO)
		end
		for i = 1, #targets do
			local target = targets[i]
			if timer == 20 + (i-1)*16
				playSound(mo.battlen, sfx_buff2)
				target.powercharge = true
				BTL_logMessage(targets[1].battlen, target.name.." is building up Strength...")
				for i = 1,16
					local dust = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
					dust.angle = ANGLE_90 + ANG1* (22*(i-1))
					dust.state = S_CDUST1
					P_InstaThrust(dust, dust.angle, 30*FRACUNIT)
					dust.color = SKINCOLOR_RED
					dust.scale = FRACUNIT*2
				end
			elseif timer > 20 + (i-1)*16 and timer <= 50 + (i-1)*16
				if leveltime%2 == 0
					for i = 1,16
						local thok = P_SpawnMobj(target.x+P_RandomRange(-70, 70)*FRACUNIT, target.y+P_RandomRange(-70, 70)*FRACUNIT, target.z+P_RandomRange(0, 50)*FRACUNIT, MT_DUMMY)
						thok.state = S_CDUST1
						thok.momz = P_RandomRange(3, 10)*FRACUNIT
						thok.color = SKINCOLOR_RED
						thok.tics = P_RandomRange(10, 35)
						thok.scale = FRACUNIT*3/2
					end
				end
				for i = 1, 8
					local thok = P_SpawnMobj(target.x+P_RandomRange(-70, 70)*FRACUNIT, target.y+P_RandomRange(-70, 70)*FRACUNIT, target.z+P_RandomRange(0, 50)*FRACUNIT, MT_DUMMY)
					thok.sprite = SPR_SUMN
					thok.frame = F|FF_FULLBRIGHT|TR_TRANS50
					thok.momz = P_RandomRange(6, 16)*FRACUNIT
					thok.color = SKINCOLOR_RED
					thok.tics = P_RandomRange(10, 35)
				end
			end
		end
		if timer == 60 + (#targets-1)*16
			return true
		end
	end,
}

attackDefs["fighting spirit s"] = {
	name = "Fighting Spirit",
	type = ATK_SUPPORT,
	costtype = CST_SP,
	cost = 80,
	desc = "Fusion (w/ Ember) - \nGives Power Charge to \nall allies.",
	target = TGT_ALLALLIES,
	superbuff = true,
	powercharge = true,
	norogue = true,
	norandom = true,
	nometronome = true,
	nocast = function(targets, n, mo)
		local tgt = targets[n]
		local battlen = tgt.battlen
		local skincheck = "ember"
		local checkteam = tgt.allies
		local found
		mo.fusionpartner = false
		local fusioncost = ATK_getSkillCost(mo, attackDefs["fighting spirit s"])
		local can_afford
		local incapacitated
		for i = 1, #checkteam do
			if checkteam[i].skin == skincheck
				found = true
				mo.fusionpartner = checkteam[i]
				if mo.fusionpartner.sp and mo.fusionpartner.sp >= fusioncost
					can_afford = true
				end
				if mo.fusionpartner.down 
				or mo.fusionpartner.status_condition == COND_SHOCK 
				or mo.fusionpartner.status_condition == COND_BRAINWASH 
				or mo.fusionpartner.status_condition == COND_SLEEP 
				or mo.fusionpartner.status_condition == COND_RAGE
					incapacitated = true
					break
				end
			end
		end
		if not found
			BTL_logMessage(battlen, "Ember is not alive.")
			playSound(battlen, sfx_not)
			return true
		elseif not can_afford
			BTL_logMessage(battlen, mo.fusionpartner.name.." has insufficient SP.")
			playSound(battlen, sfx_not)
			return true
		elseif incapacitated
			BTL_logMessage(battlen, mo.fusionpartner.name.." can't think for themselves right now.")
			playSound(battlen, sfx_not)
			return true
		elseif mo.powercharge
			BTL_logMessage(battlen, "Maybe use your Power Charge first.")
			playSound(battlen, sfx_not)
			return true
		end
	end,
	hudfunc = function(v, mo, timer)
		for i = 1, #mo.allies do
			local target = mo.allies[i]
			local firstt = TICRATE - timer
			local t = (TICRATE - (firstt*2))
			local t2 = (t<<FRACBITS)/3
			local t3 = t2
			local scale = t*FRACUNIT/6
			local trflag = V_70TRANS
			if firstt < 15
				trflag = V_90TRANS - (V_10TRANS)
			end
			if scale > 0
			and timer < TICRATE
				v.drawScaled(160<<FRACBITS, 100<<FRACBITS, scale, v.cachePatch("H_1M_B"), trflag)
				v.drawScaled(160<<FRACBITS, 100<<FRACBITS, scale, v.cachePatch("H_1M_C"))
			end
			t3 = FixedMul(t3, t3)
			t3 = $+ FixedMul(t3, t2)
			local pp = v.cachePatch(charStats[mo.skin] and charStats[mo.skin].hudaoa or "")
			if mo.status_condition == COND_SUPER
			and charStats[mo.skin] and charStats[mo.skin].hudsaoa
				pp = v.cachePatch(charStats[mo.skin].hudsaoa)
			end
			if timer <100
				v.drawScaled((150)<<FRACBITS + t3/3, (80)<<FRACBITS +t3/8, FRACUNIT/2, pp, V_SNAPTOLEFT, v.getColormap(TC_DEFAULT, mo.color))
				pp = v.cachePatch(charStats["ember"] and charStats["ember"].hudaoa or "shin")
				if target.skin == "ember"
					if target.status_condition == COND_SUPER
					and charStats[target.skin] and charStats[target.skin].hudsaoa
						pp = v.cachePatch(charStats[target.skin].hudsaoa)
					end
					v.drawScaled((150)<<FRACBITS - t3/3, (80)<<FRACBITS -t3/7, FRACUNIT/2, pp, V_SNAPTOLEFT, v.getColormap(TC_DEFAULT, target.color))
				end
			end
		end
	end,
	anim = function(mo, targets, hittargets, timer)
		for i = 1, #mo.allies do
			local target = mo.allies[i]
			if timer == 1
				if target.skin == "ember"
					VFX_Play(target, VFX_AOADO)
					local fusioncost = ATK_getSkillCost(mo, attackDefs["fighting spirit s"])
					damageSP(target, fusioncost)
				end
			elseif timer >= 1
				if target.skin == "shin"
					summonAura(target, SKINCOLOR_TEAL)
				end
				if target.skin == "ember"
					summonAura(target, SKINCOLOR_TEAL)
				end
			end
		end
		if timer == 1
			mo.fangle = 0
			mo.fdist = 400
			mo.columns = {}
			playSound(mo.battlen, sfx_aoado)
			VFX_Play(target, VFX_AOADO)
		end
		for i = 1, #targets do
			local target = targets[i]
			if timer == 20 + (i-1)*16
				playSound(mo.battlen, sfx_buff2)
				target.powercharge = true
				BTL_logMessage(targets[1].battlen, target.name.." is building up Strength...")
				for i = 1,16
					local dust = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
					dust.angle = ANGLE_90 + ANG1* (22*(i-1))
					dust.state = S_CDUST1
					P_InstaThrust(dust, dust.angle, 30*FRACUNIT)
					dust.color = SKINCOLOR_RED
					dust.scale = FRACUNIT*2
				end
			elseif timer > 20 + (i-1)*16 and timer <= 50 + (i-1)*16
				if leveltime%2 == 0
					for i = 1,16
						local thok = P_SpawnMobj(target.x+P_RandomRange(-70, 70)*FRACUNIT, target.y+P_RandomRange(-70, 70)*FRACUNIT, target.z+P_RandomRange(0, 50)*FRACUNIT, MT_DUMMY)
						thok.state = S_CDUST1
						thok.momz = P_RandomRange(3, 10)*FRACUNIT
						thok.color = SKINCOLOR_RED
						thok.tics = P_RandomRange(10, 35)
						thok.scale = FRACUNIT*3/2
					end
				end
				for i = 1, 8
					local thok = P_SpawnMobj(target.x+P_RandomRange(-70, 70)*FRACUNIT, target.y+P_RandomRange(-70, 70)*FRACUNIT, target.z+P_RandomRange(0, 50)*FRACUNIT, MT_DUMMY)
					thok.sprite = SPR_SUMN
					thok.frame = F|FF_FULLBRIGHT|TR_TRANS50
					thok.momz = P_RandomRange(6, 16)*FRACUNIT
					thok.color = SKINCOLOR_RED
					thok.tics = P_RandomRange(10, 35)
				end
			end
		end
		if timer == 60 + (#targets-1)*16
			return true
		end
	end,
}

attackDefs["freikugel e"] = {
	name = "Freikugel EX",
	type = ATK_ALMIGHTY,
	power = 1400,
	accuracy = 9999,
	costtype = CST_HPPERCENT,
	cost = 20,
	desc = "Fusion (w/ Voidy) - \nInsta-kill/Colossal Almighty dmg. \nCan only use if >1 foe remains.",
	target = TGT_ENEMY,
	norogue = true,
	norandom = true,
	nometronome = true,
	nocast = function(targets, n, mo)
		local tgt = targets[n]
		local battlen = tgt.battlen
		local skincheck = "voidy"
		local checkteam = tgt.enemies
		local checkenemies = tgt.allies
		local found
		mo.fusionpartner = false
		local fusioncost = ATK_getSkillCost(mo, attackDefs["freikugel e"])
		local can_afford
		local incapacitated
		for i = 1, #checkteam do
			if checkteam[i].skin == skincheck
				found = true
				mo.fusionpartner = checkteam[i]
				if mo.fusionpartner.hp and mo.fusionpartner.hp >= fusioncost
					can_afford = true
				end
				if mo.fusionpartner.down 
				or mo.fusionpartner.status_condition == COND_SHOCK 
				or mo.fusionpartner.status_condition == COND_BRAINWASH 
				or mo.fusionpartner.status_condition == COND_SLEEP 
				or mo.fusionpartner.status_condition == COND_RAGE
					incapacitated = true
					break
				end
			end
		end
		local remaining = 0
		for i = 1, #checkenemies do
			if checkenemies[i].hp
				remaining = $ + 1
			end
		end
		if not found
			BTL_logMessage(battlen, "Voidy is not alive.")
			playSound(battlen, sfx_not)
			return true
		elseif not can_afford
			BTL_logMessage(battlen, mo.fusionpartner.name.." has insufficient HP.")
			playSound(battlen, sfx_not)
			return true
		elseif incapacitated
			BTL_logMessage(battlen, mo.fusionpartner.name.." can't think for themselves right now.")
			playSound(battlen, sfx_not)
			return true
		elseif remaining == 1
			BTL_logMessage(battlen, "Only the 'Devil' can choose the bullet's last target...")
			playSound(battlen, sfx_not)
			return true
		end
	end,
	hudfunc = function(v, mo, timer)
		for i = 1, #mo.allies do
			local target = mo.allies[i]
			local firstt = TICRATE - timer
			local t = (TICRATE - (firstt*2))
			local t2 = (t<<FRACBITS)/3
			local t3 = t2
			local scale = t*FRACUNIT/6
			local trflag = V_70TRANS
			if firstt < 15
				trflag = V_90TRANS - (V_10TRANS)
			end
			if scale > 0
			and timer < TICRATE
				v.drawScaled(160<<FRACBITS, 100<<FRACBITS, scale, v.cachePatch("H_1M_B"), trflag)
				v.drawScaled(160<<FRACBITS, 100<<FRACBITS, scale, v.cachePatch("H_1M_C"))
			end
			t3 = FixedMul(t3, t3)
			t3 = $+ FixedMul(t3, t2)
			local pp = v.cachePatch(charStats[mo.skin] and charStats[mo.skin].hudaoa or "")
			if mo.status_condition == COND_SUPER
			and charStats[mo.skin] and charStats[mo.skin].hudsaoa
				pp = v.cachePatch(charStats[mo.skin].hudsaoa)
			end
			if timer <100
				v.drawScaled((150)<<FRACBITS + t3/3, (80)<<FRACBITS +t3/8, FRACUNIT/2, pp, V_SNAPTOLEFT, v.getColormap(TC_DEFAULT, mo.color))
				pp = v.cachePatch(charStats["voidy"] and charStats["voidy"].hudaoa or "ember")
				if target.skin == "voidy"
					if target.status_condition == COND_SUPER
					and charStats[target.skin] and charStats[target.skin].hudsaoa
						pp = v.cachePatch(charStats[target.skin].hudsaoa)
					end
					v.drawScaled((150)<<FRACBITS - t3/3, (80)<<FRACBITS -t3/7, FRACUNIT/2, pp, V_SNAPTOLEFT, v.getColormap(TC_DEFAULT, target.color))
				end
			end
		end
	end,
	anim = function(mo, targets, hittargets, timer)
		for i = 1, #mo.allies do
			local target = mo.allies[i]
			if timer == 1
				if target.skin == "voidy"
					VFX_Play(target, VFX_AOADO)
					if not (target.boss)
						local fusioncost = ATK_getSkillCost(mo, attackDefs["freikugel e"])
						target.hp = $ - fusioncost
					end
				end
			elseif timer >= 1
				if target.skin == "ember"
					summonAura(target, SKINCOLOR_TEAL)
				end
				if target.skin == "voidy"
					summonAura(target, SKINCOLOR_TEAL)
				end
			end
		end
		if timer == 1
			mo.fangle = 0
			mo.fdist = 400
			mo.columns = {}
			playSound(mo.battlen, sfx_aoado)
			VFX_Play(target, VFX_AOADO)
		end
		local target = hittargets[1]
		if timer == 20
			local sun = P_SpawnMobj(mo.x,mo.y,mo.z + FRACUNIT*120,MT_DUMMY)
			sun.sprite = SPR_NTHK
			sun.frame = A|FF_FULLBRIGHT
			sun.color = SKINCOLOR_PEACHY
			sun.scale = FRACUNIT*2
			sun.tics = -1
			mo.sun = sun
			playSound(mo.battlen, sfx_s3k84)
		elseif timer >= 20 and timer <= 40
			if mo.sun and mo.sun.valid
				local h_angle = P_RandomRange(1, 359)*ANG1
				local v_angle = P_RandomRange(1, 359)*ANG1
				local dist = 256
				local spd = P_RandomRange(40, 50)
				local s_x = mo.sun.x+ dist*FixedMul(cos(h_angle), cos(v_angle))
				local s_y = mo.sun.y+ dist*FixedMul(sin(h_angle), cos(v_angle))
				local s_z = (mo.sun.z+mo.sun.height/2)+ dist* sin(v_angle)
				local s = P_SpawnMobj(s_x, s_y, s_z, MT_DUMMY)
				s.frame = A|FF_FULLBRIGHT
				s.color = SKINCOLOR_PEACHY
				s.scale = FRACUNIT*3/2
				s.destscale = FRACUNIT/5
				s.target = mo.sun
				s.tics = 10
				s.momx = (mo.sun.x - s.x)/10
				s.momy = (mo.sun.y - s.y)/10
				s.momz = (mo.sun.z - s.z)/10
			end
		elseif timer >= 40 and timer <= 50
			local cx = mo.sun.x + 1*cos(mo.sun.angle + ANG1*90)
            local cy = mo.sun.y + 1*sin(mo.sun.angle + ANG1*90)
            local stinger = P_SpawnMobj(cx, cy, mo.sun.z, MT_DUMMY)  
            stinger.frame = A|FF_FULLBRIGHT
			stinger.color = SKINCOLOR_PEACHY
			stinger.scale = FRACUNIT*3
            stinger.momx = (target.x - stinger.x)/2
            stinger.momy = (target.y - stinger.y)/2
            stinger.momz = (target.z - stinger.z)/2
			stinger.fuse = 20
			local stinger = P_SpawnMobj(cx, cy, mo.sun.z, MT_DUMMY)  
            stinger.frame = A|FF_FULLBRIGHT
			stinger.color = SKINCOLOR_PEACHY
			stinger.scale = FRACUNIT*3
            stinger.momx = (target.x - stinger.x)/2
            stinger.momy = (target.y - stinger.y)/2
            stinger.momz = (target.z - stinger.z)/2
			stinger.fuse = 20
			local stinger = P_SpawnMobj(cx, cy, mo.sun.z, MT_DUMMY)  
            stinger.frame = A|FF_FULLBRIGHT
			stinger.color = SKINCOLOR_PEACHY
			stinger.scale = FRACUNIT*3
            stinger.momx = (target.x - stinger.x)/2
            stinger.momy = (target.y - stinger.y)/2
            stinger.momz = (target.z - stinger.z)/2
			stinger.fuse = 20
			if timer == 45
				if not target.boss
					damageObject(target, 9999)
				else
					damageObject(target)
				end
				localquake(mo.battlen, FRACUNIT*64, 10)
				playSound(mo.battlen, sfx_s3k54)
				playSound(mo.battlen, sfx_trfire)
				playSound(mo.battlen, sfx_hamas2)
			end
		end
		if timer == 70
			if mo.sun and mo.sun.valid
				mo.sun.fuse = 20
				mo.sun.destscale = 1
				mo.sun.scalepseed = FRACUNIT/20
				mo.sun = nil
			end
			return true
		end
	end,
}

-- Trait
personaList["scathach"].trait = "unfaltering justice"

attackDefs["unfaltering justice"] = {
	name = "Unfaltering Justice",
	type = ATK_PASSIVE,
	desc = "50% chance of immediately getting \nback up from downed for all allies. \nAttacker will not receive a 1More.",
	passive = PSV_ONDAMAGE_RECEIVED,
	norogue = true,
	norandom = true,
	anim = function(mo, target)
		local btl = server.P_BattleStatus[mo.battlen]
		if target.attack 
		and mo.damagestate ~= DMG_MISS 
		and mo.damagestate ~= DMG_BLOCK 
		and mo.damagestate ~= DMG_DRAIN 
		and btl.turnorder[1] ~= mo 
		and mo.down 
		and P_RandomRange(0, 100) < 50
			mo.down = nil
			target.setonemore = nil
			BTL_logMessage(mo.battlen, "Unfaltering Justice activated!")
		end
	end,
}

local EmberTrait = BTL_splitSkills
BTL_splitSkills = function(v)
	if v.allies and #v.allies and PersonaTraits
        local justice_check = false
        for i = 1, #v.allies
            if not v.allies[i] or not v.allies[i].valid then continue end
            local ally = v.allies[i]
            if ally.persona and ally.persona.trait and ally.persona.trait == "unfaltering justice"
                justice_check = true
            end
        end
        if justice_check
            table.insert(v.skills, "unfaltering justice")
        end
    end
	EmberTrait(v)
end