diff options
Diffstat (limited to 'Assembly_CSharp/Projectile')
-rw-r--r-- | Assembly_CSharp/Projectile/Landmine.cs | 67 | ||||
-rw-r--r-- | Assembly_CSharp/Projectile/MorterShell.cs | 81 | ||||
-rw-r--r-- | Assembly_CSharp/Projectile/ParticleBeam.cs | 19 | ||||
-rw-r--r-- | Assembly_CSharp/Projectile/Projectile.cs | 141 | ||||
-rw-r--r-- | Assembly_CSharp/Projectile/ProjectileFX.cs | 47 | ||||
-rw-r--r-- | Assembly_CSharp/Projectile/Sawblade.cs | 87 | ||||
-rw-r--r-- | Assembly_CSharp/Projectile/SnowFlake.cs | 23 |
7 files changed, 465 insertions, 0 deletions
diff --git a/Assembly_CSharp/Projectile/Landmine.cs b/Assembly_CSharp/Projectile/Landmine.cs new file mode 100644 index 0000000..5422016 --- /dev/null +++ b/Assembly_CSharp/Projectile/Landmine.cs @@ -0,0 +1,67 @@ +using System.Collections; +using UnityEngine; + +public class Landmine : Projectile +{ + public float blastRadius = 0.5f; + + private bool armed; + + [SerializeField] + private GameObject explosion; + + protected override void Start() + { + base.Start(); + SpawnManager.instance.destroyOnNewLevel.Add(base.gameObject); + } + + public void SetEndPosition(Vector3 endPos) + { + StartCoroutine(ThrowMine(endPos)); + } + + protected override void FixedUpdate() + { + } + + private void OnTriggerEnter(Collider other) + { + if (armed && other.gameObject.layer == LayerMask.NameToLayer("Enemy")) + { + Explode(); + } + } + + private void Explode() + { + Collider[] array = Physics.OverlapSphere(base.transform.position, blastRadius, layermask, QueryTriggerInteraction.Collide); + for (int i = 0; i < array.Length; i++) + { + IDamageable component = array[i].GetComponent<IDamageable>(); + if (component != null) + { + DealDamage(component); + } + } + Object.Instantiate(explosion, base.transform.position, Quaternion.identity).transform.localScale = Vector3.one * 0.5f; + SpawnManager.instance.destroyOnNewLevel.Remove(base.gameObject); + Object.Destroy(base.gameObject); + } + + private IEnumerator ThrowMine(Vector3 endPos) + { + Vector3 direction = endPos - base.transform.position; + float throwTime = 1f; + base.transform.localScale = Vector3.zero; + for (float i = 0f; i < 1f; i += Time.deltaTime / throwTime) + { + base.transform.localScale = Vector3.one * i; + base.transform.Translate(direction * Time.deltaTime / throwTime); + yield return null; + } + base.transform.localScale = Vector3.one; + base.transform.position = endPos; + armed = true; + } +} diff --git a/Assembly_CSharp/Projectile/MorterShell.cs b/Assembly_CSharp/Projectile/MorterShell.cs new file mode 100644 index 0000000..ce93441 --- /dev/null +++ b/Assembly_CSharp/Projectile/MorterShell.cs @@ -0,0 +1,81 @@ +using UnityEngine; + +public class MorterShell : Projectile +{ + [SerializeField] + private GameObject artObject; + + [SerializeField] + private LayerMask layersAffectedByBlast; + + public float blastRadius = 1f; + + private Vector3 destination; + + private float timeOfFlight; + + [SerializeField] + private float vSpeed; + + [SerializeField] + private float hSpeed; + + [SerializeField] + private float gravity = 5f; + + [SerializeField] + private GameObject explosion; + + private float lookAhead; + + private Vector3 previousPos; + + public void SetMorterPhysics(Vector3 pos) + { + destination = pos; + timeOfFlight = speed; + vSpeed = gravity * timeOfFlight / 2f; + hSpeed = Vector3.Magnitude(base.transform.position - destination) / timeOfFlight; + lookAhead = vSpeed + hSpeed; + } + + protected override void MoveProjectile() + { + previousPos = base.transform.position; + base.transform.Translate(Vector3.forward * hSpeed * Time.fixedDeltaTime); + base.transform.Translate(Vector3.up * vSpeed * Time.fixedDeltaTime); + vSpeed -= gravity * Time.fixedDeltaTime; + artObject.transform.rotation = Quaternion.LookRotation(base.transform.position - previousPos, Vector3.up); + } + + protected override void CheckForHits() + { + if (!(vSpeed > 0f) && Physics.Raycast(artObject.transform.position, artObject.transform.forward, out var hitInfo, lookAhead * Time.fixedDeltaTime, layermask, QueryTriggerInteraction.Collide)) + { + OnHit(hitInfo); + } + } + + protected override void OnHit(RaycastHit hit) + { + Collider[] array = Physics.OverlapSphere(base.transform.position, blastRadius, layersAffectedByBlast, QueryTriggerInteraction.Collide); + for (int i = 0; i < array.Length; i++) + { + IDamageable component = array[i].GetComponent<IDamageable>(); + if (component != null) + { + DealDamage(component); + } + } + if (detachOnDestruction != null) + { + detachOnDestruction.transform.parent = null; + } + if (extraFX != null) + { + extraFX.OnDetach(); + } + Object.Instantiate(explosion, base.transform.position, Quaternion.identity); + Object.Destroy(base.gameObject); + } +} diff --git a/Assembly_CSharp/Projectile/ParticleBeam.cs b/Assembly_CSharp/Projectile/ParticleBeam.cs new file mode 100644 index 0000000..6a7bf2a --- /dev/null +++ b/Assembly_CSharp/Projectile/ParticleBeam.cs @@ -0,0 +1,19 @@ +using UnityEngine; + +public class ParticleBeam : Projectile +{ + [SerializeField] + private GameObject beamTrail; + + protected override void MoveProjectile() + { + base.MoveProjectile(); + beamTrail.transform.position = base.transform.position + new Vector3(Random.Range(-1f, 1f), Random.Range(0f, 1f), Random.Range(-1f, 1f)); + } + + protected new virtual void OnHit(RaycastHit hit) + { + beamTrail.transform.position = hit.point; + base.OnHit(hit); + } +} diff --git a/Assembly_CSharp/Projectile/Projectile.cs b/Assembly_CSharp/Projectile/Projectile.cs new file mode 100644 index 0000000..3c15fe4 --- /dev/null +++ b/Assembly_CSharp/Projectile/Projectile.cs @@ -0,0 +1,141 @@ +using UnityEngine; + +public class Projectile : MonoBehaviour +{ + [SerializeField] + protected Sound launchSound; + + [SerializeField] + protected Sound hitSound; + + protected TowerType shotBy; + + [SerializeField] + protected LayerMask layermask; + + [SerializeField] + protected float speed; + + [SerializeField] + protected bool homing; + + [SerializeField] + protected float maximumLifeTime = 10f; + + [SerializeField] + public GameObject detachOnDestruction; + + [SerializeField] + public ProjectileFX extraFX; + + protected GameObject target; + + protected int damage; + + protected int healthDamage; + + protected int armorDamage; + + protected int shieldDamage; + + protected float slowPercent; + + protected float bleedPercent; + + protected float burnPercent; + + protected float poisonPercent; + + protected float critChance; + + protected float stunChance; + + protected virtual void Start() + { + if (launchSound != 0) + { + SFXManager.instance.PlaySound(launchSound, base.transform.position); + } + } + + protected virtual void FixedUpdate() + { + maximumLifeTime -= Time.fixedDeltaTime; + if (maximumLifeTime < 0f) + { + Object.Destroy(base.gameObject); + } + CheckForHits(); + MoveProjectile(); + if (homing) + { + AlterCourse(); + } + } + + public virtual void SetStats(TowerType whoShotMe, GameObject _target, float spd, int dmg, int healthDmg, int armorDmg, int shieldDmg, float slow, float bleed, float burn, float poison, float crit, float stun) + { + shotBy = whoShotMe; + target = _target; + speed = spd; + damage = dmg; + healthDamage = healthDmg; + armorDamage = armorDmg; + shieldDamage = shieldDmg; + slowPercent = slow; + bleedPercent = bleed; + burnPercent = burn; + poisonPercent = poison; + critChance = crit; + stunChance = stun; + } + + protected virtual void MoveProjectile() + { + base.transform.Translate(Vector3.forward * speed * Time.fixedDeltaTime); + } + + protected virtual void AlterCourse() + { + if (!(target == null)) + { + Quaternion rotation = Quaternion.LookRotation(0.25f * Vector3.up + target.transform.position - base.transform.position, Vector3.up); + base.transform.rotation = rotation; + } + } + + protected virtual void CheckForHits() + { + if (Physics.Raycast(base.transform.position, base.transform.forward, out var hitInfo, speed * Time.fixedDeltaTime, layermask, QueryTriggerInteraction.Collide)) + { + OnHit(hitInfo); + } + } + + protected virtual void OnHit(RaycastHit hit) + { + IDamageable component = hit.transform.GetComponent<IDamageable>(); + if (component != null) + { + DealDamage(component); + } + if (detachOnDestruction != null) + { + detachOnDestruction.transform.parent = null; + } + if (extraFX != null) + { + extraFX.OnDetach(); + } + Object.Destroy(base.gameObject); + } + + protected virtual void DealDamage(IDamageable target) + { + target.TakeDamage(shotBy, damage, healthDamage, armorDamage, shieldDamage, slowPercent, bleedPercent, burnPercent, poisonPercent, critChance, stunChance); + if (hitSound != 0) + { + SFXManager.instance.PlaySound(hitSound, base.transform.position); + } + } +} diff --git a/Assembly_CSharp/Projectile/ProjectileFX.cs b/Assembly_CSharp/Projectile/ProjectileFX.cs new file mode 100644 index 0000000..df82c3d --- /dev/null +++ b/Assembly_CSharp/Projectile/ProjectileFX.cs @@ -0,0 +1,47 @@ +using System.Collections; +using UnityEngine; + +public class ProjectileFX : MonoBehaviour +{ + [SerializeField] + private GameObject bleedingPS; + + [SerializeField] + private GameObject burrningPS; + + [SerializeField] + private GameObject poisonPS; + + public void SetFX(float bleeding, float burning, float poison, float slow, bool arcane) + { + if (OptionsMenu.instance.extraProjectileEffects) + { + if (bleeding > 0f) + { + bleedingPS.SetActive(value: true); + } + if (burning > 0f) + { + burrningPS.SetActive(value: true); + } + if (poison > 0f) + { + poisonPS.SetActive(value: true); + } + } + } + + public void OnDetach() + { + StartCoroutine(Die()); + } + + private IEnumerator Die() + { + bleedingPS.GetComponent<ParticleSystem>().Stop(withChildren: true); + burrningPS.GetComponent<ParticleSystem>().Stop(withChildren: true); + poisonPS.GetComponent<ParticleSystem>().Stop(withChildren: true); + yield return new WaitForSeconds(1.1f); + Object.Destroy(base.gameObject); + } +} diff --git a/Assembly_CSharp/Projectile/Sawblade.cs b/Assembly_CSharp/Projectile/Sawblade.cs new file mode 100644 index 0000000..19038df --- /dev/null +++ b/Assembly_CSharp/Projectile/Sawblade.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; +using UnityEngine; + +public class Sawblade : Projectile +{ + private Pathfinder targetPathfinder; + + private Waypoint nextWaypoint; + + private bool pathMode; + + private HashSet<Collider> targetsHit = new HashSet<Collider>(); + + public override void SetStats(TowerType whoShotMe, GameObject _target, float spd, int dmg, int healthDmg, int armorDmg, int shieldDmg, float slow, float bleed, float burn, float poison, float crit, float stun) + { + base.SetStats(whoShotMe, _target, spd, dmg, healthDmg, armorDmg, shieldDmg, slow, bleed, burn, poison, crit, stun); + targetPathfinder = target.GetComponent<Pathfinder>(); + nextWaypoint = targetPathfinder.currentWaypoint; + } + + protected override void AlterCourse() + { + if (!pathMode && targetPathfinder != null) + { + nextWaypoint = targetPathfinder.currentWaypoint; + } + if (!pathMode && (target == null || Vector3.SqrMagnitude(target.transform.position - base.transform.position) < 0.125f)) + { + nextWaypoint = GetPreviousWaypoint(); + pathMode = true; + } + Vector3 position; + if (!pathMode) + { + position = target.transform.position; + } + else + { + if (Vector3.SqrMagnitude(nextWaypoint.transform.position - base.transform.position) < 0.125f) + { + nextWaypoint = GetPreviousWaypoint(); + } + position = nextWaypoint.transform.position; + } + Quaternion rotation = Quaternion.LookRotation(position - base.transform.position, Vector3.up); + base.transform.rotation = rotation; + } + + protected override void CheckForHits() + { + Collider[] array = Physics.OverlapBox(base.transform.position, Vector3.one * 0.25f, Quaternion.identity, layermask, QueryTriggerInteraction.Collide); + foreach (Collider collider in array) + { + if (!pathMode && collider.gameObject == target) + { + nextWaypoint = GetPreviousWaypoint(); + pathMode = true; + } + if (targetsHit.Contains(collider)) + { + continue; + } + IDamageable component = collider.GetComponent<IDamageable>(); + if (component != null) + { + DealDamage(component); + damage--; + if (damage <= 0) + { + Object.Destroy(base.gameObject); + } + } + targetsHit.Add(collider); + } + } + + private Waypoint GetPreviousWaypoint() + { + Waypoint[] previousWaypoints = nextWaypoint.GetPreviousWaypoints(); + if (previousWaypoints.Length == 0) + { + Object.Destroy(base.gameObject); + return nextWaypoint; + } + return previousWaypoints[Random.Range(0, previousWaypoints.Length)]; + } +} diff --git a/Assembly_CSharp/Projectile/SnowFlake.cs b/Assembly_CSharp/Projectile/SnowFlake.cs new file mode 100644 index 0000000..238b829 --- /dev/null +++ b/Assembly_CSharp/Projectile/SnowFlake.cs @@ -0,0 +1,23 @@ +using UnityEngine; + +public class SnowFlake : Projectile +{ + protected override void Start() + { + base.Start(); + base.transform.Translate(new Vector3(Random.Range(-0.25f, 0.25f), Random.Range(-0.25f, 0.25f), Random.Range(-0.25f, 0.25f))); + } + + protected override void MoveProjectile() + { + base.transform.Translate(Vector3.down * speed * Time.fixedDeltaTime); + } + + protected override void CheckForHits() + { + if (Physics.SphereCast(base.transform.position, 0.125f, Vector3.down, out var hitInfo, speed * Time.fixedDeltaTime, layermask, QueryTriggerInteraction.Collide)) + { + OnHit(hitInfo); + } + } +} |