Exemplo n.º 1
0
        /// <summary>
        /// Get a list of all scholars studying this artifact.
        /// </summary>
        /// <param name="artifactID"></param>
        /// <returns></returns>
        public static String[] GetScholars(String artifactID)
        {
            if (artifactID != null)
            {
                lock (m_artifacts)
                    if (m_artifacts.ContainsKey(artifactID))
                    {
                        return(Util.SplitCSV(m_artifacts[artifactID].ScholarID).ToArray());
                    }
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the current ability name
        /// </summary>
        private void UpdateCurrentName()
        {
            try
            {
                string name        = m_serializedNames;
                var    nameByLevel = new Dictionary <int, string>();
                foreach (string levelNamePair in Util.SplitCSV(name.Trim()))
                {
                    if (levelNamePair.Trim().Length <= 0)
                    {
                        continue;
                    }

                    string[] levelAndName = levelNamePair.Trim().Split('|');

                    if (levelAndName.Length < 2)
                    {
                        nameByLevel.Add(0, levelNamePair);
                    }
                    else
                    {
                        nameByLevel.Add(int.Parse(levelAndName[0]), levelAndName[1]);
                    }
                }

                int level = Level;
                if (nameByLevel.ContainsKey(level))
                {
                    name = nameByLevel[level];
                }
                else
                {
                    var entry = nameByLevel.OrderBy(k => k.Key).FirstOrDefault(k => k.Key <= level);
                    name = entry.Value ?? string.Format("??{0}", KeyName);

                    // Warn about default value
                    if (entry.Value == null && log.IsWarnEnabled)
                    {
                        log.WarnFormat("Parsing ability display name: keyname='{0}' m_serializedNames='{1}', No Value for Level {2}", KeyName, m_serializedNames, level);
                    }
                }

                string roman = getRomanLevel();
                m_name = name.Replace("%n", roman);
            }
            catch (Exception e)
            {
                log.ErrorFormat("Parsing ability display name: keyname='{0}' m_serializedNames='{1}'\n{2}", KeyName, m_serializedNames, e);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// No trainer for disabled classes
        /// </summary>
        /// <returns></returns>
        public override bool AddToWorld()
        {
            if (!string.IsNullOrEmpty(ServerProperties.Properties.DISABLED_CLASSES))
            {
                if (disabled_classes == null)
                {
                    // creation of disabled_classes list.
                    disabled_classes = Util.SplitCSV(ServerProperties.Properties.DISABLED_CLASSES).ToList();
                }

                if (disabled_classes.Contains(TrainedClass.ToString()))
                {
                    return(false);
                }
            }
            return(base.AddToWorld());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a hashtable containing all item templates that are valid for
        /// this class.
        /// </summary>
        /// <param name="artifactID"></param>
        /// <param name="charClass"></param>
        /// <param name="realm"></param>
        /// <returns></returns>
        public static Dictionary <String, ItemTemplate> GetArtifactVersions(String artifactID, eCharacterClass charClass, eRealm realm)
        {
            if (artifactID == null)
            {
                return(null);
            }

            List <ArtifactXItem> allVersions = GetArtifactVersions(artifactID, realm);
            Dictionary <String, ItemTemplate> classVersions = new Dictionary <String, ItemTemplate>();

            lock (allVersions)
            {
                ItemTemplate itemTemplate;
                foreach (ArtifactXItem version in allVersions)
                {
                    itemTemplate = GameServer.Database.FindObjectByKey <ItemTemplate>(version.ItemID);

                    if (itemTemplate == null)
                    {
                        log.Warn(String.Format("Artifact item template '{0}' is missing", version.ItemID));
                    }
                    else
                    {
                        foreach (String classID in Util.SplitCSV(itemTemplate.AllowedClasses, true))
                        {
                            try
                            {
                                if (Int32.Parse(classID) == (int)charClass)
                                {
                                    classVersions.Add(version.Version, itemTemplate);
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Error(String.Format("Invalid class ID '{0}' for item template '{1}', checked by class '{2}'", classID, itemTemplate.Id_nb, (int)charClass));
                                log.Error(ex.Message);
                            }
                        }
                    }
                }
            }

            return(classVersions);
        }
Exemplo n.º 5
0
        /// <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 = GameServer.Database.SelectObjects <DBInstanceXElement>("`InstanceID` = @InstanceID", new QueryParameter("@InstanceID", 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.X               = entry.X;
                obj.Y               = entry.Y;
                obj.Z               = 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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Register a generator for the given parameters,
        /// If all parameters are null a global generaotr for all mobs will be registered
        /// </summary>
        /// <param name="generator"></param>
        /// <param name="mobname"></param>
        /// <param name="mobguild"></param>
        /// <param name="mobfaction"></param>
        /// <param name="mobregion"></param>
        public static void RegisterLootGenerator(ILootGenerator generator, string mobname, string mobguild, string mobfaction, int mobregion)
        {
            if (generator == null)
            {
                return;
            }

            // Loot Generator Name Indexed
            if (!Util.IsEmpty(mobname))
            {
                // Parse CSV
                try {
                    List <string> mobNames = Util.SplitCSV(mobname);

                    foreach (string mob in mobNames)
                    {
                        if ((IList)m_mobNameGenerators[mob] == null)
                        {
                            m_mobNameGenerators[mob] = new ArrayList();
                        }
                        ((IList)m_mobNameGenerators[mob]).Add(generator);
                    }
                }
                catch
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Could not Parse mobNames for Registering LootGenerator : " + generator.GetType().FullName);
                    }
                }
            }

            // Loot Generator Guild Indexed
            if (!Util.IsEmpty(mobguild))
            {
                // Parse CSV
                try {
                    List <string> mobGuilds = Util.SplitCSV(mobguild);

                    foreach (string guild in mobGuilds)
                    {
                        if ((IList)m_mobGuildGenerators[guild] == null)
                        {
                            m_mobGuildGenerators[guild] = new ArrayList();
                        }
                        ((IList)m_mobGuildGenerators[guild]).Add(generator);
                    }
                }
                catch
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Could not Parse mobGuilds for Registering LootGenerator : " + generator.GetType().FullName);
                    }
                }
            }

            // Loot Generator Region Indexed
            if (mobregion > 0)
            {
                IList regionList = (IList)m_mobRegionGenerators[mobregion];
                if (regionList == null)
                {
                    regionList = new ArrayList();
                    m_mobRegionGenerators[mobregion] = regionList;
                }
                regionList.Add(generator);
            }

            if (Util.IsEmpty(mobname) && Util.IsEmpty(mobguild) && Util.IsEmpty(mobfaction) && mobregion == 0)
            {
                m_globalGenerators.Add(generator);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Unregister a generator for the given parameters
        /// </summary>
        /// <param name="generator"></param>
        /// <param name="mobname"></param>
        /// <param name="mobguild"></param>
        /// <param name="mobfaction"></param>
        public static void UnRegisterLootGenerator(ILootGenerator generator, string mobname, string mobguild, string mobfaction, int mobregion)
        {
            if (generator == null)
            {
                return;
            }

            // Loot Generator Name Indexed
            if (!Util.IsEmpty(mobname))
            {
                try
                {
                    // Parse CSV
                    List <string> mobNames = Util.SplitCSV(mobname);

                    foreach (string mob in mobNames)
                    {
                        if ((IList)m_mobNameGenerators[mob] != null)
                        {
                            ((IList)m_mobNameGenerators[mob]).Remove(generator);
                        }
                    }
                }
                catch
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Could not Parse mobNames for Removing LootGenerator : " + generator.GetType().FullName);
                    }
                }
            }

            // Loot Generator Guild Indexed
            if (!Util.IsEmpty(mobguild))
            {
                try
                {
                    // Parse CSV
                    List <string> mobGuilds = Util.SplitCSV(mobguild);

                    foreach (string guild in mobGuilds)
                    {
                        if ((IList)m_mobGuildGenerators[guild] != null)
                        {
                            ((IList)m_mobGuildGenerators[guild]).Remove(generator);
                        }
                    }
                }
                catch
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Could not Parse mobGuilds for Removing LootGenerator : " + generator.GetType().FullName);
                    }
                }
            }

            // Loot Generator Faction Indexed
            if (!Util.IsEmpty(mobfaction))
            {
                try
                {
                    // Parse CSV
                    List <string> mobFactions = Util.SplitCSV(mobfaction);

                    foreach (string sfaction in mobFactions)
                    {
                        try
                        {
                            int ifaction = int.Parse(sfaction);

                            if ((IList)m_mobFactionGenerators[ifaction] != null)
                            {
                                ((IList)m_mobFactionGenerators[ifaction]).Remove(generator);
                            }
                        }
                        catch
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Could not parse faction [" + sfaction + "] into an integer.");
                            }
                        }
                    }
                }
                catch
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Could not Parse mobFactions for Removing LootGenerator : " + generator.GetType().FullName);
                    }
                }
            }

            // Loot Generator Region Indexed
            if (mobregion > 0)
            {
                IList regionList = (IList)m_mobRegionGenerators[mobregion];
                if (regionList != null)
                {
                    regionList.Remove(generator);
                }
            }

            if (Util.IsEmpty(mobname) && Util.IsEmpty(mobguild) && Util.IsEmpty(mobfaction) && mobregion == 0)
            {
                m_globalGenerators.Remove(generator);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Constructs a new NpcTemplate
        /// </summary>
        /// <param name="data">The source npc template data</param>
        public NpcTemplate(DBNpcTemplate data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            m_templateId     = data.TemplateId;
            m_translationId  = data.TranslationId;
            m_name           = data.Name;
            m_suffix         = data.Suffix;
            m_classType      = data.ClassType;
            m_guildName      = data.GuildName;
            m_examineArticle = data.ExamineArticle;
            m_messageArticle = data.MessageArticle;
            m_model          = data.Model;
            m_gender         = data.Gender;
            m_size           = data.Size;
            if (m_size == null)
            {
                m_size = "50";
            }
            m_level = data.Level;
            if (m_level == null)
            {
                m_level = "0";
            }
            m_equipmentTemplateID = data.EquipmentTemplateID;
            m_itemsListTemplateID = data.ItemsListTemplateID;
            m_maxSpeed            = data.MaxSpeed;
            m_parryChance         = data.ParryChance;
            m_evadeChance         = data.EvadeChance;
            m_blockChance         = data.BlockChance;
            m_leftHandSwingChance = data.LeftHandSwingChance;
            m_strength            = data.Strength;
            m_constitution        = data.Constitution;
            m_dexterity           = data.Dexterity;
            m_quickness           = data.Quickness;
            m_intelligence        = data.Intelligence;
            m_piety     = data.Piety;
            m_charisma  = data.Charisma;
            m_empathy   = data.Empathy;
            WeaponDps   = data.WeaponDps;
            WeaponSpd   = data.WeaponSpd;
            ArmorFactor = data.ArmorFactor;
            ArmorAbsorb = data.ArmorAbsorb;

            //Time to add Spells/Styles and Abilties to the templates
            m_abilities  = new ArrayList();
            m_spelllines = new ArrayList();
            m_spells     = new ArrayList();
            //Adding the spells to an Arraylist here
            if (data.Spells != null && data.Spells.Length > 0)
            {
                string[] spells = data.Spells.Split(';');
                for (int k = 0; k < spells.Length; k++)
                {
                    int   id = int.Parse(spells[k]);
                    Spell sp = SkillBase.GetSpellByID(id);
                    if (sp != null)
                    {
                        m_spells.Add(sp);
                    }
                    else
                    {
                        log.Error("Tried to load a null spell into NPC template " + m_templateId + " spell ID: " + id);
                    }
                }
            }

            // Adding Style list to Template NPC
            m_styles = new ArrayList();
            if (data.Styles != null && data.Styles.Length > 0)
            {
                string[] styles = data.Styles.Split(';');
                for (int i = 0; i < styles.Length; i++)
                {
                    if (styles[i].Trim().Length == 0)
                    {
                        continue;
                    }
                    string[] styleAndClass = styles[i].Split('|');
                    if (styleAndClass.Length != 2)
                    {
                        continue;
                    }
                    string stylePart = styleAndClass[0].Trim();
                    string classPart = styleAndClass[1].Trim();
                    if (stylePart.Length == 0 || classPart.Length == 0)
                    {
                        continue;
                    }
                    int   styleID = int.Parse(stylePart);
                    int   classID = int.Parse(classPart);
                    Style style   = SkillBase.GetStyleByID(styleID, classID);
                    m_styles.Add(style);
                }
            }
            //Adding Abilities to Template NPC.
            //Certain Abilities have levels will need to fix that down the road. -Batlas

            if (data.Abilities != null && data.Abilities.Length > 0)
            {
                foreach (string splitab in Util.SplitCSV(data.Abilities))
                {
                    string[] ab = splitab.Split('|');
                    if (splitab.Trim().Length == 0)
                    {
                        continue;
                    }
                    int id = 1;
                    if (ab.Length > 1)
                    {
                        id = int.Parse(ab[1]);
                    }
                    Ability abil = SkillBase.GetAbility(ab[0], id);
                    if (abil != null)
                    {
                        m_abilities.Add(abil);
                    }
                }
            }

            m_flags = data.Flags;

            m_meleeDamageType = (eDamageType)data.MeleeDamageType;
            if (data.MeleeDamageType == 0)
            {
                m_meleeDamageType = eDamageType.Slash;
            }

            m_inventory               = data.EquipmentTemplateID;
            m_aggroLevel              = data.AggroLevel;
            m_aggroRange              = data.AggroRange;
            m_race                    = (ushort)data.Race;
            m_bodyType                = (ushort)data.BodyType;
            m_maxdistance             = data.MaxDistance;
            m_tetherRange             = data.TetherRange;
            m_visibleActiveWeaponSlot = data.VisibleWeaponSlots;

            m_replaceMobValues = data.ReplaceMobValues;
        }