Esempio n. 1
0
    private void CheckCurrentTileContents()
    {
        Tile currentTile = Utils.TileAt(Position.x, Position.y);

        //Removing any existing stockpiles from the tile
        StockpileCreator.RemoveStockpileFromTile(currentTile);

        //there must be no other items or vegetation on the tile
        if (currentTile.Contents.HasItem)
        {
            RemoveItemFromTileUnderConstructionPlan();
            return;
        }

        if (currentTile.Contents.StaticObject is ICuttable vegetation)
        {
            Job job = new CutJob(vegetation, Position);
            job.JobResultHandler += OnTileClearJobFinish;
            _jobs.Add(job);
            JobSystem.GetInstance().AddJob(job);
            return;
        }

        foreach (var ingredient in Ingredients)
        {
            for (int i = ingredient.count; i > 0; i--)
            {
                CreateHaulingJobForIngredient(SearchEngine.GetTypeDerivativeOf <Item>(ingredient.itemName));
            }
        }
    }
Esempio n. 2
0
        public void delete_job_from_job_system()
        {
            TestJob job = new TestJob(Vector2Int.zero, null);

            _jobFinished          = false;
            job.JobResultHandler += OnJobFinish;
            JobSystem.GetInstance().AddJob(job);
            job.DeleteJob();

            //test removal from job system lists
            if (JobSystem.GetInstance().AllJobs.Contains(job) == true)
            {
                Assert.Fail();
            }

            //test that job result handler did invoke
            if (JobSystem.GetInstance().AvailableJobs.Contains(job) == true)
            {
                Assert.Fail();
            }

            //test that job finished with flag wasJobCanceled
            if (_wasJobCanceled == false || _jobFinished == false)
            {
                Assert.Fail();
            }

            Assert.Pass();
        }
Esempio n. 3
0
    private void CreateHaulingJobForIngredient(Type ingredientType)
    {
        HaulToItemHolderJob job = new HaulToItemHolderJob(ingredientType, this);

        JobSystem.GetInstance().AddJob(job);
        _jobs.Add(job);
        job.JobResultHandler += HandleHaulJobResult;
    }
    private void CreateJobs()
    {
        Dictionary <Tree, GameObject> temp = new Dictionary <Tree, GameObject>(_trees);

        foreach (KeyValuePair <Tree, GameObject> pair in temp)
        {
            if (pair.Key.HasCutJob == false)
            {
                JobSystem.GetInstance().AddJob(new CutJob(pair.Key, pair.Key.Position, pair.Value));
                _trees.Remove(pair.Key);
            }
        }
    }
Esempio n. 5
0
    public override bool CheckInitialization()
    {
        if (_worker is null)
        {
            return(false);
        }

        if (JobSystem.GetInstance().HasWorker(this) == false)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 6
0
    private void Update()
    {
        jobsList.ClearViewport();
        foreach (Job job in JobSystem.GetInstance().AllJobs)
        {
            GameObject element = jobsList.AddElement();
            element.GetComponent <TMPro.TextMeshProUGUI>().text = "" + job.GetType();
        }

        if (JobSystem.GetInstance().AllJobs.Count == 0)
        {
            jobsList.AddElement().GetComponent <TMPro.TextMeshProUGUI>().text = "No jobs available.";
        }
    }
    private void TryHaulingItemToAnyStockpile(Item item)
    {
        if (Utils.TileAt(item.Position).Contents.StockpilePart != null || item.HasHaulJob)
        {
            return;
        }

        StockpilePart part = FindStockpilePartForItem(item);

        if (part != null)
        {
            HaulJob job = new HaulJob(item, part.position);
            part.SetHaulJob(job);
            JobSystem.GetInstance().AddJob(job);
        }
    }
Esempio n. 8
0
    protected override void OnJobFinish(object source, System.EventArgs e)
    {
        bool result = (e as Task.TaskResultEventArgs).Result;

        if (result == true)
        {
            _worker.WithdrawJob();
            JobSystem.GetInstance().DeleteJob(this);
            DeleteJobIcon();
            OnJobResultChanged(result);
        }
        else
        {
            DeleteJob();
        }
    }
    public override bool CanDoJob(JobHandlerComponent worker)
    {
        if (_wasJobCanceled)
        {
            JobSystem.GetInstance().DeleteJob(this);
            return(false);
        }

        //check that worker can actually get to the dropPosition
        if (!base.CanDoJob(worker))
        {
            return(false);
        }

        //item search
        Func <Tile, bool> requirementsFunction = delegate(Tile tile) {
            if (tile == null)
            {
                return(false);
            }
            else
            {
                if (tile.Contents.HasItem)
                {
                    return(tile.Contents.Item.GetType().Equals(ItemType) && tile.Contents.Item.HasHaulJob == false);
                }
                else
                {
                    return(false);
                }
            }
        };

        Tile t = SearchEngine.FindClosestBySubregionTileWhere(worker.MotionComponent.GridPosition, requirementsFunction, true);

        if (t == null)
        {
            JobSystem.GetInstance().StartCoroutine(JobSystem.GetInstance().HideJobForSeconds(this, 5f));
            return(false);
        }
        else
        {
            _item = t.Contents.Item;
            return(true);
        }
        /////////////////
    }
Esempio n. 10
0
    protected virtual void OnJobFinish(object source, System.EventArgs e)
    {
        _task.ResultHandler -= OnJobFinish;
        bool result = (e as Task.TaskResultEventArgs).Result;

        _worker.WithdrawJob();
        if (result == true)
        {
            JobSystem.GetInstance().DeleteJob(this);
            DeleteJobIcon();
        }
        else
        {
            JobSystem.GetInstance().ReturnJob(this);
        }
        OnJobResultChanged(result);
    }
Esempio n. 11
0
    public void DeleteJob()
    {
        if (_wasJobCanceled)
        {
            return;
        }

        _wasJobCanceled = true;
        if (_worker != null)
        {
            _worker.WithdrawJob();
            _task.ResultHandler -= OnJobFinish;
            _task.AbortTask();
        }
        DeleteJobIcon();
        JobSystem.GetInstance().DeleteJob(this);
        OnJobResultChanged(false);
    }
Esempio n. 12
0
        public void add_job()
        {
            TestJob job = new TestJob(Vector2Int.zero, null);

            JobSystem.GetInstance().AddJob(job);

            if (JobSystem.GetInstance().AllJobs.Contains(job) == false)
            {
                Assert.Fail();
            }

            if (JobSystem.GetInstance().AvailableJobs.Contains(job) == false)
            {
                Assert.Fail();
            }

            job.DeleteJob();
            Assert.Pass();
        }
Esempio n. 13
0
    private void RemoveItemFromTileUnderConstructionPlan()
    {
        //find closest free spot
        bool RequirementsFunction(Tile t) => (t is null) ? false : !t.Contents.HasItem;

        Tile haulToTile = SearchEngine.FindClosestTileWhere(Position, RequirementsFunction);

        if (haulToTile != null)
        {
            Job job = new HaulJob(Utils.TileAt(Position).Contents.Item, haulToTile.Position);
            _jobs.Add(job);
            JobSystem.GetInstance().AddJob(job);
            job.JobResultHandler += OnTileClearJobFinish;
        }
        else
        {
            Debug.LogError("No empty tile to move item to was found. Implement wait function to try again some time later. P: " + Position);
        }
    }
Esempio n. 14
0
 private void CreateConstructionJob() => JobSystem.GetInstance().AddJob(new BuildJob(this));
Esempio n. 15
0
 public void WithdrawJob()
 {
     _currentJob = null;
     JobSystem.GetInstance().AddWorker(this);
 }
Esempio n. 16
0
 public void AssignJob(Job job)
 {
     _currentJob = job;
     _currentJob.AssignWorker(this);
     JobSystem.GetInstance().RemoveWorker(this);
 }
Esempio n. 17
0
 public JobHandlerComponent(Human worker)
 {
     _worker = worker;
     JobSystem.GetInstance().AddWorker(this);
 }
Esempio n. 18
0
        private ConstructionPlan create_construction_plan(string dataName)
        {
            ConstructionPlan plan = Factory.CreateConstructionPlan("plank wall", _spawnPosition);

            //check data + check all fields
            if (plan.Data is null)
            {
                Assert.Fail();
            }

            if (plan.Data.construction is null)
            {
                Assert.Fail();
            }

            if (plan.Data.ingredients == null ||
                plan.Data.ingredients.Count == 0)
            {
                Assert.Fail();
            }

            //check position
            if (plan.Position != _spawnPosition)
            {
                Assert.Fail();
            }

            //check traversability
            if (plan.IsTraversable == false)
            {
                Assert.Fail();
            }

            //check ingredients
            if (plan.Ingredients.Count != plan.Data.ingredients.Count)
            {
                Assert.Fail();
            }

            //check gameobject + position
            if (plan.gameObject == null)
            {
                Assert.Fail();
            }

            //check tile content
            if (Utils.TileAt(plan.Position).Contents.ConstructionPlan != plan)
            {
                Assert.Fail();
            }

            //check that tile doesn't have a stockpile
            if (Utils.TileAt(plan.Position).Contents.StockpilePart != null)
            {
                Assert.Fail();
            }

            //check that if there was an item on construction plan
            //haul job to remove the item was created and other jobs were not created
            if (Utils.TileAt(plan.Position).Contents.HasItem == true)
            {
                bool hasHaulJob = false;
                foreach (Job job in JobSystem.GetInstance().AllJobs)
                {
                    if (job.GetType() == typeof(HaulToItemHolderJob))
                    {
                        Assert.Fail();
                    }

                    if (job.GetType() == typeof(HaulJob))
                    {
                        hasHaulJob = true;
                    }
                }

                if (hasHaulJob == false)
                {
                    Assert.Fail();
                }
            }
            else if (Utils.TileAt(plan.Position).Contents.StaticObject is ICuttable)
            {
                bool hasCutJob = false;
                foreach (Job job in JobSystem.GetInstance().AllJobs)
                {
                    if (job.GetType() == typeof(HaulToItemHolderJob))
                    {
                        Assert.Fail();
                    }

                    if (job.GetType() == typeof(CutJob))
                    {
                        hasCutJob = true;
                    }
                }

                if (hasCutJob == false)
                {
                    Assert.Fail();
                }
            }

            return(plan);
        }