Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    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);
    }