'== included in the starnode.bmx file =='

Print "EVENT TRIGGER " + e.name + "   (layer " + pnode.eventLayer +")"

'an event can only be triggered once
If a <> Null Then ListRemove(a.eventList, e)

'certain conditionals filter events
If a <> Null
	For Local filter:Event = EachIn a.eventList
		If e.selectable <= pnode.eventLayer
			Select e.name
			Case "if_bossalive"
				'clears the rest of the actions if the boss died
				If Not bossSurvived
					ClearList(a.eventList)
					Print a.name + " events cleared because boss is dead"
					Return False
				EndIf
			EndSelect
		EndIf
	Next
EndIf

Local div = Instr(e.name,"_")
Local label$, datum$
If div > 0 Then
	label = Lower(e.name[..div-1])
	datum = Lower(e.name[(div)..])
	Print " label " + label + "   datum " + datum
Else
	label = Lower(e.name)
EndIf

If label <> "sfx" Then playSFX(getSound("hit_misc.wav"), blipChannel)

Select label
Case "sfx"
	playSFX(getSound(datum), Null)

Case "battle"
	mode = MODE_BATTLE
	
	If Not a.durable
		Local box:Messagebox = new_message("ALIEN NEMESIS APPROACHES!", "stolenrobot", 16)
		box.x:+ sidewid/2
	EndIf

Case "station"
	If bossSurvived
		'get a full heal
		'a.addEvent("fullheal", 5)
		'be a shop
		a.addEvent("shop", 6)
	Else
		pnode.addExplosionEffect(a.x, a.y)
		pnode.addText("They didn't make it...", a.x, a.y)
		ListRemove(pnode.actorList, a)
	EndIf

Case "shop"
	'get our inventory
	For Local i = 0 To 5
		Local ctype$
		If i = 2 Or i = 5
			If Rand(1,2) = 1 Then ctype = "gun" Else ctype = "ability"
		Else
			If Rand(1,2) = 1 Then ctype = "misc" Else ctype = "addon"
		EndIf
		'Local inventoryList:TList = pilot.selectPurchasableComponentsByCost(1, 200 * starnode.level, Null, ctype)
		'Local inventoryList:TList = pilot.selectPurchasableComponentsByCost(1, (starnode.bank / (6-i)), Null, ctype)
		'Local inventoryList:TList = pilot.selectPurchasableComponentsByCost(1, (starnode.repairStep*5 / (6-i)), Null, ctype)
		'Local inventoryList:TList = pilot.selectPurchasableComponentsByCost(1, starnode.level * (currentRepairCost()/2) / (6-i), Null, ctype)
		Local inventoryList:TList = pilot.selectPurchasableComponentsByCost(1, (400 * starnode.level) / (6-i), Null, ctype)


		For Local comp$ = EachIn inventoryList
			a.addEvent("comp_"+comp, 0)
		Next
	Next
	
	'give the option to open up the shop
	shopB.active = True
	shopActor = a
				
Case "points"'get some points
	Local loot
	If datum = "" Then loot = Rand(1, starnode.level) * 50 + Rand(0,50) Else loot = Int(datum)
	bank:+ loot
	bank_old = bank'we take care of the notification here -v
	pnode.addText("+" + loot + " points!", a.x, a.y)
	
	'remove the treasure chest
	ListRemove(pnode.actorList, a)

Case "message"
	Local box:Messagebox = new_message(e.text, e.mug, 30)
	box.x:+ sidewid/2
	If Not e.skippable Then listenToMessage = True
	
Case "gate", "winnerisyou"
	'get the destination from our eventlist
	For Local dest:Event = EachIn a.eventList
		If Left(dest.name, 5) = "dest_"
			Local d$ = Right(dest.name, Len(dest.name)-5)
			destination = d
			mode = label'will fade out the map then call this event
			If label = "winnerisyou" Then fadeOnEvent = False Else fadeOnEvent = True'neverminde no fade out
		EndIf
	Next
					
Case "fullheal"
	health = healthMax
	pnode.addText("Full heal!", 0, -1)

Case "stopmusic"
	stopmusic = True

Case "equipment"'get a component
	Local comptype$ = "misc"
	If Rand(1,3) = 1 Then comptype = "addon"
	'If Rand(1,6) = 1 Then comptype = "gun"
	'If Rand(1,6) = 1 Then comptype = "ability"

	'select the component
	Local comp$ = String(pilot.selectPurchasableComponentsByCost(1, 50 * starnode.level, Null, comptype).First())
	purchaseList.addLast(comp)
	newcompList.addLast(comp)
	pnode.addText("Found " + comp + "!", a.x, a.y)
	
	'remove the treasure chest
	ListRemove(pnode.actorList, a)
	
Case "getsweetrims"
	purchaseList.addLast("Sweet Rims")
	newcompList.addLast("Sweet Rims")

Case "extralife"'get an ankh
	Local comp$ = "Ankh"
	purchaseList.addLast(comp)
	newcompList.addLast(comp)
	pnode.addText("Obtained " + comp + "!", a.x, a.y)
	
	'remove the treasure chest
	ListRemove(pnode.actorList, a)



	
Case "treasure"'get a component or a potion or something
	Local treasure = Rand(1,10)
	Local e:StarEffect
	
	'HEAL
	If treasure = 1 And health < healthMax
		a.addEvent("fullheal")
	'POINTS
	ElseIf treasure <= 1'4
		Local loot = starnode.level * Rand(25, 50)
		bank:+ loot
		bank_old = bank'we take care of the notification here -v
		pnode.addText("+" + loot + " points!", a.x, a.y)
	'COMPONENT
	ElseIf treasure <= 10
		'get the first component from our eventlist
		Local comp$ = String(pilot.selectPurchasableComponentsByCost(1, 50 * starnode.level).First())
		purchaseList.addLast(comp)
		newcompList.addLast(comp)
		pnode.addText("Found " + comp + "!", a.x, a.y)
	EndIf
	
	'remove the treasure chest
	ListRemove(pnode.actorList, a)

Case "pausedestructcountdown"
	'timerRemove(timerList, "destructCountdown")
	timerDisable(timerList, "destructCountdown", True)
	'timerSet(timerList, "destructCountdown", -1)
	'timerBump(timerList, "destructCountdown", -1)
	

Case "startdestructcountdown"
	timerSet(timerList, "destructCountdown", 6000)
	timerDisable(timerList, "destructCountdown", False)'enable the timer
			
Case "selfdestruct"
	health = 0
	pnode.addExplosionEffect(0,0)
	highlight = pnode
	ClearList(mboxList)
	ClearList(shakytextList)
	ship_gfx = resizeImage(load_shipimage(GFX_EFFECT_PATH + "explode5.png")[1], 5)
	
	steamAchievement("eden_gate")

Case "returntosender"
	If previousNode <> Null Then moveToNode(previousNode, True)'return to the previous node, retaining any displayed messages

Case "countsavedcryopods"
	Local count
	For Local sname$ = EachIn warpedOutList
		If Lower(sname) = "cryopod" Then count:+ 1
	Next
	Print "=============================== " + count + " ========="
	
	'if any cryopods were saved
	If count > 0
		'adds a pixel to the pilot's collection
		addPixel()
		If count > 1
			pnode.addText("Rescued " + count + " cryopods!", a.x, a.y)
		Else
			pnode.addText("Only a single cryopod rescued.", a.x, a.y)
		EndIf
		
		cryopods:+ count
	Else
		pnode.addText("Not a single cryopod survived...", a.x, a.y)
	EndIf
	
	ListRemove(pnode.actorList, a)
	
Case "bigredbutton"
	'make a button to destroy the planet
	deathstarB.active = True
	deathstarActor = a
	locked = True

Case "survivor"
	'select a random survivor that we haven't found yet
	If Not ListIsEmpty(humanList)
		Local pix:Actor = Actor(randomlySelectObjectFromList(1, humanList).RemoveFirst())
		Print "Found survivor " + pix.name
		pix.x = a.x
		pix.y = a.y
		'add this actor to this node
		pnode.actorList.addLast(pix)
		'upgrade this actor if we've increased the base difficulty
		If level >= 2 Then pix.upgrade()
		'remove this actor from the list of people we can encounter
		ListRemove(humanList, pix)
	EndIf

Case "pixel"
	Print "Got pixel!"

	Local survivorSurvived = False
	If bossSurvived Then survivorSurvived = True
	For Local sname$ = EachIn warpedOutList
		If Lower(sname) = "" Then survivorSurvived = True
		If Lower(sname) = "chatbot" Then survivorSurvived = True
	Next

	'if the human survived the fight
	If survivorSurvived
		'adds a pixel to the pilot's collection
		addPixel()
		pnode.addText("Found survivor!", a.x, a.y)
	Else
		pnode.addText("They didn't make it...", a.x, a.y)
		'ClearList(mboxList)
	EndIf
	
	ListRemove(pnode.actorList, a)
	
Case "fleet"
	'get the correct mugshot for this actor
	If a.portrait <> ""
		a.icon = LoadImage(GFX_HUD_PATH + "char_" + a.portrait + ".png")
		SetImageHandle(a.icon, 0, 0)
	EndIf
	
	'fleetBList.addLast(a.makeFleetButton())
	a.makeFleetButton(Self)


	'this actor is just a holder for the survivor spawn information; no more events
	ClearList(a.eventList)

	'put this actor in our list of encountered survivors
	fleetList.addLast(a)
	'fleetMobilizedList.addLast(a)
	ListRemove(pnode.actorList, a)

	'add some upgrade to the fleet
	'upgradeList.addLast(datum)
	
	'clear ALL survivors from the rest of the map; we can only get one per level
	For Local n:Node = EachIn nodeList
		For Local char:Actor = EachIn n.actorList
			For Local charevent:Event = EachIn char.eventList
				If Lower(charevent.name) = "survivor"
					n.addExplosionEffect(char.x,char.y)
					ListRemove(n.actorList, char)
				EndIf
			Next
		Next
	Next
	
Case "endnaptime"
	'repair and activate all allies
	For Local char:Actor = EachIn fleetList
		fleetMobilizedList.addLast(char)
		char.repairTimer = 0
		ListRemove(fleetDamagedList, char)
	Next

Rem
Case "economy"
	Local e:StarEffect = pnode.addText("Minat:")
	e.yoffset = -14 - TextHeight("BOBCAT")
	bank:+ 50
			
	

Case "maintenance"
	Local heal# = healthMax * .25
	If health + heal > healthMax Then heal = (healthMax - health)
	If heal > 0
		health:+ heal
		pnode.addText("Dovell: +"+Int(heal)+" health")
	EndIf
EndRem

Case "epilogue1"
	stopmusic = True
	lockButtons = True

	'if the boss survived the fight
	If bossSurvived
	
		'get the boss back from the explodelist
		For Local boss:Actor = EachIn pnode.explodeActorList
			If boss.displayName = "ARCHANGEL"
				pnode.actorList.addLast(boss)
				ListRemove(pnode.explodeActorList, boss)
				ClearList(boss.eventList)
				ClearList(boss.waveList)
			EndIf
		Next
		'short sequence
		a.addMessage("ARCHANGEL: I continue to exist; you spared me?", "archangel", 4, 0, 1)
		a.addMessage("TRAITOR PILOT VILLAIN TRUANT BLACKGUARD OFFENDER WRETCH", "stolenrobot_angry", 4, 0, 1)
		a.addMessage("COMMAND TO PILOT LIFEPOD SYSTEMS: SHUT DOWN IMMEDIATELY", "stolenrobot_angry", 4, 0, 1)
		a.addMessage("THEN EJECT PILOT", "stolenrobot", 4, 0, 1)
		
		a.addEvent("startdestructcountdown", 5)
		a.addEvent("revealhiddennodes", 6)

	Else
		
		'remove the epilogue 2 node
		ClearList(pnode.gateList)
		
		'KHAAAAN
		a.addMessage("ARCHANGEL: No...", "archangel", 5, 0, 1)
		a.addMessage("It's done. Are you satisfied?", "pilot", 6, 0, 1)
		a.addMessage("GREAT JUSTICE IS SERVED WITH RELISH", "stolenrobot", 6, 0, 1)
		
		'fade out, play cutscene
		a.addEvent("credits1", 6)
	EndIf
	
Case "revealhiddennodes"
	For Local g:Node = EachIn pnode.gateList
		g.hidden = False
	Next
	
Case "classicarcade"
	'timerSet(timerList, "destructCountdown", -1)
	'timerBump(timerList, "destructCountdown", -1)
	
	'saveStarnode(Self)
	
	health = healthMax

	For Local player:TGNetObject = EachIn playerObjectList
		Local pship:Ship = loadShip("VectorClassic",1,"ALPHA")
		Local pshipString$ = configToString(pship)
	
		If pship <> Null
			Print pshipString
			'SetGNetTarget(player, pship)
			SetGNetString(player, NET_PLAYER_SHIP, pshipString)
			'pship.controller.remoteInput = TGNetObject(GetGNetTarget(player))
		EndIf
	Next
	
	getPlayerStats()
	
Case "epilogue2"

	
	'the ol switcharoo, hide the normally-displayed player icon and make a new one to explode in its place
	hidePlayerIcon = True
	Local p:Actor = New Actor
	p.icon = player_gfx
	pnode.explodeActorList.addLast(p)

	'fade out, play cutscene
	a.addEvent("credits2", 6)
	
Case "credits1", "credits2"

	'get an achievement
	If label = "credits1" Then steamAchievement("ending_bad")
	If label = "credits2" Then steamAchievement("ending_good")
	If hardcore Then steamAchievement("ending_hard")

	'get points from the bank
	pilot.points:+ bank

	fadeOnEvent = True
	fadeTarget = 1
	mode = label'have gameControl handle the fadeout, credits roll
EndSelect
