コード例 #1
0
        /// <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();
                    }
                }
            }
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
ファイル: NewsMgr.cs プロジェクト: NetDwarf/DOLSharp
        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);
                }
            }
        }
コード例 #5
0
        public override bool AddToWorld()
        {
            House house = HouseMgr.GetHouse(HouseNumber);

            if (house == null)
            {
                log.ErrorFormat("CM: Can't find house #{0}!", HouseNumber);
                return(false);
            }

            SetInventoryTemplate();

            var houseCM = DOLDB <HouseConsignmentMerchant> .SelectObject(DB.Column(nameof(HouseConsignmentMerchant.HouseNumber)).IsEqualTo(HouseNumber));

            if (houseCM != null)
            {
                TotalMoney = houseCM.Money;
            }
            else
            {
                log.ErrorFormat("CM: Can't find HouseConsignmentMerchant entry for CM on lot {0}!", HouseNumber);
                return(false);
            }

            base.AddToWorld();

            house.ConsignmentMerchant = this;
            SetEmblem();

            CheckInventory();

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Not Livelike but looks better - adds the owners guild emblem to the consignment merchants cloak
        /// </summary>
        public virtual void SetEmblem()
        {
            if (Inventory == null)
            {
                return;
            }

            House house = HouseMgr.GetHouse(HouseNumber);

            if (house == null)
            {
                return;
            }

            if (house.DatabaseItem.GuildHouse)
            {
                var guild = DOLDB <DBGuild> .SelectObject(DB.Column(nameof(DBGuild.GuildName)).IsEqualTo(house.DatabaseItem.GuildName));

                int emblem = guild.Emblem;

                InventoryItem cloak = Inventory.GetItem(eInventorySlot.Cloak);
                if (cloak != null)
                {
                    cloak.Emblem = emblem;
                    BroadcastLivingEquipmentUpdate();
                }
            }
        }
コード例 #7
0
        /// <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));
        }
コード例 #8
0
        /// <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);
                }
            }
        }
コード例 #9
0
ファイル: MarketCache.cs プロジェクト: dol-leodagan/DOLSharp
        /// <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);
        }
コード例 #10
0
ファイル: Doppelganger.cs プロジェクト: dol-leodagan/DOLSharp
        static Doppelganger()
        {
            DBNpcTemplate chthonian = DOLDB <DBNpcTemplate> .SelectObject(DB.Column("Name").IsEqualTo("chthonian crawler"));

            if (chthonian != null)
            {
                m_petTemplate = new NpcTemplate(chthonian);
            }
        }
コード例 #11
0
        /// <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)));
        }
コード例 #12
0
ファイル: SinglePermission.cs プロジェクト: NetDwarf/DOLSharp
        public static bool HasPermission(GamePlayer player, string command)
        {
            var obj = DOLDB <DBSinglePermission> .SelectObject(DB.Column(nameof(DBSinglePermission.Command)).IsEqualTo(command).And(DB.Column(nameof(DBSinglePermission.PlayerID)).IsEqualTo(player.ObjectId).Or(DB.Column(nameof(DBSinglePermission.PlayerID)).IsEqualTo(player.AccountName))));

            if (obj == null)
            {
                return(false);
            }
            return(true);
        }
コード例 #13
0
        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
        }
コード例 #14
0
ファイル: SinglePermission.cs プロジェクト: NetDwarf/DOLSharp
        public static bool removePermissionAccount(GamePlayer player, string command)
        {
            var obj = DOLDB <DBSinglePermission> .SelectObject(DB.Column(nameof(DBSinglePermission.Command)).IsEqualTo(command).And(DB.Column(nameof(DBSinglePermission.PlayerID)).IsEqualTo(player.AccountName)));

            if (obj == null)
            {
                return(false);
            }
            GameServer.Database.DeleteObject(obj);
            return(true);
        }
コード例 #15
0
        /// <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());
            }
        }
コード例 #16
0
        /// <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);
            }
        }
コード例 #17
0
        /// <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);
            }
        }
コード例 #18
0
ファイル: Recipe.cs プロジェクト: dol-leodagan/DOLSharp
        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);
        }
コード例 #19
0
        /// <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());
            }
        }
コード例 #20
0
ファイル: Faction.cs プロジェクト: dol-leodagan/DOLSharp
        public void SaveAggroToFaction(string charID)
        {
            var dbfactionAggroLevel = DOLDB <DBFactionAggroLevel> .SelectObject(DB.Column("CharacterID").IsEqualTo(charID).And(DB.Column("FactionID").IsEqualTo(ID)));

            if (dbfactionAggroLevel == null)
            {
                dbfactionAggroLevel             = new DBFactionAggroLevel();
                dbfactionAggroLevel.AggroLevel  = (int)m_playerxFaction[charID];
                dbfactionAggroLevel.CharacterID = charID;
                dbfactionAggroLevel.FactionID   = this.ID;
                GameServer.Database.AddObject(dbfactionAggroLevel);
            }
            else
            {
                dbfactionAggroLevel.AggroLevel = (int)m_playerxFaction[charID];
                GameServer.Database.SaveObject(dbfactionAggroLevel);
            }
        }
コード例 #21
0
        /// <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);
        }
コード例 #22
0
        /// <summary>
        /// Get the item in the specified page and slot
        /// </summary>
        /// <param name="page">The item page</param>
        /// <param name="slot">The item slot</param>
        /// <returns>Item template or null</returns>
        public virtual ItemTemplate GetItem(int page, eMerchantWindowSlot slot)
        {
            try
            {
                slot = GetValidSlot(page, slot);
                if (slot == eMerchantWindowSlot.Invalid)
                {
                    return(null);
                }

                ItemTemplate item;
                lock (m_usedItemsTemplates.SyncRoot)
                {
                    item = m_usedItemsTemplates[(int)slot + (page * MAX_ITEM_IN_TRADEWINDOWS)] as ItemTemplate;
                    if (item != null)
                    {
                        return(item);
                    }
                }

                if (m_itemsListID != null && m_itemsListID.Length > 0)
                {
                    var itemToFind = DOLDB <MerchantItem> .SelectObject(DB.Column("ItemListID").IsEqualTo(m_itemsListID).And(DB.Column("PageNumber").IsEqualTo(page)).And(DB.Column("SlotPosition").IsEqualTo((int)slot)));

                    if (itemToFind != null)
                    {
                        item = GameServer.Database.FindObjectByKey <ItemTemplate>(itemToFind.ItemTemplateID);
                    }
                }
                return(item);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Loading merchant items list (" + m_itemsListID + ") page (" + page + ") slot (" + slot + "): ", e);
                }
                return(null);
            }
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        /// <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)));
        }
コード例 #25
0
ファイル: Salvage.cs プロジェクト: NetDwarf/DOLSharp
        /// <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);
        }
コード例 #26
0
ファイル: Salvage.cs プロジェクト: NetDwarf/DOLSharp
        /// <summary>
        /// Begin salvaging an inventory item
        /// </summary>
        /// <param name="item"></param>
        /// <param name="player"></param>
        /// <returns></returns>
        public static int BeginWork(GamePlayer player, InventoryItem item)
        {
            SalvageYield salvageYield = null;

            if (!IsAllowedToBeginWork(player, item))
            {
                return(0);
            }

            int salvageLevel = CraftingMgr.GetItemCraftLevel(item) / 100;

            if (salvageLevel > 9)
            {
                salvageLevel = 9;                              // max 9
            }
            var whereClause = WhereClause.Empty;

            if (item.SalvageYieldID == 0)
            {
                whereClause = DB.Column(nameof(SalvageYield.ObjectType)).IsEqualTo(item.Object_Type).And(DB.Column(nameof(SalvageYield.SalvageLevel)).IsEqualTo(salvageLevel));
            }
            else
            {
                whereClause = DB.Column(nameof(SalvageYield.ID)).IsEqualTo(item.SalvageYieldID);
            }

            if (ServerProperties.Properties.USE_SALVAGE_PER_REALM)
            {
                whereClause = whereClause.And(DB.Column(nameof(SalvageYield.Realm)).IsEqualTo((int)eRealm.None).Or(DB.Column(nameof(SalvageYield.Realm)).IsEqualTo(item.Realm)));
            }

            salvageYield = DOLDB <SalvageYield> .SelectObject(whereClause);

            ItemTemplate material = null;

            if (salvageYield != null && string.IsNullOrEmpty(salvageYield.MaterialId_nb) == false)
            {
                material = GameServer.Database.FindObjectByKey <ItemTemplate>(salvageYield.MaterialId_nb);

                if (material == null)
                {
                    player.Out.SendMessage("Can't find material (" + material.Id_nb + ") needed to salvage this item!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                    log.ErrorFormat("Salvage Error for ID: {0}:  Material not found: {1}", salvageYield.ID, material.Id_nb);
                }
            }

            if (material == null)
            {
                if (salvageYield == null && item.SalvageYieldID > 0)
                {
                    player.Out.SendMessage("This items salvage recipe (" + item.SalvageYieldID + ") not implemented yet.", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                    log.ErrorFormat("SalvageYield ID {0} not found for item: {1}", item.SalvageYieldID, item.Name);
                }
                else if (salvageYield == null)
                {
                    player.Out.SendMessage("Salvage recipe not found for this item.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    log.ErrorFormat("Salvage Lookup Error: ObjectType: {0}, Item: {1}", item.Object_Type, item.Name);
                }
                return(0);
            }

            if (player.IsMoving || player.IsStrafing)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.InterruptSalvage"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return(0);
            }

            if (player.IsStealthed)
            {
                player.Stealth(false);
            }

            player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.BeginSalvage", item.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow);

            // clone the yield entry and update values to work with this salvage (not saved to the DB)
            SalvageYield yield = salvageYield.Clone() as SalvageYield;

            if (item.SalvageYieldID == 0 || yield.Count == 0)
            {
                // Calculated salvage values
                int count = GetMaterialYield(player, item, yield, material);
                if (count < 1)
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.NoSalvage", item.Name + ". The material returned amount is zero"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return(0);
                }
            }

            player.Out.SendTimerWindow(LanguageMgr.GetTranslation(player.Client.Account.Language, "Salvage.BeginWork.Salvaging", item.Name), yield.Count);
            player.CraftTimer = new RegionTimer(player)
            {
                Callback = new RegionTimerCallback(Proceed)
            };
            player.CraftTimer.Properties.setProperty(AbstractCraftingSkill.PLAYER_CRAFTER, player);
            player.CraftTimer.Properties.setProperty(SALVAGED_ITEM, item);
            player.CraftTimer.Properties.setProperty(SALVAGE_YIELD, yield);

            player.CraftTimer.Start(yield.Count * 1000);
            return(1);
        }
コード例 #27
0
        /// <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);
        }
コード例 #28
0
        /// <summary>
        /// Talk to the NPC.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        public override bool WhisperReceive(GameLiving source, string text)
        {
            if (!base.WhisperReceive(source, text) || !(source is GamePlayer))
            {
                return(false);
            }

            GamePlayer player = source as GamePlayer;

            if ((text.ToLower() == "king" || text.ToLower() == "exit") && GlobalConstants.IsExpansionEnabled((int)eClientExpansion.DarknessRising))
            {
                uint   throneRegionID   = 0;
                string teleportThroneID = "error";
                string teleportExitID   = "error";

                switch (Realm)
                {
                case eRealm.Albion:
                    throneRegionID   = 394;
                    teleportThroneID = "AlbThroneRoom";
                    teleportExitID   = "AlbThroneExit";
                    break;

                case eRealm.Midgard:
                    throneRegionID   = 360;
                    teleportThroneID = "MidThroneRoom";
                    teleportExitID   = "MidThroneExit";
                    break;

                case eRealm.Hibernia:
                    throneRegionID   = 395;
                    teleportThroneID = "HibThroneRoom";
                    teleportExitID   = "HibThroneExit";
                    break;
                }

                if (throneRegionID == 0)
                {
                    log.ErrorFormat("Can't find King for player {0} speaking to {1} of realm {2}!", player.Name, Name, Realm);
                    player.Out.SendMessage("Server error, can't find throne room.", DOL.GS.PacketHandler.eChatType.CT_Staff, DOL.GS.PacketHandler.eChatLoc.CL_SystemWindow);
                    return(false);
                }

                Teleport teleport = null;

                if (player.CurrentRegionID == throneRegionID)
                {
                    teleport = DOLDB <Teleport> .SelectObject(DB.Column("TeleportID").IsEqualTo(teleportExitID));

                    if (teleport == null)
                    {
                        log.ErrorFormat("Can't find throne room exit TeleportID {0}!", teleportExitID);
                        player.Out.SendMessage("Server error, can't find exit to this throne room.  Moving you to your last bind point.", DOL.GS.PacketHandler.eChatType.CT_Staff, DOL.GS.PacketHandler.eChatLoc.CL_SystemWindow);
                        player.MoveToBind();
                    }
                }
                else
                {
                    teleport = DOLDB <Teleport> .SelectObject(DB.Column("TeleportID").IsEqualTo(teleportThroneID));

                    if (teleport == null)
                    {
                        log.ErrorFormat("Can't find throne room TeleportID {0}!", teleportThroneID);
                        player.Out.SendMessage("Server error, can't find throne room teleport location.", DOL.GS.PacketHandler.eChatType.CT_Staff, DOL.GS.PacketHandler.eChatLoc.CL_SystemWindow);
                    }
                }

                if (teleport != null)
                {
                    SayTo(player, "Very well ...");
                    player.MoveTo((ushort)teleport.RegionID, teleport.X, teleport.Y, teleport.Z, (ushort)teleport.Heading);
                }

                return(true);
            }


            if (text.ToLower() == "do")
            {
                if (player.Inventory.CountItemTemplate("Personal_Bind_Recall_Stone", eInventorySlot.Min_Inv, eInventorySlot.Max_Inv) == 0)
                {
                    SayTo(player, "Very well then. Here's your Personal Bind Recall Stone, may it serve you well.");
                    player.ReceiveItem(this, "Personal_Bind_Recall_Stone");
                }
                return(false);
            }

            return(true);
        }
コード例 #29
0
ファイル: RegionInstance.cs プロジェクト: NetDwarf/DOLSharp
        /// <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;
        }
コード例 #30
0
ファイル: Instance.cs プロジェクト: JVirant/DOLSharp
        /// <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);
        }