public IEnumerator add_multiple_tasks()
        {
            Human            human = CreateHuman();
            CommandProcessor cp    = human.AI.CommandProcessor;

            int taskCount = (int)Random.Range(2, 10);

            for (int i = 0; i < taskCount; i++)
            {
                cp.AddTask(new Task());
            }

            for (int i = 0; i <= taskCount; i++)
            {
                yield return(null);
            }

            if (cp.HasTask == true)
            {
                Assert.Fail();
            }

            human.Die();
            Assert.Pass();
        }
        public IEnumerator cut_task()
        {
            Human      human = CreateHuman();
            Vector2Int vegetationSpawnPosition = _spawnPosition + new Vector2Int(0, 10);
            ICuttable  vegetation     = Factory.Create <CuttableTestClass>("tall tree", vegetationSpawnPosition);
            Vector2Int targetPosition =
                SearchEngine.FindNodeNear(Utils.NodeAt(vegetationSpawnPosition), human.MotionComponent.Node).Position;
            Task task = new CutTask(human.MotionComponent, targetPosition, vegetation);

            yield return(AddTaskAndWaitUntilFinished(task, human.CommandProcessor));

            yield return(null);

            //check that ICuttable was destroyed
            if (((StaticObject)vegetation).gameObject != null)
            {
                Assert.Fail();
            }
            //check tile contents
            Tile t = Utils.TileAt(vegetationSpawnPosition);

            if (t.Contents.StaticObject == ((StaticObject)vegetation))
            {
                Assert.Fail();
            }
            //check human position
            if (human.MotionComponent.GridPosition != targetPosition)
            {
                Debug.Log(human.MotionComponent.GridPosition + " " + targetPosition);
                Assert.Fail();
            }

            human.Die();
            Assert.Pass();
        }
        public IEnumerator haul_task()
        {
            Human      human             = CreateHuman();
            Vector2Int itemSpawnPosition = _spawnPosition + new Vector2Int(-10, 0);
            Vector2Int targetPosition    = _spawnPosition - new Vector2Int(-10, 0);
            WoodLog    item = Factory.Create <WoodLog>("wood log", itemSpawnPosition);
            Task       task = new HaulTask(item, targetPosition, human.MotionComponent, human.InventoryComponent);

            yield return(AddTaskAndWaitUntilFinished(task, human.CommandProcessor));

            //test inventory
            if (human.InventoryComponent.HasItem(item) == true)
            {
                Assert.Fail();
            }
            //test item position
            if (item.Position != targetPosition)
            {
                Assert.Fail();
            }

            human.Die();
            item.Destroy();

            Assert.Pass();
        }
        public IEnumerator eat_food_task()
        {
            Human human              = CreateHuman();
            Node  grassNode          = Utils.NodeAt(_spawnPosition + new Vector2Int(0, 10));
            Grass grass              = Factory.Create <Grass>("grass", grassNode.Position);
            float defaultHungerLevel = human.HungerComponent.HungerLevel;
            Node  targetNode         = SearchEngine.FindNodeNear(grassNode, human.MotionComponent.Node);
            var   task = new EatFoodTask(human, targetNode, grass);

            yield return(AddTaskAndWaitUntilFinished(task, human.CommandProcessor));

            yield return(null);

            //check position
            if (human.MotionComponent.Node != targetNode)
            {
                Assert.Fail();
            }
            //check hunger
            if (human.HungerComponent.HungerLevel == defaultHungerLevel)
            {
                Assert.Fail();
            }
            //check food destroy
            if (grass.gameObject != null)
            {
                Assert.Fail();
            }

            human.Die();
            Assert.Pass();
        }
Ejemplo n.º 5
0
        public void spawn_human_test()
        {
            Human human = Factory.Create <Human>("human", _spawnPosition);

            //Base character test
            if (check_character_initialization(human) == false)
            {
                Assert.Fail();
            }

            #region Unique components

            //Motion animator
            if (human.MotionAnimator.CheckInitialization() == false)
            {
                Assert.Fail();
            }

            //Job handler component
            if (human.JobHandlerComponent.CheckInitialization() == false)
            {
                Assert.Fail();
            }

            //Inventory component
            if (human.InventoryComponent.CheckInitialization() == false)
            {
                Assert.Fail();
            }

            #endregion

            human.Die();
            Assert.Pass();
        }
Ejemplo n.º 6
0
        public IEnumerator kill_human_test()
        {
            Human human = Factory.Create <Human>("human", _spawnPosition);

            human.Die();
            yield return(new WaitForEndOfFrame());

            //Common character checks
            if (check_character_death(human) == false)
            {
                Assert.Fail();
            }

            //Verify that all components are disabled.
            List <CharacterComponent> components = new List <CharacterComponent>()
            {
                human.MotionAnimator,
                human.JobHandlerComponent,
                human.InventoryComponent,
            };

            foreach (CharacterComponent component in components)
            {
                if (component.IsDisabled == false)
                {
                    Assert.Fail();
                }
            }

            Assert.Pass();
        }
Ejemplo n.º 7
0
        public void human_on_select_must_switch_to_move_command_input_state()
        {
            Human human = Factory.Create <Human>("human", _spawnPosition);

            human.Select();

            if (CommandInputStateMachine.currentCommandState.GetType() != typeof(MoveCommandInputState))
            {
                Assert.Fail();
            }

            human.Die();
            Assert.Pass();
        }
        public IEnumerator move_task()
        {
            Human      human          = CreateHuman();
            Vector2Int targetPosition = human.MotionComponent.GridPosition + new Vector2Int(-10, 10);
            var        moveTask       = new MoveTask(human.MotionComponent, targetPosition);

            yield return(AddTaskAndWaitUntilFinished(moveTask, human.CommandProcessor));

            //test position
            if (human.MotionComponent.GridPosition != targetPosition)
            {
                Assert.Fail();
            }

            human.Die();
            Assert.Pass();
        }
        public IEnumerator wait_task()
        {
            Human            human = CreateHuman();
            CommandProcessor cp    = human.CommandProcessor;

            Task task = new WaitTask(0.1f);

            yield return(AddTaskAndWaitUntilFinished(task, cp));

            if (cp.HasTask == true)
            {
                Assert.Fail();
            }

            human.Die();
            Assert.Pass();
        }
        public void abort_task()
        {
            Human human = CreateHuman();
            Task  task  = new Task();

            _taskFinished       = false;
            task.ResultHandler += OnTaskFinish;
            human.CommandProcessor.AddTask(task);
            task.AbortTask();

            if (human.CommandProcessor.HasTask == true)
            {
                Assert.Fail();
            }

            human.Die();
            Assert.Pass();
        }
        public IEnumerator haul_to_item_holder_task()
        {
            Human      human          = CreateHuman();
            WoodLog    item           = Factory.Create <WoodLog>("wood log", _spawnPosition);
            Vector2Int holderPosition = _spawnPosition + new Vector2Int(0, 10);
            ItemHolder holder         = Factory.Create <ItemHolder>("plank wall", holderPosition);
            Task       task           = new HaulToItemHolderTask(item, holder, human.MotionComponent, human.InventoryComponent);

            yield return(AddTaskAndWaitUntilFinished(task, human.CommandProcessor));

            //check human position
            if ((human.MotionComponent.GridPosition - holder.Position).magnitude > 1)
            {
                Assert.Fail();
            }
            //check item position
            if (item.Position != holder.Position)
            {
                Assert.Fail();
            }
            //check holder inventory
            if (holder.Items.Contains(item) == false)
            {
                Assert.Fail();
            }
            //check human inventory
            if (human.InventoryComponent.HasItem(item))
            {
                Assert.Fail();
            }

            human.Die();
            holder.Destroy();
            item.Destroy();

            Assert.Pass();
        }