Advertisement
Guest User

BallisticNG - Time Trial Gamemode

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