示例#1
0
 public EnemyMarker(HumanoidModel target, Vector3 location, HumanoidTargeter founder)
 {
     this.location = location;
     this.target   = target;
     usedBy        = new HashSet <HumanoidTargeter>();
     enemyVantage  = target.InfoGetVantageData();
     enemyVantage.SetLocation(location);
 }
示例#2
0
    private static IEnumerator CreateCommunicatorCoroutine(float timeToCommunicate,
                                                           HumanoidTargeter reciever,
                                                           CommunicationPackage package)
    {
        yield return(new WaitForSeconds(timeToCommunicate));

        reciever.RecieveCommunication(package);
    }
示例#3
0
 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++;
 }
示例#4
0
 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);
         }
     });
 }
示例#5
0
 private void Awake()
 {
     targeters = new List <HumanoidTargeter>();
     foreach (Transform enemy in targeterObject.transform)
     {
         HumanoidTargeter targeter = enemy.GetComponent <HumanoidTargeter>();
         if (targeter != null)
         {
             targeters.Add(targeter);
         }
     }
 }
示例#6
0
    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);
    }
示例#7
0
 public bool IsUsedBy(HumanoidTargeter targeter)
 {
     return(usedBy.Contains(targeter));
 }
示例#8
0
 public void RemoveUser(HumanoidTargeter targeter)
 {
     usedBy.Remove(targeter);
 }
示例#9
0
 public void AddUser(HumanoidTargeter targeter)
 {
     usedBy.Add(targeter);
 }
示例#10
0
 public EnemyMarker(EnemyTarget target, HumanoidTargeter founder)
     : this(target.GetEnemy(), target.GetLocation(), founder)
 {
 }
示例#11
0
 public bool CanCommunicate(HumanoidTargeter other)
 {
     return(Vector3.Distance(centerBottom.position, other.centerBottom.position) < communicateRadius);
 }
示例#12
0
    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);
        }
    }
示例#13
0
 public static void AddBlackBoardSubscriber(HumanoidTargeter blackBoard)
 {
     instance.targeters.Add(blackBoard);
 }
示例#14
0
 public Communicator(HumanoidTargeter issuer,
                     List <IEnumerator> coroutines)
 {
     this.issuer     = issuer;
     this.coroutines = coroutines;
 }
示例#15
0
 public bool AlreadyCommunicated(HumanoidTargeter targeter)
 {
     return(alreadyCommunicated.Contains(targeter));
 }
示例#16
0
 public void AddToCommunicated(HumanoidTargeter targeter)
 {
     alreadyCommunicated.Add(targeter);
 }