-- SRB2 Persona Support for Cacee

if not srb2p return end
-- Due to the exe nature of the mod, this only requires a one-time check.

-- Define our base character's stats!
charStats["cacee"] = {

	-- GENERAL

	name = "Cacee",			-- This is only for bots / enemies
	basehp = 70,			-- base HP for level 1
	basesp = 30,
	persona = "polydeuces",
	persona_pvp = "polydeuces_pvp",
	melee_natk = "cacee_atk1",	-- normal melee attack

	supercolor_start = SKINCOLOR_SUPER_CACEE_1,

	atk = 35,
	acc = 999,
	crit = 2,
	
	wep = "cbg_01",
	weptype = WPT_KNUCKLES,
	-- ANIMS
	-- Anims are built like this:
	-- {SPR_SPRITE, frame1, frame2, frame3, ... , duration between each frame}

	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, C, D, E, F, G, H, A, B, C, D, E, F, G, H, 5, "SPR2_WAIT"},	-- standing (rare anim)
	anim_guard = 		{SPR_PLAY, A, 1, "SPR2_SKID"},		-- guarding
	anim_move =			{SPR_PLAY, A, B, C, D, E, F, G, H, 2, "SPR2_WALK"},		-- moving
	anim_run =			{SPR_PLAY, A, B, C, D, 2, "SPR2_RUN_"},	-- guess what
	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 of 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, 1, "SPR2_STUN"},		-- is down
	anim_getup =		{SPR_PLAY, C, 1, "SPR2_TWIN"},		-- gets up from down
	anim_death =		{SPR_PLAY, A, 30, "SPR2_PAIN"},		-- dies
	anim_revive =		{SPR_PLAY, C, 1, "SPR2_TWIN"},		-- gets revived
	anim_evoker =		{SPR_PLAY, B, 1, "SPR2_FROZ"},		-- holding evoker to head
	anim_evoker_shoot =	{SPR_PLAY, A, 1, "SPR2_CLMB"},		-- shooting evoker

	anim_special1 = {SPR_PLAY, A, B, 2, "SPR2_GLID"}, -- hammer prep
	anim_special2 = {SPR_PLAY, A, 2, "SPR2_MLEL"}, -- hammer swing
	
	vfx_summon = {"sfx_cepers", "sfx_cego"},	-- Summoning Persona to use a Skill
	vfx_skill = {"sfx_ceskl1", "sfx_ceskl2", "sfx_ceskl3"},		-- Used a Skill
	vfx_item = {"sfx_ceitem"},		-- Used an item
	vfx_hurt = {"sfx_ceoof", "sfx_ceouch"},		-- Sustained damage
	vfx_hurtx = {"sfx_ceyow", "sfx_cehey"},		-- Sustained heavy damage / Critical hit / Weakness
	vfx_die = {"sfx_cedead", "sfx_celose"},		-- Death
	vfx_heal = {"sfx_cehel1"},		-- Healed by teammate
	vfx_healself = {"sfx_cehel2", "sfx_cehel3"},	-- Healed self
	vfx_kill = {"sfx_cenmed"},		-- Killed an enemy
	vfx_1more = {"sfx_cecut", "sfx_cehit"},		-- Performed 1more
	vfx_crit = {"sfx_cecrit", "sfx_ceskl1"},		-- Cut-in for Weakness/Critical Hit
	vfx_aoaask = {"sfx_cecnfm"},	-- Ask to All-Out Attack
	vfx_aoado = {"sfx_ceallo"},		-- Performing All-Out Attack
	vfx_aoarelent = {"sfx_cenoal"},	-- Relenting from All-Out Attack
	vfx_miss = {"sfx_cemiss", "sfx_cenowy"},		-- Missed attack
	vfx_dodge = {"sfx_ceddge"},		-- Dodged enemy attack
	vfx_win = {"sfx_cewin1", "sfx_cewin2"},		-- Battle won
	vfx_levelup = {"sfx_celvl"},	-- Level Up!

	icon = "ICO_CACE",	-- icon for net select and other menus
	hudbust = "H_CACEBAR",			-- patch to draw on the stat hud
	hudbustlayer = "",		-- transparent patch to draw for status conditions
	hudaoa = "H_CACEAOA",	-- patch for all out attack hud
	aoa_quote = "All enemies are \ndown ese, shall \nwe dogpile?",
	hudcutin = "CACE_A",	-- cut in
	hudspr = "CACE",	-- sprite prefix since hud can't retrieve it. yikes

	tip = "Learns Strike, Electric and a handful \nof debuffing skills. An utiliy character \nthat can tank hits, but slow. \nYou have low SP, so use your \ndebuffs wisely and prioritize physical \nskills for offence.",

}

VFX_freeslotC("cacee")

attackDefs["cacee_atk1"] = {
	name = "Spike Rush Finisher",
	type = ATK_STRIKE,
	power = 45,
	accuracy = 85,
	critical = 7, -- was 7
	target = TGT_ENEMY,
	cost = CST_HP,
	cost = 0,
	desc = "A strong fisted ground pound.",
	anim_norepel = true,	-- do not bounce back our ANIMATION
	physical = true,	-- don't play the summoning anim for phys attacks, duh
	anim = 	function(mo, targets, hittargets, timer)
		local target = targets[1]
		if timer == 1
			ANIM_set(mo, mo.anim_special1, true)
			playSound(mo.battlen, sfx_cepun3)
			
			P_SpawnParaloop(mo.x, mo.y, mo.z,
			mo.radius*4, 8, MT_DUST, ANGLE_90, nil, true)

			-- fake A_LobShot:
			mo.angle = R_PointToAngle2(mo.x, mo.y, target.x, target.y)

			local z = mo.z
			local hit = P_SpawnMobj(target.x & (64*FRACUNIT -1), target.y & (64*FRACUNIT -1), target.subsector.sector.floorheight, MT_NULL)
			hit.tics = TICRATE

			local dist = P_AproxDistance(target.x - mo.x, target.y - mo.y)
			local horizontal = dist / TICRATE
			local vertical = FixedMul((gravity*TICRATE)/2, mo.scale)

			mo.momx = FixedMul(horizontal, cos(mo.angle))
			mo.momy = FixedMul(horizontal, sin(mo.angle))
			mo.momz = vertical


			-- move camera to an interresting spot

			local an = target.angle + 45*ANG1

			local cx = target.x + 384*cos(an)
			local cy = target.y + 384*sin(an)

			CAM_goto(server.P_BattleStatus[mo.battlen].cam, cx, cy, server.P_BattleStatus[mo.battlen].cam.z, 70*FRACUNIT)
			CAM_angle(server.P_BattleStatus[mo.battlen].cam, R_PointToAngle2(cx, cy, target.x, target.y), ANG1*4)
			--CAM_aiming(server.P_BattleStatus[mo.battlen].cam, -ANG1*10, ANG1)
		
		elseif timer < TICRATE and timer%2
			local ghost = P_SpawnGhostMobj(mo)
			ghost.colorized = true
			ghost.color = SKINCOLOR_SUPERGOLD2

		elseif timer == TICRATE
			damageObject(hittargets[1])
			ANIM_set(mo, mo.anim_special2, true)
			P_InstaThrust(mo, 0, 0)

			-- explode hearts all over!
			-- heart ring:
			for i = 1, 8
				local h = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
				h.state = S_SSPK1
				h.fuse = TICRATE
				P_InstaThrust(h, (360/8 *i)*ANG1, FRACUNIT*32)

				if i%2
					createSplat(mo)
				end
			end

			localquake(mo.battlen, FRACUNIT*30, 8)
			playSound(mo.battlen, sfx_cepun4)
			playSound(mo.battlen, sfx_cehit1)

			for i = 1, 16
				local h = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
				h.state = S_SSPK1
				h.fuse = TICRATE
				h.momx = P_RandomRange(-24, 24)*FRACUNIT
				h.momy = P_RandomRange(-24, 24)*FRACUNIT
				h.momz = P_RandomRange(2, 24)*FRACUNIT
			end
			
			local ghost = P_SpawnGhostMobj(mo)
			ghost.colorized = true
			ghost.color = SKINCOLOR_SUPERGOLD2
			ghost.destscale = $*16
			
		elseif timer == TICRATE*2
			return true
		end
	end,
}