Пример #1
0
        public override G2B_BattleReward DoResponse(B2G_BattleReward request, Client client)
        {
            //check ?

            Managers.UserData data;
            if (!MonitorPool.S.Get <UserDataManager>().TryToGetUserData(request.UserID, out data))
            {
                return(new G2B_BattleReward {
                    Code = ErrorCode.NoGamePlayerData
                });
            }

            var diff = new Dictionary <int, Proto.PlayerItem>();

            foreach (var i in request.DropItems)
            {
                if (diff.ContainsKey(i.ItemID))
                {
                    diff[i.ItemID].Num += i.Num;
                }
                else
                {
                    diff.Add(i.ItemID, i);
                }
            }

            foreach (var i in request.ConsumeItems)
            {
                if (diff.ContainsKey(i.ItemID))
                {
                    diff[i.ItemID].Num -= i.Num;
                }
                else
                {
                    diff.Add(i.ItemID, i);
                }
            }

            ErrorCode code = ErrorCode.OK;

            foreach (var i in diff)
            {
                if (i.Value.Num == 0)
                {
                    continue;
                }
                if (i.Value.Num > 0)
                {
                    if (!data.AddItem(i.Value))
                    {
                        code = ErrorCode.Error;
                    }
                }
                else
                {
                    if (!data.ConsumeItem(i.Value))
                    {
                        code = ErrorCode.Error;
                    }
                }
            }

            data.AddGold(request.Gold);

            var userClient = Appliaction.Current.GetClientByUserID(request.UserID);

            if (userClient != null)
            {
                var syncHero = new Task_G2C_SyncHero {
                    Hero = data.GetHero()
                };
                var syncPackage = new Task_G2C_SyncPackage
                {
                    Package = data.GetPackage(),
                    Gold    = data.Gold,
                    Coin    = data.Coin
                };
                NetProtoTool.SendTask(userClient, syncHero);
                NetProtoTool.SendTask(userClient, syncPackage);
            }

            return(new G2B_BattleReward {
                Code = code
            });
        }
Пример #2
0
        //开始进入战斗
        internal ErrorCode BeginBattle(
            long userID,
            int mapID, int serverID, out GameServerInfo serverInfo)
        {
            serverInfo = null;
            var battleServer = ServerManager.Singleton.GetFreeBattleServerID();

            if (battleServer == null)
            {
                return(ErrorCode.NOFreeBattleServer);
            }
            UserServerInfo user;

            if (_servers.TryToGetValue(userID, out user))
            {
                var task = new Task_L2B_ExitUser {
                    UserID = user.UserID
                };
                var b       = ServerManager.Singleton.GetBattleServerMappingByServerID(user.BattleServerID);
                var bClient = Appliaction.Current.GetServerConnectByClientID(b.ClientID);
                if (bClient != null)
                {
                    NetProtoTool.SendTask(bClient, task);
                    //bClient.SendMessage(m);
                }
                return(ErrorCode.PlayerIsInBattle);
            }

            var su = _servers.Add(
                userID,
                new UserServerInfo
            {
                MapID          = mapID,
                BattleServerID = battleServer.ServerInfo.ServerID,
                GServerID      = serverID,
                UserID         = userID
            });

            if (su)
            {
                serverInfo = battleServer.ServerInfo;
                var gateserver = ServerManager.Singleton.GetGateServerMappingByServerID(serverID);
                var task       = new Task_L2B_StartBattle
                {
                    MapID = mapID,
                    Users = new List <PlayerServerInfo> {
                        new PlayerServerInfo {
                            UserID      = userID,
                            ServerID    = serverID,
                            ServiceHost = gateserver.ServiceHost,
                            ServicePort = gateserver.ServicePort
                        }
                    }
                };
                //task
                //var message = NetProtoTool.ToNetMessage(XNet.Libs.Net.MessageClass.Task, task);
                var serverConnect = Appliaction.Current.GetServerConnectByClientID(battleServer.ClientID);
                if (serverConnect == null)
                {
                    _servers.Remove(userID);
                    return(ErrorCode.BattleServerHasDisconnect);
                }
                NetProtoTool.SendTask(serverConnect, task);
                //serverConnect.SendMessage(message);
                return(Proto.ErrorCode.OK);
            }
            else
            {
                return(Proto.ErrorCode.PlayerIsInBattle);
            }
        }
Пример #3
0
        public override G2C_GMTool DoResponse(C2G_GMTool request, Client client)
        {
#if USEGM
            if (!Appliaction.Current.EnableGM)
            {
                return new G2C_GMTool()
                       {
                           Code = ErrorCode.Error
                       }
            }
            ;

            var args = request.GMCommand.Split(' ');
            if (args.Length == 0)
            {
                return new G2C_GMTool {
                           Code = ErrorCode.Error
                }
            }
            ;
            var      userid = (long)client.UserState;
            UserData userData;
            if (!MonitorPool.S.Get <UserDataManager>().TryToGetUserData(userid, out userData))
            {
                return(new G2C_GMTool {
                    Code = ErrorCode.NoGamePlayerData
                });
            }
            switch (args[0].ToLower())
            {
            case "level":
            {
                var level = 0;
                if (int.TryParse(args[1], out level))
                {
                    userData.HeroLevelTo(level);
                }
            }
            break;

            case "make":
            {
                int id  = int.Parse(args[1]);
                var num = 1;
                if (args.Length > 2)
                {
                    num = int.Parse(args[2]);
                }

                var playerItem = new PlayerItem {
                    ItemID = id, Num = num
                };
                userData.AddItem(playerItem);
            }
            break;

            case "addgold":
            {
                userData.AddGold(int.Parse(args[1]));
            }
            break;

            case "addcoin":
            {
                userData.AddCoin(int.Parse(args[1]));
            }
            break;

            case "addexp":
            {
                int level = 0;
                userData.AddExp(int.Parse(args[1]), out level);
            }
            break;
            }

            //sync
            var syncHero = new Task_G2C_SyncHero {
                Hero = userData.GetHero()
            };
            var syncPackage = new Task_G2C_SyncPackage
            {
                Package = userData.GetPackage(),
                Gold    = userData.Gold,
                Coin    = userData.Coin
            };
            NetProtoTool.SendTask(client, syncHero);
            NetProtoTool.SendTask(client, syncPackage);

            return(new G2C_GMTool
            {
                Code = ErrorCode.OK
            });
#else
            return(new G2C_GMTool {
                Code = ErrorCode.Error
            });
#endif
        }
    }
}