Exemple #1
0
        // Create a localized cache for spell names
        public static void SpellInfoCreateCache(List <uint> listId)
        {
            lock (SpellManagerLocker)
            {
                try
                {
                    string listIdString = "{ ";
                    foreach (uint id in listId)
                    {
                        listIdString += id + " ,";
                    }
                    if (listIdString.EndsWith(","))
                    {
                        listIdString = listIdString.Remove(listIdString.Length - 1);
                    }
                    listIdString += "}";

                    string randomString = Others.GetRandomString(Others.Random(5, 10));
                    string command      = randomString + " = \"\"; " +
                                          "local spellBookList = " + listIdString + " " +
                                          "for arrayId = 1, table.getn(spellBookList) do " +
                                          "local name, rank, icon, castTime, minRange, maxRange, spellId = GetSpellInfo(spellBookList[arrayId]); " +
                                          randomString + " = " + randomString +
                                          " .. tostring(name) .. \"##\" .. tostring(icon) .. \"##\" .. tostring(castTime) .. \"##\" .. tostring(minRange)  .. \"##\" .. tostring(maxRange)  .. \"##\" .. tostring(spellId);" +
                                          randomString + " = " + randomString + " .. \"||\"" +
                                          "end ";
                    string result = Lua.LuaDoString(command, randomString);
                    if (!string.IsNullOrWhiteSpace(result))
                    {
                        string[] listSpell = result.Split(new[] { "||" }, StringSplitOptions.None);
                        if (listSpell.Length > 0)
                        {
                            foreach (string s in listSpell)
                            {
                                if (string.IsNullOrWhiteSpace(s))
                                {
                                    break;
                                }
                                string[] slipped = s.Split(new[] { "##" }, StringSplitOptions.None);
                                if (slipped.Length == 6)
                                {
                                    var   spellInfo = new SpellInfoLua();
                                    int   intOut;
                                    float floatOut;

                                    // name
                                    if (!string.IsNullOrWhiteSpace(slipped[0]) && slipped[0] != "nil")
                                    {
                                        spellInfo.Name = slipped[0];
                                    }
                                    // icon
                                    if (!string.IsNullOrWhiteSpace(slipped[1]))
                                    {
                                        spellInfo.Icon = slipped[1];
                                    }
                                    // castTime
                                    if (!string.IsNullOrWhiteSpace(slipped[2]) &&
                                        int.TryParse(slipped[2].Replace(".", ","), out intOut))
                                    {
                                        spellInfo.CastTime = intOut;
                                    }
                                    // minRange
                                    if (!string.IsNullOrWhiteSpace(slipped[3]) &&
                                        float.TryParse(slipped[3].Replace(".", ","), out floatOut))
                                    {
                                        spellInfo.MinRange = floatOut;
                                    }
                                    // maxRange
                                    if (!string.IsNullOrWhiteSpace(slipped[4]) &&
                                        float.TryParse(slipped[4].Replace(".", ","), out floatOut))
                                    {
                                        spellInfo.MaxRange = floatOut;
                                    }
                                    // ID
                                    if (!string.IsNullOrWhiteSpace(slipped[5]) &&
                                        int.TryParse(slipped[5].Replace(".", ","), out intOut))
                                    {
                                        spellInfo.ID = (uint)intOut;
                                    }

                                    if (listId.Contains(spellInfo.ID))
                                    {
                                        if (!_spellInfos.ContainsKey(spellInfo.ID))
                                        {
                                            _spellInfos.Add(spellInfo.ID, spellInfo);
                                        }
                                    }
                                }
                                else
                                {
                                    Logging.WriteDebug("Return as bad format: public static SpellInfo SpellInfoCreateCache()");
                                }
                            }
                        }
                    }
                    else
                    {
                        Logging.WriteDebug("Cannot find spell: public static SpellInfo SpellInfoCreateCache()");
                    }
                }
                catch (Exception exception)
                {
                    Logging.WriteError("SpellInfo GetSpellInfo(uint id): " + exception);
                }
            }
        }
Exemple #2
0
        // Localized spell names

        public static SpellInfoLua GetSpellInfo(uint id)
        {
            try
            {
                lock (SpellManagerLocker)
                {
                    if (_spellInfos.ContainsKey(id))
                    {
                        return(_spellInfos[id]);
                    }
                    string randomString = Others.GetRandomString(Others.Random(5, 10));
                    string result       = Lua.LuaDoString(
                        randomString + " = \"\"; " +
                        "local name, rank, icon, castTime, minRange, maxRange, spellId = GetSpellInfo(" + id + "); " +
                        randomString +
                        " = tostring(name) .. \"##\" .. tostring(icon) .. \"##\" .. tostring(castTime) .. \"##\" .. tostring(minRange)  .. \"##\" .. tostring(maxRange)  .. \"##\" .. tostring(spellId);"
                        , randomString);
                    if (!string.IsNullOrWhiteSpace(result))
                    {
                        string[] ar      = { "##" };
                        string[] slipped = result.Split(ar, StringSplitOptions.None);
                        if (slipped.Length == 6)
                        {
                            var   spellInfo = new SpellInfoLua();
                            int   intOut;
                            float floatOut;

                            // ID
                            spellInfo.ID = id;
                            // name
                            if (!string.IsNullOrWhiteSpace(slipped[0]) && slipped[0] != "nil")
                            {
                                spellInfo.Name = slipped[0];
                            }
                            // icon
                            if (!string.IsNullOrWhiteSpace(slipped[1]))
                            {
                                spellInfo.Icon = slipped[1];
                            }
                            // castTime
                            if (!string.IsNullOrWhiteSpace(slipped[2]) && int.TryParse(slipped[2].Replace(".", ","), out intOut))
                            {
                                spellInfo.CastTime = intOut;
                            }
                            // minRange
                            if (!string.IsNullOrWhiteSpace(slipped[3]) && float.TryParse(slipped[3].Replace(".", ","), out floatOut))
                            {
                                spellInfo.MinRange = floatOut;
                            }
                            // maxRange
                            if (!string.IsNullOrWhiteSpace(slipped[4]) && float.TryParse(slipped[4].Replace(".", ","), out floatOut))
                            {
                                spellInfo.MaxRange = floatOut;
                            }

                            _spellInfos.Add(id, spellInfo);
                            return(spellInfo);
                        }
                        Logging.WriteDebug("Return as bad format: public static SpellInfo GetSpellInfo(" + id + ")");
                    }
                    else
                    {
                        Logging.WriteDebug("Cannot find spell: public static SpellInfo GetSpellInfo(" + id + ")");
                    }
                }
            }
            catch (Exception exception)
            {
                Logging.WriteError("SpellInfo GetSpellInfo(uint id): " + exception);
            }
            return(new SpellInfoLua());
        }