Exemple #1
0
        public override void Update(GameTime gameTime)
        {
            client.Update();
            keyboard.Update(gameTime);

            foreach (var obj in CircleList)
            {
                obj.Value.Update(gameTime);
            }
            if (Player != null)
            {
                Player.Update(gameTime);

                Player.Position = ClampPlayerPosition(Player.Position);

                if (IsConnect && Player.Changed)
                {
                    Player.Changed  = false;
                    var msg         = new Msg_AgarPlayInfo();
                    msg.Operat      = Msg_AgarPlayInfo.Changed;
                    msg.UserId      = Uid;
                    msg.Tag         = GameMessageHelper.POSITION_TAG;
                    msg.X           = Player.Position.X;
                    msg.Y           = Player.Position.Y;
                    client.SendMessage(msg);
                }
            }
        }
Exemple #2
0
        private static void OnPlayerExit(object sender, PlayerBallManager.PlayerExitArgs msg)
        {
            var removeMsg       = new Msg_AgarPlayInfo();
            removeMsg.Operat    = Msg_AgarPlayInfo.Remove;
            removeMsg.UserId    = msg.UserId;

            MarkMgr.Remove(msg.UserId);
            SendMessage(AgarServer, removeMsg);
        }
Exemple #3
0
        private static void OnPlayerDead(object sender, PlayerBallManager.PlayerDeadArgs msg)
        {
            var conn = AgarConnMgr.Get(msg.UserId);

            MarkMgr.Remove(msg.UserId);

            // 为自己发送死亡信息
            var selfMsg     = new Msg_AgarSelf();
            selfMsg.Operat  = Msg_AgarSelf.Dead;
            SendMessage(AgarServer, selfMsg, conn);

            // 为其他玩家推送玩家死亡信息
            var pubMsg      = new Msg_AgarPlayInfo();
            pubMsg.Operat   = Msg_AgarPlayInfo.Remove;
            pubMsg.UserId   = msg.UserId;
            SendMessageExceptOne(AgarServer, pubMsg, conn);
        }
Exemple #4
0
        private static bool OnProcessPlayerInfo(NetServer server, int id, NetIncomingMessage msg)
        {
            Msg_AgarPlayInfo r  = new Msg_AgarPlayInfo();
            r.R(msg);
            uint uid            = r.UserId;
            if (r.Operat == Msg_AgarPlayInfo.Changed)
            {
                if (!PlayerBallMgr.IsContain(uid)) return true;

                PlayerBall newBall  = PlayerBallMgr.Get(uid);
                uint tag            = r.Tag;
                if (GameMessageHelper.Is_Changed(tag, GameMessageHelper.POSITION_TAG))
                {
                    newBall.X = r.X;
                    newBall.Y = r.Y;
                }
                if (GameMessageHelper.Is_Changed(tag, GameMessageHelper.RADIUS_TAG))
                {
                    newBall.Radius = r.Radius;
                }
                if (GameMessageHelper.Is_Changed(tag, GameMessageHelper.COLOR_TAG))
                {
                    newBall.Color = r.Color;
                }
                if (GameMessageHelper.Is_Changed(tag, GameMessageHelper.NAME_TAG))
                {
                    newBall.Name = r.Name;
                }

                bool RaduisChanged  = false;
                bool FoodChanged    = false;
                bool PlayerChanged  = false;
                // 检查食物有没有被吃
                if (UpdateFood(uid, ref newBall))
                {
                    FoodChanged = true;
                }
                // 检查能不能吃其他玩家
                if (UpdatePlayer(uid, ref newBall))
                {
                    PlayerChanged = true;
                }
                if (FoodChanged || PlayerChanged)
                {
                    r.Tag           = r.Tag | GameMessageHelper.RADIUS_TAG;
                    r.Radius        = newBall.Radius;
                    var self        = new Msg_AgarSelf();
                    self.Operat     = Msg_AgarSelf.GroupUp;
                    self.Radius     = newBall.Radius;
                    RaduisChanged   = true;
                    SendMessage(server, self, msg.SenderConnection);
                }
                PlayerBallMgr.Change(uid, newBall);

                // 检查会不会被其他玩家吃
                uint EatId = 0;
                if (UpdateOtherPlayer(uid, newBall, out EatId))
                {
                    if (PlayerBallMgr.IsContain(EatId))
                    {
                        var EatBall     = PlayerBallMgr.Get(EatId);
                        var conn        = AgarConnMgr.Get(EatId);
                        EatBall.Radius  += newBall.Radius;
                        PlayerBallMgr.Change(EatId, EatBall);

                        // 向其他玩家发送
                        Msg_AgarPlayInfo eatMsg = new Msg_AgarPlayInfo();
                        eatMsg.Operat           = Msg_AgarPlayInfo.Changed;
                        eatMsg.UserId           = EatId;
                        eatMsg.Tag              = GameMessageHelper.RADIUS_TAG;
                        eatMsg.Radius           = EatBall.Radius;
                        RaduisChanged           = true;
                        SendMessageExceptOne(server, eatMsg, conn);

                        // 向自身发送
                        var selfEatMsg          = new Msg_AgarSelf();
                        selfEatMsg.Operat       = Msg_AgarSelf.GroupUp;
                        selfEatMsg.Radius       = EatBall.Radius;
                        SendMessage(server, selfEatMsg, conn);
                    }
                }

                if (RaduisChanged)
                {
                    MarkMgr.Update(uid, newBall.Radius);
                }
            }
            SendMessageExceptOne(server, r, msg.SenderConnection);
            return true;
        }
Exemple #5
0
        private static bool OnProcessBorn(NetServer server, int id, NetIncomingMessage msg)
        {
            var r = new Msg_AgarBorn();
            r.R(msg);

            uint uid    = r.UserId;
            string name = r.Name;

            int x       = RandomMaker.Next(GameWidth);
            int y       = RandomMaker.Next(GameHeight);
            int radius  = PlayerBall.DefaultPlayerRadius;
            uint c      = CustomColors.RandomColor;

            // 添加Player到Manager
            PlayerBall player   = new PlayerBall();
            player.X            = x;
            player.Y            = y;
            player.Radius       = radius;
            player.Color        = c;
            player.Name         = name;
            PlayerBallMgr.Add(uid, player);

            MarkMgr.Update(uid, radius);

            // 更新链接对应的ID
            AgarConnMgr.Modify(msg.SenderConnection, uid);

            // 向自身发送出生位置等信息
            var selfMsg         = new Msg_AgarSelf();
            selfMsg.Operat      = Msg_AgarSelf.Born;
            selfMsg.X           = x;
            selfMsg.Y           = y;
            selfMsg.Radius      = radius;
            selfMsg.Color       = c;
            SendMessage(server, selfMsg, msg.SenderConnection);

            // 向之前加入的玩家推送新用户出生信息
            var oMsg        = new Msg_AgarPlayInfo();
            oMsg.Operat     = Msg_AgarPlayInfo.Add;
            oMsg.UserId     = uid;
            oMsg.Tag        = GameMessageHelper.ALL_TAG;
            oMsg.X          = x;
            oMsg.Y          = y;
            oMsg.Radius     = radius;
            oMsg.Color      = c;
            oMsg.Name       = name;
            SendMessageExceptOne(server, oMsg, msg.SenderConnection);
            return true;
        }
Exemple #6
0
 public void OnDataMessage(object sender, NetIncomingMessage im)
 {
     if (DataMessage != null)
     {
         int id = im.ReadInt32();
         if (id == MsgId.ChatToAll)
         {
             MsgBase msg = new Msg_ChatToAll();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if (id == MsgId.AccountRegRsp)
         {
             MsgBase msg = new Msg_AccountRegRsp();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarLoginRsp)
         {
             MsgBase msg = new Msg_AgarLoginRsp();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarFixedBall)
         {
             MsgBase msg = new Msg_AgarFixedBall();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarPlayInfo)
         {
             MsgBase msg = new Msg_AgarPlayInfo();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarFixBallPack)
         {
             MsgBase msg = new Msg_AgarFixBallPack();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarPlayInfoPack)
         {
             MsgBase msg = new Msg_AgarPlayInfoPack();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarSelf)
         {
             MsgBase msg = new Msg_AgarSelf();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarMarkListPark)
         {
             MsgBase msg = new Msg_AgarMarkListPack();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyPlayerLoginRsp)
         {
             MsgBase msg = new Msg_HappyPlayerLoginRsp();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyOtherPlayerLogin)
         {
             MsgBase msg = new Msg_HappyOtherPlayerLogin();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyPlayerMove)
         {
             MsgBase msg = new Msg_HappyPlayerMove();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyPlayerQuit)
         {
             MsgBase msg = new Msg_HappyPlayerQuit();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyPlayerPack)
         {
             MsgBase msg = new Msg_HappyPlayerPack();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
     }
 }