Beispiel #1
0
 public CutTask(MotionComponent motionComponent, Vector2Int targetPosition, ICuttable cuttable)
 {
     AddCommand(new MoveCommand(motionComponent, targetPosition));
     AddCommand(new RotateToCommand(motionComponent, Utils.NodeAt((cuttable as StaticObject).Position)));
     AddCommand(new WaitCommand(1f));
     AddCommand(new CutCommand(cuttable));
 }
        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();
        }
Beispiel #3
0
 public CutJob(ICuttable cuttable, Vector2Int jobPosition, GameObject jobIcon = null) : base(jobPosition, jobIcon)
 {
     _cuttable           = cuttable;
     _cuttable.HasCutJob = true;
     JobResultHandler   += _cuttable.HandleCutJobResult;
 }
Beispiel #4
0
 public CutCommand(ICuttable cuttable)
 {
     _cuttable = cuttable;
     (_cuttable as IDestroyable).OnDestroyed += OnObjectDestroyedOutside;
 }
Beispiel #5
0
 protected void OnObjectDestroyedOutside(object source, EventArgs e)
 {
     (source as IDestroyable).OnDestroyed -= OnObjectDestroyedOutside;
     _cuttable = null;
     Finish(false);
 }