This commit is contained in:
Crizomb 2025-01-29 06:34:44 +01:00
parent 4e91f448c9
commit 1b2611e5a9
90 changed files with 7029 additions and 2762 deletions

View file

@ -43,7 +43,7 @@ public class AttackCAC : MonoBehaviour
// Update is called once per frame
void Update()
{
if (baseDuckScript.getGameManagerScript().combatPhase)
if (GameManager.Instance.fightStarted)
{
if (canAttack)
{
@ -55,35 +55,21 @@ public class AttackCAC : MonoBehaviour
{
Vector3 directionToTarget = hit.transform.position - transform.position;
float distanceToTarget = directionToTarget.magnitude;
if (baseDuckScript.getAttackMode() == 3)
{
distanceToTarget = Vector3.Distance(baseDuckScript.getArmyManagerScript().getCrownDuck(baseDuckScript.getTeam()).transform.position, hit.transform.position);
}
if (!Physics.Raycast(transform.position, directionToTarget.normalized, distanceToTarget,
wallLayer))
{
if (baseDuckScript.getArmyManagerScript().getArmy(!baseDuckScript.getTeam()).Contains(hit.gameObject))
if (ArmyManager.getArmy(!baseDuckScript.getTeam()).Contains(hit.GetComponent<AbstractUnit>()))
{
if (baseDuckScript.getAttackMode() == 1)
{
if (baseDuckScript.getArmyManagerScript().getCrownDuck(!baseDuckScript.getTeam()) ==
if (ArmyManager.getCrownDuck(!baseDuckScript.getTeam()) ==
hit.gameObject)
{
targetToAttack = hit.gameObject;
targetFound = true;
}
}
if (baseDuckScript.getAttackMode() == 2 || baseDuckScript.getAttackMode() == 3)
{
if (distanceToTarget < distanceToChosenTarget)
{
distanceToChosenTarget = distanceToTarget;
targetToAttack = hit.gameObject;
targetFound = true;
}
}
}
}
@ -104,8 +90,8 @@ public class AttackCAC : MonoBehaviour
private void AttackC(GameObject targetToAttack)
{
StartCoroutine(coolDown());
targetToAttack.GetComponent<BaseDuckScript>().TakeDamage(damage);
Debug.Log("Corps à corps");
targetToAttack.GetComponent<AbstractUnit>().TakeDamage(damage);
Debug.Log("Corps <EFBFBD> corps");
ATTACK.Invoke();
}

View file

@ -3,17 +3,14 @@ using UnityEngine.AI;
using System.Collections.Generic;
using UnityEngine.UI;
public class BaseDuckScript : MonoBehaviour
public class BaseDuckScript : AbstractUnit
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
private bool isEnemy = true;
[SerializeField] public bool hasCrown = false;
[SerializeField] GameObject armyManagerEntity;
[SerializeField] GameObject gameManagerEntity;
private ArmyManager armyManagerScript;
private GameManager gameManagerScript;
[SerializeField] GameObject crownPrefab;
[SerializeField] private int attackMode = 0; //0 do Nothing, 1 offense, 2 Neutre, 3 Défense
NavMeshAgent agent;
private Rigidbody duckRB;
Vector3 destination;
@ -38,17 +35,11 @@ public class BaseDuckScript : MonoBehaviour
void Start()
{
health = baseHealth;
armyManagerScript = armyManagerEntity.GetComponent<ArmyManager>();
gameManagerScript = gameManagerEntity.GetComponent<GameManager>();
armyManagerScript.addTroopToArmy(isEnemy, gameObject);
agent = GetComponent<NavMeshAgent>();
duckRB = gameObject.GetComponent<Rigidbody>();
healthCanvasRect = healthCanvas.GetComponent<RectTransform>();
if (hasCrown){
becomeCrownDuck();
}
DuckHeight = transform.Find("TigeUI").GetComponent<Renderer>().bounds.size.y;
allGroundLayers = LayerMask.GetMask("Dirt") | LayerMask.GetMask("Sand");
}
@ -62,8 +53,7 @@ public class BaseDuckScript : MonoBehaviour
transform.LookAt(GetComponent<AttackCAC>().GetTarget().transform);
}
if (gameManagerScript.combatPhase)
if (GameManager.Instance.fightStarted)
{
updateMovement();
}
@ -118,95 +108,20 @@ public class BaseDuckScript : MonoBehaviour
public void updateMovement()
{
duckRB.isKinematic = false;
if (attackMode == 1 && armyManagerScript.getCrownDuck(!isEnemy))
if (attackMode == 1 && ArmyManager.getCrownDuck(!isEnemy))
{
destination = armyManagerScript.getCrownDuck(!isEnemy).transform.position;
destination = ArmyManager.getCrownDuck(!isEnemy).transform.position;
agent.destination = destination;
}
if (attackMode == 2)
{
List<GameObject> opposingArmy = armyManagerScript.getArmy(!isEnemy);
if (opposingArmy.Count > 0){
GameObject closestOpponent = opposingArmy[0];
float closestDistance = Vector3.Distance(opposingArmy[0].transform.position, transform.position);
foreach (GameObject opposingDuck in opposingArmy)
{
if (Vector3.Distance(opposingDuck.transform.position, transform.position) < closestDistance)
{
closestOpponent = opposingDuck;
closestDistance = Vector3.Distance(opposingDuck.transform.position, transform.position);
}
}
destination = closestOpponent.transform.position;
agent.destination = destination;
}
}
if (attackMode == 3)
{
List<GameObject> opposingArmy = armyManagerScript.getArmy(!isEnemy);
if (opposingArmy.Count > 0){
GameObject closestOpponent = opposingArmy[0];
float closestDistance = Vector3.Distance(opposingArmy[0].transform.position, armyManagerScript.getCrownDuck(isEnemy).transform.position);
foreach (GameObject opposingDuck in opposingArmy)
{
if (Vector3.Distance(opposingDuck.transform.position, armyManagerScript.getCrownDuck(isEnemy).transform.position) < closestDistance)
{
closestOpponent = opposingDuck;
closestDistance = Vector3.Distance(opposingDuck.transform.position, armyManagerScript.getCrownDuck(isEnemy).transform.position);
}
}
destination = closestOpponent.transform.position;
agent.destination = destination;
}
}
}
public void setTeam(bool isOnEnemyTeam){
isEnemy = isOnEnemyTeam;
}
public void giveCrown(){
hasCrown = true;
}
public void setArmyManager(GameObject armyManagerEntity)
{
this.armyManagerEntity = armyManagerEntity;
}
public ArmyManager getArmyManagerScript()
{
return armyManagerScript;
}
public void setGameManager(GameObject gameManagerEntity)
{
this.gameManagerEntity = gameManagerEntity;
}
public void becomeCrownDuck()
{
hasCrown = true;
armyManagerScript.setCrownDuck(isEnemy, gameObject);
crown = Instantiate(crownPrefab, this.transform);
}
public void loseMyCrown()
{
hasCrown = false;
armyManagerScript.removeCrownDuck(isEnemy);
Destroy(crown);
}
public void despawn()
{
if (hasCrown)
{
armyManagerScript.removeCrownDuck(isEnemy);
}
armyManagerScript.removeTroopFromArmy(isEnemy, gameObject);
gameManagerScript.refundCoins(cost);
Destroy(gameObject);
}
@ -228,7 +143,7 @@ public class BaseDuckScript : MonoBehaviour
*/
}
public void TakeDamage(float damage)
public override void TakeDamage(float damage)
{
float damageReallyTaken = Mathf.Max(0, damage - armor);
health -= damageReallyTaken;
@ -239,12 +154,28 @@ public class BaseDuckScript : MonoBehaviour
}
}
public void Heal(float value)
public override void Heal(float value)
{
health += value;
health = (health > baseHealth) ? baseHealth : health;
}
public override void AddArmor(float armor)
{
// Nothing
}
public override void RemoveArmor(float armor)
{
// Nothing
}
public override void StartFight()
{
// Nothing
}
public float getHealth()
{
return health;
@ -257,7 +188,6 @@ public class BaseDuckScript : MonoBehaviour
private void die()
{
Destroy(healthBar);
armyManagerScript.kill(isEnemy, gameObject, hasCrown);
Destroy(gameObject);
}
@ -286,8 +216,4 @@ public class BaseDuckScript : MonoBehaviour
this.healthCanvas = healthCanvas;
}
public GameManager getGameManagerScript()
{
return(gameManagerScript);
}
}

View file

@ -1,89 +0,0 @@
using System.Collections;
using UnityEngine;
public class CharDuck : MonoBehaviour
{
private Rigidbody rib;
[SerializeField] GameObject Lazer;
[SerializeField] GameObject LazerBoom;
[SerializeField] GameObject Gauche;
[SerializeField] GameObject Droit;
[SerializeField] GameObject Tete;
[SerializeField] float ForceTir;
private bool Shoot=true;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
GetComponent<AttackCAC>().changeCACouDistance(false);
AttackCAC.ATTACK += Attack;
}
void Attack()
{
if (Shoot)
{
Debug.Log("Attaque");
StartCoroutine(Lasers());
}
}
// Update is called once per frame
void Update()
{
/*
//à supprimer
if (Input.GetKeyDown(KeyCode.B))
{
if (Shoot)
{
Debug.Log("Attack !!");
StartCoroutine(Lasers());
}
}
if (Input.GetKeyDown(KeyCode.P))
{
Debug.Log("Explosion");
StartCoroutine(Special());
}
*/
}
//Tire des Lasers des yeux du pion vers la cible (Target). Donc rbg=RigidBodyGauche par exemple.
IEnumerator Lasers()
{
Shoot = false;
GameObject Target = GetComponent<AttackCAC>().GetTarget();
Vector3 Destination = Vector3.Normalize(Target.transform.position-transform.position);
GameObject LazGauche = Instantiate(Lazer, Gauche.transform.position, Gauche.transform.rotation);
Rigidbody rbg = LazGauche.GetComponent<Rigidbody>();
rbg.AddForce(Destination * ForceTir, ForceMode.Impulse);
GameObject LazDroite = Instantiate(Lazer, Droit.transform.position, Droit.transform.rotation);
Rigidbody rbd = LazDroite.GetComponent<Rigidbody>();
rbd.AddForce(Destination * ForceTir, ForceMode.Impulse);
yield return null;
Shoot = true;
}
//Génere une sphère qui se dirige vers sa cible (Target) pour faire une explosion
IEnumerator Special()
{
Shoot = false;
GameObject Target = GetComponent<AttackCAC>().GetTarget();
Vector3 Destination = Vector3.Normalize(Target.transform.position - transform.position);
//Vector3 Salse = new Vector3(0, -1, 0);
GameObject Laz = Instantiate(LazerBoom, Tete.transform.position, Tete.transform.rotation);
Rigidbody rb = Laz.GetComponent<Rigidbody>();
rb.AddForce(Destination * ForceTir, ForceMode.Impulse);
//rb.AddForce(Salse * ForceTir, ForceMode.Impulse);
yield return null;
Shoot = true;
}
//On tue le signal pour éviter tout problèmes (conseil de Game Jam)
void OnDestroy()
{
AttackCAC.ATTACK -= Attack;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 7c6232b4da47c4448b112c51f245a9f7

View file

@ -1,89 +0,0 @@
using System.Collections;
using UnityEngine;
public class ExplosifDuck : MonoBehaviour
{
private Rigidbody rib;
float Speed;
float Cooldown=10.0f;
[SerializeField] float explosionRadius;
[SerializeField] float explosionForce;
[SerializeField] float RangeExplosion;
private float upwardModifier = 0.0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
GetComponent<AttackCAC>().changeCACouDistance(true);
Speed = GetComponent<BaseDuckScript>().getSpeed();
AttackCAC.ATTACK += Attack;
}
void Attack()
{
Debug.Log("Attaque");
Explode();
}
// Update is called once per frame
void Update()
{
GameObject Target = GetComponent<AttackCAC>().GetTarget();
if (Target != null)
{
Vector3 RangeWeapon = Target.transform.position - transform.position;
if (RangeWeapon.magnitude < RangeExplosion)
{
Attack();
}
}
if (Input.GetKey(KeyCode.B))
{
StartCoroutine(Boost());
}
if (Input.GetKeyDown(KeyCode.P))
{
Debug.Log("Explosion");
Explode();
}
}
//Le speed est utilisé ici pour son spécial lui permettant de boost. On peut créer une fonction public dans BaseDuckScript getSpeed
//Et changeSpeed permettant de manipuler la Speed du duck. Vestige de l'ancien code qui ne mérite pas d'être supprimé actuellement
//C'est un cut content, donc ça passe
IEnumerator Boost()
{
Speed=12.0f;
yield return new WaitForSeconds(Cooldown);
Speed = 6.0f;
}
//Prend tout les rigidbody sauf le sien et leurs applique une force pour les expulser
void Explode()
{
rib = GetComponent<Rigidbody>();
Vector3 explosionPosition = transform.position;
Collider[] colliders = Physics.OverlapSphere(explosionPosition, explosionRadius);
foreach (Collider collider in colliders)
{
Rigidbody rb = collider.GetComponent<Rigidbody>();
if (rb != null & rb != rib)
{
rb.AddExplosionForce(explosionForce, explosionPosition, explosionRadius, upwardModifier, ForceMode.Impulse);
}
}
Destroy(this.gameObject);
}
//On tue le signal pour eviter tout problemes (conseil de Game Jam)
void OnDestroy()
{
AttackCAC.ATTACK -= Attack;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 3c634d25b1c457f42ade841848d6f3ff

View file

@ -1,82 +0,0 @@
using UnityEngine;
using System.Collections;
public class SniperDuck : MonoBehaviour
{
[SerializeField] private GameObject Bout;
[SerializeField] private GameObject Balle;
private float Cooldown;
[SerializeField] private float ForceTir;
private Rigidbody rib;
private bool Shoot = true;
Vector3 STAY;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
GetComponent<AttackCAC>().changeCACouDistance(false);
AttackCAC.ATTACK += Attack;
STAY=transform.position;
}
// Update is called once per frame
void Attack()
{
if(Shoot)
{
Debug.Log("Attaque");
StartCoroutine(Tir());
}
}
void Update()
{
transform.position = STAY;
rib = GetComponent<Rigidbody>();
//rib.linearVelocity = Vector3.zero;
/*
if (Input.GetKeyDown(KeyCode.R))
{
if (Shoot)
{
Debug.Log("Attaque");
StartCoroutine(Tir());
}
}
if (Input.GetKeyDown(KeyCode.P))
{
Debug.Log("Special");
StartCoroutine(Special());
}
*/
}
//Tir. La variable Shoot est le garde-fou pour <20>viter de tirer sans prendre en compte le cooldown
IEnumerator Tir()
{
Shoot = false;
GameObject BULLET = Instantiate(Balle, Bout.transform.position, Bout.transform.rotation);
BULLET.GetComponent<Lazer>().parent = this.gameObject;
BULLET.GetComponent<Lazer>().damage = GetComponent<AttackCAC>().GetDamage();
Rigidbody rb = BULLET.GetComponent<Rigidbody>();
rb.AddForce(transform.forward * ForceTir, ForceMode.Impulse);
yield return null;
Shoot = true;
}
//Le cooldown est utilisé ici pour son spécial lui permettant de mitrailler. On peut créer une fonction public dans BaseDuckScript getCooldown
//Et changeCooldown permettant de manipuler le cooldown du duck. Vestige de l'ancien code qui ne mérite pas d'être supprimé actuellement
//C'est un cut content, donc ça passe
IEnumerator Special()
{
float BackupCooldown = Cooldown;
Cooldown = 1.0f;
yield return new WaitForSeconds(5.0f);
Cooldown = BackupCooldown;
}
//On tue le signal pour eviter tout problemes (conseil de Game Jam)
void OnDestroy()
{
AttackCAC.ATTACK -= Attack;
}
}

View file

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

View file

@ -1,51 +0,0 @@
using UnityEngine;
using System.Collections;
public class TankDuck : MonoBehaviour
{
[SerializeField] private GameObject Bout;
[SerializeField] private GameObject Balle;
[SerializeField] private float ForceTir;
private bool Shoot = true;
private Rigidbody rib;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
GetComponent<AttackCAC>().changeCACouDistance(false);
AttackCAC.ATTACK += Attack;
}
// Update is called once per frame
void Update()
{
}
void Attack()
{
if (Shoot)
{
Debug.Log("Attaque");
StartCoroutine(Tir());
}
}
IEnumerator Tir()
{
Shoot = false;
GameObject BULLET = Instantiate(Balle, Bout.transform.position, Bout.transform.rotation);
Rigidbody rb = BULLET.GetComponent<Rigidbody>();
rb.AddForce(transform.forward * ForceTir, ForceMode.Impulse);
yield return null;
Shoot = true;
}
//On tue le signal pour eviter tout problemes (conseil de Game Jam)
void OnDestroy()
{
AttackCAC.ATTACK -= Attack;
}
}

View file

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

View file

@ -1,98 +0,0 @@
using System.Collections;
using UnityEngine;
public class TimeDuck: MonoBehaviour
{
private Rigidbody rib;
float Speed;
private float cooldown = 5.0f;
[SerializeField] float explosionRadius;
[SerializeField] float RangeExplosion;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
Speed = GetComponent<BaseDuckScript>().getSpeed();
GetComponent<AttackCAC>().changeCACouDistance(true);
AttackCAC.ATTACK += Attack;
}
void Attack()
{
Debug.Log("Attaque TIME");
StartCoroutine(Explode());
}
// Update is called once per frame
void Update()
{
//Prend sa cible et regarde sa distance pour voir quelle arme prendre contre lui
GameObject Target = GetComponent<AttackCAC>().GetTarget();
if (Target != null)
{
Vector3 RangeWeapon = Target.transform.position - transform.position;
if (RangeWeapon.magnitude < RangeExplosion)
{
Attack();
}
}
/*
//à supprimer
if (Input.GetKey(KeyCode.B))
{
StartCoroutine(Boost());
}
if (Input.GetKeyDown(KeyCode.P))
{
Debug.Log("Explosion");
StartCoroutine(Explode());
}
*/
}
//Le speed est utilisé ici pour son spécial lui permettant de boost. On peut créer une fonction public dans BaseDuckScript getSpeed
//Et changeSpeed permettant de manipuler la Speed du duck. Vestige de l'ancien code qui ne mérite pas d'être supprimé actuellement
//C'est un cut content, donc ça passe
IEnumerator Boost()
{
Speed = 12.0f;
yield return null;
Speed = 5.0f;
}
IEnumerator Explode()
{
rib = GetComponent<Rigidbody>();
Vector3 explosionPosition = transform.position;
Collider[] colliders = Physics.OverlapSphere(explosionPosition, explosionRadius);
foreach (Collider collider in colliders)
{
Rigidbody rb = collider.GetComponent<Rigidbody>();
if (LayerMask.LayerToName(collider.gameObject.layer)=="duck")
{
if (rb != null & rb != rib)
{
rb.isKinematic = true;
collider.GetComponent<AttackCAC>().enabled = false;
rb.linearVelocity = Vector3.zero;
yield return new WaitForSeconds(cooldown);
rb.isKinematic = false;
collider.GetComponent<AttackCAC>().enabled = true;
}
}
}
Destroy(this.gameObject);
}
//On tue le signal pour eviter tout problemes (conseil de Game Jam)
void OnDestroy()
{
AttackCAC.ATTACK -= Attack;
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 983a511a5a7517b478b8909da220e895