Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq;
- using BallisticNG.Gamemodes;
- using BallisticNG.RaceUI;
- using Battlehub.Utils;
- using GameData;
- using GameData.Constants;
- using Settings;
- using UnityEngine;
- namespace BallisticNG.Gamemodes
- {
- public class GmRace : Gamemode
- {
- /*---Interfaces---*/
- private ScriptableMenu _pauseInterface;
- private ScriptableMenu _eliminatedInterface;
- private ScriptableMenu _eventCompleteInterface;
- private ScriptableHud[] _speedAndShieldHud;
- private ScriptableHud[] _notificationHud;
- private ScriptableHud[] _timeHud;
- private ScriptableHud[] _positionHud;
- private ScriptableHud[] _lapHud;
- private ScriptableHud[] _weaponHud;
- private ScriptableHud[] _nowPlayingHud;
- private ScriptableHud[] _awardHuds;
- /*---Splitscreen---*/
- private int _playerCount;
- private int _playerDeaths;
- public GmRace()
- {
- }
- public GmRace(Config config) : base(config)
- {
- }
- public override void OnAwake()
- {
- base.OnAwake();
- RaceManager.Instance.AutoLapSetup = true;
- Race.RacerCount = 1 + Race.AiCount;
- }
- public override void OnStart()
- {
- base.OnStart();
- if (Ships.LoadedShips.Count > 0) LoadTime(Ships.LoadedShips[0]);
- _playerCount = CalculatePlayerCount();
- }
- public override void OnUpdate()
- {
- base.OnUpdate();
- RaceManager.Instance.RacePositionManager.CalculateRacePositions();
- }
- public override void OnShipTriggerStartLine(ShipRefs r)
- {
- if (r.LapValidated || r.CurrentLap == 0)
- {
- r.LapValidated = false;
- /*---Racing Tasks---*/
- if (r.CurrentLap > 0 && r.CurrentLap <= Race.MaxLaps)
- {
- /*---Player Specific Tasks---*/
- if (r.IsPlayer)
- {
- // 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.FinishedEvent into RaceHelpers.FinishRace
- r.FinishedEvent = true;
- if (r.IsPlayer) IncrementExperience("Place", (int)Mathf.Lerp(0, 100, 1.0f - (float)(r.FinalPlace - 1) / (Ships.LoadedShips.Count - 1)));
- 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;
- }
- r.IsAi = true;
- SaveTime(r);
- }
- }
- /*---Reset Tasks---*/
- r.CurrentLapTime = 0.0f;
- r.IsPerfectLap = true;
- ++r.CurrentLap;
- r.PassedValidationGate = false;
- r.ClearHitPads();
- BallisticEvents.Race.CallOnShipLapUpdate(r);
- if (r.IsPlayer ) CalculateAndDisplayRelativeTime(r);
- }
- }
- 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);
- CalculateAndDisplayRelativeTime(r);
- r.PassedValidationGate = true;
- }
- }
- public override void OnShipExploded(ShipRefs r)
- {
- base.OnShipExploded(r);
- if (r.IsPlayer)
- {
- ++_playerDeaths;
- if (_playerDeaths == _playerCount) _eliminatedInterface.OpenDelayed(1.0f);
- }
- }
- public override void OnEventComplete()
- {
- base.OnEventComplete();
- Stats.IncrementStats(true, true);
- if (_eventCompleteInterface) _eventCompleteInterface.Open();
- }
- /// <summary>
- /// Loads all of the interfaces required.
- /// </summary>
- 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);
- _positionHud = CreateNewHuds(InterfaceLoader.Huds.Position);
- _lapHud = CreateNewHuds(InterfaceLoader.Huds.Lap);
- _weaponHud = CreateNewHuds(InterfaceLoader.Huds.Weapon);
- _nowPlayingHud = CreateNewHuds(InterfaceLoader.Huds.NowPlaying);
- if (Campaign.PlayingCampaign) _awardHuds = CreateNewHuds(InterfaceLoader.Huds.RaceAwards);
- }
- /// <summary>
- /// Destroys all of the interfaces being used.
- /// </summary>
- 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 (_positionHud != null) DestroyHuds(_positionHud);
- if (_lapHud != null) DestroyHuds(_lapHud);
- if (_weaponHud != null) DestroyHuds(_weaponHud);
- if (_nowPlayingHud != null) DestroyHuds(_nowPlayingHud);
- if (_awardHuds != null) DestroyHuds(_awardHuds);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement