Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Assets.Scripts.Levels.Enemies
- {
- using System.Collections.Generic;
- using Assets.Game.Weapons;
- using Assets.Scripts.Levels;
- using Assets.Scripts.Levels.Damage;
- using Assets.Scripts.Parts.Targeting;
- using UnityEngine;
- /// <summary>
- /// Script for the pyramid to do unusual things for a pyramid.
- /// </summary>
- /// <seealso cref="UnityEngine.MonoBehaviour" />
- public class PyramidScript : MonoBehaviour
- {
- /// <summary>
- /// The climb height
- /// </summary>
- private float _climbHeight = 0f;
- /// <summary>
- /// The engaged flag.
- /// </summary>
- private bool _engaged;
- /// <summary>
- /// The timer to wait before engaging.
- /// </summary>
- private float _engageTimer = 10f;
- /// <summary>
- /// The engines that are still alive.
- /// </summary>
- private List<PyramidEngine> _engines = new List<PyramidEngine>();
- /// <summary>
- /// The speed
- /// </summary>
- private float _speed = 0;
- /// <summary>
- /// The surprise
- /// </summary>
- [SerializeField]
- private GameObject _surprise = null;
- /// <summary>
- /// The trigger volume
- /// </summary>
- [SerializeField]
- private PartVolumeScript _triggerVolume = null;
- /// <summary>
- /// Engages the surprise.
- /// </summary>
- private void Engage()
- {
- var aircraft = LevelBase.CurrentLevel.PlayerControlledAircraft;
- var damageableBodies = this.GetComponentsInChildren<DamageableBody>(true);
- foreach (var damageableBody in damageableBodies)
- {
- var engine = new PyramidEngine(this, damageableBody);
- this._engines.Add(engine);
- aircraft.TargetingSystem.AddTarget(engine);
- }
- this._engaged = true;
- this._surprise.gameObject.SetActive(true);
- LevelBase.CurrentLevel.GuiScript.ShowMessage("Something ancient has awoken...");
- }
- /// <summary>
- /// Called when an engine has died.
- /// </summary>
- /// <param name="engine">The engine.</param>
- private void OnEngineDied(PyramidEngine engine)
- {
- this._engines.Remove(engine);
- if (this._engines.Count == 0)
- {
- LevelBase.CurrentLevel.GuiScript.ShowMessage("You have defeated...whatever that thing was.");
- }
- }
- /// <summary>
- /// Update is called once per frame.
- /// </summary>
- private void Update()
- {
- if (this._engaged)
- {
- if (this._climbHeight >= 0f)
- {
- int numEngines = this._engines.Count;
- if (numEngines > 0)
- {
- this._speed += numEngines * Time.deltaTime;
- }
- else
- {
- this._speed -= 9.8f * Time.deltaTime;
- }
- var distance = this._speed * Time.deltaTime;
- this._climbHeight += distance;
- this.transform.Translate(Vector3.up * distance);
- this.transform.Rotate(Vector3.up, this._speed * 0.1f * Time.deltaTime);
- }
- }
- else if (Game.Game.Instance.CurrentLevel.IsSandbox)
- {
- if (this._triggerVolume.HasAnyParts())
- {
- this._engageTimer -= Time.deltaTime;
- }
- else if (this._engageTimer < 0f)
- {
- // All parts must leave the trigger before it can be engaged
- this.Engage();
- }
- }
- }
- /// <summary>
- /// Pyramid engine.
- /// </summary>
- /// <seealso cref="Assets.Scripts.Parts.Targeting.Target" />
- internal class PyramidEngine : Target
- {
- /// <summary>
- /// The is dead flag.
- /// </summary>
- private bool _isDead;
- /// <summary>
- /// Initializes a new instance of the <see cref="PyramidEngine" /> class.
- /// </summary>
- /// <param name="pyramid">The pyramid.</param>
- /// <param name="damageableBody">The damageable body.</param>
- public PyramidEngine(PyramidScript pyramid, DamageableBody damageableBody)
- {
- this.DamageableBody = damageableBody;
- this.DamageableBody.DamageReceived += this.DamageableBody_DamageReceived;
- this.DamageableBody.DamageThresholdReached += this.DamageableBody_DamageThresholdReached;
- this.ParticleSystem = damageableBody.GetComponentInChildren<ParticleSystem>(true);
- this.Pyramid = pyramid;
- this.Name = "Alien Engine";
- }
- /// <summary>
- /// Gets the damageable body.
- /// </summary>
- /// <value>
- /// The damageable body.
- /// </value>
- public DamageableBody DamageableBody { get; }
- /// <summary>
- /// Gets a value indicating whether [is dead].
- /// </summary>
- /// <value>
- /// <c>true</c> if [is dead]; otherwise, <c>false</c>.
- /// </value>
- public override bool IsDead
- {
- get
- {
- return this._isDead;
- }
- }
- /// <summary>
- /// Gets the particle system.
- /// </summary>
- /// <value>
- /// The particle system.
- /// </value>
- public ParticleSystem ParticleSystem { get; }
- /// <summary>
- /// Gets the position.
- /// </summary>
- /// <value>
- /// The position.
- /// </value>
- public override Vector3 Position
- {
- get
- {
- return this.DamageableBody.transform.position;
- }
- }
- /// <summary>
- /// Gets the pyramid.
- /// </summary>
- /// <value>
- /// The pyramid.
- /// </value>
- public PyramidScript Pyramid { get; }
- /// <summary>
- /// Gets a value indicating whether this target suppors occlusion.
- /// </summary>
- /// <value>
- /// <c>true</c> if this target suppors occlusion; otherwise, <c>false</c>.
- /// </value>
- public override bool SupportsOcclusion
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// Gets the type of the target.
- /// </summary>
- /// <value>
- /// The type of the target.
- /// </value>
- public override TargetType TargetType
- {
- get
- {
- return TargetType.Air;
- }
- }
- /// <summary>
- /// Gets the velocity.
- /// </summary>
- /// <value>
- /// The velocity.
- /// </value>
- public override Vector3 Velocity
- {
- get
- {
- return Vector3.zero;
- }
- }
- /// <summary>
- /// Alerts the target that it is being acquired and/or locked.
- /// </summary>
- /// <param name="locked">if set to <c>true</c> [locked].</param>
- public override void Alert(bool locked)
- {
- }
- /// <summary>
- /// Called as a warning when a threat (missile, guns, etc.) has been fired againts this entity.
- /// </summary>
- /// <param name="threat">The threat.</param>
- public override void FireWarning(Rigidbody threat)
- {
- }
- /// <summary>
- /// Handles the DamageReceived event of the DamageableBody control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="DamageEventArgs"/> instance containing the event data.</param>
- private void DamageableBody_DamageReceived(object sender, DamageEventArgs e)
- {
- }
- /// <summary>
- /// Handles the DamageThresholdReached event of the DamageableBody control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="DamageThresholdEventArgs"/> instance containing the event data.</param>
- private void DamageableBody_DamageThresholdReached(object sender, DamageThresholdEventArgs e)
- {
- var emission = this.ParticleSystem.emission;
- //emission.enabled = false;
- emission.rateOverTime = 0;
- this._isDead = true;
- this.Pyramid.OnEngineDied(this);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement