Exemplo n.º 1
0
        public bool AddServant(NpcCmpt follower)
        {
            if (ContainsServant(follower))
            {
                return(false);
            }

            for (int i = 0; i < mFollowers.Length; i++)
            {
                if (null == mFollowers[i])
                {
                    mFollowers[i] = follower;

                    if (UINPCfootManMgr.Instance != null)
                    {
                        UINPCfootManMgr.Instance.GetFollowerAlive();
                    }
                    //DoFollow(follower.Entity.GetCmpt<FollowCmpt>());
                    follower.SetServantLeader(this);
                    follower.NpcControlCmdId = 19;
                    PeEntityCreator.RecruitRandomNpc(follower.Entity);
                    InitSleepInfo(mFollowers[i]);
                    if (UIMissionMgr.Instance != null)
                    {
                        UIMissionMgr.Instance.DeleteMission(follower.Entity);
                    }
                    changeEventor.Dispatch(new ServantChanged(true, follower.Entity));

                    //lz-2016.08.22 玩家召一个仆从
                    InGameAidData.CheckGetServant(follower.Entity.Id);
                    //lw:完成成就同生共死
                    SteamAchievementsSystem.Instance.OnGameStateChange(Eachievement.Eleven);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public bool AddServant(NpcCmpt follower, int index)
        {
            if (ContainsServant(follower))
            {
                return(false);
            }

            bool isFull = true;

            for (int i = 0; i < mFollowers.Length; i++)
            {
                if (mFollowers[i] == null)
                {
                    isFull = false;
                    break;
                }
            }
            if (isFull)
            {
                return(false);
            }

            for (int i = 0; i < mFollowers.Length; i++)
            {
                if (i == index)
                {
                    if (mFollowers[i] != null)
                    {
                        List <NpcCmpt> fList = mFollowers.Where(a => a != null).ToList();
                        fList.Insert(i, follower);
                        if (fList.Count < MaxFollower)
                        {
                            for (int j = 0; j < MaxFollower - fList.Count; j++)
                            {
                                fList.Add(null);
                            }
                        }
                        mFollowers = fList.ToArray();
                    }
                    else
                    {
                        mFollowers[i] = follower;
                    }

                    if (UINPCfootManMgr.Instance != null)
                    {
                        UINPCfootManMgr.Instance.GetFollowerAlive();
                    }


                    //log: lz-2016.05.11  这里移除一个仆从的时候进行排序,让前面不要空出位置
                    mFollowers = mFollowers.OrderBy(a => a == null).ToArray();
                    //DoFollow(follower.Entity.GetCmpt<FollowCmpt>());
                    follower.SetServantLeader(this);
                    follower.NpcControlCmdId = 19;
                    PeEntityCreator.RecruitRandomNpc(follower.Entity);
                    InitSleepInfo(follower);
                    changeEventor.Dispatch(new ServantChanged(false, follower.Entity));
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
    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);
    }
Exemplo n.º 4
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);
    }