-- I wonder what this is for?
-- I kid, I kid, this is obviously for SRB2Persona!
 
-- Hey, you bothered checking the files. If this is included in an unrelated character release, surely this means something... right?
-- PS: SRB2P custom character support works, but is rough.
-- There are NO failsafes if you fuck up declarations, so read the comments here.
 
if not srb2p return end

addHook("PlayerThink", function(player)
	if player.mo.skin == "doomguy"
		player.charability2 = CA2_MELEE
	end	
end)

-- Due to the exe nature of the mod, this only requires a one-time check.
freeslot("SPR_DVTH", "sfx_voice1")
-- Define our base character's stats!
charStats["doomguy"] = {
 
        -- GENERAL
 
        name = "The Doom Slayer",        -- This is only for bots / enemies
        basehp = 100,            -- base HP for level 1 (Cannot be <= 0)
        basesp = 50,            -- base SP for level 1 (Can be 0, but not < 0!)
        persona = "Davoth",     -- Persona to use
        melee_natk = "dsr_atk1", -- normal melee attack
 
 		wep = "ranged_01",
		weptype = WPT_GENERICRANGED,

        -- Normal attack attributes
        -- Scales with game difficulty
        atk = 40,   -- power (generally < 50)
        acc = 35,   -- accuracy (%)
        crit = 30,   -- crit rate (%)
 
        -- ANIMS
        -- Anims are built like this:
        -- {SPR_SPRITE, frame1, frame2, frame3, ... , duration between each frame, ["SPR2_CONST"]}
        -- (SPR2 must be a string, and is optional. Only for use with SPR_PLAY)
 
        -- Note: As of Beta 1.0.0, not all animations are implemented
        -- (* = unimplemented)
 
        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, 8, "SPR2_STND"},                  -- standing (occasionally plays after anim_stand has played several times)
        anim_guard =        {SPR_PLAY, A, 1, "SPR2_GARD"},                  -- 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, E, F, G, H, 2, "SPR2_WALK"},   -- guess what
        anim_atk =          {SPR_PLAY, A, 2, "SPR2_BFGF"},         -- attacking
        anim_aoa_end =      {SPR_PLAY, A, 2, "SPR2_BFGF"},         -- jumping out of all-out attack
        anim_hurt =         {SPR_PLAY, A, 35, "SPR2_DEAD"},                 -- taking damage
        anim_getdown =      {SPR_PLAY, A, 1, "SPR2_CNT1"},                  -- knocked down from weakness / crit *
        anim_downloop =     {SPR_PLAY, A, 1, "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_PAIN"},                 -- dies
        anim_revive =       {SPR_PLAY, A, B, C, D, 1, "SPR2_ROLL"},         -- gets revived
 
        -- anim_special1 through anim_special32 may also be used for various purposes (ie: attack animations)
		anim_special1 = {SPR_PLAY, A, 2, "SPR2_MLEE"}, -- hammer prep
		anim_special2 = {SPR_PLAY, B, C, D, 2, "SPR2_MLEE"}, -- hammer swing
		anim_special3 = {SPR_PLAY, A, "SPR2_MLEE"},	-- hammer swung
		anim_special4 = {SPR_PLAY, A, B, C, D, E, "SPR2_TWIN"},	-- hammer spin
 
        -- VOICES
        -- Possible list of voices
        -- vfx_action = {"sfx_voice1", "sfx_voice2", [...], "sfx_voicen"}
 
        -- ...In the case of kanade, she's silent, but I will leave these here for reference!
 
        vfx_summon = {},    -- Summoning Persona to use a Skill
        vfx_skill = {},     -- Used a Skill
        vfx_item = {},      -- Used an item
        vfx_hurt = {},      -- Sustained damage
        vfx_hurtx = {},     -- Sustained heavy damage / Critical hit / Weakness
        vfx_die = {},       -- Death
        vfx_heal = {},      -- Healed by teammate
        vfx_healself = {},  -- Healed self
        vfx_kill = {},      -- Killed an enemy
        vfx_1more = {},     -- Performed 1more
        vfx_crit = {},      -- Cut-in for Weakness/Critical Hit
        vfx_aoaask = {},    -- Ask to All-Out Attack
        vfx_aoado = {sfx_voice1},     -- Performing All-Out Attack
        vfx_aoarelent = {}, -- Relenting from All-Out Attack
        vfx_miss = {},      -- Missed attack
        vfx_dodge = {},     -- Dodged enemy attack
        vfx_win = {},       -- Battle won
        vfx_levelup = {},   -- Level Up!
 
 
        -- HUD DEFINTIIONS
 
        icon = "ICO_DOOM",          -- head icon for character select
        hudbust = "DSR_H",           -- patch to draw on the stat hud
        hudaoa = "H_DSRAOA",        -- patch for all out attack hud
        aoa_quote = "UNF!1!!11",
        hudcutin = "DOOM_A",        -- cut in frames prefix
 
        -- Tip to display on the character select.
        -- Give insight on their skill type and their strengths/weaknesses in battle!
        tip = "When against gods, bullets, and bombs, he will always come out on top.\nHe is fairly overpowered and can be relied on to carry the team,\ndue to his strength and agility you dont want to get on his bad side.",
}
 

personaList["Davoth"] = {
        -- GENERAL
        name = "Davoth",    -- Name of the Persona
        arcana = ARCANA_CHARIOT,           -- Arcana (unused in Beta 1.0.0, can be left nil as well)
 
        sprite = SPR_DVTH,      -- Unused outside of debugging purposes for shortcuts. Can be left nil
        startframe = 0,         -- Unused outside of debugging purposes for shortcuts. Can be left nil
 
        -- Animations function the same way they do for players. (In Kanade's case, she's so good she doesn't need one, so let's make it invisible)
        anim_idle =     {SPR_DVTH, A, B, C, B, 10},  -- Idle animation when summoned in the menu
        anim_atk =      {SPR_DVTH, C, D, E, F, G, H, I, 3},  -- Animation when attacking
 
        -- Stats (at level 10)
        -- Remember that stats naturally cap at 99.
        strength = 8,
        magic = 6,
        endurance = 7,
        luck = 5,
        agility = 6,
 
        -- Affinities (weak, resist, block, drain)
        weak = ATK_FIRE|ATK_ICE,
        resist = ATK_ALMIGHTY|ATK_PIERCE|ATK_NUCLEAR,
        block = ATK_BLESS,
        drain = ATK_CURSE,
 
        /*Skills learnt and their level:
            {
                {"skillname", level, ["skill_to_replace"]},
                {"skill2name", level, ["skill_to_replace"]},
                [...]
            }
 
            Documentation for every existing skill name will be available publically at a later date.
            For now, feel free to scout the game files yourself!
 
            the 3rd argument is only useful on higher difficulties where characters automatically start at
            higher levels, meaning their skills need to be automatically replaced.
 
            NOTE: Characters can only have 8 skills total! But if you mess this up, the game won't stop you from having 69 skills.
            So pay attention!
        */
 
        skills = {
                    {"argent thunder", 1},
					{"cleave", 4},
					{"toxic slice", 12, "cleave",},
					{"kouha", 16},
					{"giant slice", 20, "toxic slice"},
                    {"argent strike", 20, "argent thunder"},
                    {"makouha", 25, "kouha"},
					{"gale slash", 29, "giant slice"},
                    {"kouga", 30, "makouha"},
                    {"makouga", 35, "kouga"},
					{"danse macabre", 36, "gale slash"},
					{"argent cloud", 40, "argent strike"},
                    {"kougaon", 40, "makouga"},
					{"blade of fury", 42, "danse macabre"},
                    {"makougaon", 45, "kougaon"},
                    {"hamaon", 50, "makougaon"},
					{"virus cutter", 50, "blade of fury"},
					{"argent storm", 60, "argent cloud",},
					{"fatal end", 61, "virus cutter"},
					{"brave blade", 73, "fatal end"},
                    {"mahamaon", 80, "hamaon"},
					{"deathbound", 86, "brave blade"},
					{"myriad slashes", 96, "deathbound"},
                    {"samsara", 99, "hamaon"},
                 },
}
 
	attackDefs["argent thunder"] = {
		name = "Argent Thunder",
		type = ATK_CURSE,
		power = 69,
		accuracy = 88,
		costtype = CST_SP,
		status = COND_SHOCK,
		statuschance = 5,
		cost = 4,
		desc = "Light Curse dmg to one enemy. \nMay inflict shock.",
		target = TGT_ENEMY,
		anim = function(mo, targets, hittargets, timer)
			local target = hittargets[1]
            if (timer == 20)
				-- first one, the one behind
				local z1 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
                z1.state, z1.scale, z1.color = S_LZIO11, target.scale*9/4, SKINCOLOR_RED
                z1.destscale = target.scale    -- this probably looks retarded at smaller scales from afar lmao
				-- second, the dominant in front
				local z2 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
				z2.state, z2.scale, z2.color = S_LZIO21, target.scale*9/4, SKINCOLOR_RED
				z2.destscale = target.scale

				playSound(mo.battlen, sfx_zio1)
				damageObject(target)
			elseif (timer == 60)
				return true
			end
		end,
	}

	attackDefs["argent strike"] = {
		name = "Argent Strike",
		type = ATK_CURSE,
		power = 120,
		accuracy = 88,
		costtype = CST_SP,
		status = COND_SHOCK,
		statuschance = 5,
		cost = 4,
		desc = "Medium Curse dmg to one enemy. \nMay inflict shock.",
		target = TGT_ENEMY,
		anim = function(mo, targets, hittargets, timer)
			local target = hittargets[1]
            if (timer == 20)
				-- first one, the one behind
				local z1 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x*2, target.y*2, target.floorz, MT_DUMMY)
                z1.state, z1.scale, z1.color = S_LZIO11, target.scale*9/4, SKINCOLOR_RED
                z1.destscale = target.scale    -- this probably looks retarded at smaller scales from afar lmao
				-- second, the dominant in front
				local z2 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x*2, target.y*2, target.floorz, MT_DUMMY)
				z2.state, z2.scale, z2.color = S_LZIO21, target.scale*9/4, SKINCOLOR_RED
				z2.destscale = target.scale

				playSound(mo.battlen, sfx_zio1)
				damageObject(target)
			elseif (timer == 60)
				return true
			end
		end,
	}

	attackDefs["argent cloud"] = {
		name = "Argent Cloud",
		type = ATK_CURSE,
		power = 240,
		accuracy = 88,
		costtype = CST_SP,
		status = COND_SHOCK,
		statuschance = 5,
		cost = 4,
		desc = "Heavy Curse dmg to one enemy. \nMay inflict shock.",
		target = TGT_ENEMY,
		anim = function(mo, targets, hittargets, timer)
			local target = hittargets[1]
            if (timer == 20)
				-- first one, the one behind
				local z1 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x*2, target.y*2, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x/2, target.y/2, target.floorz, MT_DUMMY)
                z1.state, z1.scale, z1.color = S_LZIO11, target.scale*9/4, SKINCOLOR_RED
                z1.destscale = target.scale    -- this probably looks retarded at smaller scales from afar lmao
				-- second, the dominant in front
				local z2 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x*2, target.y*2, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x/2, target.y/2, target.floorz, MT_DUMMY)
				z2.state, z2.scale, z2.color = S_LZIO21, target.scale*9/4, SKINCOLOR_RED
				z2.destscale = target.scale

				playSound(mo.battlen, sfx_zio1)
				damageObject(target)
			elseif (timer == 60)
				return true
			end
		end,
}

	attackDefs["argent storm"] = {
		name = "Argent Storm",
		type = ATK_CURSE,
		power = 420,
		accuracy = 88,
		costtype = CST_SP,
		status = COND_SHOCK,
		statuschance = 5,
		cost = 4,
		desc = "Heavy Curse dmg to one enemy. \nMay inflict shock.",
		target = TGT_ENEMY,
		anim = function(mo, targets, hittargets, timer)
			local target = hittargets[1]
            if (timer == 20)
				-- first one, the one behind
				local z1 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x*2, target.y*2, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x*3, target.y*3, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x/2, target.y/2, target.floorz, MT_DUMMY)
                z1.state, z1.scale, z1.color = S_LZIO11, target.scale*9/4, SKINCOLOR_RED
                z1.destscale = target.scale    -- this probably looks retarded at smaller scales from afar lmao
				-- second, the dominant in front
				local z2 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x*2, target.y*2, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x*3, target.y*3, target.floorz, MT_DUMMY)
				P_SpawnMobj(target.x/2, target.y/2, target.floorz, MT_DUMMY)
				z2.state, z2.scale, z2.color = S_LZIO21, target.scale*9/4, SKINCOLOR_RED
				z2.destscale = target.scale

				playSound(mo.battlen, sfx_zio1)
				damageObject(target)
			elseif (timer == 60)
				return true
			end
		end,
}

	attackDefs["dsr_atk1"] = {
		name = "Crucible Clash",
		type = ATK_SLASH,
		power = 45,
		accuracy = 90,
		critical = 7, -- was 7
		target = TGT_ENEMY,
		cost = CST_HP,
		cost = 0,
		desc = "A slice from the blade that felled a Titan.",
		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_s220)

						-- 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 - 7
						ANIM_set(mo, mo.anim_special2)	-- hammer hit prep

					elseif timer == TICRATE
						damageObject(hittargets[1])
						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_FIREBALL
							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_pstop)

						for i = 1, 16
				-- first one, the one behind
				local z1 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
                z1.state, z1.scale, z1.color = S_LZIO11, target.scale*9/4, SKINCOLOR_RED
                z1.destscale = target.scale    -- this probably looks retarded at smaller scales from afar lmao
				-- second, the dominant in front
				local z2 = P_SpawnMobj(target.x, target.y, target.floorz, MT_DUMMY)
				z2.state, z2.scale, z2.color = S_LZIO21, target.scale*9/4, SKINCOLOR_RED
				z2.destscale = target.scale

				playSound(mo.battlen, sfx_zio1)
							local h = P_SpawnMobj(target.x, target.y, target.z, MT_DUMMY)
							h.state = S_FIREBALL
							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
					elseif timer == TICRATE*2
						return true
					end
				end,
	}
