From d5e2c9ae1bf0ebb15a46499c789b03b64d6529d4 Mon Sep 17 00:00:00 2001 From: Maciekxdabu <40292375+Maciekxdabu@users.noreply.github.com> Date: Fri, 3 Jun 2022 13:53:29 +0200 Subject: [PATCH] merloj: finished basic communication - rough, working design for now, needs to be polished --- theProject/Assets/Prefabs/Soldier.prefab | 3 ++- .../Assets/Scripts/Entities/Communication.cs | 15 ++++++++++----- theProject/Assets/Scripts/Entities/Soldier.cs | 6 ++++++ theProject/Assets/Scripts/Squad.cs | 5 +++++ theProject/Assets/Scripts/TickSystem/TTLList.cs | 7 +++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/theProject/Assets/Prefabs/Soldier.prefab b/theProject/Assets/Prefabs/Soldier.prefab index 8fe69179..b9eeccee 100644 --- a/theProject/Assets/Prefabs/Soldier.prefab +++ b/theProject/Assets/Prefabs/Soldier.prefab @@ -75,9 +75,10 @@ MonoBehaviour: m_Calls: [] tileCoord: {x: 0, y: 0} WORLD_SPACE_OFFSET: {x: 0.5, y: 0.5, z: 0.5} + MySquad: {fileID: 0} rangeAttack: 3 rangeView: 1 - damageAttack: 25 + damageAttack: 0 speedAttack: 2 lastAttackTick: -1 target: {fileID: 0} diff --git a/theProject/Assets/Scripts/Entities/Communication.cs b/theProject/Assets/Scripts/Entities/Communication.cs index 5bbf6a37..ce797283 100644 --- a/theProject/Assets/Scripts/Entities/Communication.cs +++ b/theProject/Assets/Scripts/Entities/Communication.cs @@ -45,12 +45,17 @@ public class Communication : MonoBehaviour break; } } - Debug.Log(result.resetTTL); // look fo enemies (enemyTeam) - add Enemies to enemiesSpotted (send List) if (result.resetTTL)//only check for enemies if you can see your squad { - + foreach (Soldier sold in soldiersFound) + { + if (sold.GetOwnTeam() != myTeam) + { + result.enemiesSpotted.Add(sold); + } + } } return result; @@ -73,10 +78,10 @@ public class Communication : MonoBehaviour Vector2Int curTile = new Vector2Int(i, j); if ( (curTile - curPos).sqrMagnitude <= rangeSQR && curTile != curPos)//is current Tile in a circular range (and not our tile) { - Soldier newSoldier = (Soldier)TilemapManager.GetSoldierS(i, j); + Entity newSoldier = TilemapManager.GetSoldierS(i, j); - if (newSoldier != null) - soldiersFound.Add(newSoldier); + if (newSoldier != null && newSoldier.GetType() != typeof(Base)) + soldiersFound.Add((Soldier)newSoldier); } } } diff --git a/theProject/Assets/Scripts/Entities/Soldier.cs b/theProject/Assets/Scripts/Entities/Soldier.cs index d026932c..8d7cd6ba 100644 --- a/theProject/Assets/Scripts/Entities/Soldier.cs +++ b/theProject/Assets/Scripts/Entities/Soldier.cs @@ -105,7 +105,13 @@ public class Soldier : Entity if (cResult.resetTTL) { + //reset TTL + MySquad.AddSoldierToSquad(this); + foreach (Soldier sold in cResult.enemiesSpotted) + { + MySquad.AddSpottedEnemy(sold); + } } ref Queue queueToHandle = ref interrupts; diff --git a/theProject/Assets/Scripts/Squad.cs b/theProject/Assets/Scripts/Squad.cs index 2c6b155c..98c1f0f1 100644 --- a/theProject/Assets/Scripts/Squad.cs +++ b/theProject/Assets/Scripts/Squad.cs @@ -65,6 +65,11 @@ public class Squad : MonoBehaviour soldier.OnDeath.RemoveListener(RemoveSoldierFromSquad); } + public void AddSpottedEnemy(Entity enemy) + { + enemiesSpotted.AddToList(enemy); + } + private void Awake() { TickSystem.OnTick += HandleTick; diff --git a/theProject/Assets/Scripts/TickSystem/TTLList.cs b/theProject/Assets/Scripts/TickSystem/TTLList.cs index 5dce16a7..20b82ad8 100644 --- a/theProject/Assets/Scripts/TickSystem/TTLList.cs +++ b/theProject/Assets/Scripts/TickSystem/TTLList.cs @@ -21,8 +21,11 @@ public class TTLList where T : UnityEngine.Object public void AddToList(T obj) { Debug.Log(obj); - dict.Add(obj, basicTTL); - Debug.Log("Added object to dictionary", obj); + if (dict.ContainsKey(obj)) + dict[obj] = basicTTL; + else + dict.Add(obj, basicTTL); + Debug.Log("Added/Changed object in dictionary", obj); UpdateViewList(); }