diff --git a/Assets/Prefabs/Vampire.prefab b/Assets/Prefabs/Vampire.prefab index f556d73..2fbad74 100644 --- a/Assets/Prefabs/Vampire.prefab +++ b/Assets/Prefabs/Vampire.prefab @@ -29,7 +29,7 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 159974} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 5, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -140,7 +140,11 @@ Prefab: serializedVersion: 2 m_Modification: m_TransformParent: {fileID: 0} - m_Modifications: [] + m_Modifications: + - target: {fileID: 0} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 0} m_RootGameObject: {fileID: 159974} diff --git a/Assets/Prefabs/Zombie.prefab b/Assets/Prefabs/Zombie.prefab index 3ec996d..03c12ff 100644 --- a/Assets/Prefabs/Zombie.prefab +++ b/Assets/Prefabs/Zombie.prefab @@ -29,7 +29,7 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 196328} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 5, z: 41.8800011} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -140,7 +140,15 @@ Prefab: serializedVersion: 2 m_Modification: m_TransformParent: {fileID: 0} - m_Modifications: [] + m_Modifications: + - target: {fileID: 0} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 0} m_RootGameObject: {fileID: 196328} diff --git a/Assets/Scenes/sam_squad.unity b/Assets/Scenes/sam_squad.unity index a5f8a9b..9b7aa45 100644 --- a/Assets/Scenes/sam_squad.unity +++ b/Assets/Scenes/sam_squad.unity @@ -87,6 +87,78 @@ NavMeshSettings: cellSize: .166666672 manualCellSize: 0 m_NavMeshData: {fileID: 0} +--- !u!1001 &151831733 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalPosition.x + value: 15 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalPosition.y + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_RootOrder + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 159974, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_Name + value: Human + objectReference: {fileID: 0} + - target: {fileID: 159974, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_TagString + value: Human + objectReference: {fileID: 0} + - target: {fileID: 2386094, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_Materials.Array.data[0] + value: + objectReference: {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_RemovedComponents: + - {fileID: 11449880, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + m_ParentPrefab: {fileID: 100100000, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + m_IsPrefabParent: 0 +--- !u!1 &151831734 stripped +GameObject: + m_PrefabParentObject: {fileID: 159974, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + m_PrefabInternal: {fileID: 151831733} +--- !u!114 &151831735 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 151831734} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8a1ccd1ad32d6bc4fb600c5b5720e01c, type: 3} + m_Name: + m_EditorClassIdentifier: + defaultHp: 250 + defaultAttack: 100 --- !u!1 &272569008 GameObject: m_ObjectHideFlags: 0 @@ -171,7 +243,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 + m_RootOrder: 1 --- !u!1 &550371263 GameObject: m_ObjectHideFlags: 0 @@ -231,7 +303,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 + m_RootOrder: 2 --- !u!1001 &1196959011 Prefab: m_ObjectHideFlags: 0 @@ -249,7 +321,7 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 417792, guid: 8d6d640df84c10549b99d9ccf6b349d9, type: 2} propertyPath: m_LocalPosition.z - value: 41.8800011 + value: 40.7999992 objectReference: {fileID: 0} - target: {fileID: 417792, guid: 8d6d640df84c10549b99d9ccf6b349d9, type: 2} propertyPath: m_LocalRotation.x @@ -269,7 +341,7 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 417792, guid: 8d6d640df84c10549b99d9ccf6b349d9, type: 2} propertyPath: m_RootOrder - value: 4 + value: 5 objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 8d6d640df84c10549b99d9ccf6b349d9, type: 2} @@ -311,7 +383,11 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} propertyPath: m_RootOrder - value: 3 + value: 4 + objectReference: {fileID: 0} + - target: {fileID: 11449880, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: defaultHp + value: 10050 objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} @@ -385,7 +461,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 3 --- !u!1 &1740025638 GameObject: m_ObjectHideFlags: 0 @@ -397,7 +473,6 @@ GameObject: - 33: {fileID: 1740025642} - 65: {fileID: 1740025641} - 23: {fileID: 1740025640} - - 114: {fileID: 1740025639} m_Layer: 0 m_Name: Cube m_TagString: Untagged @@ -405,19 +480,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 0 ---- !u!114 &1740025639 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1740025638} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 03db9d7aaef4ee545971f18bb90ceadb, type: 3} - m_Name: - m_EditorClassIdentifier: - defaultHp: 250 - defaultAttack: 100 --- !u!23 &1740025640 MeshRenderer: m_ObjectHideFlags: 0 @@ -472,4 +534,4 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 5 + m_RootOrder: 6 diff --git a/Assets/Scripts/Squad.cs b/Assets/Scripts/Squad.cs index 8c29d28..fbc7468 100644 --- a/Assets/Scripts/Squad.cs +++ b/Assets/Scripts/Squad.cs @@ -11,12 +11,12 @@ public class Squad : Unit /// /// List of non attackable units. /// - private List humans; + private List _humans; /// /// List of attackable units. /// - private List soldiers; + private List _soldiers; /// /// List of abandonned units. (this list is accessible for both teams) @@ -26,20 +26,20 @@ public class Squad : Unit /// /// Index of the first soldier in the list. /// - private int targetSoldierIndex; + private int squadLeaderPosition; /// /// The tag to assign for each soldiers in the squad /// - protected String squadTag; + //protected String SquadTag; #endregion // Use this for initialization void Awake () { - humans = new List(); - soldiers = new List(); + _humans = new List(); + _soldiers = new List(); } // Update is called once per frame @@ -48,9 +48,9 @@ public class Squad : Unit // TODO execute movement command // TODO Check if all the units are dead // if yes destroy - if (soldiers.Count != 0) return; + if (_soldiers.Count != 0) return; // first release all humans ... - AbandonUnits(humans.Count); + AbandonUnits(_humans.Count); // then we destroy the squad DestroyUnit(); } @@ -61,9 +61,9 @@ public class Squad : Unit /// protected void InitializeSquad() { - if (soldiers.Count == 0) + if (_soldiers.Count == 0) { - this.soldiers.Add(this.gameObject.GetComponent()); + this._soldiers.Add(this.gameObject.GetComponent()); } } @@ -73,7 +73,7 @@ public class Squad : Unit /// the human unit to add in the human unit list void AddHuman(Unit humanUnit) { - humans.Add(humanUnit); + _humans.Add(humanUnit); } /// @@ -82,7 +82,7 @@ public class Squad : Unit /// the soldier unit to add in the soldier unit list void AddSoldier(Squad soldierUnit) { - soldiers.Add(soldierUnit); + _soldiers.Add(soldierUnit); } /// @@ -111,9 +111,9 @@ public class Squad : Unit public void HealSquad(Unit humanUnit) { - var percentageOfHpToHeal = ( humanUnit.Hp / soldiers.Count ); + var percentageOfHpToHeal = ( humanUnit.Hp / _soldiers.Count ); - foreach (var soldier in soldiers) + foreach (var soldier in _soldiers) { soldier.Hp += soldier.Hp * ( 1 + percentageOfHpToHeal ); } @@ -128,12 +128,12 @@ public class Squad : Unit /// The number of units to abandon public void AbandonUnits(int nbUnits) { - if (nbUnits <= humans.Count) + if (nbUnits <= _humans.Count) { for (var i = 0; i < nbUnits; i++) { // retreive the human at the specified index - var humanUnit = humans.ElementAt(i); + var humanUnit = _humans.ElementAt(i); // add the human to the abandonned Unit list AddAbandonnedHuman(humanUnit); // remove the human from the humandUnit that was added to the abandonned unit list @@ -152,7 +152,7 @@ public class Squad : Unit /// the corresponding soldier that we want to remove void RemoveSoldier(Squad soldierUnit) { - soldiers.Remove(soldierUnit); + _soldiers.Remove(soldierUnit); } /// @@ -161,7 +161,7 @@ public class Squad : Unit /// the corresponding human that we want to remove void RemoveHuman(Unit humanUnit) { - humans.Remove(humanUnit); + _humans.Remove(humanUnit); } /// @@ -170,12 +170,12 @@ public class Squad : Unit /// the number of humans to transform public void TransformHuman(int nbHumans) { - if (nbHumans <= humans.Count) + if (nbHumans <= _humans.Count) { for (var i = 0; i < nbHumans; i++) { // retreive the human at the specified index - var humanUnit = humans.ElementAt(i); + var humanUnit = _humans.ElementAt(i); // remove the human from the human list RemoveHuman(humanUnit); @@ -184,7 +184,7 @@ public class Squad : Unit humanUnit.Tag = Tag; // AddSoldier((VampireSquad) humanUnit) ) (VampireSquad or ZombieSquad) - if (squadTag.Equals(TagManager.VampirePlayer)) + if (Tag.Equals(TagManager.VampirePlayer)) { // add the vampire to the soldier list AddSoldier((VampireSquad) humanUnit); @@ -206,14 +206,11 @@ public class Squad : Unit public void ReceiveDamage(int amountOfDamage) { // apply the damage to the first soldier in the list - // update the soldier hp - // if the soldier hp reach zero - // the soldier is destroyed - // and then dead soldier is removed in the soldier list - var topSoldier = soldiers.ElementAt(0); - topSoldier.Hp -= amountOfDamage; - - Debug.Log(string.Format("{0} received {1} damage!",topSoldier.name, amountOfDamage)); + foreach (var soldier in _soldiers) + { + soldier.Hp -= amountOfDamage; + Debug.Log(string.Format("{0} received {1} damage!", soldier.name, amountOfDamage)); + } } void CaptureHuman(Unit unit) @@ -233,10 +230,16 @@ public class Squad : Unit Debug.Log("Attacked the ennemy : " + targettedEnemySquad.Tag); } + /// + /// Compute to attack damage depending of the numbers of soldiers in the squad. + /// + /// the damage to apply to each enemy soldiers units int ComputeAttackDamage() { - // TODO improve the damage algorithm depending of the number of units in the soldiers list. - return Attack; + // LINQ + Resharper FTW!!!!! + var sumOfAttack = _soldiers.Sum(soldier => soldier.Attack); + + return ( 1 + (sumOfAttack / _soldiers.Count)); } #endregion @@ -253,9 +256,5 @@ public class Squad : Unit return abandonnedUnits; } - public int NumberOfSoldiers() - { - return soldiers.Count(); - } #endregion }