public void SeesEnemy(HumanoidModel enemy, Vector3 location) { /* * first remove the nearest enemy marker that is in range * if seeing enemy for the first time */ EnemyTarget target = null; viewableEnemies.TryGetValue(enemy, out target); if (target == null) { foreach (CommunicatableEnemyMarker marker in hiddenEnemies) { if (Vector3.Distance(location, marker.GetEnemyMarker().GetLocation()) < hiddenEnemyRadius) { marker.Invalidate(); HumanoidTargeterCommunication.Communicate( new CommunicationPackage( GetDeepCopyOfHiddenEnemies(), this ) ); RemoveHiddenEnemy(marker); break; } } } // next add viewable enemy viewableEnemies[enemy] = new EnemyTarget(enemy, location); }
public void DoesNotSeeEnemy(HumanoidModel enemy) { EnemyTarget enemyTarget; viewableEnemies.TryGetValue(enemy, out enemyTarget); if (enemyTarget != null) { viewableEnemies.Remove(enemy); EnemyMarker newMarker = new EnemyMarker(enemyTarget, this); CommunicatableEnemyMarker newCMarker = new CommunicatableEnemyMarker( newMarker, checkHiddenEnemyRadius ); // avoid clustering enemy markers in one spot if (NoMarkerTooCloseTo(newCMarker)) { AddHiddenEnemy(newCMarker); HumanoidTargeterCommunication.Communicate( new CommunicationPackage( GetDeepCopyOfHiddenEnemies(), this ) ); } } }
/* * Communicator must be in hiddenEnemies */ public void InvalidateMarker(CommunicatableEnemyMarker communicator) { communicator.Invalidate(); HumanoidTargeterCommunication.Communicate( new CommunicationPackage( GetDeepCopyOfHiddenEnemies(), this ) ); RemoveHiddenEnemy(communicator); }
public void RecieveCommunication(CommunicationPackage package) { //Debug.Log("Sent by: " + package.GetIssuer().gameObject.name + " to " + this.gameObject.name + " for package " + package.id); HashSet <CommunicatableEnemyMarker> markerPayload = package.GetPayload(); foreach (CommunicatableEnemyMarker marker in markerPayload) { if (marker.IsValid()) { if (NoMarkerTooCloseTo(marker)) { AddHiddenEnemy(marker.GetNewMarker()); } } else { RemoveHiddenEnemy(marker); } } HumanoidTargeterCommunication.Communicate(package.RecievedBy(this)); }
// Use this for initialization void Start() { HumanoidTargeterCommunication.AddBlackBoardSubscriber(this); }
public void InterruptCommunication() { HumanoidTargeterCommunication.InterruptUpdate(this); }
// Use this for initialization private void Awake() { targeters = new HashSet <HumanoidTargeter>(); communicators = new List <Communicator>(); instance = this; }