/// <summary> /// Initializes the <see cref="PersistentCharacterStatusEffects"/> class. /// </summary> static PersistentCharacterStatusEffects() { _dbController = DbControllerBase.GetInstance(); _insertQuery = _dbController.GetQuery<InsertCharacterStatusEffectQuery>(); _deleteQuery = _dbController.GetQuery<DeleteCharacterStatusEffectQuery>(); _updateQuery = _dbController.GetQuery<UpdateCharacterStatusEffectQuery>(); }
/// <summary> /// Loads the requirements for starting a quest. /// </summary> /// <param name="dbController">The <see cref="IDbController"/> to use to load values.</param> /// <returns>The requirements for starting a quest.</returns> IQuestRequirementCollection <User> LoadStartRequirements(IDbController dbController) { var questManager = QuestManager.Instance; var l = new List <IQuestRequirement <User> >(); // Items var reqItems = dbController.GetQuery <SelectQuestRequireStartItemQuery>().Execute(QuestID); if (!reqItems.IsEmpty()) { l.Add(new ItemsQuestRequirement(this, reqItems.Select(x => new QuestItemTemplateAmount(x.ItemTemplateID, x.Amount)))); } // Complete quests var reqCompleteQuests = dbController.GetQuery <SelectQuestRequireStartCompleteQuestsQuery>().Execute(QuestID); if (!reqCompleteQuests.IsEmpty()) { if (!questManager.IsEmpty()) { l.Add(new CompleteQuestQuestRequirement(this, reqCompleteQuests.Select(questManager.GetQuest))); } } return(new QuestRequirementCollection <User>(l)); }
/// <summary> /// Gets the <see cref="IMapTable"/>s for all of the maps. /// </summary> /// <param name="dbController">The <see cref="IDbController"/> to use. If null, will attempt to find /// the <see cref="IDbController"/> instance automatically.</param> /// <returns> /// The <see cref="IMapTable"/>s for all of the maps. /// </returns> /// <exception cref="ArgumentException"><paramref name="dbController"/> is null and no valid <see cref="IDbController"/> /// instance could be found automatically.</exception> public static IEnumerable <IMapTable> FindAllMaps(IDbController dbController = null) { if (dbController == null) { dbController = DbControllerBase.GetInstance(); } if (dbController == null) { throw new ArgumentException("Param was null and could not find a valid IDbController instance.", "dbController"); } // Get the IDs var ids = dbController.GetQuery <SelectMapIDsQuery>().Execute(); // Get all of the maps one at a time using the IDs var ret = new List <IMapTable>(); var templateQuery = dbController.GetQuery <SelectMapQuery>(); foreach (var id in ids) { var template = templateQuery.Execute(id); ret.Add(template); } // Return the results sorted return(ret.OrderBy(x => x.ID).ToImmutable()); }
/// <summary> /// Loads the requirements for finishing a quest. /// </summary> /// <param name="dbController">The <see cref="IDbController"/> to use to load values.</param> /// <returns>The requirements for finishing a quest.</returns> IQuestRequirementCollection <User> LoadFinishRequirements(IDbController dbController) { var questManager = QuestManager.Instance; var l = new List <IQuestRequirement <User> >(); // Items var reqItems = dbController.GetQuery <SelectQuestRequireFinishItemQuery>().Execute(QuestID); Debug.Assert(reqItems.All(x => x.QuestID == QuestID)); if (!reqItems.IsEmpty()) { l.Add(new ItemsQuestRequirement(this, reqItems.Select(x => new QuestItemTemplateAmount(x.ItemTemplateID, x.Amount)))); } // Kills var reqKills = dbController.GetQuery <SelectQuestRequireKillQuery>().Execute(QuestID); Debug.Assert(reqItems.All(x => x.QuestID == QuestID)); if (!reqKills.IsEmpty()) { l.Add(new KillQuestRequirement(this, reqKills.Select(x => new KeyValuePair <CharacterTemplateID, ushort>(x.CharacterTemplateID, x.Amount)))); } // Complete quests var reqCompleteQuests = dbController.GetQuery <SelectQuestRequireFinishCompleteQuestsQuery>().Execute(QuestID); if (!reqCompleteQuests.IsEmpty()) { l.Add(new CompleteQuestQuestRequirement(this, reqCompleteQuests.Select(questManager.GetQuest))); } return(new QuestRequirementCollection <User>(l)); }
/// <summary> /// Initializes the <see cref="PersistentCharacterStatusEffects"/> class. /// </summary> static PersistentCharacterStatusEffects() { _dbController = DbControllerBase.GetInstance(); _insertQuery = _dbController.GetQuery <InsertCharacterStatusEffectQuery>(); _deleteQuery = _dbController.GetQuery <DeleteCharacterStatusEffectQuery>(); _updateQuery = _dbController.GetQuery <UpdateCharacterStatusEffectQuery>(); }
/// <summary> /// Initializes a new instance of the <see cref="EditorCharacterTemplate"/> class. /// </summary> /// <param name="charTemplateTable">The <see cref="ICharacterTemplateTable"/>.</param> /// <param name="dbController">The <see cref="IDbController"/>.</param> public EditorCharacterTemplate(ICharacterTemplateTable charTemplateTable, IDbController dbController) { var id = charTemplateTable.ID; // Load the main table values CopyValuesFrom(charTemplateTable); // Load values from other tables // Equipped var equippedRaw = dbController.GetQuery<SelectCharacterTemplateEquippedQuery>().Execute(id); if (equippedRaw != null) { var equipped = equippedRaw.Select(x => new CharacterTemplateEquippedItem(x.ItemTemplateID, x.Chance)); _equipped.AddRange(equipped); } // Inventory var inventoryRaw = dbController.GetQuery<SelectCharacterTemplateInventoryQuery>().Execute(id); if (inventoryRaw != null) { var inventory = inventoryRaw.Select(x => new CharacterTemplateInventoryItem(x.ItemTemplateID, x.Chance, x.Min, x.Max)); _inventory.AddRange(inventory); } // Known skills var knownSkills = dbController.GetQuery<SelectCharacterTemplateSkillsQuery>().Execute(id); if (knownSkills != null) _knownSkills.AddRange(knownSkills); // Quests var quests = dbController.GetQuery<SelectCharacterTemplateQuestsQuery>().Execute(id); if (quests != null) _quests.AddRange(quests); }
/// <summary> /// Initializes a new instance of the <see cref="EditorShop"/> class. /// </summary> /// <param name="id">The <see cref="ShopID"/>.</param> /// <param name="dbController">The <see cref="IDbController"/>.</param> /// <exception cref="ArgumentException">No shop exists for the specified <paramref name="id"/>.</exception> public EditorShop(ShopID id, IDbController dbController) { _id = id; // Grab the general shop information var table = dbController.GetQuery <SelectShopQuery>().Execute(id); if (table == null) { const string errmsg = "No Shop with ID `{0}` exists."; throw new ArgumentException(string.Format(errmsg, id), "id"); } Debug.Assert(id == table.ID); Name = table.Name; CanBuy = table.CanBuy; // Grab the items from the database and add them var dbItems = dbController.GetQuery <SelectShopItemsQuery>().Execute(id); _items = new List <ItemTemplateID>(); if (dbItems != null) { _items.AddRange(dbItems.Select(x => x.ItemTemplateID)); } }
/// <summary> /// When overridden in the derived class, provides a chance to cache frequently used queries instead of /// having to grab the query from the <see cref="IDbController"/> every time. Caching is completely /// optional, but if you do cache any queries, it should be done here. Do not use this method for /// anything other than caching queries from the <paramref name="dbController"/>. /// </summary> /// <param name="dbController">The <see cref="IDbController"/> to grab the queries from.</param> protected override void CacheDbQueries(IDbController dbController) { _selectShopItemsQuery = dbController.GetQuery <SelectShopItemsQuery>(); _selectShopQuery = dbController.GetQuery <SelectShopQuery>(); base.CacheDbQueries(dbController); }
/// <summary> /// Gets and reserves the next free <see cref="ItemTemplateID"/>. /// </summary> /// <param name="dbController">The db controller.</param> /// <returns>The next free <see cref="ItemTemplateID"/>.</returns> public static ItemTemplateID ReserveFreeItemTemplateID(IDbController dbController) { var getUsedQuery = dbController.GetQuery <SelectItemTemplateIDsQuery>(); var selectQuery = dbController.GetQuery <SelectItemTemplateQuery>(); var insertByIDQuery = dbController.GetQuery <InsertItemTemplateIDOnlyQuery>(); return(GetFreeID(dbController, true, t => new ItemTemplateID(t), x => (int)x, getUsedQuery.Execute, selectQuery.Execute, insertByIDQuery.Execute)); }
/// <summary> /// When overridden in the derived class, provides a chance to cache frequently used queries instead of /// having to grab the query from the <see cref="IDbController"/> every time. Caching is completely /// optional, but if you do cache any queries, it should be done here. Do not use this method for /// anything other than caching queries from the <paramref name="dbController"/>. /// </summary> /// <param name="dbController">The <see cref="IDbController"/> to grab the queries from.</param> protected override void CacheDbQueries(IDbController dbController) { _selectAllianceQuery = dbController.GetQuery <SelectAllianceQuery>(); _selectAllianceAttackableQuery = dbController.GetQuery <SelectAllianceAttackableQuery>(); _selectAllianceHostileQuery = dbController.GetQuery <SelectAllianceHostileQuery>(); base.CacheDbQueries(dbController); }
/// <summary> /// When overridden in the derived class, provides a chance to cache frequently used queries instead of /// having to grab the query from the <see cref="IDbController"/> every time. Caching is completely /// optional, but if you do cache any queries, it should be done here. Do not use this method for /// anything other than caching queries from the <paramref name="dbController"/>. /// </summary> /// <param name="dbController">The <see cref="IDbController"/> to grab the queries from.</param> protected override void CacheDbQueries(IDbController dbController) { _selectCharacterTemplateQuery = dbController.GetQuery <SelectCharacterTemplateQuery>(); _selectInventoryQuery = dbController.GetQuery <SelectCharacterTemplateInventoryQuery>(); _selectEquippedQuery = dbController.GetQuery <SelectCharacterTemplateEquippedQuery>(); _selectQuestsQuery = dbController.GetQuery <SelectCharacterTemplateQuestsQuery>(); _selectSkillsQuery = dbController.GetQuery <SelectCharacterTemplateSkillsQuery>(); base.CacheDbQueries(dbController); }
/// <summary> /// Gets and reserves the next free <see cref="QuestID"/>. /// </summary> /// <param name="dbController">The db controller.</param> /// <returns>The next free <see cref="QuestID"/>.</returns> public static QuestID ReserveFreeQuestID(IDbController dbController) { var getUsedQuery = dbController.GetQuery <SelectQuestIDsQuery>(); var selectQuery = dbController.GetQuery <SelectQuestQuery>(); var insertByIDQuery = dbController.GetQuery <InsertQuestQuery>(); return(GetFreeID(dbController, true, t => new QuestID(t), x => (int)x, getUsedQuery.Execute, selectQuery.Execute, x => insertByIDQuery.Execute(new QuestTable { ID = x }))); }
/// <summary> /// Gets and reserves the next free <see cref="ShopID"/>. /// </summary> /// <param name="dbController">The db controller.</param> /// <returns>The next free <see cref="ShopID"/>.</returns> public static ShopID ReserveFreeShopID(IDbController dbController) { var getUsedQuery = dbController.GetQuery <SelectShopIDsQuery>(); var selectQuery = dbController.GetQuery <SelectShopQuery>(); var insertByIDQuery = dbController.GetQuery <InsertUpdateShopQuery>(); return(GetFreeID(dbController, true, t => new ShopID(t), x => (int)x, getUsedQuery.Execute, selectQuery.Execute, x => insertByIDQuery.Execute(new ShopTable { ID = x, Name = string.Empty }))); }
/// <summary> /// Initializes a new instance of the <see cref="GuildManagerBase{T}"/> class. /// </summary> GuildManager(IDbController dbController) { _dbController = dbController; // Cache the queries this object will be using _selectGuildByNameQuery = _dbController.GetQuery <SelectGuildByNameQuery>(); _selectGuildByTagQuery = _dbController.GetQuery <SelectGuildByTagQuery>(); _insertGuildEventQuery = _dbController.GetQuery <InsertGuildEventQuery>(); _insertGuildQuery = _dbController.GetQuery <InsertGuildQuery>(); Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="EditorQuest"/> class. /// </summary> /// <param name="questID">The quest ID.</param> /// <param name="dbController">The <see cref="IDbController"/>.</param> /// <exception cref="ArgumentException">No quests for the given <paramref name="questID"/> exist.</exception> public EditorQuest(QuestID questID, IDbController dbController) { _id = questID; // Get the quest database table row var questTable = dbController.GetQuery<SelectQuestQuery>().Execute(questID); if (questTable == null) { const string errmsg = "Invalid QuestID ({0}) supplied - no quests with this ID exists."; throw new ArgumentException(string.Format(errmsg, questID), "questID"); } Debug.Assert(questID == questTable.ID); // Get the quest description stuff from the client-side var qd = _questDescriptions[ID]; if (qd != null) { Name = qd.Name; Description = qd.Description; } else { Name = string.Empty; Description = string.Empty; } // Get the quest details from the server side RewardExp = questTable.RewardExp; RewardCash = questTable.RewardCash; Repeatable = questTable.Repeatable; _startItems = dbController.GetQuery<SelectQuestRequireStartItemQuery>().Execute(questID).Select( x => new MutablePair<ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList(); _finishItems = dbController.GetQuery<SelectQuestRequireFinishItemQuery>().Execute(questID).Select( x => new MutablePair<ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList(); _startQuests = dbController.GetQuery<SelectQuestRequireStartCompleteQuestsQuery>().Execute(questID).ToList(); _finishQuests = dbController.GetQuery<SelectQuestRequireFinishCompleteQuestsQuery>().Execute(questID).ToList(); _rewardItems = dbController.GetQuery<SelectQuestRewardItemQuery>().Execute(questID).Select( x => new MutablePair<ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList(); _kills = dbController.GetQuery<SelectQuestRequireKillQuery>().Execute(questID).Select( x => new MutablePair<CharacterTemplateID, ushort>(x.CharacterTemplateID, x.Amount)).ToList(); }
/// <summary> /// Loads a MapSpawnValues from the database. /// </summary> /// <param name="dbController">DbController used to communicate with the database.</param> /// <param name="id">ID of the MapSpawnValues to load.</param> /// <returns>The MapSpawnValues with ID <paramref name="id"/>.</returns> public static MapSpawnValues Load(IDbController dbController, MapSpawnValuesID id) { var values = dbController.GetQuery <SelectMapSpawnQuery>().Execute(id); Debug.Assert(id == values.ID); return(new MapSpawnValues(dbController, values)); }
/// <summary> /// Initializes a new instance of the <see cref="EditorCharacterTemplate"/> class. /// </summary> /// <param name="charTemplateTable">The <see cref="ICharacterTemplateTable"/>.</param> /// <param name="dbController">The <see cref="IDbController"/>.</param> public EditorCharacterTemplate(ICharacterTemplateTable charTemplateTable, IDbController dbController) { var id = charTemplateTable.ID; // Load the main table values CopyValuesFrom(charTemplateTable); // Load values from other tables // Equipped var equippedRaw = dbController.GetQuery <SelectCharacterTemplateEquippedQuery>().Execute(id); if (equippedRaw != null) { var equipped = equippedRaw.Select(x => new CharacterTemplateEquippedItem(x.ItemTemplateID, x.Chance)); _equipped.AddRange(equipped); } // Inventory var inventoryRaw = dbController.GetQuery <SelectCharacterTemplateInventoryQuery>().Execute(id); if (inventoryRaw != null) { var inventory = inventoryRaw.Select(x => new CharacterTemplateInventoryItem(x.ItemTemplateID, x.Chance, x.Min, x.Max)); _inventory.AddRange(inventory); } // Known skills var knownSkills = dbController.GetQuery <SelectCharacterTemplateSkillsQuery>().Execute(id); if (knownSkills != null) { _knownSkills.AddRange(knownSkills); } // Quests var quests = dbController.GetQuery <SelectCharacterTemplateQuestsQuery>().Execute(id); if (quests != null) { _quests.AddRange(quests); } }
/// <summary> /// Initializes a new instance of the <see cref="GuildMemberPerformerBase"/> class. /// </summary> /// <param name="dbController">The <see cref="IDbController"/>.</param> /// <param name="findGuildMember">The <see cref="Func{T,U}"/> used to find a guild member by name.</param> /// <exception cref="ArgumentNullException"><paramref name="dbController" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="findGuildMember" /> is <c>null</c>.</exception> public GuildMemberPerformer(IDbController dbController, Func<string, IGuildMember> findGuildMember) : base(GetSaveHandler(dbController)) { if (dbController == null) throw new ArgumentNullException("dbController"); if (findGuildMember == null) throw new ArgumentNullException("findGuildMember"); _findGuildMember = findGuildMember; _selectGuildMemberQuery = dbController.GetQuery<SelectGuildMemberByNameQuery>(); }
/// <summary> /// Initializes a new instance of the <see cref="Quest"/> class. /// </summary> /// <param name="questID">The quest's ID.</param> /// <param name="dbController">The <see cref="IDbController"/> to use to load the values.</param> public Quest(QuestID questID, IDbController dbController) { _questID = questID; var info = dbController.GetQuery <SelectQuestQuery>().Execute(questID); _repeatable = info.Repeatable; _rewards = LoadRewards(questID, info, dbController); _startRequirements = LoadStartRequirements(dbController); _finishRequirements = LoadFinishRequirements(dbController); }
/// <summary> /// Initializes a new instance of the <see cref="EditorAlliance"/> class. /// </summary> /// <param name="id">The <see cref="AllianceID"/>.</param> /// <param name="dbController">The <see cref="IDbController"/>.</param> /// <exception cref="ArgumentException">No <see cref="Alliance"/> exists for the given <paramref name="id"/>.</exception> public EditorAlliance(AllianceID id, IDbController dbController) { _id = id; var table = dbController.GetQuery<SelectAllianceQuery>().Execute(id); if (table == null) { const string errmsg = "No Alliance with ID `{0}` exists."; throw new ArgumentException(string.Format(errmsg, id), "id"); } Debug.Assert(id == table.ID); Name = table.Name; var attackable = dbController.GetQuery<SelectAllianceAttackableQuery>().Execute(id); _attackable = new List<AllianceID>(attackable.Select(x => x.AttackableID)); var hostile = dbController.GetQuery<SelectAllianceHostileQuery>().Execute(id); _hostile = new List<AllianceID>(hostile.Select(x => x.HostileID)); }
/// <summary> /// Creates an <see cref="Action{T}"/> needed for the <see cref="GuildMemberPerformer"/> to save the guild /// state of a <see cref="IGuildMember"/>. /// </summary> /// <param name="dbController"></param> /// <returns></returns> static Action<IGuildMember> GetSaveHandler(IDbController dbController) { var replaceQuery = dbController.GetQuery<InsertGuildMemberQuery>(); var deleteQuery = dbController.GetQuery<DeleteGuildMemberQuery>(); return delegate(IGuildMember target) { if (target.Guild == null) { var id = new CharacterID(target.ID); deleteQuery.Execute(id); } else { var id = new CharacterID(target.ID); var guildID = target.Guild.ID; var rank = target.GuildRank; var args = new InsertGuildMemberQuery.QueryArgs(id, guildID, rank); replaceQuery.Execute(args); } }; }
/// <summary> /// Loads all of the MapSpawnValues for the given <paramref name="mapID"/> from the database. /// </summary> /// <param name="dbController">DbController used to communicate with the database.</param> /// <param name="mapID">Index of the map to load the MapSpawnValues for.</param> /// <returns>An IEnumerable of all of the MapSpawnValues for the given <paramref name="mapID"/>.</returns> public static IEnumerable <MapSpawnValues> Load(IDbController dbController, MapID mapID) { var ret = new List <MapSpawnValues>(); var queryValues = dbController.GetQuery <SelectMapSpawnsOnMapQuery>().Execute(mapID); foreach (var v in queryValues) { Debug.Assert(v.MapID == mapID); ret.Add(new MapSpawnValues(dbController, v)); } return(ret); }
/// <summary> /// Creates an <see cref="Action{T}"/> needed for the <see cref="GuildMemberPerformer"/> to save the guild /// state of a <see cref="IGuildMember"/>. /// </summary> /// <param name="dbController"></param> /// <returns></returns> static Action <IGuildMember> GetSaveHandler(IDbController dbController) { var replaceQuery = dbController.GetQuery <InsertGuildMemberQuery>(); var deleteQuery = dbController.GetQuery <DeleteGuildMemberQuery>(); return(delegate(IGuildMember target) { if (target.Guild == null) { var id = new CharacterID(target.ID); deleteQuery.Execute(id); } else { var id = new CharacterID(target.ID); var guildID = target.Guild.ID; var rank = target.GuildRank; var args = new InsertGuildMemberQuery.QueryArgs(id, guildID, rank); replaceQuery.Execute(args); } }); }
/// <summary> /// Initializes a new instance of the <see cref="EditorShop"/> class. /// </summary> /// <param name="id">The <see cref="ShopID"/>.</param> /// <param name="dbController">The <see cref="IDbController"/>.</param> /// <exception cref="ArgumentException">No shop exists for the specified <paramref name="id"/>.</exception> public EditorShop(ShopID id, IDbController dbController) { _id = id; // Grab the general shop information var table = dbController.GetQuery<SelectShopQuery>().Execute(id); if (table == null) { const string errmsg = "No Shop with ID `{0}` exists."; throw new ArgumentException(string.Format(errmsg, id), "id"); } Debug.Assert(id == table.ID); Name = table.Name; CanBuy = table.CanBuy; // Grab the items from the database and add them var dbItems = dbController.GetQuery<SelectShopItemsQuery>().Execute(id); _items = new List<ItemTemplateID>(); if (dbItems != null) _items.AddRange(dbItems.Select(x => x.ItemTemplateID)); }
/// <summary> /// Initializes a new instance of the <see cref="EditorQuest"/> class. /// </summary> /// <param name="questID">The quest ID.</param> /// <param name="dbController">The <see cref="IDbController"/>.</param> /// <exception cref="ArgumentException">No quests for the given <paramref name="questID"/> exist.</exception> public EditorQuest(QuestID questID, IDbController dbController) { _id = questID; // Get the quest database table row var questTable = dbController.GetQuery <SelectQuestQuery>().Execute(questID); if (questTable == null) { const string errmsg = "Invalid QuestID ({0}) supplied - no quests with this ID exists."; throw new ArgumentException(string.Format(errmsg, questID), "questID"); } Debug.Assert(questID == questTable.ID); // Get the quest description stuff from the client-side var qd = _questDescriptions[ID]; if (qd != null) { Name = qd.Name; Description = qd.Description; } else { Name = string.Empty; Description = string.Empty; } // Get the quest details from the server side RewardExp = questTable.RewardExp; RewardCash = questTable.RewardCash; Repeatable = questTable.Repeatable; _startItems = dbController.GetQuery <SelectQuestRequireStartItemQuery>().Execute(questID).Select( x => new MutablePair <ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList(); _finishItems = dbController.GetQuery <SelectQuestRequireFinishItemQuery>().Execute(questID).Select( x => new MutablePair <ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList(); _startQuests = dbController.GetQuery <SelectQuestRequireStartCompleteQuestsQuery>().Execute(questID).ToList(); _finishQuests = dbController.GetQuery <SelectQuestRequireFinishCompleteQuestsQuery>().Execute(questID).ToList(); _rewardItems = dbController.GetQuery <SelectQuestRewardItemQuery>().Execute(questID).Select( x => new MutablePair <ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList(); _kills = dbController.GetQuery <SelectQuestRequireKillQuery>().Execute(questID).Select( x => new MutablePair <CharacterTemplateID, ushort>(x.CharacterTemplateID, x.Amount)).ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="EditorAlliance"/> class. /// </summary> /// <param name="id">The <see cref="AllianceID"/>.</param> /// <param name="dbController">The <see cref="IDbController"/>.</param> /// <exception cref="ArgumentException">No <see cref="Alliance"/> exists for the given <paramref name="id"/>.</exception> public EditorAlliance(AllianceID id, IDbController dbController) { _id = id; var table = dbController.GetQuery <SelectAllianceQuery>().Execute(id); if (table == null) { const string errmsg = "No Alliance with ID `{0}` exists."; throw new ArgumentException(string.Format(errmsg, id), "id"); } Debug.Assert(id == table.ID); Name = table.Name; var attackable = dbController.GetQuery <SelectAllianceAttackableQuery>().Execute(id); _attackable = new List <AllianceID>(attackable.Select(x => x.AttackableID)); var hostile = dbController.GetQuery <SelectAllianceHostileQuery>().Execute(id); _hostile = new List <AllianceID>(hostile.Select(x => x.HostileID)); }
/// <summary> /// Initializes a new instance of the <see cref="GuildMemberPerformerBase"/> class. /// </summary> /// <param name="dbController">The <see cref="IDbController"/>.</param> /// <param name="findGuildMember">The <see cref="Func{T,U}"/> used to find a guild member by name.</param> /// <exception cref="ArgumentNullException"><paramref name="dbController" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="findGuildMember" /> is <c>null</c>.</exception> public GuildMemberPerformer(IDbController dbController, Func <string, IGuildMember> findGuildMember) : base(GetSaveHandler(dbController)) { if (dbController == null) { throw new ArgumentNullException("dbController"); } if (findGuildMember == null) { throw new ArgumentNullException("findGuildMember"); } _findGuildMember = findGuildMember; _selectGuildMemberQuery = dbController.GetQuery <SelectGuildMemberByNameQuery>(); }
/// <summary> /// Loads the rewards for finishing a quest. /// </summary> /// <param name="questID">The ID of the quest.</param> /// <param name="table">The <see cref="IQuestTable"/>.</param> /// <param name="dbController">The <see cref="IDbController"/> to use to load values.</param> /// <returns>The rewards for finishing a quest.</returns> static IQuestRewardCollection <User> LoadRewards(QuestID questID, IQuestTable table, IDbController dbController) { var l = new List <IQuestReward <User> > { new MoneyQuestReward(table.RewardCash), new ExpQuestReward(table.RewardExp) }; // Items var rewardItems = dbController.GetQuery <SelectQuestRewardItemQuery>().Execute(questID); if (!rewardItems.IsEmpty()) { l.Add(new ItemsQuestReward(rewardItems.Select(x => new QuestItemTemplateAmount(x.ItemTemplateID, x.Amount)))); } return(new QuestRewardCollection <User>(l)); }
/// <summary> /// Checks if the CharacterTemplate with the given CharacterTemplateID exists in the database. /// </summary> /// <param name="id">CharacterTemplateID to check.</param> /// <returns>True if a CharacterTemplate with the given id exists; otherwise false.</returns> public static bool TemplateExists(this CharacterTemplateID id) { IDbController dbController = DbControllerBase.GetInstance(); var query = dbController.GetQuery <SelectCharacterTemplateQuery>(); try { var result = query.Execute(id); if (result == null) { return(false); } } catch (ArgumentException) { return(false); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="WorldStatsTracker"/> class. /// </summary> /// <param name="dbController">The db controller.</param> /// <exception cref="ArgumentNullException"><paramref name="dbController"/> is null.</exception> WorldStatsTracker(IDbController dbController) : base(_logNetStatsRate) { // Locally cache an instance of all the queries we will be using _npcKillUserQuery = dbController.GetQuery <InsertWorldStatsNPCKillUserQuery>(); _userConsumeItemQuery = dbController.GetQuery <InsertWorldStatsUserConsumeItemQuery>(); _userKillNPCQuery = dbController.GetQuery <InsertWorldStatsUserKillNpcQuery>(); _userLevelQuery = dbController.GetQuery <InsertWorldStatsUserLevelQuery>(); _userShoppingQuery = dbController.GetQuery <InsertWorldStatsUserShoppingQuery>(); _networkQuery = dbController.GetQuery <InsertWorldStatsNetworkQuery>(); _guildUserChangeQuery = dbController.GetQuery <InsertWorldStatsGuildUserChangeQuery>(); _questCancelQuery = dbController.GetQuery <InsertWorldStatsQuestCancelQuery>(); _questCompleteQuery = dbController.GetQuery <InsertWorldStatsQuestCompleteQuery>(); _questAcceptQuery = dbController.GetQuery <InsertWorldStatsQuestAcceptQuery>(); _countConsumeItemQuery = dbController.GetQuery <InsertWorldStatsCountConsumeItemQuery>(); _countItemBuyQuery = dbController.GetQuery <InsertWorldStatsCountItemBuyQuery>(); _countItemCreateQuery = dbController.GetQuery <InsertWorldStatsCountItemCreateQuery>(); _countItemSellQuery = dbController.GetQuery <InsertWorldStatsCountItemSellQuery>(); _countNPCKillUserQuery = dbController.GetQuery <InsertWorldStatsCountNPCKillUserQuery>(); _countShopBuyQuery = dbController.GetQuery <InsertWorldStatsCountShopBuyQuery>(); _countShopSellQuery = dbController.GetQuery <InsertWorldStatsCountShopSellQuery>(); _countUserConsumeItemQuery = dbController.GetQuery <InsertWorldStatsCountUserConsumeItemQuery>(); _countUserKillNPCQuery = dbController.GetQuery <InsertWorldStatsCountUserKillNPCQuery>(); }
/// <summary> /// When overridden in the derived class, provides a chance to cache frequently used queries instead of /// having to grab the query from the <see cref="IDbController"/> every time. Caching is completely /// optional, but if you do cache any queries, it should be done here. Do not use this method for /// anything other than caching queries from the <paramref name="dbController"/>. /// </summary> /// <param name="dbController">The <see cref="IDbController"/> to grab the queries from.</param> protected override void CacheDbQueries(IDbController dbController) { _selectItemTemplateQuery = dbController.GetQuery <SelectItemTemplateQuery>(); base.CacheDbQueries(dbController); }
static MapSpawnValuesID GetFreeID(IDbController dbController) { return(dbController.GetQuery <MapSpawnValuesIDCreator>().GetNext()); }
/// <summary> /// Handles the Click event of the btnAllianceDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnAllianceDelete_Click(object sender, EventArgs e) { var a = pgAlliance.SelectedObject as EditorAlliance; if (a == null) { return; } const string confirmMsg = "Are you sure you wish to delete the alliance `{0}` [ID: {1}]?"; if (MessageBox.Show(string.Format(confirmMsg, a.Name, a.ID), "Delete?", MessageBoxButtons.YesNo) == DialogResult.No) { return; } _dbController.GetQuery <DeleteAllianceQuery>().Execute(a.ID); pgAlliance.SelectedObject = null; MessageBox.Show(string.Format("Alliance `{0}` [ID: {1}] successfully deleted!", a.Name, a.ID)); }
/// <summary> /// When overridden in the derived class, gets all of the guilds loaded from the database. /// </summary> /// <returns>All of the guilds loaded from the database.</returns> protected override IEnumerable <Guild> LoadGuilds() { var guildValues = _dbController.GetQuery <SelectGuildsQuery>().Execute(); return(guildValues.Select(x => new Guild(this, x))); }
static MapSpawnValuesID GetFreeID(IDbController dbController) { return dbController.GetQuery<MapSpawnValuesIDCreator>().GetNext(); }
/// <summary> /// Loads a MapSpawnValues from the database. /// </summary> /// <param name="dbController">DbController used to communicate with the database.</param> /// <param name="id">ID of the MapSpawnValues to load.</param> /// <returns>The MapSpawnValues with ID <paramref name="id"/>.</returns> public static MapSpawnValues Load(IDbController dbController, MapSpawnValuesID id) { var values = dbController.GetQuery<SelectMapSpawnQuery>().Execute(id); Debug.Assert(id == values.ID); return new MapSpawnValues(dbController, values); }
/// <summary> /// Loads all of the MapSpawnValues for the given <paramref name="mapID"/> from the database. /// </summary> /// <param name="dbController">DbController used to communicate with the database.</param> /// <param name="mapID">Index of the map to load the MapSpawnValues for.</param> /// <returns>An IEnumerable of all of the MapSpawnValues for the given <paramref name="mapID"/>.</returns> public static IEnumerable<MapSpawnValues> Load(IDbController dbController, MapID mapID) { var ret = new List<MapSpawnValues>(); var queryValues = dbController.GetQuery<SelectMapSpawnsOnMapQuery>().Execute(mapID); foreach (var v in queryValues) { Debug.Assert(v.MapID == mapID); ret.Add(new MapSpawnValues(dbController, v)); } return ret; }
/// <summary> /// Initializes a new instance of the <see cref="QuestManager"/> class. /// </summary> /// <param name="dbController">The <see cref="IDbController"/>.</param> QuestManager(IDbController dbController) { _dbController = dbController; LoadQuests(dbController.GetQuery <SelectQuestIDsQuery>().Execute()); }
/// <summary> /// Gets the <see cref="IMapTable"/>s for all of the maps. /// </summary> /// <param name="dbController">The <see cref="IDbController"/> to use. If null, will attempt to find /// the <see cref="IDbController"/> instance automatically.</param> /// <returns> /// The <see cref="IMapTable"/>s for all of the maps. /// </returns> /// <exception cref="ArgumentException"><paramref name="dbController"/> is null and no valid <see cref="IDbController"/> /// instance could be found automatically.</exception> public static IEnumerable<IMapTable> FindAllMaps(IDbController dbController = null) { if (dbController == null) dbController = DbControllerBase.GetInstance(); if (dbController == null) throw new ArgumentException("Param was null and could not find a valid IDbController instance.", "dbController"); // Get the IDs var ids = dbController.GetQuery<SelectMapIDsQuery>().Execute(); // Get all of the maps one at a time using the IDs var ret = new List<IMapTable>(); var templateQuery = dbController.GetQuery<SelectMapQuery>(); foreach (var id in ids) { var template = templateQuery.Execute(id); ret.Add(template); } // Return the results sorted return ret.OrderBy(x => x.ID).ToImmutable(); }