Beispiel #1
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);
                }
            }
        }
Beispiel #2
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);
                    }
                }
            }
        }