Beispiel #1
0
        public void SpawnPlayer(ActorPeer peer)
        {
            IActor player = new IActor()
            {
                actorType = (byte)ActorType.Player,
                peerID    = peer.playerID,
                actorID   = AllocateActorId(),
                posX      = 10,
                posY      = 10
            };

            ListPlayer.Add(player);

            //#region Test Code
            ////List<MPlayer> listTest = new List<MPlayer>()
            ////{
            ////    new MPlayer() { id = 1,name = "duc anh"},
            ////    new MPlayer() {id = 2, name = "hoang anh"}
            ////};
            //EventData evtData = new EventData()
            //{
            //    Code = (byte)AckEventType.CreateActor,
            //    Parameters = new Dictionary<byte, object>()
            //    {
            //        {(byte)ActorType.Creep, GeneralFunc.Serialize(listCreep)}
            //    }
            //};
            //peer.SendEvent(evtData, new SendParameters());
            //#endregion

            Region startRegion = Region.GetRegionFromPosition(player);

            Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaa");
            startRegion.ActorEnter(player);

            EventData evtPlayer = new EventData()
            {
                Code       = (byte)AckEventType.AssignPlayerID,
                Parameters = new Dictionary <byte, object>()
                {
                    { 0, GeneralFunc.Serialize(player) }
                }
            };

            peer.SendEvent(evtPlayer, new SendParameters());
        }
Beispiel #2
0
 private void DeletePeerToOther(IActor player, List <IActor> listPlayerInRegion)
 {
     foreach (var playerInRegion in listPlayerInRegion)
     {
         ActorPeer actorPeer = ServerArena.Instance.ListPeer.Where(a => a.playerID == playerInRegion.actorID).FirstOrDefault();
         if (actorPeer != null)
         {
             EventData evtOtherPlayer = new EventData()
             {
                 Code       = (byte)AckEventType.DestroyActor,
                 Parameters = new Dictionary <byte, object>()
                 {
                     { (byte)Parameter.Data, GeneralFunc.Serialize(player) }
                 }
             };
             actorPeer.SendEvent(evtOtherPlayer, new SendParameters());
         }
     }
 }
Beispiel #3
0
        private void SendNewPeerToTheOthers(IActor player, List <IActor> listPlayerInRegion)
        {
            List <IActor> listOnePlayer = new List <IActor>();

            listOnePlayer.Add(player);

            foreach (var playerInRegion in listPlayerInRegion)
            {
                ActorPeer actorPeer = ServerArena.Instance.ListPeer.Where(a => a.playerID == playerInRegion.actorID).FirstOrDefault();
                if (actorPeer != null)
                {
                    EventData evtOtherPlayer = new EventData()
                    {
                        Code       = (byte)AckEventType.CreateActor,
                        Parameters = new Dictionary <byte, object>()
                        {
                            { (byte)ActorType.Player, GeneralFunc.Serialize(listOnePlayer) }
                        }
                    };
                    actorPeer.SendEvent(evtOtherPlayer, new SendParameters());
                }
            }
        }
Beispiel #4
0
        private void SendNewInfoToPeer(ActorPeer peer, IActor player)
        {
            List <IActor> listPlayerInRegion = new List <IActor>();
            List <IActor> listCreepInRegion  = new List <IActor>();

            List <Region> listInterestRegion = GetInterestRegion();

            foreach (var region in listInterestRegion)
            {
                listPlayerInRegion.AddRange(region.listPlayer);
                listCreepInRegion.AddRange(region.listCreep);
            }
            listPlayerInRegion.Remove(player);

            InterestRegions dataInterest = GetDataInterestRegion(listInterestRegion);

            dataInterest.playerPosition = new MPosition()
            {
                x = player.posX,
                y = player.posY
            };


            EventData evtDataCrrepAndOtherPlayers = new EventData()
            {
                Code       = (byte)AckEventType.CreateActor,
                Parameters = new Dictionary <byte, object>()
                {
                    { (byte)Parameter.Player, GeneralFunc.Serialize(listPlayerInRegion) },
                    { (byte)Parameter.Creep, GeneralFunc.Serialize(listCreepInRegion) },
                    { (byte)Parameter.Regions, GeneralFunc.Serialize(dataInterest) }
                }
            };

            peer.SendEvent(evtDataCrrepAndOtherPlayers, new SendParameters());
        }