void RPC_S2C_CLN_InitData(uLink.BitStream stream, uLink.NetworkMessageInfo info) { int dwellingsID = stream.Read <int>(); Vector3 guardPos = stream.Read <Vector3>(); int occupation = stream.Read <int>(); int state = stream.Read <int>(); int workMode = stream.Read <int>(); int workRoomID = stream.Read <int>(); bool isProcessing = stream.Read <bool>(); int processingIndex = stream.Read <int>(); int trainerType = stream.Read <int>(); int trainingType = stream.Read <int>(); bool isTraining = stream.Read <bool>(); CSPersonnelData cspd = new CSPersonnelData(); cspd.ID = Id; cspd.dType = CSConst.dtPersonnel; cspd.m_State = state; cspd.m_Occupation = occupation; cspd.m_WorkMode = workMode; cspd.m_DwellingsID = dwellingsID; //--to do:remove cspd.m_GuardPos = guardPos; cspd.m_WorkRoomID = workRoomID; cspd.m_IsProcessing = isProcessing; cspd.m_ProcessingIndex = processingIndex; cspd.m_TrainerType = trainerType; cspd.m_TrainingType = trainingType; cspd.m_IsTraining = isTraining; //--to do: new attribute StartCoroutine(InitDataRoutine(cspd)); }
IEnumerator InitDataRoutine(CSPersonnelData cspd) { PeEntity npc = null; while (true) { npc = EntityMgr.Instance.Get(Id); if (npc == null) { yield return(new WaitForSeconds(0.5f)); } else { break; } } CSCreator creator = null; while (true) { creator = MultiColonyManager.GetCreator(TeamId); if (creator == null) { yield return(new WaitForSeconds(0.5f)); } else { break; } } ((CSMgCreator)creator).AddNpc(npc, cspd, true); // if (TeamId == PlayerNetwork.MainPlayer.TeamId) // { // CSCreator creator = CSMain.GetCreator(CSConst.ciDefMgCamp); // while (creator == null) // { // yield return new WaitForSeconds(0.5f); // creator = MultiColonyManager.GetCreator(CSConst.ciDefMgCamp); // } // // // ((CSMgCreator)creator).AddNpc(npc, cspd, true); // } // else // { // CSCreator creator = CSMain.GetCreator(TeamId); // while (creator == null) // { // yield return new WaitForSeconds(0.5f); // creator = MultiColonyManager.GetCreator(TeamId); // } // // ((CSMgCreator)creator).AddNpc(npc, cspd, true); // } //m_PersonnelDatas.Add(cspd.ID, cspd); }
public void CreateData(CSPersonnelData data) { bool isNew = m_Creator.m_DataInst.AddData(data); m_Data = data; if (isNew && (!PeGameMgr.IsMulti)) { } else { Dwellings = m_Creator.GetCommonEntity(m_Data.m_DwellingsID) as CSDwellings; if (Dwellings != null) { Dwellings.AddNpcs(this); } CSCommon workRoom = m_Creator.GetCommonEntity(m_Data.m_WorkRoomID); //if (workRoom != null && workRoom.AddWorker(this)) //m_BrainMemory.Add(workRoom); if (workRoom != null) { WorkRoom = workRoom; } //_createGuardTriggerGo (); //m_GuardTrigger.Pos = Data.m_GuardPos; if (processingIndex >= 0) { if (m_ProcessingIndexInitListenner != null) { m_ProcessingIndexInitListenner(this); } } //if (m_Dwellings != null && m_Dwellings.Assembly != null) //{ // if ( !m_Dwellings.Assembly.InRange(m_Pos) ) // _state = CSConst.pstUnknown; //} } //--to do: wait //m_Skill.RegisterListener(OnNPCEventTrigger); }
// <CETC> Assign Record Data public bool AssignData(int id, int type, ref CSDefaultData refData) { // Personnel if (type == CSConst.dtPersonnel) { if (m_PersonnelDatas.ContainsKey(id)) { Debug.Log("The Personnel Data ID [" + id.ToString() + "] is exist."); refData = m_PersonnelDatas[id]; return(false); } else { refData = new CSPersonnelData(); refData.ID = id; m_PersonnelDatas.Add(id, refData as CSPersonnelData); return(true); } } // Object else { if (m_ObjectDatas.ContainsKey(id)) { Debug.Log("The Object data ID [" + id.ToString() + "] is exist."); refData = m_ObjectDatas[id]; return(false); } else { switch (type) { case CSConst.dtAssembly: refData = new CSAssemblyData(); break; case CSConst.dtStorage: refData = new CSStorageData(); break; case CSConst.dtEngineer: refData = new CSEngineerData(); break; case CSConst.dtEnhance: refData = new CSEnhanceData(); break; case CSConst.dtRepair: refData = new CSRepairData(); break; case CSConst.dtRecyle: refData = new CSRecycleData(); break; case CSConst.dtppCoal: refData = new CSPPCoalData(); break; case CSConst.dtDwelling: refData = new CSDwellingsData(); break; case CSConst.dtFactory: refData = new CSFactoryData(); break; case CSConst.dtProcessing: refData = new CSProcessingData(); break; default: //refData = new CSDefaultData(); refData = new CSObjectData(); break; } refData.ID = id; m_ObjectDatas.Add(id, refData as CSObjectData); return(true); } } }
// <CETC> Import type Data public void Import(byte[] buffer) { if (buffer == null) { return; } if (buffer.Length < 8) { return; } MemoryStream ms = new MemoryStream(buffer); BinaryReader r = new BinaryReader(ms); int version = r.ReadInt32(); if (VERSION != version) { Debug.LogWarning("The version of ColonyrecordMgr is newer than the record."); } switch (version) { #region Version_0x0101 case 0x0101: { int rcnt = r.ReadInt32(); for (int i = 0; i < rcnt; i++) { CSObjectData csdd = null; int type = r.ReadInt32(); switch (type) { case CSConst.dtAssembly: { csdd = new CSAssemblyData(); CSAssemblyData cssa = csdd as CSAssemblyData; _readCSObjectData(r, cssa, version); cssa.m_Level = r.ReadInt32(); cssa.m_UpgradeTime = r.ReadSingle(); cssa.m_CurUpgradeTime = r.ReadSingle(); } break; case CSConst.dtppCoal: { csdd = new CSPPCoalData(); CSPPCoalData csppc = csdd as CSPPCoalData; _readCSObjectData(r, csppc, version); csppc.m_CurWorkedTime = r.ReadSingle(); csppc.m_WorkedTime = r.ReadSingle(); } break; case CSConst.dtStorage: { csdd = new CSStorageData(); CSStorageData cssd = csdd as CSStorageData; _readCSObjectData(r, cssd, version); int itemCnt = r.ReadInt32(); for (int j = 0; j < itemCnt; j++) { cssd.m_Items.Add(r.ReadInt32(), r.ReadInt32()); } } break; case CSConst.dtEngineer: { csdd = new CSEngineerData(); CSEngineerData csed = csdd as CSEngineerData; _readCSObjectData(r, csed, version); csed.m_EnhanceItemID = r.ReadInt32(); csed.m_CurEnhanceTime = r.ReadSingle(); csed.m_EnhanceTime = r.ReadSingle(); csed.m_PatchItemID = r.ReadInt32(); csed.m_CurPatchTime = r.ReadSingle(); csed.m_PatchTime = r.ReadSingle(); csed.m_RecycleItemID = r.ReadInt32(); csed.m_CurRecycleTime = r.ReadSingle(); csed.m_RecycleTime = r.ReadSingle(); } break; case CSConst.dtEnhance: { csdd = new CSEnhanceData(); CSEnhanceData cseh = csdd as CSEnhanceData; _readCSObjectData(r, cseh, version); cseh.m_ObjID = r.ReadInt32(); cseh.m_CurTime = r.ReadSingle(); cseh.m_Time = r.ReadSingle(); } break; case CSConst.dtRepair: { csdd = new CSRepairData(); CSRepairData csrd = csdd as CSRepairData; _readCSObjectData(r, csrd, version); csrd.m_ObjID = r.ReadInt32(); csrd.m_CurTime = r.ReadSingle(); csrd.m_Time = r.ReadSingle(); } break; case CSConst.dtRecyle: { csdd = new CSRecycleData(); CSRecycleData csrd = csdd as CSRecycleData; _readCSObjectData(r, csrd, version); csrd.m_ObjID = r.ReadInt32(); csrd.m_CurTime = r.ReadSingle(); csrd.m_Time = r.ReadSingle(); } break; case CSConst.dtDwelling: { csdd = new CSDwellingsData(); CSDwellingsData csdw = csdd as CSDwellingsData; _readCSObjectData(r, csdw, version); } break; default: csdd = new CSObjectData(); break; } m_ObjectDatas.Add(csdd.ID, csdd); } rcnt = r.ReadInt32(); for (int i = 0; i < rcnt; i++) { CSPersonnelData cspd = new CSPersonnelData(); cspd.ID = r.ReadInt32(); cspd.dType = r.ReadInt32(); cspd.m_State = r.ReadInt32(); cspd.m_DwellingsID = r.ReadInt32(); cspd.m_WorkRoomID = r.ReadInt32(); m_PersonnelDatas.Add(cspd.ID, cspd); } } break; #endregion case 0x0102: case 0x0103: { int rcnt = r.ReadInt32(); for (int i = 0; i < rcnt; i++) { CSObjectData csdd = null; int type = r.ReadInt32(); switch (type) { case CSConst.dtAssembly: { csdd = new CSAssemblyData(); CSAssemblyData cssa = csdd as CSAssemblyData; _readCSObjectData(r, cssa, version); cssa.m_Level = r.ReadInt32(); cssa.m_UpgradeTime = r.ReadSingle(); cssa.m_CurUpgradeTime = r.ReadSingle(); } break; case CSConst.dtppCoal: { csdd = new CSPPCoalData(); CSPPCoalData csppc = csdd as CSPPCoalData; _readCSObjectData(r, csppc, version); int cnt = r.ReadInt32(); for (int j = 0; j < cnt; j++) { csppc.m_ChargingItems.Add(r.ReadInt32(), r.ReadInt32()); } csppc.m_CurWorkedTime = r.ReadSingle(); csppc.m_WorkedTime = r.ReadSingle(); } break; case CSConst.dtStorage: { csdd = new CSStorageData(); CSStorageData cssd = csdd as CSStorageData; _readCSObjectData(r, cssd, version); int itemCnt = r.ReadInt32(); for (int j = 0; j < itemCnt; j++) { cssd.m_Items.Add(r.ReadInt32(), r.ReadInt32()); } } break; case CSConst.dtEngineer: { csdd = new CSEngineerData(); CSEngineerData csed = csdd as CSEngineerData; _readCSObjectData(r, csed, version); csed.m_EnhanceItemID = r.ReadInt32(); csed.m_CurEnhanceTime = r.ReadSingle(); csed.m_EnhanceTime = r.ReadSingle(); csed.m_PatchItemID = r.ReadInt32(); csed.m_CurPatchTime = r.ReadSingle(); csed.m_PatchTime = r.ReadSingle(); csed.m_RecycleItemID = r.ReadInt32(); csed.m_CurRecycleTime = r.ReadSingle(); csed.m_RecycleTime = r.ReadSingle(); } break; case CSConst.dtEnhance: { csdd = new CSEnhanceData(); CSEnhanceData cseh = csdd as CSEnhanceData; _readCSObjectData(r, cseh, version); cseh.m_ObjID = r.ReadInt32(); cseh.m_CurTime = r.ReadSingle(); cseh.m_Time = r.ReadSingle(); } break; case CSConst.dtRepair: { csdd = new CSRepairData(); CSRepairData csrd = csdd as CSRepairData; _readCSObjectData(r, csrd, version); csrd.m_ObjID = r.ReadInt32(); csrd.m_CurTime = r.ReadSingle(); csrd.m_Time = r.ReadSingle(); } break; case CSConst.dtRecyle: { csdd = new CSRecycleData(); CSRecycleData csrd = csdd as CSRecycleData; _readCSObjectData(r, csrd, version); csrd.m_ObjID = r.ReadInt32(); csrd.m_CurTime = r.ReadSingle(); csrd.m_Time = r.ReadSingle(); } break; case CSConst.dtDwelling: { csdd = new CSDwellingsData(); CSDwellingsData csdw = csdd as CSDwellingsData; _readCSObjectData(r, csdw, version); } break; default: csdd = new CSObjectData(); break; } m_ObjectDatas.Add(csdd.ID, csdd); } rcnt = r.ReadInt32(); for (int i = 0; i < rcnt; i++) { CSPersonnelData cspd = new CSPersonnelData(); cspd.ID = r.ReadInt32(); cspd.dType = r.ReadInt32(); cspd.m_State = r.ReadInt32(); cspd.m_DwellingsID = r.ReadInt32(); cspd.m_WorkRoomID = r.ReadInt32(); m_PersonnelDatas.Add(cspd.ID, cspd); } } break; default: break; } }
public bool AddNpc(PeEntity npc, CSPersonnelData data, bool bSetPos = false) { if (npc.IsRecruited()) { Debug.Log("This npc is already a CSPersonnel object!"); return(false); } CSPersonnel personnel = new CSPersonnel(); personnel.ID = npc.Id; personnel.NPC = npc; personnel.m_Creator = this; personnel.CreateData(data); // if (personnel.Dwellings == null) // { // if (m_Assembly == null) // { // Debug.Log("There is no assembly In the word!"); // personnel.RemoveData(); // return false; // } // // CSCommon[] dwellings = m_Assembly.m_BelongObjectsMap[CSConst.ObjectType.Dwelling].ToArray(); // int dwellingsID = 0; // if (dwellings.Length == 0) // { // Debug.Log("There is not enough Dwellings for this NPC"); // personnel.RemoveData(); // return false; // } // foreach (CSCommon csc in dwellings) // { // CSDwellings dw = csc as CSDwellings; // if(dw.ID == data.m_DwellingsID) // { // if (dw.AddNpcs(personnel)) // { // dwellingsID = dw.ID; // break; // } // else // return false; // } // } // // if (personnel.Dwellings == null) // { // Debug.Log("There is not enough Dwellings for this NPC"); // personnel.RemoveData(); // return false; // } // } // personnel.InitProcessingState(); // CSPersonnelObject po = npc.GetGameObject().AddComponent<CSPersonnelObject>(); // po.m_Personnel = personnel; // personnel.m_Object = po; //RandomNpc if (npc.IsRandomNpc()) { m_RandomNpcs.Add(personnel); PeEntityCreator.RecruitRandomNpc(npc); } // Main Npc else { m_MainNpcs.Add(personnel); PeEntityCreator.RecruitMainNpc(npc); } // Set pos if need // if (bSetPos) // { // Vector2 randomFactor = Random.insideUnitCircle; // Vector3 pos = new Vector3(m_Assembly.Position.x + 5, 1000, m_Assembly.Position.z) // + new Vector3(randomFactor.x, 0, randomFactor.y) * (m_Assembly.Radius - 10); // // // Find the Postion Y // RaycastHit hit; // if (Physics.Raycast(pos, Vector3.down, out hit, 1000, 1 << Pathea.Layer.VFVoxelTerrain)) // { // pos.y = hit.point.y + 1; // } // else // pos.y = m_Assembly.Position.y + 5; // // // } // else // { // if (personnel.Data.m_State == CSConst.pstPrepare) // personnel.Data.m_State = CSConst.pstIdle; // } // if(personnel.WorkRoom!=null) // { // if(personnel.WorkRoom.IsRunning){ // personnel.WorkRoom.UpdateDataToUI(); // } // } ExecuteEventPersonnel(CSConst.cetAddPersonnel, personnel); _increaseOccupationNum(personnel, personnel.Occupation); _increaseWorkModeNum(personnel, personnel.m_WorkMode); personnel.UpdateNpcCmpt(); return(true); }
public void CreateData() { CSDefaultData ddata = null; bool isNew = m_Creator.m_DataInst.AssignData(ID, CSConst.dtPersonnel, ref ddata); m_Data = ddata as CSPersonnelData; if (isNew) { } else { Dwellings = m_Creator.GetCommonEntity(m_Data.m_DwellingsID) as CSDwellings; Dwellings.AddNpcs(this); CSCommon workRoom = m_Creator.GetCommonEntity(m_Data.m_WorkRoomID); //if (workRoom != null && workRoom.AddWorker(this)) WorkRoom = workRoom; // _createGuardTriggerGo (); // m_GuardTrigger.Pos = Data.m_GuardPos; //init processor if (processingIndex >= 0) { if (m_ProcessingIndexChangeListenner != null) { m_ProcessingIndexChangeListenner(this, -1, processingIndex); } } // if (m_Dwellings.m_Assembly != null) // { //// _updateWorkType(-1, Data.m_WorkMode); // // // Add Soldier to all Entities and set the guard pos // // if the new work mode is Guard. // if (m_WorkMode == CSConst.pwtGuard ) // { // if (Data.m_GuardPos == Vector3.zero) // SetGuardAttr(m_Pos); // else // SetGuardAttr(Data.m_GuardPos); // } // // // Add Soldier to all Entities if the new work mode is Patrol // if (m_WorkMode == CSConst.pwtPatrol) // { // m_Dwellings.m_Assembly.AddSoldier(this); // //// Dictionary<int, CSCommon> commons = mgCreator.GetCommonEntities(); // List<CSCommon> commons = m_Dwellings.m_Assembly .GetBelongCommons(); // //// foreach (KeyValuePair<int, CSCommon> kvp in commons) //// kvp.Value.AddSoldier(this); // foreach (CSCommon common in commons) // common.AddSoldier(this); // } // } //if (m_Dwellings != null && m_Dwellings.Assembly != null) //{ // if ( !m_Dwellings.Assembly.InRange(m_Pos) ) // _state = CSConst.pstUnknown; //} } //--to do: wait //m_Npc.RegisterListener(OnNPCEventTrigger); }