// Just like Kirby and PointySonic, this lua determines the secondary colors.
// Lua originally done by Tripel for kcl_kirby-v2.wad
freeslot("MT_MOVERRALLS", "S_MOVERRALLS", "SPR_MOVR")

// Array of colors!
local moverallscolor = {}
// Cant actually access these in lua.
// pls fix kart krew
local SKINCOLOR_WHITE = 1
local SKINCOLOR_SILVER = 2
local SKINCOLOR_GREY = 3
local SKINCOLOR_NICKEL = 4
local SKINCOLOR_BLACK = 5
local SKINCOLOR_SEPIA = 6
local SKINCOLOR_BEIGE = 7
local SKINCOLOR_BROWN = 8
local SKINCOLOR_LEATHER = 9
local SKINCOLOR_SALMON = 10
local SKINCOLOR_PINK = 11
local SKINCOLOR_ROSE = 12
local SKINCOLOR_RUBY = 13
local SKINCOLOR_RASPBERRY = 14
local SKINCOLOR_RED = 15
local SKINCOLOR_CRIMSON = 16
local SKINCOLOR_KETCHUP = 17
local SKINCOLOR_DAWN = 18
local SKINCOLOR_CREAMSICLE = 19
local SKINCOLOR_ORANGE = 20
local SKINCOLOR_PUMPKIN = 21
local SKINCOLOR_ROSEWOOD = 22
local SKINCOLOR_BURGUNDY = 23
local SKINCOLOR_TANGERINE = 24
local SKINCOLOR_PEACH = 25
local SKINCOLOR_CARAMEL = 26
local SKINCOLOR_GOLD = 27
local SKINCOLOR_BRONZE = 28
local SKINCOLOR_YELLOW = 29
local SKINCOLOR_MUSTARD = 30
local SKINCOLOR_OLIVE = 31
local SKINCOLOR_VOMIT = 32
local SKINCOLOR_GARDEN = 33
local SKINCOLOR_LIME = 34
local SKINCOLOR_TEA = 35
local SKINCOLOR_PISTACHIO = 36
local SKINCOLOR_ROBOHOOD = 37
local SKINCOLOR_MOSS = 38
local SKINCOLOR_MINT = 39
local SKINCOLOR_GREEN = 40
local SKINCOLOR_PINETREE = 41
local SKINCOLOR_EMERALD = 42
local SKINCOLOR_SWAMP = 43
local SKINCOLOR_DREAM = 44
local SKINCOLOR_AQUA = 45
local SKINCOLOR_TEAL = 46
local SKINCOLOR_CYAN = 47
local SKINCOLOR_JAWZ = 48
local SKINCOLOR_CERULEAN = 49
local SKINCOLOR_NAVY = 50
local SKINCOLOR_SLATE = 51
local SKINCOLOR_STEEL = 52
local SKINCOLOR_JET = 53
local SKINCOLOR_SAPPHIRE = 54
local SKINCOLOR_PERIWINKLE = 55
local SKINCOLOR_BLUE = 56
local SKINCOLOR_BLUEBERRY = 57
local SKINCOLOR_DUSK = 58
local SKINCOLOR_PURPLE = 59
local SKINCOLOR_LAVENDER = 60
local SKINCOLOR_BYZANTIUM = 61
local SKINCOLOR_POMEGRANATE = 62
local SKINCOLOR_LILAC = 63
// This list is extremely long
// 63 colors.
// ow.
// *** If you want to customize your color set, here is where you do it!***
// This set is more than acceptable, though; the team behind Kirby did a good job!
moverallscolor[SKINCOLOR_WHITE] = SKINCOLOR_RED // Fire Mario
moverallscolor[SKINCOLOR_SILVER] = SKINCOLOR_NICKEL // SSB4 Variant #5
moverallscolor[SKINCOLOR_GREY] = SKINCOLOR_GREY // Metal Mario
moverallscolor[SKINCOLOR_NICKEL] = SKINCOLOR_WHITE // Game Boy colors
moverallscolor[SKINCOLOR_BLACK] = SKINCOLOR_RED // Red Star Mario
moverallscolor[SKINCOLOR_SEPIA] = SKINCOLOR_BROWN
moverallscolor[SKINCOLOR_BEIGE] = SKINCOLOR_CRIMSON // Rock Mario
moverallscolor[SKINCOLOR_BROWN] = SKINCOLOR_YELLOW
moverallscolor[SKINCOLOR_LEATHER] = SKINCOLOR_DREAM
moverallscolor[SKINCOLOR_SALMON] = SKINCOLOR_PERIWINKLE
moverallscolor[SKINCOLOR_PINK] = SKINCOLOR_TEA
moverallscolor[SKINCOLOR_ROSE] = SKINCOLOR_GARDEN
moverallscolor[SKINCOLOR_RUBY] = SKINCOLOR_TEAL //SSB4 Variant #3
moverallscolor[SKINCOLOR_RASPBERRY] = SKINCOLOR_CYAN //SMW Mario
moverallscolor[SKINCOLOR_RED] = SKINCOLOR_BLUE // Mario (Default)
moverallscolor[SKINCOLOR_CRIMSON] = SKINCOLOR_SALMON // GRAND DAD! FLINSTONES 
moverallscolor[SKINCOLOR_KETCHUP] = SKINCOLOR_CERULEAN 
moverallscolor[SKINCOLOR_DAWN] = SKINCOLOR_MOSS
moverallscolor[SKINCOLOR_CREAMSICLE] = SKINCOLOR_TANGERINE	
moverallscolor[SKINCOLOR_ORANGE] = SKINCOLOR_NAVY	
moverallscolor[SKINCOLOR_PUMPKIN] = SKINCOLOR_BLUEBERRY		
moverallscolor[SKINCOLOR_ROSEWOOD] = SKINCOLOR_SEPIA	
moverallscolor[SKINCOLOR_BURGUNDY] = SKINCOLOR_LILAC	
moverallscolor[SKINCOLOR_TANGERINE] = SKINCOLOR_RED // Builder outfit colors		
moverallscolor[SKINCOLOR_PEACH] = SKINCOLOR_DUSK	
moverallscolor[SKINCOLOR_CARAMEL] = SKINCOLOR_MINT	
moverallscolor[SKINCOLOR_GOLD] = SKINCOLOR_GOLD // Gold Mario
moverallscolor[SKINCOLOR_BRONZE] = SKINCOLOR_ROSEWOOD		
moverallscolor[SKINCOLOR_YELLOW] = SKINCOLOR_WHITE // P-Raccoon suit colors
moverallscolor[SKINCOLOR_MUSTARD] = SKINCOLOR_PURPLE // Wario	
moverallscolor[SKINCOLOR_OLIVE] = SKINCOLOR_KETCHUP		
moverallscolor[SKINCOLOR_VOMIT] = SKINCOLOR_BRONZE			
moverallscolor[SKINCOLOR_GARDEN] = SKINCOLOR_RED // Original 8 bit colors	
moverallscolor[SKINCOLOR_LIME] = SKINCOLOR_JAWZ
moverallscolor[SKINCOLOR_TEA] = SKINCOLOR_POMEGRANATE			
moverallscolor[SKINCOLOR_PISTACHIO] = SKINCOLOR_SLATE	
moverallscolor[SKINCOLOR_ROBOHOOD] = SKINCOLOR_SILVER
moverallscolor[SKINCOLOR_MOSS] = SKINCOLOR_SWAMP			
moverallscolor[SKINCOLOR_MINT] = SKINCOLOR_RASPBERRY		
moverallscolor[SKINCOLOR_GREEN] = SKINCOLOR_BLUEBERRY // Luigi		
moverallscolor[SKINCOLOR_PINETREE] = SKINCOLOR_JET // SSB4 Variant #6		
moverallscolor[SKINCOLOR_EMERALD] = SKINCOLOR_NICKEL		
moverallscolor[SKINCOLOR_SWAMP] = SKINCOLOR_PUMPKIN		
moverallscolor[SKINCOLOR_DREAM] = SKINCOLOR_RUBY	
moverallscolor[SKINCOLOR_AQUA] = SKINCOLOR_EMERALD		
moverallscolor[SKINCOLOR_TEAL] = SKINCOLOR_BYZANTIUM			
moverallscolor[SKINCOLOR_CYAN] = SKINCOLOR_RED // Ice Mario			
moverallscolor[SKINCOLOR_JAWZ] = SKINCOLOR_ROBOHOOD		
moverallscolor[SKINCOLOR_CERULEAN] = SKINCOLOR_STEEL		
moverallscolor[SKINCOLOR_NAVY] = SKINCOLOR_DAWN				
moverallscolor[SKINCOLOR_SLATE] = SKINCOLOR_GOLD	
moverallscolor[SKINCOLOR_STEEL] = SKINCOLOR_RASPBERRY // NES Golf outfit colors		
moverallscolor[SKINCOLOR_JET] = SKINCOLOR_CYAN			
moverallscolor[SKINCOLOR_SAPPHIRE] = SKINCOLOR_BROWN	
moverallscolor[SKINCOLOR_PERIWINKLE] = SKINCOLOR_PEACH		
moverallscolor[SKINCOLOR_BLUE] = SKINCOLOR_RED	
moverallscolor[SKINCOLOR_BLUEBERRY] = SKINCOLOR_WHITE		
moverallscolor[SKINCOLOR_DUSK] = SKINCOLOR_SAPPHIRE			
moverallscolor[SKINCOLOR_PURPLE] = SKINCOLOR_TEAL	
moverallscolor[SKINCOLOR_LAVENDER] = SKINCOLOR_SILVER		
moverallscolor[SKINCOLOR_BYZANTIUM] = SKINCOLOR_BRONZE	
moverallscolor[SKINCOLOR_POMEGRANATE] = SKINCOLOR_PISTACHIO	
moverallscolor[SKINCOLOR_LILAC] = SKINCOLOR_TEA			
		

addHook("ThinkFrame", function()
	for player in players.iterate
		// **** Put your own character's name (not true name!) here! **** DFSASD
		if(player.mo and player.mo.valid and player.mo.skin == "mario")
			// Create the second object
			if not(player.moveralls and player.moveralls.valid)
				// **** Change the xxxx here! This is the same as the MT you put in earlier! **** DFSASD
				player.moveralls = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_MOVERRALLS)
			end
			
			// Set the second object's frame to your character's frame! (and tics)
			player.moveralls.state = player.mo.state
			player.moveralls.frame = player.mo.frame
			player.moveralls.tics = player.mo.tics
			
			// Match the colors!
			if(player.moverallscol)
				player.moveralls.color = player.moverallscol
			else
				if(moverallscolor[player.mo.color] == nil)
					player.moveralls.color = player.mo.color	// Match the color!
				else
					player.moveralls.color = moverallscolor[player.mo.color]
				end
			end
			
			// Move the second object and face to your character!
			P_TeleportMove(player.moveralls, player.mo.x, player.mo.y, player.mo.z)
			
			// Make the second object and face's angles the same as the player's!
			player.moveralls.angle = player.frameangle
			
			// Scale them the same too!
			player.moveralls.scale = player.mo.scale
			
			// Also height
			player.moveralls.height = player.mo.height
			
			// Set the second object's sprite to the second object's... sprite... yeah could've put that better but whatever
			// **** Change this to your SPR you put earlier! **** DFSASD
			player.moveralls.sprite = SPR_MOVR
			
			// REVERSE GRAVITY WOAAAAAH
			if(player.mo.eflags & MFE_VERTICALFLIP)
				player.moveralls.eflags = $1|MFE_VERTICALFLIP
			else
				player.moveralls.eflags = $1 & ~MFE_VERTICALFLIP
			end
			
			// MF2_DONTDRAW WOAAAAAH
			if(player.mo.flags2 & MF2_DONTDRAW)
				or not(player.mo.sprite == SPR_PLAY)
				player.moveralls.flags2 = $1|MF2_DONTDRAW
			else
				player.moveralls.flags2 = $1 & ~MF2_DONTDRAW
			end
			
			// Keep the sobj and face in the world!
			player.moveralls.timer = 1
		else
			if(player.moveralls and player.moveralls.valid)
				P_RemoveMobj(player.moveralls)
			end
		end
	end
end)

addHook("MobjThinker", function(overlay)
	// ***** Put your own character's name (not true name!) here! ***** DFSASD
	if(overlay.skin == "mario")
		and(overlay.target and overlay.target.valid)
		// Create the second object
		// **** Change the xxxx here! This is the same as the MT you put in earlier! **** DFSASD
		overlay.moveralls = P_SpawnMobj(overlay.target.x, overlay.target.y, overlay.target.z, MT_MOVERRALLS)
		
		// Set the second object's frame to your character's frame! (and tics)
		local height = states[overlay.state].var2*FRACUNIT
		// Wiki's down, so replace 117 and 922 with the proper object type and state constant when its back up
		if not(overlay.target.type == MT_SIGN)
			overlay.moveralls.state = overlay.state
			overlay.moveralls.frame = overlay.frame
			overlay.moveralls.tics = overlay.tics
		elseif(overlay.target.type == MT_SIGN)
			overlay.moveralls.frame = S
		end
		
		// Match the colors!
		overlay.moveralls.color = moverallscolor[overlay.color]	// Match the color!
		
		// Move the second object and face to your character!
		P_TeleportMove(overlay.moveralls, overlay.x, overlay.y, overlay.target.z+height)
		
		// Make the second object and face's angles the same as the player's!
		overlay.moveralls.angle = overlay.angle
		
		// Scale them the same too!
		overlay.moveralls.scale = overlay.scale
		
		// Also height
		overlay.moveralls.height = overlay.height
		
		// Set the second object's sprite to the second object's... sprite... yeah could've put that better but whatever
		// **** Change this to your SPR you put earlier! **** DFSASD
		overlay.moveralls.sprite = SPR_MOVR
		
		// REVERSE GRAVITY WOAAAAAH
		if(overlay.eflags & MFE_VERTICALFLIP)
			overlay.moveralls.eflags = $1|MFE_VERTICALFLIP
		else
			overlay.moveralls.eflags = $1 & ~MFE_VERTICALFLIP
		end
		
		// MF2_DONTDRAW WOAAAAAH
		if(overlay.flags2 & MF2_DONTDRAW)
			or(overlay.target.sprite == SPR_PINV)
			overlay.moveralls.flags2 = $1|MF2_DONTDRAW
		else
			overlay.moveralls.flags2 = $1 & ~MF2_DONTDRAW
		end
		
		overlay.moveralls.flags = $1|MF_NOGRAVITY
		
		overlay.momz = 0
		
		// **** Change this to your SPR you put earlier! **** DFSASD
		overlay.moveralls.sprite = SPR_MOVR
		
		overlay.moveralls.timer = 1
	end
end, MT_OVERLAY)
