public override void ChangeState() { base.ChangeState(); if (m_IsRunning) { if (FarmManager.Instance == null) { Debug.Log("FarmManager is missing?"); return; } else { RefreshPlant(); } } else { if (FarmManager.Instance != null) { FarmManager.Instance.CreatePlantEvent -= OnCreatePlant; FarmManager.Instance.RemovePlantEvent -= OnRemovePlant; FarmPlantLogic.UnregisterEventListener(PlantEventListener); } } }
// void RPC_S2C_CLN_SetGuardPos(uLink.BitStream stream, uLink.NetworkMessageInfo info) // { // //--to do: wait // Vector3 guardPos = stream.Read<Vector3>(); // //int playID = stream.Read<int>(); // //if (playID == PlayerFactory.mMainPlayer.OwnerView.viewID.id) // //{ // CSCreator creator = CSMain.GetCreator(CSConst.ciDefMgCamp); // if (creator != null) // { // CSPersonnel[] personnels = creator.GetNpcs(); // foreach (CSPersonnel csp in personnels) // { // if (csp != null && csp.m_Npc != null) // { // if (Id == csp.m_Npc.Id) // { // csp.SetGuardAttr(guardPos); // } // } // } // } // //} // } void RPC_S2C_CLN_PlantGetBack(uLink.BitStream stream, uLink.NetworkMessageInfo info) { int objId = stream.Read <int> (); if (objId != -1) { FarmManager.Instance.RemovePlant(objId); DragArticleAgent.Destory(objId); ItemMgr.Instance.DestroyItem(objId); } else { FarmPlantLogic plant = stream.Read <FarmPlantLogic>(); CSMgCreator creator = MultiColonyManager.GetCreator(TeamId); if (creator == null || creator.Assembly == null) { return; } CSFarm farm = creator.Assembly.Farm; if (farm == null) { return; } farm.RestoreWateringPlant(plant); } }
void RPC_S2C_Plant_PutOut(uLink.BitStream stream, uLink.NetworkMessageInfo info) { Vector3 pos = stream.Read <Vector3>(); Quaternion rot = stream.Read <Quaternion>(); Vector3 scale = stream.Read <Vector3>(); int instanceId = stream.Read <int>(); ItemObject itemobj = ItemMgr.Instance.Get(instanceId); DragArticleAgent dragItem = DragArticleAgent.Create(itemobj.GetCmpt <Drag>(), pos, scale, rot, instanceId); FarmPlantLogic plant = dragItem.itemLogic as FarmPlantLogic; plant.InitInMultiMode(); stream.Read <FarmPlantLogic>(); plant.UpdateInMultiMode(); //DragItem item = new DragItem(objID); //item.position = plantPos; //item.rotation = transform.rotation; //item.itemScript = null; ////item.DependType = dependType; //item.network = this; //DragItem.Mgr.Instance.Add(item); }
void RPC_S2C_CLN_PlantPutOut(uLink.BitStream stream, uLink.NetworkMessageInfo info) { Vector3 pos = stream.Read <Vector3>(); Quaternion rot = stream.Read <Quaternion>(); int objID = stream.Read <int>(); /*byte type = */ stream.Read <byte>(); //FarmPlantLogic mPlant = FarmManager.Instance.GetPlantByItemObjID (objID); //if(null == mPlant) //{ // mPlant = FarmManager.Instance.CreatePlant(objID, PlantInfo.GetPlantInfoByItemId(m_ItemID).mTypeID, pos); // mPlant.mTerrianType = type; // mPlant.UpdateGrowRate(0); //} //mPlant.mPos = pos; //DragArticleAgent item = DragArticleAgent.PutItemByProroId(objID, pos, transform.rotation); ItemObject itemobj = ItemMgr.Instance.Get(objID); DragArticleAgent dragItem = DragArticleAgent.Create(itemobj.GetCmpt <Drag>(), pos, Vector3.one, rot, objID); FarmPlantLogic plant = dragItem.itemLogic as FarmPlantLogic; plant.InitInMultiMode(); stream.Read <FarmPlantLogic>(); plant.UpdateInMultiMode(); }
CSUI_PlantGrid _createPlantGrid(FarmPlantLogic p) { CSUI_PlantGrid pg = Instantiate(m_PlantPart.m_PlantGridPrefab) as CSUI_PlantGrid; pg.transform.parent = m_PlantPart.m_Root.transform; CSUtils.ResetLoacalTransform(pg.transform); pg.m_Plant = p; pg.OnDestroySelf = OnPlantGridDestroySelf; //ItemObject itemObj = ItemMgr.Instance.Get( pg.m_Plant.mInstanceId); //if (itemObj != null) //{ string[] iconStr = ItemProto.Mgr.Instance.Get(pg.m_Plant.protoTypeId).icon; if (iconStr.Length != 0) { pg.IconSpriteName = iconStr[0]; } else { pg.IconSpriteName = ""; } //} m_PlantGrids.Add(pg); UICheckbox cb = pg.gameObject.GetComponent <UICheckbox>(); cb.radioButtonRoot = m_PlantPart.m_Root.transform; cb.startsChecked = false; return(pg); }
public FarmPlantLogic PlantTo(Vector3 pos) { FarmPlantLogic fpl = null; // Sequential planting if (Data.m_SequentialPlanting) { int orgin = m_PlantSequence; for (int i = m_PlantSequence; i < PLANTS_SEEDS_COUNT; i++) { ItemObject io = GetPlantSeed(i); if (io != null) { fpl = _plant(io, pos, i); m_PlantSequence++; if (m_PlantSequence >= PLANTS_SEEDS_COUNT) { m_PlantSequence = PLANTS_SEEDS_COUNT - 1; } break; } } if (orgin == m_PlantSequence) { for (int i = 0; i < orgin; i++) { ItemObject io = GetPlantSeed(i); if (io != null) { fpl = _plant(io, pos, i); m_PlantSequence = i + 1; if (m_PlantSequence >= PLANTS_SEEDS_COUNT) { m_PlantSequence = PLANTS_SEEDS_COUNT - 1; } break; } } } } // Normal plant else { for (int i = 0; i < PLANTS_SEEDS_COUNT; i++) { ItemObject io = GetPlantSeed(i); if (io != null) { fpl = _plant(io, pos, i); break; } } } return(fpl); //DrawItemManager.Instance.CreateMapItem() }
// CSFarm void OnCreatePlant(FarmPlantLogic plant) { if (plant != null) { _createPlantGrid(plant); m_PlantPart.m_Root.repositionNow = true; } }
//public FarmPlantLogic CreatePlant(int itemObjID, int plantTypeID, Vector3 pos) //{ // FarmPlantLogic addPlant = new FarmPlantLogic(); // addPlant.mPlantInstanceId = itemObjID; // addPlant._PlantType = plantTypeID; // addPlant.mLife = 100f; // addPlant.mPos = pos; // addPlant.mPutOutGameTime = GameTime.Timer.Second; // addPlant.mWater = addPlant.mPlantInfo.mDefaultWater; // addPlant.mClean = addPlant.mPlantInfo.mDefaultClean; // addPlant.mDead = false; // addPlant.mGrowTimeIndex = 0; // mPlantMap[itemObjID] = addPlant; // mPlantHelpMap[new IntVec3(addPlant.mPos)] = addPlant.mPlantInstanceId; // if(null != CreatePlantEvent) // CreatePlantEvent(addPlant); // return addPlant; //} public void AddPlant(FarmPlantLogic addPlant) { mPlantMap[addPlant.mPlantInstanceId] = addPlant; mPlantHelpMap[new IntVec3(addPlant.mPos)] = addPlant.mPlantInstanceId; if (null != CreatePlantEvent) { CreatePlantEvent(addPlant); } }
private void RPC_S2C_Plant_UpdateInfo(uLink.BitStream stream, uLink.NetworkMessageInfo info) { FarmPlantLogic plant = stream.Read <FarmPlantLogic>(); if (plant != null) { plant.UpdateInMultiMode(); } }
public FarmWorkInfo(FarmPlantLogic plant) { if (plant == null) { Debug.LogError("Giving plant must be not null."); Debug.DebugBreak(); } m_Plant = plant; m_Pos = plant.mPos; }
public void RestoreWateringPlant(FarmPlantLogic plant) { if (!m_Plants.ContainsKey(plant.mPlantInstanceId)) { return; } if (plant.NeedWater) { m_WateringIds.Add(plant.mPlantInstanceId); } }
private void OnRemovePlant(FarmPlantLogic plant) { if (RemovePlantEvent != null) { RemovePlantEvent(plant); } m_Plants.Remove(plant.mPlantInstanceId); m_WateringIds.Remove(plant.mPlantInstanceId); m_CleaningIds.Remove(plant.mPlantInstanceId); m_RipedIds.Remove(plant.mPlantInstanceId); m_DeadIds.Remove(plant.mPlantInstanceId); }
public void RestoreRipePlant(FarmPlantLogic plant) { if (!m_Plants.ContainsKey(plant.mPlantInstanceId)) { return; } if (plant.IsRipe) { m_RipedIds.Add(plant.mPlantInstanceId); } }
void RPC_S2C_Plant_Clear(uLink.BitStream stream, uLink.NetworkMessageInfo info) { int objId = stream.Read <int> (); FarmPlantLogic plant = FarmManager.Instance.GetPlantByItemObjID(objId); if (plant != null) { FarmManager.Instance.RemovePlant(objId); DragArticleAgent.Destory(objId); //ItemMgr.Instance.DestroyItem(objId); } }
public FarmPlantLogic AssignOutRipePlant() { if (m_RipedIds.Count == 0) { return(null); } FarmPlantLogic p = m_Plants[m_RipedIds[0]]; m_RipedIds.RemoveAt(0); return(p); }
public FarmPlantLogic AssignOutCleaningPlant() { if (m_CleaningIds.Count == 0) { return(null); } FarmPlantLogic p = m_Plants[m_CleaningIds[0]]; m_CleaningIds.RemoveAt(0); return(p); }
//[Obsolete] void RPC_S2C_Plant_Water(uLink.BitStream stream, uLink.NetworkMessageInfo info) { int objId = stream.Read <int> (); double water = stream.Read <double> (); FarmPlantLogic plant = FarmManager.Instance.GetPlantByItemObjID(objId); if (plant != null) { plant.mWater = water; plant.UpdateInMultiMode(); } }
void RPC_S2C_FARM_RestoreGetBack(uLink.BitStream stream, uLink.NetworkMessageInfo info) { // CSFarmData reocrdData = (CSFarmData)_ColonyObj._RecordData; FarmPlantLogic plant = stream.Read <FarmPlantLogic>(); if (m_Entity == null) { Debug.LogError("entity not ready"); return; } (m_Entity as CSFarm).RestoreRipePlant(plant); }
public FarmPlantLogic AssignOutWateringPlant() { if (m_WateringIds.Count == 0) { return(null); } FarmPlantLogic p = m_Plants[m_WateringIds[0]]; //Debug.LogError("water!"+p.mPlantInstanceId); m_WateringIds.RemoveAt(0); return(p); }
void OnRemovePlant(FarmPlantLogic plant) { if (plant != null) { int index = m_PlantGrids.FindIndex(item0 => item0.m_Plant == plant); if (index != -1) { DestroyImmediate(m_PlantGrids[index].gameObject); m_PlantGrids.RemoveAt(index); m_PlantPart.m_Root.repositionNow = true; } } }
void RPC_S2C_CLN_PlantClean(uLink.BitStream stream, uLink.NetworkMessageInfo info) { /*int farmId = */ stream.Read <int>(); FarmPlantLogic plant = stream.Read <FarmPlantLogic>(); CSMgCreator creator = MultiColonyManager.GetCreator(TeamId); if (creator == null || creator.Assembly == null) { return; } CSFarm farm = creator.Assembly.Farm; farm.RestoreCleaningPlant(plant); }
public void InitPlant(FarmPlantLogic addPlant) { addPlant._PlantType = addPlant.mPlantInfo.mTypeID; addPlant.mLife = 100f; addPlant.mPutOutGameTime = GameTime.Timer.Second; addPlant.mWater = addPlant.mPlantInfo.mDefaultWater; addPlant.mClean = addPlant.mPlantInfo.mDefaultClean; addPlant.mDead = false; addPlant.mGrowTimeIndex = 0; IntVector3 safePos = new IntVector3(addPlant.transform.position + 0.1f * Vector3.down); addPlant.mTerrianType = VFVoxelTerrain.self.Voxels.SafeRead(safePos.x, safePos.y, safePos.z).Type; addPlant.InitGrowRate(0); addPlant.InitUpdateTime(); }
void RPC_S2C_CLN_PlantUpdateInfo(uLink.BitStream stream, uLink.NetworkMessageInfo info) { int objId = stream.Read <int> (); double life = stream.Read <double> (); double water = stream.Read <double> (); double clean = stream.Read <double> (); FarmPlantLogic plant = FarmManager.Instance.GetPlantByItemObjID(objId); if (plant != null) { plant.mLife = life; plant.mWater = water; plant.mClean = clean; } }
//[Obsolete] void RPC_S2C_Plant_FarmInfo(uLink.BitStream stream, uLink.NetworkMessageInfo info) { byte[] data = stream.Read <byte[]> (); List <FarmPlantInitData> initList = FarmManager.Instance.ImportPlantData(data); foreach (FarmPlantInitData plantData in initList) { ItemObject itemObj = ItemMgr.Instance.Get(plantData.mPlantInstanceId); DragArticleAgent dragItem = DragArticleAgent.Create(itemObj.GetCmpt <Drag>(), plantData.mPos, Vector3.one, plantData.mRot, plantData.mPlantInstanceId); FarmPlantLogic plant = dragItem.itemLogic as FarmPlantLogic; plant.InitDataFromPlant(plantData); FarmManager.Instance.AddPlant(plant); plant.UpdateInMultiMode(); } }
private void OnCreatePlant(FarmPlantLogic plant) { if (Assembly == null) { return; } if (!m_Plants.ContainsKey(plant.mPlantInstanceId) && Assembly.InRange(plant.mPos)) { m_Plants.Add(plant.mPlantInstanceId, plant); if (CreatePlantEvent != null) { CreatePlantEvent(plant); } } }
// IEnumerator PlantUpdate(List<FarmPlantLogic> pList,List<CSCreator> creators){ // int counter=0; // // foreach (FarmPlantLogic plant in pList) // { // if(WeatherConfig.IsRaining){ // plant.GetRain(); // } // // float maxNpcRate = 0; // if(creators.Count>0){ // foreach(CSCreator creator in creators){ // CSMgCreator mCreator = creator as CSMgCreator; // if(mCreator==null) // continue; // if(creator.Assembly==null) // continue; // if(creator.Assembly.Farm==null) // continue; // if(!creator.Assembly.Farm.IsRunning) // continue; // if(creator.Assembly.Farm.FarmerGrowRate<=maxNpcRate) // continue; // maxNpcRate = creator.Assembly.Farm.FarmerGrowRate; // } // } // // if(maxNpcRate!=plant.npcGrowRate) // plant.UpdateNpcGrowRate(maxNpcRate); // else if (plant.mNextUpdateTime > 0 && plant.mNextUpdateTime < GameTime.Timer.Second) // plant.UpdateStatus(); // counter++; // if(counter>=200){ // yield return null; // } // } // } #region CALL_BACK void OnDirtyVoxel(Vector3 pos, byte terrainType) { for (int i = 0; i < 2; i++) { IntVec3 idx = new IntVec3(pos); if (mPlantHelpMap.ContainsKey(idx)) { FarmPlantLogic p = mPlantMap[mPlantHelpMap[idx]]; if (p.mTerrianType != terrainType) { p.mTerrianType = terrainType; p.UpdateGrowRate(0, false); } } } }
void OnRemovePlant(FarmPlantLogic plant) { #if NEW_CLOD_MGR foreach (KeyValuePair <int, CSCreator> kvp in m_Creators) { CSMgCreator mgCreator = kvp.Value as CSMgCreator; if (mgCreator == null) { continue; } mgCreator.m_Clod.DirtyTheClod(plant.mPos, false); } #else CSClodMgr.DirtyTheClod(plant.mPos, false); #endif }
private void PlantEventListener(FarmPlantLogic plant, int event_type) { if (!m_Plants.ContainsKey(plant.mPlantInstanceId)) { return; } if (event_type == FarmPlantLogic.cEvent_NeedWater) { if (!m_WateringIds.Contains(plant.mPlantInstanceId)) { m_WateringIds.Add(plant.mPlantInstanceId); } } else if (event_type == FarmPlantLogic.cEvent_NoNeedWater) { m_WateringIds.Remove(plant.mPlantInstanceId); } else if (event_type == FarmPlantLogic.cEvent_NeedClean) { if (!m_CleaningIds.Contains(plant.mPlantInstanceId)) { m_CleaningIds.Add(plant.mPlantInstanceId); } } else if (event_type == FarmPlantLogic.cEvent_NoNeedClean) { m_CleaningIds.Remove(plant.mPlantInstanceId); } else if (event_type == FarmPlantLogic.cEvent_Dead) { if (!m_DeadIds.Contains(plant.mPlantInstanceId)) { m_DeadIds.Add(plant.mPlantInstanceId); } } else if (event_type == FarmPlantLogic.cEvent_Ripe) { if (!m_RipedIds.Contains(plant.mPlantInstanceId)) { m_RipedIds.Add(plant.mPlantInstanceId); } } }
public override void OnConstruct() { base.OnConstruct(); mPlant = GetComponentInParent <FarmPlantLogic>(); //mPlant = FarmManager.Instance.GetPlantByItemObjID(mItemObj.instanceId); if (null == mPlant) { //mPlant = FarmManager.Instance.CreatePlant(mItemObj.instanceId, PlantInfo.GetPlantInfoByItemId(protoId).mTypeID, transform.position); //mPlant.mTerrianType = mTerrainType; //mPlant.UpdateGrowRate(0); Debug.LogError(transform.position + "No logic layer!"); return; } if (GetComponent <DragItemMousePickPlant>() == null) { gameObject.AddComponent <DragItemMousePickPlant>(); } //mPlant.mPos = transform.position; mGrowTimeIndex = mPlant.mGrowTimeIndex; mIsDead = mPlant.mDead; ResetModel(mPlant.mGrowTimeIndex, mPlant.mPlantInfo); UpdatModel(); }
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); } } }