#base robot_giant.pop
#base robot_standard.pop
#base robot_gatebot.pop

// This is an example mission with vscript and popextensions
// Functions provided by popextensions are defined at the end of the file
// Documentation: https://github.com/potato-tf/PopExtensionsPlus/blob/main/documentation.md
WaveSchedule
{

	StartingCurrency		1200
	RespawnWaveTime 		2
	CanBotsAttackWhileInSpawnRoom no

	Mission
	{
		Objective Engineer

		InitialCooldown 1
		Where spawnbot
		Where spawnbot_mission_sniper
		BeginAtWave 2
		RunForThisManyWaves 1
		CooldownTime 1
		DesiredCount 1

		TFBot
		{
			// Template T_TFBot_Engineer_Sentry_Teleporter
			Template T_TFBot_Engineer_Sentry_Tele_Battle
			Tag "popext_dispenseroverride{ type = OBJ_SENTRYGUN }"
			// Attributes AlwaysFireWeapon
		}
	}

	// Wave X Spies
	Mission
	{
		Objective           Spy
		Where               spawnbot_mission_spy
		BeginAtWave         1
		RunForThisManyWaves 1
		CooldownTime        10
		DesiredCount        5
		InitialCooldown     0
		TFBot { Template T_TFBot_Spy }
	}
	
	Wave
	{
		// Add or replace existing InitWaveOutput with code below
		InitWaveOutput
		{
			Target BigNet
			Action RunScriptCode
			Param "
				// Load popextensions script
				IncludeScript(`popextensions_main.nut`, getroottable())

				// parameters: text, prefix color, prefix text, sync with game_text true/false
				Info(@`This is an explanation text example
				|PAUSE 2
				|Explanation text can support pauses, and optionally syncing chat prints with the game_text
				|By default, text lifetime is determined by the length of the sentence
				|See DoExplanation in util.nut for more info`, 
				`FFFF66`, `Explanation: `, true)

				::ExtraItems <- {

					`Wasp Launcher`: {

						OriginalItemName = `Upgradeable TF_WEAPON_ROCKETLAUNCHER`
						Model = `models/weapons/c_models/c_wasp_launcher/c_wasp_launcher.mdl`
						`Blast radius increased` : 1.5
						`max health additive bonus` : 100
						`reloads full clip at once` : 1
						`is miniboss` : 1
						// `min respawn time`: 500
						`provide on active` : 1
						`move speed bonus` : 0.4
						`rocket penetration` : 10
					}
				}

				MissionAttrs({

					// EnableGlobalFixes  	 = 1
					NoReanimators 	   	 = 1
					ForceHoliday 	   	 = 2
					NoRome 			   	 = 2
					BotHeadshots 	   	 = 1
					BotsAreHumans 	   	 = 2
					WaveStartCountdown 	 = 3
					SpellRateCommon    	 = 0.5
					NoSkeleSplit 	   	 = 1
					WaveNum 		   	 = 3
					MaxWaveNum 		   	 = 60
					StandableHeads 	   	 = 1
					MultiSapper 	   	 = 1
					TeamWipeWaveLoss   	 = 1
					UnusedGiantFootsteps = 2
					GiantSentryKillCountOffset = -4

					ClassLimits = {
						[TF_CLASS_SCOUT]   = 1,      // Limit class to 1
						[TF_CLASS_SPY] 	   = 1,      // Prevent class selection
					}
					SoundOverrides = { //overrides teamplay_broadcast_audio sounds
						`Announcer.MVM_Get_To_Upgrade`: null
						`music.mvm_end_last_wave`: null
						`Game.YourTeamWon`: null
						`MVM.PlayerDied`: null
					}
					IconOverride = {

						scout = { //remove from current wave
							count = 0
							flags = MVM_CLASS_FLAG_NORMAL
						}

						pyro = { //replace with a new icon
							replace = `scout_bat`
							count = 20
							flags = MVM_CLASS_FLAG_NORMAL
							newflags = MVM_CLASS_FLAG_ALWAYSCRIT|MVM_CLASS_FLAG_MINIBOSS // see constants.nut for flags
							index = 4
						}
					}

					// AddCond = [32, 10] //speed boost for 10s

					LoadoutControl = {

						`tf_weapon_rocketlauncher_directhit`: `Wasp Launcher`, //accepts custom weapons as well
						// `Mad Milk`: `Pretty Boy's Pocket Pistol`,
						// [812] = {`tf_weapon_pistol`: 23},
						// tf_weapon_sniperrifle = null,
						[10442] = {`tf_wearable` : `Memes vs Machines Player 2019`},
						// `18, 102, 205, 658, 15006, 15014, 15129, 15130, 15150`: {`tf_weapon_minigun`: 23}
					},

					PlayerAttributes = {

						`damage bonus`: 10,
						`can breathe under water`: 1,
						`mult swim speed`: 3,
						`crit when health below`: 75,
						`last shot crits`: 0.2,
						`mult dmg vs same class`: 2,
						`reloads full clip at once`: 1,
						`passive reload`: 1,
						`max health additive bonus` : 100,

						[TF_CLASS_SCOUT] = {
							`damage bonus` : 5,
							`fire rate penalty` : 2,
							`max health additive bonus` : 100,
							`replace weapon fire sound`: [ [`Weapon_Soda_Popper.Single`, `Weapon_Soda_Popper.SingleCrit`], [`weapons/flaregun/fire.wav`, `Weapon_CowMangler.Single`] ],
						},

						[TF_CLASS_SOLDIER] = {
							`damage penalty` : 0.5,
							`fire rate bonus` : 0.5,
							`mult dmg vs same class`: 10
							`replace weapon fire sound`: [ [`Weapon_Liberty_Launcher.Single`, `Weapon_Liberty_Launcher.SingleCrit`], [`weapons/flaregun/fire.wav`, `Weapon_CowMangler.Single`] ],
						},
					},
					ItemAttributes = {
						`Memes vs Machines Player 2019` : {
							// `set item tint RGB`: 3555399,
							`set item tint RGB`: 4669494,
							`set item tint RGB 2`: 4079424,
							`item style override`: 1,
						}
						`Madness vs Machines Pinnacle of Ingenuity 2019`: {
							`set item tint RGB`: 16738816,

						}
					}
				})
			"
		}
		StartWaveOutput
		{
			Target wave_start_relay
			Action Trigger
		}
		DoneOutput
		{
			Target wave_finished_relay
			Action trigger
		}
		WaveSpawn
		{
			Name "Wave1"
			ClosestPoint spawnbot
			TotalCount 10
			MaxActive 5
			SpawnCount 5
			WaitBeforeStarting 1
			TotalCurrency 200
			TFBot
			{
				Attributes IgnoreFlag
				// Attributes IgnoreEnemies
				BehaviorModifiers Push
				Attributes DisableDodge
				Tag "popext_forceromevision"
				Tag "popext_addcond{cond = 32, duration = 10}"
				Tag "popext_alwaysglow"
				// remove 2 scout_bats per death, positive values will add icons on death
				Tag "popext_iconoverride{
					icon = `scout_bat`
					count = 1
				}"
				Tag "popext_actionpoint{
					target = `-648 4802 234`
					repeats = 5
					duration = 1
					distance = 100
					waituntildone = true
					repeat_cooldown = 10
					killaimtarget = 2048
					aimtarget = `RandomEnemy`
				}"
				// Tag "popext_improvedairblast"
				// Tag "popext_usehumananims"
				Tag "popext_spell{type = SPELL_SKELETON, cooldown = 5, charges = 5}"
				Tag "popext_ringoffire{damage = 20, interval = 2}"
				// Tag "popext_meleeai"
				// Tag "popext_reprogrammed"
				Class Pyro
				Skill Hard
				// Item "The Thermal Thruster"
				// Item "Fancy Spellbook"
				// Attributes IgnoreEnemies
				// WeaponRestrictions SecondaryOnly
				// ItemAttributes {
					// ItemName "TF_WEAPON_FLAMETHROWER"
					// "fire particle blue" "flamethrower_underwater" // client crash
				// }
				// CharacterAttributes
				// {
					// "damage bonus" -10
				// }
			}
		}
		WaveSpawn
		{

			Name "Wave1a"
			Where spawnbot
			TotalCount 9999
			MaxActive 1
			SpawnCount 1
			WaitBeforeStarting 0
			WaitBetweenSpawns 5
			TFBot
			{
				Template T_TFBot_Giant_Soldier
				Attributes HoldFireUntilFullReload // now works with every clip-based weapon with EnableGlobalFixes mission attribute
				// Attributes IgnoreFlag
				Item "The Cow Mangler 5000"
				Tag "popext_homingprojectile{turn_power = 0.5, speed_mult = 1.0}"
				Tag "popext_customweaponmodel{model = `models/weapons/c_models/c_wasp_launcher/c_wasp_launcher.mdl`}"
				// Tag "popext_reprogrammed"
				Tag "popext_usehumanmodel"
				// Tag "popext_meleeai"
				Tag "popext_spawnhere{where = `-779.491150 3302.379883 312.992340`, spawn_uber_duration = 3}" //custom spawn origin
				Tag "popext_customattr{attr = `wet immunity`, value = 1}"
				Tag "popext_weaponresist{weapon = ID_IRON_CURTAIN, amount = 20}" //20x damage from iron curtain
				// Tag "popext_weaponresist{type = 298, amount = 20}"
				// Tag "popext_setskin{skin = 0}"
				// Tag "popext_mobber"
				// Tag "popext_fireweapon{button = IN_ATTACK2}"
				Tag "popext_rocketcustomtrail{name = `eyeboss_projectile`}"
			}
		}
		WaveSpawn
		{

			Name "Wave1a"
			Where spawnbot
			TotalCount 9999
			MaxActive 1
			SpawnCount 1
			WaitBetweenSpawns 1
			WaitBeforeStarting 1
			TFBot
			{
				Class Scout
				WeaponRestrictions MeleeOnly
				// Attributes UseBossHealthBar
				Health 400
				Tag "popext_giveweapon{weapon = `tf_weapon_bat`, id = 1071, attrs = {`item style override`: 0}}"
				// Tag "popext_halloweenboss|eyeball_boss|3000|752 4529 389|60"
				// CharacterAttributes
				// {
					// "move speed bonus" 0.2
				// }
			}
		}
	}
	Wave
	{
		InitWaveOutput
        {
            Target bignet
            Action RunScriptCode
            Param "

                IncludeScript(`popextensions_main`, getroottable())

                MissionAttrs({

                    WaveStartCountdown = 1
                    // `ExtraTankPath`: [
					// 	[`686 4000 392`, `667 4358 390`, `378 4515 366`, `-193 4250 289`],
					// 	[`640 5404 350`, Vector(640, 4810, 350), `640 4400 550`, `1100 4100 650`, `1636 3900 770`]
					// ]
					ExtraTankPath = {

						name = `mytankpath`
						tracks = [

							[`686 4000 392`, `667 4358 390`, `378 4515 366`, `-193 4250 289`],
							[`640 5404 350`, Vector(640, 4810, 350), `640 4400 550`, `1100 4100 650`, `1636 3900 770`]
						]
					}

					SoundOverrides = { //overrides teamplay_broadcast_audio sounds
						`Game.YourTeamWon`: 			null
						`music.mvm_end_last_wave`: 		null
						`Announcer.MVM_Get_To_Upgrade`: null
					}
                })

                PopExt.CustomTank(`abc*`, {

                    Scale = `0.5`
                    DisableSmoke = true
					NoDeathFX = 2

                    function OnSpawn(tank, name) {

                        local prop = SpawnEntityFromTable(`prop_dynamic`, {model = `models/props_badlands/barrel01.mdl`, origin = `0 0 79`})
                        local trigger = SpawnEntityFromTable(`trigger_ignite`, {origin = `0 0 100`, spawnflags = `1`})

                        trigger.SetSize(Vector(-175,-175,-175), Vector(175,175,175))
                        PopExtUtil.SetParentLocalOrigin([prop, trigger], tank)

                        tank.KeyValueFromString(`rendercolor`, `255 0 0`)
                    }
                })

                PopExt.CustomTank(`tank2`, {

                    IsBlimp = true
					Icon = `blimp2_lite`
					StartTrack = `extratankpath2_1` //this is only required for blimps so the func_tracktrain knows where to go
					CritImmune = true
					NoScreenShake = true
					CrushDamageMult = 0
					Team = 2

					SoundOverrides = {

						Ping = `npc/combine_gunship/ping_search.wav`
						Start = `ui/chime_rd_2base_pos.wav`
						EngineLoop = `npc/combine_gunship/dropship_engine_distant_loop1.wav`
						Destroy = `ui/chime_rd_2base_neg.wav`
						Deploy = `ui/chime_rd_2base_neg.wav`
					}
					// SpawnTemplate = `templateName`
                })
				// create a point_viewcontrol with custom ent_additions spawnflags
				::PointTemplates <- {

					viewcontrol = {

						[0] = {

							point_viewcontrol = {

								targetname = `viewcontrol_example`
								spawnflags = 256|512 //custom spawnflags to fix viewcontrol + enable for all players
								vscripts = `popextensions/ent_additions`
								origin = `32 4892 659`
								angles = `23 -47 0`
							}
						}
					}
				}
            "
		}
		StartWaveOutput
		{
			Target bignet
			Action RunScriptCode
			Param "
				EntFire(`wave_start_relay`, `Trigger`)

				SpawnTemplate(`viewcontrol`)

				// the name ends with 1 due to name fixup, set NoFixup 1 in 'viewcontrol' to disable this
				EntFire(`viewcontrol_example1`, `Enable`, 1)
				EntFire(`viewcontrol_example1`, `Disable`, 3)
			"
		}
		DoneOutput
		{
			Target wave_finished_relay
			Action trigger
		}
        WaveSpawn
        {
            Name "Wave2a"
            TotalCount 1
            TotalCurrency 0
            Tank
            {
                Health 100
                Speed 75
                Name "abcd"
                StartingPathTrackNode "mytankpath1_1"

                OnBombDroppedOutput
                {
                    Target boss_deploy_relay
                    Action Trigger
                }
            }
        }
        WaveSpawn
        {
            Name "Wave2b"
            TotalCount 1
            TotalCurrency 0
			WaitForAllDead "Wave2a"
            Tank
            {
                Health 100
                Speed 70
                Name "tank2"
                Skin 0
                StartingPathTrackNode "mytankpath2_1"

                OnBombDroppedOutput
                {
                    Target boss_deploy_relay
                    Action Trigger
                }
            }
        }
	}

	Wave
	{
		InitWaveOutput
		{
			Target bignet
			Action RunScriptCode
			Param "
				IncludeScript(`popextensions_main`, getroottable())

				// Besides loading your 'point templates' from a separate pointtemplates.nut file,
				// you can also add them on the fly

				if(!(`PointTemplates` in getroottable()))
					::PointTemplates <- {}

				PointTemplates.SampleTemplateName <- {
					NoFixup = 1, // Name fix-up appends a unique number to the end of the targetname to separate identical templates.  Set NoFixup 1 to disable this behavior
					[0] = { //first entity to spawn in the template
						item_teamflag = { //entity classnames here
								targetname = `example_flag`
								origin = `0 0 0`
								angles = `0 0 0`
								//other item_teamflag key/values go in here
						}
					},
					[1] = { //second entity to spawn in the template
						prop_dynamic = {
								targetname = `example_barrel`
								parentname = `example_flag` //parent a barrel prop to the flag
								model = `models/props_badlands/barrel01.mdl`
						}
					}
				}
				PointTemplates.Sentry <- {
					KeepAlive = 1, //Dont remove entities after their spawner had been killed
					RemoveIfKilled = `sentry`, // Remove all entities in template if the specified entity is killed
					[0] = {
						OnSpawnOutput = { //Parent entity is the !activator. Set builder to parent entity
							Target = `sentry` //targetname of an entity added below
							Action = `setbuilder`
							Delay = 0.2
						}
					},
					[1] = {
							OnParentKilledOutput = { //kill players after the carrier was dead
							Target = `player`
							Action =`sethealth`
							Delay = 0.00
							Param = 1
						}
					},
					[2] = {
						prop_dynamic = { //Entity classname
							model = `models/props_coalmines/wood_fence_short_128.mdl` //keyvalue
							solid = 0 //Physics collision model (0- No collision, 1 - BSP, 2 - Bounding box, 3 - Oriented bounding box, 6 - VPhysics)=
						}
					},
					[3] = {
						obj_sentrygun = {
							targetname = `sentry` //Entity name. Required if the entity is going to be referenced somewhere
							origin = `0 0 0`
							teamnum = 3 // 2 - Red team, 3 - Blu team
							SolidToPlayer = 0
						}
					}
				}

				PopExtTags.AddRobotTag(`abc`, {

                    // Called when the robot is spawned
                    function OnSpawn( bot, tag ) {

                        bot.KeyValueFromString(`rendercolor`, `0 255 0`)
                        // Create a barrel prop on bot's head
                        PopExtUtil.CreatePlayerWearable(bot, `models/props_farm/wooden_barrel.mdl`, false, `head`)
                    },

                    // Called when the robot is killed
                    // Params as in player_death event in https://wiki.alliedmods.net/Team_Fortress_2_Events
                    // Params may be null if the bot was forcefully changed to spectator team
                    function OnDeath( bot, params ) {
                        // Restore colors back to normal as necessary
                        bot.KeyValueFromString(`rendercolor`, `255 255 255`)
                    },
                })

			"
		}

		StartWaveOutput
		{
			// if you have templates that you want to spawn on wave start, replace the StartWaveOutput trigger with RunScriptCode
			Target bignet
			Action RunScriptCode
			Param "
				// The original StartWaveOutput trigger, change if necessary
				EntFire(`wave_start_relay`, `Trigger`)

				// SpawnTemplate's args: (string pointtemplatename, handle parent = null, origin = '', angles = '')
				// origin/angles will also accept Vectors/QAngles
				// calling SpawnTemplate here will spawn when the wave starts
				SpawnTemplate(`Sentry`, null, `0 -800 500`)

			"
		}

		DoneOutput
		{
			Target wave_finished_relay
			Action trigger
		}

		WaveSpawn
		{
			Name "Wave3"
			Where spawnbot
			TotalCount 2
			MaxActive 2
			SpawnCount 2
			WaitBeforeStarting 1
			WaitBetweenSpawns 5
			TotalCurrency 5000
			TFBot
			{
				Template T_TFBot_Giant_Soldier
				Attributes HoldFireUntilFullReload //now works with every clip-based weapon
				Item "The Cow Mangler 5000"
				Tag "popext_spawntemplate{template = `Sentry`, attachment = `head`}" // spawns the template with the bot as its parent
			}
		}

		// Subwave description here
		WaveSpawn
		{
			Name "waveXXy"
			Where spawnbot
			// TotalCount 3
			MaxActive 13
			SpawnCount 3
			WaitBeforeStarting 0
			WaitBetweenSpawns 0
			TotalCurrency 120
			Support 1 // This will make the robots appear in Support. 1 makes them spawn infinitely and Limited makes only TotalCount spawn. Delete this line to make them normal bots
			TFBot
			{
				Class Scout
				Tag abc
			}
		}

	}
	Wave
	{
		// Add or replace existing InitWaveOutput with code below
		InitWaveOutput
		{
			Target bignet
			Action RunScriptCode
			Param "
				// The original InitWaveOutput trigger, change if necessary
				// EntFire(`wave_init_relay`, `Trigger`)

				// Load popextensions script
				IncludeScript(`popextensions_main`, getroottable())

				MissionAttrs({
					NoReanimators = 1
					ForceHoliday = 8
					EnableGlobalFixes = 1
					NoRome = 2
					BotHeadshots = 1
					NoCrumpkins = 1
					WaveStartCountdown = 3
					PlayersAreRobots = 1|8|16 //see missionattributes.nut for bitflag info
					ReverseMVM = 1|2|8|16|32|64  //see missionattributes.nut for bitflag info
					SpellRateCommon = 0.5
					NoSkeleSplit = 1
					WaveNum = 3
					MaxWaveNum = 60
					StandableHeads = 1
					MultiSapper = 1
					TeamWipeWaveLoss = 1
					GiantSentryKillCountOffset = -4
					RemoveBotViewmodels = 1
					UnusedGiantFootsteps = 1

					SoundOverrides = { //overrides teamplay_broadcast_audio sounds
						`Announcer.MVM_Get_To_Upgrade`: null
						`music.mvm_end_last_wave`: null
						`Game.YourTeamWon`: null
						`MVM.PlayerDied`: null
					}

					// AddCond = [32, 10] //speed boost for 10s

					PlayerAttributes = {

						`damage bonus`: 10,
						`can breathe under water`: 1,
						`mult swim speed`: 3,
						`teleport instead of die`: 1,
						`crit when health below`: 75,

						[TF_CLASS_SCOUT] = {
							`damage bonus` : 5,
							`fire rate penalty` : 2,
							`max health additive bonus` : 100,
						},

						[TF_CLASS_SOLDIER] = {
							`damage penalty` : 0.5,
							`fire rate bonus` : 0.5,
							`mult dmg vs same class`: 10
						},

						[TF_CLASS_DEMOMAN] = {
							`fire rate bonus` : 0.5,
						}
					},
					ItemAttributes = {
						tf_weapon_scattergun = {
							`max health additive bonus` : 100
							`fire rate bonus` : 0.5
							`Reload time decreased` : 0.5
							`clip size bonus` : 2
							`reloads full clip at once`: 1
							`passive reload`: 1
							`collect currency on kill`: 1
						},
						tf_weapon_flamethrower = {
							`paintkit_proto_def_index` : 214
							`set warpaint seed` : 1674041643762947354
						},
						tf_weapon_rocketlauncher =  { //string with no spaces (like item classnames) can use this syntax
							`projectile gravity`: 10
							`fire rate penalty` : 3
							`damage bonus` : 10
							`custom projectile model`: `models/player/heavy.mdl`
							`add cond when active`: 91
							// `self add cond on hit`: [91, 1]
						},
						tf_weapon_pistol = {
							`passive reload`: 1
						},
						tf_weapon_shotgun = {
							`reloads full clip at once`: 1
						},
						tf_weapon_crossbow = {
							`fires milk bolt`: 1
							`set turn to ice`: 1
							`radius sleeper`: 1
						},
						[132] = { //item id, eyelander
							`melee cleave attack`: 32
							`stun on hit`: { duration = 4 type = 2 speedmult = 0.2 stungiants = true }
						},
						tf_weapon_wrench = {
							// `mult teleporter recharge rate` : 2
							`build small sentries`: 1
						},
						`The Sydney Sleeper`: { //localized name in items_game.txt/item_map.nut
							`radius sleeper`: 1
							`explosive bullets ext`: {
								damage = 300
								radius = 100
								team = TF_TEAM_RED
							}
						},
						`The Sandman` : { //strings with spaces require this syntax.
							`old sandman stun`: 1
						},
						`Iron Curtain` : {
							`alt-fire disabled`: 1
						}
					}
				})
			"
		}
		StartWaveOutput
		{
			Target wave_start_relay
			Action Trigger
		}
		DoneOutput
		{
			Target wave_finished_relay
			Action trigger
		}
		WaveSpawn
		{

			Name "Wave4"
			Where spawnbot
			TotalCount 10
			MaxActive 5
			SpawnCount 5
			WaitBeforeStarting 1
			WaitBetweenSpawns 5
			TotalCurrency 5000
			TFBot
			{
				Template T_TFBot_Giant_Soldier
				Attributes HoldFireUntilFullReload //now works with every clip-based weapon
				Item "The Cow Mangler 5000"
				Tag "popext_homingprojectile{turn_power = 0.5, speed_mult = 2.0}"
				Tag "popext_reprogrammed"
				Tag "popext_spawnhere{where = `-779.491150 3302.379883 312.992340`, spawn_uber_duration = 3}" //custom spawn origin
				Tag "popext_customattr{attr = `wet immunity`, value = 1}"
				Tag "popext_customattr{attr = `custom projectile model`, value = `models/player/heavy.mdl`}"
				Tag "popext_weaponresist{weapon = ID_IRON_CURTAIN, amount = 20}" //20x damage from iron curtain
				// Tag "popext_mobber"
				Tag "popext_setskin{ skin = 0 }" //red skin
				Tag "popext_fireweapon{ button = IN_ATTACK2 }"
				Tag "popext_rocketcustomtrail{name = `eyeboss_projectile`}"
			}
		}
	}
}