public static void Remove(Gift gift) { const string query = "DELETE FROM inventory_items WHERE gift=@giftId"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => command.Parameters.Add(new MySqlParameter("@id", gift.Id))); }
private static void LoadItemSets() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM items_set", "Items Set", (reader) => { while (reader.Read()) { ItemSets.Add(new ItemSet { Id = reader.GetInt16("id"), Name = reader.GetString("name"), Items = reader.GetString("items") .Split(',') .Select(itemId => ItemsInfos.Find(x => x.Id == int.Parse(itemId))) .ToList(), BonusesDictionary = ItemSet.ToBonusDictionary(reader.GetString("effects2"), reader.GetString("effects3"), reader.GetString("effects4"), reader.GetString("effects5"), reader.GetString("effects6"), reader.GetString("effects7"), reader.GetString("effects8")).ToDictionary(x => x.Key, x => x.Value) }); } return(ItemSets.Count); }); task.Wait(); }
private static void LoadInventoryItems() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM inventory_items", "Inventory Items", (reader) => { while (reader.Read()) { InventoryItems.Add(new InventoryItem { Id = reader.GetInt16("id"), Character = Characters.Find(x => x.Id == reader.GetInt16("characterId")), ItemInfos = ItemsInfos.Find(x => x.Id == reader.GetInt16("ItemId")), ItemPosition = (StatsManager.Position)reader.GetInt16("position"), Quantity = reader.GetInt16("quantity"), Stats = ItemStats.ToStats(reader.GetString("stats")), }); } foreach (var character in Characters) { character.CalculateItemStats(); } return(InventoryItems.Count); }); task.Wait(); }
public static void Update(Character character) { StatsRepository.Update(character.Stats); AlignmentRepository.Update(character.Alignment); const string query = "UPDATE characters SET skin=@skin, level=@level, " + "pdvNow=@pdvNow, exp=@exp, mapId=@mapId, cellId=@cellId, direction=@direction, channels=@channels, " + "statsPoints=@statsPoints, spellsPoints=@spellsPoints, kamas=@kamas WHERE id=@id"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@id", character.Id)); command.Parameters.Add(new MySqlParameter("@skin", character.Skin)); command.Parameters.Add(new MySqlParameter("@level", character.Level)); command.Parameters.Add(new MySqlParameter("@pdvNow", character.PdvNow)); command.Parameters.Add(new MySqlParameter("@exp", character.Exp)); command.Parameters.Add(new MySqlParameter("@mapId", character.Map.Id)); command.Parameters.Add(new MySqlParameter("@cellId", character.MapCell)); command.Parameters.Add(new MySqlParameter("@direction", character.Direction)); command.Parameters.Add(new MySqlParameter("@channels", string.Format("{0}", string.Join("", character.Channels)))); command.Parameters.Add(new MySqlParameter("@statsPoints", character.StatsPoints)); command.Parameters.Add(new MySqlParameter("@spellsPoints", character.SpellPoints)); command.Parameters.Add(new MySqlParameter("@kamas", character.Kamas)); }); }
private static void LoadItemInfos() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM items_infos", "Items", (reader) => { while (reader.Read()) { ItemsInfos.Add(new ItemInfos { Id = reader.GetInt16("ID"), Name = reader.GetString("Name"), ItemType = (StatsManager.ItemType)reader.GetInt16("Type"), Level = reader.GetInt16("Level"), Weight = reader.GetInt16("Weight"), WeaponInfo = reader.GetString("WeaponInfo"), TwoHands = reader.GetBoolean("TwoHands"), IsEthereal = reader.GetBoolean("IsEthereal"), IsBuff = reader.GetBoolean("IsBuff"), Usable = reader.GetBoolean("Usable"), Targetable = reader.GetBoolean("Targetable"), Price = reader.GetInt32("Price"), Conditions = reader.GetString("Conditions"), Stats = ItemStats.ToStats(reader.GetString("stats")), UseEffects = reader.GetString("UseEffects"), }); } return(ItemsInfos.Count); }); task.Wait(); }
public static void Create(InventoryItem inventoryItem, bool addToList) { const string query = "INSERT INTO inventory_items SET id=@id, characterId=@characterId, itemId=@itemId, position=@position," + "stats=@stats, quantity=@quantity"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@id", inventoryItem.Id)); command.Parameters.Add(new MySqlParameter("@characterId", inventoryItem.Character.Id)); command.Parameters.Add(new MySqlParameter("@itemId", inventoryItem.ItemInfos.Id)); command.Parameters.Add(new MySqlParameter("@position", (int)inventoryItem.ItemPosition)); command.Parameters.Add(new MySqlParameter("@stats", string.Join(",", inventoryItem.Stats))); command.Parameters.Add(new MySqlParameter("@quantity", inventoryItem.Quantity)); }); if (!addToList) { return; } lock (DatabaseProvider.InventoryItems) DatabaseProvider.InventoryItems.Add(inventoryItem); }
private static void LoadMaps() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM maps_data", "Maps", (reader) => { while (reader.Read()) { var newMap = new Map { Id = reader.GetInt32("id"), Width = reader.GetInt32("width"), Height = reader.GetInt16("height"), PosX = reader.GetInt16("posX"), PosY = reader.GetInt16("posY"), MapData = reader.GetString("mapData"), Key = reader.GetString("decryptkey"), Time = reader.GetString("createTime"), Subarea = reader.GetInt16("subarea"), }; newMap.Cells = newMap.UncompressDatas(); Maps.Add(newMap); } return(Maps.Count); }); task.Wait(); }
public static void Create(Character character, int accountId) { const string query = "INSERT INTO characters SET id=@id, name=@name, classe=@classe, sex=@sex, color1=@color1, color2=@color2," + "color3=@color3, skin=@skin, level=@level, alignmentId=@alignmentId, statsId=@statsId, " + "pdvNow=@pdvNow, mapId=@mapId, cellId=@cellId, direction=@direction, channels=@channels, statsPoints=@statsPoints, " + "spellsPoints=@spellsPoints, kamas=@kamas"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@id", character.Id)); command.Parameters.Add(new MySqlParameter("@name", character.Name)); command.Parameters.Add(new MySqlParameter("@classe", (int)character.Classe)); command.Parameters.Add(new MySqlParameter("@sex", character.Sex)); command.Parameters.Add(new MySqlParameter("@color1", character.Color1)); command.Parameters.Add(new MySqlParameter("@color2", character.Color2)); command.Parameters.Add(new MySqlParameter("@color3", character.Color3)); command.Parameters.Add(new MySqlParameter("@skin", character.Skin)); command.Parameters.Add(new MySqlParameter("@level", character.Level)); command.Parameters.Add(new MySqlParameter("@alignmentId", character.Alignment.Id)); command.Parameters.Add(new MySqlParameter("@statsId", character.Stats.Id)); command.Parameters.Add(new MySqlParameter("@pdvNow", character.PdvNow)); command.Parameters.Add(new MySqlParameter("@mapId", character.Map.Id)); command.Parameters.Add(new MySqlParameter("@cellId", character.MapCell)); command.Parameters.Add(new MySqlParameter("@direction", character.Direction)); command.Parameters.Add(new MySqlParameter("@channels", string.Join("", character.Channels))); command.Parameters.Add(new MySqlParameter("@statsPoints", character.StatsPoints)); command.Parameters.Add(new MySqlParameter("@spellsPoints", character.SpellPoints)); command.Parameters.Add(new MySqlParameter("@kamas", character.Kamas)); }); Logs.LogWritter(Constant.GameFolder, string.Format("Création du personnage {0}", character.Name)); const string query2 = "INSERT INTO characters SET accountId=@accountId, gameserverId=@gameServer, characterId=@id"; Base.Repository.ExecuteQuery(query2, RealmDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@accountId", accountId)); command.Parameters.Add(new MySqlParameter("@gameServer", DatabaseProvider.ServerId)); command.Parameters.Add(new MySqlParameter("@id", character.Id)); }); lock (DatabaseProvider.Characters) DatabaseProvider.Characters.Add(character); lock (DatabaseProvider.AccountCharacters) DatabaseProvider.AccountCharacters.Add(new AccountCharacters { Account = DatabaseProvider.Accounts.Find(x => x.Id == accountId), Character = character }); }
public static void UpdateCharactersList(int id) { const string query = "SELECT * FROM characters WHERE accountId = @accountId AND gameServerId = @gsId"; var charactersId = new List <int>(); using (var connection = RealmDbManager.GetDatabaseConnection()) { using (var command = new MySqlCommand(query, connection)) { command.Parameters.Add(new MySqlParameter("@accountId", id)); command.Parameters.Add(new MySqlParameter("@gsId", DatabaseProvider.ServerId)); using (var reader = command.ExecuteReader()) { while (reader.Read()) { charactersId.Add(reader.GetInt16("characterId")); } } } } const string query2 = "SELECT * FROM characters WHERE FIND_IN_SET(id, @charactersId)"; using (var connection = GameDbManager.GetDatabaseConnection()) { using (var command = new MySqlCommand(query2, connection)) { command.Parameters.Add(new MySqlParameter("@charactersId", string.Join(",", charactersId))); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var character = DatabaseProvider.Characters.Find(x => x.Id == reader.GetInt16("id")); character.Name = reader.GetString("name"); character.Color1 = reader.GetInt32("color1"); character.Color2 = reader.GetInt32("color2"); character.Color3 = reader.GetInt32("color3"); character.Kamas = reader.GetInt32("kamas"); character.Level = reader.GetInt16("level"); character.Sex = reader.GetInt16("sex"); character.Skin = reader.GetInt16("skin"); character.Map = DatabaseProvider.Maps.Find(x => x.Id == reader.GetInt32("mapId")); character.MapCell = reader.GetInt32("cellId"); character.Direction = reader.GetInt16("direction"); character.StatsPoints = reader.GetInt32("statsPoints"); character.SpellPoints = reader.GetInt32("spellsPoints"); } } } } }
public static void RemoveFromAccount(int giftId, int accountId) { const string query = "DELETE FROM account_gifts WHERE giftId=@giftId AND accountId=@accountId"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@giftId", giftId)); command.Parameters.Add(new MySqlParameter("@accountId", accountId)); }); }
public static IEnumerable <Gift> FindAll(int accountId) { var giftItems = new List <GiftItems>(); const string query = "SELECT gi.giftId, gi.itemId, gi.quantity FROM gift_items gi, account_gifts ag WHERE ag.giftId = gi.giftId AND ag.accountId = @accountId"; const string query2 = "SELECT g.id, g.description, g.pictureUrl, g.title FROM gift g, account_gifts a WHERE a.giftId = g.id AND a.accountId = @accountId;"; using (var connection = GameDbManager.GetDatabaseConnection()) { using (var command = new MySqlCommand(query, connection)) { command.Parameters.Add(new MySqlParameter("@accountId", accountId)); using (var reader = command.ExecuteReader()) { while (reader.Read()) { giftItems.Add(new GiftItems { GiftId = reader.GetInt16("giftId"), Item = DatabaseProvider.ItemsInfos.Find(x => x.Id == reader.GetInt16("itemId")), Quantity = reader.GetInt16("quantity") }); } } } using (var command = new MySqlCommand(query2, connection)) { command.Parameters.Add(new MySqlParameter("@accountId", accountId)); using (var reader = command.ExecuteReader()) { while (reader.Read()) { yield return(new Gift { Id = reader.GetInt16("id"), Description = reader.GetString("description"), Items = giftItems, PictureUrl = reader.GetString("pictureUrl"), Title = reader.GetString("title") }); } } } } }
public static void Remove(InventoryItem inventoryItem, bool removeFromList) { const string query = "DELETE FROM Inventory_items WHERE id=@id"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => command.Parameters.Add(new MySqlParameter("@id", inventoryItem.Id))); if (!removeFromList) { return; } lock (DatabaseProvider.InventoryItems) DatabaseProvider.InventoryItems.Remove(inventoryItem); }
public static void Update(InventoryItem inventoryItem) { const string query = "UPDATE inventory_items SET id=@id, characterId=@characterId, itemId=@itemId, position=@position," + "stats=@stats, quantity=@quantity WHERE id=@id"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@id", inventoryItem.Id)); command.Parameters.Add(new MySqlParameter("@characterId", inventoryItem.Character.Id)); command.Parameters.Add(new MySqlParameter("@itemId", inventoryItem.ItemInfos.Id)); command.Parameters.Add(new MySqlParameter("@position", (int)inventoryItem.ItemPosition)); command.Parameters.Add(new MySqlParameter("@stats", string.Join(",", inventoryItem.Stats))); command.Parameters.Add(new MySqlParameter("@quantity", inventoryItem.Quantity)); }); }
public static void Update(Alignment alignment) { const string query = "UPDATE alignments SET Type=@Type, Honor=@Honor," + "Deshonor=@Deshonor, Level=@Level, Grade=@Grade, Enabled=@Enabled " + "WHERE id=@Id"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@Id", alignment.Id)); command.Parameters.Add(new MySqlParameter("@Type", alignment.Type)); command.Parameters.Add(new MySqlParameter("@Honor", alignment.Honor)); command.Parameters.Add(new MySqlParameter("@Deshonor", alignment.Deshonor)); command.Parameters.Add(new MySqlParameter("@Level", alignment.Level)); command.Parameters.Add(new MySqlParameter("@Grade", alignment.Grade)); command.Parameters.Add(new MySqlParameter("@Enabled", alignment.Enabled)); }); }
public static void Update(StatsManager stats) { const string query = "UPDATE character_stats SET Vitality=@Vitality, Wisdom=@Wisdom," + "Strenght=@Strenght, Intelligence=@Intelligence, Chance=@Chance, Agility=@Agility " + "WHERE id=@Id"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@Id", stats.Id)); command.Parameters.Add(new MySqlParameter("@Vitality", stats.Vitality)); command.Parameters.Add(new MySqlParameter("@Wisdom", stats.Wisdom)); command.Parameters.Add(new MySqlParameter("@Strenght", stats.Strength)); command.Parameters.Add(new MySqlParameter("@Intelligence", stats.Intelligence)); command.Parameters.Add(new MySqlParameter("@Chance", stats.Chance)); command.Parameters.Add(new MySqlParameter("@Agility", stats.Agility)); }); }
public static void Create(Alignment alignment) { const string query = "INSERT INTO alignments SET Id=@Id, Type=@Type, Honor=@Honor," + "Deshonor=@Deshonor, Level=@Level, Grade=@Grade, Enabled=@Enabled"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@Id", alignment.Id)); command.Parameters.Add(new MySqlParameter("@Type", alignment.Type)); command.Parameters.Add(new MySqlParameter("@Honor", alignment.Honor)); command.Parameters.Add(new MySqlParameter("@Deshonor", alignment.Deshonor)); command.Parameters.Add(new MySqlParameter("@Level", alignment.Level)); command.Parameters.Add(new MySqlParameter("@Grade", alignment.Grade)); command.Parameters.Add(new MySqlParameter("@Enabled", alignment.Enabled)); }); lock (DatabaseProvider.Alignments) DatabaseProvider.Alignments.Add(alignment); }
public static void Create(StatsManager stats) { const string query = "INSERT INTO character_stats SET Id=@Id, Vitality=@Vitality, Wisdom=@Wisdom," + "Strenght=@Strenght, Intelligence=@Intelligence, Chance=@Chance, Agility=@Agility"; Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(), (command) => { command.Parameters.Add(new MySqlParameter("@Id", stats.Id)); command.Parameters.Add(new MySqlParameter("@Vitality", stats.Vitality)); command.Parameters.Add(new MySqlParameter("@Wisdom", stats.Wisdom)); command.Parameters.Add(new MySqlParameter("@Strenght", stats.Strength)); command.Parameters.Add(new MySqlParameter("@Intelligence", stats.Intelligence)); command.Parameters.Add(new MySqlParameter("@Chance", stats.Chance)); command.Parameters.Add(new MySqlParameter("@Agility", stats.Agility)); }); lock (DatabaseProvider.StatsManager) DatabaseProvider.StatsManager.Add(stats); }
private static void LoadSubareas() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM subareas", "Subareas", (reader) => { while (reader.Read()) { Subareas.Add(new Subarea { Id = reader.GetInt32("id"), Name = reader.GetString("name"), NeedRegistered = reader.GetBoolean("needRegistered") }); } return(Subareas.Count); }); task.Wait(); }
private static void LoadTriggers() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM maps_triggers", "Trigger", (reader) => { while (reader.Read()) { MapTriggers.Add(new MapTrigger { Map = reader.GetInt32("MapID"), Cell = reader.GetInt32("CellID"), NewMap = reader.GetInt32("NewMap"), NewCell = reader.GetInt32("NewCell") }); } return(MapTriggers.Count); }); task.Wait(); }
private static void LoadCharacters() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM characters", "Characters", (reader) => { while (reader.Read()) { Characters.Add(new Character { Id = reader.GetInt16("id"), Name = reader.GetString("name"), Classe = (Character.Class)reader.GetInt16("classe"), Color1 = reader.GetInt32("color1"), Color2 = reader.GetInt32("color2"), Color3 = reader.GetInt32("color3"), Level = reader.GetInt16("level"), Sex = reader.GetInt16("sex"), Skin = reader.GetInt16("skin"), Stats = StatsManager.Find(x => x.Id == reader.GetInt16("statsId")), Alignment = Alignments.Find(x => x.Id == reader.GetInt16("alignmentId")), PdvNow = reader.GetInt16("pdvNow"), PdvMax = reader.GetInt16("pdvNow"), Map = Maps.Find(x => x.Id == reader.GetInt32("mapId")), MapCell = reader.GetInt32("cellId"), Direction = reader.GetInt16("direction"), StatsPoints = reader.GetInt32("statsPoints"), SpellPoints = reader.GetInt32("spellsPoints"), Kamas = reader.GetInt32("kamas"), Channels = reader.GetString("channels").Select(channel => new Channel { Header = (Channel.ChannelHeader)channel }).ToList(), }); } return(Characters.Count); }); task.Wait(); }
private static void LoadExperience() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM exp_data", "Levels", (reader) => { while (reader.Read()) { Experiences.Add(new Experience { Level = reader.GetInt32("Level"), CharacterExp = reader.GetInt64("Character"), JobExp = reader.GetInt32("Job"), MountExp = reader.GetInt32("Mount"), PvpExp = reader.GetInt32("Pvp") }); } return(Experiences.Count); }); task.Wait(); }
private static void LoadStatsManager() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM character_stats", "Character Stats", (reader) => { while (reader.Read()) { StatsManager.Add(new StatsManager { Id = reader.GetInt16("id"), Vitality = new GeneralStats { Base = reader.GetInt16("Vitality") }, Wisdom = new GeneralStats { Base = reader.GetInt16("Wisdom") }, Strength = new GeneralStats { Base = reader.GetInt16("Strenght") }, Intelligence = new GeneralStats { Base = reader.GetInt16("Intelligence") }, Chance = new GeneralStats { Base = reader.GetInt16("Chance") }, Agility = new GeneralStats { Base = reader.GetInt16("Agility") }, }); } return(StatsManager.Count); }); task.Wait(); }
private static void LoadAlignments() { var task = ExecuteQueryLight(GameDbManager.GetDatabaseConnection(), "SELECT * FROM alignments", "Alignments", (reader) => { while (reader.Read()) { Alignments.Add(new Alignment { Id = reader.GetInt16("Id"), Type = reader.GetInt16("Type"), Honor = reader.GetInt16("Honor"), Deshonor = reader.GetInt16("Deshonor"), Grade = reader.GetInt16("Grade"), Level = reader.GetInt16("Level"), Enabled = reader.GetBoolean("Enabled") }); } return(Alignments.Count); }); task.Wait(); }