Ejemplo n.º 1
0
        /// <summary>
        /// StringTableを読み込み、言語ファイルを返す。
        /// 言語ファイルにファイル履歴の枠組みを作成し設定する。
        /// </summary>
        /// <param name="path">StringTableファイルのパス</param>
        /// <param name="productLine">製品区分</param>
        /// <param name="fileID">FileID</param>
        /// <returns>言語ファイル</returns>
        public static MieLanguageFile LoadFromXml(string path, MieProduct.NProductLine productLine, out string fileID)
        {
            //// StringTableの読み込み
            var stringTableFile = StringTableFile.Load(path);
            //// ファイル履歴の作成
            MieLanguageHistoryFile mieLanguageHistoryFile = new MieLanguageHistoryFile(stringTableFile.Name);

            //// FileIDを統一形式に変換する。
            fileID = MieFileUtils.ConvertFileIDToCommon(stringTableFile.Name);
            var commonFileID = MieStringUtils.NormalizedFileID(fileID);
            var fileCode     = MieHashTools.ComputeFileID(commonFileID);

            var mieLanguageFile = new MieLanguageFile(fileCode);

            stringTableFile
            .Entries
            .ForEach(entry =>
            {
                var referenceID      = MieTranslationLib.MieUtils.MieHashTools.ComputeReferenceID(stringTableFile.Name, entry.ID);
                var mieLanguageEntry = new MieLanguageEntry(entry.ID, entry.DefaultText, entry.FemaleText, productLine, referenceID);
                mieLanguageFile.AddEntry(mieLanguageEntry);
            });

            return(mieLanguageFile);
        }
Ejemplo n.º 2
0
        public void TestRowMethods()
        {
            const string ROW_KEY     = "Test Key";
            const int    ROW_ID      = 1;
            const string ROW_VALUE_1 = "Test Value 1";
            const string ROW_VALUE_2 = "Test Value 2";

            StringTableFile savedStringTableFile = new StringTableFile();

            savedStringTableFile.AddRow(ROW_KEY, ROW_ID);

            Assert.AreEqual(savedStringTableFile.RowCount, 1, "Row count is incorrect");

            savedStringTableFile[0].SetText(ROW_VALUE_1);
            string rowValue = savedStringTableFile[0].GetText();

            Assert.AreEqual(rowValue, ROW_VALUE_1, "Row value is incorrect");

            savedStringTableFile[ROW_KEY].SetText(ROW_VALUE_2);
            rowValue = savedStringTableFile[ROW_KEY].GetText();

            Assert.AreEqual(rowValue, ROW_VALUE_2, "Row value is incorrect");

            savedStringTableFile.RemoveRow(ROW_KEY);

            Assert.AreEqual(savedStringTableFile.RowCount, 0, "Row count is incorrect");
        }
Ejemplo n.º 3
0
        public static string GetFileIdFromXML(string path)
        {
            //// StringTableの読み込み
            var stringTableFile = StringTableFile.Load(path);
            var fileID          = MieFileUtils.ConvertFileIDToCommon(stringTableFile.Name);

            return(fileID);
        }
Ejemplo n.º 4
0
        public void LoadAndConvert()
        {
            int         typeIdx     = 0;
            List <Item> sqlFileList = new List <Item>();

            foreach (var itemDataFile in itemDataFiles)
            {
                ++typeIdx;
                var stringFile = new StringTableFile();
                var dataFile   = new DataFile();

                try
                {
                    dataFile.Load(itemDataFile.DataFile);
                    stringFile.Load(itemDataFile.StringFile);
                }
                catch (FileNotFoundException)
                {
                    continue;
                }
                catch (ArgumentNullException)
                {
                    continue;
                }

                for (var i = 0; i < dataFile.RowCount; i++)
                {
                    StringTableRow strTableRow;
                    var            curRow = dataFile[i];
                    try
                    {
                        strTableRow = stringFile[curRow[(dataFile.ColumnCount - 1)]];
                    }
                    catch (ArgumentException)
                    {
                        continue;
                    }

                    var itemData = new Item(i, typeIdx);
                    itemData.Load(curRow, strTableRow);

                    sqlFileList.Add(itemData);
                }
            }

            var jsonString = JsonConvert.SerializeObject(sqlFileList, Formatting.Indented,
                                                         new JsonSerializerSettings {
                DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
            });

            (new FileInfo("srv_data\\item_db.json")).Directory.Create();
            var sqlFile = new System.IO.StreamWriter("srv_data\\item_db.json", false);

            using (sqlFile)
            {
                sqlFile.WriteLine(jsonString);
            }
        }
Ejemplo n.º 5
0
        public void LoadAndConvert(string stbPath = null, string stlPath = null)
        {
            if (stbPath == null || stlPath == null)
            {
                return;
            }

            var stringFile = new StringTableFile();
            var dataFile   = new DataFile();

            try
            {
                dataFile.Load(stbPath);
                stringFile.Load(stlPath);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e);
                return;
            }

            List <Skill> sqlFileList = new List <Skill>();

            for (var i = 0; i < dataFile.RowCount; i++)
            {
                StringTableRow strTableRow;
                var            curRow = dataFile[i];
                try
                {
                    strTableRow = stringFile[curRow[(dataFile.ColumnCount - 1)]];
                }
                catch (ArgumentException)
                {
                    continue;
                }

                var skill = new Skill(i);
                skill.Load(curRow, strTableRow);

                sqlFileList.Add(skill);
            }

            var jsonString = JsonConvert.SerializeObject(sqlFileList, Formatting.Indented,
                                                         new JsonSerializerSettings {
                DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
            });

            (new FileInfo("srv_data\\skill_db.json")).Directory.Create();
            var sqlFile = new System.IO.StreamWriter("srv_data\\skill_db.json", false);

            using (sqlFile)
            {
                sqlFile.WriteLine(jsonString);
            }
        }
Ejemplo n.º 6
0
        public static void SaveToXml(
            string fileID,
            StringTableFile stringTableFile,
            string jpFolderPath,
            bool useReferenceID = false)
        {
            var path   = Path.Combine(jpFolderPath, fileID + ".stringtable");
            var folder = Path.GetDirectoryName(path);

            MieCommonUtils.SafeCreateDirectory(folder);

            StringTableFile.Save(stringTableFile, path, StringTableFile.ExportType.Xml);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Tests the load method using the specified file path and row count.
        /// </summary>
        private void TestLoadMethod(string filePath, int rowCount)
        {
            Stream stream = File.OpenRead(filePath);

            stream.Seek(0, SeekOrigin.End);
            long fileSize = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);

            StringTableFile stringTableFile = new StringTableFile();

            stringTableFile.Load(stream);

            long streamPosition = stream.Position;

            stream.Close();

            Assert.AreEqual(fileSize, streamPosition, "Not all of the file was read");
            Assert.AreEqual(rowCount, stringTableFile.RowCount, "Incorrect row count");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Tests the save method using the specified file path.
        /// </summary>
        private void TestSaveMethod(string filePath)
        {
            StringTableFile stringTableFile = new StringTableFile();

            stringTableFile.Load(filePath);

            MemoryStream savedStream = new MemoryStream();

            stringTableFile.Save(savedStream);
            savedStream.Seek(0, SeekOrigin.Begin);

            StringTableFile savedStringTableFile = new StringTableFile();

            savedStringTableFile.Load(savedStream);
            savedStream.Close();

            Assert.AreEqual(stringTableFile.TableType, stringTableFile.TableType, "Table types do not match");
            Assert.AreEqual(stringTableFile.RowCount, stringTableFile.RowCount, "Row counts do not match");

            for (int i = 0; i < stringTableFile.RowCount; i++)
            {
                for (int j = 0; j < stringTableFile.LanguageCount; j++)
                {
                    StringTableLanguage language = (StringTableLanguage)j;

                    Assert.AreEqual(stringTableFile[i].GetText(language), savedStringTableFile[i].GetText(language), "Text values do not match");

                    if (stringTableFile.TableType == StringTableType.Item || stringTableFile.TableType == StringTableType.Quest)
                    {
                        Assert.AreEqual(stringTableFile[i].GetDescription(language), savedStringTableFile[i].GetDescription(language), "Description values do not match");

                        if (stringTableFile.TableType == StringTableType.Quest)
                        {
                            Assert.AreEqual(stringTableFile[i].GetStartMessage(language), savedStringTableFile[i].GetStartMessage(language), "Start message values do not match");
                            Assert.AreEqual(stringTableFile[i].GetEndMessage(language), savedStringTableFile[i].GetEndMessage(language), "End message values do not match");
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 日本語化とXMLファイルの保存。
        /// </summary>
        /// <param name="fileID">FileID</param>
        /// <param name="enFolderPath">原文のXMLファイルのパス</param>
        /// <param name="jpFolderPath">日本語版のXMLファイルのパス</param>
        /// <param name="transSheetFile">翻訳シートファイル</param>
        /// <param name="useReferenceID">ReferenceIDの有無</param>
        public static void SaveToXml(
            string fileID,
            string enFolderPath,
            string jpFolderPath,
            MieTransSheetFile transSheetFile,
            bool useReferenceID = false)
        {
            //// StringTableの読み込み
            var enPath = Path.Combine(enFolderPath, fileID + ".stringtable");
            {
                //// Bugfix: stringtable内のNameパラメーターに誤りがあるため、修正する。
                enPath = enPath.Replace("bounty encounters", "bounty_encounters");
            }

            var stringTableFile = StringTableFile.Load(enPath);
            //// ファイル履歴の作成
            MieLanguageHistoryFile mieLanguageHistoryFile = new MieLanguageHistoryFile(stringTableFile.Name);

            //// FileIDを統一形式に変換する。
            var commonFileID = MieStringUtils.NormalizedFileID(fileID);
            var fileCode     = MieHashTools.ComputeFileID(commonFileID);

            if (transSheetFile == null)
            {
                //// 翻訳シートがない場合は転記しない。
            }
            else
            {
                foreach (var entry in stringTableFile.Entries)
                {
                    MieTransSheetEntry sheetEntry = transSheetFile.GetEntry(entry.ID);

                    if (sheetEntry == null || string.IsNullOrWhiteSpace(entry.DefaultText))
                    {
                        //// 原文の翻訳テキストが存在しない場合は転記しない。
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(sheetEntry.DefaultTranslationText))
                        {
                            //// 翻訳テキストが存在しない場合は転記しない。
                        }
                        else
                        {
                            entry.DefaultText = sheetEntry.DefaultTranslationText;
                            if (!string.IsNullOrWhiteSpace(entry.FemaleText))
                            {
                                //// 女性版テキストが存在する場合は標準テキストを転記する。
                                entry.FemaleText = sheetEntry.DefaultTranslationText;
                            }
                        }
                    }

                    if (sheetEntry != null)
                    {
                        if (sheetEntry.FileID.StartsWith(@"game"))
                        {
                            if (useReferenceID)
                            {
                                entry.DefaultText = $"{sheetEntry.ReferenceID}:{entry.DefaultText}";
                            }
                        }
                    }
                }
            }

            var jpPath   = Path.Combine(jpFolderPath, fileID + ".stringtable");
            var jpFolder = Path.GetDirectoryName(jpPath);

            MieCommonUtils.SafeCreateDirectory(jpFolder);
            StringTableFile.Save(stringTableFile, jpPath, StringTableFile.ExportType.Xml);
        }
Ejemplo n.º 10
0
        public static void CreateXml(
            string fileID,
            MieLanguageFile langFile,
            string jpPath,
            MieTransSheetFile transSheetFile,
            bool useMT,
            bool useReferenceID)
        {
            var stringTableFile = new StringTableFile(fileID);

            foreach (var tableEntry in langFile.Items)
            {
                MieTransSheetEntry transSheetEntry = null;
                if (transSheetFile != null)
                {
                    transSheetEntry = transSheetFile.GetEntry(tableEntry.ID);
                }

                var translatedText = string.Empty;
                if (transSheetEntry == null)
                {
                    //// 翻訳シートエントリーがないので、ReferenceIDを個別に算出。
                    //// no | useRef | en | result
                    //// 0  |    o   |  o | ref付きen
                    //// 1  |    o   |  x | en
                    //// 2  |    x   |  o | en
                    //// 3  |    x   |  x | en
                    if (useReferenceID && !string.IsNullOrEmpty(tableEntry.DefaultText)) //// 0
                    {
                        //// 翻訳シートにエントリーが存在しない。
                        logger.Error($"TransSheetEntry not found. Product({tableEntry.ProductLine.ToString()}) FileID({fileID}), ID({tableEntry.ID})");

                        //// ReferenceIDを算出。
                        long referenceID = MieHashTools.ComputeReferenceID(stringTableFile.Name, tableEntry.ID);
                        //// ReferenceIDからhash文字列を生成
                        var strReferenceID = $"{MieHashTools.ComputeHashIds(referenceID)}:";

                        translatedText = $"{strReferenceID}{tableEntry.DefaultText}";
                    }
                    else
                    {
                        translatedText = tableEntry.DefaultText;
                    }
                }
                else
                {
                    //// 翻訳
                    translatedText = transSheetEntry.Translate(tableEntry.DefaultText, useMT, useReferenceID);
                }

                if (string.IsNullOrWhiteSpace(tableEntry.FemaleText))
                {
                    //// 女性の台詞なしの場合。
                    var entry = new StringTableFile.Entry(tableEntry.ID, translatedText);
                    stringTableFile.Entries.Add(entry);
                }
                else
                {
                    //// 女性の台詞ありの場合。
                    //// 男性と同じ台詞を割り当てる。
                    var entry = new StringTableFile.Entry(tableEntry.ID, translatedText, translatedText);
                    stringTableFile.Entries.Add(entry);
                }
            }

            Console.WriteLine(fileID);
            SaveToXml(fileID, stringTableFile, jpPath);
        }
Ejemplo n.º 11
0
        public void Load(ItemType type = 0, string stbPath = null, string stlPath = null)
        {
            if (type == 0 || stbPath == null || stlPath == null)
            {
                return;
            }

            var stringFile = new StringTableFile();
            var dataFile   = new DataFile();

            Console.Write("Attempting to load \"" + stbPath + "\" and \"" + stlPath + "\" - ");

            try
            {
                dataFile.Load(stbPath);
                stringFile.Load(stlPath);
            }
            catch (FileNotFoundException e)
            {
                Console.Write("Failed!\n");
                Console.WriteLine(e);
                return;
            }
            Console.Write("Successful!\n");
            List <string> sqlFileList = new List <string>();

            for (var i = 0; i < dataFile.RowCount; i++)
            {
                StringTableRow strTableRow;
                var            curRow = dataFile[i];
                try
                {
                    strTableRow = stringFile[curRow[(dataFile.ColumnCount - 1)]];
                }
                catch (ArgumentException)
                {
                    continue;
                }

                var itemName = strTableRow.GetText();
                var itemDesc = strTableRow.GetDescription();

                if (itemName.Length == 0 || itemDesc.Length == 0)
                {
                    continue;
                }

                string        script = "";
                List <string> reqTable = new List <string>();
                List <string> bonusTable = new List <string>();
                double        priceSell = 0.0f;
                int           subtype, priceBuy, weight, attack, defense, range, slots, equipJobs, groundViewModel, durability, attackSpeed, magic, moveSpeed, usageRestrictions;
                subtype = priceBuy = weight = attack = defense = range = slots = equipJobs = groundViewModel = durability = attackSpeed = magic = moveSpeed = usageRestrictions = 0;

                int.TryParse(curRow[4], out usageRestrictions);
                int.TryParse(curRow[5], out subtype);
                int.TryParse(curRow[6], out priceBuy);
                double.TryParse(curRow[7], out priceSell);
                int.TryParse(curRow[8], out weight);

                int.TryParse(curRow[11], out groundViewModel);
                int.TryParse(curRow[17], out equipJobs);

                try
                {
                    for (var reqIndex = 0; reqIndex < 2; reqIndex++)
                    {
                        var reqType = curRow[(20 + (reqIndex * 2))];
                        var value   = curRow[(21 + (reqIndex * 2))];

                        if (reqType.Length == 0 || value.Length == 0)
                        {
                            continue;
                        }

                        var reqId = "reqTable[" + (reqIndex + 1) + "]";
                        reqTable.Add(reqId + " = {}\n" +
                                     reqId + ".type = " + reqType + "\n" +
                                     reqId + ".value = " + value + "\n");
                    }

                    for (var bonusIndex = 0; bonusIndex < 2; bonusIndex++)
                    {
                        var bonusType = curRow[(25 + (bonusIndex * 3))];
                        var value     = curRow[(26 + (bonusIndex * 3))];

                        if (bonusType.Length == 0 || value.Length == 0)
                        {
                            continue;
                        }

                        var bonusId = "bonusTable[" + (bonusIndex + 1) + "]";
                        bonusTable.Add(bonusId + " = {}\n" +
                                       bonusId + ".type = " + bonusType + "\n" +
                                       bonusId + ".value = " + value + "\n");
                    }

                    int.TryParse(curRow[30], out durability);
                    int.TryParse(curRow[32], out defense);

                    switch (type)
                    {
                    case ItemType.BACK:
                    case ItemType.FOOT:
                    {
                        int.TryParse(curRow[34], out moveSpeed);
                        break;
                    }

                    case ItemType.WEAPON:
                    {
                        int.TryParse(curRow[31], out slots);
                        int.TryParse(curRow[34], out range);
                        int.TryParse(curRow[36], out attack);
                        int.TryParse(curRow[37], out attackSpeed);
                        int.TryParse(curRow[38], out magic);
                        break;
                    }

                    case ItemType.SUB_WEAPON:
                    {
                        int.TryParse(curRow[31], out slots);
                        break;
                    }

                    default:
                        break;
                    }
                }
                catch (ArgumentOutOfRangeException e)
                {
                    //Console.WriteLine(e);
                    //Shit borked..... naaaa just this STB prob doesn't have extra data in it
                }

#if OUTPUT_STB_DATA_COMMENT
                script += "--[[ ";
                for (var j = 0; j < dataFile.ColumnCount - 1; j++)
                {
                    script += "COLUMN " + j + 1 + " =='" + curRow[j + 1] + "'\n";
                }
                script += "--]]\n\n";
#endif

                if (reqTable.Count > 0)
                {
                    script += "reqTable = {}\n";
                }

                foreach (var requirement in reqTable)
                {
                    script += requirement;
                }


                if (bonusTable.Count > 0)
                {
                    script += "bonusTable = {}\n";
                }
                foreach (var bonus in bonusTable)
                {
                    script += bonus;
                }

                script +=
                    @"
function OnInit()
  return true
end

function OnCreate()
  return true
end

function OnDelete()
  return true
end

function OnEquip(entity)";
                if (reqTable.Count > 0)
                {
                    script +=
                        @"
  for i, data in ipairs(reqTable) do
    if data.value > getAttr(entity, data.type) then
      return false
    end
  end";
                }

                if (bonusTable.Count > 0)
                {
                    script +=
                        @"
  for i, data in ipairs(bonusTable) do
    addBonusAttr(entity, data.type, data.value)
  end";
                }

                script +=
                    @"
  return true
end

function OnUnequip(entity)";

                if (bonusTable.Count > 0)
                {
                    script +=
                        @"
  for i, data in ipairs(bonusTable) do
    removeBonusAttr(entity, data.type, data.value)
  end";
                }

                script +=
                    @"
  return true
end

function OnDrop(entity)
  return true
end

function OnPickup(entity)
  return true
end

function OnUse(entity)
  return true
end

function GetAttackSpd()
  return " + attackSpeed + @"
end

function GetMoveSpd()
  return " + moveSpeed + @"
end

function GetMagic()
  return " + magic + @"
end

function GetUsageRestrictions()
  return " + usageRestrictions + @"
end";

                itemDesc = itemDesc.Replace("\"", "\\\"");
                string sqlEntry =
                    "REPLACE into item_db(id, name, `desc`, type, subtype, price_buy, price_sell, weight, attack, defense, `range`, slots, equip_jobs, view_id, script) ";
                sqlEntry += "values(" + i + ", \"" + itemName + "\", \"" + itemDesc + "\", " + (int)(type) + ", " + subtype + ", " + priceBuy + ", " + priceSell + ", " + weight + ", " + attack + ", " + defense + ", " + range.ToString("G", CultureInfo.InvariantCulture) + ", " + slots + ", " + equipJobs + ", " + groundViewModel + ", \"" + script + "\");";

                sqlFileList.Add(sqlEntry);
            }

            var sqlFile = new System.IO.StreamWriter("srv_data\\item_db.sql", true);
            using (sqlFile)
            {
                foreach (var itemLine in sqlFileList)
                {
                    sqlFile.WriteLine(itemLine);
                }
            }
        }
Ejemplo n.º 12
0
        public void Load(string stbPath = null, string stlPath = null)
        {
            if (stbPath == null || stlPath == null)
            {
                return;
            }

            var stringFile = new StringTableFile();
            var dataFile   = new DataFile();

            Console.Write("Attempting to load \"" + stbPath + "\" and \"" + stlPath + "\" - ");

            try
            {
                dataFile.Load(stbPath);
                stringFile.Load(stlPath);
            }
            catch (FileNotFoundException e)
            {
                Console.Write("Failed!\n");
                Console.WriteLine(e);
                return;
            }
            Console.Write("Successful!\n");
            List <string> sqlFileList = new List <string>();

            for (var i = 0; i < dataFile.RowCount; i++)
            {
                StringTableRow strTableRow;
                var            curRow = dataFile[i];
                try
                {
                    strTableRow = stringFile[curRow[(dataFile.ColumnCount - 1)]];
                }
                catch (ArgumentException)
                {
                    continue;
                }

                var skillName = strTableRow.GetText();
                var skillDesc = strTableRow.GetDescription();

                if (skillName.Length == 0 || skillDesc.Length == 0)
                {
                    continue;
                }

                string script = "";
                int    level, type, range, class_, power, pointsToLevelUp, zulyNeededToLevelUp, usageAttribute;
                level = type = range = class_ = power = pointsToLevelUp = zulyNeededToLevelUp = usageAttribute = 0;


//enum
//{
//  SKILL_TYPE_01 = 1,
//  SKILL_TYPE_02,
//  SKILL_TYPE_03,
//  SKILL_TYPE_04,
//  SKILL_TYPE_05,
//  SKILL_TYPE_06,
//  SKILL_TYPE_07,
//  SKILL_TYPE_08,
//  SKILL_TYPE_09,
//  SKILL_TYPE_10,
//  SKILL_TYPE_11,
//  SKILL_TYPE_12,
//  SKILL_TYPE_13,
//  SKILL_TYPE_14,
//  SKILL_TYPE_15,
//  // ÆÐ½Ãºê ½ºÅ³
//  SKILL_TYPE_PASSIVE = SKILL_TYPE_15,
//  SKILL_TYPE_16,
//  // Emotion
//  SKILL_TYPE_17,
//  // Self & damage
//  SKILL_TYPE_18,
//  // warp skill
//  SKILL_TYPE_19,
//  SKILL_TYPE_20,
//};

//SKILL_1LEV_INDEX(S)					      [ S ][  1 ]
//SKILL_LEVEL(S)						        [ S ][  2 ]
//SKILL_NEED_LEVELUPPOINT(S)	      [ S ][  3 ]
//SKILL_TAB_TYPE(S)					        [ S ][  4 ]
//SKILL_TYPE( I )						        [ I ][  5 ]
//SKILL_DISTANCE( I )					      [ I ][  6 ]
//SKILL_WARP_PLANET_NO( I )		      [ I ][  6 ]
//SKILL_CLASS_FILTER( I )			      [ I ][  7 ]
//SKILL_SCOPE(S)						        [ S ][  8 ]
//SKILL_POWER(S)						        [ S ][  9 ]
//SKILL_ITEM_MAKE_NUM		            SKILL_POWER
//SKILL_HARM( I )						        [ I ][ 10 ]
//SKILL_STATE_STB( I,C )			      [ I ][ 11+C ]
//SKILL_STATE_STB1( I )				      [ I ][ 11 ]
//SKILL_STATE_STB2( I )				      [ I ][ 12 ]
//SKILL_SUCCESS_RATIO( I )		      [ I ][ 13 ]
//SKILL_DURATION( I )					      [ I ][ 14 ]
//SKILL_DAMAGE_TYPE(S)				      [ S ][ 15 ]
//SKILL_USE_PROPERTY_CNT			      2
//  SKILL_USE_PROPERTY(S,T)			      [ S ][ 16+(T)*2 ]
//  SKILL_USE_VALUE(S,T)				      [ S ][ 17+(T)*2 ]
//SKILL_RELOAD_TIME(S)				      [ S ][ 20 ]
//SKILL_INCREASE_ABILITY_CNT			  2
//  SKILL_INCREASE_ABILITY(S,T)			  [ S ][ 21+(T)*3 ]
//  SKILL_INCREASE_ABILITY_VALUE(S,T)	[ S ][ 22+(T)*3 ]
//SKILL_CHANGE_ABILITY_RATE(S,T)		[ S ][ 23+(T)*3 ]
//SKILL_WARP_ZONE_NO( S )				    [ S ][ 21 ]
//SKILL_WARP_ZONE_XPOS( S )			    [ S ][ 22 ]
//SKILL_WARP_ZONE_YPOS( S )			    [ S ][ 23 ]
//SKILL_RELOAD_TYPE(S)				      [ S ][ 27 ]
//SKILL_SUMMON_PET(S)					      [ S ][ 28 ]
//SKILL_ACTION_MODE(S)				      [ S ][ 29 ]
//SKILL_NEED_WEAPON_CNT				      5
//  SKILL_NEED_WEAPON(S,T)				  [ S ][ 30+(T) ]
//SKILL_AVAILBLE_CLASS_SET(S)		    [ S ][ 35 ]
//SKILL_AVAILBLE_UNION_CNT			    3
//  SKILL_AVAILBLE_UNION(S,T)			  [ S ][ 36+(T) ]
//SKILL_NEED_SKILL_CNT				      3
//  SKILL_NEED_SKILL_INDEX(S,T)		  [ S ][ 39+(T)*2 ]
//  SKILL_NEDD_SKILL_LEVEL(S,T)		  [ S ][ 40+(T)*2 ]
//SKILL_NEED_ABILITY_TYPE_CNT		    2
//  SKILL_NEED_ABILITY_TYPE(S,T)	  [ S ][ 45+(T)*2 ]
//  SKILL_NEED_ABILITY_VALUE(S,T)	  [ S ][ 46+(T)*2 ]
//SKILL_SCRIPT1( I )					      [ I ][ 49 ]
//SKILL_RESERVE_02( I )				      [ I ][ 50 ]
//SKILL_LEVELUP_NEED_ZULY( I )		  [ I ][ 85 ]
//SKILL_ATTRIBUTE( I )				      [ I ][ 86 ]
//SKILL_ATTRIBUTE_AVATAR				1
//SKILL_ATTRIBUTE_CART				  2
//SKILL_ATTRIBUTE_CASTLEGEAR		4

//-----------------------------------
//Graphics related
//SKILL_ICON_NO( I )					      [ I ][ 51 ]
//SKILL_ANI_CASTING(S)				      [ S ][ 52 ]
//SKILL_ANI_CASTING_SPEED(S)		    [ S ][ 53 ]
//SKILL_ANI_CASTING_REPEAT(S)		    [ S ][ 54 ]
//SKILL_ANI_CASTING_REPEAT_CNT(S)		[ S ][ 55 ]
//SKILL_CASTING_EFFECT_CNT			    4
//  SKILL_CASTING_EFFECT( I,T )			  [ I ][ 56 + (T * 3) ]
//  SKILL_CASTING_EFFECT_POINT( I,T )	[ I ][ 57 + (T * 3) ]
//  SKILL_CASTING_SOUND( I,T )			  [ I ][ 58 + (T * 3) ]
//SKILL_ANI_ACTION_TYPE(S)			    [ S ][ 68 ]
//SKILL_ANI_ACTION_SPEED(S)			    [ S ][ 69 ]
//SKILL_ANI_HIT_COUNT(S)				    [ S ][ 70 ]
//SKILL_BULLET_NO( I )				      [ I ][ 71 ]
//SKILL_BULLET_LINKED_POINT( I )		[ I ][ 72 ]
//SKILL_BULLET_FIRE_SOUND( I )		  [ I ][ 73 ]
//SKILL_HIT_EFFECT( I )				      [ I ][ 74 ]
//SKILL_HIT_EFFECT_LINKED_POINT( I )	[ I ][ 75 ]
//SKILL_HIT_SOUND( I )				        [ I ][ 76 ]
//SKILL_HIT_DUMMY_EFFECT_CNT			    2
//  SKILL_HIT_DUMMY_EFFECT( I, T )			          [ I ][ 77 + 3*T ]
//  SKILL_HIT_DUMMY_EFFECT_LINKED_POINT( I, T )		[ I ][ 78 + 3*T ]
//  SKILL_HIT_DUMMY_SOUND( I, T )					        [ I ][ 79 + 3*T ]
//SKILL_AREA_HIT_EFFECT( I )			  [ I ][ 83 ]
//SKILL_AREA_HIT_SOUND( I )			    [ I ][ 84 ]

                int.TryParse(curRow[3], out level);
                int.TryParse(curRow[4], out pointsToLevelUp);
                int.TryParse(curRow[6], out type);
                int.TryParse(curRow[7], out range);
                int.TryParse(curRow[8], out class_);
                int.TryParse(curRow[10], out power);
                script = curRow[50]; // not used by any skill
                int.TryParse(curRow[86], out zulyNeededToLevelUp);
                int.TryParse(curRow[87], out usageAttribute);

//#if OUTPUT_STB_DATA_COMMENT
//        script += "--[[ ";
//        for (var j = 0; j < dataFile.ColumnCount - 1; j++)
//        {
//          script += "COLUMN " + j+1 + " =='" + curRow[j+1] + "'\n";
//        }
//        script += "--]]\n\n";
//#endif

                skillDesc = skillDesc.Replace("\"", "\\\"");
                string sqlEntry =
                    "REPLACE into skill_db(id, name, `desc`, level, type, `range`, class_, power, script) ";
                sqlEntry += "values(" + i + ", \"" + skillName + "\", \"" + skillDesc + "\", " + (int)(level) + ", " + (int)(type) + ", " + range.ToString("G", CultureInfo.InvariantCulture) + ", " + class_ + ", " + power + ", \"" + script + "\");";

                sqlFileList.Add(sqlEntry);
            }

            var sqlFile = new System.IO.StreamWriter("srv_data\\skill_db.sql", true);

            using (sqlFile)
            {
                foreach (var itemLine in sqlFileList)
                {
                    sqlFile.WriteLine(itemLine);
                }
            }
        }
Ejemplo n.º 13
0
        private static void Convert(string inputPath, string outputPath)
        {
            MemoryStream data;

            using (var input = File.OpenRead(inputPath))
            {
                data = input.ReadToMemoryStream(input.Length);
            }

            using (data)
            {
                var magic = data.ReadValueU32();
                data.Seek(0, SeekOrigin.Begin);

                // detect type
                if (magic == 0x4C425453)
                {
                    if (outputPath == null)
                    {
                        outputPath = Path.ChangeExtension(inputPath, ".xml");
                    }

                    var stbl = new StringTableFile();
                    stbl.Deserialize(data);

                    var settings = new XmlWriterSettings();
                    settings.Indent = true;

                    using (var writer = XmlWriter.Create(outputPath, settings))
                    {
                        writer.WriteStartDocument();
                        writer.WriteStartElement("stringtable");
                        writer.WriteAttributeString("version", stbl.Version.ToString());

                        foreach (var kvp in stbl.Strings.OrderBy(kv => kv.Key))
                        {
                            writer.WriteStartElement("string");
                            writer.WriteAttributeString("id", "0x" + kvp.Key.ToString("X16"));
                            writer.WriteValue(kvp.Value);
                            writer.WriteEndElement();
                        }

                        writer.WriteEndElement();
                        writer.WriteEndDocument();
                    }
                }
                else
                {
                    if (outputPath == null)
                    {
                        outputPath = Path.ChangeExtension(inputPath, ".stbl");
                    }

                    var stbl = new StringTableFile();

                    var xml = new XPathDocument(data);
                    var nav = xml.CreateNavigator();

                    var doc = nav.SelectSingleNode("/stringtable");
                    if (doc == null)
                    {
                        throw new InvalidOperationException();
                    }
                    else
                    {
                        var strings = doc.Select("/string");
                        while (strings.MoveNext() == true)
                        {
                            var idText   = strings.Current.GetAttribute("id", "");
                            var nameText = strings.Current.GetAttribute("name", "");

                            if (string.IsNullOrWhiteSpace(idText) == true &&
                                string.IsNullOrWhiteSpace(nameText) == true)
                            {
                                throw new InvalidOperationException();
                            }

                            ulong name;
                            if (string.IsNullOrWhiteSpace(nameText) == false)
                            {
                                name = nameText.HashFNV64();
                            }
                            else
                            {
                                if (Hex.TryParseU64(idText, out name) == false)
                                {
                                    throw new InvalidOperationException();
                                }
                            }

                            if (stbl.Strings.ContainsKey(name) == false)
                            {
                                stbl.Strings[name] = strings.Current.Value;
                            }
                        }

                        using (var output = File.Create(outputPath))
                        {
                            stbl.Serialize(output);
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public void Load(string stbPath = null, string stlPath = null)
        {
            if (stbPath == null || stlPath == null)
            {
                return;
            }

            var stringFile = new StringTableFile();
            var dataFile   = new DataFile();

            Console.Write("Attempting to load \"" + stbPath + "\" and \"" + stlPath + "\" - ");

            try
            {
                dataFile.Load(stbPath);
                stringFile.Load(stlPath);
            }
            catch (FileNotFoundException e)
            {
                Console.Write("Failed!\n");
                Console.WriteLine(e);
                return;
            }

            Console.Write("Successful!\n");

            var luaList = new List <string>();
            Dictionary <string, string> luaCode = new Dictionary <string, string>();

            for (var i = 0; i < dataFile.RowCount; i++)
            {
                StringTableRow strTableRow;
                var            curRow = dataFile[i];
                try
                {
                    strTableRow = stringFile[curRow[41]];
                }
                catch (ArgumentException)
                {
                    continue;
                }

                var npcName = strTableRow.GetText();
                var npcDesc = curRow[41];

                if (npcName.Length == 0)
                {
                    continue;
                }

                int npcHeight,
                    npcWalkSpeed,
                    npcRunSpeed,
                    npcScale,
                    npcRWeapon,
                    npcLWeapon,
                    npcLevel,
                    npcHp,
                    npcAttack,
                    npcHit,
                    npcDef,
                    npcRes,
                    npcAvoid,
                    npcAttackSpd,
                    npcIsMagicDamage,
                    npcAiType,
                    npcGiveExp,
                    npcDropType,
                    npcMarkNumber,
                    npcDropMoney,
                    npcDropItem,
                    npcUnionNumber,
                    npcNeedSummonCount,
                    npcSellTab0,
                    npcSellTab1,
                    npcSellTab2,
                    npcSellTab3,
                    npcCanTarget,
                    npcAttackRange,
                    npcType,
                    npcHitMaterialType,
                    npcFaceIcon,
                    npcSummonMobType,
                    npcNormalEffectSound,
                    npcAttackSound,
                    npcHitSound,
                    npcHandHitEffect,
                    npcDeadEffect,
                    npcDieSound,
                    npcQuestType,
                    npcGlowColor,
                    npcCreateEffect,
                    npcCreateSound;

                npcHeight         = npcWalkSpeed = npcRunSpeed = npcScale = npcRWeapon = npcLWeapon = npcLevel = npcHp = npcAttack =
                    npcHit        = npcDef = npcRes = npcAvoid = npcAttackSpd = npcIsMagicDamage =
                        npcAiType = npcGiveExp = npcDropType = npcMarkNumber = npcDropMoney = npcDropItem = npcUnionNumber =
                            npcNeedSummonCount          =
                                npcSellTab0             = npcSellTab1 = npcSellTab2 = npcSellTab3 = npcCanTarget = npcAttackRange = npcType =
                                    npcHitMaterialType  = npcFaceIcon = npcSummonMobType = npcNormalEffectSound = npcAttackSound =
                                        npcHitSound     = npcHandHitEffect = npcDeadEffect =
                                            npcDieSound = npcQuestType = npcGlowColor = npcCreateEffect = npcCreateSound = 0;


                int.TryParse(curRow[03], out npcWalkSpeed);       //lua?
                int.TryParse(curRow[04], out npcRunSpeed);        //lua?
                int.TryParse(curRow[05], out npcScale);           //lua
                int.TryParse(curRow[06], out npcRWeapon);         //lua?
                int.TryParse(curRow[07], out npcLWeapon);         //lua?
                int.TryParse(curRow[08], out npcLevel);           //lua?
                int.TryParse(curRow[09], out npcHp);              //sql? lua?
                int.TryParse(curRow[10], out npcAttack);          //lua?
                int.TryParse(curRow[11], out npcHit);             //lua?
                int.TryParse(curRow[12], out npcDef);             //lua?
                int.TryParse(curRow[13], out npcRes);             //lua?
                int.TryParse(curRow[14], out npcAvoid);           //lua?
                int.TryParse(curRow[15], out npcAttackSpd);       //lua?
                int.TryParse(curRow[16], out npcIsMagicDamage);   //lua?
                int.TryParse(curRow[17], out npcAiType);          //lua
                int.TryParse(curRow[18], out npcGiveExp);         //lua
                int.TryParse(curRow[19], out npcDropType);        //lua
                int.TryParse(curRow[19], out npcMarkNumber);      // NPC icon (only used with EVO style npc boxes)
                int.TryParse(curRow[20], out npcDropMoney);       //lua

                int.TryParse(curRow[21], out npcDropItem);        //lua
                int.TryParse(curRow[21], out npcUnionNumber);     //sql
                int.TryParse(curRow[22], out npcNeedSummonCount); //lua, used for unknown...
                // This is indexes into LIST_SELL.STB
                // We need to read LIST_SELL to convert these NPC tabs
                int.TryParse(curRow[22], out npcSellTab0); //lua
                int.TryParse(curRow[23], out npcSellTab1); //lua
                int.TryParse(curRow[24], out npcSellTab2); //lua
                int.TryParse(curRow[25], out npcSellTab3); //lua

                int.TryParse(curRow[26], out npcCanTarget);
                int.TryParse(curRow[27], out npcAttackRange); //lua?
                int.TryParse(curRow[28], out npcType);        //sql?
                int.TryParse(curRow[29], out npcHitMaterialType);
                int.TryParse(curRow[30], out npcFaceIcon);    // NPC face icon (only used with EVO style npc boxes)
                int.TryParse(curRow[30], out npcSummonMobType);

                int.TryParse(curRow[31], out npcNormalEffectSound);
                int.TryParse(curRow[32], out npcAttackSound);
                int.TryParse(curRow[33], out npcHitSound);
                int.TryParse(curRow[34], out npcHandHitEffect);
                int.TryParse(curRow[35], out npcDeadEffect);
                int.TryParse(curRow[36], out npcDieSound);
                int.TryParse(curRow[39], out npcQuestType); //lua
                int.TryParse(curRow[40], out npcGlowColor);

                int.TryParse(curRow[42], out npcHeight);
                int.TryParse(curRow[43], out npcCreateEffect);
                int.TryParse(curRow[44], out npcCreateSound);

                string script = "";


                script += "registerNpc(" + i + ", {\n";
                script += "  walk_speed        = " + npcWalkSpeed.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  run_speed         = " + npcRunSpeed.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  scale             = " + npcScale.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  r_weapon          = " + npcRWeapon.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  l_weapon          = " + npcLWeapon.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  level             = " + npcLevel.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  hp                = " + npcHp.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  attack            = " + npcAttack.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  hit               = " + npcHit.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  def               = " + npcDef.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  res               = " + npcRes.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  avoid             = " + npcAvoid.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  attack_spd        = " + npcAttackSpd.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  is_magic_damage   = " + npcIsMagicDamage.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  ai_type           = " + npcAiType.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  give_exp          = " + npcGiveExp.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  drop_type         = " + npcDropType.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  drop_money        = " + npcDropMoney.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  drop_item         = " + npcDropItem.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  union_number      = " + npcUnionNumber.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  need_summon_count = " + npcNeedSummonCount.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  sell_tab0         = " + npcSellTab0.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  sell_tab1         = " + npcSellTab1.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  sell_tab2         = " + npcSellTab2.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  sell_tab3         = " + npcSellTab3.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  can_target        = " + npcCanTarget.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  attack_range      = " + npcAttackRange.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  npc_type          = " + npcType.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  hit_material_type = " + npcHitMaterialType.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  face_icon         = " + npcFaceIcon.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  summon_mob_type   = " + npcSummonMobType.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  quest_type        = " + npcQuestType.ToString("G", CultureInfo.InvariantCulture) + ",\n";
                script += "  height            = " + npcHeight.ToString("G", CultureInfo.InvariantCulture) + "\n";
                script += "});\n";

                /*
                 *      script += "npc[" + i + "] = {}\n";
                 *      script += "npc[" + i + "].walk_speed = " + npcWalkSpeed + "\n";
                 *      script += "npc[" + i + "].run_speed = " + npcRunSpeed + "\n";
                 *      script += "npc[" + i + "].scale = " + npcScale + "\n";
                 *      script += "npc[" + i + "].r_weapon = " + npcRWeapon + "\n";
                 *      script += "npc[" + i + "].l_weapon = " + npcLWeapon + "\n";
                 *      script += "npc[" + i + "].level = " + npcLevel + "\n";
                 *      script += "npc[" + i + "].hp = " + npcHp + "\n";
                 *      script += "npc[" + i + "].attack = " + npcAttack + "\n";
                 *      script += "npc[" + i + "].hit = " + npcHit + "\n";
                 *      script += "npc[" + i + "].def = " + npcDef + "\n";
                 *      script += "npc[" + i + "].res = " + npcRes + "\n";
                 *      script += "npc[" + i + "].avoid = " + npcAvoid + "\n";
                 *      script += "npc[" + i + "].attack_spd = " + npcAttackSpd + "\n";
                 *      script += "npc[" + i + "].is_magic_damage = " + npcIsMagicDamage + "\n";
                 *      script += "npc[" + i + "].ai_type = " + npcAiType + "\n";
                 *      script += "npc[" + i + "].give_exp = " + npcGiveExp + "\n";
                 *      script += "npc[" + i + "].drop_type = " + npcDropType + "\n";
                 *      script += "npc[" + i + "].drop_money = " + npcDropMoney + "\n";
                 *      script += "npc[" + i + "].drop_item = " + npcDropItem + "\n";
                 *      script += "npc[" + i + "].union_number = " + npcUnionNumber + "\n";
                 *      script += "npc[" + i + "].need_summon_count = " + npcNeedSummonCount + "\n";
                 *      script += "npc[" + i + "].sell_tab0 = " + npcSellTab0 + "\n";
                 *      script += "npc[" + i + "].sell_tab1 = " + npcSellTab1 + "\n";
                 *      script += "npc[" + i + "].sell_tab2 = " + npcSellTab2 + "\n";
                 *      script += "npc[" + i + "].sell_tab3 = " + npcSellTab3 + "\n";
                 *      script += "npc[" + i + "].can_target = " + npcCanTarget + "\n";
                 *      script += "npc[" + i + "].attack_range = " + npcAttackRange + "\n";
                 *      script += "npc[" + i + "].npc_type = " + npcType + "\n";
                 *      script += "npc[" + i + "].hit_material_type = " + npcHitMaterialType + "\n";
                 *      script += "npc[" + i + "].face_icon = " + npcFaceIcon + "\n";
                 *      script += "npc[" + i + "].summon_mob_type = " + npcSummonMobType + "\n";
                 *      script += "npc[" + i + "].quest_type = " + npcQuestType + "\n";
                 *      script += "npc[" + i + "].height = " + npcHeight + "\n";
                 *      //*/


                var luaObjFixed = npcName.ToLower().Replace(" ", "_");
                if (!luaCode.ContainsKey(luaObjFixed))
                {
                    luaCode.Add(luaObjFixed, script);
                }
                else
                {
                    string oldScript = luaCode[luaObjFixed];
                    luaCode.Remove(luaObjFixed);

                    luaCode.Add(luaObjFixed, oldScript + "\n" + script);
                }
            }

            foreach (var luaOut in luaCode)
            {
                var catagoryName = "mobs";
                if (luaOut.Key.Contains("["))
                {
                    catagoryName = "npcs";
                }
                var outFilePath = "srv_data\\scripts\\" + catagoryName + "\\ai\\" + luaOut.Key + ".lua";
                (new FileInfo(outFilePath)).Directory.Create();
                var luaFile = new System.IO.StreamWriter(outFilePath, false);
                luaList.Add("include(\"" + outFilePath + "\");\n");
                using (luaFile)
                {
                    var valueOut = luaOut.Value + @"
function OnInit(entity)
  return true
end

function OnCreate(entity)
  return true
end

function OnDelete(entity)
  return true
end

function OnDead(entity)
end

function OnDamaged(entity)
end";
                    luaFile.Write(valueOut);
                }
            }

            if (luaList.Count > 0)
            {
                var outFilePath = "srv_data\\scripts\\npc_scripts.lua";
                (new FileInfo(outFilePath)).Directory.Create();
                var luaFile = new System.IO.StreamWriter(outFilePath, true);
                using (luaFile)
                {
                    foreach (var luaObj in luaList)
                    {
                        var luaObjFixed = luaObj.Replace("srv_data\\scripts\\", "");
                        luaObjFixed = luaObjFixed.Replace("\\", "/");
                        luaFile.Write(luaObjFixed);
                    }
                }
            }
        }