/// <summary> /// Process for changing an emblem /// </summary> /// <param name="player"></param> /// <param name="oldemblem"></param> /// <param name="newemblem"></param> public static void ChangeEmblem(GamePlayer player, int oldemblem, int newemblem) { player.Guild.Emblem = newemblem; if (oldemblem != 0) { player.RemoveMoney(COST_RE_EMBLEM, null); InventoryLogging.LogInventoryAction(player, "(GUILD;" + player.GuildName + ")", eInventoryActionType.Other, COST_RE_EMBLEM); var objs = DOLDB <InventoryItem> .SelectObjects(DB.Column(nameof(InventoryItem.Emblem)).IsEqualTo(oldemblem)); foreach (InventoryItem item in objs) { item.Emblem = newemblem; } GameServer.Database.SaveObject(objs); // change guild house emblem if (player.Guild.GuildOwnsHouse && player.Guild.GuildHouseNumber > 0) { Housing.House guildHouse = Housing.HouseMgr.GetHouse(player.Guild.GuildHouseNumber); if (guildHouse != null) { guildHouse.Emblem = player.Guild.Emblem; guildHouse.SaveIntoDatabase(); guildHouse.SendUpdate(); } } } }
protected void RefreshLootTemplate(string templateName) { lock (m_lootTemplates) { if (m_lootTemplates.ContainsKey(templateName.ToLower())) { m_lootTemplates.Remove(templateName.ToLower()); } } var lootTemplates = DOLDB <LootTemplate> .SelectObjects(DB.Column("TemplateName").IsEqualTo(templateName)); if (lootTemplates != null) { lock (m_lootTemplates) { if (m_lootTemplates.ContainsKey(templateName.ToLower())) { m_lootTemplates.Remove(templateName.ToLower()); } Dictionary <string, LootTemplate> lootList = new Dictionary <string, LootTemplate>(); foreach (LootTemplate lt in lootTemplates) { if (lootList.ContainsKey(lt.ItemTemplateID.ToLower()) == false) { lootList.Add(lt.ItemTemplateID.ToLower(), lt); } } m_lootTemplates.Add(templateName.ToLower(), lootList); } } }
/// <summary> /// Refresh the OTDs for this mob /// </summary> /// <param name="mob"></param> public override void Refresh(GameNPC mob) { if (mob == null) { return; } IList <LootOTD> otds = DOLDB <LootOTD> .SelectObjects(DB.Column(nameof(LootOTD.MobName)).IsEqualTo(mob.Name)); lock (m_mobOTDList) { if (m_mobOTDList.ContainsKey(mob.Name.ToLower())) { m_mobOTDList.Remove(mob.Name.ToLower()); } } if (otds != null) { lock (m_mobOTDList) { List <LootOTD> newList = new List <LootOTD>(); foreach (LootOTD otd in otds) { newList.Add(otd); } m_mobOTDList.Add(mob.Name.ToLower(), newList); } } }
/// <summary> /// Check all items that belong to this ownerid and fix the OwnerLot if needed /// </summary> public virtual bool CheckInventory() { House house = HouseMgr.GetHouse(CurrentRegionID, HouseNumber); if (house == null) { return(false); } bool isFixed = false; var items = DOLDB <InventoryItem> .SelectObjects(DB.Column(nameof(InventoryItem.OwnerID)).IsEqualTo(house.OwnerID).And(DB.Column(nameof(InventoryItem.SlotPosition)).IsGreaterOrEqualTo(FirstDBSlot)).And(DB.Column(nameof(InventoryItem.SlotPosition)).IsLessOrEqualTo(LastDBSlot)).And(DB.Column(nameof(InventoryItem.OwnerLot)).IsEqualTo(0))); foreach (InventoryItem item in items) { item.OwnerLot = (ushort)HouseNumber; MarketCache.AddItem(item); if (ServerProperties.Properties.MARKET_ENABLE_LOG) { log.DebugFormat("CM: Fixed OwnerLot for item '{0}' on CM for lot {1}", item.Name, HouseNumber); } isFixed = true; } GameServer.Database.SaveObject(items); return(isFixed); }
public static void DisplayNews(GameClient client) { // N,chanel(0/1/2),index(0-4),string time,\"news\" for (int type = 0; type <= 2; type++) { int index = 0; string realm = ""; //we can see all captures IList <DBNews> newsList; if (type > 0) { newsList = DOLDB <DBNews> .SelectObjects(DB.Column(nameof(DBNews.Type)).IsEqualTo(type).And(DB.Column(nameof(DBNews.Realm)).IsEqualTo(0).Or(DB.Column(nameof(DBNews.Realm)).IsEqualTo(realm)))); } else { newsList = DOLDB <DBNews> .SelectObjects(DB.Column(nameof(DBNews.Type)).IsEqualTo(type)); } newsList = newsList.OrderByDescending(it => it.CreationDate).Take(5).ToArray(); int n = newsList.Count; while (n > 0) { n--; DBNews news = newsList[n]; client.Out.SendMessage(string.Format("N,{0},{1},{2},\"{3}\"", news.Type, index++, RetElapsedTime(news.CreationDate), news.Text), eChatType.CT_SocialInterface, eChatLoc.CL_SystemWindow); } } }
/// <summary> /// Attach this vault to a hookpoint in a house. /// </summary> /// <param name="house"></param> /// <param name="hookpointID"></param> /// <returns></returns> public bool Attach(House house, uint hookpointID, ushort heading) { if (house == null) { return(false); } // register vault in the DB. var hookedItem = new DBHouseHookpointItem { HouseNumber = house.HouseNumber, HookpointID = hookpointID, Heading = (ushort)(heading % 4096), ItemTemplateID = _templateID, Index = (byte)Index }; var hpitem = DOLDB <DBHouseHookpointItem> .SelectObjects(DB.Column("HouseNumber").IsEqualTo(house.HouseNumber).And(DB.Column("HookpointID").IsEqualTo(hookpointID))); // if there isn't anything already on this hookpoint then add it to the DB if (hpitem.Count == 0) { GameServer.Database.AddObject(hookedItem); } // now add the vault to the house. return(Attach(house, hookedItem)); }
/// <summary> /// Load or reload all items into the market cache /// </summary> public static bool Initialize() { log.Info("Building Market Cache ...."); try { m_itemCache = new Dictionary <string, InventoryItem>(); var filterBySlot = DB.Column("SlotPosition").IsGreaterOrEqualTo((int)eInventorySlot.Consignment_First).And(DB.Column("SlotPosition").IsLessOrEqualTo((int)eInventorySlot.Consignment_Last)); var list = DOLDB <InventoryItem> .SelectObjects(filterBySlot.And(DB.Column("OwnerLot").IsGreatherThan(0))); foreach (InventoryItem item in list) { GameInventoryItem playerItem = GameInventoryItem.Create(item); m_itemCache.Add(item.ObjectId, playerItem); } log.Info("Market Cache initialized with " + m_itemCache.Count + " items."); } catch { return(false); } return(true); }
/// <summary> /// Use the NPC Guild Name to find all the valid destinations for this teleporter /// </summary> protected void LoadDestinations() { if (m_destinations.Count > 0 || GuildName == null || GuildName.Length == 0) { return; } m_destinations.AddRange(DOLDB <Teleport> .SelectObjects(DB.Column("Type").IsEqualTo(GuildName))); }
static void PreloadItemTemplates() { IList <ItemTemplate> itemTemplates = null; for (int i = 0; i <= LEVEL_SIZE; i++) { try { var filterLevel = DB.Column("Level").IsGreaterOrEqualTo(i * LEVEL_RANGE).And(DB.Column("Level").IsLessOrEqualTo((i + 1) * LEVEL_RANGE)); var filterByFlags = DB.Column("IsPickable").IsEqualTo(1).And(DB.Column("IsDropable").IsEqualTo(1)).And(DB.Column("CanDropAsLoot").IsEqualTo(1)); var filterBySlot = DB.Column("Item_Type").IsGreaterOrEqualTo((int)eInventorySlot.MinEquipable).And(DB.Column("Item_Type").IsLessOrEqualTo((int)eInventorySlot.MaxEquipable)); itemTemplates = DOLDB <ItemTemplate> .SelectObjects(filterLevel.And(filterByFlags).And(filterBySlot)); } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("LootGeneratorRandom: ItemTemplates could not be loaded", e); } return; } List <ItemTemplate> templatesAlb = new List <ItemTemplate>(); List <ItemTemplate> templatesHib = new List <ItemTemplate>(); List <ItemTemplate> templatesMid = new List <ItemTemplate>(); foreach (ItemTemplate itemTemplate in itemTemplates) { switch (itemTemplate.Realm) { case (int)eRealm.Albion: templatesAlb.Add(itemTemplate); break; case (int)eRealm.Hibernia: templatesHib.Add(itemTemplate); break; case (int)eRealm.Midgard: templatesMid.Add(itemTemplate); break; default: templatesAlb.Add(itemTemplate); templatesHib.Add(itemTemplate); templatesMid.Add(itemTemplate); break; } } m_itemTemplatesAlb[i] = templatesAlb.ToArray(); m_itemTemplatesHib[i] = templatesHib.ToArray(); m_itemTemplatesMid[i] = templatesMid.ToArray(); } // for }
/// <summary> /// Get the list of all items in the specified page /// </summary> public virtual IDictionary GetItemsInPage(int page) { try { HybridDictionary itemsInPage = new HybridDictionary(MAX_ITEM_IN_TRADEWINDOWS); if (m_itemsListID != null && m_itemsListID.Length > 0) { var itemList = DOLDB <MerchantItem> .SelectObjects(DB.Column("ItemListID").IsEqualTo(m_itemsListID).And(DB.Column("PageNumber").IsEqualTo(page))); foreach (MerchantItem merchantitem in itemList) { ItemTemplate item = GameServer.Database.FindObjectByKey <ItemTemplate>(merchantitem.ItemTemplateID); if (item != null) { ItemTemplate slotItem = (ItemTemplate)itemsInPage[merchantitem.SlotPosition]; if (slotItem == null) { itemsInPage.Add(merchantitem.SlotPosition, item); } else { log.ErrorFormat("two merchant items on same page/slot: listID={0} page={1} slot={2}", m_itemsListID, page, merchantitem.SlotPosition); } } else { log.ErrorFormat("Item template with ID = '{0}' not found for merchant item list '{1}'", merchantitem.ItemTemplateID, ItemsListID); } } } lock (m_usedItemsTemplates.SyncRoot) { foreach (DictionaryEntry de in m_usedItemsTemplates) { if ((int)de.Key >= (MAX_ITEM_IN_TRADEWINDOWS * page) && (int)de.Key < (MAX_ITEM_IN_TRADEWINDOWS * page + MAX_ITEM_IN_TRADEWINDOWS)) { itemsInPage[(int)de.Key % MAX_ITEM_IN_TRADEWINDOWS] = (ItemTemplate)de.Value; } } } return(itemsInPage); } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("Loading merchant items list (" + m_itemsListID + ") page (" + page + "): ", e); } return(new HybridDictionary()); } }
/// <summary> /// Deletes a guild /// </summary> public static bool DeleteGuild(string guildName) { try { Guild removeGuild = GetGuildByName(guildName); // Does guild exist, if not return false. if (removeGuild == null) { return(false); } var guilds = DOLDB <DBGuild> .SelectObjects(DB.Column(nameof(DBGuild.GuildID)).IsEqualTo(removeGuild.GuildID)); foreach (var guild in guilds) { foreach (var cha in DOLDB <DOLCharacters> .SelectObjects(DB.Column(nameof(DOLCharacters.GuildID)).IsEqualTo(guild.GuildID))) { cha.GuildID = ""; } } GameServer.Database.DeleteObject(guilds); //[StephenxPimentel] We need to delete the guild specific ranks aswell! var ranks = DOLDB <DBRank> .SelectObjects(DB.Column(nameof(DBRank.GuildID)).IsEqualTo(removeGuild.GuildID)); GameServer.Database.DeleteObject(ranks); lock (removeGuild.GetListOfOnlineMembers()) { foreach (GamePlayer ply in removeGuild.GetListOfOnlineMembers()) { ply.Guild = null; ply.GuildID = ""; ply.GuildName = ""; ply.GuildRank = null; } } RemoveGuild(removeGuild); return(true); } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("DeleteGuild", e); } return(false); } }
private static Recipe LoadFromDB(ushort recipeDatabaseID) { var dbRecipe = GameServer.Database.FindObjectByKey <DBCraftedItem>(recipeDatabaseID.ToString()); if (dbRecipe == null) { throw new ArgumentException("No DBCraftedItem with ID " + recipeDatabaseID + "exists."); } ItemTemplate product = GameServer.Database.FindObjectByKey <ItemTemplate>(dbRecipe.Id_nb); if (product == null) { throw new ArgumentException("Product ItemTemplate " + dbRecipe.Id_nb + " for Recipe with ID " + dbRecipe.CraftedItemID + " does not exist."); } var rawMaterials = DOLDB <DBCraftedXItem> .SelectObjects(DB.Column("CraftedItemId_nb").IsEqualTo(dbRecipe.Id_nb)); if (rawMaterials.Count == 0) { throw new ArgumentException("Recipe with ID " + dbRecipe.CraftedItemID + " has no ingredients."); } bool isRecipeValid = true; var errorText = ""; var ingredients = new List <Ingredient>(); foreach (DBCraftedXItem material in rawMaterials) { ItemTemplate template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb); if (template == null) { errorText += "Cannot find raw material ItemTemplate: " + material.IngredientId_nb + ") needed for recipe: " + dbRecipe.CraftedItemID + "\n"; isRecipeValid = false; } ingredients.Add(new Ingredient(material.Count, template)); } if (!isRecipeValid) { throw new ArgumentException(errorText); } var recipe = new Recipe(product, ingredients, (eCraftingSkill)dbRecipe.CraftingSkillType, dbRecipe.CraftingLevel, dbRecipe.MakeTemplated); return(recipe); }
/// <summary> /// Reload the loot templates for this mob /// </summary> /// <param name="mob"></param> public override void Refresh(GameNPC mob) { if (mob == null) { return; } bool isDefaultLootTemplateRefreshed = false; // First see if there are any MobXLootTemplates associated with this mob IList <MobDropTemplate> mxlts = DOLDB <MobDropTemplate> .SelectObjects(DB.Column("MobName").IsEqualTo(mob.Name)); if (mxlts != null) { lock (m_mobXLootTemplates) { foreach (MobDropTemplate mxlt in mxlts) { m_mobXLootTemplates.Remove(mxlt.MobName.ToLower()); } foreach (MobDropTemplate mxlt in mxlts) { List <MobDropTemplate> mobxLootTemplates; if (!m_mobXLootTemplates.TryGetValue(mxlt.MobName.ToLower(), out mobxLootTemplates)) { mobxLootTemplates = new List <MobDropTemplate>(); m_mobXLootTemplates[mxlt.MobName.ToLower()] = mobxLootTemplates; } mobxLootTemplates.Add(mxlt); RefreshLootTemplate(mxlt.LootTemplateName); if (mxlt.LootTemplateName.ToLower() == mob.Name.ToLower()) { isDefaultLootTemplateRefreshed = true; } } } } // now force a refresh of the mobs default loot template if (isDefaultLootTemplateRefreshed == false) { RefreshLootTemplate(mob.Name); } }
/// <summary> /// Gets a copy of all intems in trade window /// </summary> /// <returns>A list where key is the slot position and value is the ItemTemplate</returns> public virtual IDictionary GetAllItems() { try { Hashtable allItems = new Hashtable(); if (m_itemsListID != null && m_itemsListID.Length > 0) { var itemList = DOLDB <MerchantItem> .SelectObjects(DB.Column("ItemListID").IsEqualTo(m_itemsListID)); foreach (MerchantItem merchantitem in itemList) { ItemTemplate item = GameServer.Database.FindObjectByKey <ItemTemplate>(merchantitem.ItemTemplateID); if (item != null) { ItemTemplate slotItem = (ItemTemplate)allItems[merchantitem.SlotPosition]; if (slotItem == null) { allItems.Add(merchantitem.SlotPosition, item); } else { log.ErrorFormat("two merchant items on same page/slot: listID={0} page={1} slot={2}", m_itemsListID, merchantitem.PageNumber, merchantitem.SlotPosition); } } } } lock (m_usedItemsTemplates.SyncRoot) { foreach (DictionaryEntry de in m_usedItemsTemplates) { allItems[(int)de.Key] = (ItemTemplate)de.Value; } } return(allItems); } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("Loading merchant items list (" + m_itemsListID + "):", e); } return(new HybridDictionary()); } }
/// <summary> /// Loads the inventory template from the Database /// </summary> /// <returns>success</returns> public override bool LoadFromDatabase(string templateID) { if (Util.IsEmpty(templateID, true)) { return(false); } lock (m_items) { IList <NPCEquipment> npcEquip; if (m_npcEquipmentCache.ContainsKey(templateID)) { npcEquip = m_npcEquipmentCache[templateID]; } else { npcEquip = DOLDB <NPCEquipment> .SelectObjects(DB.Column(nameof(NPCEquipment.TemplateID)).IsEqualTo(templateID)); } if (npcEquip == null || npcEquip.Count == 0) { if (log.IsWarnEnabled) { log.Warn(string.Format("Failed loading NPC inventory template: {0}", templateID)); } return(false); } foreach (NPCEquipment npcItem in npcEquip) { if (!AddNPCEquipment((eInventorySlot)npcItem.Slot, npcItem.Model, npcItem.Color, npcItem.Effect, npcItem.Extension, npcItem.Emblem)) { if (log.IsWarnEnabled) { log.Warn("Error adding NPC equipment for templateID " + templateID + ", ModelID=" + npcItem.Model + ", slot=" + npcItem.Slot); } } } } return(true); }
/// <summary> /// Loads elements relating to the given instance keyname from the database and populates the instance. /// </summary> /// <param name="instanceName"></param> public virtual void LoadFromDatabase(string instanceName) { var objects = DOLDB <DBInstanceXElement> .SelectObjects(DB.Column(nameof(DBInstanceXElement.InstanceID)).IsEqualTo(instanceName)); if (objects.Count == 0) { return; } int count = 0; //Now we have a list of DBElements, lets create the various entries //associated with them and populate the instance. foreach (DBInstanceXElement entry in objects) { if (entry == null) { continue; //an odd error, but experience knows best. } GameObject obj = null; string theType = "DOL.GS.GameNPC"; //Switch the classtype to see what we are making. switch (entry.ClassType) { case "entrance": { //create the entrance, then move to the next. m_entranceLocation = new GameLocation(instanceName + "entranceRegion" + ID, ID, entry.X, entry.Y, entry.Z, entry.Heading); //move to the next entry, nothing more to do here... continue; } case "region": continue; //This is used to save the regionID as NPCTemplate. case "DOL.GS.GameNPC": break; default: theType = entry.ClassType; break; } //Now we have the classtype to create, create it thus! //This is required to ensure we check scripts for the space aswell, such as quests! foreach (Assembly asm in ScriptMgr.GameServerScripts) { obj = (GameObject)(asm.CreateInstance(theType, false)); if (obj != null) { break; } } if (obj == null) { continue; } //We now have an object that isnt null. Lets place it at the location, in this region. obj.Position = new Vector3(entry.X, entry.Y, entry.Z); obj.Heading = entry.Heading; obj.CurrentRegionID = ID; //If its an npc, load from the npc template about now. //By default, we ignore npctemplate if its set to 0. if ((GameNPC)obj != null && !Util.IsEmpty(entry.NPCTemplate, true)) { var listTemplate = Util.SplitCSV(entry.NPCTemplate, true); int template = 0; if (int.TryParse(listTemplate[Util.Random(listTemplate.Count - 1)], out template) && template > 0) { INpcTemplate npcTemplate = NpcTemplateMgr.GetTemplate(template); //we only want to load the template if one actually exists, or there could be trouble! if (npcTemplate != null) { ((GameNPC)obj).LoadTemplate(npcTemplate); } } } //Finally, add it to the world! obj.AddToWorld(); //Keep track of numbers. count++; } log.Info("Successfully loaded a db entry to " + Description + " - Region ID " + ID + ". Loaded Entities: " + count); }
/// <summary> /// Load all guilds and alliances from the database /// </summary> public static bool LoadAllGuilds() { lock (m_guilds.SyncRoot) { m_guilds.Clear(); //clear guild list before loading! } m_lastID = 0; //load guilds var guildObjs = GameServer.Database.SelectAllObjects <DBGuild>(); foreach (var obj in guildObjs) { var myguild = new Guild(obj); if (obj.Ranks == null || obj.Ranks.Length < 10 || obj.Ranks[0] == null || obj.Ranks[1] == null || obj.Ranks[2] == null || obj.Ranks[3] == null || obj.Ranks[4] == null || obj.Ranks[5] == null || obj.Ranks[6] == null || obj.Ranks[7] == null || obj.Ranks[8] == null || obj.Ranks[9] == null) { log.ErrorFormat("GuildMgr: Ranks missing for {0}, creating new ones!", myguild.Name); RepairRanks(myguild); // now reload the guild to fix the relations myguild = new Guild(DOLDB <DBGuild> .SelectObjects(DB.Column(nameof(DBGuild.GuildID)).IsEqualTo(obj.GuildID)).FirstOrDefault()); } AddGuild(myguild); var guildCharacters = DOLDB <DOLCharacters> .SelectObjects(DB.Column(nameof(DOLCharacters.GuildID)).IsEqualTo(myguild.GuildID)); var tempList = new Dictionary <string, GuildMemberDisplay>(guildCharacters.Count); foreach (DOLCharacters ch in guildCharacters) { var member = new GuildMemberDisplay(ch.ObjectId, ch.Name, ch.Level.ToString(), ch.Class.ToString(), ch.GuildRank.ToString(), "0", ch.LastPlayed.ToShortDateString(), ch.GuildNote); tempList.Add(ch.ObjectId, member); } m_guildXAllMembers.Add(myguild.GuildID, tempList); } //load alliances var allianceObjs = GameServer.Database.SelectAllObjects <DBAlliance>(); foreach (DBAlliance dball in allianceObjs) { var myalliance = new Alliance(); myalliance.LoadFromDatabase(dball); if (dball != null && dball.DBguilds != null) { foreach (DBGuild mydbgui in dball.DBguilds) { var gui = GetGuildByName(mydbgui.GuildName); myalliance.Guilds.Add(gui); gui.alliance = myalliance; } } } return(true); }
/// <summary> /// Save the inventory template to Database /// </summary> /// <returns>success</returns> public override bool SaveIntoDatabase(string templateID) { lock (m_items) { try { if (templateID == null) { throw new ArgumentNullException("templateID"); } var npcEquipment = DOLDB <NPCEquipment> .SelectObjects(DB.Column(nameof(NPCEquipment.TemplateID)).IsEqualTo(templateID)); // delete removed item templates foreach (NPCEquipment npcItem in npcEquipment) { if (!m_items.ContainsKey((eInventorySlot)npcItem.Slot)) { GameServer.Database.DeleteObject(npcItem); } } // save changed item templates foreach (InventoryItem item in m_items.Values) { bool foundInDB = false; foreach (NPCEquipment npcItem in npcEquipment) { if (item.SlotPosition != npcItem.Slot) { continue; } if (item.Model != npcItem.Model || item.Color != npcItem.Color || item.Effect != npcItem.Effect || item.Emblem != npcItem.Emblem) { npcItem.Model = item.Model; npcItem.Color = item.Color; npcItem.Effect = item.Effect; npcItem.Extension = item.Extension; npcItem.Emblem = item.Emblem; GameServer.Database.SaveObject(npcItem); } foundInDB = true; break; } if (!foundInDB) { NPCEquipment npcItem = new NPCEquipment(); npcItem.Slot = item.SlotPosition; npcItem.Model = item.Model; npcItem.Color = item.Color; npcItem.Effect = item.Effect; npcItem.TemplateID = templateID; npcItem.Extension = item.Extension; npcItem.Emblem = item.Emblem; GameServer.Database.AddObject(npcItem); } } return(true); } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("Error saving NPC inventory template, templateID=" + templateID, e); } return(false); } } }
/// <summary> /// List of items in the vault. /// </summary> public IList <InventoryItem> DBItems(GamePlayer player = null) { var filterBySlot = DB.Column(nameof(InventoryItem.SlotPosition)).IsGreaterOrEqualTo(FirstDBSlot).And(DB.Column(nameof(InventoryItem.SlotPosition)).IsLessOrEqualTo(LastDBSlot)); return(DOLDB <InventoryItem> .SelectObjects(DB.Column(nameof(InventoryItem.OwnerID)).IsEqualTo(GetOwner(player)).And(filterBySlot))); }
public static void CreateServerStats(GameClient client) { GamePlayer player = client.Player; if (m_lastUpdatedTime == 0) { m_lastUpdatedTime = player.CurrentRegion.Time; } m_timeToChange = (m_lastUpdatedTime + TIME_BETWEEN_UPDATES); if (player.CurrentRegion.Time < m_timeToChange && m_hasBeenRun) { return; } #region /stats top var chars = DOLDB <DOLCharacters> .SelectObjects(DB.Column(nameof(DOLCharacters.RealmPoints)).IsGreatherThan(213881)).OrderByDescending(dc => dc.RealmPoints).Take(100).ToArray(); // assuming we can get at least 20 players if (toplist.Count > 0) { toplist.Clear(); } int count = 1; foreach (DOLCharacters chr in chars) { if (chr.IgnoreStatistics == false) { var account = GameServer.Database.FindObjectByKey <Account>(chr.AccountName); if (account != null && account.PrivLevel == 1) { toplist.Add("\n" + count.ToString() + " - [ " + chr.Name + " ] with " + String.Format("{0:0,0}", chr.RealmPoints) + " RP - [ " + (((chr.RealmLevel + 10) / 10) + "L" + ((chr.RealmLevel + 10) % 10)) + " ]"); if (++count > 20) { break; } } } } if (count == 1) { toplist.Add("None found!"); } #endregion /stats top List <StatToCount> allstatsrp = new List <StatToCount>(); List <StatToCount> allstatslrp = new List <StatToCount>(); List <StatToCount> allstatskills = new List <StatToCount>(); List <StatToCount> allstatsdeath = new List <StatToCount>(); List <StatToCount> allstatsirs = new List <StatToCount>(); List <StatToCount> allstatsheal = new List <StatToCount>(); List <StatToCount> allstatsres = new List <StatToCount>(); List <StatToCount> allstatsrpearnedfromheal = new List <StatToCount>(); foreach (GameClient c in WorldMgr.GetAllPlayingClients()) { if (c == null || c.Account.PrivLevel != 1 || c.Player.IgnoreStatistics) { continue; } PlayerStatistics stats = c.Player.Statistics as PlayerStatistics; if (stats != null) { if (c.Player.RealmLevel > 31) { allstatsrp.Add(new StatToCount(c.Player.Name, stats.TotalRP)); TimeSpan onlineTime = DateTime.Now.Subtract(stats.LoginTime); allstatslrp.Add(new StatToCount(c.Player.Name, (uint)Math.Round(stats.RPsPerHour(stats.TotalRP, onlineTime)))); uint deaths = stats.Deaths; if (deaths < 1) { deaths = 1; } allstatsirs.Add(new StatToCount(c.Player.Name, (uint)Math.Round((double)stats.TotalRP / (double)deaths))); } allstatskills.Add(new StatToCount(c.Player.Name, stats.KillsThatHaveEarnedRPs)); allstatsdeath.Add(new StatToCount(c.Player.Name, stats.Deathblows)); allstatsheal.Add(new StatToCount(c.Player.Name, stats.HitPointsHealed)); allstatsres.Add(new StatToCount(c.Player.Name, stats.RessurectionsPerformed)); allstatsrpearnedfromheal.Add(new StatToCount(c.Player.Name, stats.RPEarnedFromHitPointsHealed)); } } allstatsrp.Sort((ctc1, ctc2) => ctc1.count.CompareTo(ctc2.count)); allstatsrp.Reverse(); allstatslrp.Sort((ctc1, ctc2) => ctc1.count.CompareTo(ctc2.count)); allstatslrp.Reverse(); allstatskills.Sort((ctc1, ctc2) => ctc1.count.CompareTo(ctc2.count)); allstatskills.Reverse(); allstatsdeath.Sort((ctc1, ctc2) => ctc1.count.CompareTo(ctc2.count)); allstatsdeath.Reverse(); allstatsirs.Sort((ctc1, ctc2) => ctc1.count.CompareTo(ctc2.count)); allstatsirs.Reverse(); allstatsheal.Sort((ctc1, ctc2) => ctc1.count.CompareTo(ctc2.count)); allstatsheal.Reverse(); allstatsres.Sort((ctc1, ctc2) => ctc1.count.CompareTo(ctc2.count)); allstatsres.Reverse(); allstatsrpearnedfromheal.Sort((ctc1, ctc2) => ctc1.count.CompareTo(ctc2.count)); allstatsrpearnedfromheal.Reverse(); statsrp = ""; statslrp = ""; statskills = ""; statsdeath = ""; statsirs = ""; statsheal = ""; statsres = ""; for (int c = 0; c < allstatsrp.Count; c++) { if (c > 19 || allstatsrp[c].count < 1) { break; } statsrp += (c + 1) + ". " + allstatsrp[c].name + " with " + allstatsrp[c].count.ToString() + " RP\n"; } for (int c = 0; c < allstatslrp.Count; c++) { if (c > 19 || allstatslrp[c].count < 1) { break; } statslrp += (c + 1) + ". " + allstatslrp[c].name + " with " + allstatslrp[c].count.ToString() + " RP/hour\n"; } for (int c = 0; c < allstatskills.Count; c++) { if (c > 19 || allstatskills[c].count < 1) { break; } statskills += (c + 1) + ". " + allstatskills[c].name + " with " + allstatskills[c].count.ToString() + " kills\n"; } for (int c = 0; c < allstatsdeath.Count; c++) { if (c > 19 || allstatsdeath[c].count < 1) { break; } statsdeath += (c + 1) + ". " + allstatsdeath[c].name + " with " + allstatsdeath[c].count.ToString() + " deathblows\n"; } for (int c = 0; c < allstatsirs.Count; c++) { if (c > 19 || allstatsirs[c].count < 1) { break; } statsirs += (c + 1) + ". " + allstatsirs[c].name + " with " + allstatsirs[c].count.ToString() + " RP/death\n"; } for (int c = 0; c < allstatsheal.Count; c++) { if (c > 19 || allstatsheal[c].count < 1) { break; } statsheal += (c + 1) + ". " + allstatsheal[c].name + " with " + allstatsheal[c].count.ToString() + " HP and " + allstatsrpearnedfromheal[c].count.ToString() + " RP gained from heal\n"; } for (int c = 0; c < allstatsres.Count; c++) { if (c > 19 || allstatsres[c].count < 1) { break; } statsres += (c + 1) + ". " + allstatsres[c].name + " with " + allstatsres[c].count.ToString() + " res\n"; } m_lastUpdatedTime = player.CurrentRegion.Time; m_hasBeenRun = true; }
protected static bool PreloadLootOTDs() { lock (m_mobOTDList) { m_mobOTDList.Clear(); IList <LootOTD> lootOTDs; try { lootOTDs = GameServer.Database.SelectAllObjects <LootOTD>(); } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("LootGeneratorOneTimeDrop: Drops could not be loaded:", e); } return(false); } if (lootOTDs != null && lootOTDs.Count > 0) { int count = 0; foreach (LootOTD l in lootOTDs) { IList <Mob> mobs = DOLDB <Mob> .SelectObjects(DB.Column(nameof(Mob.Name)).IsEqualTo(l.MobName)); if (mobs == null || mobs.Count == 0) { log.ErrorFormat("Can't find MobName {0} for OTD {1}", l.MobName, l.ItemTemplateID); continue; } ItemTemplate item = GameServer.Database.FindObjectByKey <ItemTemplate>(l.ItemTemplateID); if (item == null) { log.ErrorFormat("Can't find ItemTemplate {0} for OTD MobName {1}", l.ItemTemplateID, l.MobName); continue; } if (m_mobOTDList.ContainsKey(l.MobName.ToLower())) { List <LootOTD> drops = m_mobOTDList[l.MobName.ToLower()]; if (drops.Contains(l) == false) { drops.Add(l); count++; } else { log.ErrorFormat("Same OTD ItemTemplate {0} specified multiple times for MobName {1}", l.ItemTemplateID, l.MobName); } } else { List <LootOTD> drops = new List <LootOTD>(); drops.Add(l); m_mobOTDList.Add(l.MobName.ToLower(), drops); count++; } } log.InfoFormat("One Time Drop generator pre-loaded {0} drops.", count); } } return(true); }
/// <summary> /// Load from Database override to clone objects from original Region. /// Loads Objects, Mobs, Areas from Database using "SkinID" /// </summary> public override void LoadFromDatabase(Mob[] mobObjs, ref long mobCount, ref long merchantCount, ref long itemCount, ref long bindCount) { if (!LoadObjects) { return; } Assembly gasm = Assembly.GetAssembly(typeof(GameServer)); var staticObjs = DOLDB <WorldObject> .SelectObjects(DB.Column(nameof(WorldObject.Region)).IsEqualTo(Skin)); var areaObjs = DOLDB <DBArea> .SelectObjects(DB.Column(nameof(DBArea.Region)).IsEqualTo(Skin)); int count = mobObjs.Length + staticObjs.Count; if (count > 0) { PreAllocateRegionSpace(count + 100); } int myItemCount = staticObjs.Count; int myMobCount = 0; int myMerchantCount = 0; string allErrors = string.Empty; if (mobObjs.Length > 0) { foreach (Mob mob in mobObjs) { GameNPC myMob = null; string error = string.Empty; // Default Classtype string classtype = ServerProperties.Properties.GAMENPC_DEFAULT_CLASSTYPE; // load template if any INpcTemplate template = null; if (mob.NPCTemplateID != -1) { template = NpcTemplateMgr.GetTemplate(mob.NPCTemplateID); } if (mob.Guild.Length > 0 && mob.Realm >= 0 && mob.Realm <= (int)eRealm._Last) { Type type = ScriptMgr.FindNPCGuildScriptClass(mob.Guild, (eRealm)mob.Realm); if (type != null) { try { myMob = (GameNPC)type.Assembly.CreateInstance(type.FullName); } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("LoadFromDatabase", e); } } } } if (myMob == null) { if (template != null && template.ClassType != null && template.ClassType.Length > 0 && template.ClassType != Mob.DEFAULT_NPC_CLASSTYPE && template.ReplaceMobValues) { classtype = template.ClassType; } else if (mob.ClassType != null && mob.ClassType.Length > 0 && mob.ClassType != Mob.DEFAULT_NPC_CLASSTYPE) { classtype = mob.ClassType; } try { myMob = (GameNPC)gasm.CreateInstance(classtype, false); } catch { error = classtype; } if (myMob == null) { foreach (Assembly asm in ScriptMgr.Scripts) { try { myMob = (GameNPC)asm.CreateInstance(classtype, false); error = string.Empty; } catch { error = classtype; } if (myMob != null) { break; } } if (myMob == null) { myMob = new GameNPC(); error = classtype; } } } if (!allErrors.Contains(error)) { allErrors += " " + error + ","; } if (myMob != null) { try { Mob clone = (Mob)mob.Clone(); clone.AllowAdd = false; clone.AllowDelete = false; clone.Region = this.ID; myMob.LoadFromDatabase(clone); if (myMob is GameMerchant) { myMerchantCount++; } else { myMobCount++; } } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("Failed: " + myMob.GetType().FullName + ":LoadFromDatabase(" + mob.GetType().FullName + ");", e); } throw; } myMob.AddToWorld(); } } } if (staticObjs.Count > 0) { foreach (WorldObject item in staticObjs) { WorldObject itemclone = (WorldObject)item.Clone(); itemclone.AllowAdd = false; itemclone.AllowDelete = false; itemclone.Region = this.ID; GameStaticItem myItem; if (!string.IsNullOrEmpty(itemclone.ClassType)) { myItem = gasm.CreateInstance(itemclone.ClassType, false) as GameStaticItem; if (myItem == null) { foreach (Assembly asm in ScriptMgr.Scripts) { try { myItem = (GameStaticItem)asm.CreateInstance(itemclone.ClassType, false); } catch { } if (myItem != null) { break; } } if (myItem == null) { myItem = new GameStaticItem(); } } } else { myItem = new GameStaticItem(); } myItem.AddToWorld(); } } int areaCnt = 0; // Add missing area foreach (DBArea area in areaObjs) { // Don't bind in instance. if (area.ClassType.Equals("DOL.GS.Area+BindArea")) { continue; } // clone DB object. DBArea newDBArea = ((DBArea)area.Clone()); newDBArea.AllowAdd = false; newDBArea.Region = this.ID; // Instantiate Area with cloned DB object and add to region try { AbstractArea newArea = (AbstractArea)gasm.CreateInstance(newDBArea.ClassType, false); newArea.LoadFromDatabase(newDBArea); newArea.Sound = newDBArea.Sound; newArea.CanBroadcast = newDBArea.CanBroadcast; newArea.CheckLOS = newDBArea.CheckLOS; this.AddArea(newArea); areaCnt++; } catch { log.Warn("area type " + area.ClassType + " cannot be created, skipping"); continue; } } if (myMobCount + myItemCount + myMerchantCount > 0) { if (log.IsInfoEnabled) { log.Info(String.Format("AdventureWingInstance: {0} ({1}) loaded {2} mobs, {3} merchants, {4} items, {5}/{6} areas from DB ({7})", Description, ID, myMobCount, myMerchantCount, myItemCount, areaCnt, areaObjs.Count, TimeManager.Name)); } log.Debug("Used Memory: " + GC.GetTotalMemory(false) / 1024 / 1024 + "MB"); if (allErrors != string.Empty) { log.Error("Error loading the following NPC ClassType(s), GameNPC used instead:" + allErrors.TrimEnd(',')); } Thread.Sleep(0); // give up remaining thread time to other resources } mobCount += myMobCount; merchantCount += myMerchantCount; itemCount += myItemCount; }
/// <summary> /// Begin salvaging a siege weapon /// </summary> /// <param name="player"></param> /// <param name="siegeWeapon"></param> /// <returns></returns> public static int BeginWork(GamePlayer player, GameSiegeWeapon siegeWeapon) { if (siegeWeapon == null) { return(0); } // Galenas siegeWeapon.ReleaseControl(); siegeWeapon.RemoveFromWorld(); bool error = false; var recipe = DOLDB <DBCraftedItem> .SelectObject(DB.Column(nameof(DBCraftedItem.Id_nb)).IsEqualTo(siegeWeapon.ItemId)); if (recipe == null) { player.Out.SendMessage("Error retrieving salvage data!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.Error("Salvage Siege Error: DBCraftedItem is null for" + siegeWeapon.ItemId); return(1); } var rawMaterials = DOLDB <DBCraftedXItem> .SelectObjects(DB.Column(nameof(DBCraftedXItem.CraftedItemId_nb)).IsEqualTo(recipe.Id_nb)); if (rawMaterials == null || rawMaterials.Count == 0) { player.Out.SendMessage("No raw materials provided for this siege weapon!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.Error("Salvage Siege Error: No Raw Materials found for " + siegeWeapon.ItemId); return(1); } if (player.IsCrafting) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.IsAllowedToBeginWork.EndCurrentAction"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return(0); } InventoryItem item; ItemTemplate template; foreach (DBCraftedXItem material in rawMaterials) { template = GameServer.Database.FindObjectByKey <ItemTemplate>(material.IngredientId_nb); if (template == null) { player.Out.SendMessage("Missing raw material " + material.IngredientId_nb + "!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.Error("Salvage Siege Error: Raw Material not found " + material.IngredientId_nb); return(1); } item = GameInventoryItem.Create(template); item.Count = material.Count; if (!player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, item)) { error = true; break; } InventoryLogging.LogInventoryAction("(salvage)", player, eInventoryActionType.Craft, item.Template, item.Count); } if (error) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.NoRoom"), eChatType.CT_System, eChatLoc.CL_SystemWindow); } return(1); }