Esempio n. 1
0
        public string CreateCity(Session session, String[] parms)
        {
            bool   help       = false;
            string cityName   = string.Empty;
            string playerName = string.Empty;
            uint   x          = 0;
            uint   y          = 0;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "newcity=", v => cityName = v.TrimMatchingQuotes() },
                    { "player=", v => playerName = v.TrimMatchingQuotes() },
                    { "x=", v => x = uint.Parse(v.TrimMatchingQuotes()) },
                    { "y=", v => y = uint.Parse(v.TrimMatchingQuotes()) },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || cityName == string.Empty)
            {
                return("createcity --player=### --newcity=### --x=#### --y=####");
            }

            uint playerId;

            if (!world.FindPlayerId(playerName, out playerId))
            {
                return("Player not found");
            }

            IPlayer player;

            return(locker.Lock(playerId, out player).Do(() =>
            {
                {
                    if (player == null)
                    {
                        return "Player not found";
                    }

                    ICity city = player.GetCityList().First();
                    var cityCreateAction = actionFactory.CreateCityCreatePassiveAction(city.Id, x, y, cityName);
                    Error ret = city.Worker.DoPassive(city[1], cityCreateAction, true);
                    if (ret != Error.Ok)
                    {
                        return string.Format("Error: {0}", ret);
                    }
                }

                return "OK!";
            }));
        }
Esempio n. 2
0
        private void CreateCity(Session session, Packet packet)
        {
            uint   cityId;
            uint   x;
            uint   y;
            string cityName;

            try
            {
                cityId   = packet.GetUInt32();
                x        = packet.GetUInt32();
                y        = packet.GetUInt32();
                cityName = packet.GetString();
            }
            catch (Exception)
            {
                ReplyError(session, packet, Error.Unexpected);
                return;
            }

            locker.Lock(session.Player).Do(() =>
            {
                ICity city = session.Player.GetCity(cityId);

                if (city == null)
                {
                    ReplyError(session, packet, Error.Unexpected);
                    return;
                }

                var cityCreateAction = actionFactory.CreateCityCreatePassiveAction(cityId, x, y, cityName);
                Error ret            = city.Worker.DoPassive(city[1], cityCreateAction, true);
                if (ret != 0)
                {
                    ReplyError(session, packet, ret);
                }
                else
                {
                    ReplySuccess(session, packet);
                }
            });
        }