Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq;
- using BallisticNG.RaceUI;
- using GameData;
- using GameData.Constants;
- using Settings;
- using UnityEngine;
- namespace BallisticNG.Gamemodes
- {
- public class GmTimeTrial : Gamemode
- {
- /*---Interfaces---*/
- private ScriptableMenu _pauseInterface;
- private ScriptableMenu _eliminatedInterface;
- private ScriptableMenu _eventCompleteInterface;
- private ScriptableHud[] _speedAndShieldHud;
- private ScriptableHud[] _notificationHud;
- private ScriptableHud[] _timeHud;
- private ScriptableHud[] _lapHud;
- private ScriptableHud[] _weaponHud;
- private ScriptableHud[] _nowPlayingHud;
- private ScriptableHud[] _awardHud;
- private GhostManager _ghostManager;
- public GmTimeTrial()
- {
- }
- public GmTimeTrial(Config config) : base(config)
- {
- }
- public override void OnAwake()
- {
- base.OnAwake();
- RaceManager.Instance.AutoLapSetup = true;
- Race.RacerCount = 1;
- }
- public override void OnStart()
- {
- base.OnStart();
- if (Ships.LoadedShips.Count > 0) LoadTime(Ships.LoadedShips[0]);
- GameObject go = new GameObject("< Ghost Manager >");
- _ghostManager = go.AddComponent<GhostManager>();
- _ghostManager.Init(Ships.LoadedShips[0], false);
- }
- public override void OnShipTriggerMidLine(ShipRefs r)
- {
- base.OnShipTriggerMidLine(r);
- // checkpoint
- if (r.IsPlayer && !r.PassedValidationGate)
- {
- AudioHelpers.PlayOneShot(AudioHelpers.UI_Checkpoint, AudioHelpers.E_AUDIOCHANNEL.INTERFACE, 1.0f, 1.0f);
- r.PassedValidationGate = true;
- }
- }
- public override void OnShipTriggerStartLine(ShipRefs r)
- {
- if (r.LapValidated || r.CurrentLap == 0)
- {
- if (r.CurrentLap == 0)
- {
- _ghostManager.StartGhostRecord();
- _ghostManager.PlayLoadedGhost();
- }
- // give turbo
- //r.CurrentPickup = PickupHelper.GivePickup(r, E_WEAPONS.TURBO);
- r.LapValidated = false;
- /*---Racing Tasks---*/
- if (r.CurrentLap > 0 && r.CurrentLap <= Race.MaxLaps)
- {
- // steam lap stats
- if (Steam.Enabled)
- {
- SteamAchieves.IncrementStat(E_STATS.stat_laps);
- if (r.IsPerfectLap) SteamAchieves.IncrementStat(E_STATS.st_perfectlaps);
- }
- // update best time
- if ((r.CurrentLapTime < r.BestLapTime || !r.HasBestLapTime) && !r.LoadedBestLapTime)
- {
- r.BestLapTime = r.CurrentLapTime;
- r.HasBestLapTime = true;
- }
- // notify of perfect lap
- if (r.IsPerfectLap)
- {
- IncrementExperience("Perfect Lap", Experience.PerfectLap);
- BallisticEvents.Ui.CallOnTriggerMessage("PERFECT LAP", r, ScriptableHud.BnGAccent);
- AudioHelpers.PlayVoice(AudioHelpers.Voice_PerfectLap);
- }
- // interface sounds
- if (r.CurrentLap == Race.MaxLaps - 1)
- {
- BallisticEvents.Ui.CallOnTriggerMessage("FINAL LAP", r, ScriptableHud.BnGAccent);
- AudioHelpers.PlayVoice(AudioHelpers.Voice_FinalLap);
- }
- AudioHelpers.PlayOneShot(AudioHelpers.UI_Checkpoint, AudioHelpers.E_AUDIOCHANNEL.INTERFACE, 1.0f, 1.0f);
- /*---All Ship Tasks---*/
- // set lap values
- r.LapTimes[r.CurrentLap - 1] = r.CurrentLapTime;
- r.PerfectLaps[r.CurrentLap - 1] = r.IsPerfectLap;
- }
- /*---Finished Task---*/
- if (r.CurrentLap >= Race.MaxLaps && !r.FinishedEvent && !r.Eliminated)
- {
- // todo: move r.finished into RaceHelpers.FinishRace
- r.FinishedEvent = true;
- RaceHelpers.FinishRace(r);
- // attach finished camera to ship | todo: make this part of the race finished callback
- if (r.IsPlayer)
- {
- if (!Gameplay.SplitscreenEnabled)
- {
- Object.Destroy(r.ShipCamera.GetComponent<ShipCamera>());
- ShipFCam fCam = r.ShipCamera.gameObject.AddComponent<ShipFCam>();
- fCam.r = r;
- // ghost save
- bool beatBest = (!r.LoadedBestLapTime || r.TotalRaceTime < r.TargetTime) && !Cheats.Enabled;
- _ghostManager.StopGhostRecord(beatBest, false);
- SaveTime(r);
- }
- r.IsAi = true;
- }
- }
- /*---Reset Tasks---*/
- r.CurrentLapTime = 0.0f;
- r.IsPerfectLap = true;
- ++r.CurrentLap;
- r.PassedValidationGate = false;
- r.ClearHitPads();
- BallisticEvents.Race.CallOnShipLapUpdate(r);
- }
- }
- public override void OnShipExploded(ShipRefs r)
- {
- base.OnShipExploded(r);
- if (r.IsPlayer) _eliminatedInterface.OpenDelayed(1.0f);
- }
- public override void OnEventComplete()
- {
- base.OnEventComplete();
- Stats.IncrementStats(false, true);
- if (_eventCompleteInterface) _eventCompleteInterface.Open();
- }
- public override void LoadInterfaces()
- {
- /*---Menus---*/
- _pauseInterface = InterfaceLoader.LoadMenu(InterfaceLoader.Menus.EventPause, false);
- _eliminatedInterface = InterfaceLoader.LoadMenu(InterfaceLoader.Menus.Eliminated, false);
- _eventCompleteInterface = InterfaceLoader.LoadMenu(Campaign.PlayingCampaign ? InterfaceLoader.Menus.EventCompleteStandardCampaign : InterfaceLoader.Menus.EventCompleteStandard, false);
- /*---HUDs---*/
- _speedAndShieldHud = CreateNewHuds(InterfaceLoader.Huds.SpeedAndShield);
- _notificationHud = CreateNewHuds(InterfaceLoader.Huds.NotificationBuffer);
- _timeHud = CreateNewHuds(InterfaceLoader.Huds.TimeStandard);
- _lapHud = CreateNewHuds(InterfaceLoader.Huds.Lap);
- _weaponHud = CreateNewHuds(InterfaceLoader.Huds.Weapon);
- _nowPlayingHud = CreateNewHuds(InterfaceLoader.Huds.NowPlaying);
- if (Campaign.PlayingCampaign) CreateNewHuds(InterfaceLoader.Huds.TimetrialAwards);
- }
- public override void DestroyInterfaces()
- {
- /*---Menus---*/
- if (_pauseInterface) Object.Destroy(_pauseInterface.gameObject);
- if (_eliminatedInterface) Object.Destroy(_eliminatedInterface.gameObject);
- if (_eventCompleteInterface) Object.Destroy(_eventCompleteInterface.gameObject);
- /*---HUDs---*/
- if (_speedAndShieldHud != null) DestroyHuds(_speedAndShieldHud);
- if (_notificationHud != null) DestroyHuds(_notificationHud);
- if (_timeHud != null) DestroyHuds(_timeHud);
- if (_lapHud != null) DestroyHuds(_lapHud);
- if (_weaponHud != null) DestroyHuds(_weaponHud);
- if (_nowPlayingHud != null) DestroyHuds(_nowPlayingHud);
- if (_awardHud != null) DestroyHuds(_awardHud);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement