Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using BallisticNG.RaceUI;
- using BallisticUnityTools.TrackTools;
- using BnG.AI;
- using GameData;
- using Settings;
- using UnityEngine;
- namespace BallisticNG.Gamemodes
- {
- public class EliminatorAi : CustomAiBehaviour
- {
- private float _currentWeaponTime;
- private float _weaponCyclingTime;
- public EliminatorAi(ShipRefs r) : base(r)
- {
- }
- public override void Init()
- {
- }
- public override void LogicUpdate()
- {
- BaseLogicUpdate();
- RubberBand();
- }
- public override void WeaponUpdate()
- {
- if (Race.HasCountdownFinished && _weaponCyclingTime < 5.0f) _weaponCyclingTime += Time.deltaTime;
- _currentWeaponTime += Time.deltaTime;
- if (_currentWeaponTime > 10.0f)
- {
- _currentWeaponTime = 0.0f;
- R.CurrentPickup?.OnDrop();
- }
- if (R.CurrentPickup == null && _weaponCyclingTime >= 5.0f && !R.Eliminated) R.CurrentPickup = PickupHelper.GetPickup(true, R);
- float timerIncrease = 0.0f;
- switch (Gameplay.AiLevel)
- {
- case EAiLevel.Novice:
- timerIncrease = 0.0f;
- break;
- case EAiLevel.Experienced:
- timerIncrease = 1.0f;
- break;
- case EAiLevel.Expert:
- timerIncrease = 1.5f;
- break;
- case EAiLevel.Elite:
- timerIncrease = 3.0f;
- break;
- case EAiLevel.Hardcore:
- timerIncrease = 8.0f;
- break;
- }
- R.Ai.itemPlaceTimer += Time.deltaTime * timerIncrease;
- BaseWeaponUpdate();
- }
- private void RubberBand()
- {
- R.PysSim.enginePower = 1.0f;
- }
- }
- public class GmEliminator : Gamemode
- {
- public class EliminatorMono : MonoBehaviour
- {
- public static EliminatorMono Instance;
- private void Awake()
- {
- Instance = this;
- }
- public List<ShipRefs> ShipsCombatSpinning = new List<ShipRefs>();
- public IEnumerator CombatSpin(ShipRefs r)
- {
- if (ShipsCombatSpinning.Contains(r)) yield break;
- ShipsCombatSpinning.Add(r);
- Quaternion currentRot = r.RBody.rotation;
- Quaternion targetRot = r.RBody.rotation * Quaternion.AngleAxis(180.0f, Vector3.up);
- for (float t = 0; t <= 1.0f; t += Time.deltaTime * 5.0f)
- {
- r.RBody.rotation = Quaternion.Lerp(currentRot, targetRot, t);
- yield return new WaitForFixedUpdate();
- }
- r.PysSim.engineAccel = 0.0f;
- r.PysSim.engineThrust = 0.0f;
- ShipsCombatSpinning.Remove(r);
- }
- }
- /*---Interfaces---*/
- private ScriptableMenu _pauseInterface;
- private ScriptableMenu _eliminatedInterface;
- private ScriptableMenu _eventCompleteInterface;
- private ScriptableHud[] _speedAndShieldHud;
- private ScriptableHud[] _eliminatorHud;
- private ScriptableHud[] _notificationHud;
- private ScriptableHud[] _weaponHud;
- private ScriptableHud[] _nowPlayingHud;
- private ScriptableHud[] _awardHud;
- public bool LastManStanding;
- public GmEliminator()
- {
- }
- public GmEliminator(Config config) : base(config)
- {
- }
- public override void OnAwake()
- {
- base.OnAwake();
- RaceManager.Instance.gameObject.AddComponent<EliminatorMono>();
- Race.Speedclass = ESpeedClass.Toxic;
- Race.MaxLaps = 100;
- Race.RacerCount = 1 + Race.AiCount;
- Race.BlockedWeapons = new List<E_WEAPONS>(new[] {E_WEAPONS.AUTOPILOT, E_WEAPONS.SHIELD, E_WEAPONS.EPACK, E_WEAPONS.TURBO, E_WEAPONS.ENERGYWALL});
- }
- public override void OnStart()
- {
- base.OnStart();
- for (int i = 0; i < Ships.LoadedShips.Count; ++i)
- {
- ShipRefs r = Ships.LoadedShips[i];
- r.CurrentLap = Race.MaxLaps;
- EliminatorAi behaviour = new EliminatorAi(r);
- r.Ai.CustomBehaviour = behaviour;
- }
- }
- public override void OnUpdate()
- {
- base.OnUpdate();
- if (Inputs.GetButtonDown(Inputs.ButtonAfterburner, 0) && EliminatorMono.Instance && Race.HasCountdownFinished
- && Ships.LoadedShips.Count > 0) EliminatorMono.Instance.StartCoroutine(EliminatorMono.Instance.CombatSpin(Ships.LoadedShips[0]));
- RaceManager.Instance.RacePositionManager.CalculateRacePositions();
- }
- public override void OnFixedUpdate()
- {
- base.OnFixedUpdate();
- if (LastManStanding)
- {
- for (int i = 0; i < Ships.LoadedShips.Count; ++i) Ships.LoadedShips[i].ShieldIntegrity -= Time.deltaTime * 0.5f;
- }
- }
- public override void OnShipDrop(ShipRefs r)
- {
- if (!LastManStanding) r.ShieldTimer = 1.0f;
- }
- public override void OnShipAbsorb(ShipRefs r, float shieldRestored)
- {
- r.ShieldIntegrity -= shieldRestored;
- }
- public override void OnShipHitWeaponTile(ShipRefs r, WeaponPad pad)
- {
- pad.disabledTimer = 0.0f;
- r.ClearHitPads();
- }
- public override void OnShipHitWeaponPad(ShipRefs r, TrackPad pad)
- {
- pad.DeactivationTimer = 0.0f;
- r.ClearHitPads();
- }
- public override void OnShipTriggerStartLine(ShipRefs r)
- {
- if (r.LapValidated)
- {
- if (!LastManStanding)
- {
- r.Effects.PlayAbsorbEffect();
- r.ShieldIntegrity += 8.0f;
- }
- r.LapValidated = false;
- }
- }
- public override void OnShipExploded(ShipRefs r)
- {
- base.OnShipExploded(r);
- if (r.IsPlayer) _eliminatedInterface.OpenDelayed(1.0f);
- if (Ships.LoadedShips.Count == 3)
- {
- BallisticEvents.Ui.CallOnTriggerMessage("Last Man Standing", Ships.LoadedShips[0], Color.green);
- BallisticEvents.Ui.CallOnTriggerMessage("Shields disabled", Ships.LoadedShips[0], Color.red);
- LastManStanding = true;
- Race.BlockedWeapons = new List<E_WEAPONS>(new[]
- {
- E_WEAPONS.AUTOPILOT, E_WEAPONS.CANNONS, E_WEAPONS.ENERGYWALL, E_WEAPONS.EPACK, E_WEAPONS.HELLSTORM, E_WEAPONS.HUNTER,
- E_WEAPONS.MINES, E_WEAPONS.QUAKE, E_WEAPONS.PLASMABOLT, E_WEAPONS.ROCKETS, E_WEAPONS.TRANSFERBEAM, E_WEAPONS.TURBO, E_WEAPONS.SHIELD
- });
- }
- if (Ships.LoadedShips.Count == 2 && Ships.LoadedShips[0].IsPlayer && r != Ships.LoadedShips[0])
- {
- r = Ships.LoadedShips[0];
- r.FinishedEvent = true;
- Object.Destroy(r.ShipCamera.GetComponent<ShipCamera>());
- ShipFCam fCam = r.ShipCamera.gameObject.AddComponent<ShipFCam>();
- fCam.r = r;
- r.IsAi = true;
- OnEventComplete();
- IncrementExperience("Last Alive", 500);
- }
- }
- 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);
- _eliminatorHud = CreateNewHuds(InterfaceLoader.Huds.Eliminator);
- _notificationHud = CreateNewHuds(InterfaceLoader.Huds.NotificationBuffer);
- _weaponHud = CreateNewHuds(InterfaceLoader.Huds.Weapon);
- _nowPlayingHud = CreateNewHuds(InterfaceLoader.Huds.NowPlaying);
- if (Campaign.PlayingCampaign) _awardHud = 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 (_eliminatorHud != null) DestroyHuds(_eliminatorHud);
- if (_notificationHud != null) DestroyHuds(_notificationHud);
- 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