Advertisement
Guest User

BallisticNG - Eliminator Gamemode

a guest
Aug 15th, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using BallisticNG.RaceUI;
  4. using BallisticUnityTools.TrackTools;
  5. using BnG.AI;
  6. using GameData;
  7. using Settings;
  8. using UnityEngine;
  9.  
  10. namespace BallisticNG.Gamemodes
  11. {
  12.     public class EliminatorAi : CustomAiBehaviour
  13.     {
  14.         private float _currentWeaponTime;
  15.         private float _weaponCyclingTime;
  16.         public EliminatorAi(ShipRefs r) : base(r)
  17.         {
  18.  
  19.         }
  20.  
  21.         public override void Init()
  22.         {
  23.  
  24.         }
  25.  
  26.         public override void LogicUpdate()
  27.         {
  28.             BaseLogicUpdate();
  29.             RubberBand();
  30.         }
  31.  
  32.         public override void WeaponUpdate()
  33.         {
  34.             if (Race.HasCountdownFinished && _weaponCyclingTime < 5.0f) _weaponCyclingTime += Time.deltaTime;
  35.             _currentWeaponTime += Time.deltaTime;
  36.             if (_currentWeaponTime > 10.0f)
  37.             {
  38.                 _currentWeaponTime = 0.0f;
  39.                 R.CurrentPickup?.OnDrop();
  40.             }
  41.             if (R.CurrentPickup == null && _weaponCyclingTime >= 5.0f && !R.Eliminated) R.CurrentPickup = PickupHelper.GetPickup(true, R);
  42.  
  43.             float timerIncrease = 0.0f;
  44.             switch (Gameplay.AiLevel)
  45.             {
  46.                 case EAiLevel.Novice:
  47.                     timerIncrease = 0.0f;
  48.                     break;
  49.                 case EAiLevel.Experienced:
  50.                     timerIncrease = 1.0f;
  51.                     break;
  52.                 case EAiLevel.Expert:
  53.                     timerIncrease = 1.5f;
  54.                     break;
  55.                 case EAiLevel.Elite:
  56.                     timerIncrease = 3.0f;
  57.                     break;
  58.                 case EAiLevel.Hardcore:
  59.                     timerIncrease = 8.0f;
  60.                     break;
  61.             }
  62.             R.Ai.itemPlaceTimer += Time.deltaTime * timerIncrease;
  63.             BaseWeaponUpdate();
  64.         }
  65.  
  66.         private void RubberBand()
  67.         {
  68.             R.PysSim.enginePower = 1.0f;
  69.         }
  70.     }
  71.  
  72.     public class GmEliminator : Gamemode
  73.     {
  74.         public class EliminatorMono : MonoBehaviour
  75.         {
  76.             public static EliminatorMono Instance;
  77.  
  78.             private void Awake()
  79.             {
  80.                 Instance = this;
  81.             }
  82.  
  83.             public List<ShipRefs> ShipsCombatSpinning = new List<ShipRefs>();
  84.  
  85.             public IEnumerator CombatSpin(ShipRefs r)
  86.             {
  87.                 if (ShipsCombatSpinning.Contains(r)) yield break;
  88.  
  89.                 ShipsCombatSpinning.Add(r);
  90.                 Quaternion currentRot = r.RBody.rotation;
  91.                 Quaternion targetRot = r.RBody.rotation * Quaternion.AngleAxis(180.0f, Vector3.up);
  92.  
  93.                 for (float t = 0; t <= 1.0f; t += Time.deltaTime * 5.0f)
  94.                 {
  95.                     r.RBody.rotation = Quaternion.Lerp(currentRot, targetRot, t);
  96.                     yield return new WaitForFixedUpdate();
  97.                 }
  98.  
  99.                 r.PysSim.engineAccel = 0.0f;
  100.                 r.PysSim.engineThrust = 0.0f;
  101.                 ShipsCombatSpinning.Remove(r);
  102.             }
  103.         }
  104.  
  105.         /*---Interfaces---*/
  106.         private ScriptableMenu _pauseInterface;
  107.         private ScriptableMenu _eliminatedInterface;
  108.         private ScriptableMenu _eventCompleteInterface;
  109.  
  110.         private ScriptableHud[] _speedAndShieldHud;
  111.         private ScriptableHud[] _eliminatorHud;
  112.         private ScriptableHud[] _notificationHud;
  113.         private ScriptableHud[] _weaponHud;
  114.         private ScriptableHud[] _nowPlayingHud;
  115.         private ScriptableHud[] _awardHud;
  116.  
  117.         public bool LastManStanding;
  118.  
  119.         public GmEliminator()
  120.         {
  121.            
  122.         }
  123.  
  124.         public GmEliminator(Config config) : base(config)
  125.         {
  126.  
  127.         }
  128.  
  129.         public override void OnAwake()
  130.         {
  131.             base.OnAwake();
  132.  
  133.             RaceManager.Instance.gameObject.AddComponent<EliminatorMono>();
  134.             Race.Speedclass = ESpeedClass.Toxic;
  135.             Race.MaxLaps = 100;
  136.             Race.RacerCount = 1 + Race.AiCount;
  137.  
  138.             Race.BlockedWeapons = new List<E_WEAPONS>(new[] {E_WEAPONS.AUTOPILOT, E_WEAPONS.SHIELD, E_WEAPONS.EPACK, E_WEAPONS.TURBO, E_WEAPONS.ENERGYWALL});
  139.         }
  140.  
  141.         public override void OnStart()
  142.         {
  143.             base.OnStart();
  144.  
  145.             for (int i = 0; i < Ships.LoadedShips.Count; ++i)
  146.             {
  147.                 ShipRefs r = Ships.LoadedShips[i];
  148.                 r.CurrentLap = Race.MaxLaps;
  149.                 EliminatorAi behaviour = new EliminatorAi(r);
  150.                 r.Ai.CustomBehaviour = behaviour;
  151.             }
  152.         }
  153.  
  154.         public override void OnUpdate()
  155.         {
  156.             base.OnUpdate();
  157.  
  158.             if (Inputs.GetButtonDown(Inputs.ButtonAfterburner, 0) && EliminatorMono.Instance && Race.HasCountdownFinished
  159.                 && Ships.LoadedShips.Count > 0) EliminatorMono.Instance.StartCoroutine(EliminatorMono.Instance.CombatSpin(Ships.LoadedShips[0]));
  160.  
  161.             RaceManager.Instance.RacePositionManager.CalculateRacePositions();
  162.         }
  163.  
  164.         public override void OnFixedUpdate()
  165.         {
  166.             base.OnFixedUpdate();
  167.             if (LastManStanding)
  168.             {
  169.                 for (int i = 0; i < Ships.LoadedShips.Count; ++i) Ships.LoadedShips[i].ShieldIntegrity -= Time.deltaTime * 0.5f;
  170.             }
  171.         }
  172.  
  173.         public override void OnShipDrop(ShipRefs r)
  174.         {
  175.             if (!LastManStanding) r.ShieldTimer = 1.0f;
  176.         }
  177.  
  178.         public override void OnShipAbsorb(ShipRefs r, float shieldRestored)
  179.         {
  180.             r.ShieldIntegrity -= shieldRestored;
  181.         }
  182.  
  183.         public override void OnShipHitWeaponTile(ShipRefs r, WeaponPad pad)
  184.         {
  185.             pad.disabledTimer = 0.0f;
  186.             r.ClearHitPads();
  187.         }
  188.  
  189.         public override void OnShipHitWeaponPad(ShipRefs r, TrackPad pad)
  190.         {
  191.             pad.DeactivationTimer = 0.0f;
  192.             r.ClearHitPads();
  193.         }
  194.  
  195.         public override void OnShipTriggerStartLine(ShipRefs r)
  196.         {
  197.             if (r.LapValidated)
  198.             {
  199.                 if (!LastManStanding)
  200.                 {
  201.                     r.Effects.PlayAbsorbEffect();
  202.                     r.ShieldIntegrity += 8.0f;
  203.                 }
  204.                 r.LapValidated = false;
  205.             }
  206.         }
  207.  
  208.         public override void OnShipExploded(ShipRefs r)
  209.         {
  210.             base.OnShipExploded(r);
  211.             if (r.IsPlayer) _eliminatedInterface.OpenDelayed(1.0f);
  212.  
  213.             if (Ships.LoadedShips.Count == 3)
  214.             {
  215.                 BallisticEvents.Ui.CallOnTriggerMessage("Last Man Standing", Ships.LoadedShips[0], Color.green);
  216.                 BallisticEvents.Ui.CallOnTriggerMessage("Shields disabled", Ships.LoadedShips[0], Color.red);
  217.                 LastManStanding = true;
  218.  
  219.                 Race.BlockedWeapons = new List<E_WEAPONS>(new[]
  220.                 {
  221.                     E_WEAPONS.AUTOPILOT, E_WEAPONS.CANNONS, E_WEAPONS.ENERGYWALL, E_WEAPONS.EPACK, E_WEAPONS.HELLSTORM, E_WEAPONS.HUNTER,
  222.                     E_WEAPONS.MINES, E_WEAPONS.QUAKE, E_WEAPONS.PLASMABOLT, E_WEAPONS.ROCKETS, E_WEAPONS.TRANSFERBEAM, E_WEAPONS.TURBO, E_WEAPONS.SHIELD
  223.                 });
  224.             }
  225.  
  226.             if (Ships.LoadedShips.Count == 2 && Ships.LoadedShips[0].IsPlayer && r != Ships.LoadedShips[0])
  227.             {
  228.                 r = Ships.LoadedShips[0];
  229.                 r.FinishedEvent = true;
  230.  
  231.                 Object.Destroy(r.ShipCamera.GetComponent<ShipCamera>());
  232.                 ShipFCam fCam = r.ShipCamera.gameObject.AddComponent<ShipFCam>();
  233.                 fCam.r = r;
  234.                 r.IsAi = true;
  235.  
  236.                 OnEventComplete();
  237.                 IncrementExperience("Last Alive", 500);
  238.             }
  239.         }
  240.  
  241.         public override void OnEventComplete()
  242.         {
  243.             base.OnEventComplete();
  244.             Stats.IncrementStats(true, true);
  245.             if (_eventCompleteInterface) _eventCompleteInterface.Open();
  246.  
  247.         }
  248.  
  249.         /// <summary>
  250.         /// Loads all of the interfaces required.
  251.         /// </summary>
  252.         public override void LoadInterfaces()
  253.         {
  254.             /*---Menus---*/
  255.             _pauseInterface = InterfaceLoader.LoadMenu(InterfaceLoader.Menus.EventPause, false);
  256.             _eliminatedInterface = InterfaceLoader.LoadMenu(InterfaceLoader.Menus.Eliminated, false);
  257.             _eventCompleteInterface = InterfaceLoader.LoadMenu(Campaign.PlayingCampaign ? InterfaceLoader.Menus.EventCompleteStandardCampaign : InterfaceLoader.Menus.EventCompleteStandard, false);
  258.  
  259.             /*---HUDs---*/
  260.             _speedAndShieldHud = CreateNewHuds(InterfaceLoader.Huds.SpeedAndShield);
  261.             _eliminatorHud = CreateNewHuds(InterfaceLoader.Huds.Eliminator);
  262.             _notificationHud = CreateNewHuds(InterfaceLoader.Huds.NotificationBuffer);
  263.             _weaponHud = CreateNewHuds(InterfaceLoader.Huds.Weapon);
  264.             _nowPlayingHud = CreateNewHuds(InterfaceLoader.Huds.NowPlaying);
  265.             if (Campaign.PlayingCampaign) _awardHud = CreateNewHuds(InterfaceLoader.Huds.RaceAwards);
  266.         }
  267.  
  268.         /// <summary>
  269.         /// Destroys all of the interfaces being used.
  270.         /// </summary>
  271.         public override void DestroyInterfaces()
  272.         {
  273.             /*---Menus---*/
  274.             if (_pauseInterface) Object.Destroy(_pauseInterface.gameObject);
  275.             if (_eliminatedInterface) Object.Destroy(_eliminatedInterface.gameObject);
  276.             if (_eventCompleteInterface) Object.Destroy(_eventCompleteInterface.gameObject);
  277.  
  278.             /*---HUDs---*/
  279.             if (_speedAndShieldHud != null) DestroyHuds(_speedAndShieldHud);
  280.             if (_eliminatorHud != null) DestroyHuds(_eliminatorHud);
  281.             if (_notificationHud != null) DestroyHuds(_notificationHud);
  282.             if (_weaponHud != null) DestroyHuds(_weaponHud);
  283.             if (_nowPlayingHud != null) DestroyHuds(_nowPlayingHud);
  284.             if (_awardHud != null) DestroyHuds(_awardHud);
  285.         }
  286.     }
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement