Advertisement
Guest User

Pyramid of Et script

a guest
Nov 18th, 2022
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.45 KB | None | 0 0
  1. namespace Assets.Scripts.Levels.Enemies
  2. {
  3.     using System.Collections.Generic;
  4.     using Assets.Game.Weapons;
  5.     using Assets.Scripts.Levels;
  6.     using Assets.Scripts.Levels.Damage;
  7.     using Assets.Scripts.Parts.Targeting;
  8.     using UnityEngine;
  9.  
  10.     /// <summary>
  11.     /// Script for the pyramid to do unusual things for a pyramid.
  12.     /// </summary>
  13.     /// <seealso cref="UnityEngine.MonoBehaviour" />
  14.     public class PyramidScript : MonoBehaviour
  15.     {
  16.         /// <summary>
  17.         /// The climb height
  18.         /// </summary>
  19.         private float _climbHeight = 0f;
  20.  
  21.         /// <summary>
  22.         /// The engaged flag.
  23.         /// </summary>
  24.         private bool _engaged;
  25.  
  26.         /// <summary>
  27.         /// The timer to wait before engaging.
  28.         /// </summary>
  29.         private float _engageTimer = 10f;
  30.  
  31.         /// <summary>
  32.         /// The engines that are still alive.
  33.         /// </summary>
  34.         private List<PyramidEngine> _engines = new List<PyramidEngine>();
  35.  
  36.         /// <summary>
  37.         /// The speed
  38.         /// </summary>
  39.         private float _speed = 0;
  40.  
  41.         /// <summary>
  42.         /// The surprise
  43.         /// </summary>
  44.         [SerializeField]
  45.         private GameObject _surprise = null;
  46.  
  47.         /// <summary>
  48.         /// The trigger volume
  49.         /// </summary>
  50.         [SerializeField]
  51.         private PartVolumeScript _triggerVolume = null;
  52.  
  53.         /// <summary>
  54.         /// Engages the surprise.
  55.         /// </summary>
  56.         private void Engage()
  57.         {
  58.             var aircraft = LevelBase.CurrentLevel.PlayerControlledAircraft;
  59.  
  60.             var damageableBodies = this.GetComponentsInChildren<DamageableBody>(true);
  61.             foreach (var damageableBody in damageableBodies)
  62.             {
  63.                 var engine = new PyramidEngine(this, damageableBody);
  64.                 this._engines.Add(engine);
  65.                 aircraft.TargetingSystem.AddTarget(engine);
  66.             }
  67.  
  68.             this._engaged = true;
  69.             this._surprise.gameObject.SetActive(true);
  70.             LevelBase.CurrentLevel.GuiScript.ShowMessage("Something ancient has awoken...");
  71.         }
  72.  
  73.         /// <summary>
  74.         /// Called when an engine has died.
  75.         /// </summary>
  76.         /// <param name="engine">The engine.</param>
  77.         private void OnEngineDied(PyramidEngine engine)
  78.         {
  79.             this._engines.Remove(engine);
  80.             if (this._engines.Count == 0)
  81.             {
  82.                 LevelBase.CurrentLevel.GuiScript.ShowMessage("You have defeated...whatever that thing was.");
  83.             }
  84.         }
  85.  
  86.         /// <summary>
  87.         /// Update is called once per frame.
  88.         /// </summary>
  89.         private void Update()
  90.         {
  91.             if (this._engaged)
  92.             {
  93.                 if (this._climbHeight >= 0f)
  94.                 {
  95.                     int numEngines = this._engines.Count;
  96.                     if (numEngines > 0)
  97.                     {
  98.                         this._speed += numEngines * Time.deltaTime;
  99.                     }
  100.                     else
  101.                     {
  102.                         this._speed -= 9.8f * Time.deltaTime;
  103.                     }
  104.  
  105.                     var distance = this._speed * Time.deltaTime;
  106.                     this._climbHeight += distance;
  107.  
  108.                     this.transform.Translate(Vector3.up * distance);
  109.                     this.transform.Rotate(Vector3.up, this._speed * 0.1f * Time.deltaTime);
  110.                 }
  111.             }
  112.             else if (Game.Game.Instance.CurrentLevel.IsSandbox)
  113.             {
  114.                 if (this._triggerVolume.HasAnyParts())
  115.                 {
  116.                     this._engageTimer -= Time.deltaTime;
  117.                 }
  118.                 else if (this._engageTimer < 0f)
  119.                 {
  120.                     // All parts must leave the trigger before it can be engaged
  121.                     this.Engage();
  122.                 }
  123.             }
  124.         }
  125.  
  126.         /// <summary>
  127.         /// Pyramid engine.
  128.         /// </summary>
  129.         /// <seealso cref="Assets.Scripts.Parts.Targeting.Target" />
  130.         internal class PyramidEngine : Target
  131.         {
  132.             /// <summary>
  133.             /// The is dead flag.
  134.             /// </summary>
  135.             private bool _isDead;
  136.  
  137.             /// <summary>
  138.             /// Initializes a new instance of the <see cref="PyramidEngine" /> class.
  139.             /// </summary>
  140.             /// <param name="pyramid">The pyramid.</param>
  141.             /// <param name="damageableBody">The damageable body.</param>
  142.             public PyramidEngine(PyramidScript pyramid, DamageableBody damageableBody)
  143.             {
  144.                 this.DamageableBody = damageableBody;
  145.                 this.DamageableBody.DamageReceived += this.DamageableBody_DamageReceived;
  146.                 this.DamageableBody.DamageThresholdReached += this.DamageableBody_DamageThresholdReached;
  147.                 this.ParticleSystem = damageableBody.GetComponentInChildren<ParticleSystem>(true);
  148.                 this.Pyramid = pyramid;
  149.                 this.Name = "Alien Engine";
  150.             }
  151.  
  152.             /// <summary>
  153.             /// Gets the damageable body.
  154.             /// </summary>
  155.             /// <value>
  156.             /// The damageable body.
  157.             /// </value>
  158.             public DamageableBody DamageableBody { get; }
  159.  
  160.             /// <summary>
  161.             /// Gets a value indicating whether [is dead].
  162.             /// </summary>
  163.             /// <value>
  164.             ///   <c>true</c> if [is dead]; otherwise, <c>false</c>.
  165.             /// </value>
  166.             public override bool IsDead
  167.             {
  168.                 get
  169.                 {
  170.                     return this._isDead;
  171.                 }
  172.             }
  173.  
  174.             /// <summary>
  175.             /// Gets the particle system.
  176.             /// </summary>
  177.             /// <value>
  178.             /// The particle system.
  179.             /// </value>
  180.             public ParticleSystem ParticleSystem { get; }
  181.  
  182.             /// <summary>
  183.             /// Gets the position.
  184.             /// </summary>
  185.             /// <value>
  186.             /// The position.
  187.             /// </value>
  188.             public override Vector3 Position
  189.             {
  190.                 get
  191.                 {
  192.                     return this.DamageableBody.transform.position;
  193.                 }
  194.             }
  195.  
  196.             /// <summary>
  197.             /// Gets the pyramid.
  198.             /// </summary>
  199.             /// <value>
  200.             /// The pyramid.
  201.             /// </value>
  202.             public PyramidScript Pyramid { get; }
  203.  
  204.             /// <summary>
  205.             /// Gets a value indicating whether this target suppors occlusion.
  206.             /// </summary>
  207.             /// <value>
  208.             ///   <c>true</c> if this target suppors occlusion; otherwise, <c>false</c>.
  209.             /// </value>
  210.             public override bool SupportsOcclusion
  211.             {
  212.                 get
  213.                 {
  214.                     return false;
  215.                 }
  216.             }
  217.  
  218.             /// <summary>
  219.             /// Gets the type of the target.
  220.             /// </summary>
  221.             /// <value>
  222.             /// The type of the target.
  223.             /// </value>
  224.             public override TargetType TargetType
  225.             {
  226.                 get
  227.                 {
  228.                     return TargetType.Air;
  229.                 }
  230.             }
  231.  
  232.             /// <summary>
  233.             /// Gets the velocity.
  234.             /// </summary>
  235.             /// <value>
  236.             /// The velocity.
  237.             /// </value>
  238.             public override Vector3 Velocity
  239.             {
  240.                 get
  241.                 {
  242.                     return Vector3.zero;
  243.                 }
  244.             }
  245.  
  246.             /// <summary>
  247.             /// Alerts the target that it is being acquired and/or locked.
  248.             /// </summary>
  249.             /// <param name="locked">if set to <c>true</c> [locked].</param>
  250.             public override void Alert(bool locked)
  251.             {
  252.             }
  253.  
  254.             /// <summary>
  255.             /// Called as a warning when a threat (missile, guns, etc.) has been fired againts this entity.
  256.             /// </summary>
  257.             /// <param name="threat">The threat.</param>
  258.             public override void FireWarning(Rigidbody threat)
  259.             {
  260.             }
  261.  
  262.             /// <summary>
  263.             /// Handles the DamageReceived event of the DamageableBody control.
  264.             /// </summary>
  265.             /// <param name="sender">The source of the event.</param>
  266.             /// <param name="e">The <see cref="DamageEventArgs"/> instance containing the event data.</param>
  267.             private void DamageableBody_DamageReceived(object sender, DamageEventArgs e)
  268.             {
  269.             }
  270.  
  271.             /// <summary>
  272.             /// Handles the DamageThresholdReached event of the DamageableBody control.
  273.             /// </summary>
  274.             /// <param name="sender">The source of the event.</param>
  275.             /// <param name="e">The <see cref="DamageThresholdEventArgs"/> instance containing the event data.</param>
  276.             private void DamageableBody_DamageThresholdReached(object sender, DamageThresholdEventArgs e)
  277.             {
  278.                 var emission = this.ParticleSystem.emission;
  279.                 //emission.enabled = false;
  280.                 emission.rateOverTime = 0;
  281.  
  282.                 this._isDead = true;
  283.                 this.Pyramid.OnEngineDied(this);
  284.             }
  285.         }
  286.     }
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement