public override void RemoveNpc(PeEntity npc) { CSPersonnel csp = CSMain.GetColonyNpc(npc.Id); if (csp == null) { Debug.LogWarning("The npc you want to kick out is not a recruit."); return; } // Remove data csp.RemoveData(); if (csp.Dwellings != null) { csp.Dwellings.RemoveNpc(csp); } if (csp.WorkRoom != null) { csp.WorkRoom.RemoveWorker(csp); } //CSBehaveMgr.RemoveQueue(npc.Id); m_RandomNpcs.Remove(csp); m_MainNpcs.Remove(csp); ExecuteEventPersonnel(CSConst.cetRemovePersonnel, csp); //_decreaseStateNum(po.m_Personnel, po.m_Personnel.State); _decreaseOccupationNum(csp, csp.Occupation); _decreaseWorkModeNum(csp, csp.m_WorkMode); csp.m_Creator = null; if (npc.IsRandomNpc()) { PeEntityCreator.ExileRandomNpc(npc); } else { PeEntityCreator.ExileMainNpc(npc); } csp.UpdateNpcCmpt(); PeNpcGroup.Instance.OnRemoveCsNpc(npc); }
public bool AddNpcInMultiMode(PeEntity npc, int dwellingId, 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(); // Have enough dwellings? 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(); //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 == dwellingId) // { // dw.AddNpcs(personnel); // break; // } //} if (m_CommonEntities.ContainsKey(dwellingId)) { CSDwellings dw = m_CommonEntities[dwellingId] as CSDwellings; if (dw != null) { dw.AddNpcs(personnel); } } if (personnel.Dwellings == null) { Debug.Log("There is not enough Dwellings for this NPC"); personnel.RemoveData(); return(false); } } //RandomNpc if (npc.IsRandomNpc()) { m_RandomNpcs.Add(personnel); } // Main Npc else { m_MainNpcs.Add(personnel); } ExecuteEventPersonnel(CSConst.cetAddPersonnel, personnel); _increaseOccupationNum(personnel, personnel.Occupation); _increaseWorkModeNum(personnel, personnel.m_WorkMode); personnel.UpdateNpcCmpt(); return(true); }
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 override bool AddNpc(PeEntity npc, 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(); // Have enough dwellings? 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.AddNpcs(personnel)) { // dwellingsID = dw.ID; break; } } if (personnel.Dwellings == null) { Debug.Log("There is not enough Dwellings for this NPC"); personnel.RemoveData(); return(false); } } //RandomNpc if (npc.IsRandomNpc()) { m_RandomNpcs.Add(personnel); PeEntityCreator.RecruitRandomNpc(npc); } // Main Npc else { m_MainNpcs.Add(personnel); PeEntityCreator.RecruitMainNpc(npc); } //colony add npc talk if (npc.NpcCmpt != null) { npc.NpcCmpt.SendTalkMsg((int)ENpcTalkType.Conscribe_succeed, 0, ENpcSpeakType.Both); } //set npc fixpiont near colony //if (m_Assembly.Position != Vector3.zero && npc.NpcCmpt != null) // npc.NpcCmpt.SetFixPos(m_Assembly.Position); ExecuteEventPersonnel(CSConst.cetAddPersonnel, personnel); _increaseOccupationNum(personnel, personnel.Occupation); _increaseWorkModeNum(personnel, personnel.m_WorkMode); personnel.UpdateNpcCmpt(); return(true); }