-- Persona Support --
if not srb2p return end

-- Stats
charStats["motobug"] = {
	-- GENERAL
	name = "Motobug", -- Only for bots/enemies
	basehp = 45, -- Base HP/SP at level 1
	basesp = 55,
	persona = "hellbiker", -- Determines actual stats
	melee_natk = "motobug_atk1", -- Normal melee attack
	wep = "motobug_weapon1", -- Default weapon
	weptype = WPT_SHOES, -- Equippable weapon type(s)
	atk = 27, -- Attack power of physical attacks
	acc = 85, -- Accuracy of physical attacks
	crit = 3, -- Critical rate of physical attacks
	-- 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_ROLL"}, -- 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, 1, "SPR2_ROLL"}, -- Attacking
	anim_aoa_end = {SPR_PLAY, B, A, 1, "SPR2_ROLL"}, -- Jumping out from All Out Attack
	anim_hurt = {SPR_PLAY, A, 35, "SPR2_SPNG"}, -- Taking damage
	anim_getdown = {SPR_PLAY, B, 1, "SPR2_WAIT"}, -- Knocked down from weakness/crit
	anim_downloop = {SPR_PLAY, A, B, 15, "SPR2_CNT1"}, -- Is down
	anim_getup = {SPR_PLAY, B, A, 1, "SPR2_WAIT"}, -- Gets up from down
	anim_death = {SPR_PLAY, A, 30, "SPR2_DEAD"}, -- Dies
	anim_revive = {SPR_PLAY, A, B, 1, "SPR2_FALL"}, -- Gets revived
	anim_evoker = {SPR_PLAY, A, 2, "SPR2_CSMN"}, -- Uses evoker
	anim_evoker_shoot = {SPR_PLAY, B, C, D, E, F, G, H, I, J, K, L, M, L, K, 2, "SPR2_CSMN"},
	anim_special1 = {SPR_PLAY, A, B, C, 3, "SPR2_CALL"}, -- Custom stuff. Can have up to 32
	-- VOICES
	vfx_summon = {"sfx_mosum1", "sfx_mosum2", "sfx_mosum3"},
    vfx_skill = {"sfx_moskl1", "sfx_moskl2", "sfx_moskl3"},
    vfx_item = {"sfx_moitm1", "sfx_moitm2"},
    vfx_hurt = {"sfx_mohrt1", "sfx_mohrt2", "sfx_mohrt3"},
    vfx_hurtx = {"sfx_moxht1", "sfx_moxht2", "sfx_moxht3"},
    vfx_die = {"sfx_modie1", "sfx_modie2", "sfx_modie3"},
    vfx_heal = {"sfx_moheal"},
    vfx_healself = {"sfx_moheal"},
    vfx_kill = {"sfx_mokll1", "sfx_mokll2", "sfx_mokll3"},
    vfx_1more = {"sfx_mo1mor", "sfx_mo2mor"},
    vfx_crit = {"sfx_mocrt1", "sfx_mocrt2", "sfx_mocrt3"},
    vfx_aoaask = {"sfx_moask1", "sfx_moask2"},
    vfx_aoado = {"sfx_moaoa1", "sfx_moaoa2", "sfx_moaoa3"},
    vfx_aoarelent = {"sfx_morlt1", "sfx_morlt2"},
    vfx_miss = {"sfx_momss1", "sfx_momss2", "sfx_momss3"},
    vfx_dodge = {"sfx_modod1", "sfx_modod2", "sfx_modod3"},
    vfx_win = {"sfx_mowin1", "sfx_mowin2", "sfx_mowin3"},
    vfx_levelup = {"sfx_molvl1", "sfx_molvl2", "sfx_molvl3"},
	-- HUD/UI
	hudaoa = "H_MOTAOA", -- Patch for All Out Attack hud
	hudbust = "H_MOTBAR", -- Patch to draw on the stat hud
	icon = "ICO_MOTO", -- Icon for net select and other menus
	hudcutin = "MOTO_A", -- Cut in
	aoa_quote = "Don't mess with THIS \nMotobug!", -- Something to say when in a Hold-Up
	tip = "Learns Nuke and a Wind skill that acts as a Dekaja. His Rage skills will eventually land more often, allowing more opportunities for technical combos. Defense buffs and Dekunda also make him quite helpful in tanking hits." -- A brief description of how the character generally plays in battle
}

VFX_freeslotC("motobug")

-- Persona
personaList["hellbiker"] = {
	-- GENERAL
	name = "Hell Biker",
	arcana = ARCANA_HANGEDMAN,
	sprite = SPR_HBIK,
	startframe = 0,
	anim_idle = {SPR_HBIK, A, B, C, D, 3},
	anim_atk = {SPR_HBIK, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, 1},
	-- STATS (At level 10)
	strength = 5,
	magic = 9,
	endurance = 12,
	luck = 8,
	agility = 6,
	-- AFFINITIES
	resist = bionis and ATK_WIND|ATK_NUCLEAR|ATK_METAL or ATK_WIND|ATK_NUCLEAR,
	weak = bionis and ATK_ICE|ATK_WATER or ATK_ICE,
	-- SKILLSET
	skills = {
		{"frei", 1}, {"rakukaja", 5},
		{"mafrei", 14}, {"dekunda", 18},
		{"freila", 20}, {"provoke", 23},
		{"hell exhaust", 26}, {"nuke boost", 30},
		
		{"mafreila", 34, "frei"}, {"marakukaja", 38, "rakukaja"},
		{"infuriate", 42, "provoke"}, {"rage boost", 46, "mafrei"},
		{"freidyne", 52, "freila"}, {"nuke amp", 62, "nuke boost"},
		{"mafreidyne", 68, "mafreila"}, {"atomic flare", 77, "freidyne"},
		
		// Frei > Freila > Freidyne > Atomic Flare
		// Rakukaja > Marakukaja
		// Mafrei > Mafreila > Mafreidyne
		// Dekunda
		// Rage Boost
		// Provoke > Infuriate
		// Hell Exhaust
		// Nuke Boost > Nuke Amp
	},
}

-- Weapons
weaponsList["motobug_weapon1"] = {
	name = "Bettermonth Tire",
	type = WPT_SHOES,
	rarity = 1,
	element = nil,
	atk = 270,
	acc = 85,
	crit = 3,
	desc = "Motobug's starting weapon. \nA tire typically found on the underside of a \nMotobug capable of traversing grassy terrain.",
	slot = "technique 1",
}

weaponsList["motobug_weapon2"] = {
	name = "Spiked Tire",
	type = WPT_SHOES,
	rarity = 3,
	element = nil,
	atk = 810,
	acc = 85,
	crit = 3,
	desc = "Motobug's 2nd tier weapon. \nA tire that is lined with spikes to improve \nfriction, allowing traversal through ice and \nsnow.",
	ma = 1,
	en = 1,
	slot = "evade ice",
}

weaponsList["motobug_weapon3"] = {
	name = "Armored Tire",
	type = WPT_SHOES,
	rarity = 5,
	element = nil,
	atk = 1350,
	acc = 85,
	crit = 3,
	desc = "Motobug's 3rd tier weapon. \nA conveyor belt typically found on the \nunderside of a tank, acting as its tire. \nIt can traverse many kinds of terrain.",
	ma = 3,
	en = 3,
	slot = "merciless slayer",
}

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

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

-- Bionis Shop
table.insert(shopList["shop_bionis"].weapons, {makeWeapon("motobug_weapon1", 10), 800, nil, 4})
table.insert(shopList["shop_bionis"].weapons, {makeWeapon("motobug_weapon2", 10), 4000, 3})
table.insert(shopList["shop_bionis"].weapons, {makeWeapon("motobug_weapon3", 10), 12500, 6})

-- Skills
attackDefs["motobug_atk1"] = {
	name = "Command Troops",
	type = ATK_STRIKE,
	power = 27,
	accuracy = 85,
	critical = 3,
	target = TGT_ENEMY,
	costtype = CST_HP,
	cost = 0,
	desc = "Miniscule Strike damage to \none enemy. May inflict Dizzy \nif the attack misses.",
	anim_norepel = true,
	norepel = true,
	physical = 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
					mo.motos = {}
					CAM_stop(cam)
					mo.oldangle = mo.angle
					mo.angle = R_PointToAngle2(mo.x, mo.y, target.x, target.y)
					local tgtx = mo.x + 256*cos(mo.angle)
					local tgty = mo.y + 256*sin(mo.angle)
					P_TeleportMove(cam, tgtx, tgty, mo.z + FRACUNIT*16)
					cam.angle = R_PointToAngle2(cam.x, cam.y, mo.x, mo.y)
					ANIM_set(mo, mo.anim_special1)
				elseif timer == TICRATE
					local thean = R_PointToAngle2(target.x, target.y, mo.x, mo.y)
					local tgtx = target.x - 192*cos(thean)
					local tgty = target.y - 192*sin(thean)
					CAM_goto(cam, tgtx, tgty, target.z + FRACUNIT*64, FRACUNIT*20)
					CAM_angle(cam, thean)
				end
				if timer >= TICRATE*2/3
				and timer <= TICRATE*5/2
					if leveltime%5 == 0
						local ban = R_PointToAngle2(mo.x, mo.y, target.x, target.y)
						local an = ban + ANG1*180 + P_RandomRange(-35, 35)*ANG1
						local m = P_SpawnMobj(mo.x + 128*cos(an), mo.y + 128*sin(an), mo.z+2, MT_DUMMYMOTOBUG)
						m.flags = MF_NOGRAVITY
						m.angle = ban
						m.fuse = TICRATE*3/2
						P_InstaThrust(m, ban, 30*FRACUNIT)
						mo.motos[#mo.motos+1] = m
					end
				end
				if timer >= TICRATE and timer <= TICRATE*2
				and leveltime%5 == 0
					localquake(mo.battlen, FRACUNIT*10, TICRATE)
					createSplat(mo)
					local x = target.x + P_RandomRange(-40, 40)*FRACUNIT
					local y = target.y + P_RandomRange(-40, 40)*FRACUNIT
					local z = target.z + P_RandomRange(0, 30)*FRACUNIT
					playSound(mo.battlen, sfx_hit2)
					for i=1,16
						local b = P_SpawnMobj(x, y, z+2*FRACUNIT, MT_DUMMY)
						b.momx = P_RandomRange(-3, 3)*FRACUNIT
						b.momy = P_RandomRange(-3, 3)*FRACUNIT
						b.momz = P_RandomRange(4, 16)*FRACUNIT
						b.state = S_AOADUST1
						b.frame = A|FF_FULLBRIGHT
						b.scale = FRACUNIT*3
						b.destscale = FRACUNIT/12
					end
					for i=1,16
						local b = P_SpawnMobj(x, y, z+20*FRACUNIT, MT_DUMMY)
						b.momx = P_RandomRange(-8, 8)*FRACUNIT
						b.momy = P_RandomRange(-8, 8)*FRACUNIT
						b.momz = P_RandomRange(-8, 8)*FRACUNIT
						b.state = S_AOADUST1
						b.frame = A|FF_FULLBRIGHT
						b.scale = FRACUNIT*3
						b.destscale = FRACUNIT/12
					end
				end
				if timer == TICRATE*3/2
					damageObject(hittargets[1])
					if hittargets[1].damagestate == DMG_MISS
						if P_RandomRange(0, 100) < 50	
							inflictStatus(hittargets[1], COND_DIZZY)
						end
					end
				elseif timer == TICRATE*3
					for i = 1, #mo.motos
						if mo.motos[i] and mo.motos[i].valid
							P_RemoveMobj(mo.motos[i])
						end
					end
					mo.motos = nil
					return true
				end
			end,
}

attackDefs["hell exhaust"] = {
	name = "Hell Exhaust",
	type = ATK_WIND,
	power = 240,
	accuracy = 999,
	costtype = CST_HP,
	cost = 15,
	desc = "Medium Wind dmg \nto all enemies and \nnegates enemy buffs.",
	target = TGT_ALLENEMIES,
	dekaja = true,
	norogue = true,
	norandom = true,
	norepel = true,
	anim = function(mo, targets, hittargets, timer)
		local strs = {"atk", "mag", "def", "agi", "crit"}
		for k,e in ipairs(hittargets)
		local target = e
			if timer == 20
				playSound(mo.battlen, sfx_wind2)
				for i = 1, 10
					local g = P_SpawnMobj(target.x, target.y, target.z + P_RandomRange(0, 120)*FRACUNIT, MT_EXHAUST)
					g.target = target
					g.angle = FixedAngle(P_RandomRange(1, 360)*FRACUNIT)
					if i == 1 or i == 8
						g.jizzcolor = true
					end
					if i%2
						g.invertrotation = true
					end
					g.dist = P_RandomRange(45, 140)
					g.tics = 25
					g.lowquality = true
				end
			elseif timer == 30
			or timer == 33
			or timer == 36
			or timer == 39
				local s = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
				s.scale = FRACUNIT/4
				s.sprite = SPR_SLAS
				s.frame = I|TR_TRANS50 + P_RandomRange(0, 3)
				s.destscale = FRACUNIT*9
				s.scalespeed = FRACUNIT
				s.tics = TICRATE/3
			elseif timer == 40
				damageObject(target)
			elseif timer == 41
				playSound(mo.battlen, sfx_status)
				for j = 1, 16
					local orb = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
					orb.momx = P_RandomRange(-16, 16)<<FRACBITS
					orb.momy = P_RandomRange(-16, 16)<<FRACBITS
					orb.momz = P_RandomRange(-16, 16)<<FRACBITS
					orb.destscale = 0
					orb.frame = A
					orb.color = SKINCOLOR_MOSS
				end
				for j = 1, #strs
					local s = strs[j]
					if target.buffs[s][1] > 0
						target.buffs[s][1] = 0
						target.buffs[s][2] = 0
					end
				end
				BTL_logMessage(targets[1].battlen, "Stat increases nullified")
			end
		end
		if timer == 75 + 5*(#hittargets-1)
			return true
		end
	end,
}

-- Fusion Skills
local MotobugFusions_BTL_splitSkills = BTL_splitSkills
BTL_splitSkills = function(v)
	if server.gamemode ~= GM_PVP 
	and server.gamemode ~= GM_VOIDRUN
		if bionis 
		and v.skin == "motobug"
		and v.level >= 46 -- Learns Rage Boost
		and #v.allies_noupdate
			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 == "flchan"
					table.insert(v.skills, "banshee scream m")
				end
			end
		end
		if v.skin == "motobug"
		and v.level >= 52 -- Learns Freidyne
		and #v.allies_noupdate
			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, "mad inferno mot")
				end
			end
		end
		if v.skin == "motobug"
		and v.level >= 65 -- 3 levels past Nuke Amp
		and #v.allies_noupdate
			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 == "eggman"
					table.insert(v.skills, "high energy m")
				end
			end
		end
		if v.skin == "eggman"
		and v.level >= 65 -- Learns Curse Amp
		and #v.allies_noupdate
			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 == "motobug"
					table.insert(v.skills, "high energy e")
				end
			end
		end
	end
	MotobugFusions_BTL_splitSkills(v)
end

attackDefs["banshee scream m"] = {
	name = "Banshee's Scream",
	type = ATK_ALMIGHTY,
	power = 100,
	accuracy = 999,
	costtype = CST_SP,
	instakill = true,
	cost = 10,
	desc = "Fusion (w/ FL Chan) - \nInstantly kills foes inflicted \nwith any ailment.",
	target = TGT_ALLENEMIES,
	norogue = true,
	norandom = true,
	nocast = function(targets, n)
		local tgt = targets[n]
		local battlen = tgt.battlen
		local skincheck = "flchan"
		local checkteam = tgt.enemies
		local found
		for i = 1, #checkteam do
			if checkteam[i].skin == skincheck
				found = true
				break
			end
		end
		if not found
			BTL_logMessage(battlen, "You'll need FL Chan alive to cast this skill.")
			playSound(battlen, sfx_not)
			return true
		end
	end,
	hudfunc = 	function(v, mo, timer)
					if timer > 5
					and timer < TICRATE*3/2 + 1
						v.fadeScreen(0xFF00, 10)
					end
					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["flchan"] and charStats["flchan"].hudaoa or "motobug")
							if target.skin == "flchan"
								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)
		local avgx, avgy = 0, 0
		for i = 1, #targets
			avgx = $ + targets[i].x/FRACUNIT
			avgy = $ + targets[i].y/FRACUNIT
		end
		avgx = ($/#targets)	*FRACUNIT
		avgy = ($/#targets)	*FRACUNIT
		local cam = server.P_BattleStatus[mo.battlen].cam
		for i = 1, #mo.allies do
			local target = mo.allies[i]
			if timer == 1
				if target.skin == "flchan"
					VFX_Play(target, VFX_AOADO)
				end
			elseif timer >= 1
				if target.skin == "motobug"
					summonAura(target, SKINCOLOR_TEAL)
				end
				if target.skin == "flchan"
					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
		if timer == 1
			mo.oldangle = mo.angle
			mo.angle = R_PointToAngle2(mo.x, mo.y, avgx, avgy)
			local tgtx = mo.x + 256*cos(mo.angle)
			local tgty = mo.y + 256*sin(mo.angle)
			P_TeleportMove(cam, tgtx, tgty, mo.z + FRACUNIT*16)
			cam.angle = R_PointToAngle2(cam.x, cam.y, mo.x, mo.y)
			CAM_stop(cam)
		elseif timer == 5
			local thean = mo.angle
			local tgtx = avgx + 512*cos(thean)
			local tgty = avgy + 512*sin(thean)
			playSound(mo.battlen, sfx_howl1)
			localquake(mo.battlen, FRACUNIT*64, 10)
			CAM_goto(cam, tgtx, tgty, mo.z + FRACUNIT*128, FRACUNIT*20)
		elseif timer >= 5
		and timer <= TICRATE*3/2
			if leveltime%5 == 0
				local d = P_SpawnMobj(mo.x, mo.y, mo.z + FRACUNIT*64, MT_THOK)
				d.state = S_HOWL1
				d.color = SKINCOLOR_AETHER
				d.frame = $|FF_FULLBRIGHT
				d.angle = mo.angle + ANG1*90
				d.scale = mo.scale*2
				d.destscale = mo.scale*7
				d.scalespeed = FRACUNIT/4
			end
		elseif timer == TICRATE*3/2 + 1
			for i = 1, #hittargets
				if hittargets[i].status_condition and hittargets[i].status_condition < COND_HYPER
					damageObject(hittargets[i])
				end
			end
		elseif timer == TICRATE*3
			return true
		end
	end,
}

attackDefs["mad inferno mot"] = {
	name = "Mad Inferno",
	type = ATK_FIRE,
	power = 420,
	accuracy = 95,
	costtype = CST_SP,
	cost = 16,
	status = COND_RAGE,
	statuschance = 9999,
	desc = "Fusion (w/ Morshu) - \nx3 Medium Fire dmg to one enemy. \nGuarantees Rage if Motobug initiates.",
	target = TGT_ENEMY,
	hits = 3,
	norogue = true,
	norandom = true,
	nocast = function(targets, n)
		local tgt = targets[n]
		local battlen = tgt.battlen
		local skincheck = "pmorshu"
		local checkteam = tgt.enemies
		local found
		for i = 1, #checkteam do
			if checkteam[i].skin == skincheck
				found = true
				break
			end
		end
		if not found
			BTL_logMessage(battlen, "You'll need Morshu alive to cast this skill.")
			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 "motobug")
				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
		if timer > 80
		and timer < 90
			local t = timer-80
			local p = "H_ATR"..t/2
			if v.patchExists(p)
				drawScreenwidePatch(v, v.cachePatch(p))
			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)
				end
			elseif timer >= 1
				if target.skin == "motobug"
					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
		local target = hittargets[1]
		if timer == 1
			mo.fangle = 0
			mo.fdist = 400
			mo.columns = {}
		elseif timer == 15 
			local cx = target.x + 90*cos(target.angle)
			local cy = target.y + 90*sin(target.angle)
			local h = P_SpawnMobj(cx, cy, target.z, MT_DUMMY)
			h.state = S_INVISIBLE
			h.tics = -1
			mo.columns[#mo.columns+1] = h
		elseif timer == 30 
			local cx = target.x - 90*cos(target.angle + ANGLE_45)
            local cy = target.y - 90*sin(target.angle + ANGLE_45)
			local h = P_SpawnMobj(cx, cy, target.z, MT_DUMMY)
			h.state = S_INVISIBLE
			h.tics = -1
			mo.columns[#mo.columns+1] = h
		elseif timer == 45 
			local cx = target.x - 90*cos(target.angle - ANGLE_45)
            local cy = target.y - 90*sin(target.angle - ANGLE_45)
			local h = P_SpawnMobj(cx, cy, target.z, MT_DUMMY)
			h.state = S_INVISIBLE
			h.tics = -1
			mo.columns[#mo.columns+1] = h
		elseif timer == 60 
			damageObject(target)
			playSound(mo.battlen, sfx_s3k4e)
			local cx = target.x + 90*cos(target.angle)
			local cy = target.y + 90*sin(target.angle)
			local boom = P_SpawnMobj(cx, cy, target.z+20*FRACUNIT, MT_BOSSEXPLODE)
            boom.scale = FRACUNIT*2
            boom.state = S_FBOMB_EXPL1
			mo.columns[#mo.columns-1] = boom
		elseif timer == 75 
			damageObject(target)
			playSound(mo.battlen, sfx_s3k4e)
			local cx = target.x - 90*cos(target.angle + ANGLE_45)
			local cy = target.y - 90*sin(target.angle + ANGLE_45)
			local boom = P_SpawnMobj(cx, cy, target.z+20*FRACUNIT, MT_BOSSEXPLODE)
            boom.scale = FRACUNIT*2
            boom.state = S_FBOMB_EXPL1
			mo.columns[#mo.columns-1] = boom
		elseif timer == 90 
			damageObject(target)
			playSound(mo.battlen, sfx_s3k4e)
			local cx = target.x - 90*cos(target.angle - ANGLE_45)
			local cy = target.y - 90*sin(target.angle - ANGLE_45)
			local boom = P_SpawnMobj(cx, cy, target.z+20*FRACUNIT, MT_BOSSEXPLODE)
            boom.scale = FRACUNIT*2
            boom.state = S_FBOMB_EXPL1
			mo.columns = {}
		end
		local j = #mo.columns
		while j
			local m = mo.columns[j]
			if not m or not m.valid
				j = $-1
				continue
			end
			for i = 1, 12
				local boom = P_SpawnMobj(m.x + P_RandomRange(-48, 48)*FRACUNIT, m.y + P_RandomRange(-48, 48)*FRACUNIT, m.z, MT_DUMMY)
				boom.state = S_QUICKBOOM1
				boom.momz = P_RandomRange(0, 48)*FRACUNIT
				boom.scale = FRACUNIT*3/2
			end
			localquake(mo.battlen, FRACUNIT*8, 1)
			if timer%4 == 0
				playSound(mo.battlen, sfx_fire1)
			end
			j = $-1
		end
		if timer == 120
			mo.fangle = nil
			mo.columns = nil
			return true
		end
	end,
}

attackDefs["high energy m"] = {
	name = "High Energy",
	type = ATK_SUPPORT,
	costtype = CST_SP,
	cost = 80,
	desc = "Fusion (w/ Eggman) - \nGives Mind Charge to \nall allies.",
	target = TGT_ALLALLIES,
	superbuff = true,
	mindcharge = true,
	norogue = true,
	norandom = true,
	nocast = function(targets, n, mo)
		local tgt = targets[n]
		local battlen = tgt.battlen
		local skincheck = "eggman"
		local checkteam = tgt.allies
		local found
		for i = 1, #checkteam do
			if checkteam[i].skin == skincheck
				found = true
				break
			end
		end
		if not found
			BTL_logMessage(battlen, "You'll need Eggman alive to cast this skill.")
			playSound(battlen, sfx_not)
			return true
		end
		if mo.mindcharge
			BTL_logMessage(battlen, "Maybe use your Mind 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["eggman"] and charStats["eggman"].hudaoa or "motobug")
				if target.skin == "eggman"
					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 == "eggman"
					VFX_Play(target, VFX_AOADO)
				end
			elseif timer >= 1
				if target.skin == "motobug"
					summonAura(target, SKINCOLOR_TEAL)
				end
				if target.skin == "eggman"
					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.mindcharge = true
				BTL_logMessage(targets[1].battlen, target.name.." is building up Magic power...")
				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_CYAN
					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_CYAN
						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_CYAN
					thok.tics = P_RandomRange(10, 35)
				end
			end
		end
		if timer == 60 + (#targets-1)*16
			return true
		end
	end,
}

attackDefs["high energy e"] = {
	name = "High Energy",
	type = ATK_SUPPORT,
	costtype = CST_SP,
	cost = 80,
	desc = "Fusion (w/ Motobug) - \nGives Mind Charge to \nall allies.",
	target = TGT_ALLALLIES,
	superbuff = true,
	mindcharge = true,
	norogue = true,
	norandom = true,
	nocast = function(targets, n, mo)
		local tgt = targets[n]
		local battlen = tgt.battlen
		local skincheck = "motobug"
		local checkteam = tgt.allies
		local found
		for i = 1, #checkteam do
			if checkteam[i].skin == skincheck
				found = true
				break
			end
		end
		if not found
			BTL_logMessage(battlen, "You'll need Motobug alive to cast this skill.")
			playSound(battlen, sfx_not)
			return true
		end
		if mo.mindcharge
			BTL_logMessage(battlen, "Maybe use your Mind 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["motobug"] and charStats["motobug"].hudaoa or "eggman")
				if target.skin == "motobug"
					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 == "motobug"
					VFX_Play(target, VFX_AOADO)
				end
			elseif timer >= 1
				if target.skin == "eggman"
					summonAura(target, SKINCOLOR_TEAL)
				end
				if target.skin == "motobug"
					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.mindcharge = true
				BTL_logMessage(targets[1].battlen, target.name.." is building up Magic power...")
				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_CYAN
					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_CYAN
						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_CYAN
					thok.tics = P_RandomRange(10, 35)
				end
			end
		end
		if timer == 60 + (#targets-1)*16
			return true
		end
	end,
}

-- Trait
personaList["hellbiker"].trait = "hell throttle"

attackDefs["hell throttle"] = {
	name = "Hell Throttle",
	type = ATK_PASSIVE,
	target = TGT_CASTER,
	desc = "50% chance of receiving a free \n1More at the start of each turn \nwhen HP is at or below 50%.",
	passive = PSV_STARTTURN,
	norogue = true,
	norandom = true,
	anim = function(mo, targets, hittargets, timer)
		local target = hittargets[1]
		if timer == 1
			if (target.hp <= target.maxhp*1/2) and P_RandomRange(0, 100) < 50
				target.setonemore = 1
				local sun = P_SpawnMobj(mo.x,mo.y,mo.z + FRACUNIT*120,MT_DUMMY)
				sun.sprite = SPR_FLAM
				sun.frame = M|FF_FULLBRIGHT
				sun.colorized = true
				sun.color = SKINCOLOR_SUPERORANGE1
				sun.tics = -1
				mo.sun = sun
				playSound(mo.battlen, sfx_s3k9f)
			else
				return true
			end
		elseif timer >= 1 and timer <= 20
			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
				s.color = SKINCOLOR_ORANGE
				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
		end
		if timer == 20
			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,
}

-- Exhaust Thinker
addHook("MobjThinker", function(mo)
	local target = mo.target
	if not target return end
	if not target.valid return end
	if not mo.alivefor then mo.alivefor = 1 else mo.alivefor = min(16, $+2) end
	local sx = mo.x + mo.dist*cos(mo.angle)
	local sy = mo.y + mo.dist*sin(mo.angle)
	if mo.invertrotation
		mo.angle = $+ ANG1*40
		if not mo.momz then mo.momz = -8*FRACUNIT end
	else
		mo.angle = $ - ANG1*40
		if not mo.momz then mo.momz = 8*FRACUNIT end
	end
	if not (leveltime%4)
		mo.momz = -mo.momz
	end
	local qualityfactor = 1
	if mo.lowquality then qualityfactor = 2 end
	if not mo.fakeangle
		mo.fakeangle = P_RandomRange(0, 359)*ANG1
	end
	for i = 1,mo.alivefor / qualityfactor
		local ref = ANG1*2 * qualityfactor
		if not mo.invertrotation then ref = -ref end
		local sx = mo.x + mo.dist*cos(mo.angle - (ref)*i)
		local sy = mo.y + mo.dist*sin(mo.angle - (ref)*i)
		local sz = mo.z + 16*sin(mo.angle - (ref)*i - mo.fakeangle)
		local trail = P_SpawnMobj(sx, sy, sz, MT_THOK)
		trail.frame = A|FF_FULLBRIGHT
		trail.scale = FRACUNIT/3
		trail.scalespeed = $
		trail.destscale = 1
		if mo.tics == 1
			trail.angle = mo.angle - (ref)*i + ANGLE_90
			P_InstaThrust(trail, trail.angle, FRACUNIT*70)
			trail.tics = 7
		end
		if mo.jizzcolor
			trail.color = SKINCOLOR_MINT
		else
			trail.color = SKINCOLOR_MOSS
		end
	end
end, MT_EXHAUST)