Exemplo n.º 1
0
        private void OnRecvCMall(IChannel channel, Message message)
        {
            Console.WriteLine("OnRecvCMall");
            SMall msg = new SMall();

            msg.goods = new Dictionary <string, DTreasureMall>(backMall);
            channel.Send(msg);
        }
Exemplo n.º 2
0
        private void OnRecvMall(IChannel channel, Message message)
        {
            SMall msg = message as SMall;

            TreasureInfo.treasureMall = new Dictionary <string, TreasureMall>();
            foreach (KeyValuePair <string, DTreasureMall> tmp in msg.goods)
            {
                TreasureInfo.treasureMall.Add(tmp.Key, new TreasureMall().FromDTreasureMall(tmp.Value));
            }
            //MessageBox.Show("OnRecvMall");
        }
Exemplo n.º 3
0
        private void OnRecvPlayerEnter(IChannel channel, Message message)
        {
            CPlayerEnter request = message as CPlayerEnter;
            Player       player  = (Player)channel.GetContent();
            Scene        scene   = World.Instance.GetScene(player.scene);

            // add the player to the scene
            player.Spawn();
            scene.AddEntity(player);

            // send player attributes
            SPlayerAttribute attrMessage = new SPlayerAttribute()
            {
                playerId     = player.entityId,
                name         = player.user,
                currentHP    = player.currentHP,
                level        = player.level,
                intelligence = player.intelligence,
                speed        = player.speed,
                attack       = player.attack,
                defense      = player.defense,
                GoldNum      = player.GoldNum,
                SilverNum    = player.SilverNum
            };

            channel.Send(attrMessage);

            // add online player
            OnlinePlayers.Add(player.user, player);
            // send oneline player to frontend
            Dictionary <int, string> SendDic = new Dictionary <int, string>();

            foreach (KeyValuePair <string, Player> tmp in OnlinePlayers)
            {
                SendDic.Add(tmp.Value.entityId, tmp.Key);
                Console.WriteLine("contains user:{0}", tmp.Key);
            }
            SFindFriends response = new SFindFriends()
            {
                friends = SendDic
            };

            player.Broadcast(response);


            // send treasure attributes
            ConnectDB connect = new ConnectDB();

            if (treasureAttributes.Count == 0)
            {
                treasureAttributes = new Dictionary <string, DTreasure>(connect.GetTreasureAttri());
            }
            STreasureAttribute treasureAttribute = new STreasureAttribute()
            {
                treasureAttri = new Dictionary <string, DTreasure>(treasureAttributes)
            };

            channel.Send(treasureAttribute);

            // send mall
            if (backMall.Count == 0)
            {
                backMall = new Dictionary <string, DTreasureMall>(connect.DBGetMall());
            }
            SMall mall = new SMall()
            {
                goods = new Dictionary <string, DTreasureMall>(backMall)
            };

            channel.Send(mall);

            // send package
            SPackage package = new SPackage()
            {
                goods = new Dictionary <string, DTreasurePackage>(connect.DBGetPackage(player.user))
            };

            channel.Send(package);

            // send friends
            SFriends friendList = new SFriends()
            {
                friends = new List <string>(connect.GetFriends(player.user))
            };

            channel.Send(friendList);

            // send friend requests
            SFindFriendRequests requestList = new SFindFriendRequests()
            {
                requests = new List <string>(connect.GetFriendRequest(player.user))
            };

            channel.Send(requestList);
        }