float GetFastDistance(long id) { IEntity en = EntityManager.Instance().GetEntity(id); if (en == null) { return(0.0f); } if (EntitySystem.m_ClientGlobal.MainPlayer == null) { return(0.0f); } Vector3 pos = EntitySystem.m_ClientGlobal.MainPlayer.GetPos(); pos.y = 0.0f; Vector3 otherPos = en.GetPos(); otherPos.y = 0.0f; float dx = pos.x - otherPos.x; float dz = pos.z - otherPos.z; return(dx * dx + dz * dz); }
//系统更新 public void Update(float dt) { EntityManager.Instance().Update(dt); // 根据同屏人数设置人物 EntityManager.Instance().UpdateMaxPlayer(MaxPlayer); // 更新强制移动标识 UpdateForceMove(); }
public void RemoveEntity(IEntity en) { if (en != null) { //先发送事件在删除。因为触发事件中有可能会获取该实体 Client.stRemoveEntity removeEntiy = new Client.stRemoveEntity(); removeEntiy.uid = en.GetUID(); Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_REMOVEENTITY, removeEntiy); EntityManager.Instance().RemoveEntity(en); } }
public INPC FindNPCByBaseId(int baseId, bool nearest = false) { allNpcList.Clear(); npcList.Clear(); EntityManager.Instance().FindAllEntity <INPC>(ref allNpcList); for (int i = 0; i < allNpcList.Count; ++i) { INPC npc = allNpcList[i]; if (npc.GetProp((int)EntityProp.BaseID) == baseId && !npc.IsDead()) { if (!nearest) { return(npc); } else { npcList.Add(npc); } } } if (m_ClientGlobal.MainPlayer == null) { return(null); } Vector3 pos = m_ClientGlobal.MainPlayer.GetPos(); INPC getNpc = null; float fMinDis = 5000000.0f; for (int i = 0; i < npcList.Count; i++) { float sqrlen = (npcList[i].GetPos() - pos).sqrMagnitude; if (sqrlen < fMinDis) { fMinDis = sqrlen; getNpc = npcList[i]; } } return(getNpc); }
//------------------------------------------------------------------------------------------------------- /** * @brief 清理 退出时清理数据 * @param bFlag 标识是否清理主角 true清理主角 */ public void Clear(bool bFlag = false) { if (m_ClientGlobal == null) { return; } long[] ids = EntityManager.Instance().entityID; if (ids == null) { return; } if (m_ClientGlobal.MainPlayer == null) { return; } long mainid = m_ClientGlobal.MainPlayer.GetUID(); for (int i = 0; i < ids.Length; ++i) { if (ids[i] == mainid && !bFlag) { continue; } // 物品类不删除 IEntity en = FindEntity(ids[i]); // EntityType_Pet 是宠物数据对象,只是自己的 if (!bFlag && (en.GetEntityType() == EntityType.EntityType_Item || en.GetEntityType() == EntityType.EntityType_Puppet || en.GetEntityType() == EntityType.EntityType_Pet)) //忽略EntityType_Puppet因为RenderTextuerObj中有使用Puppet { continue; } // 删除实体 RemoveEntity(ids[i]); } }
private void OnEvent(int nEventID, object param) { // 地表没有创建成功的时候,就已经收到了角色和NPC的创建 这里重新设置位置和地表做碰撞 if (nEventID == (int)GameEventID.SYSTEM_LOADSCENECOMPELETE) { //List<IPlayer> lstPlayer; FindAllEntity <IPlayer>(ref lstPlayer); for (int i = 0; i < lstPlayer.Count; ++i) { Vector3 pos = lstPlayer[i].GetPos(); lstPlayer[i].SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos); } lstPlayer.Clear(); //List<INPC> lstNPC; FindAllEntity <INPC>(ref lstNPC); for (int i = 0; i < lstNPC.Count; ++i) { Vector3 pos = lstNPC[i].GetPos(); lstNPC[i].SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos); } lstNPC.Clear(); //List<IBox> lstBox; FindAllEntity <IBox>(ref lstBox); for (int i = 0; i < lstBox.Count; ++i) { Vector3 pos = lstBox[i].GetPos(); pos.y += 0.2f; lstBox[i].SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos); } lstBox.Clear(); //List<IRobot> lstRobot; FindAllEntity <IRobot>(ref lstRobot); for (int i = 0; i < lstRobot.Count; ++i) { Vector3 pos = lstRobot[i].GetPos(); lstRobot[i].SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos); } lstRobot.Clear(); // 请求同步移动时间 ReqMoveServerTime(); } else if (nEventID == (int)GameEventID.RECONNECT_SUCESS) // 重新连接成功 { stReconnectSucess st = (stReconnectSucess)param; if (st.isLogin) { Clear(false); // 不清理除主角 // 请求同步移动时间 ReqMoveServerTime(); } else {//强制同步 GameCmd.stUserMoveMoveUserCmd_C cmd = new GameCmd.stUserMoveMoveUserCmd_C(); cmd.client_time = 0; List <GameCmd.Pos> list = new List <GameCmd.Pos>(); GameCmd.Pos pp = new GameCmd.Pos(); pp.x = 0; pp.y = 0; list.Add(pp); cmd.poslist.AddRange(list); m_ClientGlobal.netService.Send(cmd); } } else if (nEventID == (int)GameEventID.NETWORK_CONNECTE_CLOSE)// 网络断开 { if (m_ClientGlobal.MainPlayer != null) { m_ClientGlobal.MainPlayer.SendMessage(EntityMessage.EntityCommand_RemoveLinkAllEffect); } } else if (nEventID == (int)GameEventID.ENTITYSYSTEM_ENTITYDEAD) // 实体死亡 { stEntityDead ed = (stEntityDead)param; if (m_ClientGlobal.IsMainPlayer(ed.uid)) { Engine.IRenderSystem rs = Engine.RareEngine.Instance().GetRenderSystem(); if (rs != null) { rs.EnableGray(true); } } IEntity en = FindEntity(ed.uid); if (en != null) { AddEffectOnEntity(en, false); } } else if (nEventID == (int)GameEventID.ENTITYSYSTEM_RELIVE) { stEntityRelive ed = (stEntityRelive)param; if (m_ClientGlobal.IsMainPlayer(ed.uid)) { Engine.IRenderSystem rs = Engine.RareEngine.Instance().GetRenderSystem(); if (rs != null) { rs.EnableGray(false); } } IEntity en = FindEntity(ed.uid); if (en != null) { AddEffectOnEntity(en, true); } } else if (nEventID == (int)GameEventID.PLAYER_LOGIN_SUCCESS) { Engine.IRenderSystem rs = Engine.RareEngine.Instance().GetRenderSystem(); if (rs != null) { rs.EnableGray(false); } // 请求同步移动时间 ReqMoveServerTime(); } else if (nEventID == (int)GameEventID.ENTITYSYSTEM_LEAVEMAP) // 离开地图 { // 清理地图上所有对象 Clear(false); // 切地图时让主角停止移动 IPlayer mainPlayer = EntitySystem.m_ClientGlobal.MainPlayer; if (mainPlayer != null) { bool ismoving = (bool)mainPlayer.SendMessage(Client.EntityMessage.EntityCommand_IsMove, null); if (ismoving) { mainPlayer.SendMessage(Client.EntityMessage.EntityCommand_StopMove, mainPlayer.GetPos()); } } } else if (nEventID == (int)GameEventID.ENTITYSYSTEM_CHANGEAREA) // 区域变化 动作处理 { stEntityChangeArea changeArea = (stEntityChangeArea)param; IEntity en = FindEntity(changeArea.uid); if (en != null && en.GetEntityType() == EntityType.EntityType_Player) { string strCurAni = (string)en.SendMessage(EntityMessage.EntityCommand_GetCurAni, null); bool bChangeArea = false; if (changeArea.eType == MapAreaType.Safe || changeArea.eType == MapAreaType.Fish) { if (strCurAni == EntityAction.Stand_Combat) { strCurAni = EntityAction.Stand; bChangeArea = true; } if (strCurAni == EntityAction.Run_Combat) { strCurAni = EntityAction.Run; bChangeArea = true; } } else { if (strCurAni == EntityAction.Stand) { strCurAni = EntityAction.Stand_Combat; bChangeArea = true; } if (strCurAni == EntityAction.Run) { strCurAni = EntityAction.Run_Combat; bChangeArea = true; } } if (bChangeArea) { PlayAni anim_param = new PlayAni(); anim_param.strAcionName = strCurAni; anim_param.fSpeed = 1; anim_param.nStartFrame = 0; anim_param.nLoop = -1; anim_param.fBlendTime = 0.1f; en.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param); } } } else if (nEventID == (int)GameEventID.ENTITYSYSTEM_CREATEENTITY) { stCreateEntity create = (stCreateEntity)param; IEntity en = FindEntity(create.uid); if (en != null) { EntityManager.Instance().OnCreateEntity(en); } } }
public IEntity FindEntity(long uid) { return(EntityManager.Instance().GetEntity(uid)); }
public ISoil FindSoil(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_Soil, uid); return((ISoil)EntityManager.Instance().GetEntity(id)); }
public IMinerals FindMinerals(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_Minerals, uid); return((IMinerals)EntityManager.Instance().GetEntity(id)); }
public ITree FindTree(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_Tree, uid); return((ITree)EntityManager.Instance().GetEntity(id)); }
public IAnimal FindAnimal(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_Animal, uid); return((IAnimal)EntityManager.Instance().GetEntity(id)); }
private IEntity CreateEntityObj(EntityType etype, EntityCreateData data) { IEntity en = null; switch (etype) { case EntityType.EntityType_Player: { Player player = new Player(); if (player != null) { player.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(player); if (data.bMainPlayer) { EntitySystem.m_ClientGlobal.MainPlayer = player; } player.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = player; break; } case EntityType.EntityType_Monster: { Monster monster = new Monster(); if (monster != null) { monster.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(monster); monster.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = monster; break; } case EntityType.EntityType_NPC: { NPC npc = new NPC(); if (npc != null) { npc.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(npc); npc.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = npc; break; } case EntityType.EntityTYpe_Robot: { Robot robot = new Robot(); if (robot != null) { robot.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(robot); robot.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = robot; break; } case EntityType.EntityType_Item: // 物品 { Item item = new Item(); if (item != null) { item.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(item); item.Create(data, ColliderCheckType.ColliderCheckType_null); } en = item; break; } case EntityType.EntityType_Pet: // 宠物 { Pet pet = new Pet(); if (pet != null) { pet.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(pet); pet.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = pet; break; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// // 家园对象 case EntityType.EntityType_Plant: // 植物 { Plant plant = new Plant(); if (plant != null) { plant.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(plant); plant.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = plant; break; } case EntityType.EntityType_Animal: // 动物 { Animal animal = new Animal(); if (animal != null) { animal.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(animal); animal.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = animal; break; } case EntityType.EntityType_Tree: // 许愿树 { Tree tree = new Tree(); if (tree != null) { tree.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(tree); tree.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = tree; break; } case EntityType.EntityType_Minerals: // 矿产 { Minerals mine = new Minerals(); if (mine != null) { mine.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(mine); mine.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = mine; break; } case EntityType.EntityType_Soil: // 土地 { Soil soil = new Soil(); if (soil != null) { soil.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(soil); soil.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = soil; break; } case EntityType.EntityType_Puppet: // 木偶 { Puppet puppet = new Puppet(); if (puppet != null) { puppet.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(puppet); puppet.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = puppet; break; } case EntityType.EntityType_Box: { //UnityEngine.Sprite sp; Box box = new Box(); if (box != null) { box.SetUID(MakeUID(etype, data.ID)); EntityManager.Instance().AddEntity(box); box.Create(data, ColliderCheckType.ColliderCheckType_CloseTerrain | ColliderCheckType.ColliderCheckType_Wall); } en = box; break; } } //if(en!=null) //{ // Client.stCreateEntity createEntity = new Client.stCreateEntity(); // createEntity.uid = en.GetUID(); // Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_CREATEENTITY, createEntity); //} return(en); }
public IItem FindItem(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_Item, uid); return((IItem)EntityManager.Instance().GetEntity(id)); }
public void RemoveEntity(long uid) { IEntity en = EntityManager.Instance().GetEntity(uid); RemoveEntity(en); }
public IRobot FindRobot(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityTYpe_Robot, uid); return((IRobot)EntityManager.Instance().GetEntity(id)); }
public IBox FindBox(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_Box, uid); return((IBox)EntityManager.Instance().GetEntity(id)); }
public INPC FindNPC(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_NPC, uid); return((INPC)EntityManager.Instance().GetEntity(id)); }
public IMonster FindMonster(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_Monster, uid); return((IMonster)EntityManager.Instance().GetEntity(id)); }
public void FindAllEntity <T>(ref List <T> lst) { EntityManager.Instance().FindAllEntity <T>(ref lst); }
public IPlant FindPlant(uint uid) { long id = EntityFactory.Instance().MakeUID(EntityType.EntityType_Plant, uid); return((IPlant)EntityManager.Instance().GetEntity(id)); }
public List <long> GetEntityUids() { return(EntityManager.Instance().GetEntityUids()); }
// 显示实体 public void ShowEntity(bool bShow) { EntityManager.Instance().ShowEntity(bShow); }