Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        EntityBody body = null;

        if (GameManager.Instance.SelectionController != null)
        {
            body = GameManager.Instance.SelectionController.Selected;
        }
        if (body)
        {
            if (!Background.activeSelf)
            {
                Background.SetActive(true);
            }
            if (body != lastSelected)
            {
                UpdateSelection(body);
            }

            if (energy != body.Energy ||
                maxenergy != body.MaxEnergy)
            {
                UpdateEnergy(body);
            }

            if (hp != body.Health ||
                maxhp != body.MaxHealth)
            {
                UpdateHP(body);
            }

            LivingEntityBody living = body as LivingEntityBody;
            if (living != null)
            {
                if (!ProgressBar.parent.gameObject.activeInHierarchy)
                {
                    ProgressBar.parent.gameObject.SetActive(true);
                }
                UpdateProgress(living);
            }
            else if (ProgressBar.parent.gameObject.activeInHierarchy)
            {
                ProgressBar.parent.gameObject.SetActive(false);
            }
        }
        else if (Background.activeInHierarchy)
        {
            Background.SetActive(false);
        }
    }
    /// <summary>
    /// After SpeakingTime seconds,
    /// broadcast a message to all
    /// entities in range, triggering their Hear()
    /// </summary>
    public virtual IEnumerator Speak(Talk talk)
    {
        CurrentCommand = talk;
        float maxDistance = GameManager.Instance.Config.MaxHearingDistance;

        switch (talk.Style)
        {
        case TalkStyle.Speak:
            IsSneaking = true;
            break;

        case TalkStyle.Yell:
            IsSneaking   = false;
            maxDistance *= 4;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        yield return(StartCoroutine(WaitWithProgress(SpeakingTime)));

        talk.Words.SourceXCoords = Position.x;
        talk.Words.SourceYCoords = Position.y;
        talk.Words.Language      = Alignment;
        talk.Words.TalkerID      = EntityID;
        int c = 0;

        foreach (EntityBody body in EntityManager.Entities)
        {
            if (body == null)
            {
                continue;
            }
            if (DistanceTo(body) <= maxDistance)
            {
                LivingEntityBody b = body as LivingEntityBody;
                if (b != null)
                {
                    c++;
                    Animal a = b.GetComponent <Animal>();
                    if (a != null)
                    {
                        a.Hear(talk.Words);
                    }
                }
            }
        }
        CurrentCommand = null;
    }
Exemplo n.º 3
0
    public virtual IEnumerable <BaseDescription> GetDescriptions()
    {
        foreach (var entityBody in EntityManager.Entities)
        {
            LivingEntityBody lb       = entityBody as LivingEntityBody;
            float            modifier = lb == null
                ? 1f : lb.Sneakiness;

            if (DistanceTo(entityBody) < SeeingDistance * modifier &&
                entityBody != this)
            {
                yield return(entityBody.Description);
            }
        }
    }
Exemplo n.º 4
0
 public void MagazinePull(ResourceType type, LivingEntityBody who)
 {
     Vector3 mod = UnityEngine.Random.onUnitSphere;
     mod.y = 0;
     mod.Normalize();
     Vector3 location = who.transform.position + mod * 2;
     if (type == ResourceType.Wood && WoodInBank > 0)
     {
         Instantiate(WoodPrefab, location, Quaternion.identity);
         WoodInBank--;
     }
     if (type == ResourceType.Food && FoodInBank > 0)
     {
         Instantiate(FoodPrefab, location, Quaternion.identity);
         FoodInBank--;
     }
 }
Exemplo n.º 5
0
    protected virtual void Start()
    {
        TextPrefab = Instantiate(TextPrefab);
        TextPrefab.SetActive(false);
        TextPrefab.transform.SetParent(GameObject.Find("Canvas").transform, false);
        TextPrefab.transform.localScale = new Vector3(0, 0, 0);

        Brain = GetComponent <BrainWrapper>();
        if (Brain == null || Brain.Brain == null)
        {
            if (Brain == null)
            {
                Brain = gameObject.AddComponent <BrainWrapper>();
            }
            Brain.Brain = new TigerBrain();
            print("added tigerbrain");
        }
        Body = GetComponent <LivingEntityBody>();
    }
Exemplo n.º 6
0
    void UpdateProgress(LivingEntityBody body)
    {
        CurrentActivityText.text = "";
        if (body == null)
        {
            // HideProgressBar
        }
        else
        {
            progress = body.Progress;
            if (progress > 1)
            {
                progress = 1;
            }
            if (body.CurrentCommand != null)
            {
                CurrentActivityText.text = body.CurrentCommand.ToString();
            }

            ProgressBar.localScale = new Vector3(progress, 1, 1);
        }
    }