Beispiel #1
0
        public override IEnumerator Execute()
        {
            bool success = false;
            LookForFoodAround();
            foreach (var foodItem in _visibleFood)
            {
                if (_agent.Character.BackPack.IsFull)
                {
                    break;
                }

                //двигаемся к следующему объекту
                var moveTo = new MoveToAction(_agent, foodItem.transform.position);
                yield return _agent.StartCoroutine(moveTo.Execute());

                //TODO: нужно еще раз проверить дистанцию до цели
                //подбераем объект, к которому подошли
                var pickUpAction = new PickupItemAction(_agent, foodItem);
                pickUpAction.Finished = (finished) =>success = finished;
                yield return _agent.StartCoroutine(pickUpAction.Execute());

                yield return new WaitForSeconds(0.5f);

                if (_visibleFood.Count < 2)
                    LookForFoodAround();

                if (!success) break;
            }
            yield return new WaitForSeconds(0.5f);

            Finished(true);
        }
Beispiel #2
0
        public override IEnumerator Execute()
        {
            //find the nearest log
            var logs = _agent.GetItems<Log>(null);
            if (logs.Count == 0)
            {
                yield return new WaitForSeconds(0.2f);
                logs = _agent.GetItems<Log>(null);
            }

            if (logs == null || logs.Count == 0)
            {
                Debug.LogError("Nearby there are no logs");
                Cancel();
                yield break;
            }
            logs.SortActorsByDisntace(_agent.transform.position);
            _targetLog = logs.FirstOrDefault();

            //go to log
            var goTo = new MoveToAction(_agent, _targetLog.Position);
            yield return _agent.StartCoroutine(goTo.Execute());
            yield return new WaitForSeconds(1);

            //cut the log
            while (!_targetLog.Processed)
            {
                _agent.Character.CutTheLog(_targetLog);
                yield return new WaitForSeconds(1f);
            }

            Finished(true);
        }
Beispiel #3
0
        public override IEnumerator Execute()
        {
            yield return new WaitForSeconds(1);

            var moveTo = new MoveToAction(_agent, _campFire.transform.position);

            yield return _agent.StartCoroutine(moveTo.Execute());

            Finished(true);
        }
Beispiel #4
0
        public override IEnumerator Execute()
        {
            MoveToAction goTo;
            //find the bed
            var beds = _agent.GetItems<Bed>(bed => !bed.IsOccupied);

            //if nearby there are no beds, go to place from momory
            if (beds.Count == 0)
            {
                var memoryBeds = _agent.GetItemsFromMemory(typeof(Bed));
                memoryBeds.SortActorsByDisntace(_agent.Character.Position);

                var bedInfo = memoryBeds.FirstOrDefault();
                if (bedInfo == null)
                {
                    Debug.Log("Nearby there are no beds");
                    Cancel();
                    yield break;
                }

                goTo = new MoveToAction(_agent, bedInfo.Position);
                yield return _agent.StartCoroutine(goTo.Execute());
            }
            yield return new WaitForSeconds(1f);

            //after we arrived to the place from memory - lookaroynd one more time
            beds = _agent.GetItems<Bed>(bed => !bed.IsOccupied);
            beds.SortActorsByDisntace(_agent.Character.Position);
            _visibleBed = beds.FirstOrDefault();

            if (_visibleBed == null)
            {
                Debug.LogError("Can't find any not occupied beds");
                Cancel();
                yield break;
            }

            goTo = new MoveToAction(_agent, _visibleBed.transform.position);
            yield return _agent.StartCoroutine(goTo.Execute());

            if (_visibleBed.IsOccupied)
            {
                Debug.LogError("I arrived to bed, but its already occupied");
                Cancel();
                yield break;
            }
            yield return new WaitForSeconds(1);

            _visibleBed.LieDown(_agent.Character);
            Finished(true);
        }
Beispiel #5
0
        public override IEnumerator Execute()
        {
            if (_storage == null)
                _storage = StorageManager.Instance.GetClosestStorage(_agent.transform.position);
            if (_storage == null)
            {
                Debug.LogError("There are no any available storages!");
                Cancel();
                yield break;
            }

            yield return new WaitForSeconds(1);

            var moveTo = new MoveToAction(_agent, _storage.transform.position);
            yield return _agent.StartCoroutine(moveTo.Execute());

            if (!_agent.Character.BackPack.IsEmpty)
            {
                var putDown = new PutDownItemToStorageAction(_agent, _storage);
                yield return _agent.StartCoroutine(putDown.Execute());
            }
            Finished(true);
        }
Beispiel #6
0
        public override IEnumerator Execute()
        {
            if (_tree == null)
            {
                //look for trees
                var trees = _agent.GetItems<Tree>(tree => tree.Alive);

                //if nearby there are not trees, go to place from momory
                if (trees.Count == 0)
                {
                    var memoryTrees = _agent.GetItemsFromMemory(typeof (Tree));
                    memoryTrees.SortActorsByDisntace(_agent.Character.Position);

                    var treeInfo = memoryTrees.FirstOrDefault();
                    if (treeInfo == null)
                    {
                        Debug.Log("Nearby there are no trees");
                        Cancel();
                        yield break;
                    }

                    var moveTo = new MoveToAction(_agent, treeInfo.Position);
                    yield return _agent.StartCoroutine(moveTo.Execute());
                    yield return new WaitForSeconds(1f);

                    trees = _agent.GetItems<Tree>(tree => tree.Alive);
                }

                //go to closest  visible tree
                trees.SortActorsByDisntace(_agent.Character.Position);
                _tree = trees.FirstOrDefault();
            }

            if (_tree == null)
            {
                Debug.LogError("targetTree == null, BUG");
                Cancel();
                yield break;
            }

            var goTo = new MoveToAction(_agent, _tree.Position);
            yield return _agent.StartCoroutine(goTo.Execute());
            yield return new WaitForSeconds(1f);

            _agent.Memory.Forget(_tree);
            //chop the tree
            var chopTree = new ChopTreeAction(_agent, _tree);
            yield return _agent.StartCoroutine(chopTree.Execute());
            yield return new WaitForSeconds(0.5f);

            //cut the log
            var cutLog = new CutLogAction(_agent);
            yield return _agent.StartCoroutine(cutLog.Execute());
            yield return new WaitForSeconds(1f);

            //collect woodbeams

            var woodBeams =
                _agent.GetItems<WoodBeam>(wb => (wb.Position - _agent.Character.Position).sqrMagnitude < 12);
            if (woodBeams.Count == 0)
            {
                yield return new WaitForSeconds(0.1f);
                woodBeams =_agent.GetItems<WoodBeam>(wb => (wb.Position - _agent.Character.Position).sqrMagnitude < 12);
            }
            if (woodBeams == null || woodBeams.Count == 0)
            {
                Debug.LogError("Nearby there are no woodbeams");
                Cancel();
                yield break;
            }

            foreach (var woodBeam in woodBeams)
            {
                var collectWoodBeam = new PickupItemAction(_agent, woodBeam);
                yield return _agent.StartCoroutine(collectWoodBeam.Execute());
                yield return new WaitForSeconds(0.5f);
            }

            Finished(true);
        }
Beispiel #7
0
        public override IEnumerator Execute()
        {
            List<IResource> resources = null;
            MoveToAction goTo;

            if (_harvestable == null)
            {
                //trying get from visible actors
                var harvestables = _agent.GetItems<IHarvestable>(h=>h.CanHarvest);

                //trying get from memory
                if (harvestables == null)
                {
                    var harvestablesInMemory = _agent.GetItemsFromMemory(typeof (IHarvestable));
                    if (harvestablesInMemory.Count != 0)
                    {
                        harvestablesInMemory.SortActorsByDisntace(_agent.Character.Position);
                        var info = harvestablesInMemory.FirstOrDefault();
                        if (info == null)
                        {
                            Debug.Log("there are no harvestables in memory");
                            Cancel();
                            yield break;
                        }

                        goTo = new MoveToAction(_agent, info.Position);
                        yield return _agent.StartCoroutine(goTo.Execute());
                        yield return new WaitForSeconds(1f);

                        harvestables = _agent.GetItems<IHarvestable>(h => h.CanHarvest);
                    }
                }

                harvestables.SortActorsByDisntace(_agent.Character.Position);
                if (harvestables != null) _harvestable = harvestables.FirstOrDefault();
            }

            if (_harvestable == null)
            {
                Debug.Log("Nearby there are no harvestables");
                Cancel();
                yield break;
            }

            //if we are to far away from target
            if ((_harvestable.Position - _agent.Character.Position).magnitude > 1)
            {
                goTo = new MoveToAction(_agent, _harvestable.Position);
                yield return _agent.StartCoroutine(goTo.Execute());
            }

            //get reference to ienumerator to be able to stop coroutine
            _harvesting = _harvestable.Harvest((result)=> resources = result);

            //run character visulization of harvesting
            _agent.Character.Harvest(_harvestable);
            yield return _agent.StartCoroutine(_harvesting);

            if (resources == null || resources.Count == 0)
            {
                Debug.Log("Harvesting failed");
                Finished(false);
            }

            //collect harvest basket
            var makeBasket = new CollectHarvestBasketAction(_agent, resources);
            yield return _agent.StartCoroutine(makeBasket.Execute());
            Finished(true);
        }