/*/

ACROBATICS LOCK-ON TECH BLOCK

/*/

/*

Oh boy here we fuckin go
A series of tiny crossmod bonuses. None of these things are particular game changers, but they're included to make the experience more streamlined with other added functionalities. 
defintely way too unfinished.

separated for my sanity:tm:

*/

if acrobatics == nil then --you'll never see this in practice unless i was a certified dumbass
	if not(acrobasics) then print("\142*Acrobatics failed to load - \131what did you do???") end
	return --that's that.
end

rawset(_G, "ac_lockon", CV_RegisterVar({ --Enable or disable cross-mod compatability.
  name = "ac_lockon",
  defaultvalue = "On",
  flags = CV_NETVAR|CV_NOSHOWHELP,
  PossibleValue = CV_OnOff
}))

--HostMod [v7+] Integration. Wew!
local ac_dyk = {
	{msg = "With\x85 BURST \128Tricks, light karters get \130stronger \128trickboosts; slow karters get \130longer \128trickboosts."},
	{msg = "With\x88 STORE \128Tricks, heavier karts need more stored boost to get a full boost going."},
	{msg = "With\x83 AUGMENT \128Tricks, Your weight determines how soon you get to MAX Augment. While heavier karts have an easier time reaching it, their MAX is way lower than lighter karts."},
	{msg = "Release a drift charge with\x85 BURST \128mid-trickboost to get a \130zipboost \128and blast forward. Snip corners or turn in a blink!"},
	{msg = "You can \130sliptide\128 during a trickboost!"},
	{msg = "Missing tricks? Try filling the gauge up, letting it hit the top, and then releasing a little before you land. The meter should deflate allowing you to land a trick with no worries."},
	{msg = "Having the trick button held down upon landing will result in a trickfail and no boost. Don't get greedy!"},
	{msg = "\x88STORE \128Tricks are the only type of trick that persist after death and spinout. Use it to get back in the fray quickly!"},
	{msg = "Release a \x88STORE \128Trick in mid-air for a bit more of a push. Release a\x85 BURST \128Trick in midair to careen off the screen...?"},
	{msg = "\x83 AUGMENT \128Tricks are made for the long game. The bonuses stack to something incredibly fast over time, provided you can maintain it..."},
	{msg = "Be wary of Daredevil warnings; you can get bonuses from all three trick styles, but the penalty for failure is high..."},
	{msg = "You can adjust your landing angle during a trick to make sure you launch off in the right direction."},
	{msg = "You can change your trick button to BRAKE or CUSTOM 1 - though some other mods may conflict with using either."},
	{msg = "You can adjust your trickstyle race-to-race by typing \130trickstyle #\128 in the console. See what fits your playstyle the best!"},	
	{msg = "Make like Garen and SPIN TO WIN.", humor = true}
}
local ac_hmload = false

--Why a ThinkFrame? Probably because someone might load acrobatics before hostmod first. yayyy.
addHook("ThinkFrame", function()
	if ac_hmload then return end
	if server and (CV_FindVar("hm_scoreboard")) and leveltime > TICRATE --check for hostmod
		for i = 1, #ac_dyk
			HM_Scoreboard_AddTip(ac_dyk[i])
		end
		HM_Scoreboard_AddMod({disp = "Acrobatics", var = "ac_active"})
		ac_debug("====THE MORE YOU KNOW")
		ac_hmload = true
	end
end)

--These all run after mo validity checks, so checking is a moot point.

--FOR THINKFRAME, BEFORE TRICKS
rawset(_G, "ac_lockon_prethink", function(p)
	if ac_lockon.value
	
		if p.mo.drifthold then ac_debug("no tricks4mkdrift") end  --for the 0.8 people that use mkdrift??
		if (CV_FindVar("slipstream_boostchain"))
			ac_debug("bluestacks.")
			if CV_FindVar("slipstream_boostchain").value
				booststacknerf = true
				ac_debug("SHUT IT DOWN")
			else
				booststacknerf = false
				ac_debug("B-but not on")
			end
		end
		
		
	end
end)

--FOR LANDING TRICKS
rawset(_G, "ac_lockon_land", function(p)
	if ac_lockon.value
	
		--ELIMINATION: A person meant to die will have enhanced boosts of some sort.
		if p.needOrbit --No need to bust into elimination - if the mod's on, this var in p will be defined somehow
			if p.trickstyle == 0
				p.trickboost = $*2 
			elseif p.trickstyle == 1
				p.acrostore = $*2 
			elseif p.trickstyle == 2
				p.basebonus = $*2
				p.basebonusgrade = $*2
			end
			ac_debug("LOCKON: DANGER TRICKS")
		end
		
		/*
		BATTLE PLUS: Aggrobatics will act differently according to BP's gamemodes.
			Hot Eggtato: The tagged's STOMP will rather than push away!
			Emerald Thief: Everyone else's STOMP will draw in, rather than push away!
			The target player in question will have a stronger opposite force in relation...
		*/
		if battleplus and G_BattleGametype()
			if server.bp_gamemode == 3 --Emerald Thief
				if p == server.et_t
					ac_stompPush(p, stompDist, 50*FRACUNIT)
				else
					ac_stompPush(p, stompDist, -30*FRACUNIT) --succ
				end
			elseif server.bp_gamemode == 5 --Hot Eggtato
				if p == server.he_p
					ac_stompPush(p, stompDist, -30*FRACUNIT) --succ
				else
					ac_stompPush(p, stompDist, 50*FRACUNIT)
				end			
			else
				ac_stompPush(p, stompDist, 40*FRACUNIT) --default to regular stomp fx.
			end
		end
		
		/*
		EASTER EGGS for skin-specific characters... tbd
		*/
		
	end
end)

--TRICKBOOST THINK
rawset(_G, "ac_lockon_trickboostthink", function(p)
	if ac_lockon.value
	
		--TSRB2K: Trickboost augments slingshots.
		if p.mo.tsr_slingshotout 
			local speedboostplus = p.trickbooststr/10 + (p.mo.tsr_slingshot)*FRACUNIT*8/1000
			p.kartstuff[k_speedboost] = max($, speedboostplus)	--remax-min'd
			ac_debug("LOCKON: SLINGTRICKboost")
		end	
		
	end
end)

--TRICKFAIL
rawset(_G, "ac_lockon_trickfail", function(p, pain)
	if ac_lockon.value
	
		--HITFEED v2: Broadcast overcharge terrible wipeouts. [thx snu]
		if (hitfeed) and pain > 2
			local s = {{nil, nil}, {nil, nil}, nil}
			local v = {{p.name, p.mo.hf_overridenamecolor or p.skincolor}, {skins[p.mo.skin].facemmap, p.skincolor}, p}
			HF_SendHitMessage(s, v, "K_CHGHF", p.skincolor)
			ac_debug("LOCKON: HIT WAS FED")
		end
		
		--HPMOD: Trickfails hurt a bit, don't they?
		if hpmod ~= nil
			hpmod_damagehp(p, 2*pain, {{"Wipeout", 0}, {"K_CHGHF", 0}}, false) 
			ac_debug("LOCKON: tony hawk's existential trick crisis")
		end
		
	end
end)	

--Garbage collection.
acrofunc_loaded = nil
