示例#1
0
 public GetWoodAction(AIAgent agent, Tree tree )
     : base(agent)
 {
     Name = "Get Wood";
     BaseUtility = 10;
     _tree = tree;
 }
示例#2
0
 // Use this for initialization
 public ChopTreeAction(AIAgent agent, Tree tree) : base(agent)
 {
     Name = "Chop the tree action";
     BaseUtility = 5;
     _tree = tree;
 }
示例#3
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);
        }
示例#4
0
 public void ChopTheTree(Tree tree)
 {
     //play chipping animation
     tree.Chop(10);
 }