public CookWorker(int value, WORKER_TYPE workerType) : base(value, workerType) { Debug.Log("Cookworker has arrived"); mCurTime = 0.0f; mMaxTime = 5.0f; Debug.Log("max time for cook set to: " + mMaxTime); mCapCount = 10; //TODO set this to zero and make it unlockable amountOfSeedsToUse = 1; cwei = new CookingWorkerEventInfo(); // this isnt going to update when we change? cwei.eventGO = go; }
//TODO fix double event system call //Event Driven private void CookWorkerUpdate(CookingWorkerEventInfo eventInfo) { float power = eventInfo.workerPower; int seedTypesToCook = 0; //amount of selected seedtypes to cook float totalSeedsToUse = 0; int availableSeedsToCook = 0; List <Seeds> seedsToCook = new List <Seeds>(); //This feels so wasteful. May have a function that does this calculation when you check the //seed to be used, so we could just retrieve the value without having to calculate every time foreach (KeyValuePair <string, Seeds> seed in mFarmingSeeds) { if (seed.Value.mToBeCooked && seed.Value.getCount() > 0) { seedsToCook.Add(seed.Value); //special case availableSeedsToCook += seed.Value.getCount(); //special case seedTypesToCook++; } } if (seedTypesToCook < 1) { return; } //the true amount of seeds to use totalSeedsToUse = (eventInfo.mSeedsToUse * eventInfo.mWorkerCount); //possible amount we can cook&&possible seeds that can be cooked while (totalSeedsToUse > 0 && availableSeedsToCook > 0) { int idx = Random.Range(0, seedsToCook.Count); if (seedsToCook[idx].modifyCountCond(-1, 1)) { Debug.Log("true?"); availableSeedsToCook--; totalSeedsToUse--; GameController.GetInstance().ChangeFoodAmount(seedsToCook[idx].mFood * power); if (seedsToCook[idx].mCount == 0) { seedsToCook.RemoveAt(idx); } } } EventController.getInstance().FireEvent(ruei); EventController.getInstance().FireEvent(fuei); }