コード例 #1
0
    void ReturnGoods()
    {
        ResetAllTriggers();
        Transform _ResourceCollection = _Manager._FindObject.ClosestBuildingOfInterest(_Manager._FindObject._ResourceCollection, gameObject, transform.position).transform;

        _Nav.SetDestination(_ResourceCollection.position);
        _Anim.SetLayerWeight(1, 1);

        if (_CurrentTool != null)
        {
            Destroy(_CurrentTool);
        }
        DisplayResource();

        if (Vector3.Distance(transform.position, _ResourceCollection.position) < 2)
        {
            if (!_ShowingPopup)
            {
                StartCoroutine(ShowPopup());
            }
            Destroy(_CurrentTool);
            _Task = VillagerTask.GatherResources;
            _Anim.SetLayerWeight(1, 0);
        }
    }
コード例 #2
0
    public void InteractWithObject(ISelectable selectableObject)
    {
        if (selectableObject != null)
        {
            if (selectableObject != this)
            {
                GameObject obj = selectableObject.GetObject();
                if (obj != null)
                {
                    //World resource check (Wood,Stone,Food)
                    if (obj.GetComponent <WorldResource>() != null)
                    {
                        _WantedGoal = obj.GetComponent <WorldResource>()._ResourceType;

                        if (_CurrentTool != null)
                        {
                            Destroy(_CurrentTool);
                        }

                        ResetAllTriggers();
                        FindClosestResource();


                        if (_WantedGoal != ResourceType.building)
                        {
                            _Task = VillagerTask.GatherResources;
                        }
                        else
                        {
                            _Task       = VillagerTask.Building;
                            _ObjOfFocus = obj;
                        }
                    }
                    //Move to the point if alive
                    if (Alive())
                    {
                        if (_Nav.isOnNavMesh)
                        {
                            _Nav.destination = obj.transform.position;
                        }

                        SetTask();
                    }
                    //Villager Check & checks to see if they are not on the same team
                    if (obj.GetComponent <VillagerController>())
                    {
                        if (obj.GetComponent <TeamSide>()._team != Team.player)
                        {
                            Attack(obj);
                        }
                    }
                    //Attack Animal (Chickens)
                    if (obj.GetComponent <Animal>())
                    {
                        Attack(obj);
                    }
                }
            }
        }
    }
コード例 #3
0
 void Attack(GameObject obj)
 {
     FreeWorldResource();
     _Task       = VillagerTask.Combat;
     _WantedGoal = ResourceType.combat;
     _ObjOfFocus = obj;
 }
コード例 #4
0
 public void InteractWithLocation(Vector3 location)
 {
     if (Alive())
     {
         _Nav.destination = location;
     }
     _Task = VillagerTask.DoNothing;
 }
コード例 #5
0
 void SetTask()
 {
     if (_ObjOfFocus != null)
     {
         if (_ObjOfFocus.GetComponent <WorldResource>())
         {
             _Task = VillagerTask.GatherResources;
         }
     }
 }
コード例 #6
0
    private void Update()
    {
        if (_Task == VillagerTask.Combat)
        {
            if (_ObjOfFocus != null)
            {
                if (_ObjOfFocus.GetComponent <VillagerController>())
                {
                    if (_ObjOfFocus.GetComponent <VillagerController>().enabled == false)
                    {
                        _ObjOfFocus = null;
                    }
                }
                if (_ObjOfFocus != null)
                {
                    if (_ObjOfFocus.GetComponent <Animal>() != null)
                    {
                        if (_ObjOfFocus.GetComponent <Animal>().enabled == false)
                        {
                            _ObjOfFocus = null;
                        }
                    }
                }
            }
            else
            {
                if (_Manager._FindObject.ClosestEnemyVillager(_Manager._FindObject._Villagers, gameObject) != null)
                {
                    _ObjOfFocus = _Manager._FindObject.ClosestEnemyVillager(_Manager._FindObject._Villagers, gameObject).gameObject;
                }
            }
        }
        SetAnimation();
        if (!Alive())
        {
            KillVillager();
        }
        else
        {
            RunTasks();
        }

        if (_Wood >= _CarryCapacity || _Stone >= _CarryCapacity || _Food >= _CarryCapacity)
        {
            _Task = VillagerTask.ReturnGoods;
        }
    }
コード例 #7
0
    public void OnGatherResource()
    {
        if (_ObjOfFocus != null)
        {
            if (_Task == VillagerTask.Combat)
            {
                if (_ObjOfFocus.GetComponent <VillagerController>()) //Makes the other villager attack this villager back
                {
                    VillagerController Villager = _ObjOfFocus.GetComponent <VillagerController>();
                    if (Villager._ObjOfFocus != null)
                    {
                        if (Villager._ObjOfFocus.GetComponent <WorldResource>() != null)
                        {
                            Villager._ObjOfFocus.GetComponent <WorldResource>()._SupplyBeingTaken = false;
                        }
                    }
                    Villager._Wood       = 0; Villager._Stone = 0; Villager._Food = 0;
                    Villager._Task       = VillagerTask.Combat;
                    Villager._ObjOfFocus = this.gameObject;
                    Villager._WantedGoal = ResourceType.combat;
                }
                if (_ObjOfFocus.GetComponent <ITakeDamage>() != null && _ObjOfFocus.GetComponent <WorldResource>() == null)
                {
                    _ObjOfFocus.GetComponent <ITakeDamage>().TakeDamage(20); //Deal damage to other entity
                }
                else
                {
                    Destroy(_CurrentTool); _Task = VillagerTask.GatherResources;
                }
            }
            else
            {
                if (_ObjOfFocus.GetComponent <ITakeDamage>() != null)
                {
                    _ObjOfFocus.GetComponent <ITakeDamage>().TakeDamage(1); //Deal damage to resources
                }
            }
            if (_CurrentTool != null)
            {
                if (_CurrentTool.GetComponentInChildren <ParticleSystem>() != null)
                {
                    _CurrentTool.GetComponentInChildren <ParticleSystem>().Play();
                }
            }
            if (_Task == VillagerTask.GatherResources) //Gather resources
            {
                switch (_WantedGoal)
                {
                case ResourceType.wood:
                    _Wood       += 1;
                    _Audio.pitch = Random.Range(0.8f, 1.2f);
                    PlaySound(_WoodHit);
                    break;

                case ResourceType.stone:
                    _Stone      += 1;
                    _Audio.pitch = Random.Range(0.8f, 1.2f);
                    PlaySound(_StoneHit);
                    break;

                case ResourceType.food:
                    _Food       += 1;
                    _Audio.pitch = Random.Range(0.8f, 1.2f);
                    PlaySound(_WoodHit);
                    break;
                }
            }
        }
    }