public override void ClientDo(ServerConnectionWorker connectionWork)
 {
     for (int i = 0; i < list.Count; i++)
     {
         ClientEntityInfo info = list[i];
         if (info.type == EntityType.MONSTER)
         {
             MonsterInfo monsterInfo = new MonsterInfo();
             monsterInfo.aoId      = info.aoId;
             monsterInfo.monsterId = info.entityId;
             monsterInfo.position  = info.position;
             monsterInfo.isNetObj  = true;
             HasActionObjectManager.Instance.monsterManager.InitMonster(monsterInfo);
         }
         else if (info.type == EntityType.NPC)
         {
             NPCInfo npcInfo = new NPCInfo();
             npcInfo.aoId     = info.aoId;
             npcInfo.NPCId    = info.entityId;
             npcInfo.position = info.position;
             npcInfo.isNetObj = true;
             HasActionObjectManager.Instance.npcManager.InitNPC(npcInfo);
         }
         else if (info.type == EntityType.PLANT)
         {
             HasActionObjectManager.Instance.plantManager.buildPlant(info.position, (DecorationType)info.entityId, info.aoId);
         }
     }
 }
Пример #2
0
 public ClientEntity(ClientEntityInfo info)
 {
     this.aoId       = info.aoId;
     this.type       = info.type;
     this.entityId   = info.entityId;
     this.extData    = info.extData;
     this.hostPlayer = NetManager.Instance.server.playerManager.GetPlayer(info.roleId);
     InitPosition(info.position);
 }
Пример #3
0
 private void WriteClientEntityInfo(ClientEntityInfo info)
 {
     WriteInt(info.aoId);
     WriteInt(info.entityId);
     WriteInt(info.type);
     WriteInt(info.roleId);
     WriteListInt(info.extData);
     WriteVector3(info.position);
 }
Пример #4
0
        public void UpdateViewEntity()
        {
            List <int> curViewEntities = NetManager.Instance.server.entityManager.GetAroundEntity(inChunkPos, viewWidth);

            for (int i = 0; i < curViewEntities.Count; i++)
            {
                //如果原先已经包含了该玩家,那么跳过
                if (viewEntities.Contains(curViewEntities[i]))
                {
                    RemoveViewEntity(curViewEntities[i]);
                    continue;
                }
                else
                {
                    //如果看见其他怪物了,其他怪物的应用需要更新
                    ClientEntity otherEntity = NetManager.Instance.server.entityManager.GetEntity(curViewEntities[i]);
                    otherEntity.AddViewPlayer(id);

                    //通知当前玩家,有entity进入视野
                    EntityJoinViewPackage entityJoinViewPackage = PackageFactory.GetPackage(PackageType.EntityJoinView)
                                                                  as EntityJoinViewPackage;
                    ClientEntityInfo info = new ClientEntityInfo();
                    info.aoId     = otherEntity.aoId;
                    info.type     = otherEntity.type;
                    info.entityId = otherEntity.entityId;
                    info.position = otherEntity.position;
                    info.extData  = otherEntity.extData;
                    info.roleId   = otherEntity.hostPlayer == null ? -1 : otherEntity.hostPlayer.id;
                    entityJoinViewPackage.info = info;
                    this.worker.SendPackage(entityJoinViewPackage);

                    //更新当前entity所属
                    otherEntity.CheckViewHold();
                }
            }

            //剩下的怪物都是看不见的了
            for (int i = 0; i < viewEntities.Count; i++)
            {
                ClientEntity otherEntity = NetManager.Instance.server.entityManager.GetEntity(viewEntities[i]);
                otherEntity.RemoveViewPlayer(id);

                //通知玩家,有entity退出视野
                EntityLeaveViewPackage entityLeaveViewPackage = PackageFactory.GetPackage(PackageType.EntityLeaveView)
                                                                as EntityLeaveViewPackage;
                entityLeaveViewPackage.aoId = otherEntity.aoId;
                entityLeaveViewPackage.type = otherEntity.type;
                this.worker.SendPackage(entityLeaveViewPackage);

                //更新当前entity所属
                otherEntity.CheckViewHold();
            }
            //最后更新自己能看见的人
            viewEntities = curViewEntities;
        }
Пример #5
0
        public ClientEntityInfo GetClientEntityInfo()
        {
            ClientEntityInfo info = new ClientEntityInfo();

            info.aoId     = aoId;
            info.type     = type;
            info.entityId = entityId;
            info.extData  = extData;
            info.position = position;
            info.roleId   = hostPlayer == null ? 0 : hostPlayer.id;
            return(info);
        }
Пример #6
0
        private ClientEntityInfo ReadClientEntityInfo()
        {
            ClientEntityInfo info = new ClientEntityInfo();

            info.aoId     = ReadInt();
            info.entityId = ReadInt();
            info.type     = ReadInt();
            info.roleId   = ReadInt();
            info.extData  = ReadListInt();
            info.position = ReadVector3();
            return(info);
        }
Пример #7
0
        private void UpdateViewPlayer()
        {
            List <int> curViewPlayers = NetManager.Instance.server.playerManager.GetAroundPlayer(inChunkPos, ClientPlayer.VIEW_WIDTH);

            for (int i = 0; i < curViewPlayers.Count; i++)
            {
                if (viewPlayers.Contains(curViewPlayers[i]))
                {
                    RemoveViewPlayer(curViewPlayers[i]);
                }
                else
                {
                    ClientPlayer otherPlayer = NetManager.Instance.server.playerManager.GetPlayer(curViewPlayers[i]);
                    otherPlayer.AddViewEntity(aoId);
                    //通知玩家,有entity进入视野
                    EntityJoinViewPackage entityJoinViewPackage = PackageFactory.GetPackage(PackageType.EntityJoinView)
                                                                  as EntityJoinViewPackage;
                    ClientEntityInfo info = new ClientEntityInfo();
                    info.aoId     = aoId;
                    info.type     = type;
                    info.entityId = entityId;
                    info.position = position;
                    info.extData  = extData;
                    info.roleId   = hostPlayer == null ? -1 : hostPlayer.id;
                    entityJoinViewPackage.info = info;
                    otherPlayer.worker.SendPackage(entityJoinViewPackage);
                }
            }
            for (int i = 0; i < viewPlayers.Count; i++)
            {
                ClientPlayer otherPlayer = NetManager.Instance.server.playerManager.GetPlayer(viewPlayers[i]);
                otherPlayer.RemoveViewEntity(aoId);
                //通知玩家,有entity退出视野
                EntityLeaveViewPackage entityLeaveViewPackage = PackageFactory.GetPackage(PackageType.EntityLeaveView)
                                                                as EntityLeaveViewPackage;
                entityLeaveViewPackage.aoId = aoId;
                entityLeaveViewPackage.type = type;
                otherPlayer.worker.SendPackage(entityLeaveViewPackage);
            }
            viewPlayers = curViewPlayers;
            //检测当前entity是否退出玩家视野,如果是的话,更改entity所属
            CheckViewHold();
        }
        public override void ServerDo(ClientConnectionWorker connectionWork)
        {
            if (NetManager.Instance.server.sceneManager.RefreshEntity(pos))
            {
                List <int> listRefershEntity = new List <int>();
                for (int i = 0; i < entities.Count; i++)
                {
                    int aoId = AoIdManager.instance.getAoId();
                    ClientEntityInfo info = new ClientEntityInfo();
                    info.aoId     = aoId;
                    info.entityId = entities[i].id;
                    info.type     = entities[i].type;
                    info.extData  = entities[i].exData;
                    info.position = entities[i].pos;
                    info.roleId   = connectionWork.player.id;
                    NetManager.Instance.server.entityManager.InitEntity(info);
                    listRefershEntity.Add(aoId);
                }
                //全部刷新完成后,通知持有该块的玩家更改刷新标志,并通知其刷新怪物
                ChunkSignChangedPackage signChangedPackage = PackageFactory.GetPackage(PackageType.ChunkSignChanged) as ChunkSignChangedPackage;
                signChangedPackage.pos  = pos;
                signChangedPackage.sign = NetManager.Instance.server.sceneManager.GetSign(pos);
                NetManager.Instance.server.sceneManager.BroadcastPlayerHasChunkPackage(connectionWork.player, pos, signChangedPackage, true);
                for (int i = 0; i < listRefershEntity.Count; i++)
                {
                    ClientEntity          clientEntity          = NetManager.Instance.server.entityManager.GetEntity(listRefershEntity[i]);
                    ClientEntityInfo      clientEntityInfo      = clientEntity.GetClientEntityInfo();
                    EntityJoinViewPackage entityJoinViewPackage = PackageFactory.GetPackage(PackageType.EntityJoinView)
                                                                  as EntityJoinViewPackage;
                    entityJoinViewPackage.info = clientEntityInfo;
                    for (int j = 0; j < clientEntity.viewPlayers.Count; j++)
                    {
                        ClientPlayer clientPlayer = NetManager.Instance.server.playerManager.GetPlayer(clientEntity.viewPlayers[j]);
                        clientPlayer.worker.SendPackage(entityJoinViewPackage);
                    }
                }
//				Debug.Log("请求刷新区块pos:" + pos.ToString() + "的entity成功,刷新数量:" + listRefershEntity.Count + " changedSign:" +signChangedPackage.sign);
            }
        }
        public void InitEntity(ClientEntityInfo info)
        {
            ClientEntity entity = new ClientEntity(info);

            AddEntity(entity);
        }
Пример #10
0
 public override void ReadAllData()
 {
     info = ReadClientEntityInfo();
 }