mirror of
https://github.com/ConjureETS/VZ.git
synced 2026-03-25 10:51:14 +00:00
- Added Squad script (not done)
- Updated Unit Hp property - Added functions - addHuman - AddSoldier - healSquad( unit humanUnit ) - abandonUnits( int nbUnits ) - removeHuman( Unit humanUnit ) - removeSoldier( Unit soldierUnit ) - transformHuman() (not done)
This commit is contained in:
parent
581334cbc6
commit
280fd57c2b
95
Assets/Scripts/Squad.cs
Normal file
95
Assets/Scripts/Squad.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
public class Squad : Unit
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// List of non attackable units.
|
||||||
|
/// </summary>
|
||||||
|
private List<Unit> humans;
|
||||||
|
/// <summary>
|
||||||
|
/// List of attackable units.
|
||||||
|
/// </summary>
|
||||||
|
private List<Unit> soldiers;
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
void Start ()
|
||||||
|
{
|
||||||
|
humans = new List<Unit>();
|
||||||
|
soldiers = new List<Unit>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update ()
|
||||||
|
{
|
||||||
|
// TODO execute movement command
|
||||||
|
// TODO Check if all the units are dead
|
||||||
|
// if yes destroy
|
||||||
|
if (soldiers.Count == 0)
|
||||||
|
{
|
||||||
|
// then we destroy the squad
|
||||||
|
DestroyUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addHuman(Unit humanUnit)
|
||||||
|
{
|
||||||
|
humans.Add(humanUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addSoldier(Unit soldierUnit)
|
||||||
|
{
|
||||||
|
soldiers.Add(soldierUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dispose of a human unit and heal all the soldiers with a percentage depending
|
||||||
|
/// of the number of remaining soldiers.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="humanUnit">The human to dispose</param>
|
||||||
|
void healSquad(Unit humanUnit )
|
||||||
|
{
|
||||||
|
|
||||||
|
var percentageOfHpToHeal = ( humanUnit.Hp / soldiers.Count );
|
||||||
|
|
||||||
|
foreach (var soldier in soldiers)
|
||||||
|
{
|
||||||
|
soldier.Hp += soldier.Hp * ( 1 + percentageOfHpToHeal );
|
||||||
|
}
|
||||||
|
|
||||||
|
// dispose of the human unit
|
||||||
|
removeHuman(humanUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Abandon a specified amount of units.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="nbUnits">The number of units to abandon</param>
|
||||||
|
void AbandonUnits(int nbUnits)
|
||||||
|
{
|
||||||
|
humans.RemoveRange(0,nbUnits);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove the selected soldier from the unit list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="soldierUnit">the corresponding soldier that we want to remove</param>
|
||||||
|
void removeSoldier(Unit soldierUnit)
|
||||||
|
{
|
||||||
|
soldiers.Remove(soldierUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove the selected human from the human list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="humanUnit">the corresponding human that we want to remove</param>
|
||||||
|
void removeHuman(Unit humanUnit)
|
||||||
|
{
|
||||||
|
humans.Remove(humanUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void transformHuman()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Scripts/Squad.cs.meta
Normal file
12
Assets/Scripts/Squad.cs.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 03db9d7aaef4ee545971f18bb90ceadb
|
||||||
|
timeCreated: 1439412250
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -9,17 +9,17 @@ public class Unit : MonoBehaviour
|
|||||||
private LinkedList<Command> commandList;
|
private LinkedList<Command> commandList;
|
||||||
public int defaultHp = 250;
|
public int defaultHp = 250;
|
||||||
public int defaultAttack = 100;
|
public int defaultAttack = 100;
|
||||||
|
private int _hp; // the unit hp
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start ()
|
void Start ()
|
||||||
{
|
{
|
||||||
// initialize default hp
|
// initialize default hp
|
||||||
//Hp = defaultHp;
|
Hp = defaultHp;
|
||||||
// initialize default attack
|
// initialize default attack
|
||||||
Attack = defaultAttack;
|
Attack = defaultAttack;
|
||||||
// initialize default team
|
// initialize default team
|
||||||
// initialize default specie
|
// initialize default specie
|
||||||
isDead = false;
|
IsDead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -41,17 +41,39 @@ public class Unit : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected void DestroyUnit()
|
protected void DestroyUnit()
|
||||||
{
|
{
|
||||||
|
//TODO First play dead animation
|
||||||
|
// then destroy the game object
|
||||||
Destroy(this.transform.gameObject);
|
Destroy(this.transform.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Unit properties
|
#region Unit properties
|
||||||
|
|
||||||
public int Hp { get; set; }
|
public int Hp
|
||||||
|
{
|
||||||
|
get { return _hp; }
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (Hp < 0)
|
||||||
|
{
|
||||||
|
_hp = 0;
|
||||||
|
IsDead = true;
|
||||||
|
}
|
||||||
|
else if (value > defaultHp)
|
||||||
|
{
|
||||||
|
_hp = defaultHp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_hp = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int Attack { get; set; }
|
public int Attack { get; set; }
|
||||||
//public bool isAlly { get; set; }
|
//public bool isAlly { get; set; }
|
||||||
//public bool isHuman { get; set; }
|
//public bool isHuman { get; set; }
|
||||||
public bool isDead { get; set; }
|
public bool IsDead { get; set; }
|
||||||
|
|
||||||
public String Tag
|
public String Tag
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,13 +17,13 @@ public class VampireUnit : Unit
|
|||||||
Attack = defaultAttack;
|
Attack = defaultAttack;
|
||||||
// initialize default team
|
// initialize default team
|
||||||
// initialize default specie
|
// initialize default specie
|
||||||
isDead = false;
|
IsDead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update ()
|
void Update ()
|
||||||
{
|
{
|
||||||
if (isDead)
|
if (IsDead)
|
||||||
{
|
{
|
||||||
// TODO play dead animation before destroying unit
|
// TODO play dead animation before destroying unit
|
||||||
DestroyUnit();
|
DestroyUnit();
|
||||||
@ -58,17 +58,10 @@ public class VampireUnit : Unit
|
|||||||
void AttackEnemy(Unit unit)
|
void AttackEnemy(Unit unit)
|
||||||
{
|
{
|
||||||
//TODO improve this method to compute the reduce of hp, etc...
|
//TODO improve this method to compute the reduce of hp, etc...
|
||||||
if (unit.Hp <= 0)
|
// compute the amount of hp reduced to this unit
|
||||||
{
|
unit.Hp -= Attack; // we remove some hp of the unit that was
|
||||||
unit.isDead = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// compute the amount of hp reduced to this unit
|
|
||||||
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)
|
||||||
|
|||||||
@ -17,13 +17,13 @@ public class ZombieUnit : Unit
|
|||||||
Attack = defaultAttack;
|
Attack = defaultAttack;
|
||||||
// initialize default team
|
// initialize default team
|
||||||
// initialize default specie
|
// initialize default specie
|
||||||
isDead = false;
|
IsDead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (isDead)
|
if (IsDead)
|
||||||
{
|
{
|
||||||
// TODO play dead animation before destroying unit
|
// TODO play dead animation before destroying unit
|
||||||
DestroyUnit();
|
DestroyUnit();
|
||||||
@ -56,17 +56,11 @@ public class ZombieUnit : Unit
|
|||||||
}
|
}
|
||||||
void AttackEnemy(Unit unit)
|
void AttackEnemy(Unit unit)
|
||||||
{
|
{
|
||||||
if (unit.Hp <= 0)
|
|
||||||
{
|
// compute the amount of hp reduced to this unit
|
||||||
unit.isDead = true;
|
unit.Hp -= Attack; // we remove some hp of the unit that was
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// compute the amount of hp reduced to this unit
|
|
||||||
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user