Ejemplo n.º 1
0
        /// <summary>
        /// Send the specified player to jail.
        /// </summary>
        /// <param name="aName">The name of the player to send to jail.</param>
        /// <returns>True on success, false otherwise.</returns>
        public static Boolean SendPlayerToJail(String aName)
        {
            bool success = false;

            GameMap map = null;

            if (!MapManager.TryGetMap(MapManager.PRISON_MAP_UID, out map))
            {
                return(false);
            }

            using (var connection = sDefaultPool.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = (
                        "UPDATE `user` SET `record_map` = @record_map, `record_x` = @record_x, `record_y` = @record_y, " +
                        "`jail` = `jail` + 1 WHERE `name` = @name");
                    command.Parameters.AddWithValue("@name", aName);
                    command.Parameters.AddWithValue("@record_map", map.Id);
                    command.Parameters.AddWithValue("@record_x", map.PortalX);
                    command.Parameters.AddWithValue("@record_y", map.PortalY);
                    command.Prepare();

                    sLogger.Debug("Executing SQL: {0}", GetSqlCommand(command));

                    try
                    {
                        int count = command.ExecuteNonQuery();
                        success = count == 1;
                    }
                    catch (MySqlException exc)
                    {
                        sLogger.Error("Failed to execute the following cmd : \"{0}\"\nError {1}: {2}",
                                      GetSqlCommand(command), exc.Number, exc.Message);
                    }
                }
            }

            if (success)
            {
                Player player = null;
                if (World.AllPlayerNames.TryGetValue(aName, out player))
                {
                    player.Move(map.Id, map.PortalX, map.PortalY);
                    ++player.JailC;
                }

                World.BroadcastMsg(new MsgTalk("SYSTEM", "ALLUSERS", aName + " has been sent to jail!", Channel.GM, Color.White));
            }

            return(success);
        }
Ejemplo n.º 2
0
        public static void BroadcastMapMsg(UInt32 aMapId, Msg aMsg)
        {
            GameMap map = null;

            if (MapManager.TryGetMap(aMapId, out map))
            {
                var players = from entity in map.Entities.Values where entity.IsPlayer() select(Player) entity;

                foreach (Player player in players)
                {
                    player.Send(aMsg);
                }
            }
        }
Ejemplo n.º 3
0
        public static void GetSpawnsInfo()
        {
            sLogger.Info("Loading spawns informations...");

            using (var connection = sDefaultPool.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT `mapid`, `bound_x`, `bound_y`, `bound_cx`, `bound_cy`, `max_npc`, `rest_secs`, `max_per_gen`, `monster_type` FROM `generator`";
                    command.Prepare();

                    sLogger.Debug("Executing SQL: {0}", GetSqlCommand(command));

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            GameMap     map;
                            MonsterInfo monster_type;

                            if (!MapManager.TryGetMap(reader.GetUInt32("mapid"), out map))
                            {
                                sLogger.Warn("Map {0} is not loaded, but required by a generator.",
                                             reader.GetUInt32("mapid"));
                                continue;
                            }

                            if (!Database.AllMonsters.TryGetValue(reader.GetInt32("monster_type"), out monster_type))
                            {
                                sLogger.Warn("Monster {0} is not loaded, but required by a generator.",
                                             reader.GetInt32("monster_type"));
                                continue;
                            }

                            Generator generator = new Generator(
                                map, reader.GetUInt16("bound_x"), reader.GetUInt16("bound_y"), reader.GetUInt16("bound_cx"), reader.GetUInt16("bound_cy"),
                                reader.GetUInt16("max_npc"), reader.GetUInt16("rest_secs"), reader.GetUInt16("max_per_gen"), monster_type);

                            AllGenerators.Add(generator);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void GetAllNPCs()
        {
            sLogger.Info("Loading all npcs in memory...");

            using (var connection = sDefaultPool.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT `id`, `name`, `type`, `lookface`, `mapid`, `cellx`, `celly`, `base`, `sort`  FROM `npc`";
                    command.Prepare();

                    sLogger.Debug("Executing SQL: {0}", GetSqlCommand(command));

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Int32  id       = reader.GetInt32("id");
                            String name     = reader.GetString("name");
                            Byte   type     = reader.GetByte("type");
                            UInt32 look     = reader.GetUInt32("lookface");
                            UInt32 mapId    = reader.GetUInt32("mapid");
                            UInt16 posX     = reader.GetUInt16("cellx");
                            UInt16 posY     = reader.GetUInt16("celly");
                            Byte   npc_base = reader.GetByte("base");
                            Byte   npc_sort = reader.GetByte("sort");

                            GameMap map;
                            if (!MapManager.TryGetMap(mapId, out map))
                            {
                                sLogger.Warn("Missing map {0} for NPC {1} ({2})",
                                             mapId, name, id);
                                continue;
                            }

                            if (World.AllNPCs.ContainsKey(id))
                            {
                                continue;
                            }

                            NPC npc = new NPC(id, name, type, look, map, posX, posY, npc_base, npc_sort);

                            World.AllNPCs.Add(npc.UniqId, npc);
                            npc.Map.AddEntity(npc);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT `ownerid`, `ownertype`, `name`, `type`, `lookface`, `mapid`, `cellx`, `celly`, `life`, `base`, `sort`, `level`, `defence`, `magic_def` FROM `dynanpc`";
                    command.Prepare();

                    sLogger.Debug("Executing SQL: {0}", GetSqlCommand(command));

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            String name     = reader.GetString("name");
                            Byte   type     = reader.GetByte("type");
                            UInt32 look     = reader.GetUInt32("lookface");
                            UInt32 mapId    = reader.GetUInt32("mapid");
                            UInt16 posX     = reader.GetUInt16("cellx");
                            UInt16 posY     = reader.GetUInt16("celly");
                            Byte   npc_base = reader.GetByte("base");
                            Byte   npc_sort = reader.GetByte("sort");

                            Byte   level    = reader.GetByte("level");
                            UInt32 life     = reader.GetUInt32("life");
                            UInt16 defense  = reader.GetUInt16("defence");
                            Byte   magicDef = reader.GetByte("magic_def");

                            GameMap map;
                            if (!MapManager.TryGetMap(mapId, out map))
                            {
                                continue;
                            }

                            TerrainNPC npc = new TerrainNPC(
                                World.GetNextDynaNpcUID(), name, type, look, map, posX, posY, npc_base, npc_sort,
                                level, life, defense, magicDef);

                            World.AllTerrainNPCs.Add(npc.UniqId, npc);
                            npc.Map.AddEntity(npc);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static Boolean Save(Player aPlayer, bool aIsOnline)
        {
            bool success = false;

            // TODO superman table
            //AMSXml.SetValue("Informations", "KO", 0);

            String friends = "";

            foreach (var friend in aPlayer.Friends)
            {
                friends += friend.Key.ToString() + ":" + friend.Value + ",";
            }
            if (friends.Length > 0)
            {
                friends = friends.Substring(0, friends.Length - 1);
            }

            String enemies = "";

            foreach (var enemy in aPlayer.Enemies)
            {
                enemies += enemy.Key.ToString() + ":" + enemy.Value + ",";
            }
            if (enemies.Length > 0)
            {
                enemies = enemies.Substring(0, enemies.Length - 1);
            }

            using (var connection = sDefaultPool.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = (
                        "UPDATE `user` SET " +
                        "`money` = @money, `money_saved` = @money_saved,  " +
                        "`profession` = @profession, `level` = @level, `exp` = @exp, " +
                        "`first_profession` = @first_profession, `first_level` = @first_level, `second_profession` = @second_profession, `second_level` = @second_level, " +
                        "`force` = @force, `dexterity` = @dexterity, `health` = @health, `soul` = @soul, `add_points` = @add_points, " +
                        "`life` = @life, `mana` = @mana, `pk` = @pk, `virtue` = @virtue, " +
                        "`time_add` = @time_add, " +
                        "`dbl_exp_time` = @dbl_exp_time, `lucky_time` = @lucky_time, " +
                        "`record_map` = @record_map, `record_x` = @record_x, `record_y` = @record_y, `friends` = @friends, `enemies` = @enemies, `online` = @online WHERE `id` = @id");

                    command.Parameters.AddWithValue("@id", aPlayer.UniqId);

                    command.Parameters.AddWithValue("@money", aPlayer.Money);
                    command.Parameters.AddWithValue("@money_saved", aPlayer.WHMoney);

                    command.Parameters.AddWithValue("@profession", aPlayer.Profession);
                    command.Parameters.AddWithValue("@level", aPlayer.Level);
                    command.Parameters.AddWithValue("@exp", aPlayer.Exp);

                    command.Parameters.AddWithValue("@first_profession", aPlayer.FirstProfession);
                    command.Parameters.AddWithValue("@first_level", aPlayer.FirstLevel);
                    command.Parameters.AddWithValue("@second_profession", aPlayer.SecondProfession);
                    command.Parameters.AddWithValue("@second_level", aPlayer.SecondLevel);

                    command.Parameters.AddWithValue("@force", aPlayer.Strength);
                    command.Parameters.AddWithValue("@dexterity", aPlayer.Agility);
                    command.Parameters.AddWithValue("@health", aPlayer.Vitality);
                    command.Parameters.AddWithValue("@soul", aPlayer.Spirit);
                    command.Parameters.AddWithValue("@add_points", aPlayer.AddPoints);

                    command.Parameters.AddWithValue("@life", aPlayer.CurHP > 0 ? aPlayer.CurHP : 1);
                    command.Parameters.AddWithValue("@mana", aPlayer.CurMP);

                    command.Parameters.AddWithValue("@pk", aPlayer.PkPoints);
                    command.Parameters.AddWithValue("@virtue", aPlayer.VPs);

                    if (aPlayer.CurHP > 0)
                    {
                        if (!aPlayer.Map.IsRecord_Disable())
                        {
                            command.Parameters.AddWithValue("@record_map", aPlayer.Map.Id);
                            command.Parameters.AddWithValue("@record_x", aPlayer.X);
                            command.Parameters.AddWithValue("@record_y", aPlayer.Y);
                        }
                        else
                        {
                            GameMap rebornMap = null;
                            if (MapManager.TryGetMap(aPlayer.Map.RebornMap, out rebornMap))
                            {
                                command.Parameters.AddWithValue("@record_map", rebornMap.Id);
                                command.Parameters.AddWithValue("@record_x", rebornMap.PortalX);
                                command.Parameters.AddWithValue("@record_y", rebornMap.PortalY);
                            }
                            else
                            {
                                command.Parameters.AddWithValue("@record_map", 1002);
                                command.Parameters.AddWithValue("@record_x", 400);
                                command.Parameters.AddWithValue("@record_y", 400);
                            }
                        }
                    }
                    else
                    {
                        GameMap rebornMap;
                        if (MapManager.TryGetMap(aPlayer.Map.RebornMap, out rebornMap))
                        {
                            command.Parameters.AddWithValue("@record_map", rebornMap.Id);
                            command.Parameters.AddWithValue("@record_x", rebornMap.PortalX);
                            command.Parameters.AddWithValue("@record_y", rebornMap.PortalY);
                        }
                    }

                    command.Parameters.AddWithValue("@time_add", aPlayer.TimeAdd);

                    if (aPlayer.DblExpEndTime == 0)
                    {
                        command.Parameters.AddWithValue("@dbl_exp_time", 0);
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@dbl_exp_time", (Int32)((aPlayer.DblExpEndTime - Environment.TickCount) / 1000));
                    }
                    command.Parameters.AddWithValue("@lucky_time", aPlayer.LuckyTime);

                    command.Parameters.AddWithValue("@friends", friends);
                    command.Parameters.AddWithValue("@enemies", enemies);
                    command.Parameters.AddWithValue("@online", aIsOnline);
                    command.Prepare();

                    sLogger.Debug("Executing SQL: {0}", GetSqlCommand(command));

                    try
                    {
                        int count = command.ExecuteNonQuery();
                        success = count == 1;
                    }
                    catch (MySqlException exc)
                    {
                        sLogger.Error("Failed to execute the following cmd : \"{0}\"\nError {1}: {2}",
                                      GetSqlCommand(command), exc.Number, exc.Message);
                    }
                }
            }

            return(success);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Try to retreive the player information for the specified client.
        /// </summary>
        /// <param name="aClient">The client</param>
        /// <returns>True on success, false otherwise.</returns>
        public static Boolean GetPlayerInfo(ref Client aClient)
        {
            bool success = false;

            using (var connection = sDefaultPool.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM `user` WHERE `account_id` = @account_id";
                    command.Parameters.AddWithValue("@account_id", aClient.AccountID);
                    command.Prepare();

                    sLogger.Debug("Executing SQL: {0}", GetSqlCommand(command));

                    using (var reader = command.ExecuteReader())
                    {
                        int count = 0;
                        while (reader.Read())
                        {
                            ++count;

                            Int32  uid    = reader.GetInt32("id");
                            Player player = new Player(uid, aClient);

                            player.Name = reader.GetString("name");
                            player.Mate = reader.GetString("mate");
                            player.Look = reader.GetUInt32("lookface");
                            player.Hair = reader.GetUInt16("hair");

                            player.Money   = reader.GetUInt32("money");
                            player.WHMoney = reader.GetUInt32("money_saved");

                            player.Profession     = reader.GetByte("profession");
                            player.Level          = reader.GetByte("level");
                            player.Exp            = reader.GetUInt32("exp");
                            player.Metempsychosis = reader.GetByte("metempsychosis");

                            player.FirstProfession  = reader.GetByte("first_profession");
                            player.FirstLevel       = reader.GetByte("first_level");
                            player.SecondProfession = reader.GetByte("second_profession");
                            player.SecondLevel      = reader.GetByte("second_level");

                            player.Strength  = reader.GetUInt16("force");
                            player.Agility   = reader.GetUInt16("dexterity");
                            player.Vitality  = reader.GetUInt16("health");
                            player.Spirit    = reader.GetUInt16("soul");
                            player.AddPoints = reader.GetUInt16("add_points");

                            player.CurHP = reader.GetUInt16("life");
                            player.CurMP = reader.GetUInt16("mana");

                            player.PkPoints = reader.GetInt16("pk");
                            player.VPs      = reader.GetInt32("virtue");

                            UInt32 mapId = reader.GetUInt32("record_map");
                            if (MapManager.TryGetMap(mapId, out player.Map))
                            {
                                player.X = reader.GetUInt16("record_x");
                                player.Y = reader.GetUInt16("record_y");
                            }
                            else
                            {
                                // map not found...
                                if (MapManager.TryGetMap(1002, out player.Map))
                                {
                                    player.X = 400;
                                    player.Y = 400;
                                }
                            }

                            player.PrevMap = player.Map;
                            player.PrevX   = player.X;
                            player.PrevY   = player.Y;

                            player.mLockPin = reader.GetUInt32("depot_pin");

                            // TODO KO in superman table
                            // Player.KO = AMSXml.GetValue("Informations", "KO", 0);

                            player.TimeAdd = reader.GetInt32("time_add");

                            player.DblExpEndTime = Environment.TickCount + (reader.GetInt32("dbl_exp_time") * 1000);
                            player.LuckyTime     = reader.GetInt32("lucky_time");

                            player.JailC = reader.GetByte("jail");

                            #region Friends / Enemies
                            String[] parts = null;

                            String friends = reader.GetString("friends");
                            parts = friends.Split(',');
                            foreach (String friend in parts)
                            {
                                String[] info = friend.Split(':');
                                if (info.Length < 2)
                                {
                                    continue;
                                }

                                Int32 friendId = 0;
                                if (!Int32.TryParse(info[0], out friendId))
                                {
                                    continue;
                                }

                                if (!player.Friends.ContainsKey(friendId))
                                {
                                    player.Friends.Add(friendId, info[1]);
                                }
                            }

                            String enemies = reader.GetString("enemies");
                            parts = enemies.Split(',');
                            foreach (String enemy in parts)
                            {
                                String[] info = enemy.Split(':');
                                if (info.Length < 2)
                                {
                                    continue;
                                }

                                Int32 enemyId = 0;
                                if (!Int32.TryParse(info[0], out enemyId))
                                {
                                    continue;
                                }

                                if (!player.Enemies.ContainsKey(enemyId))
                                {
                                    player.Enemies.Add(enemyId, info[1]);
                                }
                            }
                            #endregion

                            //MyMath
                            player.CalcMaxHP();
                            player.CalcMaxMP();

                            Database.GetPlayerSyndicate(player);
                            Database.GetPlayerWeaponSkills(player);
                            Database.GetPlayerMagics(player);

                            aClient.Player = player;
                        }

                        success = count == 1;
                    }
                }
            }

            return(success);
        }