Advertisement
Guest User

BallisticNG - Race Gamemode

a guest
Aug 15th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.56 KB | None | 0 0
  1. using System.Linq;
  2. using BallisticNG.Gamemodes;
  3. using BallisticNG.RaceUI;
  4. using Battlehub.Utils;
  5. using GameData;
  6. using GameData.Constants;
  7. using Settings;
  8. using UnityEngine;
  9.  
  10. namespace BallisticNG.Gamemodes
  11. {
  12.     public class GmRace : Gamemode
  13.     {
  14.         /*---Interfaces---*/
  15.         private ScriptableMenu _pauseInterface;
  16.         private ScriptableMenu _eliminatedInterface;
  17.         private ScriptableMenu _eventCompleteInterface;
  18.  
  19.         private ScriptableHud[] _speedAndShieldHud;
  20.         private ScriptableHud[] _notificationHud;
  21.         private ScriptableHud[] _timeHud;
  22.         private ScriptableHud[] _positionHud;
  23.         private ScriptableHud[] _lapHud;
  24.         private ScriptableHud[] _weaponHud;
  25.         private ScriptableHud[] _nowPlayingHud;
  26.         private ScriptableHud[] _awardHuds;
  27.  
  28.         /*---Splitscreen---*/
  29.         private int _playerCount;
  30.         private int _playerDeaths;
  31.  
  32.         public GmRace()
  33.         {
  34.            
  35.         }
  36.  
  37.         public GmRace(Config config) : base(config)
  38.         {
  39.  
  40.         }
  41.  
  42.         public override void OnAwake()
  43.         {
  44.             base.OnAwake();
  45.  
  46.             RaceManager.Instance.AutoLapSetup = true;
  47.             Race.RacerCount = 1 + Race.AiCount;
  48.         }
  49.  
  50.         public override void OnStart()
  51.         {
  52.             base.OnStart();
  53.             if (Ships.LoadedShips.Count > 0) LoadTime(Ships.LoadedShips[0]);
  54.             _playerCount = CalculatePlayerCount();
  55.         }
  56.  
  57.         public override void OnUpdate()
  58.         {
  59.             base.OnUpdate();
  60.  
  61.             RaceManager.Instance.RacePositionManager.CalculateRacePositions();
  62.         }
  63.  
  64.         public override void OnShipTriggerStartLine(ShipRefs r)
  65.         {
  66.             if (r.LapValidated || r.CurrentLap == 0)
  67.             {
  68.                 r.LapValidated = false;
  69.  
  70.                 /*---Racing Tasks---*/
  71.                 if (r.CurrentLap > 0 && r.CurrentLap <= Race.MaxLaps)
  72.                 {
  73.                     /*---Player Specific Tasks---*/
  74.                     if (r.IsPlayer)
  75.                     {
  76.                         // steam lap stats
  77.                         if (Steam.Enabled)
  78.                         {
  79.                             SteamAchieves.IncrementStat(E_STATS.stat_laps);
  80.                             if (r.IsPerfectLap) SteamAchieves.IncrementStat(E_STATS.st_perfectlaps);
  81.                         }
  82.  
  83.                         // update best time
  84.                         if ((r.CurrentLapTime < r.BestLapTime || !r.HasBestLapTime) && !r.LoadedBestLapTime)
  85.                         {
  86.                             r.BestLapTime = r.CurrentLapTime;
  87.                             r.HasBestLapTime = true;
  88.                         }
  89.  
  90.                         // notify of perfect lap
  91.                         if (r.IsPerfectLap)
  92.                         {
  93.                             IncrementExperience("Perfect Lap", Experience.PerfectLap);
  94.                             BallisticEvents.Ui.CallOnTriggerMessage("PERFECT LAP", r, ScriptableHud.BnGAccent);
  95.                             AudioHelpers.PlayVoice(AudioHelpers.Voice_PerfectLap);
  96.                         }
  97.  
  98.                         // interface sounds
  99.                         if (r.CurrentLap == Race.MaxLaps - 1)
  100.                         {
  101.                             BallisticEvents.Ui.CallOnTriggerMessage("FINAL LAP", r, ScriptableHud.BnGAccent);
  102.                             AudioHelpers.PlayVoice(AudioHelpers.Voice_FinalLap);
  103.                         }
  104.                         AudioHelpers.PlayOneShot(AudioHelpers.UI_Checkpoint, AudioHelpers.E_AUDIOCHANNEL.INTERFACE, 1.0f, 1.0f);
  105.                     }
  106.  
  107.                     /*---All Ship Tasks---*/
  108.                     // set lap values
  109.                     r.LapTimes[r.CurrentLap - 1] = r.CurrentLapTime;
  110.                     r.PerfectLaps[r.CurrentLap - 1] = r.IsPerfectLap;
  111.                 }
  112.  
  113.                 /*---Finished Task---*/
  114.                 if (r.CurrentLap >= Race.MaxLaps && !r.FinishedEvent && !r.Eliminated)
  115.                 {
  116.                     // todo: move r.FinishedEvent into RaceHelpers.FinishRace
  117.                     r.FinishedEvent = true;
  118.                     if (r.IsPlayer) IncrementExperience("Place", (int)Mathf.Lerp(0, 100, 1.0f - (float)(r.FinalPlace - 1) / (Ships.LoadedShips.Count - 1)));
  119.                     RaceHelpers.FinishRace(r);
  120.  
  121.                     // attach finished camera to ship | todo: make this part of the race finished callback
  122.                     if (r.IsPlayer)
  123.                     {
  124.                         if (!Gameplay.SplitscreenEnabled)
  125.                         {
  126.                             Object.Destroy(r.ShipCamera.GetComponent<ShipCamera>());
  127.  
  128.                             ShipFCam fCam = r.ShipCamera.gameObject.AddComponent<ShipFCam>();
  129.                             fCam.r = r;
  130.                         }
  131.                         r.IsAi = true;
  132.  
  133.                         SaveTime(r);
  134.                     }
  135.                 }
  136.  
  137.                 /*---Reset Tasks---*/
  138.                 r.CurrentLapTime = 0.0f;
  139.                 r.IsPerfectLap = true;
  140.                 ++r.CurrentLap;
  141.                 r.PassedValidationGate = false;
  142.                 r.ClearHitPads();
  143.                 BallisticEvents.Race.CallOnShipLapUpdate(r);
  144.  
  145.                 if (r.IsPlayer ) CalculateAndDisplayRelativeTime(r);
  146.             }
  147.         }
  148.  
  149.         public override void OnShipTriggerMidLine(ShipRefs r)
  150.         {
  151.             base.OnShipTriggerMidLine(r);
  152.  
  153.             // checkpoint
  154.             if (r.IsPlayer && !r.PassedValidationGate)
  155.             {
  156.                 AudioHelpers.PlayOneShot(AudioHelpers.UI_Checkpoint, AudioHelpers.E_AUDIOCHANNEL.INTERFACE, 1.0f, 1.0f);
  157.                 CalculateAndDisplayRelativeTime(r);
  158.  
  159.                 r.PassedValidationGate = true;
  160.             }
  161.         }
  162.  
  163.         public override void OnShipExploded(ShipRefs r)
  164.         {
  165.             base.OnShipExploded(r);
  166.             if (r.IsPlayer)
  167.             {
  168.                 ++_playerDeaths;
  169.                 if (_playerDeaths == _playerCount) _eliminatedInterface.OpenDelayed(1.0f);
  170.             }
  171.         }
  172.  
  173.         public override void OnEventComplete()
  174.         {
  175.             base.OnEventComplete();
  176.             Stats.IncrementStats(true, true);
  177.             if (_eventCompleteInterface) _eventCompleteInterface.Open();
  178.         }
  179.  
  180.         /// <summary>
  181.         /// Loads all of the interfaces required.
  182.         /// </summary>
  183.         public override void LoadInterfaces()
  184.         {
  185.             /*---Menus---*/
  186.             _pauseInterface = InterfaceLoader.LoadMenu(InterfaceLoader.Menus.EventPause, false);
  187.             _eliminatedInterface = InterfaceLoader.LoadMenu(InterfaceLoader.Menus.Eliminated, false);
  188.             _eventCompleteInterface = InterfaceLoader.LoadMenu(Campaign.PlayingCampaign ? InterfaceLoader.Menus.EventCompleteStandardCampaign : InterfaceLoader.Menus.EventCompleteStandard, false);
  189.  
  190.             /*---HUDs---*/
  191.             _speedAndShieldHud = CreateNewHuds(InterfaceLoader.Huds.SpeedAndShield);
  192.             _notificationHud = CreateNewHuds(InterfaceLoader.Huds.NotificationBuffer);
  193.             _timeHud = CreateNewHuds(InterfaceLoader.Huds.TimeStandard);
  194.             _positionHud = CreateNewHuds(InterfaceLoader.Huds.Position);
  195.             _lapHud = CreateNewHuds(InterfaceLoader.Huds.Lap);
  196.             _weaponHud = CreateNewHuds(InterfaceLoader.Huds.Weapon);
  197.             _nowPlayingHud = CreateNewHuds(InterfaceLoader.Huds.NowPlaying);
  198.             if (Campaign.PlayingCampaign) _awardHuds = CreateNewHuds(InterfaceLoader.Huds.RaceAwards);
  199.         }
  200.  
  201.         /// <summary>
  202.         /// Destroys all of the interfaces being used.
  203.         /// </summary>
  204.         public override void DestroyInterfaces()
  205.         {
  206.             /*---Menus---*/
  207.             if (_pauseInterface) Object.Destroy(_pauseInterface.gameObject);
  208.             if (_eliminatedInterface) Object.Destroy(_eliminatedInterface.gameObject);
  209.             if (_eventCompleteInterface) Object.Destroy(_eventCompleteInterface.gameObject);
  210.  
  211.             /*---HUDs---*/
  212.             if (_speedAndShieldHud != null) DestroyHuds(_speedAndShieldHud);
  213.             if (_notificationHud != null) DestroyHuds(_notificationHud);
  214.             if (_timeHud != null) DestroyHuds(_timeHud);
  215.             if (_positionHud != null) DestroyHuds(_positionHud);
  216.             if (_lapHud != null) DestroyHuds(_lapHud);
  217.             if (_weaponHud != null) DestroyHuds(_weaponHud);
  218.             if (_nowPlayingHud != null) DestroyHuds(_nowPlayingHud);
  219.             if (_awardHuds != null) DestroyHuds(_awardHuds);
  220.         }
  221.     }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement