public void ClearFarmWorks() { if (WorkRoom == null) { return; } CSFarm farm = WorkRoom as CSFarm; if (farm == null) { m_FarmWorkMap.Clear(); return; } foreach (KeyValuePair <EFarmWorkType, FarmWorkInfo> kvp in m_FarmWorkMap) { switch (kvp.Key) { case EFarmWorkType.Watering: farm.RestoreWateringPlant(kvp.Value.m_Plant); break; case EFarmWorkType.Cleaning: farm.RestoreCleaningPlant(kvp.Value.m_Plant); break; case EFarmWorkType.Harvesting: farm.RestoreRipePlant(kvp.Value.m_Plant); break; case EFarmWorkType.Planting: #if NEW_CLOD_MGR CSMgCreator mgCreator = m_Creator as CSMgCreator; if (mgCreator == null) { Debug.Log(" CSCreator is error"); break; } mgCreator.m_Clod.DirtyTheChunk(kvp.Value.m_ClodChunk.m_ChunkIndex, false); #else CSClodMgr.DirtyTheChunk(kvp.Value.m_ClodChunk.m_ChunkIndex, false); #endif break; } } m_FarmWorkMap.Clear(); }
private void _farmWorkStyle() { CSFarm farm = WorkRoom as CSFarm; if (farm == null) { return; } FarmPlantLogic plant = null; CSMgCreator mgCreator = m_Creator as CSMgCreator; // Only watering and weeding if (m_WorkMode == CSConst.pwtFarmForMag) { if (m_FarmWorkMap.Count != 0) { return; } ItemObject waterItem = farm.GetPlantTool(0); ItemObject weedingItem = farm.GetPlantTool(1); // Watering plant = waterItem == null ? null : farm.AssignOutWateringPlant(); if (plant != null) { FarmWorkInfo fwi = new FarmWorkInfo(plant); m_FarmWorkMap.Add(EFarmWorkType.Watering, fwi); //_sendToWorkOnFarm(fwi.m_Pos); } else { // Weeding plant = weedingItem == null ? null : farm.AssignOutCleaningPlant(); if (plant != null) { FarmWorkInfo fwi = new FarmWorkInfo(plant); m_FarmWorkMap.Add(EFarmWorkType.Cleaning, fwi); //_sendToWorkOnFarm(fwi.m_Pos); } //else // Idle(0.0f, false); } } else if (m_WorkMode == CSConst.pwtFarmForHarvest) { if (m_FarmWorkMap.Count != 0) { return; } CSStorage storage = null; foreach (CSStorage css in farm.Assembly.m_BelongObjectsMap[CSConst.ObjectType.Storage]) { SlotList slotList = css.m_Package.GetSlotList(); if (slotList.GetVacancyCount() >= 2) //if (css.m_Package.GetEmptyGridCount() >= 2) { storage = css; break; } } if (storage != null) { plant = farm.AssignOutRipePlant(); if (plant != null) { FarmWorkInfo fwi = new FarmWorkInfo(plant); m_FarmWorkMap.Add(EFarmWorkType.Harvesting, fwi); //_sendToWorkOnFarm(fwi.m_Pos); } //else // Idle(0.0f, false); } //else // Idle(0.0f, false); } else if (m_WorkMode == CSConst.pwtFarmForPlant) { // Planting if (m_FarmWorkMap.Count == 0) { #if NEW_CLOD_MGR ClodChunk cc = mgCreator.m_Clod.FindCleanChunk(farm.Assembly.Position, farm.Assembly.Radius); #else ClodChunk cc = CSClodMgr.FindCleanChunk(farm.Assembly.Position, farm.Assembly.Radius); #endif if (farm.HasPlantSeed() && cc != null) { Vector3 pos; bool flag = cc.FindCleanClod(out pos); if (flag) { #if NEW_CLOD_MGR mgCreator.m_Clod.DirtyTheChunk(cc.m_ChunkIndex, true); #else CSClodMgr.DirtyTheChunk(cc.m_ChunkIndex, true); #endif FarmWorkInfo fwi = new FarmWorkInfo(cc, pos); m_FarmWorkMap.Add(EFarmWorkType.Planting, fwi); _sendToWorkOnFarm(fwi.m_Pos); } } //else // Idle(0.0f, false); } else if (m_FarmWorkMap.ContainsKey(EFarmWorkType.Planting) && m_FarmWorkMap[EFarmWorkType.Planting].m_Pos == Vector3.zero) { if (farm.HasPlantSeed()) { FarmWorkInfo fwi = m_FarmWorkMap[EFarmWorkType.Planting]; bool flag = fwi.m_ClodChunk.FindCleanClod(out fwi.m_Pos); if (flag) { //_sendToWorkOnFarm(fwi.m_Pos); } else { m_FarmWorkMap.Remove(EFarmWorkType.Planting); } } else { FarmWorkInfo fwi = m_FarmWorkMap[EFarmWorkType.Planting]; #if NEW_CLOD_MGR mgCreator.m_Clod.DirtyTheChunk(fwi.m_ClodChunk.m_ChunkIndex, false); #else CSClodMgr.DirtyTheChunk(fwi.m_ClodChunk.m_ChunkIndex, false); #endif m_FarmWorkMap.Remove(EFarmWorkType.Planting); } } if (!m_FarmWorkMap.ContainsKey(EFarmWorkType.Planting)) { //Idle(0.0f, false); } } }