temporary files rename

This commit is contained in:
Crizomb 2025-01-29 00:34:36 +01:00
parent 8e077e523c
commit a87f0ed109
823 changed files with 20 additions and 5 deletions

View file

@ -1,66 +0,0 @@
using UnityEngine;
public enum DeathSate
{
NotImportant = 0,
QueenADead = 1,
QueenBDead = 2,
}
// For compatibility with the other team units, only contains things that need to be in common
public abstract class AbstractUnit : MonoBehaviour
{
public float price;
[field: SerializeField] public bool IsTeamA { get; private set; }
[field: SerializeField]
protected bool _isQueen;
public virtual bool IsQueen
{
get => _isQueen;
set => SetQueen(value);
}
protected virtual void SetQueen(bool isQueen)
{
_isQueen = isQueen;
}
public abstract void TakeDamage(float damage);
public abstract void Heal(float heal);
public abstract void AddArmor(float armor);
public abstract void RemoveArmor(float armor);
public abstract void StartFight();
protected void Awake()
{
if (IsTeamA)
{
GlobalsVariable.AliveUnitsTeamA.Add(this);
if (IsQueen) GlobalsVariable.QueenA = this;
}
else
{
GlobalsVariable.AliveUnitsTeamB.Add(this);
if (IsQueen) GlobalsVariable.QueenB = this;
}
}
public DeathSate AbstractDeath()
{
if (IsTeamA)
{
GlobalsVariable.AliveUnitsTeamA.Remove(this);
if (IsQueen) return DeathSate.QueenADead;
}
else
{
GlobalsVariable.AliveUnitsTeamB.Remove(this);
if (IsQueen) return DeathSate.QueenBDead;
}
return DeathSate.NotImportant;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: c34c1a29dc0657256b674f37fe8466d9

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: bbb6d2297b3261d3a8edbd488757550a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,92 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using Random = UnityEngine.Random;
[RequireComponent(typeof(MinecraftUnit))]
public class AttackHandler : MonoBehaviour
{
[SerializeField] protected float damage;
[SerializeField] protected float cooldown;
[SerializeField] protected Collider attackShape;
[SerializeField] protected float knockbackHorizontalForce;
[SerializeField] protected float knockbackVerticalForce;
protected MinecraftUnit _minecraftUnit;
void Awake()
{
_minecraftUnit = GetComponent<MinecraftUnit>();
}
void Start()
{
InvokeRepeating(nameof(Attack), Random.Range(-cooldown*0.2f, cooldown*0.2f), cooldown);
}
/// <summary>
/// Launch an Attack, and return true if it's possible to attack
/// see what Units are in the attackShape, apply damage and knockback to those unit if they're ennemies
/// </summary>
public virtual bool Attack()
{
Collider[] targets = DetectTargets();
bool hasHit = false;
foreach (Collider target in targets)
{
if (!target.CompareTag("Unit")) continue;
// GetComponent is expensive in performance, optimize here if it's slow
AbstractUnit targetUnit = target.GetComponent<AbstractUnit>();
// No friendly fire
if (targetUnit.IsTeamA == _minecraftUnit.IsTeamA) continue;
targetUnit.TakeDamage(damage);
_minecraftUnit.Capacity.AddMana(damage);
hasHit = true;
Vector3 knockbackVector = knockbackHorizontalForce * (target.transform.position - transform.position).normalized
+ knockbackVerticalForce * Vector3.up;
// logic specific if targetUnit is Unit
if (targetUnit is MinecraftUnit)
{
MinecraftUnit minecraftTarget = (MinecraftUnit)targetUnit;
minecraftTarget.StartCoroutine(minecraftTarget.MovementHandler.TakeImpulse(knockbackVector));
}
}
// Attack animation
if (_minecraftUnit.Animator && hasHit)
{
_minecraftUnit.Animator.SetTrigger("Attack");
}
return hasHit;
}
private Collider[] DetectTargets()
{
Collider[] hitColliders;
switch (attackShape)
{
case SphereCollider sphere:
hitColliders = Physics.OverlapSphere(transform.position, sphere.radius, sphere.includeLayers);
break;
case BoxCollider box:
hitColliders = Physics.OverlapBox(box.bounds.center, box.bounds.extents, box.transform.rotation, box.includeLayers);
break;
default:
throw new ArgumentException("Only sphere or box are supported");
}
return hitColliders;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: eb03fb8c097f016f09d345ce200c3f41

View file

@ -1,29 +0,0 @@
using System.Collections;
using UnityEngine;
public class CreeperBomb : AttackHandler
{
[SerializeField] private GameObject explodeMesh;
[SerializeField] private float exploseMeshTime = 0.5f;
public override bool Attack()
{
bool hasExploded = base.Attack();
if (hasExploded)
{
_minecraftUnit.HealthHandler.Death();
CoroutineManager.Instance.StartCoroutine(ExplodeVisual());
Destroy(gameObject);
}
return hasExploded;
}
private IEnumerator ExplodeVisual()
{
GameObject explosion = Instantiate(explodeMesh, transform.position, Quaternion.identity);
explosion.transform.parent = null;
yield return new WaitForSeconds(exploseMeshTime);
Destroy(explosion);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: a3898c60f9d89bde4973aa3d701f6282

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 81db3118949a24b2d83ea142891913b3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,25 +0,0 @@
using UnityEngine;
public class Arrow : ProjectileHandler
{
[SerializeField] private float baseDamage;
[SerializeField] private float baseKnockback;
void OnCollisionEnter(Collision collision)
{
// Can be optimized with tags, but it add dependance beetween teams
if (collision.gameObject.TryGetComponent<AbstractUnit>(out AbstractUnit unit))
{
if (unit is MinecraftUnit && unit.IsTeamA != FromTeamA) // No friendly fire
{
MinecraftUnit minecraftUnit = unit as MinecraftUnit;
Vector3 knockback = RigidBody.linearVelocity * baseKnockback;
minecraftUnit.StartCoroutine(minecraftUnit.MovementHandler.TakeImpulse(knockback));
}
unit.TakeDamage(baseDamage);
_minecraftUnitOrigin.Capacity.AddMana(baseDamage);
}
Destroy(this.gameObject);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 36e1a3cc9e04b444cadcfe2b444d0abc

View file

@ -1,70 +0,0 @@
using UnityEngine;
public class AttackProjectile : AttackHandler
{
[SerializeField] private GameObject arrowPrefab;
[SerializeField] private float arrowBaseSpeed;
[SerializeField] private Transform spawnPos;
[SerializeField] private bool directShot;
public override bool Attack()
{
// If no target (target is dead an destroyed)
if (!_minecraftUnit.MovementHandler.TargetUnit)
{
if (_minecraftUnit.IsTeamA)
{
if (GlobalsVariable.AliveUnitsTeamB.Count == 0) return false;
}
else
{
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return false;
}
}
float launchAngle = findLaunchAngle();
//print(launchAngle);
// If target not reachable
if (launchAngle < 0) return false;
GameObject arrow = Instantiate(arrowPrefab, spawnPos.position, spawnPos.rotation);
ProjectileHandler projectileHandler = arrow.GetComponent<ProjectileHandler>();
// In target <-> launcher + transform.up basis
Vector2 localLaunchVector = arrowBaseSpeed * new Vector2(Mathf.Cos(launchAngle), Mathf.Sin(launchAngle));
// Transform it in global basis
AbstractUnit targetUnit = _minecraftUnit.MovementHandler.TargetUnit;
Vector3 diffVector = Vector3.ProjectOnPlane(targetUnit.transform.position - spawnPos.position, Vector3.up);
Vector3 launchVectorNormalized = (localLaunchVector.x * diffVector.normalized + localLaunchVector.y * Vector3.up).normalized;
projectileHandler.LaunchProjectile(launchVectorNormalized * arrowBaseSpeed, _minecraftUnit.IsTeamA, _minecraftUnit);
return true;
}
private float findLaunchAngle()
{
// Source : https://en.wikipedia.org/wiki/Projectile_motion#Angle_%CE%B8_required_to_hit_coordinate_(x,_y)
AbstractUnit targetUnit = _minecraftUnit.MovementHandler.TargetUnit;
if (targetUnit == null) return -1f;
Vector3 diffVector = targetUnit.transform.position - spawnPos.position;
Vector3 projectOnPlane = Vector3.ProjectOnPlane(diffVector, Vector3.up);
float x = Vector3.ProjectOnPlane(projectOnPlane, Vector3.up).magnitude;
float y = diffVector.y;
float g = Physics.gravity.magnitude;
float v = arrowBaseSpeed;
float v_sqr = v * v;
//print("x : " + x);
float inside_sqrt_root = v_sqr*v_sqr - g*(g*x*x + 2*y*v_sqr);
if (inside_sqrt_root < 0.0f) return -1f; // Can't reach target
// directShot is the smallest angle, undirectShot shot is the biggest angle
float numerator = directShot ? v_sqr - Mathf.Sqrt(inside_sqrt_root) : v_sqr + Mathf.Sqrt(inside_sqrt_root);
float inside_arctan = numerator / (g * x);
return Mathf.Atan(inside_arctan);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 6fa6d262ce5ee0761b28bd18f6bcd247

View file

@ -1,38 +0,0 @@
using UnityEngine;
using System.Collections;
public class HealthPotion : ProjectileHandler
{
[SerializeField] private float healthAdd;
[SerializeField] private SphereCollider healthPotionEffectArea;
[SerializeField] private GameObject explodeMesh;
[SerializeField] private float exploseMeshTime = 0.5f;
void OnCollisionEnter(Collision collision)
{
Collider[] targets = Physics.OverlapSphere(transform.position, healthPotionEffectArea.radius, healthPotionEffectArea.includeLayers);
foreach (Collider target in targets)
{
if (!target.CompareTag("Unit")) continue;
// GetComponent is expensive in performance, optimize here if it's slow
AbstractUnit targetUnit = target.GetComponent<AbstractUnit>();
// No EnemyHealing
if (targetUnit.IsTeamA != FromTeamA) continue;
targetUnit.Heal(healthAdd);
_minecraftUnitOrigin.Capacity.AddMana(healthAdd*0.1f);
}
CoroutineManager.Instance.StartCoroutine(ExplodeVisual());
Destroy(gameObject);
}
private IEnumerator ExplodeVisual()
{
GameObject explosion = Instantiate(explodeMesh, transform.position, Quaternion.identity);
explosion.transform.parent = null;
yield return new WaitForSeconds(exploseMeshTime);
Destroy(explosion);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: fd66c851299240c02a3082ade5b6295d

View file

@ -1,40 +0,0 @@
using Unity.VisualScripting;
using UnityEngine;
/// <summary>
/// Should be attached to the Arrow, not the skeleton
/// </summary>
[RequireComponent(typeof(Rigidbody))]
public class ProjectileHandler : MonoBehaviour
{
[SerializeField] protected float _lifeSpan = 8.0f;
protected Rigidbody RigidBody;
protected bool FromTeamA;
protected MinecraftUnit _minecraftUnitOrigin;
void Awake()
{
RigidBody = GetComponent<Rigidbody>();
}
void Start()
{
// Destroy after _lifeSpan, in all case
Destroy(this.gameObject, _lifeSpan);
}
void Update()
{
// Align with speed
if (RigidBody.linearVelocity.magnitude >= 1f) transform.forward = RigidBody.linearVelocity.normalized;
}
public void LaunchProjectile(Vector3 baseSpeed, bool fromTeamA, MinecraftUnit minecraftUnit)
{
RigidBody.linearVelocity = baseSpeed;
FromTeamA = fromTeamA;
_minecraftUnitOrigin = minecraftUnit;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 9aa6ff4d0673f53389daff2a5ba3c45f

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 6a9e2d1e9e9f8774395ab8c8b44e8dba
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,23 +0,0 @@
using UnityEngine;
using UnityEngine.UI;
public class HealthBar : MonoBehaviour
{
[SerializeField] private HealthHandler healthHandler;
[SerializeField] private Slider healthSlider;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
healthSlider.maxValue = healthHandler.MaxHealth;
}
void Update()
{
healthSlider.value = healthHandler.CurrentHealth;
}
// Update is called once per frame
void LateUpdate()
{
transform.LookAt(Camera.main.transform);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: da56039456f5041c88cca65308f23ca0

View file

@ -1,21 +0,0 @@
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
public class ManaBars : MonoBehaviour
{
[SerializeField] private BaseCapacity capacity;
[SerializeField] private Slider manaSlider;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
manaSlider.maxValue = capacity.MaxMana;
}
void Update()
{
manaSlider.value = capacity.Mana;
}
// Child of healthbar, rotation is handled by healthbar
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: bc83878e8ee5d68b2b4f5622c7100b52

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 9d27c54e796078de08e2819b80f8cbcd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,32 +0,0 @@
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(MinecraftUnit))]
[RequireComponent(typeof(MovementHandler))]
public abstract class AbstractBehaviour : MonoBehaviour
{
[SerializeField] private float pathFps = 1.0f;
[SerializeField] protected float distanceGoal = 0.0f;
protected abstract void MoveAction();
protected MinecraftUnit CurrentMinecraftUnit;
void Start()
{
CurrentMinecraftUnit = GetComponent<MinecraftUnit>();
StartCoroutine(pathUpdate());
}
private IEnumerator pathUpdate()
{
while (true)
{
MoveAction();
yield return new WaitForSeconds(1.0f/pathFps);
}
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: bca22bdff905462e49dd5f0d224452c6

View file

@ -1,23 +0,0 @@
using UnityEngine;
public class DefensiveBehaviour : AbstractBehaviour
{
protected override void MoveAction()
{
if (CurrentMinecraftUnit.IsTeamA)
{
if (GlobalsVariable.QueenA != null) return;
CurrentMinecraftUnit.MovementHandler.UpdateNearestFrom(GlobalsVariable.QueenA.transform);
}
else
{
if (GlobalsVariable.QueenB != null) return;
CurrentMinecraftUnit.MovementHandler.UpdateNearestFrom(GlobalsVariable.QueenB.transform);
}
Vector3 targetPos = CurrentMinecraftUnit.MovementHandler.TargetUnit.transform.position;
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 4d7eb557429d0c73b8e60870d6370ff6

View file

@ -1,26 +0,0 @@
using System;
using UnityEngine;
public class NeutralBehaviour : AbstractBehaviour
{
protected override void MoveAction()
{
if (CurrentMinecraftUnit.IsTeamA)
{
if (GlobalsVariable.AliveUnitsTeamB.Count == 0) return;
}
else
{
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return;
}
CurrentMinecraftUnit.MovementHandler.UpdateNearest();
AbstractUnit targetUnit = CurrentMinecraftUnit.MovementHandler.TargetUnit;
if (targetUnit == null)
{
return;
}
Vector3 targetPos = targetUnit.transform.position;
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 794f919ac24609c05b9c690aaab19146

View file

@ -1,22 +0,0 @@
using UnityEngine;
public class OffensiveBehaviour : AbstractBehaviour
{
protected override void MoveAction()
{
if (CurrentMinecraftUnit.IsTeamA)
{
if (GlobalsVariable.QueenB == null) return;
}
else
{
if (GlobalsVariable.QueenA == null) return;
}
CurrentMinecraftUnit.MovementHandler.TargetUnit = GlobalsVariable.QueenB;
Vector3 targetPos = CurrentMinecraftUnit.MovementHandler.TargetUnit.transform.position;
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 02c5dcee842138a4ab3b5db250170c31

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: d76dce105c83372aebd5f8d8f33ee08b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,40 +0,0 @@
using UnityEngine;
using UnityEngine.Serialization;
public class BaseCapacity : MonoBehaviour
{
[field: SerializeField] public float MaxMana { get; private set; }
[field: SerializeField] public float Mana { get; private set; }
[SerializeField] private float manaCost;
protected AbstractUnit _unit;
// Called every frame
protected virtual bool CapacityCall()
{
return true;
}
public void AddMana(float manaAdd)
{
Mana = Mathf.Min(Mana + manaAdd, MaxMana);
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_unit = GetComponent<AbstractUnit>();
}
// Update is called once per frame
void Update()
{
if (Mana >= manaCost)
{
bool capacityLaunched = CapacityCall();
if (capacityLaunched) Mana -= manaCost;
}
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: adbf6613bee8e8088b3389c62d61b845

View file

@ -1,33 +0,0 @@
using UnityEngine;
using System.Collections;
public class GolemDefense : BaseCapacity
{
[SerializeField] private float armorGain;
[SerializeField] private float buffTime;
[SerializeField] private SphereCollider buffArea;
protected override bool CapacityCall()
{
Collider[] hitColliders = Physics.OverlapSphere(transform.position, buffArea.radius, buffArea.includeLayers);
foreach (Collider target in hitColliders)
{
if (!target.CompareTag("CurrentMinecraftUnit")) continue;
AbstractUnit targetUnit = target.GetComponent<AbstractUnit>();
if (targetUnit.IsTeamA == _unit.IsTeamA)
{
CoroutineManager.Instance.StartCoroutine(AddThenRemoveArmor(targetUnit));
}
}
return hitColliders.Length > 0;
}
private IEnumerator AddThenRemoveArmor(AbstractUnit targetUnit)
{
targetUnit.AddArmor(armorGain);
yield return new WaitForSeconds(buffTime);
targetUnit.RemoveArmor(armorGain);
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 1ca640aad27b1da9d87fdc4302aa0cd3

View file

@ -1,23 +0,0 @@
using UnityEngine;
using System.Collections;
public class TripleAttack : BaseCapacity
{
protected override bool CapacityCall()
{
MinecraftUnit minecraftUnit = _unit as MinecraftUnit;
StartCoroutine(TripleAttackRoutine(minecraftUnit));
return true;
}
private IEnumerator TripleAttackRoutine(MinecraftUnit minecraftUnit)
{
minecraftUnit.AttackHandler.Attack();
yield return new WaitForSeconds(0.1f);
minecraftUnit.AttackHandler.Attack();
yield return new WaitForSeconds(0.1f);
minecraftUnit.AttackHandler.Attack();
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: b0344a53e7b8b8f30b008023599beb65

View file

@ -1,14 +0,0 @@
using UnityEngine;
public class WitchSummon : BaseCapacity
{
[SerializeField] private GameObject summonUnit;
protected override bool CapacityCall()
{
GameObject unit = Instantiate(summonUnit, transform.position, Quaternion.identity);
AbstractUnit unitScript = unit.GetComponent<AbstractUnit>();
unitScript.StartFight();
return true;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 1c3c6b3848aa5f3cd9b73630ddae811e

View file

@ -1,22 +0,0 @@
using UnityEngine;
using System.Collections;
public class ZombieSpeedBoost : BaseCapacity
{
[SerializeField] float timeToBoost;
[SerializeField] float boost;
protected override bool CapacityCall()
{
MinecraftUnit minecraftUnit = _unit as MinecraftUnit;
StartCoroutine(AddThenRemoveSpeed(minecraftUnit));
return true;
}
private IEnumerator AddThenRemoveSpeed(MinecraftUnit minecraftUnit)
{
// Possibility float imprecision issues
minecraftUnit.MovementHandler.speed *= boost;
yield return new WaitForSeconds(timeToBoost);
minecraftUnit.MovementHandler.speed /= boost;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: c3b089e9358a7b3adbe2f521fcfbc8c2

View file

@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
public static class GlobalsVariable
{
public static int money=100;
public static List<AbstractUnit> AliveUnitsTeamA = new List<AbstractUnit>();
public static List<AbstractUnit> AliveUnitsTeamB = new List<AbstractUnit>();
public static AbstractUnit QueenA;
public static AbstractUnit QueenB;
public static Dictionary<string, int> prices = new Dictionary<string, int>()
{
{ "Zombie",1 },
{ "Squelette",2 },
{ "Creeper",3 },
{ "Sorciere",3 },
{ "Golem",8 }
};
public static void Pay(int X)
{
money -= X;
}
public static void Gain(int Y)
{
money += Y;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: aff398f48f2c36187b8027e20ad9dc16

View file

@ -1,68 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
[RequireComponent(typeof(MinecraftUnit))]
public class HealthHandler : MonoBehaviour
{
[field: SerializeField] public float MaxHealth{ get; private set; }
[field: SerializeField] public float CurrentHealth{ get; private set; }
[field: SerializeField] public float Armor{ get; private set; }
private MinecraftUnit _minecraftUnit;
public void Awake()
{
_minecraftUnit = GetComponent<MinecraftUnit>();
}
public void TakeDamage(float damage)
{
Debug.Assert(damage >= 0, "Damage cannot be negative, use Heal if you want to heal");
CurrentHealth -= Mathf.Max(0, damage-Armor);
_minecraftUnit.Capacity.AddMana(damage);
if (CurrentHealth <= 0) Death();
}
public void Heal(float value)
{
Debug.Assert(value >= 0, "value can't be less than zero");
CurrentHealth = Mathf.Min(CurrentHealth + value, MaxHealth);
}
public void AddArmor(float armorBoost)
{
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use RemoveArmor instead");
Armor += armorBoost;
}
public void RemoveArmor(float armorBoost)
{
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use AddArmor instead");
Armor -= armorBoost;
}
public void Death(float delay = 0)
{
DeathSate deathState = _minecraftUnit.AbstractDeath();
if (deathState == DeathSate.NotImportant)
{
Destroy(gameObject, delay);
return;
}
if (deathState == DeathSate.QueenBDead)
{
print("get good, reload current scene");
GameManager.Instance.ReloadLevel();
}
if (deathState == DeathSate.QueenADead)
{
print("GG going to next scene");
GameManager.Instance.GoNextLevel();
}
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 8511709ac7cfc1d05bee202fa8b8b095

View file

@ -1,85 +0,0 @@
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.AI;
[DisallowMultipleComponent]
[RequireComponent(typeof(Rigidbody), typeof(HealthHandler), typeof(AttackHandler))]
[RequireComponent(typeof(MovementHandler), typeof(BaseCapacity))]
public class MinecraftUnit : AbstractUnit
{
[field: SerializeField] public Rigidbody Body { get; private set; }
[field: SerializeField] public HealthHandler HealthHandler { get; private set; }
[field: SerializeField] public AttackHandler AttackHandler { get; private set; }
[field: SerializeField] public MovementHandler MovementHandler { get; private set; }
[field: SerializeField] public BaseCapacity Capacity { get; private set; }
// Not required
[field: SerializeField] public Animator Animator { get; private set; }
protected override void SetQueen(bool isQueen)
{
_isQueen = isQueen;
transform.Find("Crown").gameObject.SetActive(true);
}
new void Awake()
{
base.Awake();
if (IsQueen)
{
transform.Find("Crown").gameObject.SetActive(true);
if (IsTeamA)
{
GlobalsVariable.QueenA = this;
}
else
{
GlobalsVariable.QueenB = this;
}
}
}
// Abstract implementation for compatibility with other team
public override void TakeDamage(float damage)
{
HealthHandler.TakeDamage(damage);
}
public override void Heal(float heal)
{
HealthHandler.Heal(heal);
}
public override void AddArmor(float armor)
{
HealthHandler.AddArmor(armor);
}
public override void RemoveArmor(float armor)
{
HealthHandler.RemoveArmor(armor);
}
public override void StartFight()
{
Component[] components = GetComponents<Component>();
foreach (Component component in components)
{
if (component is MonoBehaviour monoBehaviour)
{
monoBehaviour.enabled = true;
}
if (component is NavMeshAgent agent)
{
agent.enabled = true;
}
}
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 9815bed5dc151c8c6a271899ed1b7c4f

View file

@ -1,131 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(MinecraftUnit))]
[RequireComponent(typeof(Rigidbody))]
public class MovementHandler : MonoBehaviour
{
[SerializeField] public float speed;
[SerializeField] private NavMeshAgent agent;
[SerializeField] private bool followEnemy = true;
[SerializeField] private float knockbackTime = 1.2f;
[SerializeField] private float _noNavMeshDeadTime = 3.0f;
[HideInInspector] public AbstractUnit TargetUnit {get; set; }
private MinecraftUnit _minecraftUnit;
private Rigidbody _rigidbody;
void Awake()
{
_minecraftUnit = GetComponent<MinecraftUnit>();
_rigidbody = GetComponent<Rigidbody>();
}
void Start()
{
agent.speed = speed;
}
private void Update()
{
if (Mathf.Abs(agent.speed - speed) < 0.01f) agent.speed = speed;
}
public void ChangeSpeed(float newSpeed)
{
speed = newSpeed;
}
public void StopMoving()
{
agent.speed = 0;
}
public void ResumeMoving()
{
agent.speed = speed;
}
public void MoveTowards(Vector3 destination)
{
if (agent.enabled) agent.SetDestination(destination);
}
public void UpdateNearest()
{
TargetUnit = FindNearest(followEnemy);
}
public void UpdateNearestFrom(Transform transform)
{
TargetUnit = FindNearestFromTransform(true, transform);
}
// If findEnemy, return closest ennemy else return closest ally
private AbstractUnit FindNearestFromTransform(bool findEnemy, Transform from)
{
// Funny funny double ternary operator.
List<AbstractUnit> targets = findEnemy ?
_minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamB : GlobalsVariable.AliveUnitsTeamA
: _minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamA : GlobalsVariable.AliveUnitsTeamB;
AbstractUnit closestUnit = null;
float closestDistance = float.MaxValue;
foreach (AbstractUnit target in targets)
{
float distanceToEnemy = (target.transform.position - from.position).sqrMagnitude;
if (distanceToEnemy < closestDistance && target != _minecraftUnit)
{
closestUnit = target;
closestDistance = distanceToEnemy;
}
}
if (closestUnit == null)
{
print("What");
print(targets.Count);
print(targets);
}
return closestUnit;
}
private AbstractUnit FindNearest(bool findEnemy)
{
return FindNearestFromTransform(findEnemy, transform);
}
public IEnumerator TakeImpulse(Vector3 impulse)
{
// Unity navmesh, can't handle physics (it rewrite velocity). So we deactivate it when applying force.
agent.enabled = false;
_rigidbody.AddForce(impulse, ForceMode.Impulse);
yield return new WaitForSeconds(knockbackTime);
float noSurfaceTime = 0.0f;
// Make sure to be on the navmesh surface before reactivating agent
while (_rigidbody != null && !NavMesh.SamplePosition(_rigidbody.position, out _, 1.0f, NavMesh.AllAreas))
{
yield return new WaitForSeconds(0.5f);
noSurfaceTime += 0.5f;
// Die if exited navMesh for to long
if (noSurfaceTime > _noNavMeshDeadTime)
{
_minecraftUnit.HealthHandler.Death();
yield break;
}
}
if (agent != null) agent.enabled = true;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: aa245c9f3dff7f6b9888b009a1023628