public EnemyMarker(HumanoidModel target, Vector3 location, HumanoidTargeter founder) { this.location = location; this.target = target; usedBy = new HashSet <HumanoidTargeter>(); enemyVantage = target.InfoGetVantageData(); enemyVantage.SetLocation(location); }
private static IEnumerator CreateCommunicatorCoroutine(float timeToCommunicate, HumanoidTargeter reciever, CommunicationPackage package) { yield return(new WaitForSeconds(timeToCommunicate)); reciever.RecieveCommunication(package); }
public CommunicationPackage(HashSet <CommunicatableEnemyMarker> payload, HumanoidTargeter origin) { this.payload = new HashSet <CommunicatableEnemyMarker>(payload); issuer = origin; alreadyCommunicated = new HashSet <HumanoidTargeter>(); alreadyCommunicated.Add(origin); id = counter; counter++; }
public static void InterruptUpdate(HumanoidTargeter whoToInterrupt) { instance.communicators.ForEach(c => { if (c.issuer == whoToInterrupt) { c.coroutines.ForEach(co => instance.StopCoroutine(co)); instance.communicators.Remove(c); } }); }
private void Awake() { targeters = new List <HumanoidTargeter>(); foreach (Transform enemy in targeterObject.transform) { HumanoidTargeter targeter = enemy.GetComponent <HumanoidTargeter>(); if (targeter != null) { targeters.Add(targeter); } } }
public CommunicationPackage RecievedBy(HumanoidTargeter newIssuer) { CommunicationPackage newPackage = new CommunicationPackage( new HashSet <CommunicatableEnemyMarker>(this.payload), newIssuer ); // Debug.Log("Inside RecievedBy of issuer " + newIssuer.gameObject.name + " " + newPackage.GetPayload().Count); newPackage.alreadyCommunicated = new HashSet <HumanoidTargeter>( this.alreadyCommunicated ); newPackage.alreadyCommunicated.Add(newIssuer); return(newPackage); }
public bool IsUsedBy(HumanoidTargeter targeter) { return(usedBy.Contains(targeter)); }
public void RemoveUser(HumanoidTargeter targeter) { usedBy.Remove(targeter); }
public void AddUser(HumanoidTargeter targeter) { usedBy.Add(targeter); }
public EnemyMarker(EnemyTarget target, HumanoidTargeter founder) : this(target.GetEnemy(), target.GetLocation(), founder) { }
public bool CanCommunicate(HumanoidTargeter other) { return(Vector3.Distance(centerBottom.position, other.centerBottom.position) < communicateRadius); }
public static void Communicate(CommunicationPackage package) { bool communicatedByMouth = false; bool communicatedByRadio = false; HumanoidTargeter issuer = package.GetIssuer(); List <IEnumerator> communicatorCoroutines = new List <IEnumerator>(); foreach (HumanoidTargeter targeter in instance.targeters) { if (targeter != issuer && !package.AlreadyCommunicated(targeter)) { if (issuer.CanCommunicate(targeter)) { package.AddToCommunicated(targeter); // Debug.Log("beginning communication from " + issuer.gameObject.name + " to " + targeter.gameObject.name); IEnumerator newCoroutine = CreateCommunicatorCoroutine( issuer.GetTimeToCommunicateByMouth(), targeter, package ); communicatorCoroutines.Add(newCoroutine); instance.StartCoroutine(newCoroutine); communicatedByMouth = true; } else if (targeter.HasRadio() && issuer.HasRadio()) { package.AddToCommunicated(targeter); IEnumerator newCoroutine = CreateCommunicatorCoroutine( issuer.GetTimeToCommunicateByRadio(), targeter, package ); communicatorCoroutines.Add(newCoroutine); instance.StartCoroutine(newCoroutine); communicatedByRadio = true; } } } if (communicatorCoroutines.Count != 0) { Communicator communicator = new Communicator( issuer, communicatorCoroutines ); instance.communicators.Add(communicator); float timeBeforeRemoveCommunicator = 0f;; if (communicatedByMouth && communicatedByRadio) { timeBeforeRemoveCommunicator = Mathf.Max( issuer.GetTimeToCommunicateByMouth() , issuer.GetTimeToCommunicateByRadio() ); } else if (communicatedByMouth) { timeBeforeRemoveCommunicator = issuer.GetTimeToCommunicateByMouth(); } else if (communicatedByRadio) { timeBeforeRemoveCommunicator = issuer.GetTimeToCommunicateByRadio(); } IEnumerator removeCoroutine = GetRemoveFromCommunicatorList( timeBeforeRemoveCommunicator, communicator ); instance.StartCoroutine(removeCoroutine); } }
public static void AddBlackBoardSubscriber(HumanoidTargeter blackBoard) { instance.targeters.Add(blackBoard); }
public Communicator(HumanoidTargeter issuer, List <IEnumerator> coroutines) { this.issuer = issuer; this.coroutines = coroutines; }
public bool AlreadyCommunicated(HumanoidTargeter targeter) { return(alreadyCommunicated.Contains(targeter)); }
public void AddToCommunicated(HumanoidTargeter targeter) { alreadyCommunicated.Add(targeter); }