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
        public void InitCreep()
        {
            for (int i = 0; i < 500; i++)
            {
                // find a random position
                double x = rand.Next(-24, 220);
                double y = rand.Next(-24, 220);

                IActor creep = new IActor()
                {
                    actorType = (byte)ActorType.Creep,
                    posX      = (float)x,
                    posY      = (float)y,
                    actorID   = AllocateActorId()
                };
                ListCreep.Add(creep);

                Region region = Region.GetRegionFromPosition(creep);
                region.ActorEnter(creep);
            }
        }
Beispiel #3
0
        public void ProcessRequest(ActorPeer sender, OperationRequest operationRequest, SendParameters sendParameters)
        {
            if (operationRequest.OperationCode == (byte)AckRequestType.MoveCommand)
            {
                Movement movement = GeneralFunc.Deserialize <Movement>(operationRequest.Parameters[(byte)Parameter.Data] as byte[]);

                // find actor
                IActor player = (ListPlayer.Find(pl => pl.actorID == movement.actorID));

                Region oldRegion = Region.GetRegionFromPosition(player);

                player.posX = movement.posX;
                player.posY = movement.posY;

                Region newRegion = Region.GetRegionFromPosition(player);

                if (oldRegion != newRegion)
                {
                    oldRegion.ActorExit(player);

                    newRegion.ActorEnter(player);
                }
            }
        }