-- Persona Support --

if not srb2p return end

charStats["flchan"] = {
	name = "FL Chan",
	basehp = 52,
	basesp = 110,
	persona = "flchan",
	melee_natk = "flchan_atk1",
	atk = 25,
	acc = 75,
	crit = 5,
	anim_stand = {SPR_PLAY, A, 8, "SPR2_STND"},
	anim_stand_hurt = {},
	anim_stand_bored = {SPR_PLAY, A, B, 15, "SPR2_WAIT"},
	anim_guard = {SPR_PLAY, C, 2, "SPR2_RUN"},
	anim_move = {SPR_PLAY, A, B, C, D, E, F, G, H, 2, "SPR2_WALK"},
	anim_run = {SPR_PLAY, A, B, C, D, E, F, G, H, 2, "SPR2_RUN"},
	anim_atk = {SPR_PLAY, A, B, C, D, E, F, G, H, 2, "SPR2_ROLL"},
	anim_aoa_end = {SPR_PLAY, H, G, F, E, D, C, B, A, 2, "SPR2_ROLL"},
	anim_hurt = {SPR_PLAY, A, 35, "SPR2_PAIN"},
	anim_getdown = {},
	anim_downloop = {},
	anim_getup = {SPR_PLAY, A, 1, "SPR2_SPNG"},
	anim_death = {SPR_PLAY, A, 30, "SPR2_DEAD"},
	anim_revive = {SPR_PLAY, A, 1, "SPR2_SPNG"},
	anim_evoker = {SPR_PLAY, A, 20, "SPR2_BACT"},
	anim_evoker_shoot = {SPR_PLAY, B, 20, "SPR2_BACT"},
	anim_special1 = {SPR_PLAY, A, B, C, D, E, 2, "SPR2_MICG"},
	anim_special2 = {SPR_PLAY, A, B, C, D, E, F, G, H, 2, "SPR2_CNT4"},
	vfx_summon = {},
    vfx_skill = {},
    vfx_item = {},
    vfx_hurt = {},
    vfx_hurtx = {},
    vfx_die = {},
    vfx_heal = {},
    vfx_healself = {},
    vfx_kill = {},
    vfx_1more = {},
    vfx_crit = {},
    vfx_aoaask = {},
    vfx_aoado = {},
    vfx_aoarelent = {},
    vfx_miss = {},
    vfx_dodge = {},
    vfx_win = {},
    vfx_levelup = {},
	icon = "ICO_FLCH",
	hudbust = "H_FLCBAR",
	hudaoa = "H_FLCAOA",
	aoa_quote = "Let's make these guys \nchange their tune! \n(Get it?)",
	hudcutin = "FLCH_A",
	tip = "This cutie learns Bless, Psy, and Fire \nwith most of her other skills being \nsupports that can inflict various status \nconditions to enemies. She has an \nextremely high SP to make up for her \nlow HP, so go nuts with it!"
}

personaList["flchan"] = {
	name = "FL Chan",
	arcana = nil,
	sprite = SPR_FUNK,
	startframe = 0,
	anim_idle = {},
	anim_atk = {},
	strength = 5,
	magic = 3,
	endurance = 10,
	luck = 9,
	agility = 13,
	weak = ATK_SLASH, -- She hates it when the music suddenly cuts off
	resist = ATK_FIRE, -- While the mixtape may be fire, hers will always be even more fire 
	block = ATK_BLESS, -- She's used to partying with bright lights
	repel = ATK_PSY, -- She converts Psy energy into lofi hip-hop
	drain = nil,
	skills = {
		{"kouha", 1}, {"psio", 2},
		{"agidyne", 5}, {"marin karin", 10},
		{"heat riser", 15}, {"pulinpa", 20},
		{"foolish whisper", 25}, {"dormina", 30},
		
		{"makouha", 31, "kouha"}, {"mapsio", 32, "psio"},
		{"maragidyne", 35, "agidyne"}, {"sexy dance", 40, "marin karin"},
		{"cheer", 45, "heat riser"}, {"tentarafoo", 50, "pulinpa"},
		{"makajamon", 55, "foolish whisper"}, {"asmr", 60, "dormina"},
	},
}

-- Bionis support
if bionis then
	personaList["flchan"].drain = ATK_WATER -- Since she dances all the time, she appreciates a drink of water
end

-- Her melee attack (a modified version of Heat Wave)
attackDefs["flchan_atk1"] = {
	name = "Mic Drop",
	type = ATK_ALMIGHTY,
	power = 45,
	accuracy = 999,
	statuschance = 10,
	status = COND_SHOCK,
	costtype = CST_HP,
	cost = 0,
	desc = "A hard-hitting beat in \nthe truest sense.\nMay inflict shock.",
	target = TGT_ALLENEMIES,
	technical = COND_SILENCE|COND_SLEEP,
	physical = true,
	anim_norepel = true,
	anim = function(mo, targets, hittargets, timer)
		if timer == TICRATE/3
			ANIM_set(mo, mo.anim_special1, false)
		end
		if timer == TICRATE/2
		or timer == TICRATE/2 + 8
			if timer == TICRATE/2
				localquake(mo.battlen, 30*FRACUNIT, 5)
				playSound(mo.battlen, sfx_pstop)
			end
			local ang = 0
			for i = 1, 24 do
				local m = P_SpawnMobj(mo.x, mo.y, mo.z, MT_DUMMY)
				m.state = S_MUSICNOTE2
				m.scale = FRACUNIT/2
				m.fuse = TICRATE
				m.destscale = FRACUNIT*4
				m.friction = FRACUNIT
				m.angle = ang
				P_InstaThrust(m, m.angle, 50*FRACUNIT)
				m = P_SpawnMobj(mo.x, mo.y, mo.z, MT_DUMMY)
				m.state = S_QUICKBOOM1
				m.scale = FRACUNIT
				m.fuse = TICRATE
				m.friction = FRACUNIT
				m.destscale = FRACUNIT*4
				m.angle = ang
				m.color = SKINCOLOR_LAVENDER
				P_InstaThrust(m, m.angle, 60*FRACUNIT)
				for i = 1, 8
					m = P_SpawnMobj(mo.x, mo.y, mo.z + (mo.height*2), MT_DUMMY)
					m.state = S_MUSICNOTE1
					m.fuse = TICRATE
					m.friction = FRACUNIT
					m.scale = FRACUNIT
					m.destscale = FRACUNIT*4
					m.angle = ang + P_RandomRange(-15, 15)*ANG1
					P_InstaThrust(m, m.angle, 50*FRACUNIT + P_RandomRange(-16, 16)*FRACUNIT)
				end
				ang = $ + (360/24)*ANG1
			end
		end
		if timer == TICRATE/2 + 10
			for k,v in ipairs(hittargets)
				damageObject(v)
			end
		end
		if timer == TICRATE*2
			return true
		end
	end,
}

-- It's pretty much Heat Riser, but it affects all allies (seriously, how is this NOT in the base game)
attackDefs["cheer"] = {
	name = "Cheer",
	type = ATK_SUPPORT,
	costtype = CST_SP,
	cost = 48,
	desc = "Raise all allies' stats by \n1 stage. GO TEAM!",
	target = TGT_ALLALLIES,
	superbuff = true,
	nocast = 	function(targets, n)
					local target = targets[n]
					if target.buffs["atk"][1] >= 75
					and target.buffs["mag"][1] >= 75
					and target.buffs["agi"][1] >= 75
					and target.buffs["def"][1] >= 75
						BTL_logMessage(targets[1].battlen, "Limit reached!")
						return true
					end
				end,
	anim = function(mo, targets, hittargets, timer)
		for i = 1, #targets do
			local target = targets[i]
			local colors = {SKINCOLOR_ORANGE, SKINCOLOR_TEAL, SKINCOLOR_LAVENDER, SKINCOLOR_EMERALD}
			if timer == 20
				if target.skin ~= "flchan" then
					ANIM_set(mo, mo.anim_special2, true)
				end
			end
			if timer == 20 + (i-1)*16
				playSound(mo.battlen, sfx_buff)
				buffStat(target, "atk")
				buffStat(target, "mag")
				buffStat(target, "def")
				buffStat(target, "agi")
				BTL_logMessage(targets[1].battlen, "All stats increased!")
				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_WHITE
					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_WHITE
						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 = colors[P_RandomRange(1, #colors)]
					thok.tics = P_RandomRange(10, 35)
				end
			end
		end
		if timer == 60 + (#targets-1)*16
			return true
		end
	end,
}

-- Yes, I really made this a thing
attackDefs["asmr"] = {
	name = "ASMR",
	type = ATK_SUPPORT,
	power = 0,
	accuracy = 25,
	statuschance = 25,
	status = COND_SLEEP,
	costtype = CST_SP,
	luckbased = true,
	cost = 12,
	desc = "Low chance of inflicting \nSleep on all enemies.",
	target = TGT_ALLENEMIES,
	anim = function(mo, targets, hittargets, timer)
			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_SILVER
					thok.tics = P_RandomRange(10, 35)
					thok.scale = FRACUNIT*3/2
				end
				if t == 20
					damageObject(target)
				end
			end
			if timer == 42 + (#hittargets-1)*6
				return true
			end
	end,
}

-- Allows other players to use Cheer
itemDefs["pom-poms"] = {
	name = "Pom-Poms",
	desc = "Raise all allies' stats by \n1 stage. GO TEAM!",
	nouse = true,
	attack = "cheer",
}

-- The higher you go, the less chance you have of getting the item
table.insert(tartarus_items[1], {"pom-poms", 30})
table.insert(tartarus_items[blockfloor[BLOCK_YABBASHAH]], {"pom-poms", 20})
table.insert(tartarus_items[blockfloor[BLOCK_HARABAH]], {"pom-poms", 10})

-- Allows other players to be ASMRtists
itemDefs["binaural mic"] = {
	name = "Binaural Mic",
	desc = "Low chance of inflicting \nSleep on all enemies.",
	nouse = true,
	attack = "asmr",
}

table.insert(tartarus_items[1], {"binaural mic", 30})
table.insert(tartarus_items[blockfloor[BLOCK_YABBASHAH]], {"binaural mic", 20})
table.insert(tartarus_items[blockfloor[BLOCK_HARABAH]], {"binaural mic", 10})

-- Stuff for the battles
enemyList["flchan_tier1"] = {
	name = "FL Chan?",
	level = 30,
	hp = 1000,
	sp = 1000,
	strength = 15,
	magic = 9,
	endurance = 30,
	agility = 39,
	luck = 27,
	melee_natk = "flchan_atk1",
	boss = true,
	skin = "flchan",
	color = SKINCOLOR_BLACK,
	hudcutin = "FLCH_A",
	weak = ATK_SLASH,
	resist = ATK_FIRE,
	block = ATK_BLESS,
	repel = ATK_PSY,
	drain = nil,
	skills = {"kouha", "psio", "agidyne", "marin karin", "heat riser", "pulinpa", "foolish whisper", "dormina"},
}

enemyList["flchan_tier2"] = {
	name = "FL Chan?",
	level = 60,
	hp = 2000,
	sp = 2000,
	strength = 30,
	magic = 18,
	endurance = 60,
	agility = 78,
	luck = 54,
	melee_natk = "flchan_atk1",
	boss = true,
	skin = "flchan",
	color = SKINCOLOR_BLACK,
	hudcutin = "FLCH_A",
	weak = ATK_SLASH,
	resist = ATK_FIRE,
	block = ATK_BLESS,
	repel = ATK_PSY,
	drain = nil,
	skills = {"makouha", "mapsio", "maragidyne", "sexy dance", "cheer", "tentarafoo", "makajamon", "asmr"},
}

enemyList["metalsonic_fl2"] = {
	name = "Metal Sonic?",
	level = 60,
	hp = 2000,
	sp = 2000,
	strength = 66,
	magic = 36,
	endurance = 72,
	agility = 36,
	luck = 24,
	melee_natk = "metal_atk1",
	boss = true,
	skin = "metalsonic",
	color = SKINCOLOR_BLACK,
	hudcutin = "MSON_A",
	weak = ATK_ELEC|ATK_BLESS,
	resist = ATK_STRIKE|ATK_PIERCE|ATK_SLASH|ATK_NUCLEAR,
	block = nil,
	repel = nil,
	drain = nil,
	skills = {"masukukaja", "freila", "marakukaja", "matarukaja", "dekunda", "gigantic fist", "power charge", "heat wave"},
}

-- Battles
BTL_challengebtllist[#BTL_challengebtllist+1] = {
	name = "FL Chan (Tier I)",
	description = {"Fight FL Chan with all", "of her Tier I skills."},
	level = 30,
	music = "MBOSS1",
	time = TICRATE*600,
	items = nil,
	subpersonas = nil,
	waves = {
		{"flchan_tier1"}
	},
}

BTL_challengebtllist[#BTL_challengebtllist+1] = {
	name = "FL Chan (Tier II)",
	description = {"Fight FL Chan with all", "of her Tier II skills AND", "with Metal Sonic in tow."},
	level = 60,
	music = "EADVN1",
	time = TICRATE*900,
	items = nil,
	subpersonas = nil,
	waves = {
		{"flchan_tier2", "metalsonic_fl2"}
	},
}