mirror of
https://github.com/ConjureETS/VZ.git
synced 2026-03-24 02:11:15 +00:00
- Upgraded Squad, ZombieSquad, VampireSquad
- Refactored the class ZombieUnit, VampireUnit now are renamed to ZombieSquad and VampireSquad
This commit is contained in:
parent
bc759b6ad9
commit
dc19a98560
@ -16,7 +16,7 @@ public class Squad : Unit
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of attackable units.
|
/// List of attackable units.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Unit> soldiers;
|
private List<Squad> soldiers;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of abandonned units. (this list is accessible for both teams)
|
/// List of abandonned units. (this list is accessible for both teams)
|
||||||
@ -31,16 +31,15 @@ public class Squad : Unit
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The tag to assign for each soldiers in the squad
|
/// The tag to assign for each soldiers in the squad
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public String squadTag;
|
protected String squadTag;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start ()
|
void Awake ()
|
||||||
{
|
{
|
||||||
InitializeSquadTag();
|
|
||||||
humans = new List<Unit>();
|
humans = new List<Unit>();
|
||||||
soldiers = new List<Unit>();
|
soldiers = new List<Squad>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
@ -49,24 +48,22 @@ public class Squad : Unit
|
|||||||
// TODO execute movement command
|
// TODO execute movement command
|
||||||
// TODO Check if all the units are dead
|
// TODO Check if all the units are dead
|
||||||
// if yes destroy
|
// if yes destroy
|
||||||
if (soldiers.Count == 0)
|
if (soldiers.Count != 0) return;
|
||||||
{
|
// first release all humans ...
|
||||||
// first release all humans ...
|
AbandonUnits(humans.Count);
|
||||||
AbandonUnits(humans.Count);
|
// then we destroy the squad
|
||||||
// then we destroy the squad
|
DestroyUnit();
|
||||||
DestroyUnit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region squad related functions
|
#region squad related functions
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Assign the corresponding squad tag to each soldiers.
|
/// Assign the corresponding squad tag to each soldiers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeSquadTag()
|
protected void InitializeSquad()
|
||||||
{
|
{
|
||||||
foreach (var soldier in soldiers)
|
if (soldiers.Count == 0)
|
||||||
{
|
{
|
||||||
soldier.Tag = squadTag;
|
this.soldiers.Add(this.gameObject.GetComponent<Squad>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +80,7 @@ public class Squad : Unit
|
|||||||
/// Add the human unit in the abandonned unit list.
|
/// Add the human unit in the abandonned unit list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="soldierUnit">the soldier unit to add in the soldier unit list</param>
|
/// <param name="soldierUnit">the soldier unit to add in the soldier unit list</param>
|
||||||
void AddSoldier(Unit soldierUnit)
|
void AddSoldier(Squad soldierUnit)
|
||||||
{
|
{
|
||||||
soldiers.Add(soldierUnit);
|
soldiers.Add(soldierUnit);
|
||||||
}
|
}
|
||||||
@ -153,7 +150,7 @@ public class Squad : Unit
|
|||||||
/// Remove the selected soldier from the unit list.
|
/// Remove the selected soldier from the unit list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="soldierUnit">the corresponding soldier that we want to remove</param>
|
/// <param name="soldierUnit">the corresponding soldier that we want to remove</param>
|
||||||
void RemoveSoldier(Unit soldierUnit)
|
void RemoveSoldier(Squad soldierUnit)
|
||||||
{
|
{
|
||||||
soldiers.Remove(soldierUnit);
|
soldiers.Remove(soldierUnit);
|
||||||
}
|
}
|
||||||
@ -182,17 +179,20 @@ public class Squad : Unit
|
|||||||
|
|
||||||
// remove the human from the human list
|
// remove the human from the human list
|
||||||
RemoveHuman(humanUnit);
|
RemoveHuman(humanUnit);
|
||||||
|
|
||||||
// AddSoldier((VampireUnit) humanUnit) ) (VampireUnit or ZombieUnit)
|
// set the human tag to the same as the squad
|
||||||
|
humanUnit.Tag = Tag;
|
||||||
|
|
||||||
|
// AddSoldier((VampireSquad) humanUnit) ) (VampireSquad or ZombieSquad)
|
||||||
if (squadTag.Equals(TagManager.VampirePlayer))
|
if (squadTag.Equals(TagManager.VampirePlayer))
|
||||||
{
|
{
|
||||||
// add the vampire to the soldier list
|
// add the vampire to the soldier list
|
||||||
AddSoldier((VampireUnit) humanUnit);
|
AddSoldier((VampireSquad) humanUnit);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// add the zombie to the soldier list
|
// add the zombie to the soldier list
|
||||||
AddSoldier((ZombieUnit)humanUnit);
|
AddSoldier((ZombieSquad)humanUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,6 +212,8 @@ public class Squad : Unit
|
|||||||
// and then dead soldier is removed in the soldier list
|
// and then dead soldier is removed in the soldier list
|
||||||
var topSoldier = soldiers.ElementAt(0);
|
var topSoldier = soldiers.ElementAt(0);
|
||||||
topSoldier.Hp -= amountOfDamage;
|
topSoldier.Hp -= amountOfDamage;
|
||||||
|
|
||||||
|
Debug.Log(string.Format("{0} received {1} damage!",topSoldier.name, amountOfDamage));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaptureHuman(Unit unit)
|
void CaptureHuman(Unit unit)
|
||||||
@ -220,28 +222,15 @@ public class Squad : Unit
|
|||||||
Debug.Log("Entered in collision with: " + unit.Tag);
|
Debug.Log("Entered in collision with: " + unit.Tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttackEnemy(Unit targetedUnit)
|
protected void AttackEnemySquad(Squad targettedEnemySquad)
|
||||||
{
|
{
|
||||||
//TODO improve this method add the total of squad damage or to compute the reduce of hp, etc...
|
//TODO improve this method add the total of squad damage or to compute the reduce of hp, etc...
|
||||||
// compute the amount of hp reduced to this unit
|
// compute the amount of hp reduced to this unit
|
||||||
//unit.Hp -= Attack; // we remove some hp of the unit that was
|
//unit.Hp -= Attack; // we remove some hp of the unit that was
|
||||||
var amountOfDamageToApply = ComputeAttackDamage();
|
var amountOfDamageToApply = ComputeAttackDamage();
|
||||||
|
targettedEnemySquad.ReceiveDamage(amountOfDamageToApply);
|
||||||
|
|
||||||
var squad = targetedUnit as Squad;
|
Debug.Log("Attacked the ennemy : " + targettedEnemySquad.Tag);
|
||||||
|
|
||||||
if (squad != null)
|
|
||||||
{
|
|
||||||
// cast the unit to a squad
|
|
||||||
var squadTargetedUnit = squad;
|
|
||||||
// apply the damage to the squad
|
|
||||||
squadTargetedUnit.ReceiveDamage(amountOfDamageToApply);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO update the attack ennemy in Vampire Unit and Zombie Unit class
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.Log("Attacked the ennemy : " + targetedUnit.Tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComputeAttackDamage()
|
int ComputeAttackDamage()
|
||||||
@ -264,5 +253,9 @@ public class Squad : Unit
|
|||||||
return abandonnedUnits;
|
return abandonnedUnits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int NumberOfSoldiers()
|
||||||
|
{
|
||||||
|
return soldiers.Count();
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,13 @@ using System.Collections;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class contains the information of the Vampire Units.
|
/// This class contains the information of the Vampire Units.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class VampireUnit : Squad
|
public class VampireSquad : Squad
|
||||||
{
|
{
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
|
|
||||||
void Start ()
|
void Start ()
|
||||||
{
|
{
|
||||||
|
InitializeSquad();
|
||||||
InitializeDefaultTag();
|
InitializeDefaultTag();
|
||||||
// initialize default hp
|
// initialize default hp
|
||||||
//Hp = defaultHp;
|
//Hp = defaultHp;
|
||||||
@ -51,18 +52,18 @@ public class VampireUnit : Squad
|
|||||||
void CaptureHuman(Unit unit)
|
void CaptureHuman(Unit unit)
|
||||||
{
|
{
|
||||||
// TODO either add the human as a squad member or change it's tag to vampireHuman
|
// TODO either add the human as a squad member or change it's tag to vampireHuman
|
||||||
// when the player is transformed we just make VampireUnit vampireUnit2 = (VampireUnit) unit;
|
// when the player is transformed we just make VampireSquad vampireUnit2 = (VampireSquad) unit;
|
||||||
Debug.Log("Entered in collision with: " + unit.Tag );
|
Debug.Log("Entered in collision with: " + unit.Tag );
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttackEnemy(Unit unit)
|
/* void AttackEnemySquad(Unit unit)
|
||||||
{
|
{
|
||||||
//TODO improve this method to compute the reduce of hp, etc...
|
//TODO improve this method to compute the reduce of hp, etc...
|
||||||
// compute the amount of hp reduced to this unit
|
// compute the amount of hp reduced to this unit
|
||||||
unit.Hp -= Attack; // we remove some hp of the unit that was
|
unit.Hp -= Attack; // we remove some hp of the unit that was
|
||||||
|
|
||||||
Debug.Log("Attacked the ennemy : " + unit.Tag);
|
Debug.Log("Attacked the ennemy : " + unit.Tag);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void OnTriggerEnter(Collider collider)
|
void OnTriggerEnter(Collider collider)
|
||||||
{
|
{
|
||||||
@ -71,20 +72,28 @@ public class VampireUnit : Squad
|
|||||||
//switch(objectTag.GetType())
|
//switch(objectTag.GetType())
|
||||||
var unitComponent = collider.GetComponent<Unit>();
|
var unitComponent = collider.GetComponent<Unit>();
|
||||||
|
|
||||||
if (unitComponent != null)
|
if (unitComponent == null)
|
||||||
|
return;
|
||||||
|
// check if the unit is not a friendly one
|
||||||
|
if (this.Tag == unitComponent.Tag)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (unitComponent.Tag.Equals(TagManager.Human))
|
||||||
{
|
{
|
||||||
// check if the unit is not a friendly one
|
CaptureHuman(unitComponent);
|
||||||
if (this.Tag != unitComponent.Tag)
|
}
|
||||||
|
else // we know that it's an ennemy
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (unitComponent.Tag.Equals(TagManager.Human))
|
AttackEnemySquad(unitComponent as Squad);
|
||||||
{
|
|
||||||
CaptureHuman(unitComponent);
|
|
||||||
}
|
|
||||||
else // we know that it's an ennemy
|
|
||||||
{
|
|
||||||
AttackEnemy(unitComponent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (InvalidCastException exception)
|
||||||
|
{
|
||||||
|
Debug.LogError(exception.ToString());
|
||||||
|
//throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,12 +4,13 @@ using System.Collections;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class contains the information of the Vampire Units.
|
/// This class contains the information of the Vampire Units.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ZombieUnit : Squad
|
public class ZombieSquad : Squad
|
||||||
{
|
{
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
InitializeSquad();
|
||||||
InitializeDefaultTag();
|
InitializeDefaultTag();
|
||||||
// initialize default hp
|
// initialize default hp
|
||||||
//Hp = defaultHp;
|
//Hp = defaultHp;
|
||||||
@ -51,17 +52,17 @@ public class ZombieUnit : Squad
|
|||||||
void CaptureHuman(Unit unit)
|
void CaptureHuman(Unit unit)
|
||||||
{
|
{
|
||||||
// TODO either add the human as a squad member or change it's tag to vampireHuman
|
// TODO either add the human as a squad member or change it's tag to vampireHuman
|
||||||
// when the player is transformed we just make VampireUnit vampireUnit2 = (VampireUnit) unit;
|
// when the player is transformed we just make VampireSquad vampireUnit2 = (VampireSquad) unit;
|
||||||
Debug.Log("Entered in collision with: " + unit.Tag);
|
Debug.Log("Entered in collision with: " + unit.Tag);
|
||||||
}
|
}
|
||||||
void AttackEnemy(Unit unit)
|
/*void AttackEnemySquad(Unit unit)
|
||||||
{
|
{
|
||||||
|
|
||||||
// compute the amount of hp reduced to this unit
|
// compute the amount of hp reduced to this unit
|
||||||
unit.Hp -= Attack; // we remove some hp of the unit that was
|
unit.Hp -= Attack; // we remove some hp of the unit that was
|
||||||
|
|
||||||
Debug.Log("Attacked the ennemy : " + unit.Tag);
|
Debug.Log("Attacked the ennemy : " + unit.Tag);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void OnTriggerEnter(Collider collider)
|
void OnTriggerEnter(Collider collider)
|
||||||
{
|
{
|
||||||
@ -70,20 +71,28 @@ public class ZombieUnit : Squad
|
|||||||
//switch(objectTag.GetType())
|
//switch(objectTag.GetType())
|
||||||
var unitComponent = collider.GetComponent<Unit>();
|
var unitComponent = collider.GetComponent<Unit>();
|
||||||
|
|
||||||
if (unitComponent != null)
|
if (unitComponent == null)
|
||||||
|
return;
|
||||||
|
// check if the unit is not a friendly one
|
||||||
|
if (this.Tag == unitComponent.Tag)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (unitComponent.Tag.Equals(TagManager.Human))
|
||||||
{
|
{
|
||||||
// check if the unit is not a friendly one
|
CaptureHuman(unitComponent);
|
||||||
if (this.Tag != unitComponent.Tag)
|
}
|
||||||
|
else // we know that it's an ennemy
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (unitComponent.Tag.Equals(TagManager.Human))
|
AttackEnemySquad(unitComponent as Squad);
|
||||||
{
|
|
||||||
CaptureHuman(unitComponent);
|
|
||||||
}
|
|
||||||
else // we know that it's an ennemy
|
|
||||||
{
|
|
||||||
AttackEnemy(unitComponent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (InvalidCastException exception)
|
||||||
|
{
|
||||||
|
Debug.LogError(exception.ToString());
|
||||||
|
//throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user