local Mint = Mint

addHook("PlayerCanDamage", function(p)
local s = p.realmo
local mint = p.minttable
if s and ActiveMint(s)
if mint and mint.burststomp==true
or p.powers[pw_sneakers]
or mint and mint.homing
or mint and mint.spinlaunchcharge
return true end
end;end)

addHook("ShouldDamage", function(s, i, so, dmg, dtype)
if not (s and s.player) return end
if (s and ActiveMint(s) and s.player.minttable) and (s.player.minttable.nofear)
return false --lol
end;end)

addHook("MobjCollide", function(s, so)
if ActiveMint(s) and s.player and (s.player.minttable and s.player.minttable.burststomp)
and so and (so.type==MT_METALSONIC_BATTLE) //and (so.flags & MF_BOSS|MF_ENEMY|MF_NOCLIPTHING)
and (so.flags2 & MF2_FRET)
and not (s.z > so.z + so.height or so.z > s.z + s.height)
so.flags2 = $ & ~MF2_FRET
so.flags = $ & ~MF_NOCLIPTHING
end
end, MT_PLAYER)

addHook("MobjDamage", function(s, i, so, dmg, dtype)
if not (so and so.player) return end
if (s.flags&MF_BOSS or s.flags&MF_ENEMY)
and (so and ActiveMint(so) and so.player and so.player.minttable)
so.player.minttable.cocky = 25
if s and s.yulsaresist and (so.state==S_PLAY_MINTDASH)
s.yulsaresist = 0 --SA Sonic compatability
S_StartSound(s, sfx_shattr)
so.player.powers[pw_flashing] = 1*TICRATE
so.player.pflags = $|PF_JUMPED
so.player.pflags = $ & ~PF_THOKKED
so.state = S_PLAY_FALL
end;end;end)

addHook("MobjDamage", function(s, i, so, dmg, dtype)
if not (s and s.player) return end
if (s and ActiveMint(s) and s.player and s.player.minttable and s.player.minttable.burststomp)
and i and i.health and (i.type==MT_FBOMB or i.type==MT_CYBRAKDEMON_NAPALM_BOMB_LARGE or i.type==MT_CYBRAKDEMON_MISSILE
or i.type==MT_CYBRAKDEMON_VILE_EXPLOSION
or i.type==MT_CYBRAKDEMON_NAPALM_BOMB_SMALL)
P_RemoveMobj(i, s, s)
local BOM = P_SpawnMobj(s.x+FixedMul(100*FU, cos(s.angle)), s.y+FixedMul(100*FU, sin(s.angle)), s.z, MT_MBOMB)
BOM.color = SKINCOLOR_PEPPER
BOM.tracer,BOM.target = so,so
BOM.blendmode = AST_ADD
Mint.CombatSFX(s.player,s,s.player.minttable)
s.player.minttable.sbs = false
s.player.powers[pw_strong] = $&~ STR_SPRING
s.player.powers[pw_strong] = $&~ STR_BUST
S_StartSound(BOM, sfx_zoom)
P_DoMintEffect4(BOM)
P_InstaThrust(s,s.angle,0*FU)
P_SetObjectMomZ(s,10*FU)
P_HomingAttack(BOM, so)
P_InstaThrust(BOM, R_PointToAngle2(BOM.x, BOM.y, so.x, so.y), R_PointToDist2(BOM.x, BOM.y, so.x, so.y)/4)
P_SetObjectMomZ(BOM, FixedMul(FixedMul(R_PointToDist2(BOM.x, BOM.y, so.x, so.y)/2, sin(R_PointToAngle2(0, (BOM.z - (so.height/3)), P_AproxDistance(so.x - so.x, BOM.y - so.y), so.z))) - so.momz, FU/2), true)
return true end
end,MT_PLAYER)

addHook("MobjDamage", function(s, i, so, dmg, dtype)
if not (s and s.player) return end
if (s and ActiveMint(s) and s.player and s.player.minttable and s.state==S_PLAY_SKID) and not (dtype&DMG_DEATHMASK)
S_StartSound(s, sfx_mdodge)
P_PlayerFlagBurst(s.player)
s.player.powers[pw_flashing] = 1*TICRATE
P_DoMintEffect(s.player,s.color)
P_InstaThrust(s, s.angle,10*FU)
P_SetObjectMomZ(s,6*FU,true)
s.state = S_PLAY_ROLL
s.player.minttable.framejump = 0
s.player.pflags = $|PF_THOKKED
s.player.pflags = $1&~PF_JUMPED
return true end
end,MT_PLAYER)

addHook("MobjDamage", function(s, i, so, dmg, dtype)
if not (s and s.player) return end
if (s and ActiveMint(s) and s.player)
and (s.player.minttable and s.player.minttable.burststomp or s.player.minttable.homing and s.player.minttable.homing < 40)
and not (dtype&DMG_DEATHMASK)
and so and so.type==MT_METALSONIC_BATTLE
P_DoMintEffect4(so)
s.player.minttable.twirl = 27
s.player.minttable.trick = 27
s.player.minttable.burststomp = false
s.player.minttable.combo = 0
s.player.minttable.homing = 0
s.player.minttable.spintrail = 0
s.player.minttable.sbs = false
//P_FlashPal(s.player, PAL_NUKE, 2)
P_SetObjectMomZ(s, 10*FU)
P_InstaThrust(so, so.angle, 0)
P_InstaThrust(s, s.angle, 0)
Mint.CombatSFX(s.player,s,s.player.minttable)
S_StartSound(so, sfx_bedeen)
S_StartSound(so, sfx_brakrx)
P_StartQuake(20*FU, 1*TICRATE*1/2)
P_DoBurstStompGFX(so)
so.state = S_METALSONIC_FLOAT
so.flags = MF_NOGRAVITY|MF_BOSS|MF_SLIDEME
so.target = nil
for a=1,30 do
local explode = P_SpawnMobj(so.x, so.y, so.z, MT_BOSSEXPLODE)
explode.momx = P_RandomRange(-32768, 32767) * 30
explode.momy = P_RandomRange(-32768, 32767) * 30
explode.momz = P_RandomFixed() * 32
end
return true end
end,MT_PLAYER)

Mint.KillFlash = function(s,so)
if ActiveMint(so) and so.player and (so.player.minttable and so.player.minttable.homing and so.player.minttable.homing < 40)
and s and s.valid and s.player
and not (so.z > s.z + s.height or s.z > so.z + so.height)
s.player.powers[pw_flashing] = 0
end;end
addHook("MobjCollide", Mint.KillFlash, MT_PLAYER)
addHook("MobjMoveCollide", Mint.KillFlash, MT_PLAYER)

//Burst Stomp combo
addHook("MobjDamage", function(s,i,so,d,dtype)
local B = CBW_Battle
if not (i and i.player and ActiveMint(i)) return end
if (i and ActiveMint(i) and i.player and i.player.minttable) and i.player.minttable.burststomp and s and s.valid
and (s.flags&MF_ENEMY|MF_BOSS or s.player and not s.player.guard)
and not P_IsObjectOnGround(i)
or (i and ActiveMint(i) and i.player and i.player.minttable) and i.player.minttable.homing and (i.player.minttable.homing < 40) and s and s.valid
and (s.flags&MF_ENEMY|MF_BOSS or s.player and not s.player.guard)
and not P_IsObjectOnGround(i)
//P_MoveOrigin(i, s.x, s.y, s.z + 40*FU)
P_DoBurstStompGFX(s)
i.player.minttable.combo = $+1
S_StopSound(s, sfx_pop)
Mint.CombatSFX(i.player,i,i.player.minttable)
P_StartQuake(16*FU, 1*TICRATE*1/2)
P_SetObjectMomZ(i, 20*FU)
P_SetObjectMomZ(s,-8*FU)
i.player.pflags = $|PF_JUMPED
i.player.pflags = $ & ~PF_THOKKED
P_DoMintEffect4(s)
if i.player.minttable.sbs
i.player.minttable.sbs = false
S_StartSound(s, sfx_bedeen)
S_StartSound(s, sfx_brakrx)
P_StartQuake(20*FU, 1*TICRATE*1/2)
s.health = $-1
s.gettingcookedbymintbeam = 10
end
if (s.type==MT_FANG)
for i = 1,30
local dust = P_SpawnMobj(s.x, s.y, s.z, MT_WATERDROP)
dust.renderflags = RF_NOCOLORMAPS
dust.flags = $|MF_NOBLOCKMAP|MF_NOCLIPTHING
dust.blendmode = AST_ADD
dust.colorized = true
dust.angle = ANG60*i
dust.color = SKINCOLOR_CRIMSON -- b l o o d
dust.momx = P_RandomRange(-12768, 12767) * 5
dust.momy = P_RandomRange(-12768, 12767) * 4
dust.momz = P_RandomRange(-12768, 12767) * 3
P_SetObjectMomZ(dust, 6*FU)
end;end
if i.player.minttable.homing or i.player.minttable.a
P_InstaThrust(i,i.angle,0*FU)
P_SetObjectMomZ(i, 15*FU)
i.player.minttable.homing = 0
i.player.minttable.zoomout = 1
i.player.minttable.a = 0
end
if i.player.minttable and i.player.minttable.combo==1
i.state = S_PLAY_SPRING
//S_StartSound(i,sfx_hoop1)
i.player.minttable.spintrail = 0
end
if i.player.minttable.combo==2
i.player.minttable.trick = 27
S_StartSound(i,sfx_hoop2)
i.player.minttable.spintrail = 0
end
if i.player.minttable.combo==3
i.player.minttable.twirl = 27
i.player.minttable.trick = 27
P_InstaThrust(i,i.angle,0*FU)
S_StartSound(i,sfx_nxdone)
i.player.minttable.combo = 0
local fx = P_SpawnGhostMobj(i)
fx.scale = i.scale
fx.destscale = 87<<16
fx.scalespeed = i.scale/3
fx.sprite2 = SPR2_RIDE
fx.frame = FF_TRANS40
if i.player.rings==0
for i = 1,6
local dust = P_SpawnMobj(s.x, s.y, s.z, MT_FLINGRING)
dust.angle = ANG60*i
dust.blendmode = AST_ADD
dust.fuse,dust.tics = 200,20
P_InstaThrust(dust, dust.angle, 2*FU)
P_SetObjectMomZ(dust, 5*FU)
end;end
if (leveltime%2==0)
if not i.player.minttable.vocalcd
local trickvo
trickvo = {sfx_mnvoc4,sfx_mnvoc5,sfx_mnvoc6}
local mrng = P_RandomRange(1, #trickvo)
local trickvo2 = trickvo[mrng]
trickvo2 = (mrng==#trickvo) and trickvo[1] or trickvo[mrng+1]
Mint.Vocals(i.player,i,i.player.minttable, trickvo2, 240)
end;end;end;end;end)

addHook("MobjDeath", function(s,i,so)
if not (i and i.player and ActiveMint(i)) return end
if i and i.player and i.player.minttable and s and s.valid
if (s.flags&MF_MONITOR)
S_StopSoundByID(i, sfx_pop)
S_StartSound(i, sfx_mpop)
i.player.minttable.spintrail = 0
i.player.minttable.sbs = false
if i.player.minttable.burststomp
P_DoBurstStompGFX(s)
P_SetObjectMomZ(i, 20*FU)
end
if i.player.minttable.homing and (i.player.minttable.homing < 40)
P_DoBurstStompGFX(s)
P_InstaThrust(i,i.angle,0*FU)
P_SetObjectMomZ(i, 15*FU)
i.player.minttable.trick = 27
i.player.minttable.homing = 0
i.player.minttable.zoomout = 1
i.player.pflags = $|PF_JUMPED
i.player.pflags = $ & ~PF_THOKKED
end;end;end;end)

addHook("MobjDeath", function(s,i,so)
if not (so and so.player and ActiveMint(so)) return end
if so and so.player and so.player.minttable and s and s.player
Mint.WinnerVoice(so.player,so,so.player.minttable)
so.player.minttable.combo = 0
end;end)

addHook("MobjMoveBlocked", function(s,so,line)
local p = s.player local s = p.realmo
if not (p and p.valid or s and s.valid) return end
if P_PlayerInPain(p) return end
if p.powers[pw_carry] return end

local mint = p.minttable

if ActiveMint(s) and mint and mint.homing and line
P_DoMintEffect(p,SKINCOLOR_RED)
s.state = S_PLAY_PAIN
S_StartSound(s, sfx_s3k49)
S_StartSound(s, sfx_s1b8)
P_InstaThrust(s, s.angle, -8*FU)
P_SetObjectMomZ(s, (s.eflags&MFE_UNDERWATER) and 3*FU or 6*FU)
mint.homing = 0
mint.spintrail = 0
mint.nocontrol = 15
mint.combo = 0
mint.zoomout = 1
end;end,MT_PLAYER)

addHook("MobjDamage", function(s,i,so,d,dtype)
if not (s and s.player and ActiveMint(s)) return end
if (s and ActiveMint(s) and s.player.minttable)

if (dtype==DMG_SPIKE)
S_StartSound(s, sfx_kc4c)
P_SetObjectMomZ(s, 20*FU)
P_DoMintEffect4(s)
end
if (dtype==DMG_FIRE)
S_StartSound(s, sfx_s3k48)
s.player.minttable.flames = 90
end;end;end,MT_PLAYER)

addHook("MobjDeath", function(s,i,so,dtype)
if not (s and s.player and ActiveMint(s)) return end
if s and s.player and s.player.minttable
s.state = S_PLAY_DEAD
s.player.minttable.vocalcd = 0
P_StartQuake(25*FU, 1*TICRATE*1/2)
Mint.STFU(s.player,s)
FactoryReset(s.player,s,s.player.minttable)
s.player.powers[pw_carry] = 0
s.player.powers[pw_sneakers] = 0
local MUSIC = S_MusicName()
if (MUSIC=="MSHOES" or MUSIC=="MSHOEB" or MUSIC=="MSHOEC"
or MUSIC=="MNTS" or MUSIC=="MCLEAR"
or MUSIC=="M1UP" or MUSIC=="MINV")
//COM_BufInsertText(p, "tunes -default")
P_RestoreMusic(s.player)
end
if not (dtype==DMG_FIRE) and not (dtype==DMG_DEATHPIT)
Mint.Vocals(s.player,s,s.player.minttable, sfx_mnvoca)
end
if (dtype==DMG_FIRE)
S_StartSound(s, sfx_s3k48)
s.player.minttable.flames = 90
end
if (dtype==DMG_DEATHPIT)
s.flags = $&~MF_NOGRAVITY
s.flags = $|MF_NOCLIPHEIGHT
P_SetObjectMomZ(s, -40*FU)
Mint.STFU(s.player,s)
Mint.Vocals(s.player,s,s.player.minttable, sfx_mnvoci)
end
if (dtype==DMG_WATER) or (dtype==DMG_DROWNED) or (s.eflags&MFE_UNDERWATER) or (dtype==DMG_SPACEDROWN)
S_StartSound(s, sfx_cdfm38)
P_SetObjectMomZ(s, 0*FU)
for a=1,6 do
local bub = P_SpawnMobj(s.x,s.y,s.z, MT_MEDIUMBUBBLE)
bub.angle = ANG60*a
P_InstaThrust(bub, bub.angle, 25*FU)
P_SetObjectMomZ(bub, 0*FU)
end;end;end;end)

addHook("MobjCollide", function(s, so)
if ActiveMint(so) and so.player and (so.player.minttable and so.player.minttable.homing and so.player.minttable.homing < 40)
and (s and s.valid and s.player and s.player.minttable and s.player.minttable.homing and s.player.minttable.homing < 40)
and not (so.z > s.z + s.height or s.z > so.z + so.height)
s.player.powers[pw_flashing] = 0
so.player.minttable.homing = 0
so.player.minttable.zoomout = 1
s.player.minttable.homing = 0
s.player.minttable.zoomout = 1
s.player.minttable.nocontrol,so.player.minttable.nocontrol = 20,20
s.state = S_PLAY_PAIN
so.state = S_PLAY_PAIN
P_DoMintEffect(so.player,SKINCOLOR_GREY)
P_InstaThrust(s,s.angle,-40*FU)
P_InstaThrust(so,so.angle,-40*FU)
P_SetObjectMomZ(s, 16*FU)
P_SetObjectMomZ(so, 16*FU)
S_StartSound(so,sfx_cdpcm9)
S_StartSound(so,sfx_s259)
end
end, MT_PLAYER)

Mint.SteamCollide = function(s,so)
if ActiveMint(so) and so.player and so.player.minttable
and not (so.z > s.z + s.height or s.z > so.z + so.height)
S_StartSound(so, sfx_kc4c)
P_SetObjectMomZ(so, 20*FU)
so.state = S_PLAY_PAIN
so.player.pflags = $&~PF_SPINNING
end;end
addHook("MobjCollide", Mint.SteamCollide, MT_STEAM)
addHook("MobjMoveCollide", Mint.SteamCollide, MT_STEAM)
addHook("MobjCollide", Mint.SteamCollide, MT_FAN)
addHook("MobjMoveCollide", Mint.SteamCollide, MT_FAN)

//Remove spikes with speedshoes
addHook("MobjCollide", function(s, so)
if ActiveMint(so) and so.player and (so.player.minttable and so.player.minttable.speedup)
and not (so.z > s.z + s.height or s.z > so.z + so.height)
or so.mintshyperbeam
and not (so.z > s.z + s.height or s.z > so.z + so.height)
P_KillMobj(s, so, so)
end
end, MT_SPIKE)

addHook("MobjCollide", function(s, so)
if ActiveMint(so) and so.player and (so.player.minttable and so.player.minttable.speedup)
and not (so.z > s.z + s.height or s.z > so.z + so.height)
or so.mintshyperbeam
and not (so.z > s.z + s.height or s.z > so.z + so.height)
P_KillMobj(s, so, so)
end
end, MT_WALLSPIKE)

addHook("MobjCollide", function(thering, themint)
if not (thering and thering.valid) return end
if themint and themint.valid and themint.player
and thering and thering.valid and thering.health and not (thering.z > themint.z + themint.height or themint.z > thering.z + thering.height)
and ActiveMint(themint)
and XSon
S_StartSound(themint, sfx_elemsg)
themint.player.powers[pw_shield] = SH_ATTRACT
P_SpawnShieldOrb(themint.player)
P_KillMobj(thering,themint,themint)
thering.health = 0
P_GivePlayerRings(themint.player, 20)
end
end, MT_XSPOWERRING)

//Damage to losers with Mint's Hyper Beam
addHook("MobjDamage", function(t, i, so)
if not (i and i.valid and i.type == MT_THOK and i.mintshyperbeam) return end
if not (t and t.valid and t.health and (t.flags & (MF_ENEMY|MF_BOSS))) return end
if (t and t.player) return end
if not t.gettingcookedbymintbeam
S_StartSound(t, sfx_mbstr2)
t.gettingcookedbymintbeam = 1
if t.type==MT_ROSY
S_StartSound(t, sfx_cdpcm7)
if (t.hits and t.hits==30)
t.hits = 29
end
end
else
t.gettingcookedbymintbeam = $+1
if t.gettingcookedbymintbeam >= 98 and so and so.player and so.player.minttable
local p = so.player
if t.type==MT_ROSY
S_ChangeMusic("MCLEAR", false, so.player)
//print("\n"+p.name+" has won SRB2")
p.score = 99999999
for i = 1,6
local dust = P_SpawnMobj(t.x, t.y, t.z, MT_FLINGRING)
dust.angle = ANG60*i
dust.blendmode = AST_ADD
dust.fuse,dust.tics = 200,20
P_InstaThrust(dust, dust.angle, 2*FU)
P_SetObjectMomZ(dust, 5*FU)
end
end
t.gettingcookedbymintbeam = 39
P_FlashPal(so.player, PAL_NUKE, 3)
S_StartSound(t, sfx_mboom)
S_StartSound(t, sfx_kc3b)
S_StartSound(t, sfx_bkpoof)
S_StartSound(t, sfx_s3k4e)
for a=1,64 do
local explode = P_SpawnMobj(t.x, t.y, t.z, MT_BOSSEXPLODE)
explode.momx = P_RandomRange(-32768, 32767) * 64
explode.momy = P_RandomRange(-32768, 32767) * 64
explode.momz = P_RandomFixed() * 32
end
P_DamageMobj(t, m, so, 1, DMG_NUKE)
if not (t and t.valid and t.health)
so.player.powers[pw_shield] = 0
end
end
end
i.fuse = 1
return true
end)
addHook("MobjDamage", function(t, i, so)
local i = t.target
if (t and t.player and i and i.type == MT_THOK and i.mintshyperbeam)
and so and so.player
//and not (t.player.ctfteam==so.player.ctfteam)
if not (t.z > t.z + t.height or t.z > t.z + t.height)
if not t.gettingcookedbymintbeam
S_StartSound(t, sfx_mbstr2)
t.gettingcookedbymintbeam = 1
else
t.gettingcookedbymintbeam = $+1
t.state = S_PLAY_PAIN
P_PlayerRingBurst(t.player, 1)
t.player.powers[pw_nocontrol] = 1
if t.gettingcookedbymintbeam >= 78 and t.player.rings==0
S_StartSound(t, sfx_mboom)
S_StartSound(t, sfx_kc3b)
S_StartSound(t, sfx_bkpoof)
S_StartSound(t, sfx_s3k4e)
P_StartQuake(30*FU, 3*TICRATE*1/2)
for a=1,64 do
local explode = P_SpawnMobj(t.x, t.y, t.z, MT_BOSSEXPLODE)
explode.momx = P_RandomRange(-32768, 32767) * 64
explode.momy = P_RandomRange(-32768, 32767) * 64
explode.momz = P_RandomFixed() * 32
end
P_KillMobj(t, i, so, DMG_NUKE)
t.gettingcookedbymintbeam = 39
if not t.health
so.player.powers[pw_shield] = 0
//so.player.minttable.b = 0
return true
end;end;end;end;end;end,MT_PLAYER)
local function EnemyAffectedByBeam()
for m in mobjs.iterate() do
if m.gettingcookedbymintbeam
m.spritexoffset = P_RandomRange(-15, 15)<<16
P_DoMintEffect4(m)
//print(m.gettingcookedbymintbeam
P_InstaThrust(m,m.angle,0*FU)
m.momz = 0
m.gettingcookedbymintbeam = $-1
if not m.gettingcookedbymintbeam
S_StopSoundByID(m, sfx_mbstr2)
m.spritexoffset = 0
end
if (m.type==MT_ROSY)
m.state = S_ROSY_PAIN
end
end
end
end
addHook("ThinkFrame", EnemyAffectedByBeam)
