Ejemplo n.º 1
0
        /// <summary>
        /// Parse Params String to Extract the Value identified by Key.
        /// Expected Format : {"key":["value"#, "value", ...#]#, "key2":[...], ...#}
        /// From Dictionary<stringKey, List<stringValue>> (List<stringValue>.First() Casted to T)
        /// </summary>
        /// <param name="key">Param Key</param>
        /// <returns>Param Value</returns>
        public T GetParamValue <T>(string key)
        {
            if (m_paramCache == null || m_paramCache.Count == 0)
            {
                return(default(T));
            }

            // is key valid ?
            if (!Util.IsEmpty(key))
            {
                // Is key existing ?
                if (m_paramCache.ContainsKey(key) && m_paramCache[key].Count > 0)
                {
                    try
                    {
                        return((T)Convert.ChangeType(m_paramCache[key].First(), typeof(T)));
                    }
                    catch
                    {
                        return(default(T));
                    }
                }
            }

            return(default(T));
        }
Ejemplo n.º 2
0
        protected CharacterClassBase()
        {
            ID          = 0;
            _name       = "Unknown Class";
            BaseName    = "Unknown Base Class";
            _profession = string.Empty;

            // initialize members from attributes
            Attribute[] attrs = Attribute.GetCustomAttributes(GetType(), typeof(CharacterClassAttribute));
            foreach (Attribute attr in attrs)
            {
                if (attr is CharacterClassAttribute attribute)
                {
                    ID       = attribute.ID;
                    _name    = attribute.Name;
                    BaseName = attribute.BaseName;
                    if (Util.IsEmpty(attribute.FemaleName) == false)
                    {
                        FemaleName = attribute.FemaleName;
                    }

                    break;
                }
            }
        }
        /// <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 = GameServer.Database.SelectObjects <NPCEquipment>("`templateID` = @templateID", new QueryParameter("@templateID", 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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get Spot Description Checking Any Area with Description or Zone Description and Try Translating it
        /// </summary>
        /// <param name="reg"></param>
        /// <param name="client"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public static string GetTranslatedSpotDescription(this Region reg, GameClient client, int x, int y, int z)
        {
            if (reg != null)
            {
                var area = reg.GetAreasOfSpot(x, y, z).OfType <AbstractArea>().FirstOrDefault(a => a.DisplayMessage);

                // Try Translate Area First
                if (area != null)
                {
                    var lng = client.GetTranslation(area) as DBLanguageArea;

                    if (lng != null && !Util.IsEmpty(lng.ScreenDescription))
                    {
                        return(lng.ScreenDescription);
                    }

                    return(area.Description);
                }

                var zone = reg.GetZone(x, y);

                // Try Translate Zone
                if (zone != null)
                {
                    var lng = client.GetTranslation(zone) as DBLanguageZone;
                    if (lng != null)
                    {
                        return(lng.ScreenDescription);
                    }

                    return(zone.Description);
                }

                return(reg.Description);
            }

            return(string.Empty);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called whenever a player enters the given area
        /// </summary>
        /// <param name="player"></param>
        public virtual void OnPlayerEnter(GamePlayer player)
        {
            if (m_displayMessage && Description != null && Description != "")
            {
                string description       = Description;
                string screenDescription = description;

                LanguageDataObject translation = LanguageMgr.GetTranslation(player.Client.Account.Language, this);
                if (translation != null)
                {
                    if (!Util.IsEmpty(((DBLanguageArea)translation).Description))
                    {
                        description = ((DBLanguageArea)translation).Description;
                    }

                    if (!Util.IsEmpty(((DBLanguageArea)translation).ScreenDescription))
                    {
                        screenDescription = ((DBLanguageArea)translation).ScreenDescription;
                    }
                }

                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "AbstractArea.Entered", description),
                                       eChatType.CT_System, eChatLoc.CL_SystemWindow);

                //Changed by Apo 9. August 2010: Areas never send an screen description, but we will support it with an server property
                if (ServerProperties.Properties.DISPLAY_AREA_ENTER_SCREEN_DESC)
                {
                    player.Out.SendMessage(screenDescription, eChatType.CT_ScreenCenterSmaller, eChatLoc.CL_SystemWindow);
                }
            }
            if (Sound != 0)
            {
                player.Out.SendRegionEnterSound(Sound);
            }
            player.Notify(AreaEvent.PlayerEnter, this, new AreaEventArgs(this, player));
        }
Ejemplo n.º 6
0
        public CharacterClassBase()
        {
            m_id         = 0;
            m_name       = "Unknown Class";
            m_basename   = "Unknown Base Class";
            m_profession = "";

            // initialize members from attributes
            Attribute[] attrs = Attribute.GetCustomAttributes(this.GetType(), typeof(CharacterClassAttribute));
            foreach (Attribute attr in attrs)
            {
                if (attr is CharacterClassAttribute)
                {
                    m_id       = ((CharacterClassAttribute)attr).ID;
                    m_name     = ((CharacterClassAttribute)attr).Name;
                    m_basename = ((CharacterClassAttribute)attr).BaseName;
                    if (Util.IsEmpty(((CharacterClassAttribute)attr).FemaleName) == false)
                    {
                        m_femaleName = ((CharacterClassAttribute)attr).FemaleName;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add starter equipment to the character
        /// </summary>
        /// <param name="c">The character</param>
        public static void AddEquipment(DOLCharacters c)
        {
            Hashtable usedSlots = new Hashtable();

            // 0 = for all classes, then quickcheck if it contains the classid
            var items = GameServer.Database.SelectObjects <StarterEquipment>("`Class` = '0' OR `Class` LIKE '%" + c.Class + "%'");

            foreach (StarterEquipment item in items)
            {
                if (item.Template == null)
                {
                    GameServer.Instance.Logger.Error("StartupEquipment.cs error adding starter equipment for class " + c.Class + " cannot find itemtemplate for " + item.TemplateID);
                    continue;
                }

                // deeper check if item is suitable to classid
                if (!Util.IsEmpty(item.Class, true))
                {
                    int  charClass;
                    bool isFind = false;
                    foreach (string currentItem in item.Class.SplitCSV(true))
                    {
                        int.TryParse(currentItem, out charClass);
                        if (charClass == c.Class)
                        {
                            isFind = true;
                            break;
                        }
                    }
                    if (!isFind)
                    {
                        continue;
                    }
                }

                InventoryItem inventoryItem = GameInventoryItem.Create <ItemTemplate>(item.Template);
                inventoryItem.OwnerID = c.ObjectId;
                inventoryItem.Realm   = c.Realm;

                //if equipable item, equip
                foreach (eInventorySlot slot in GameLivingInventory.EQUIP_SLOTS)
                {
                    if (slot == (eInventorySlot)inventoryItem.Item_Type)
                    {
                        eInventorySlot chosenSlot = eInventorySlot.FirstEmptyBackpack;

                        if (slot == eInventorySlot.LeftHandWeapon && (eObjectType)inventoryItem.Object_Type != eObjectType.Shield && usedSlots.ContainsKey(eInventorySlot.RightHandWeapon) == false)
                        {
                            chosenSlot = eInventorySlot.RightHandWeapon;
                        }
                        else
                        {
                            chosenSlot = slot;
                        }

                        if (usedSlots.ContainsKey(chosenSlot))
                        {
                            GameServer.Instance.Logger.Error("Cannot add item " + item.TemplateID + " to class " + item.Class + " already an item for that slot assigned!");
                            continue;
                        }

                        inventoryItem.SlotPosition = (int)chosenSlot;
                        usedSlots[chosenSlot]      = true;
                        if (c.ActiveWeaponSlot == 0)
                        {
                            switch (inventoryItem.SlotPosition)
                            {
                            case Slot.RIGHTHAND:
                                c.ActiveWeaponSlot = (byte)GamePlayer.eActiveWeaponSlot.Standard;
                                break;

                            case Slot.TWOHAND:
                                c.ActiveWeaponSlot = (byte)GamePlayer.eActiveWeaponSlot.TwoHanded;
                                break;

                            case Slot.RANGED:
                                c.ActiveWeaponSlot = (byte)GamePlayer.eActiveWeaponSlot.Distance;
                                break;
                            }
                        }
                    }
                }
                if (inventoryItem.SlotPosition == 0)
                {
                    //otherwise stick the item in the backpack
                    for (int i = (int)eInventorySlot.FirstBackpack; i < (int)eInventorySlot.LastBackpack; i++)
                    {
                        if (usedSlots[i] == null)
                        {
                            inventoryItem.SlotPosition = i;
                            usedSlots[i] = true;
                            break;
                        }
                    }
                }
                GameServer.Database.AddObject(inventoryItem);
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Parse Params String to Extract the Values identified by Key.
        /// Expected Format : {"key":["value"#, "value", ...#]#, "key2":[...], ...#}
        /// From Dictionary<stringKey, List<stringValue>> (List<stringValue> Casted to List<T>)
        /// </summary>
        /// <param name="key">Param Key</param>
        /// <returns>List of Values object</returns>
        public static IList <T> GetParamValues <T>(this ICustomParamsValuable obj, string key)
        {
            if (obj.CustomParamsDictionary == null || obj.CustomParamsDictionary.Count == 0 || Util.IsEmpty(key))
            {
                return(new List <T>());
            }

            var list = new List <T>();

            // Is key existing ?
            if (obj.CustomParamsDictionary.ContainsKey(key) && obj.CustomParamsDictionary[key].Count > 0)
            {
                foreach (string val in obj.CustomParamsDictionary[key])
                {
                    T content;
                    try
                    {
                        content = (T)Convert.ChangeType(val, typeof(T));
                        list.Add(content);
                    }
                    catch
                    {
                    }
                }
            }

            return(list);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Parse Params String to Extract the Value identified by Key.
        /// Expected Format : {"key":["value"#, "value", ...#]#, "key2":[...], ...#}
        /// From Dictionary<stringKey, List<stringValue>> (List<stringValue>.First() Casted to T)
        /// </summary>
        /// <param name="key">Param Key</param>
        /// <returns>Param Value</returns>
        public static T GetParamValue <T>(this ICustomParamsValuable obj, string key)
        {
            if (obj.CustomParamsDictionary == null || obj.CustomParamsDictionary.Count == 0 || Util.IsEmpty(key))
            {
                return(default(T));
            }

            // Is key existing ?
            if (obj.CustomParamsDictionary.ContainsKey(key) && obj.CustomParamsDictionary[key].Count > 0)
            {
                try
                {
                    return((T)Convert.ChangeType(obj.CustomParamsDictionary[key].First(), typeof(T)));
                }
                catch
                {
                    return(default(T));
                }
            }

            return(default(T));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Parse Params String to Extract the Values identified by Key.
        /// Expected Format : {"key":["value"#, "value", ...#]#, "key2":[...], ...#}
        /// From Dictionary<stringKey, List<stringValue>> (List<stringValue> Casted to List<T>)
        /// </summary>
        /// <param name="key">Param Key</param>
        /// <returns>List of Values object</returns>
        public static IDictionary <K, V> GetParamValues <K, V>(this ICustomParamsValuable obj, string key)
        {
            if (obj.CustomParamsDictionary == null || obj.CustomParamsDictionary.Count == 0 || Util.IsEmpty(key))
            {
                return(new Dictionary <K, V>());
            }

            Regex regex = new Regex(string.Format(@"{0}\[(.+?)\]", key));
            var   dict  = new Dictionary <K, V>();

            // Browse all Dictionary
            foreach (var pair in obj.CustomParamsDictionary)
            {
                Match match = regex.Match(pair.Key);
                // this could be an entry
                if (match.Success)
                {
                    K keyResult;
                    V valueResult;
                    try
                    {
                        keyResult   = (K)Convert.ChangeType(match.Groups[1].Value, typeof(K));
                        valueResult = (V)Convert.ChangeType(pair.Value.FirstOrDefault(), typeof(V));
                        dict.Add(keyResult, valueResult);
                    }
                    catch
                    {
                    }
                }
            }

            return(dict);
        }