public bool RemoveServant(int index) { if (ValidateIndex(index)) { //DoDefollow(mFollowers[index].Entity.GetCmpt<FollowCmpt>()); PeEntity servant = mFollowers[index].Entity; mFollowers[index].NpcControlCmdId = 1; mSleepAction.startSleepEvt -= mFollowers[index].OnLeaderSleep; mSleepAction.endSleepEvt -= mFollowers[index].OnLeaderEndSleep; mFollowers[index].RemoveSleepBuff(); mFollowers[index].SetServantLeader(null); if (mFollowers[index].Entity != null && mFollowers[index].Entity.proto == EEntityProto.RandomNpc) { PeEntityCreator.ExileRandomNpc(mFollowers[index].Entity); } mFollowers[index] = null; //log: lz-2016.05.11 这里移除一个仆从的时候进行排序,让前面不要空出位置 mFollowers = mFollowers.OrderBy(a => a == null).ToArray(); changeEventor.Dispatch(new ServantChanged(false, servant)); if (UINPCfootManMgr.Instance != null) { UINPCfootManMgr.Instance.GetFollowerAlive(); } return(true); } return(false); }
BehaveResult Init(Tree sender) { if (!GetData <Data>(sender, ref m_Data)) { return(BehaveResult.Failure); } if (m_Data.followEntity == null) { return(BehaveResult.Failure); } if (!Enemy.IsNullOrInvalid(attackEnemy)) { return(BehaveResult.Failure); } PeEntityCreator.InitRobotInfo(entity, m_Data.followEntity); if (Random.value > m_Data.prob) { return(BehaveResult.Failure); } m_HoverPosition = GetAroundPos(); m_StartTime = Time.time; //m_LastTime = Time.time; m_Time = Random.Range(m_Data.minTime, m_Data.maxTime); return(BehaveResult.Running); }
BehaveResult Init(Tree sender) { if (!GetData <Data>(sender, ref m_Data)) { return(BehaveResult.Failure); } if (Enemy.IsNullOrInvalid(attackEnemy)) { return(BehaveResult.Failure); } if (entity.robotCmpt == null) { return(BehaveResult.Failure); } if (m_Data.followEntity == null) { return(BehaveResult.Failure); } PeEntityCreator.InitRobotInfo(entity, m_Data.followEntity); //m_StartTime = Time.time; m_Data.changrPos = true; //m_findAttack = true; //startFindPosTime = Time.time; m_AttcakPos = GetAroundPos(attackEnemy.centerPos); //m_Arrived = false; return(BehaveResult.Running); }
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); }
protected void RPC_S2C_AvatarData(uLink.BitStream stream, uLink.NetworkMessageInfo info) { CreateAi(); if (ExternId >= PeEntityCreator.HumanMonsterMask) { byte[] customData = stream.Read <byte[]>(); CustomCharactor.CustomData charactorData = new CustomCharactor.CustomData(); charactorData.Deserialize(customData); if (null != _entity) { PeEntityCreator.ApplyCustomCharactorData(_entity, charactorData); } } RPCServer(EPacketType.PT_AI_ExternData); }
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); }
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); }
// public override void OnPeMsg(EMsg msg, params object[] args) // { // switch (msg) // { // case EMsg.Lod_Collider_Destroying: // canGetAuth = false; // lastAuthId = authId; // if (hasOwnerAuth) // { //#if UNITY_EDITOR // Debug.LogFormat("<color=blue>you lost [{0}]'s authority.</color>", Id); //#endif // authId = -1; // RPCServer(EPacketType.PT_InGame_LostController); // } // ResetContorller(); // break; // case EMsg.Lod_Collider_Created: // canGetAuth = true; // if (!hasAuth) // { // RPCServer(EPacketType.PT_InGame_SetController); // } // else // { // ResetContorller(); //#if UNITY_EDITOR // PlayerNetwork p = PlayerNetwork.GetPlayer(authId); // if (null != p) // Debug.LogFormat("<color=blue>{0} got [{1}]'s authority.</color>", p.RoleName, Id); //#endif // } // break; // } // } internal void CreateAi() { _entity = PeEntityCreator.Instance.CreateMonsterNet(Id, ExternId, Vector3.zero, Quaternion.identity, Vector3.one, Scale, _buffId); if (null == _entity) { return; } if (_fixId != -1) { SceneEntityCreatorArchiver.Instance.SetEntityByFixedSpId(_fixId, _entity); // if (_entity.monster) _entity.monster.Ride(false); } _entity.monster.Ride(_canride); _viewTrans = _entity.GetCmpt <PeTrans>(); if (null == _viewTrans) { Debug.LogError("entity has no ViewCmpt"); return; } _viewTrans.position = transform.position; _move = _entity.GetCmpt <Motion_Move>(); NetCmpt net = _entity.GetCmpt <NetCmpt>(); if (null == net) { net = _entity.Add <NetCmpt>(); } net.network = this; MonsterProtoDb.Item data = MonsterProtoDb.Get(ExternId); if (null == data) { gameObject.name = string.Format("TemplateId:{0}, Id:{1}", ExternId, Id); } else { gameObject.name = string.Format("{0}, TemplateId:{1}, Id:{2}", data.name, ExternId, Id); } if (-1 != _groupId) { AIGroupNetWork.OnMonsterAdd(_groupId, this, _entity); } if (-1 != _tdId) { AiTowerDefense.OnMonsterAdd(_tdId, this, _entity); if (_entity.monster) { _entity.monster.Ride(false); } } if (-1 != _dungeonId) { _entity.SetAttribute(AttribType.CampID, DungeonMonster.CAMP_ID); _entity.SetAttribute(AttribType.DamageID, DungeonMonster.DAMAGE_ID); if (_entity.monster) { _entity.monster.Ride(false); } } if (-1 != _colorType) { PeEntityCreator.InitMonsterSkinRandomNet(_entity, _colorType); } if (-1 != _playerId) { _entity.SetAttribute(AttribType.DefaultPlayerID, _playerId); } OnSpawned(_entity.GetGameObject()); if (_entity.Race == ERace.Mankind && _entity.proto == EEntityProto.Monster) { _move.AddNetTransInfo(transform.position, rot.eulerAngles, _move.speed, GameTime.Timer.Second); } else { _move.NetMoveTo(transform.position, Vector3.zero); } // if (_move is Motion_Move_Motor) //(_move as Motion_Move_Motor).NetMoveTo( transform.position,Vector3.zero); }
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); }