csv2yaml.cpp 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "csv2yaml.hpp"
  4. #include <math.h>
  5. struct s_mob_drop_csv : s_mob_drop {
  6. std::string group_string;
  7. bool mvp;
  8. };
  9. std::unordered_map<uint16, std::vector<uint32>> mob_race2;
  10. std::map<uint32, std::vector<s_mob_drop_csv>> mob_drop;
  11. static bool mob_readdb_race2(char* fields[], int columns, int current);
  12. static bool mob_readdb_drop(char* str[], int columns, int current);
  13. static bool mob_readdb_sub(char* fields[], int columns, int current);
  14. // Skill database data to memory
  15. static void skill_txt_data(const std::string& modePath, const std::string& fixedPath) {
  16. skill_require.clear();
  17. skill_cast.clear();
  18. skill_castnodex.clear();
  19. skill_unit.clear();
  20. skill_copyable.clear();
  21. skill_nearnpc.clear();
  22. if (fileExists(modePath + "/skill_require_db.txt"))
  23. sv_readdb(modePath.c_str(), "skill_require_db.txt", ',', 34, 34, -1, skill_parse_row_requiredb, false);
  24. if (fileExists(modePath + "/skill_cast_db.txt"))
  25. sv_readdb(modePath.c_str(), "skill_cast_db.txt", ',', 7, 8, -1, skill_parse_row_castdb, false);
  26. if (fileExists(modePath + "/skill_castnodex_db.txt"))
  27. sv_readdb(modePath.c_str(), "skill_castnodex_db.txt", ',', 2, 3, -1, skill_parse_row_castnodexdb, false);
  28. if (fileExists(modePath + "/skill_unit_db.txt"))
  29. sv_readdb(modePath.c_str(), "skill_unit_db.txt", ',', 8, 8, -1, skill_parse_row_unitdb, false);
  30. if (fileExists(fixedPath + "/skill_copyable_db.txt"))
  31. sv_readdb(fixedPath.c_str(), "skill_copyable_db.txt", ',', 2, 4, -1, skill_parse_row_copyabledb, false);
  32. if (fileExists(fixedPath + "/skill_nonearnpc_db.txt"))
  33. sv_readdb(fixedPath.c_str(), "skill_nonearnpc_db.txt", ',', 2, 3, -1, skill_parse_row_nonearnpcrangedb, false);
  34. }
  35. // Item database data to memory
  36. static void item_txt_data(const std::string& modePath, const std::string& fixedPath) {
  37. item_avail.clear();
  38. item_buyingstore.clear();
  39. item_flag.clear();
  40. item_delay.clear();
  41. item_stack.clear();
  42. item_nouse.clear();
  43. item_trade.clear();
  44. if (fileExists(fixedPath + "/item_avail.txt"))
  45. sv_readdb(fixedPath.c_str(), "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail, false);
  46. if (fileExists(modePath + "/item_buyingstore.txt"))
  47. sv_readdb(modePath.c_str(), "item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore, false);
  48. if (fileExists(modePath + "/item_flag.txt"))
  49. sv_readdb(modePath.c_str(), "item_flag.txt", ',', 2, 2, -1, &itemdb_read_flag, false);
  50. if (fileExists(modePath + "/item_delay.txt"))
  51. sv_readdb(modePath.c_str(), "item_delay.txt", ',', 2, 3, -1, &itemdb_read_itemdelay, false);
  52. if (fileExists(modePath + "/item_stack.txt"))
  53. sv_readdb(modePath.c_str(), "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack, false);
  54. if (fileExists(fixedPath + "/item_nouse.txt"))
  55. sv_readdb(fixedPath.c_str(), "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse, false);
  56. if (fileExists(modePath + "/item_trade.txt"))
  57. sv_readdb(modePath.c_str(), "item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade, false);
  58. }
  59. // Mob database data to memory
  60. static void mob_txt_data(const std::string &modePath, const std::string &fixedPath) {
  61. mob_race2.clear();
  62. mob_drop.clear();
  63. if (fileExists(modePath + "/mob_race2_db.txt"))
  64. sv_readdb(modePath.c_str(), "mob_race2_db.txt", ',', 2, 100, -1, mob_readdb_race2, false);
  65. if (fileExists(modePath + "/mob_drop.txt"))
  66. sv_readdb(modePath.c_str(), "mob_drop.txt", ',', 3, 5, -1, mob_readdb_drop, false);
  67. }
  68. // Branch database data to memory
  69. static void branch_txt_data(const std::string& modePath, const std::string& fixedPath) {
  70. summon_group.clear();
  71. if (fileExists(modePath + "/mob_branch.txt"))
  72. sv_readdb(modePath.c_str(), "mob_branch.txt", ',', 4, 4, -1, mob_readdb_group, false);
  73. if (fileExists(modePath + "/mob_random_db.txt"))
  74. sv_readdb(modePath.c_str(), "mob_random_db.txt", ',', 4, 4, -1, mob_readdb_group, false);
  75. if (fileExists(modePath + "/mob_poring.txt"))
  76. sv_readdb(modePath.c_str(), "mob_poring.txt", ',', 4, 4, -1, mob_readdb_group, false);
  77. if (fileExists(modePath + "/mob_boss.txt"))
  78. sv_readdb(modePath.c_str(), "mob_boss.txt", ',', 4, 4, -1, mob_readdb_group, false);
  79. if (fileExists(fixedPath + "/mob_pouch.txt"))
  80. sv_readdb(fixedPath.c_str(), "mob_pouch.txt", ',', 4, 4, -1, mob_readdb_group, false);
  81. if (fileExists(fixedPath + "/mob_mission.txt"))
  82. sv_readdb(fixedPath.c_str(), "mob_mission.txt", ',', 4, 4, -1, mob_readdb_group, false);
  83. if (fileExists(fixedPath + "/mob_classchange.txt"))
  84. sv_readdb(fixedPath.c_str(), "mob_classchange.txt", ',', 4, 4, -1, mob_readdb_group, false);
  85. }
  86. template<typename Func>
  87. bool process( const std::string& type, uint32 version, const std::vector<std::string>& paths, const std::string& name, Func lambda, const std::string& rename = "" ){
  88. for( const std::string& path : paths ){
  89. const std::string name_ext = name + ".txt";
  90. const std::string from = path + "/" + name_ext;
  91. const std::string to = path + "/" + (rename.size() > 0 ? rename : name) + ".yml";
  92. if( fileExists( from ) ){
  93. if( !askConfirmation( "Found the file \"%s\", which requires migration to yml.\nDo you want to convert it now? (Y/N)\n", from.c_str() ) ){
  94. continue;
  95. }
  96. if (fileExists(to)) {
  97. if (!askConfirmation("The file \"%s\" already exists.\nDo you want to replace it? (Y/N)\n", to.c_str())) {
  98. continue;
  99. }
  100. }
  101. ShowNotice("Conversion process has begun.\n");
  102. std::ofstream out;
  103. body.~Emitter();
  104. new (&body) YAML::Emitter();
  105. out.open(to);
  106. if (!out.is_open()) {
  107. ShowError("Can not open file \"%s\" for writing.\n", to.c_str());
  108. return false;
  109. }
  110. prepareHeader(out, type, version, (rename.size() > 0 ? rename : name));
  111. prepareBody();
  112. if( !lambda( path, name_ext ) ){
  113. out.close();
  114. return false;
  115. }
  116. finalizeBody();
  117. out << body.c_str();
  118. // Make sure there is an empty line at the end of the file for git
  119. out << "\n";
  120. out.close();
  121. // TODO: do you want to delete?
  122. }
  123. }
  124. return true;
  125. }
  126. int do_init( int argc, char** argv ){
  127. const std::string path_db = std::string( db_path );
  128. const std::string path_db_mode = path_db + "/" + DBPATH;
  129. const std::string path_db_import = path_db + "/" + DBIMPORT + "/";
  130. // Loads required conversion constants
  131. if (fileExists(item_db.getDefaultLocation())) {
  132. item_db.load();
  133. } else {
  134. parse_item_constants_txt( ( path_db_mode + "item_db.txt" ).c_str() );
  135. parse_item_constants_txt( ( path_db_import + "item_db.txt" ).c_str() );
  136. }
  137. if (fileExists(mob_db.getDefaultLocation())) {
  138. mob_db.load();
  139. } else {
  140. sv_readdb(path_db_mode.c_str(), "mob_db.txt", ',', 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, -1, &parse_mob_constants_txt, false);
  141. sv_readdb(path_db_import.c_str(), "mob_db.txt", ',', 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, -1, &parse_mob_constants_txt, false);
  142. }
  143. if (fileExists(skill_db.getDefaultLocation())) {
  144. skill_db.load();
  145. } else {
  146. sv_readdb(path_db_mode.c_str(), "skill_db.txt", ',', 18, 18, -1, parse_skill_constants_txt, false);
  147. sv_readdb(path_db_import.c_str(), "skill_db.txt", ',', 18, 18, -1, parse_skill_constants_txt, false);
  148. }
  149. // Load constants
  150. #define export_constant_npc(a) export_constant(a)
  151. init_random_option_constants();
  152. #include "../map/script_constants.hpp"
  153. std::vector<std::string> root_paths = {
  154. path_db,
  155. path_db_mode,
  156. path_db_import
  157. };
  158. if( !process( "GUILD_SKILL_TREE_DB", 1, root_paths, "guild_skill_tree", []( const std::string& path, const std::string& name_ext ) -> bool {
  159. return sv_readdb( path.c_str(), name_ext.c_str(), ',', 2 + MAX_GUILD_SKILL_REQUIRE * 2, 2 + MAX_GUILD_SKILL_REQUIRE * 2, -1, &guild_read_guildskill_tree_db, false );
  160. } ) ){
  161. return 0;
  162. }
  163. if( !process( "PET_DB", 1, root_paths, "pet_db", []( const std::string& path, const std::string& name_ext ) -> bool {
  164. return pet_read_db( ( path + name_ext ).c_str() );
  165. } ) ){
  166. return 0;
  167. }
  168. if (!process("MAGIC_MUSHROOM_DB", 1, root_paths, "magicmushroom_db", [](const std::string &path, const std::string &name_ext) -> bool {
  169. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1, 1, -1, &skill_parse_row_magicmushroomdb, false);
  170. })) {
  171. return 0;
  172. }
  173. if (!process("ABRA_DB", 1, root_paths, "abra_db", [](const std::string& path, const std::string& name_ext) -> bool {
  174. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 3, 3, -1, &skill_parse_row_abradb, false);
  175. })) {
  176. return 0;
  177. }
  178. if (!process("READING_SPELLBOOK_DB", 1, root_paths, "spellbook_db", [](const std::string& path, const std::string& name_ext) -> bool {
  179. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 3, 3, -1, &skill_parse_row_spellbookdb, false);
  180. })) {
  181. return 0;
  182. }
  183. if (!process("MOB_AVAIL_DB", 1, root_paths, "mob_avail", [](const std::string& path, const std::string& name_ext) -> bool {
  184. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 2, 12, -1, &mob_readdb_mobavail, false);
  185. })) {
  186. return 0;
  187. }
  188. skill_txt_data( path_db_mode, path_db );
  189. if (!process("SKILL_DB", 1, { path_db_mode }, "skill_db", [](const std::string& path, const std::string& name_ext) -> bool {
  190. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 18, 18, -1, &skill_parse_row_skilldb, false);
  191. })){
  192. return 0;
  193. }
  194. skill_txt_data( path_db_import, path_db_import );
  195. if (!process("SKILL_DB", 1, { path_db_import }, "skill_db", [](const std::string& path, const std::string& name_ext) -> bool {
  196. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 18, 18, -1, &skill_parse_row_skilldb, false);
  197. })){
  198. return 0;
  199. }
  200. if (!process("QUEST_DB", 2, root_paths, "quest_db", [](const std::string &path, const std::string &name_ext) -> bool {
  201. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 3 + MAX_QUEST_OBJECTIVES * 2 + MAX_QUEST_DROPS * 3, 100, -1, &quest_read_db, false);
  202. })) {
  203. return 0;
  204. }
  205. if (!process("INSTANCE_DB", 1, root_paths, "instance_db", [](const std::string& path, const std::string& name_ext) -> bool {
  206. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 7, 7 + MAX_MAP_PER_INSTANCE, -1, &instance_readdb_sub, false);
  207. })) {
  208. return 0;
  209. }
  210. item_txt_data(path_db_mode, path_db);
  211. if (!process("ITEM_DB", 1, { path_db_mode }, "item_db", [](const std::string& path, const std::string& name_ext) -> bool {
  212. return itemdb_read_db((path + name_ext).c_str());
  213. })) {
  214. return 0;
  215. }
  216. item_txt_data(path_db_import, path_db_import);
  217. if (!process("ITEM_DB", 1, { path_db_import }, "item_db", [](const std::string& path, const std::string& name_ext) -> bool {
  218. return itemdb_read_db((path + name_ext).c_str());
  219. })) {
  220. return 0;
  221. }
  222. rand_opt_db.clear();
  223. if (!process("RANDOM_OPTION_DB", 1, root_paths, "item_randomopt_db", [](const std::string& path, const std::string& name_ext) -> bool {
  224. return itemdb_read_randomopt((path + name_ext).c_str());
  225. })) {
  226. return 0;
  227. }
  228. rand_opt_group.clear();
  229. if (!process("RANDOM_OPTION_GROUP", 1, root_paths, "item_randomopt_group", [](const std::string& path, const std::string& name_ext) -> bool {
  230. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 5, 2 + 5 * MAX_ITEM_RDM_OPT, -1, &itemdb_read_randomopt_group, false) && itemdb_randomopt_group_yaml();
  231. })) {
  232. return 0;
  233. }
  234. #ifdef RENEWAL
  235. memset( level_penalty, 0, sizeof( level_penalty ) );
  236. if (!process("PENALTY_DB", 1, { path_db_mode }, "level_penalty", [](const std::string& path, const std::string& name_ext) -> bool {
  237. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 4, 4, -1, &pc_readdb_levelpenalty, false) && pc_levelpenalty_yaml();
  238. })) {
  239. return 0;
  240. }
  241. memset( level_penalty, 0, sizeof( level_penalty ) );
  242. if (!process("PENALTY_DB", 1, { path_db_import }, "level_penalty", [](const std::string& path, const std::string& name_ext) -> bool {
  243. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 4, 4, -1, &pc_readdb_levelpenalty, false) && pc_levelpenalty_yaml();
  244. })) {
  245. return 0;
  246. }
  247. #endif
  248. mob_txt_data(path_db_mode, path_db);
  249. if (!process("MOB_DB", 2, { path_db_mode }, "mob_db", [](const std::string &path, const std::string &name_ext) -> bool {
  250. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, -1, &mob_readdb_sub, false);
  251. })) {
  252. return 0;
  253. }
  254. mob_txt_data(path_db_import, path_db_import);
  255. if (!process("MOB_DB", 2, { path_db_import }, "mob_db", [](const std::string &path, const std::string &name_ext) -> bool {
  256. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, -1, &mob_readdb_sub, false);
  257. })) {
  258. return 0;
  259. }
  260. if (!process("MOB_CHAT_DB", 1, root_paths, "mob_chat_db", [](const std::string& path, const std::string& name_ext) -> bool {
  261. return sv_readdb(path.c_str(), name_ext.c_str(), '#', 3, 3, -1, &mob_parse_row_chatdb, false);
  262. })) {
  263. return 0;
  264. }
  265. if (!process("HOMUN_EXP_DB", 1, { path_db_mode }, "exp_homun", [](const std::string &path, const std::string &name_ext) -> bool {
  266. return read_homunculus_expdb((path + name_ext).c_str());
  267. })) {
  268. return 0;
  269. }
  270. if (!process("HOMUN_EXP_DB", 1, { path_db_import }, "exp_homun", [](const std::string &path, const std::string &name_ext) -> bool {
  271. return read_homunculus_expdb((path + name_ext).c_str());
  272. })) {
  273. return 0;
  274. }
  275. branch_txt_data(path_db_mode, path_db);
  276. if (!process("MOB_SUMMONABLE_DB", 1, { path_db_mode }, "mob_branch", [](const std::string &path, const std::string &name_ext) -> bool {
  277. return mob_readdb_group_yaml();
  278. }, "mob_summon")) {
  279. return 0;
  280. }
  281. branch_txt_data(path_db_import, path_db_import);
  282. if (!process("MOB_SUMMONABLE_DB", 1, { path_db_import }, "mob_branch", [](const std::string &path, const std::string &name_ext) -> bool {
  283. return mob_readdb_group_yaml();
  284. }, "mob_summon")) {
  285. return 0;
  286. }
  287. if (!process("CREATE_ARROW_DB", 1, root_paths, "create_arrow_db", [](const std::string& path, const std::string& name_ext) -> bool {
  288. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1+2, 1+2*MAX_ARROW_RESULT, MAX_SKILL_ARROW_DB, &skill_parse_row_createarrowdb, false);
  289. })) {
  290. return 0;
  291. }
  292. if (!process("STATPOINT_DB", 1, { path_db_mode }, "statpoint", [](const std::string &path, const std::string &name_ext) -> bool {
  293. return pc_read_statsdb((path + name_ext).c_str());
  294. })) {
  295. return 0;
  296. }
  297. if (!process("STATPOINT_DB", 1, { path_db_import }, "statpoint", [](const std::string &path, const std::string &name_ext) -> bool {
  298. return pc_read_statsdb((path + name_ext).c_str());
  299. })) {
  300. return 0;
  301. }
  302. if (!process("CASTLE_DB", 1, root_paths, "castle_db", [](const std::string &path, const std::string &name_ext) -> bool {
  303. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 4, 4, -1, &guild_read_castledb, false);
  304. })) {
  305. return 0;
  306. }
  307. if (!process("GUILD_EXP_DB", 1, { path_db_mode }, "exp_guild", [](const std::string &path, const std::string &name_ext) -> bool {
  308. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1, 1, MAX_GUILDLEVEL, &exp_guild_parse_row, false);
  309. })) {
  310. return 0;
  311. }
  312. if (!process("GUILD_EXP_DB", 1, { path_db_import }, "exp_guild", [](const std::string &path, const std::string &name_ext) -> bool {
  313. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1, 1, MAX_GUILDLEVEL, &exp_guild_parse_row, false);
  314. })) {
  315. return 0;
  316. }
  317. // TODO: add implementations ;-)
  318. return 0;
  319. }
  320. void do_final(void){
  321. }
  322. // Implementation of the conversion functions
  323. // Copied and adjusted from guild.cpp
  324. // <skill id>,<max lv>,<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>
  325. static bool guild_read_guildskill_tree_db( char* split[], int columns, int current ){
  326. uint16 skill_id = (uint16)atoi(split[0]);
  327. std::string* name = util::umap_find( aegis_skillnames, skill_id );
  328. if( name == nullptr ){
  329. ShowError( "Skill name for skill id %hu is not known.\n", skill_id );
  330. return false;
  331. }
  332. body << YAML::BeginMap;
  333. body << YAML::Key << "Id" << YAML::Value << *name;
  334. body << YAML::Key << "MaxLevel" << YAML::Value << atoi(split[1]);
  335. if (atoi(split[2]) > 0) {
  336. body << YAML::Key << "Required";
  337. body << YAML::BeginSeq;
  338. for (int i = 0, j = 0; i < MAX_GUILD_SKILL_REQUIRE; i++) {
  339. uint16 required_skill_id = atoi(split[i * 2 + 2]);
  340. uint16 required_skill_level = atoi(split[i * 2 + 3]);
  341. if (required_skill_id == 0 || required_skill_level == 0) {
  342. continue;
  343. }
  344. std::string* required_name = util::umap_find(aegis_skillnames, required_skill_id);
  345. if (required_name == nullptr) {
  346. ShowError("Skill name for required skill id %hu is not known.\n", required_skill_id);
  347. return false;
  348. }
  349. body << YAML::BeginMap;
  350. body << YAML::Key << "Id" << YAML::Value << *required_name;
  351. body << YAML::Key << "Level" << YAML::Value << required_skill_level;
  352. body << YAML::EndMap;
  353. }
  354. body << YAML::EndSeq;
  355. }
  356. body << YAML::EndMap;
  357. return true;
  358. }
  359. // Copied and adjusted from pet.cpp
  360. static bool pet_read_db( const char* file ){
  361. FILE* fp = fopen( file, "r" );
  362. if( fp == nullptr ){
  363. ShowError( "can't read %s\n", file );
  364. return false;
  365. }
  366. int lines = 0;
  367. size_t entries = 0;
  368. char line[1024];
  369. while( fgets( line, sizeof(line), fp ) ) {
  370. char *str[22], *p;
  371. unsigned k;
  372. lines++;
  373. if(line[0] == '/' && line[1] == '/')
  374. continue;
  375. memset(str, 0, sizeof(str));
  376. p = line;
  377. while( ISSPACE(*p) )
  378. ++p;
  379. if( *p == '\0' )
  380. continue; // empty line
  381. for( k = 0; k < 20; ++k ) {
  382. str[k] = p;
  383. p = strchr(p,',');
  384. if( p == NULL )
  385. break; // comma not found
  386. *p = '\0';
  387. ++p;
  388. }
  389. if( p == NULL ) {
  390. ShowError("read_petdb: Insufficient columns in line %d, skipping.\n", lines);
  391. continue;
  392. }
  393. // Pet Script
  394. if( *p != '{' ) {
  395. ShowError("read_petdb: Invalid format (Pet Script column) in line %d, skipping.\n", lines);
  396. continue;
  397. }
  398. str[20] = p;
  399. p = strstr(p+1,"},");
  400. if( p == NULL ) {
  401. ShowError("read_petdb: Invalid format (Pet Script column) in line %d, skipping.\n", lines);
  402. continue;
  403. }
  404. p[1] = '\0';
  405. p += 2;
  406. // Equip Script
  407. if( *p != '{' ) {
  408. ShowError("read_petdb: Invalid format (Equip Script column) in line %d, skipping.\n", lines);
  409. continue;
  410. }
  411. str[21] = p;
  412. uint16 mob_id = atoi( str[0] );
  413. std::string* mob_name = util::umap_find( aegis_mobnames, mob_id );
  414. if( mob_name == nullptr ){
  415. ShowWarning( "pet_db reading: Invalid mob-class %hu, pet not read.\n", mob_id );
  416. continue;
  417. }
  418. body << YAML::BeginMap;
  419. body << YAML::Key << "Mob" << YAML::Value << *mob_name;
  420. t_itemid tame_item_id = strtoul( str[3], nullptr, 10 );
  421. if( tame_item_id > 0 ){
  422. std::string* tame_item_name = util::umap_find( aegis_itemnames, tame_item_id );
  423. if( tame_item_name == nullptr ){
  424. ShowError( "Item name for item id %u is not known.\n", tame_item_id );
  425. return false;
  426. }
  427. body << YAML::Key << "TameItem" << YAML::Value << *tame_item_name;
  428. }
  429. t_itemid egg_item_id = strtoul( str[4], nullptr, 10 );
  430. std::string* egg_item_name = util::umap_find( aegis_itemnames, egg_item_id );
  431. if( egg_item_name == nullptr ){
  432. ShowError( "Item name for item id %u is not known.\n", egg_item_id );
  433. return false;
  434. }
  435. body << YAML::Key << "EggItem" << YAML::Value << *egg_item_name;
  436. t_itemid equip_item_id = strtoul( str[5], nullptr, 10 );
  437. if( equip_item_id > 0 ){
  438. std::string* equip_item_name = util::umap_find( aegis_itemnames, equip_item_id );
  439. if( equip_item_name == nullptr ){
  440. ShowError( "Item name for item id %u is not known.\n", equip_item_id );
  441. return false;
  442. }
  443. body << YAML::Key << "EquipItem" << YAML::Value << *equip_item_name;
  444. }
  445. t_itemid food_item_id = strtoul( str[6], nullptr, 10 );
  446. if( food_item_id > 0 ){
  447. std::string* food_item_name = util::umap_find( aegis_itemnames, food_item_id );
  448. if( food_item_name == nullptr ){
  449. ShowError( "Item name for item id %u is not known.\n", food_item_id );
  450. return false;
  451. }
  452. body << YAML::Key << "FoodItem" << YAML::Value << *food_item_name;
  453. }
  454. body << YAML::Key << "Fullness" << YAML::Value << atoi(str[7]);
  455. // Default: 60
  456. if( atoi( str[8] ) != 60 ){
  457. body << YAML::Key << "HungryDelay" << YAML::Value << atoi(str[8]);
  458. }
  459. // Default: 250
  460. if( atoi( str[11] ) != 250 ){
  461. body << YAML::Key << "IntimacyStart" << YAML::Value << atoi(str[11]);
  462. }
  463. body << YAML::Key << "IntimacyFed" << YAML::Value << atoi(str[9]);
  464. // Default: -100
  465. if( atoi( str[10] ) != 100 ){
  466. body << YAML::Key << "IntimacyOverfed" << YAML::Value << -atoi(str[10]);
  467. }
  468. // pet_hungry_friendly_decrease battle_conf
  469. //body << YAML::Key << "IntimacyHungry" << YAML::Value << -5;
  470. // Default: -20
  471. if( atoi( str[12] ) != 20 ){
  472. body << YAML::Key << "IntimacyOwnerDie" << YAML::Value << -atoi(str[12]);
  473. }
  474. body << YAML::Key << "CaptureRate" << YAML::Value << atoi(str[13]);
  475. // Default: true
  476. if( atoi( str[15] ) == 0 ){
  477. body << YAML::Key << "SpecialPerformance" << YAML::Value << "false";
  478. }
  479. body << YAML::Key << "AttackRate" << YAML::Value << atoi(str[17]);
  480. body << YAML::Key << "RetaliateRate" << YAML::Value << atoi(str[18]);
  481. body << YAML::Key << "ChangeTargetRate" << YAML::Value << atoi(str[19]);
  482. if( *str[21] ){
  483. body << YAML::Key << "Script" << YAML::Value << YAML::Literal << str[21];
  484. }
  485. if( *str[20] ){
  486. body << YAML::Key << "SupportScript" << YAML::Value << YAML::Literal << str[20];
  487. }
  488. body << YAML::EndMap;
  489. entries++;
  490. }
  491. fclose(fp);
  492. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' pets in '" CL_WHITE "%s" CL_RESET "'.\n", entries, file );
  493. return true;
  494. }
  495. // Copied and adjusted from skill.cpp
  496. static bool skill_parse_row_magicmushroomdb(char *split[], int column, int current)
  497. {
  498. uint16 skill_id = atoi(split[0]);
  499. std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
  500. if (skill_name == nullptr) {
  501. ShowError("Skill name for Magic Mushroom skill ID %hu is not known.\n", skill_id);
  502. return false;
  503. }
  504. body << YAML::BeginMap;
  505. body << YAML::Key << "Skill" << YAML::Value << *skill_name;
  506. body << YAML::EndMap;
  507. return true;
  508. }
  509. // Copied and adjusted from skill.cpp
  510. static bool skill_parse_row_abradb(char* split[], int columns, int current)
  511. {
  512. uint16 skill_id = atoi(split[0]);
  513. std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
  514. if (skill_name == nullptr) {
  515. ShowError("Skill name for Abra skill ID %hu is not known.\n", skill_id);
  516. return false;
  517. }
  518. body << YAML::BeginMap;
  519. body << YAML::Key << "Skill" << YAML::Value << *skill_name;
  520. int arr[MAX_SKILL_LEVEL];
  521. int arr_size = skill_split_atoi(split[2], arr);
  522. if (arr_size == 1) {
  523. if (arr[0] != 500)
  524. body << YAML::Key << "Probability" << YAML::Value << arr[0];
  525. } else {
  526. body << YAML::Key << "Probability";
  527. body << YAML::BeginSeq;
  528. for (int i = 0; i < arr_size; i++) {
  529. if (arr[i] > 0) {
  530. body << YAML::BeginMap;
  531. body << YAML::Key << "Level" << YAML::Value << i + 1;
  532. body << YAML::Key << "Probability" << YAML::Value << arr[i];
  533. body << YAML::EndMap;
  534. }
  535. }
  536. body << YAML::EndSeq;
  537. }
  538. body << YAML::EndMap;
  539. return true;
  540. }
  541. // Copied and adjusted from skill.cpp
  542. static bool skill_parse_row_spellbookdb(char* split[], int columns, int current)
  543. {
  544. uint16 skill_id = atoi(split[0]);
  545. std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
  546. if (skill_name == nullptr) {
  547. ShowError("Skill name for Spell Book skill ID %hu is not known.\n", skill_id);
  548. return false;
  549. }
  550. t_itemid nameid = strtoul(split[2], nullptr, 10);
  551. std::string *book_name = util::umap_find(aegis_itemnames, nameid);
  552. if (book_name == nullptr) {
  553. ShowError("Book name for item ID %u is not known.\n", nameid);
  554. return false;
  555. }
  556. body << YAML::BeginMap;
  557. body << YAML::Key << "Skill" << YAML::Value << *skill_name;
  558. body << YAML::Key << "Book" << YAML::Value << *book_name;
  559. body << YAML::Key << "PreservePoints" << YAML::Value << atoi(split[1]);
  560. body << YAML::EndMap;
  561. return true;
  562. }
  563. // Copied and adjusted from mob.cpp
  564. static bool mob_readdb_mobavail(char* str[], int columns, int current) {
  565. uint16 mob_id = atoi(str[0]);
  566. std::string *mob_name = util::umap_find(aegis_mobnames, mob_id);
  567. if (mob_name == nullptr) {
  568. ShowWarning("mob_avail reading: Invalid mob-class %hu, Mob not read.\n", mob_id);
  569. return false;
  570. }
  571. body << YAML::BeginMap;
  572. body << YAML::Key << "Mob" << YAML::Value << *mob_name;
  573. uint16 sprite_id = atoi(str[1]);
  574. std::string *sprite_name = util::umap_find(aegis_mobnames, sprite_id);
  575. if (sprite_name == nullptr) {
  576. char *sprite = const_cast<char *>(constant_lookup(sprite_id, "JOB_"));
  577. if (sprite == nullptr) {
  578. sprite = const_cast<char *>(constant_lookup(sprite_id, "JT_"));
  579. if (sprite == nullptr) {
  580. ShowError("Sprite name for id %d is not known.\n", sprite_id);
  581. return false;
  582. }
  583. sprite += 3; // Strip JT_ here because the script engine doesn't send this prefix for NPC.
  584. body << YAML::Key << "Sprite" << YAML::Value << sprite;
  585. } else
  586. body << YAML::Key << "Sprite" << YAML::Value << sprite;
  587. } else
  588. body << YAML::Key << "Sprite" << YAML::Value << *sprite_name;
  589. if (columns == 12) {
  590. body << YAML::Key << "Sex" << YAML::Value << (atoi(str[2]) ? "Male" : "Female");
  591. if (atoi(str[3]) != 0)
  592. body << YAML::Key << "HairStyle" << YAML::Value << atoi(str[3]);
  593. if (atoi(str[4]) != 0)
  594. body << YAML::Key << "HairColor" << YAML::Value << atoi(str[4]);
  595. if (atoi(str[11]) != 0)
  596. body << YAML::Key << "ClothColor" << YAML::Value << atoi(str[11]);
  597. if (strtoul(str[5], nullptr, 10) != 0) {
  598. t_itemid weapon_item_id = strtoul( str[5], nullptr, 10 );
  599. std::string *weapon_item_name = util::umap_find(aegis_itemnames, weapon_item_id);
  600. if (weapon_item_name == nullptr) {
  601. ShowError("Item name for item ID %u (weapon) is not known.\n", weapon_item_id);
  602. return false;
  603. }
  604. body << YAML::Key << "Weapon" << YAML::Value << *weapon_item_name;
  605. }
  606. if (strtoul(str[6], nullptr, 10) != 0) {
  607. t_itemid shield_item_id = strtoul( str[6], nullptr, 10 );
  608. std::string *shield_item_name = util::umap_find(aegis_itemnames, shield_item_id);
  609. if (shield_item_name == nullptr) {
  610. ShowError("Item name for item ID %u (shield) is not known.\n", shield_item_id);
  611. return false;
  612. }
  613. body << YAML::Key << "Shield" << YAML::Value << *shield_item_name;
  614. }
  615. if (strtoul(str[7], nullptr, 10) != 0) {
  616. t_itemid *headtop_item_id = util::umap_find(aegis_itemviewid, (uint32)strtoul(str[7], nullptr, 10));
  617. if (headtop_item_id == nullptr) {
  618. ShowError("Item ID for view ID %u (head top) is not known.\n", strtoul(str[7], nullptr, 10));
  619. return false;
  620. }
  621. std::string *headtop_item_name = util::umap_find(aegis_itemnames, *headtop_item_id);
  622. if (headtop_item_name == nullptr) {
  623. ShowError("Item name for item ID %u (head top) is not known.\n", *headtop_item_id);
  624. return false;
  625. }
  626. body << YAML::Key << "HeadTop" << YAML::Value << *headtop_item_name;
  627. }
  628. if (strtoul(str[8], nullptr, 10) != 0) {
  629. t_itemid *headmid_item_id = util::umap_find(aegis_itemviewid, (uint32)strtoul(str[8], nullptr, 10));
  630. if (headmid_item_id == nullptr) {
  631. ShowError("Item ID for view ID %u (head mid) is not known.\n", strtoul(str[8], nullptr, 10));
  632. return false;
  633. }
  634. std::string *headmid_item_name = util::umap_find(aegis_itemnames, *headmid_item_id);
  635. if (headmid_item_name == nullptr) {
  636. ShowError("Item name for item ID %u (head mid) is not known.\n", *headmid_item_id);
  637. return false;
  638. }
  639. body << YAML::Key << "HeadMid" << YAML::Value << *headmid_item_name;
  640. }
  641. if (strtoul(str[9], nullptr, 10) != 0) {
  642. t_itemid *headlow_item_id = util::umap_find(aegis_itemviewid, (uint32)strtoul(str[9], nullptr, 10));
  643. if (headlow_item_id == nullptr) {
  644. ShowError("Item ID for view ID %u (head low) is not known.\n", strtoul(str[9], nullptr, 10));
  645. return false;
  646. }
  647. std::string *headlow_item_name = util::umap_find(aegis_itemnames, *headlow_item_id);
  648. if (headlow_item_name == nullptr) {
  649. ShowError("Item name for item ID %u (head low) is not known.\n", *headlow_item_id);
  650. return false;
  651. }
  652. body << YAML::Key << "HeadLow" << YAML::Value << *headlow_item_name;
  653. }
  654. if (atoi(str[10]) != 0) {
  655. uint32 options = atoi(str[10]);
  656. body << YAML::Key << "Options";
  657. body << YAML::BeginMap;
  658. while (options > OPTION_NOTHING && options <= OPTION_SUMMER2) {
  659. if (options & OPTION_SIGHT) {
  660. body << YAML::Key << "Sight" << YAML::Value << "true";
  661. options &= ~OPTION_SIGHT;
  662. } else if (options & OPTION_CART1) {
  663. body << YAML::Key << "Cart1" << YAML::Value << "true";
  664. options &= ~OPTION_CART1;
  665. } else if (options & OPTION_FALCON) {
  666. body << YAML::Key << "Falcon" << YAML::Value << "true";
  667. options &= ~OPTION_FALCON;
  668. } else if (options & OPTION_RIDING) {
  669. body << YAML::Key << "Riding" << YAML::Value << "true";
  670. options &= ~OPTION_RIDING;
  671. } else if (options & OPTION_CART2) {
  672. body << YAML::Key << "Cart2" << YAML::Value << "true";
  673. options &= ~OPTION_CART2;
  674. } else if (options & OPTION_CART3) {
  675. body << YAML::Key << "Cart2" << YAML::Value << "true";
  676. options &= ~OPTION_CART3;
  677. } else if (options & OPTION_CART4) {
  678. body << YAML::Key << "Cart4" << YAML::Value << "true";
  679. options &= ~OPTION_CART4;
  680. } else if (options & OPTION_CART5) {
  681. body << YAML::Key << "Cart5" << YAML::Value << "true";
  682. options &= ~OPTION_CART5;
  683. } else if (options & OPTION_ORCISH) {
  684. body << YAML::Key << "Orcish" << YAML::Value << "true";
  685. options &= ~OPTION_ORCISH;
  686. } else if (options & OPTION_WEDDING) {
  687. body << YAML::Key << "Wedding" << YAML::Value << "true";
  688. options &= ~OPTION_WEDDING;
  689. } else if (options & OPTION_RUWACH) {
  690. body << YAML::Key << "Ruwach" << YAML::Value << "true";
  691. options &= ~OPTION_RUWACH;
  692. } else if (options & OPTION_FLYING) {
  693. body << YAML::Key << "Flying" << YAML::Value << "true";
  694. options &= ~OPTION_FLYING;
  695. } else if (options & OPTION_XMAS) {
  696. body << YAML::Key << "Xmas" << YAML::Value << "true";
  697. options &= ~OPTION_XMAS;
  698. } else if (options & OPTION_TRANSFORM) {
  699. body << YAML::Key << "Transform" << YAML::Value << "true";
  700. options &= ~OPTION_TRANSFORM;
  701. } else if (options & OPTION_SUMMER) {
  702. body << YAML::Key << "Summer" << YAML::Value << "true";
  703. options &= ~OPTION_SUMMER;
  704. } else if (options & OPTION_DRAGON1) {
  705. body << YAML::Key << "Dragon1" << YAML::Value << "true";
  706. options &= ~OPTION_DRAGON1;
  707. } else if (options & OPTION_WUG) {
  708. body << YAML::Key << "Wug" << YAML::Value << "true";
  709. options &= ~OPTION_WUG;
  710. } else if (options & OPTION_WUGRIDER) {
  711. body << YAML::Key << "WugRider" << YAML::Value << "true";
  712. options &= ~OPTION_WUGRIDER;
  713. } else if (options & OPTION_MADOGEAR) {
  714. body << YAML::Key << "MadoGear" << YAML::Value << "true";
  715. options &= ~OPTION_MADOGEAR;
  716. } else if (options & OPTION_DRAGON2) {
  717. body << YAML::Key << "Dragon2" << YAML::Value << "true";
  718. options &= ~OPTION_DRAGON2;
  719. } else if (options & OPTION_DRAGON3) {
  720. body << YAML::Key << "Dragon3" << YAML::Value << "true";
  721. options &= ~OPTION_DRAGON3;
  722. } else if (options & OPTION_DRAGON4) {
  723. body << YAML::Key << "Dragon4" << YAML::Value << "true";
  724. options &= ~OPTION_DRAGON4;
  725. } else if (options & OPTION_DRAGON5) {
  726. body << YAML::Key << "Dragon5" << YAML::Value << "true";
  727. options &= ~OPTION_DRAGON5;
  728. } else if (options & OPTION_HANBOK) {
  729. body << YAML::Key << "Hanbok" << YAML::Value << "true";
  730. options &= ~OPTION_HANBOK;
  731. } else if (options & OPTION_OKTOBERFEST) {
  732. body << YAML::Key << "Oktoberfest" << YAML::Value << "true";
  733. options &= ~OPTION_OKTOBERFEST;
  734. } else if (options & OPTION_SUMMER2) {
  735. body << YAML::Key << "Summer2" << YAML::Value << "true";
  736. options &= ~OPTION_SUMMER2;
  737. }
  738. }
  739. body << YAML::EndMap;
  740. }
  741. } else if (columns == 3) {
  742. if (atoi(str[5]) != 0) {
  743. t_itemid peteq_item_id = strtoul( str[5], nullptr, 10 );
  744. std::string *peteq_item_name = util::umap_find(aegis_itemnames, peteq_item_id);
  745. if (peteq_item_name == nullptr) {
  746. ShowError("Item name for item ID %u (pet equip) is not known.\n", peteq_item_id);
  747. return false;
  748. }
  749. body << YAML::Key << "PetEquip" << YAML::Value << *peteq_item_name;
  750. }
  751. }
  752. body << YAML::EndMap;
  753. return true;
  754. }
  755. // skill_db.yml function
  756. //----------------------
  757. static bool skill_parse_row_requiredb(char* split[], int columns, int current)
  758. {
  759. s_skill_require entry = {};
  760. skill_split_atoi(split[1], entry.hp);
  761. skill_split_atoi(split[2], entry.mhp);
  762. skill_split_atoi(split[3], entry.sp);
  763. skill_split_atoi(split[4], entry.hp_rate);
  764. skill_split_atoi(split[5], entry.sp_rate);
  765. skill_split_atoi(split[6], entry.zeny);
  766. char *p;
  767. p = split[7];
  768. while (p) {
  769. int l = atoi(p);
  770. if (l == 99) { // Any weapon
  771. entry.weapon = 0;
  772. break;
  773. } else
  774. entry.weapon |= 1 << l;
  775. p = strchr(p, ':');
  776. if (!p)
  777. break;
  778. p++;
  779. }
  780. p = split[8];
  781. while (p) {
  782. int l = atoi(p);
  783. if (l == 99) { // Any ammo type
  784. entry.ammo = AMMO_TYPE_ALL;
  785. break;
  786. } else if (l) // 0 stands for no requirement
  787. entry.ammo |= 1 << l;
  788. p = strchr(p, ':');
  789. if (!p)
  790. break;
  791. p++;
  792. }
  793. skill_split_atoi(split[9], entry.ammo_qty);
  794. if (strcmpi(split[10], "hidden") == 0) entry.state = ST_HIDDEN;
  795. else if (strcmpi(split[10], "riding") == 0) entry.state = ST_RIDING;
  796. else if (strcmpi(split[10], "falcon") == 0) entry.state = ST_FALCON;
  797. else if (strcmpi(split[10], "cart") == 0) entry.state = ST_CART;
  798. else if (strcmpi(split[10], "shield") == 0) entry.state = ST_SHIELD;
  799. else if (strcmpi(split[10], "recover_weight_rate") == 0) entry.state = ST_RECOVER_WEIGHT_RATE;
  800. else if (strcmpi(split[10], "move_enable") == 0) entry.state = ST_MOVE_ENABLE;
  801. else if (strcmpi(split[10], "water") == 0) entry.state = ST_WATER;
  802. else if (strcmpi(split[10], "dragon") == 0) entry.state = ST_RIDINGDRAGON;
  803. else if (strcmpi(split[10], "warg") == 0) entry.state = ST_WUG;
  804. else if (strcmpi(split[10], "ridingwarg") == 0) entry.state = ST_RIDINGWUG;
  805. else if (strcmpi(split[10], "mado") == 0) entry.state = ST_MADO;
  806. else if (strcmpi(split[10], "elementalspirit") == 0) entry.state = ST_ELEMENTALSPIRIT;
  807. else if (strcmpi(split[10], "elementalspirit2") == 0) entry.state = ST_ELEMENTALSPIRIT2;
  808. else if (strcmpi(split[10], "peco") == 0) entry.state = ST_PECO;
  809. else if (strcmpi(split[10], "sunstance") == 0) entry.state = ST_SUNSTANCE;
  810. else if (strcmpi(split[10], "moonstance") == 0) entry.state = ST_MOONSTANCE;
  811. else if (strcmpi(split[10], "starstance") == 0) entry.state = ST_STARSTANCE;
  812. else if (strcmpi(split[10], "universestance") == 0) entry.state = ST_UNIVERSESTANCE;
  813. else entry.state = ST_NONE; // Unknown or no state
  814. trim(split[11]);
  815. if (split[11][0] != '\0' || atoi(split[11])) {
  816. int64 require[MAX_SKILL_STATUS_REQUIRE];
  817. int32 count;
  818. if ((count = skill_split_atoi2(split[11], require, ":", SC_STONE, ARRAYLENGTH(require)))) {
  819. for (int i = 0; i < count; i++) {
  820. entry.status.push_back((sc_type)require[i]);
  821. }
  822. }
  823. }
  824. skill_split_atoi(split[12], entry.spiritball);
  825. for (int i = 0; i < MAX_SKILL_ITEM_REQUIRE; i++) {
  826. if (atoi(split[13 + 2 * i]) > 0) {
  827. t_itemid item_id = strtoul( split[13 + 2 * i], nullptr, 10 );
  828. std::string *item_name = util::umap_find(aegis_itemnames, item_id);
  829. if (item_name == nullptr) {
  830. ShowError("Item name for item id %u is not known.\n", item_id);
  831. return false;
  832. }
  833. entry.itemid[i] = item_id;
  834. entry.amount[i] = atoi(split[14 + 2 * i]);
  835. }
  836. }
  837. trim(split[33]);
  838. if (split[33][0] != '\0' || atoi(split[33])) {
  839. int64 require[MAX_SKILL_EQUIP_REQUIRE];
  840. int32 count;
  841. if ((count = skill_split_atoi2(split[33], require, ":", 500, ARRAYLENGTH(require)))) {
  842. for (int i = 0; i < count; i++) {
  843. if (require[i] > 0)
  844. entry.eqItem.push_back(static_cast<int32>(require[i]));
  845. }
  846. }
  847. }
  848. skill_require.insert({ atoi(split[0]), entry });
  849. return true;
  850. }
  851. // skill_db.yml function
  852. //----------------------
  853. static bool skill_parse_row_castdb(char* split[], int columns, int current)
  854. {
  855. s_skill_db entry = {};
  856. skill_split_atoi(split[1], entry.cast);
  857. skill_split_atoi(split[2], entry.delay);
  858. skill_split_atoi(split[3], entry.walkdelay);
  859. skill_split_atoi(split[4], entry.upkeep_time);
  860. skill_split_atoi(split[5], entry.upkeep_time2);
  861. skill_split_atoi(split[6], entry.cooldown);
  862. #ifdef RENEWAL_CAST
  863. skill_split_atoi(split[7], (int *)entry.fixed_cast);
  864. #endif
  865. skill_cast.insert({ atoi(split[0]), entry });
  866. return true;
  867. }
  868. // skill_db.yml function
  869. //----------------------
  870. static bool skill_parse_row_castnodexdb(char* split[], int columns, int current)
  871. {
  872. s_skill_db entry = {};
  873. entry.castnodex = atoi(split[1]);
  874. if (split[2]) // optional column
  875. entry.delaynodex = atoi(split[2]);
  876. skill_castnodex.insert({ atoi(split[0]), entry });
  877. return true;
  878. }
  879. // skill_db.yml function
  880. //----------------------
  881. static bool skill_parse_row_unitdb(char* split[], int columns, int current)
  882. {
  883. s_skill_unit_csv entry = {};
  884. entry.unit_id = (uint16)strtol(split[1], NULL, 16);
  885. entry.unit_id2 = (uint16)strtol(split[2], NULL, 16);
  886. skill_split_atoi(split[3], entry.unit_layout_type);
  887. skill_split_atoi(split[4], entry.unit_range);
  888. entry.unit_interval = atoi(split[5]);
  889. entry.target_str = trim(split[6]);
  890. entry.unit_flag_csv = strtol(split[7], NULL, 16);
  891. skill_unit.insert({ atoi(split[0]), entry });
  892. return true;
  893. }
  894. // skill_db.yml function
  895. //----------------------
  896. static bool skill_parse_row_copyabledb(char* split[], int column, int current)
  897. {
  898. s_skill_copyable entry = {};
  899. int skill_id = -1;
  900. trim(split[0]);
  901. if (ISDIGIT(split[0][0]))
  902. skill_id = atoi(split[0]);
  903. else {
  904. for (const auto &it : aegis_skillnames) {
  905. if (it.second == split[0])
  906. skill_id = it.first;
  907. }
  908. if (skill_id == -1) {
  909. ShowError("Skill %s is unknown.\n", split[0]);
  910. return false;
  911. }
  912. }
  913. entry.option = atoi(split[1]);
  914. entry.req_opt = cap_value(atoi(split[3]), 0, (0x2000) - 1);
  915. skill_copyable.insert({ skill_id, entry });
  916. return true;
  917. }
  918. // skill_db.yml function
  919. //----------------------
  920. static bool skill_parse_row_nonearnpcrangedb(char* split[], int column, int current)
  921. {
  922. s_skill_db entry = {};
  923. int skill_id = -1;
  924. trim(split[0]);
  925. if (ISDIGIT(split[0][0]))
  926. skill_id = atoi(split[0]);
  927. else {
  928. for (const auto &it : aegis_skillnames) {
  929. if (it.second == split[0])
  930. skill_id = it.first;
  931. }
  932. if (skill_id == -1) {
  933. ShowError("Skill %s is unknown.\n", split[0]);
  934. return false;
  935. }
  936. }
  937. entry.unit_nonearnpc_range = max(atoi(split[1]), 0);
  938. entry.unit_nonearnpc_type = (atoi(split[2])) ? cap_value(atoi(split[2]), 1, 15) : 15;
  939. skill_nearnpc.insert({ skill_id, entry });
  940. return true;
  941. }
  942. // Copied and adjusted from skill.cpp
  943. static bool skill_parse_row_skilldb(char* split[], int columns, int current) {
  944. int arr[MAX_SKILL_LEVEL], arr_size, skill_id = atoi(split[0]);
  945. body << YAML::BeginMap;
  946. body << YAML::Key << "Id" << YAML::Value << skill_id;
  947. body << YAML::Key << "Name" << YAML::Value << trim(split[16]);
  948. body << YAML::Key << "Description" << YAML::Value << trim(split[17]);
  949. body << YAML::Key << "MaxLevel" << YAML::Value << atoi(split[7]);
  950. if (strcmpi(split[13], "weapon") == 0)
  951. body << YAML::Key << "Type" << YAML::Value << "Weapon";
  952. else if (strcmpi(split[13], "magic") == 0)
  953. body << YAML::Key << "Type" << YAML::Value << "Magic";
  954. else if (strcmpi(split[13], "misc") == 0)
  955. body << YAML::Key << "Type" << YAML::Value << "Misc";
  956. std::string constant;
  957. if (atoi(split[3]) != 0) {
  958. constant = constant_lookup(atoi(split[3]), "INF_");
  959. constant.erase(0, 4);
  960. constant.erase(constant.size() - 6);
  961. body << YAML::Key << "TargetType" << YAML::Value << name2Upper(constant);
  962. }
  963. uint64 nk_val = strtol(split[5], NULL, 0);
  964. if (nk_val) {
  965. body << YAML::Key << "DamageFlags";
  966. body << YAML::BeginMap;
  967. if (nk_val & 0x1)
  968. body << YAML::Key << "NoDamage" << YAML::Value << "true";
  969. if (nk_val & 0x2)
  970. body << YAML::Key << "Splash" << YAML::Value << "true";
  971. if (nk_val & 0x4)
  972. body << YAML::Key << "SplashSplit" << YAML::Value << "true";
  973. if (nk_val & 0x8)
  974. body << YAML::Key << "IgnoreAtkCard" << YAML::Value << "true";
  975. if (nk_val & 0x10)
  976. body << YAML::Key << "IgnoreElement" << YAML::Value << "true";
  977. if (nk_val & 0x20)
  978. body << YAML::Key << "IgnoreDefense" << YAML::Value << "true";
  979. if (nk_val & 0x40)
  980. body << YAML::Key << "IgnoreFlee" << YAML::Value << "true";
  981. if (nk_val & 0x80)
  982. body << YAML::Key << "IgnoreDefCard" << YAML::Value << "true";
  983. if (nk_val & 0x100)
  984. body << YAML::Key << "Critical" << YAML::Value << "true";
  985. body << YAML::EndMap;
  986. }
  987. uint64 inf2_val = strtol(split[11], nullptr, 0);
  988. uint64 inf3_val = strtol(split[15], nullptr, 0);
  989. if (inf2_val || inf3_val) {
  990. body << YAML::Key << "Flags";
  991. body << YAML::BeginMap;
  992. if (inf2_val & 0x1)
  993. body << YAML::Key << "IsQuest" << YAML::Value << "true";
  994. if (inf2_val & 0x2)
  995. body << YAML::Key << "IsNpc" << YAML::Value << "true";
  996. if (inf2_val & 0x4)
  997. body << YAML::Key << "IsWedding" << YAML::Value << "true";
  998. if (inf2_val & 0x8)
  999. body << YAML::Key << "IsSpirit" << YAML::Value << "true";
  1000. if (inf2_val & 0x10)
  1001. body << YAML::Key << "IsGuild" << YAML::Value << "true";
  1002. if (inf2_val & 0x20)
  1003. body << YAML::Key << "IsSong" << YAML::Value << "true";
  1004. if (inf2_val & 0x40)
  1005. body << YAML::Key << "IsEnsemble" << YAML::Value << "true";
  1006. if (inf2_val & 0x80)
  1007. body << YAML::Key << "IsTrap" << YAML::Value << "true";
  1008. if (inf2_val & 0x100)
  1009. body << YAML::Key << "TargetSelf" << YAML::Value << "true";
  1010. if (inf2_val & 0x200)
  1011. body << YAML::Key << "NoTargetSelf" << YAML::Value << "true";
  1012. if (inf2_val & 0x400)
  1013. body << YAML::Key << "PartyOnly" << YAML::Value << "true";
  1014. if (inf2_val & 0x800)
  1015. body << YAML::Key << "GuildOnly" << YAML::Value << "true";
  1016. if (inf2_val & 0x1000)
  1017. body << YAML::Key << "NoTargetEnemy" << YAML::Value << "true";
  1018. if (inf2_val & 0x2000)
  1019. body << YAML::Key << "IsAutoShadowSpell" << YAML::Value << "true";
  1020. if (inf2_val & 0x4000)
  1021. body << YAML::Key << "IsChorus" << YAML::Value << "true";
  1022. if (inf2_val & 0x8000)
  1023. body << YAML::Key << "IgnoreBgReduction" << YAML::Value << "true";
  1024. if (inf2_val & 0x10000)
  1025. body << YAML::Key << "IgnoreGvgReduction" << YAML::Value << "true";
  1026. if (inf2_val & 0x20000)
  1027. body << YAML::Key << "DisableNearNpc" << YAML::Value << "true";
  1028. if (inf2_val & 0x40000)
  1029. body << YAML::Key << "TargetTrap" << YAML::Value << "true"; // ?
  1030. if (inf3_val & 0x1)
  1031. body << YAML::Key << "IgnoreLandProtector" << YAML::Value << "true";
  1032. if (inf3_val & 0x4)
  1033. body << YAML::Key << "AllowWhenHidden" << YAML::Value << "true";
  1034. if (inf3_val & 0x8)
  1035. body << YAML::Key << "AllowWhenPerforming" << YAML::Value << "true";
  1036. if (inf3_val & 0x10)
  1037. body << YAML::Key << "TargetEmperium" << YAML::Value << "true";
  1038. if (inf3_val & 0x20)
  1039. body << YAML::Key << "IgnoreStasis" << YAML::Value << "true";
  1040. if (inf3_val & 0x40)
  1041. body << YAML::Key << "IgnoreKagehumi" << YAML::Value << "true";
  1042. if (inf3_val & 0x80)
  1043. body << YAML::Key << "AlterRangeVulture" << YAML::Value << "true";
  1044. if (inf3_val & 0x100)
  1045. body << YAML::Key << "AlterRangeSnakeEye" << YAML::Value << "true";
  1046. if (inf3_val & 0x200)
  1047. body << YAML::Key << "AlterRangeShadowJump" << YAML::Value << "true";
  1048. if (inf3_val & 0x400)
  1049. body << YAML::Key << "AlterRangeRadius" << YAML::Value << "true";
  1050. if (inf3_val & 0x800)
  1051. body << YAML::Key << "AlterRangeResearchTrap" << YAML::Value << "true";
  1052. if (inf3_val & 0x1000)
  1053. body << YAML::Key << "IgnoreHovering" << YAML::Value << "true";
  1054. if (inf3_val & 0x2000)
  1055. body << YAML::Key << "AllowOnWarg" << YAML::Value << "true";
  1056. if (inf3_val & 0x4000)
  1057. body << YAML::Key << "AllowOnMado" << YAML::Value << "true";
  1058. if (inf3_val & 0x8000)
  1059. body << YAML::Key << "TargetManHole" << YAML::Value << "true";
  1060. if (inf3_val & 0x10000)
  1061. body << YAML::Key << "TargetHidden" << YAML::Value << "true";
  1062. if (inf3_val & 0x40000)
  1063. body << YAML::Key << "IncreaseDanceWithWugDamage" << YAML::Value << "true";
  1064. if (inf3_val & 0x80000)
  1065. body << YAML::Key << "IgnoreWugBite" << YAML::Value << "true";
  1066. if (inf3_val & 0x100000)
  1067. body << YAML::Key << "IgnoreAutoGuard" << YAML::Value << "true";
  1068. if (inf3_val & 0x200000)
  1069. body << YAML::Key << "IgnoreCicada" << YAML::Value << "true";
  1070. body << YAML::EndMap;
  1071. }
  1072. memset(arr, 0, sizeof(arr));
  1073. arr_size = skill_split_atoi(split[1], arr);
  1074. if (arr_size != 0) {
  1075. if (arr_size == 1) {
  1076. if (arr[0] != 0) {
  1077. body << YAML::Key << "Range";
  1078. body << YAML::Value << arr[0];
  1079. }
  1080. } else {
  1081. body << YAML::Key << "Range";
  1082. body << YAML::BeginSeq;
  1083. for (int i = 0; i < arr_size; i++) {
  1084. body << YAML::BeginMap;
  1085. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1086. body << YAML::Key << "Size" << YAML::Value << arr[i];
  1087. body << YAML::EndMap;
  1088. }
  1089. body << YAML::EndSeq;
  1090. }
  1091. }
  1092. if (atoi(split[2]) != 0) {
  1093. constant = constant_lookup(atoi(split[2]), "DMG_");
  1094. constant.erase(0, 4);
  1095. body << YAML::Key << "Hit" << YAML::Value << name2Upper(constant);
  1096. }
  1097. memset(arr, 0, sizeof(arr));
  1098. arr_size = skill_split_atoi(split[8], arr);
  1099. if (arr_size != 0) {
  1100. if (arr_size == 1) {
  1101. if (arr[0] != 0) {
  1102. body << YAML::Key << "HitCount";
  1103. body << YAML::Value << arr[0];
  1104. }
  1105. } else {
  1106. body << YAML::Key << "HitCount";
  1107. body << YAML::BeginSeq;
  1108. for (int i = 0; i < arr_size; i++) {
  1109. body << YAML::BeginMap;
  1110. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1111. body << YAML::Key << "Count" << YAML::Value << arr[i];
  1112. body << YAML::EndMap;
  1113. }
  1114. body << YAML::EndSeq;
  1115. }
  1116. }
  1117. memset(arr, 0, sizeof(arr));
  1118. arr_size = skill_split_atoi(split[4], arr);
  1119. if (arr_size != 0) {
  1120. if (arr_size == 1) {
  1121. if (arr[0] != 0){
  1122. body << YAML::Key << "Element";
  1123. if (arr[0] == -1)
  1124. body << YAML::Value << "Weapon";
  1125. else if (arr[0] == -2)
  1126. body << YAML::Value << "Endowed";
  1127. else if (arr[0] == -3)
  1128. body << YAML::Value << "Random";
  1129. else {
  1130. constant = constant_lookup(arr[0], "ELE_");
  1131. constant.erase(0, 4);
  1132. body << YAML::Value << name2Upper(constant);
  1133. }
  1134. }
  1135. } else {
  1136. body << YAML::Key << "Element";
  1137. body << YAML::BeginSeq;
  1138. for (int i = 0; i < arr_size; i++) {
  1139. body << YAML::BeginMap;
  1140. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1141. if (arr[i] == -1)
  1142. body << YAML::Key << "Element" << YAML::Value << "Weapon";
  1143. else if (arr[i] == -2)
  1144. body << YAML::Key << "Element" << YAML::Value << "Endowed";
  1145. else if (arr[i] == -3)
  1146. body << YAML::Key << "Element" << YAML::Value << "Random";
  1147. else {
  1148. constant = constant_lookup(arr[i], "ELE_");
  1149. constant.erase(0, 4);
  1150. body << YAML::Key << "Element" << YAML::Value << name2Upper(constant);
  1151. }
  1152. body << YAML::EndMap;
  1153. }
  1154. body << YAML::EndSeq;
  1155. }
  1156. }
  1157. memset(arr, 0, sizeof(arr));
  1158. arr_size = skill_split_atoi(split[6], arr);
  1159. if (arr_size != 0) {
  1160. if (arr_size == 1) {
  1161. if (arr[0] != 0) {
  1162. body << YAML::Key << "SplashArea";
  1163. body << YAML::Value << arr[0];
  1164. }
  1165. } else {
  1166. body << YAML::Key << "SplashArea";
  1167. body << YAML::BeginSeq;
  1168. for (int i = 0; i < arr_size; i++) {
  1169. body << YAML::BeginMap;
  1170. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1171. body << YAML::Key << "Area" << YAML::Value << arr[i];
  1172. body << YAML::EndMap;
  1173. }
  1174. body << YAML::EndSeq;
  1175. }
  1176. }
  1177. memset(arr, 0, sizeof(arr));
  1178. arr_size = skill_split_atoi(split[12], arr);
  1179. if (arr_size != 0) {
  1180. if (arr_size == 1) {
  1181. if (arr[0] != 0) {
  1182. body << YAML::Key << "ActiveInstance";
  1183. body << YAML::Value << arr[0];
  1184. }
  1185. } else {
  1186. body << YAML::Key << "ActiveInstance";
  1187. body << YAML::BeginSeq;
  1188. for (int i = 0; i < arr_size; i++) {
  1189. body << YAML::BeginMap;
  1190. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1191. body << YAML::Key << "Max" << YAML::Value << arr[i];
  1192. body << YAML::EndMap;
  1193. }
  1194. body << YAML::EndSeq;
  1195. }
  1196. }
  1197. memset(arr, 0, sizeof(arr));
  1198. arr_size = skill_split_atoi(split[14], arr);
  1199. if (arr_size != 0) {
  1200. if (arr_size == 1) {
  1201. if (arr[0] != 0) {
  1202. body << YAML::Key << "Knockback";
  1203. body << YAML::Value << arr[0];
  1204. }
  1205. } else {
  1206. body << YAML::Key << "Knockback";
  1207. body << YAML::BeginSeq;
  1208. for (int i = 0; i < arr_size; i++) {
  1209. body << YAML::BeginMap;
  1210. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1211. body << YAML::Key << "Amount" << YAML::Value << arr[i];
  1212. body << YAML::EndMap;
  1213. }
  1214. body << YAML::EndSeq;
  1215. }
  1216. }
  1217. auto it_copyable = skill_copyable.find(skill_id);
  1218. if (it_copyable != skill_copyable.end()) {
  1219. body << YAML::Key << "CopyFlags";
  1220. body << YAML::BeginMap;
  1221. body << YAML::Key << "Skill";
  1222. body << YAML::BeginMap;
  1223. if (it_copyable->second.option & 1)
  1224. body << YAML::Key << "Plagiarism" << YAML::Value << "true";
  1225. if (it_copyable->second.option & 2)
  1226. body << YAML::Key << "Reproduce" << YAML::Value << "true";
  1227. body << YAML::EndMap;
  1228. if (it_copyable->second.req_opt > 0) {
  1229. body << YAML::Key << "RemoveRequirement";
  1230. body << YAML::BeginMap;
  1231. if (it_copyable->second.req_opt & 0x1)
  1232. body << YAML::Key << "HpCost" << YAML::Value << "true";
  1233. if (it_copyable->second.req_opt & 0x4)
  1234. body << YAML::Key << "SpCost" << YAML::Value << "true";
  1235. if (it_copyable->second.req_opt & 0x8)
  1236. body << YAML::Key << "HpRateCost" << YAML::Value << "true";
  1237. if (it_copyable->second.req_opt & 0x10)
  1238. body << YAML::Key << "SpRateCost" << YAML::Value << "true";
  1239. if (it_copyable->second.req_opt & 0x2)
  1240. body << YAML::Key << "MaxHpTrigger" << YAML::Value << "true";
  1241. if (it_copyable->second.req_opt & 0x20)
  1242. body << YAML::Key << "ZenyCost" << YAML::Value << "true";
  1243. if (it_copyable->second.req_opt & 0x40)
  1244. body << YAML::Key << "Weapon" << YAML::Value << "true";
  1245. if (it_copyable->second.req_opt & 0x80)
  1246. body << YAML::Key << "Ammo" << YAML::Value << "true";
  1247. if (it_copyable->second.req_opt & 0x100)
  1248. body << YAML::Key << "State" << YAML::Value << "true";
  1249. if (it_copyable->second.req_opt & 0x200)
  1250. body << YAML::Key << "Status" << YAML::Value << "true";
  1251. if (it_copyable->second.req_opt & 0x400)
  1252. body << YAML::Key << "SpiritSphereCost" << YAML::Value << "true";
  1253. if (it_copyable->second.req_opt & 0x800)
  1254. body << YAML::Key << "ItemCost" << YAML::Value << "true";
  1255. if (it_copyable->second.req_opt & 0x1000)
  1256. body << YAML::Key << "Equipment" << YAML::Value << "true";
  1257. body << YAML::EndMap;
  1258. }
  1259. body << YAML::EndMap;
  1260. }
  1261. auto it_nearnpc = skill_nearnpc.find(skill_id);
  1262. if (it_nearnpc != skill_nearnpc.end()) {
  1263. body << YAML::Key << "NoNearNPC";
  1264. body << YAML::BeginMap;
  1265. if (it_nearnpc->second.unit_nonearnpc_range > 0)
  1266. body << YAML::Key << "AdditionalRange" << YAML::Value << it_nearnpc->second.unit_nonearnpc_range;
  1267. if (it_nearnpc->second.unit_nonearnpc_type > 0) {
  1268. body << YAML::Key << "Type";
  1269. body << YAML::BeginMap;
  1270. if (it_nearnpc->second.unit_nonearnpc_type & 1)
  1271. body << YAML::Key << "WarpPortal" << YAML::Value << "true";
  1272. if (it_nearnpc->second.unit_nonearnpc_type & 2)
  1273. body << YAML::Key << "Shop" << YAML::Value << "true";
  1274. if (it_nearnpc->second.unit_nonearnpc_type & 4)
  1275. body << YAML::Key << "Npc" << YAML::Value << "true";
  1276. if (it_nearnpc->second.unit_nonearnpc_type & 8)
  1277. body << YAML::Key << "Tomb" << YAML::Value << "true";
  1278. body << YAML::EndMap;
  1279. }
  1280. body << YAML::EndMap;
  1281. }
  1282. if (strcmpi(split[9], "yes") == 0)
  1283. body << YAML::Key << "CastCancel" << YAML::Value << "true";
  1284. if (atoi(split[10]) != 0)
  1285. body << YAML::Key << "CastDefenseReduction" << YAML::Value << atoi(split[10]);
  1286. auto it_cast = skill_cast.find(skill_id);
  1287. if (it_cast != skill_cast.end()) {
  1288. if (!isMultiLevel(it_cast->second.cast)) {
  1289. if (it_cast->second.cast[0] > 0)
  1290. body << YAML::Key << "CastTime" << YAML::Value << it_cast->second.cast[0];
  1291. } else {
  1292. body << YAML::Key << "CastTime";
  1293. body << YAML::BeginSeq;
  1294. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.cast); i++) {
  1295. if (it_cast->second.cast[i] > 0) {
  1296. body << YAML::BeginMap;
  1297. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1298. body << YAML::Key << "Time" << YAML::Value << it_cast->second.cast[i];
  1299. body << YAML::EndMap;
  1300. }
  1301. }
  1302. body << YAML::EndSeq;
  1303. }
  1304. if (!isMultiLevel(it_cast->second.delay)) {
  1305. if (it_cast->second.delay[0] > 0)
  1306. body << YAML::Key << "AfterCastActDelay" << YAML::Value << it_cast->second.delay[0];
  1307. } else {
  1308. body << YAML::Key << "AfterCastActDelay";
  1309. body << YAML::BeginSeq;
  1310. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.delay); i++) {
  1311. if (it_cast->second.delay[i] > 0) {
  1312. body << YAML::BeginMap;
  1313. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1314. body << YAML::Key << "Time" << YAML::Value << it_cast->second.delay[i];
  1315. body << YAML::EndMap;
  1316. }
  1317. }
  1318. body << YAML::EndSeq;
  1319. }
  1320. if (!isMultiLevel(it_cast->second.walkdelay)) {
  1321. if (it_cast->second.walkdelay[0] > 0)
  1322. body << YAML::Key << "AfterCastWalkDelay" << YAML::Value << it_cast->second.walkdelay[0];
  1323. } else {
  1324. body << YAML::Key << "AfterCastWalkDelay";
  1325. body << YAML::BeginSeq;
  1326. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.walkdelay); i++) {
  1327. if (it_cast->second.walkdelay[i] > 0) {
  1328. body << YAML::BeginMap;
  1329. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1330. body << YAML::Key << "Time" << YAML::Value << it_cast->second.walkdelay[i];
  1331. body << YAML::EndMap;
  1332. }
  1333. }
  1334. body << YAML::EndSeq;
  1335. }
  1336. if (!isMultiLevel(it_cast->second.upkeep_time)) {
  1337. if (it_cast->second.upkeep_time[0] != 0)
  1338. body << YAML::Key << "Duration1" << YAML::Value << it_cast->second.upkeep_time[0];
  1339. } else {
  1340. body << YAML::Key << "Duration1";
  1341. body << YAML::BeginSeq;
  1342. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.upkeep_time); i++) {
  1343. if (it_cast->second.upkeep_time[i] != 0) {
  1344. body << YAML::BeginMap;
  1345. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1346. body << YAML::Key << "Time" << YAML::Value << it_cast->second.upkeep_time[i];
  1347. body << YAML::EndMap;
  1348. }
  1349. }
  1350. body << YAML::EndSeq;
  1351. }
  1352. if (!isMultiLevel(it_cast->second.upkeep_time2)) {
  1353. if (it_cast->second.upkeep_time2[0] != 0)
  1354. body << YAML::Key << "Duration2" << YAML::Value << it_cast->second.upkeep_time2[0];
  1355. } else {
  1356. body << YAML::Key << "Duration2";
  1357. body << YAML::BeginSeq;
  1358. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.upkeep_time2); i++) {
  1359. if (it_cast->second.upkeep_time2[i] != 0) {
  1360. body << YAML::BeginMap;
  1361. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1362. body << YAML::Key << "Time" << YAML::Value << it_cast->second.upkeep_time2[i];
  1363. body << YAML::EndMap;
  1364. }
  1365. }
  1366. body << YAML::EndSeq;
  1367. }
  1368. if (!isMultiLevel(it_cast->second.cooldown)) {
  1369. if (it_cast->second.cooldown[0] > 0)
  1370. body << YAML::Key << "Cooldown" << YAML::Value << it_cast->second.cooldown[0];
  1371. } else {
  1372. body << YAML::Key << "Cooldown";
  1373. body << YAML::BeginSeq;
  1374. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.cooldown); i++) {
  1375. if (it_cast->second.cooldown[i] > 0) {
  1376. body << YAML::BeginMap;
  1377. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1378. body << YAML::Key << "Time" << YAML::Value << it_cast->second.cooldown[i];
  1379. body << YAML::EndMap;
  1380. }
  1381. }
  1382. body << YAML::EndSeq;
  1383. }
  1384. #ifdef RENEWAL_CAST
  1385. if (!isMultiLevel(it_cast->second.fixed_cast)) {
  1386. if (it_cast->second.fixed_cast[0] != 0)
  1387. body << YAML::Key << "FixedCastTime" << YAML::Value << it_cast->second.fixed_cast[0];
  1388. } else {
  1389. body << YAML::Key << "FixedCastTime";
  1390. body << YAML::BeginSeq;
  1391. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.fixed_cast); i++) {
  1392. if (it_cast->second.fixed_cast[i] != 0) {
  1393. body << YAML::BeginMap;
  1394. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1395. body << YAML::Key << "Time" << YAML::Value << it_cast->second.fixed_cast[i];
  1396. body << YAML::EndMap;
  1397. }
  1398. }
  1399. body << YAML::EndSeq;
  1400. }
  1401. #endif
  1402. }
  1403. auto it_castdex = skill_castnodex.find(skill_id);
  1404. if (it_castdex != skill_castnodex.end()) {
  1405. if (it_castdex->second.castnodex > 0) {
  1406. body << YAML::Key << "CastTimeFlags";
  1407. body << YAML::BeginMap;
  1408. if (it_castdex->second.castnodex & 1)
  1409. body << YAML::Key << "IgnoreDex" << YAML::Value << "true";
  1410. if (it_castdex->second.castnodex & 2)
  1411. body << YAML::Key << "IgnoreStatus" << YAML::Value << "true";
  1412. if (it_castdex->second.castnodex & 4)
  1413. body << YAML::Key << "IgnoreItemBonus" << YAML::Value << "true";
  1414. body << YAML::EndMap;
  1415. }
  1416. if (it_castdex->second.delaynodex > 0) {
  1417. body << YAML::Key << "CastDelayFlags";
  1418. body << YAML::BeginMap;
  1419. if (it_castdex->second.delaynodex & 1)
  1420. body << YAML::Key << "IgnoreDex" << YAML::Value << "true";
  1421. if (it_castdex->second.delaynodex & 2)
  1422. body << YAML::Key << "IgnoreStatus" << YAML::Value << "true";
  1423. if (it_castdex->second.delaynodex & 4)
  1424. body << YAML::Key << "IgnoreItemBonus" << YAML::Value << "true";
  1425. body << YAML::EndMap;
  1426. }
  1427. }
  1428. auto it_req = skill_require.find(skill_id);
  1429. if (it_req != skill_require.end()) {
  1430. body << YAML::Key << "Requires";
  1431. body << YAML::BeginMap;
  1432. if (!isMultiLevel(it_req->second.hp)) {
  1433. if (it_req->second.hp[0] > 0)
  1434. body << YAML::Key << "HpCost" << YAML::Value << it_req->second.hp[0];
  1435. } else {
  1436. body << YAML::Key << "HpCost";
  1437. body << YAML::BeginSeq;
  1438. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.hp); i++) {
  1439. if (it_req->second.hp[i] > 0) {
  1440. body << YAML::BeginMap;
  1441. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1442. body << YAML::Key << "Amount" << YAML::Value << it_req->second.hp[i];
  1443. body << YAML::EndMap;
  1444. }
  1445. }
  1446. body << YAML::EndSeq;
  1447. }
  1448. if (!isMultiLevel(it_req->second.sp)) {
  1449. if (it_req->second.sp[0] > 0)
  1450. body << YAML::Key << "SpCost" << YAML::Value << it_req->second.sp[0];
  1451. } else {
  1452. body << YAML::Key << "SpCost";
  1453. body << YAML::BeginSeq;
  1454. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.sp); i++) {
  1455. if (it_req->second.sp[i] > 0) {
  1456. body << YAML::BeginMap;
  1457. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1458. body << YAML::Key << "Amount" << YAML::Value << it_req->second.sp[i];
  1459. body << YAML::EndMap;
  1460. }
  1461. }
  1462. body << YAML::EndSeq;
  1463. }
  1464. if (!isMultiLevel(it_req->second.hp_rate)) {
  1465. if (it_req->second.hp_rate[0] != 0)
  1466. body << YAML::Key << "HpRateCost" << YAML::Value << it_req->second.hp_rate[0];
  1467. } else {
  1468. body << YAML::Key << "HpRateCost";
  1469. body << YAML::BeginSeq;
  1470. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.hp_rate); i++) {
  1471. if (it_req->second.hp_rate[i] != 0) {
  1472. body << YAML::BeginMap;
  1473. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1474. body << YAML::Key << "Amount" << YAML::Value << it_req->second.hp_rate[i];
  1475. body << YAML::EndMap;
  1476. }
  1477. }
  1478. body << YAML::EndSeq;
  1479. }
  1480. if (!isMultiLevel(it_req->second.sp_rate)) {
  1481. if (it_req->second.sp_rate[0] != 0)
  1482. body << YAML::Key << "SpRateCost" << YAML::Value << it_req->second.sp_rate[0];
  1483. } else {
  1484. body << YAML::Key << "SpRateCost";
  1485. body << YAML::BeginSeq;
  1486. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.sp_rate); i++) {
  1487. if (it_req->second.sp_rate[i] != 0) {
  1488. body << YAML::BeginMap;
  1489. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1490. body << YAML::Key << "Amount" << YAML::Value << it_req->second.sp_rate[i];
  1491. body << YAML::EndMap;
  1492. }
  1493. }
  1494. body << YAML::EndSeq;
  1495. }
  1496. if (!isMultiLevel(it_req->second.mhp)) {
  1497. if (it_req->second.mhp[0] > 0)
  1498. body << YAML::Key << "MaxHpTrigger" << YAML::Value << it_req->second.mhp[0];
  1499. } else {
  1500. body << YAML::Key << "MaxHpTrigger";
  1501. body << YAML::BeginSeq;
  1502. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.mhp); i++) {
  1503. if (it_req->second.mhp[i] > 0) {
  1504. body << YAML::BeginMap;
  1505. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1506. body << YAML::Key << "Amount" << YAML::Value << it_req->second.mhp[i];
  1507. body << YAML::EndMap;
  1508. }
  1509. }
  1510. body << YAML::EndSeq;
  1511. }
  1512. if (!isMultiLevel(it_req->second.zeny)) {
  1513. if (it_req->second.zeny[0] > 0)
  1514. body << YAML::Key << "ZenyCost" << YAML::Value << it_req->second.zeny[0];
  1515. } else {
  1516. body << YAML::Key << "ZenyCost";
  1517. body << YAML::BeginSeq;
  1518. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.zeny); i++) {
  1519. if (it_req->second.zeny[i] > 0) {
  1520. body << YAML::BeginMap;
  1521. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1522. body << YAML::Key << "Amount" << YAML::Value << it_req->second.zeny[i];
  1523. body << YAML::EndMap;
  1524. }
  1525. }
  1526. body << YAML::EndSeq;
  1527. }
  1528. if (it_req->second.weapon != 0) {
  1529. body << YAML::Key << "Weapon";
  1530. body << YAML::BeginMap;
  1531. int temp = it_req->second.weapon;
  1532. if (temp != 99) { // Not "All"
  1533. for (int i = 0; i < MAX_WEAPON_TYPE_ALL; i++) {
  1534. if (i == MAX_WEAPON_TYPE)
  1535. continue;
  1536. if (temp & 1 << i) {
  1537. constant = constant_lookup(i, "W_");
  1538. constant.erase(0, 2);
  1539. body << YAML::Key << name2Upper(constant) << YAML::Value << "true";
  1540. temp ^= 1 << i;
  1541. }
  1542. }
  1543. }
  1544. body << YAML::EndMap;
  1545. }
  1546. if (it_req->second.ammo != 0) {
  1547. body << YAML::Key << "Ammo";
  1548. body << YAML::BeginMap;
  1549. int temp = it_req->second.ammo;
  1550. for (int i = 1; i < MAX_AMMO_TYPE; i++) {
  1551. if (temp & 1 << i) {
  1552. constant = constant_lookup(i, "A_");
  1553. constant.erase(0, 2);
  1554. body << YAML::Key << name2Upper(constant) << YAML::Value << "true";
  1555. temp ^= 1 << i;
  1556. }
  1557. }
  1558. body << YAML::EndMap;
  1559. }
  1560. if (!isMultiLevel(it_req->second.ammo_qty)) {
  1561. if (it_req->second.ammo_qty[0] > 0)
  1562. body << YAML::Key << "AmmoAmount" << YAML::Value << it_req->second.ammo_qty[0];
  1563. } else {
  1564. body << YAML::Key << "AmmoAmount";
  1565. body << YAML::BeginSeq;
  1566. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.ammo_qty); i++) {
  1567. if (it_req->second.ammo_qty[i] > 0) {
  1568. body << YAML::BeginMap;
  1569. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1570. body << YAML::Key << "Amount" << YAML::Value << it_req->second.ammo_qty[i];
  1571. body << YAML::EndMap;
  1572. }
  1573. }
  1574. body << YAML::EndSeq;
  1575. }
  1576. if (it_req->second.state) {
  1577. constant = constant_lookup(it_req->second.state, "ST_");
  1578. constant.erase(0, 3);
  1579. body << YAML::Key << "State" << YAML::Value << name2Upper(constant);
  1580. }
  1581. if (it_req->second.status.size() > 0) {
  1582. body << YAML::Key << "Status";
  1583. body << YAML::BeginMap;
  1584. for (const auto &it : it_req->second.status) {
  1585. constant = constant_lookup(it, "SC_");
  1586. constant.erase(0, 3);
  1587. body << YAML::Key << name2Upper(constant) << YAML::Value << "true";
  1588. }
  1589. body << YAML::EndMap;
  1590. }
  1591. if (!isMultiLevel(it_req->second.spiritball)) {
  1592. if (it_req->second.spiritball[0] != 0)
  1593. body << YAML::Key << "SpiritSphereCost" << YAML::Value << it_req->second.spiritball[0];
  1594. } else {
  1595. body << YAML::Key << "SpiritSphereCost";
  1596. body << YAML::BeginSeq;
  1597. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.spiritball); i++) {
  1598. if (it_req->second.spiritball[i] != 0) {
  1599. body << YAML::BeginMap;
  1600. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1601. body << YAML::Key << "Amount" << YAML::Value << it_req->second.spiritball[i];
  1602. body << YAML::EndMap;
  1603. }
  1604. }
  1605. body << YAML::EndSeq;
  1606. }
  1607. if (it_req->second.itemid[0] > 0) {
  1608. body << YAML::Key << "ItemCost";
  1609. body << YAML::BeginSeq;
  1610. for (uint8 i = 0; i < ARRAYLENGTH(it_req->second.itemid); i++) {
  1611. if (it_req->second.itemid[i] > 0) {
  1612. body << YAML::BeginMap;
  1613. std::string *item_name = util::umap_find(aegis_itemnames, it_req->second.itemid[i]);
  1614. if (item_name == nullptr) {
  1615. ShowError("Item name for item id %hu is not known (itemcost).\n", it_req->second.itemid[i]);
  1616. return false;
  1617. }
  1618. body << YAML::Key << "Item" << YAML::Value << *item_name;
  1619. body << YAML::Key << "Amount" << YAML::Value << it_req->second.amount[i];
  1620. body << YAML::EndMap;
  1621. }
  1622. }
  1623. body << YAML::EndSeq;
  1624. }
  1625. if (it_req->second.eqItem.size() > 0) {
  1626. body << YAML::Key << "Equipment";
  1627. body << YAML::BeginMap;
  1628. for (const auto &it : it_req->second.eqItem) {
  1629. std::string *item_name = util::umap_find(aegis_itemnames, it);
  1630. if (item_name == nullptr) {
  1631. ShowError("Item name for item id %u is not known (equipment).\n", it);
  1632. return false;
  1633. }
  1634. body << YAML::Key << *item_name << YAML::Value << "true";
  1635. }
  1636. body << YAML::EndMap;
  1637. }
  1638. body << YAML::EndMap;
  1639. }
  1640. auto it_unit = skill_unit.find(skill_id);
  1641. if (it_unit != skill_unit.end()) {
  1642. body << YAML::Key << "Unit";
  1643. body << YAML::BeginMap;
  1644. constant = constant_lookup(it_unit->second.unit_id, "UNT_");
  1645. constant.erase(0, 4);
  1646. body << YAML::Key << "Id" << YAML::Value << name2Upper(constant);
  1647. if (it_unit->second.unit_id2 > 0) {
  1648. constant = constant_lookup(it_unit->second.unit_id2, "UNT_");
  1649. constant.erase(0, 4);
  1650. body << YAML::Key << "AlternateId" << YAML::Value << name2Upper(constant);
  1651. }
  1652. if (!isMultiLevel(it_unit->second.unit_layout_type)) {
  1653. if (it_unit->second.unit_layout_type[0] != 0)
  1654. body << YAML::Key << "Layout" << YAML::Value << it_unit->second.unit_layout_type[0];
  1655. } else {
  1656. body << YAML::Key << "Layout";
  1657. body << YAML::BeginSeq;
  1658. for (size_t i = 0; i < ARRAYLENGTH(it_unit->second.unit_layout_type); i++) {
  1659. if (it_unit->second.unit_layout_type[i] == 0 && i + 1 > 5)
  1660. continue;
  1661. body << YAML::BeginMap;
  1662. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1663. body << YAML::Key << "Size" << YAML::Value << it_unit->second.unit_layout_type[i];
  1664. body << YAML::EndMap;
  1665. }
  1666. body << YAML::EndSeq;
  1667. }
  1668. if (!isMultiLevel(it_unit->second.unit_range)) {
  1669. if (it_unit->second.unit_range[0] != 0)
  1670. body << YAML::Key << "Range" << YAML::Value << it_unit->second.unit_range[0];
  1671. } else {
  1672. body << YAML::Key << "Range";
  1673. body << YAML::BeginSeq;
  1674. for (size_t i = 0; i < ARRAYLENGTH(it_unit->second.unit_range); i++) {
  1675. if (it_unit->second.unit_range[i] == 0 && i + 1 > 5)
  1676. continue;
  1677. body << YAML::BeginMap;
  1678. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1679. body << YAML::Key << "Size" << YAML::Value << it_unit->second.unit_range[i];
  1680. body << YAML::EndMap;
  1681. }
  1682. body << YAML::EndSeq;
  1683. }
  1684. if (it_unit->second.unit_interval != 0)
  1685. body << YAML::Key << "Interval" << YAML::Value << it_unit->second.unit_interval;
  1686. if (it_unit->second.target_str.size() > 0) {
  1687. if (it_unit->second.target_str.compare("noenemy") == 0 || it_unit->second.target_str.compare("friend") == 0)
  1688. body << YAML::Key << "Target" << YAML::Value << "Friend";
  1689. //else if (it_unit->second.target_str.compare("noenemy") == 0) // Same as Friend
  1690. // body << YAML::Key << "Target" << YAML::Value << "NoEnemy";
  1691. else if (it_unit->second.target_str.compare("party") == 0)
  1692. body << YAML::Key << "Target" << YAML::Value << "Party";
  1693. else if (it_unit->second.target_str.compare("ally") == 0)
  1694. body << YAML::Key << "Target" << YAML::Value << "Ally";
  1695. else if (it_unit->second.target_str.compare("guild") == 0)
  1696. body << YAML::Key << "Target" << YAML::Value << "Guild";
  1697. //else if (it_unit->second.target_str.compare("all") == 0)
  1698. // body << YAML::Key << "Target" << YAML::Value << "All";
  1699. else if (it_unit->second.target_str.compare("enemy") == 0)
  1700. body << YAML::Key << "Target" << YAML::Value << "Enemy";
  1701. else if (it_unit->second.target_str.compare("self") == 0)
  1702. body << YAML::Key << "Target" << YAML::Value << "Self";
  1703. else if (it_unit->second.target_str.compare("sameguild") == 0)
  1704. body << YAML::Key << "Target" << YAML::Value << "SameGuild";
  1705. }
  1706. if (it_unit->second.unit_flag_csv > 0) {
  1707. body << YAML::Key << "Flag";
  1708. body << YAML::BeginMap;
  1709. if (it_unit->second.unit_flag_csv & 0x1)
  1710. body << YAML::Value << "NoEnemy" << YAML::Value << "true";
  1711. if (it_unit->second.unit_flag_csv & 0x2)
  1712. body << YAML::Value << "NoReiteration" << YAML::Value << "true";
  1713. if (it_unit->second.unit_flag_csv & 0x4)
  1714. body << YAML::Value << "NoFootSet" << YAML::Value << "true";
  1715. if (it_unit->second.unit_flag_csv & 0x8)
  1716. body << YAML::Value << "NoOverlap" << YAML::Value << "true";
  1717. if (it_unit->second.unit_flag_csv & 0x10)
  1718. body << YAML::Value << "PathCheck" << YAML::Value << "true";
  1719. if (it_unit->second.unit_flag_csv & 0x20)
  1720. body << YAML::Value << "NoPc" << YAML::Value << "true";
  1721. if (it_unit->second.unit_flag_csv & 0x40)
  1722. body << YAML::Value << "NoMob" << YAML::Value << "true";
  1723. if (it_unit->second.unit_flag_csv & 0x80)
  1724. body << YAML::Value << "Skill" << YAML::Value << "true";
  1725. if (it_unit->second.unit_flag_csv & 0x100)
  1726. body << YAML::Value << "Dance" << YAML::Value << "true";
  1727. if (it_unit->second.unit_flag_csv & 0x200)
  1728. body << YAML::Value << "Ensemble" << YAML::Value << "true";
  1729. if (it_unit->second.unit_flag_csv & 0x400)
  1730. body << YAML::Value << "Song" << YAML::Value << "true";
  1731. if (it_unit->second.unit_flag_csv & 0x800)
  1732. body << YAML::Value << "DualMode" << YAML::Value << "true";
  1733. if (it_unit->second.unit_flag_csv & 0x1000)
  1734. body << YAML::Value << "NoKnockback" << YAML::Value << "true";
  1735. if (it_unit->second.unit_flag_csv & 0x2000)
  1736. body << YAML::Value << "RangedSingleUnit" << YAML::Value << "true";
  1737. if (it_unit->second.unit_flag_csv & 0x4000)
  1738. body << YAML::Value << "CrazyWeedImmune" << YAML::Value << "true";
  1739. if (it_unit->second.unit_flag_csv & 0x8000)
  1740. body << YAML::Value << "RemovedByFireRain" << YAML::Value << "true";
  1741. if (it_unit->second.unit_flag_csv & 0x10000)
  1742. body << YAML::Value << "KnockbackGroup" << YAML::Value << "true";
  1743. if (it_unit->second.unit_flag_csv & 0x20000)
  1744. body << YAML::Value << "HiddenTrap" << YAML::Value << "true";
  1745. body << YAML::EndMap;
  1746. }
  1747. body << YAML::EndMap;
  1748. }
  1749. body << YAML::EndMap;
  1750. return true;
  1751. }
  1752. // Copied and adjusted from quest.cpp
  1753. static bool quest_read_db(char *split[], int columns, int current) {
  1754. int quest_id = atoi(split[0]);
  1755. if (quest_id < 0 || quest_id >= INT_MAX) {
  1756. ShowError("quest_read_db: Invalid quest ID '%d'.\n", quest_id);
  1757. return false;
  1758. }
  1759. body << YAML::BeginMap;
  1760. body << YAML::Key << "Id" << YAML::Value << quest_id;
  1761. std::string title = split[17];
  1762. if (columns > 18) { // If the title has a comma in it, concatenate
  1763. int col = 18;
  1764. while (col < columns) {
  1765. title += ',' + std::string(split[col]);
  1766. col++;
  1767. }
  1768. }
  1769. title.erase(std::remove(title.begin(), title.end(), '"'), title.end()); // Strip double quotes out
  1770. body << YAML::Key << "Title" << YAML::Value << title;
  1771. if (strchr(split[1], ':') == NULL) {
  1772. uint32 time = atoi(split[1]);
  1773. if (time > 0) {
  1774. int day = time / 86400;
  1775. time %= (24 * 3600);
  1776. int hour = time / 3600;
  1777. time %= 3600;
  1778. int minute = time / 60;
  1779. time %= 60;
  1780. int second = time;
  1781. std::string output = "+";
  1782. if (day > 0)
  1783. output += std::to_string(day) + "d";
  1784. if (hour > 0)
  1785. output += std::to_string(hour) + "h";
  1786. if (minute > 0)
  1787. output += std::to_string(minute) + "mn";
  1788. if (second > 0)
  1789. output += std::to_string(second) + "s";
  1790. body << YAML::Key << "TimeLimit" << YAML::Value << output;
  1791. }
  1792. } else {
  1793. if (*split[1]) {
  1794. std::string time_str(split[1]), hour = time_str.substr(0, time_str.find(':')), output = {};
  1795. time_str.erase(0, 3); // Remove "HH:"
  1796. if (std::stoi(hour) > 0)
  1797. output = std::to_string(std::stoi(hour)) + "h";
  1798. if (std::stoi(time_str) > 0)
  1799. output += std::to_string(std::stoi(time_str)) + "mn";
  1800. body << YAML::Key << "TimeLimit" << YAML::Value << output; // No quests in TXT format had days, default to 0
  1801. }
  1802. }
  1803. if (atoi(split[2]) > 0) {
  1804. body << YAML::Key << "Targets";
  1805. body << YAML::BeginSeq;
  1806. for (size_t i = 0; i < MAX_QUEST_OBJECTIVES; i++) {
  1807. int32 mob_id = (int32)atoi(split[i * 2 + 2]), count = atoi(split[i * 2 + 3]);
  1808. if (!mob_id || !count)
  1809. continue;
  1810. std::string *mob_name = util::umap_find(aegis_mobnames, static_cast<uint16>(mob_id));
  1811. if (!mob_name) {
  1812. ShowError("quest_read_db: Invalid mob-class %hu, target not read.\n", mob_id);
  1813. continue;
  1814. }
  1815. body << YAML::BeginMap;
  1816. body << YAML::Key << "Mob" << YAML::Value << *mob_name;
  1817. body << YAML::Key << "Count" << YAML::Value << count;
  1818. body << YAML::EndMap;
  1819. }
  1820. body << YAML::EndSeq;
  1821. }
  1822. if (atoi(split[2 * MAX_QUEST_OBJECTIVES + 2]) > 0) {
  1823. body << YAML::Key << "Drops";
  1824. body << YAML::BeginSeq;
  1825. for (size_t i = 0; i < MAX_QUEST_DROPS; i++) {
  1826. int32 mob_id = (int32)atoi(split[3 * i + (2 * MAX_QUEST_OBJECTIVES + 2)]);
  1827. t_itemid nameid = strtoul(split[3 * i + (2 * MAX_QUEST_OBJECTIVES + 3)], nullptr, 10);
  1828. if (!mob_id || !nameid)
  1829. continue;
  1830. std::string *mob_name = util::umap_find(aegis_mobnames, static_cast<uint16>(mob_id));
  1831. if (!mob_name) {
  1832. ShowError("quest_read_db: Invalid mob-class %hu, drop not read.\n", mob_id);
  1833. continue;
  1834. }
  1835. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  1836. if (!item_name) {
  1837. ShowError("quest_read_db: Invalid item name %u, drop not read.\n", nameid);
  1838. return false;
  1839. }
  1840. body << YAML::BeginMap;
  1841. body << YAML::Key << "Mob" << YAML::Value << *mob_name;
  1842. body << YAML::Key << "Item" << YAML::Value << *item_name;
  1843. //body << YAML::Key << "Count" << YAML::Value << 1; // Default is 1
  1844. body << YAML::Key << "Rate" << YAML::Value << atoi(split[3 * i + (2 * MAX_QUEST_OBJECTIVES + 4)]);
  1845. body << YAML::EndMap;
  1846. }
  1847. body << YAML::EndSeq;
  1848. }
  1849. body << YAML::EndMap;
  1850. return true;
  1851. }
  1852. // Copied and adjusted from instance.cpp
  1853. static bool instance_readdb_sub(char* str[], int columns, int current) {
  1854. body << YAML::BeginMap;
  1855. body << YAML::Key << "Id" << YAML::Value << atoi(str[0]);
  1856. body << YAML::Key << "Name" << YAML::Value << str[1];
  1857. if (atoi(str[2]) != 3600)
  1858. body << YAML::Key << "TimeLimit" << YAML::Value << atoi(str[2]);
  1859. if (atoi(str[3]) != 300)
  1860. body << YAML::Key << "IdleTimeOut" << YAML::Value << atoi(str[3]);
  1861. body << YAML::Key << "Enter";
  1862. body << YAML::BeginMap;
  1863. body << YAML::Key << "Map" << YAML::Value << str[4];
  1864. body << YAML::Key << "X" << YAML::Value << atoi(str[5]);
  1865. body << YAML::Key << "Y" << YAML::Value << atoi(str[6]);
  1866. body << YAML::EndMap;
  1867. if (columns > 7) {
  1868. body << YAML::Key << "AdditionalMaps";
  1869. body << YAML::BeginMap;
  1870. for (int i = 7; i < columns; i++) {
  1871. if (!strlen(str[i]))
  1872. continue;
  1873. if (strcmpi(str[4], str[i]) == 0)
  1874. continue;
  1875. body << YAML::Key << str[i] << YAML::Value << "true";
  1876. }
  1877. body << YAML::EndMap;
  1878. }
  1879. body << YAML::EndMap;
  1880. return true;
  1881. }
  1882. // item_db.yml function
  1883. //---------------------
  1884. static bool itemdb_read_itemavail(char *str[], int columns, int current) {
  1885. item_avail.insert({ strtoul(str[0], nullptr, 10), strtoul(str[1], nullptr, 10) });
  1886. return true;
  1887. }
  1888. // item_db.yml function
  1889. //---------------------
  1890. static bool itemdb_read_buyingstore(char* fields[], int columns, int current) {
  1891. item_buyingstore.insert({ strtoul(fields[0], nullptr, 10), true });
  1892. return true;
  1893. }
  1894. // item_db.yml function
  1895. //---------------------
  1896. static bool itemdb_read_flag(char* fields[], int columns, int current) {
  1897. s_item_flag_csv2yaml item = { 0 };
  1898. uint16 flag = abs(atoi(fields[1]));
  1899. if (flag & 1)
  1900. item.dead_branch = true;
  1901. if (flag & 2)
  1902. item.group = true;
  1903. if (flag & 4)
  1904. item.guid = true;
  1905. if (flag & 8)
  1906. item.bindOnEquip = true;
  1907. if (flag & 16)
  1908. item.broadcast = true;
  1909. if (flag & 32)
  1910. item.delay_consume = true;
  1911. if (flag & 64)
  1912. item.dropEffect = DROPEFFECT_CLIENT;
  1913. else if (flag & 128)
  1914. item.dropEffect = DROPEFFECT_WHITE_PILLAR;
  1915. else if (flag & 256)
  1916. item.dropEffect = DROPEFFECT_BLUE_PILLAR;
  1917. else if (flag & 512)
  1918. item.dropEffect = DROPEFFECT_YELLOW_PILLAR;
  1919. else if (flag & 1024)
  1920. item.dropEffect = DROPEFFECT_PURPLE_PILLAR;
  1921. else if (flag & 2048)
  1922. item.dropEffect = DROPEFFECT_ORANGE_PILLAR;
  1923. item_flag.insert({ strtoul(fields[0], nullptr, 10), item });
  1924. return true;
  1925. }
  1926. // item_db.yml function
  1927. //---------------------
  1928. static bool itemdb_read_itemdelay(char* str[], int columns, int current) {
  1929. s_item_delay_csv2yaml item = { 0 };
  1930. item.delay = atoi(str[1]);
  1931. if (columns == 3)
  1932. item.sc = trim(str[2]);
  1933. item_delay.insert({ strtoul(str[0], nullptr, 10), item });
  1934. return true;
  1935. }
  1936. // item_db.yml function
  1937. //---------------------
  1938. static bool itemdb_read_stack(char* fields[], int columns, int current) {
  1939. s_item_stack_csv2yaml item = { 0 };
  1940. item.amount = atoi(fields[1]);
  1941. int type = strtoul(fields[2], NULL, 10);
  1942. if (type & 1)
  1943. item.inventory = true;
  1944. if (type & 2)
  1945. item.cart = true;
  1946. if (type & 4)
  1947. item.storage = true;
  1948. if (type & 8)
  1949. item.guild_storage = true;
  1950. item_stack.insert({ strtoul(fields[0], nullptr, 10), item });
  1951. return true;
  1952. }
  1953. // item_db.yml function
  1954. //---------------------
  1955. static bool itemdb_read_nouse(char* fields[], int columns, int current) {
  1956. s_item_nouse_csv2yaml item = { 0 };
  1957. item.sitting = "true";
  1958. item.override = atoi(fields[2]);
  1959. item_nouse.insert({ strtoul(fields[0], nullptr, 10), item });
  1960. return true;
  1961. }
  1962. // item_db.yml function
  1963. //---------------------
  1964. static bool itemdb_read_itemtrade(char* str[], int columns, int current) {
  1965. s_item_trade_csv2yaml item = { 0 };
  1966. int flag = atoi(str[1]);
  1967. if (flag & 1)
  1968. item.drop = true;
  1969. if (flag & 2)
  1970. item.trade = true;
  1971. if (flag & 4)
  1972. item.trade_partner = true;
  1973. if (flag & 8)
  1974. item.sell = true;
  1975. if (flag & 16)
  1976. item.cart = true;
  1977. if (flag & 32)
  1978. item.storage = true;
  1979. if (flag & 64)
  1980. item.guild_storage = true;
  1981. if (flag & 128)
  1982. item.mail = true;
  1983. if (flag & 256)
  1984. item.auction = true;
  1985. item.override = atoi(str[2]);
  1986. item_trade.insert({ strtoul(str[0], nullptr, 10), item });
  1987. return true;
  1988. }
  1989. // Copied and adjusted from itemdb.cpp
  1990. static bool itemdb_read_db(const char* file) {
  1991. FILE* fp = fopen(file, "r");
  1992. if (fp == nullptr) {
  1993. ShowError("can't read %s\n", file);
  1994. return false;
  1995. }
  1996. int lines = 0;
  1997. size_t entries = 0;
  1998. char line[1024];
  1999. while (fgets(line, sizeof(line), fp)) {
  2000. char* str[32], * p;
  2001. int i;
  2002. lines++;
  2003. if (line[0] == '/' && line[1] == '/')
  2004. continue;
  2005. memset(str, 0, sizeof(str));
  2006. p = strstr(line, "//");
  2007. if (p != nullptr) {
  2008. *p = '\0';
  2009. }
  2010. p = line;
  2011. while (ISSPACE(*p))
  2012. ++p;
  2013. if (*p == '\0')
  2014. continue;// empty line
  2015. for (i = 0; i < 19; ++i) {
  2016. str[i] = p;
  2017. p = strchr(p, ',');
  2018. if (p == NULL)
  2019. break;// comma not found
  2020. *p = '\0';
  2021. ++p;
  2022. }
  2023. if (p == NULL) {
  2024. ShowError("itemdb_read_db: Insufficient columns in line %d (item with id %u), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2025. continue;
  2026. }
  2027. // Script
  2028. if (*p != '{') {
  2029. ShowError("itemdb_read_db: Invalid format (Script column) in line %d (item with id %u), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2030. continue;
  2031. }
  2032. str[19] = p + 1;
  2033. p = strstr(p + 1, "},");
  2034. if (p == NULL) {
  2035. ShowError("itemdb_read_db: Invalid format (Script column) in line %d (item with id %u), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2036. continue;
  2037. }
  2038. *p = '\0';
  2039. p += 2;
  2040. // OnEquip_Script
  2041. if (*p != '{') {
  2042. ShowError("itemdb_read_db: Invalid format (OnEquip_Script column) in line %d (item with id %u), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2043. continue;
  2044. }
  2045. str[20] = p + 1;
  2046. p = strstr(p + 1, "},");
  2047. if (p == NULL) {
  2048. ShowError("itemdb_read_db: Invalid format (OnEquip_Script column) in line %d (item with id %u), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2049. continue;
  2050. }
  2051. *p = '\0';
  2052. p += 2;
  2053. // OnUnequip_Script (last column)
  2054. if (*p != '{') {
  2055. ShowError("itemdb_read_db: Invalid format (OnUnequip_Script column) in line %d (item with id %u), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2056. continue;
  2057. }
  2058. str[21] = p;
  2059. p = &str[21][strlen(str[21]) - 2];
  2060. if (*p != '}') {
  2061. /* lets count to ensure it's not something silly e.g. a extra space at line ending */
  2062. int lcurly = 0, rcurly = 0;
  2063. for (size_t v = 0; v < strlen(str[21]); v++) {
  2064. if (str[21][v] == '{')
  2065. lcurly++;
  2066. else if (str[21][v] == '}') {
  2067. rcurly++;
  2068. p = &str[21][v];
  2069. }
  2070. }
  2071. if (lcurly != rcurly) {
  2072. ShowError("itemdb_read_db: Mismatching curly braces in line %d (item with id %u), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2073. continue;
  2074. }
  2075. }
  2076. str[21] = str[21] + 1; //skip the first left curly
  2077. *p = '\0'; //null the last right curly
  2078. t_itemid nameid = strtoul(str[0], nullptr, 10);
  2079. body << YAML::BeginMap;
  2080. body << YAML::Key << "Id" << YAML::Value << nameid;
  2081. body << YAML::Key << "AegisName" << YAML::Value << str[1];
  2082. body << YAML::Key << "Name" << YAML::Value << str[2];
  2083. int type = atoi(str[3]), subtype = atoi(str[18]);
  2084. const char* constant = constant_lookup( type, "IT_" );
  2085. if( constant == nullptr ){
  2086. ShowError( "itemdb_read_db: Unknown item type %d for item %u, skipping.\n", type, nameid );
  2087. continue;
  2088. }
  2089. body << YAML::Key << "Type" << YAML::Value << name2Upper( constant + 3 );
  2090. if( type == IT_WEAPON && subtype ){
  2091. constant = constant_lookup( subtype, "W_" );
  2092. if( constant == nullptr ){
  2093. ShowError( "itemdb_read_db: Unknown weapon type %d for item %u, skipping.\n", subtype, nameid );
  2094. continue;
  2095. }
  2096. body << YAML::Key << "SubType" << YAML::Value << name2Upper( constant + 2 );
  2097. }else if( type == IT_AMMO && subtype ){
  2098. constant = constant_lookup( subtype, "AMMO_" );
  2099. if( constant == nullptr ){
  2100. ShowError( "itemdb_read_db: Unknown ammo type %d for item %u, skipping.\n", subtype, nameid );
  2101. continue;
  2102. }
  2103. body << YAML::Key << "SubType" << YAML::Value << name2Upper(constant + 5);
  2104. }
  2105. if (atoi(str[4]) > 0)
  2106. body << YAML::Key << "Buy" << YAML::Value << atoi(str[4]);
  2107. if (atoi(str[5]) > 0) {
  2108. if (atoi(str[4]) / 2 != atoi(str[5]))
  2109. body << YAML::Key << "Sell" << YAML::Value << atoi(str[5]);
  2110. }
  2111. if (atoi(str[6]) > 0)
  2112. body << YAML::Key << "Weight" << YAML::Value << atoi(str[6]);
  2113. #ifdef RENEWAL
  2114. int atk = 0, matk = 0;
  2115. itemdb_re_split_atoi(str[7], &atk, &matk);
  2116. if (atk > 0)
  2117. body << YAML::Key << "Attack" << YAML::Value << atk;
  2118. if (matk > 0)
  2119. body << YAML::Key << "MagicAttack" << YAML::Value << matk;
  2120. #else
  2121. if (atoi(str[7]) > 0)
  2122. body << YAML::Key << "Attack" << YAML::Value << atoi(str[7]);
  2123. #endif
  2124. if (atoi(str[8]) > 0)
  2125. body << YAML::Key << "Defense" << YAML::Value << atoi(str[8]);
  2126. if (atoi(str[9]) > 0)
  2127. body << YAML::Key << "Range" << YAML::Value << atoi(str[9]);
  2128. if (atoi(str[10]) > 0)
  2129. body << YAML::Key << "Slots" << YAML::Value << atoi(str[10]);
  2130. bool equippable = type == IT_UNKNOWN ? false : type == IT_ETC ? false : type == IT_CARD ? false : type == IT_PETEGG ? false : type == IT_PETARMOR ? false : type == IT_UNKNOWN2 ? false : true;
  2131. if (equippable) {
  2132. uint64 temp_mask = strtoull(str[11], NULL, 0);
  2133. if (temp_mask == 0) {
  2134. //body << YAML::Key << "Jobs";
  2135. //body << YAML::BeginMap << YAML::Key << "All" << YAML::Value << "false" << YAML::EndMap;
  2136. } else if (temp_mask == 0xFFFFFFFF) { // Commented out because it's the default value
  2137. //body << YAML::Key << "Jobs";
  2138. //body << YAML::BeginMap << YAML::Key << "All" << YAML::Value << "true" << YAML::EndMap;
  2139. } else if (temp_mask == 0xFFFFFFFE) {
  2140. body << YAML::Key << "Jobs";
  2141. body << YAML::BeginMap;
  2142. body << YAML::Key << "All" << YAML::Value << "true";
  2143. body << YAML::Key << "Novice" << YAML::Value << "false";
  2144. body << YAML::Key << "SuperNovice" << YAML::Value << "false";
  2145. body << YAML::EndMap;
  2146. } else {
  2147. body << YAML::Key << "Jobs";
  2148. body << YAML::BeginMap;
  2149. for (const auto &it : um_mapid2jobname) {
  2150. uint64 job_mask = 1ULL << it.second;
  2151. if ((temp_mask & job_mask) == job_mask)
  2152. body << YAML::Key << it.first << YAML::Value << "true";
  2153. }
  2154. body << YAML::EndMap;
  2155. }
  2156. int temp_class = atoi(str[12]);
  2157. if (temp_class == ITEMJ_NONE) {
  2158. body << YAML::Key << "Classes";
  2159. body << YAML::BeginMap << YAML::Key << "All" << YAML::Value << "false" << YAML::EndMap;
  2160. } else if (temp_class == ITEMJ_ALL) { // Commented out because it's the default value
  2161. //body << YAML::Key << "Classes";
  2162. //body << YAML::BeginMap << YAML::Key << "All" << YAML::Value << "true" << YAML::EndMap;
  2163. } else {
  2164. body << YAML::Key << "Classes";
  2165. body << YAML::BeginMap;
  2166. if ((ITEMJ_THIRD & temp_class) && (ITEMJ_THIRD_UPPER & temp_class) && (ITEMJ_THIRD_BABY & temp_class)) {
  2167. temp_class &= ~ITEMJ_ALL_THIRD;
  2168. body << YAML::Key << "All_Third" << YAML::Value << "true";
  2169. }
  2170. if ((ITEMJ_UPPER & temp_class) && (ITEMJ_THIRD_UPPER & temp_class)) {
  2171. temp_class &= ~ITEMJ_ALL_UPPER;
  2172. body << YAML::Key << "All_Upper" << YAML::Value << "true";
  2173. }
  2174. if ((ITEMJ_BABY & temp_class) && (ITEMJ_THIRD_BABY & temp_class)) {
  2175. temp_class &= ~ITEMJ_ALL_BABY;
  2176. body << YAML::Key << "All_Baby" << YAML::Value << "true";
  2177. }
  2178. for (int32 i = ITEMJ_NONE; i <= ITEMJ_THIRD_BABY; i++) {
  2179. if (i & temp_class) {
  2180. const char* class_ = constant_lookup(i, "ITEMJ_");
  2181. if (class_ != nullptr)
  2182. body << YAML::Key << name2Upper(class_ + 6) << YAML::Value << "true";
  2183. }
  2184. }
  2185. body << YAML::EndMap;
  2186. }
  2187. switch (atoi(str[13])) {
  2188. case SEX_FEMALE:
  2189. body << YAML::Key << "Gender" << YAML::Value << "Female";
  2190. break;
  2191. case SEX_MALE:
  2192. body << YAML::Key << "Gender" << YAML::Value << "Male";
  2193. break;
  2194. //case SEX_BOTH: // Commented out because it's the default value
  2195. // body << YAML::Key << "Gender" << YAML::Value << "Both";
  2196. // break;
  2197. }
  2198. }
  2199. if (atoi(str[14]) > 0) {
  2200. int temp_loc = atoi(str[14]);
  2201. body << YAML::Key << "Locations";
  2202. body << YAML::BeginMap;
  2203. if ((EQP_HAND_R & temp_loc) && (EQP_HAND_L & temp_loc)) {
  2204. temp_loc &= ~EQP_ARMS;
  2205. body << YAML::Key << "Both_Hand" << YAML::Value << "true";
  2206. }
  2207. if ((EQP_ACC_R & temp_loc) && (EQP_ACC_L & temp_loc)) {
  2208. temp_loc &= ~EQP_ACC_RL;
  2209. body << YAML::Key << "Both_Accessory" << YAML::Value << "true";
  2210. }
  2211. for (const auto &it : um_equipnames) {
  2212. if (it.second & temp_loc)
  2213. body << YAML::Key << it.first << YAML::Value << "true";
  2214. }
  2215. body << YAML::EndMap;
  2216. }
  2217. if (atoi(str[15]) > 0)
  2218. body << YAML::Key << "WeaponLevel" << YAML::Value << atoi(str[15]);
  2219. int elv = 0, elvmax = 0;
  2220. itemdb_re_split_atoi(str[16], &elv, &elvmax);
  2221. if (elv > 0)
  2222. body << YAML::Key << "EquipLevelMin" << YAML::Value << elv;
  2223. if (elvmax > 0)
  2224. body << YAML::Key << "EquipLevelMax" << YAML::Value << elvmax;
  2225. if (atoi(str[17]) > 0)
  2226. body << YAML::Key << "Refineable" << YAML::Value << "true";
  2227. if (strtoul(str[18], nullptr, 10) > 0 && type != IT_WEAPON && type != IT_AMMO)
  2228. body << YAML::Key << "View" << YAML::Value << strtoul(str[18], nullptr, 10);
  2229. auto it_avail = item_avail.find(nameid);
  2230. if (it_avail != item_avail.end()) {
  2231. std::string *item_name = util::umap_find(aegis_itemnames, static_cast<t_itemid>(it_avail->second));
  2232. if (item_name == nullptr)
  2233. ShowError("Item name for item id %u is not known (item_avail).\n", it_avail->second);
  2234. else
  2235. body << YAML::Key << "AliasName" << YAML::Value << *item_name;
  2236. }
  2237. auto it_flag = item_flag.find(nameid);
  2238. auto it_buying = item_buyingstore.find(nameid);
  2239. if (it_flag != item_flag.end() || it_buying != item_buyingstore.end()) {
  2240. body << YAML::Key << "Flags";
  2241. body << YAML::BeginMap;
  2242. if (it_buying != item_buyingstore.end())
  2243. body << YAML::Key << "BuyingStore" << YAML::Value << "true";
  2244. if (it_flag != item_flag.end() && it_flag->second.dead_branch)
  2245. body << YAML::Key << "DeadBranch" << YAML::Value << it_flag->second.dead_branch;
  2246. if (it_flag != item_flag.end() && it_flag->second.group)
  2247. body << YAML::Key << "Container" << YAML::Value << it_flag->second.group;
  2248. if (it_flag != item_flag.end() && it_flag->second.guid)
  2249. body << YAML::Key << "UniqueId" << YAML::Value << it_flag->second.guid;
  2250. if (it_flag != item_flag.end() && it_flag->second.bindOnEquip)
  2251. body << YAML::Key << "BindOnEquip" << YAML::Value << it_flag->second.bindOnEquip;
  2252. if (it_flag != item_flag.end() && it_flag->second.broadcast)
  2253. body << YAML::Key << "DropAnnounce" << YAML::Value << it_flag->second.broadcast;
  2254. if (it_flag != item_flag.end() && it_flag->second.delay_consume)
  2255. body << YAML::Key << "NoConsume" << YAML::Value << it_flag->second.delay_consume;
  2256. if (it_flag != item_flag.end() && it_flag->second.dropEffect)
  2257. body << YAML::Key << "DropEffect" << YAML::Value << name2Upper(constant_lookup(it_flag->second.dropEffect, "DROPEFFECT_") + 11);
  2258. body << YAML::EndMap;
  2259. }
  2260. auto it_delay = item_delay.find(nameid);
  2261. if (it_delay != item_delay.end()) {
  2262. body << YAML::Key << "Delay";
  2263. body << YAML::BeginMap;
  2264. body << YAML::Key << "Duration" << YAML::Value << it_delay->second.delay;
  2265. if (it_delay->second.sc.size() > 0)
  2266. body << YAML::Key << "Status" << YAML::Value << name2Upper(it_delay->second.sc.erase(0, 3));
  2267. body << YAML::EndMap;
  2268. }
  2269. auto it_stack = item_stack.find(nameid);
  2270. if (it_stack != item_stack.end()) {
  2271. body << YAML::Key << "Stack";
  2272. body << YAML::BeginMap;
  2273. body << YAML::Key << "Amount" << YAML::Value << it_stack->second.amount;
  2274. if (it_stack->second.inventory)
  2275. body << YAML::Key << "Inventory" << YAML::Value << it_stack->second.inventory;
  2276. if (it_stack->second.cart)
  2277. body << YAML::Key << "Cart" << YAML::Value << it_stack->second.cart;
  2278. if (it_stack->second.storage)
  2279. body << YAML::Key << "Storage" << YAML::Value << it_stack->second.storage;
  2280. if (it_stack->second.guild_storage)
  2281. body << YAML::Key << "GuildStorage" << YAML::Value << it_stack->second.guild_storage;
  2282. body << YAML::EndMap;
  2283. }
  2284. auto it_nouse = item_nouse.find(nameid);
  2285. if (it_nouse != item_nouse.end()) {
  2286. body << YAML::Key << "NoUse";
  2287. body << YAML::BeginMap;
  2288. body << YAML::Key << "Override" << YAML::Value << it_nouse->second.override;
  2289. body << YAML::Key << "Sitting" << YAML::Value << "true";
  2290. body << YAML::EndMap;
  2291. }
  2292. auto it_trade = item_trade.find(nameid);
  2293. if (it_trade != item_trade.end()) {
  2294. body << YAML::Key << "Trade";
  2295. body << YAML::BeginMap;
  2296. body << YAML::Key << "Override" << YAML::Value << it_trade->second.override;
  2297. if (it_trade->second.drop)
  2298. body << YAML::Key << "NoDrop" << YAML::Value << it_trade->second.drop;
  2299. if (it_trade->second.trade)
  2300. body << YAML::Key << "NoTrade" << YAML::Value << it_trade->second.trade;
  2301. if (it_trade->second.trade_partner)
  2302. body << YAML::Key << "TradePartner" << YAML::Value << it_trade->second.trade_partner;
  2303. if (it_trade->second.sell)
  2304. body << YAML::Key << "NoSell" << YAML::Value << it_trade->second.sell;
  2305. if (it_trade->second.cart)
  2306. body << YAML::Key << "NoCart" << YAML::Value << it_trade->second.cart;
  2307. if (it_trade->second.storage)
  2308. body << YAML::Key << "NoStorage" << YAML::Value << it_trade->second.storage;
  2309. if (it_trade->second.guild_storage)
  2310. body << YAML::Key << "NoGuildStorage" << YAML::Value << it_trade->second.guild_storage;
  2311. if (it_trade->second.mail)
  2312. body << YAML::Key << "NoMail" << YAML::Value << it_trade->second.mail;
  2313. if (it_trade->second.auction)
  2314. body << YAML::Key << "NoAuction" << YAML::Value << it_trade->second.auction;
  2315. body << YAML::EndMap;
  2316. }
  2317. if (*str[19])
  2318. body << YAML::Key << "Script" << YAML::Value << YAML::Literal << trim(str[19]);
  2319. if (*str[20])
  2320. body << YAML::Key << "EquipScript" << YAML::Value << YAML::Literal << trim(str[20]);
  2321. if (*str[21])
  2322. body << YAML::Key << "UnEquipScript" << YAML::Value << YAML::Literal << trim(str[21]);
  2323. body << YAML::EndMap;
  2324. entries++;
  2325. }
  2326. fclose(fp);
  2327. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' items in '" CL_WHITE "%s" CL_RESET "'.\n", entries, file);
  2328. return true;
  2329. }
  2330. // Copied and adjusted from itemdb.cpp
  2331. static bool itemdb_read_randomopt(const char* file) {
  2332. FILE* fp = fopen( file, "r" );
  2333. if( fp == nullptr ){
  2334. ShowError( "Can't read %s\n", file );
  2335. return 0;
  2336. }
  2337. uint32 lines = 0, count = 0;
  2338. char line[1024];
  2339. char path[256];
  2340. while (fgets(line, sizeof(line), fp)) {
  2341. char *str[2], *p;
  2342. lines++;
  2343. if (line[0] == '/' && line[1] == '/') // Ignore comments
  2344. continue;
  2345. memset(str, 0, sizeof(str));
  2346. p = trim(line);
  2347. if (*p == '\0')
  2348. continue;// empty line
  2349. if (!strchr(p, ','))
  2350. {
  2351. ShowError("itemdb_read_randomopt: Insufficient columns in line %d of \"%s\", skipping.\n", lines, path);
  2352. continue;
  2353. }
  2354. str[0] = p;
  2355. p = strchr(p, ',');
  2356. *p = '\0';
  2357. p++;
  2358. str[1] = p;
  2359. if (str[1][0] != '{') {
  2360. ShowError("itemdb_read_randomopt(#1): Invalid format (Script column) in line %d of \"%s\", skipping.\n", lines, path);
  2361. continue;
  2362. }
  2363. /* no ending key anywhere (missing \}\) */
  2364. if (str[1][strlen(str[1]) - 1] != '}') {
  2365. ShowError("itemdb_read_randomopt(#2): Invalid format (Script column) in line %d of \"%s\", skipping.\n", lines, path);
  2366. continue;
  2367. } else {
  2368. str[0] = trim(str[0]);
  2369. int64 id = constant_lookup_int(str[0]);
  2370. if (id == -100) {
  2371. ShowError("itemdb_read_randomopt: Unknown random option '%s' constant, skipping.\n", str[0]);
  2372. continue;
  2373. }
  2374. body << YAML::BeginMap;
  2375. body << YAML::Key << "Id" << YAML::Value << id;
  2376. body << YAML::Key << "Option" << YAML::Value << str[0] + 7;
  2377. body << YAML::Key << "Script" << YAML::Literal << str[1];
  2378. body << YAML::EndMap;
  2379. rand_opt_db.insert({ count, str[0] + 7 });
  2380. }
  2381. count++;
  2382. }
  2383. fclose(fp);
  2384. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
  2385. return true;
  2386. }
  2387. // Copied and adjusted from itemdb.cpp
  2388. static bool itemdb_read_randomopt_group(char* str[], int columns, int current) {
  2389. if ((columns - 2) % 3 != 0) {
  2390. ShowError("itemdb_read_randomopt_group: Invalid column entries '%d'.\n", columns);
  2391. return false;
  2392. }
  2393. uint16 id = static_cast<uint16>(rand_opt_group.size() + 1);
  2394. s_random_opt_group_csv *group = util::umap_find(rand_opt_group, id);
  2395. s_random_opt_group_csv group_entry;
  2396. if (group == nullptr)
  2397. group_entry.rate.push_back((uint16)strtoul(str[1], nullptr, 10));
  2398. for (int j = 0, k = 2; k < columns && j < MAX_ITEM_RDM_OPT; k += 3) {
  2399. int32 randid_tmp = -1;
  2400. for (const auto &opt : rand_opt_db) {
  2401. if (opt.second.compare(str[k]) == 0) {
  2402. randid_tmp = opt.first;
  2403. break;
  2404. }
  2405. }
  2406. if (randid_tmp < 0) {
  2407. ShowError("itemdb_read_randomopt_group: Invalid random group id '%s' in column %d!\n", str[k], k + 1);
  2408. continue;
  2409. }
  2410. std::vector<std::shared_ptr<s_random_opt_group_entry>> entries = {};
  2411. if (group != nullptr)
  2412. entries = group->slots[j];
  2413. std::shared_ptr<s_random_opt_group_entry> entry;
  2414. entry->id = static_cast<uint16>(randid_tmp);
  2415. entry->min_value = (int16)strtoul(str[k + 1], nullptr, 10);
  2416. entry->max_value = 0;
  2417. entry->param = (int8)strtoul(str[k + 2], nullptr, 10);
  2418. entry->chance = 0;
  2419. entries.push_back(entry);
  2420. if (group == nullptr)
  2421. group_entry.slots[j] = entries;
  2422. else
  2423. group->slots[j] = entries;
  2424. j++;
  2425. }
  2426. if (group == nullptr)
  2427. rand_opt_group.insert({ id, group_entry });
  2428. return true;
  2429. }
  2430. static bool itemdb_randomopt_group_yaml(void) {
  2431. for (const auto &it : rand_opt_group) {
  2432. body << YAML::BeginMap;
  2433. body << YAML::Key << "Id" << YAML::Value << it.first;
  2434. body << YAML::Key << "Group" << YAML::Value << it.second.name;
  2435. body << YAML::Key << "Slots";
  2436. body << YAML::BeginSeq;
  2437. for (size_t i = 0; i < it.second.rate.size(); i++) {
  2438. body << YAML::BeginMap;
  2439. body << YAML::Key << "Slot" << YAML::Value << i + 1;
  2440. body << YAML::Key << "Options";
  2441. body << YAML::BeginSeq;
  2442. for (size_t j = 0; j < it.second.slots.size(); j++) {
  2443. std::vector<std::shared_ptr<s_random_opt_group_entry>> options = it.second.slots.at(static_cast<uint16>(j));
  2444. for (const auto &opt_it : options) {
  2445. body << YAML::BeginMap;
  2446. for (const auto &opt : rand_opt_db) {
  2447. if (opt.first == opt_it->id) {
  2448. body << YAML::Key << "Option" << YAML::Value << opt.second;
  2449. break;
  2450. }
  2451. }
  2452. if (opt_it->min_value != 0)
  2453. body << YAML::Key << "MinValue" << YAML::Value << opt_it->min_value;
  2454. if (opt_it->param != 0)
  2455. body << YAML::Key << "Param" << YAML::Value << opt_it->param;
  2456. body << YAML::Key << "Chance" << YAML::Value << it.second.rate[i];
  2457. body << YAML::EndMap;
  2458. }
  2459. }
  2460. body << YAML::EndSeq;
  2461. body << YAML::EndMap;
  2462. }
  2463. body << YAML::EndSeq;
  2464. body << YAML::EndMap;
  2465. }
  2466. return true;
  2467. }
  2468. static bool pc_readdb_levelpenalty( char* fields[], int columns, int current ){
  2469. // 1=experience, 2=item drop
  2470. int type = atoi( fields[0] );
  2471. if( type != 1 && type != 2 ){
  2472. ShowWarning( "pc_readdb_levelpenalty: Invalid type %d specified.\n", type );
  2473. return false;
  2474. }
  2475. int64 val = constant_lookup_int( fields[1] );
  2476. if( val == -100 ){
  2477. ShowWarning("pc_readdb_levelpenalty: Unknown class constant %s specified.\n", fields[1] );
  2478. return false;
  2479. }
  2480. int class_ = atoi( fields[1] );
  2481. if( !CHK_CLASS( class_ ) ){
  2482. ShowWarning( "pc_readdb_levelpenalty: Invalid class %d specified.\n", class_ );
  2483. return false;
  2484. }
  2485. int diff = atoi( fields[2] );
  2486. if( std::abs( diff ) > MAX_LEVEL ){
  2487. ShowWarning( "pc_readdb_levelpenalty: Level difference %d is too high.\n", diff );
  2488. return false;
  2489. }
  2490. diff += MAX_LEVEL - 1;
  2491. level_penalty[type][class_][diff] = atoi(fields[3]);
  2492. return true;
  2493. }
  2494. void pc_levelpenalty_yaml_sub( int type, const std::string& name ){
  2495. body << YAML::BeginMap;
  2496. body << YAML::Key << "Type" << YAML::Value << name;
  2497. body << YAML::Key << "LevelDifferences";
  2498. body << YAML::BeginSeq;
  2499. for( int i = ARRAYLENGTH( level_penalty[type][CLASS_NORMAL] ); i >= 0; i-- ){
  2500. if( level_penalty[type][CLASS_NORMAL][i] > 0 && level_penalty[type][CLASS_NORMAL][i] != 100 ){
  2501. body << YAML::BeginMap;
  2502. body << YAML::Key << "Difference" << YAML::Value << ( i - MAX_LEVEL + 1 );
  2503. body << YAML::Key << "Rate" << YAML::Value << level_penalty[type][CLASS_NORMAL][i];
  2504. body << YAML::EndMap;
  2505. }
  2506. }
  2507. body << YAML::EndSeq;
  2508. body << YAML::EndMap;
  2509. }
  2510. bool pc_levelpenalty_yaml(){
  2511. pc_levelpenalty_yaml_sub( 1, "Exp" );
  2512. pc_levelpenalty_yaml_sub( 2, "Drop" );
  2513. return true;
  2514. }
  2515. // mob_db.yml function
  2516. //--------------------
  2517. static bool mob_readdb_race2(char *fields[], int columns, int current) {
  2518. int64 race;
  2519. if (ISDIGIT(fields[0][0]))
  2520. race = strtoll(fields[0], nullptr, 10);
  2521. else if ((race = constant_lookup_int(fields[0])) == -100) {
  2522. ShowWarning("mob_readdb_race2: Unknown race2 constant \"%s\".\n", fields[0]);
  2523. return false;
  2524. }
  2525. std::vector<uint32> mobs;
  2526. for (uint16 i = 1; i < columns; i++) {
  2527. uint32 mob_id = strtol(fields[i], nullptr, 10);
  2528. std::string *mob_name = util::umap_find(aegis_mobnames, static_cast<uint16>(mob_id));
  2529. if (!mob_name) {
  2530. ShowWarning("mob_readdb_race2: Unknown mob id %d for race2 %lld.\n", mob_id, race);
  2531. continue;
  2532. }
  2533. mobs.push_back(mob_id);
  2534. }
  2535. mob_race2.insert({ static_cast<uint16>(race), mobs });
  2536. return true;
  2537. }
  2538. // mob_db.yml function
  2539. //--------------------
  2540. static bool mob_readdb_drop(char *str[], int columns, int current) {
  2541. uint32 mob_id = strtoul(str[0], nullptr, 10);
  2542. std::string *mob_name = util::umap_find(aegis_mobnames, static_cast<uint16>(mob_id));
  2543. if (!mob_name) {
  2544. ShowWarning("mob_readdb_drop: Unknown mob ID %s.\n", str[0]);
  2545. return false;
  2546. }
  2547. t_itemid nameid = strtoul(str[1], nullptr, 10);
  2548. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  2549. if (!item_name) {
  2550. ShowWarning("mob_readdb_drop: Invalid item ID %s.\n", str[1]);
  2551. return false;
  2552. }
  2553. int32 rate = atoi(str[2]);
  2554. s_mob_drop_csv entry = {};
  2555. uint8 flag = 0;
  2556. if (columns > 4)
  2557. flag = atoi(str[4]);
  2558. entry.nameid = nameid;
  2559. entry.rate = rate;
  2560. entry.steal_protected = (flag & 1) ? 1 : 0;
  2561. entry.mvp = (flag & 2) ? true : false;
  2562. if (columns > 3)
  2563. entry.group_string = trim(str[3]);
  2564. const auto &exists = mob_drop.find(mob_id);
  2565. if (exists != mob_drop.end())
  2566. exists->second.push_back(entry);
  2567. else {
  2568. std::vector<s_mob_drop_csv> drop;
  2569. drop.push_back(entry);
  2570. mob_drop.insert({ mob_id, drop });
  2571. }
  2572. return true;
  2573. }
  2574. // Copied and adjusted from mob.cpp
  2575. static bool mob_readdb_sub(char *fields[], int columns, int current) {
  2576. uint32 mob_id = strtoul(fields[0], nullptr, 10);
  2577. body << YAML::BeginMap;
  2578. body << YAML::Key << "Id" << YAML::Value << mob_id;
  2579. body << YAML::Key << "AegisName" << YAML::Value << fields[1];
  2580. body << YAML::Key << "Name" << YAML::Value << fields[3];
  2581. if (strcmp(fields[3], fields[2]) != 0)
  2582. body << YAML::Key << "JapaneseName" << YAML::Value << fields[2];
  2583. if (strtol(fields[4], nullptr, 10) > 0)
  2584. body << YAML::Key << "Level" << YAML::Value << fields[4];
  2585. if (strtol(fields[5], nullptr, 10) > 1)
  2586. body << YAML::Key << "Hp" << YAML::Value << fields[5];
  2587. if (strtol(fields[6], nullptr, 10) > 1)
  2588. body << YAML::Key << "Sp" << YAML::Value << fields[6];
  2589. if (strtol(fields[7], nullptr, 10) > 0)
  2590. body << YAML::Key << "BaseExp" << YAML::Value << fields[7];
  2591. if (strtol(fields[8], nullptr, 10) > 0)
  2592. body << YAML::Key << "JobExp" << YAML::Value << fields[8];
  2593. if (strtol(fields[30], nullptr, 10) > 0)
  2594. body << YAML::Key << "MvpExp" << YAML::Value << fields[30];
  2595. if (strtol(fields[10], nullptr, 10) > 0)
  2596. body << YAML::Key << "Attack" << YAML::Value << fields[10];
  2597. if (strtol(fields[11], nullptr, 10) > 0)
  2598. body << YAML::Key << "Attack2" << YAML::Value << fields[11];
  2599. if (strtol(fields[12], nullptr, 10) > 0)
  2600. body << YAML::Key << "Defense" << YAML::Value << cap_value(std::stoi(fields[12]), DEFTYPE_MIN, DEFTYPE_MAX);
  2601. if (strtol(fields[13], nullptr, 10) > 0)
  2602. body << YAML::Key << "MagicDefense" << YAML::Value << cap_value(std::stoi(fields[13]), DEFTYPE_MIN, DEFTYPE_MAX);
  2603. if (strtol(fields[14], nullptr, 10) > 1)
  2604. body << YAML::Key << "Str" << YAML::Value << fields[14];
  2605. if (strtol(fields[15], nullptr, 10) > 1)
  2606. body << YAML::Key << "Agi" << YAML::Value << fields[15];
  2607. if (strtol(fields[16], nullptr, 10) > 1)
  2608. body << YAML::Key << "Vit" << YAML::Value << fields[16];
  2609. if (strtol(fields[17], nullptr, 10) > 1)
  2610. body << YAML::Key << "Int" << YAML::Value << fields[17];
  2611. if (strtol(fields[18], nullptr, 10) > 1)
  2612. body << YAML::Key << "Dex" << YAML::Value << fields[18];
  2613. if (strtol(fields[19], nullptr, 10) > 1)
  2614. body << YAML::Key << "Luk" << YAML::Value << fields[19];
  2615. if (strtol(fields[9], nullptr, 10) > 0)
  2616. body << YAML::Key << "AttackRange" << YAML::Value << fields[9];
  2617. if (strtol(fields[20], nullptr, 10) > 0)
  2618. body << YAML::Key << "SkillRange" << YAML::Value << fields[20];
  2619. if (strtol(fields[21], nullptr, 10) > 0)
  2620. body << YAML::Key << "ChaseRange" << YAML::Value << fields[21];
  2621. if (fields[22])
  2622. body << YAML::Key << "Size" << YAML::Value << constant_lookup(strtol(fields[22], nullptr, 10), "Size_") + 5;
  2623. if (fields[23])
  2624. body << YAML::Key << "Race" << YAML::Value << name2Upper(constant_lookup(strtol(fields[23], nullptr, 10), "RC_") + 3);
  2625. std::string class_ = "Normal";
  2626. bool header = false;
  2627. for (const auto &race2 : mob_race2) {
  2628. for (const auto &mobit : race2.second) {
  2629. if (mobit == mob_id) {
  2630. // These two races are now Class types
  2631. if (race2.first == RC2_GUARDIAN) {
  2632. class_ = "Guardian";
  2633. continue;
  2634. } else if (race2.first == RC2_BATTLEFIELD) {
  2635. class_ = "Battlefield";
  2636. continue;
  2637. }
  2638. if (!header) {
  2639. body << YAML::Key << "RaceGroups";
  2640. body << YAML::BeginMap;
  2641. header = true;
  2642. }
  2643. body << YAML::Key << name2Upper(constant_lookup(race2.first, "RC2_") + 4) << YAML::Value << "true";
  2644. }
  2645. }
  2646. }
  2647. if (header)
  2648. body << YAML::EndMap;
  2649. if (fields[24]) {
  2650. int ele = strtol(fields[24], nullptr, 10);
  2651. body << YAML::Key << "Element" << YAML::Value << name2Upper(constant_lookup(ele % 20, "ELE_") + 4);
  2652. body << YAML::Key << "ElementLevel" << YAML::Value << floor(ele / 20.);
  2653. }
  2654. if (strtol(fields[26], nullptr, 10) > 0)
  2655. body << YAML::Key << "WalkSpeed" << YAML::Value << cap_value(std::stoi(fields[26]), MIN_WALK_SPEED, MAX_WALK_SPEED);
  2656. if (strtol(fields[27], nullptr, 10) > 0)
  2657. body << YAML::Key << "AttackDelay" << YAML::Value << fields[27];
  2658. if (strtol(fields[28], nullptr, 10) > 0)
  2659. body << YAML::Key << "AttackMotion" << YAML::Value << fields[28];
  2660. if (strtol(fields[29], nullptr, 10) > 0)
  2661. body << YAML::Key << "DamageMotion" << YAML::Value << fields[29];
  2662. if (fields[25]) {
  2663. uint32 mode = static_cast<e_mode>(strtoul(fields[25], nullptr, 0));
  2664. std::string ai = "06";
  2665. if ((mode & 0xC000000) == 0xC000000) {
  2666. mode &= ~0xC000000;
  2667. class_ = "Battlefield";
  2668. } else if (class_.compare("Normal") == 0 && (mode & 0x6200000) == 0x6200000) { // Check for normal because class would have been changed above in RaceGroups
  2669. mode &= ~0x6200000;
  2670. class_ = "Boss";
  2671. } else if ((mode & 0x4000000) == 0x4000000) {
  2672. mode &= ~0x4000000;
  2673. class_ = "Guardian";
  2674. } else if ((mode & 0x1000000) == 0x1000000) {
  2675. mode &= ~0x1000000;
  2676. class_ = "Event";
  2677. }
  2678. if ((mode & MONSTER_TYPE_26) == MONSTER_TYPE_26) {
  2679. mode &= ~MONSTER_TYPE_26;
  2680. ai = "26";
  2681. } else if ((mode & MONSTER_TYPE_27) == MONSTER_TYPE_27) {
  2682. mode &= ~MONSTER_TYPE_27;
  2683. ai = "27";
  2684. } else if ((mode & MONSTER_TYPE_08) == MONSTER_TYPE_08) {
  2685. mode &= ~MONSTER_TYPE_08;
  2686. ai = "08";
  2687. } else if ((mode & MONSTER_TYPE_04) == MONSTER_TYPE_04) {
  2688. mode &= ~MONSTER_TYPE_04;
  2689. ai = "04";
  2690. } else if ((mode & MONSTER_TYPE_21) == MONSTER_TYPE_21) {
  2691. mode &= ~MONSTER_TYPE_21;
  2692. ai = "21";
  2693. } else if ((mode & MONSTER_TYPE_20) == MONSTER_TYPE_20) {
  2694. mode &= ~MONSTER_TYPE_20;
  2695. ai = "20";
  2696. } else if ((mode & MONSTER_TYPE_09) == MONSTER_TYPE_09) { // 9, 19
  2697. mode &= ~MONSTER_TYPE_09;
  2698. ai = "09";
  2699. } else if ((mode & MONSTER_TYPE_13) == MONSTER_TYPE_13) {
  2700. mode &= ~MONSTER_TYPE_13;
  2701. ai = "13";
  2702. } else if ((mode & MONSTER_TYPE_05) == MONSTER_TYPE_05) { // 5, 12
  2703. mode &= ~MONSTER_TYPE_05;
  2704. ai = "05";
  2705. } else if ((mode & MONSTER_TYPE_07) == MONSTER_TYPE_07) {
  2706. mode &= ~MONSTER_TYPE_07;
  2707. ai = "07";
  2708. } else if ((mode & MONSTER_TYPE_03) == MONSTER_TYPE_03) {
  2709. mode &= ~MONSTER_TYPE_03;
  2710. ai = "03";
  2711. } else if ((mode & MONSTER_TYPE_24) == MONSTER_TYPE_24) {
  2712. mode &= ~MONSTER_TYPE_24;
  2713. ai = "24";
  2714. } else if ((mode & MONSTER_TYPE_17) == MONSTER_TYPE_17) {
  2715. mode &= ~MONSTER_TYPE_17;
  2716. ai = "17";
  2717. } else if ((mode & MONSTER_TYPE_10) == MONSTER_TYPE_10) { // 10, 11
  2718. mode &= ~MONSTER_TYPE_10;
  2719. ai = "10";
  2720. } else if ((mode & MONSTER_TYPE_02) == MONSTER_TYPE_02) {
  2721. mode &= ~MONSTER_TYPE_02;
  2722. ai = "02";
  2723. } else if ((mode & MONSTER_TYPE_01) == MONSTER_TYPE_01) {
  2724. mode &= ~MONSTER_TYPE_01;
  2725. ai = "01";
  2726. } else if ((mode & MONSTER_TYPE_25) == MONSTER_TYPE_25) {
  2727. mode &= ~MONSTER_TYPE_25;
  2728. ai = "25";
  2729. } else if ((mode & MONSTER_TYPE_06) == MONSTER_TYPE_06)
  2730. ai = "06";
  2731. if (ai.compare("06") != 0)
  2732. body << YAML::Key << "Ai" << YAML::Value << ai;
  2733. if (class_.compare("Normal") != 0)
  2734. body << YAML::Key << "Class" << YAML::Value << class_;
  2735. if (mode > 0) {
  2736. body << YAML::Key << "Modes";
  2737. body << YAML::BeginMap;
  2738. if (mode & 0x1)
  2739. body << YAML::Key << "CanMove" << YAML::Value << "true";
  2740. if (mode & 0x80)
  2741. body << YAML::Key << "CanAttack" << YAML::Value << "true";
  2742. if (mode & 0x40)
  2743. body << YAML::Key << "NoCast" << YAML::Value << "true";
  2744. if (mode & 0x2)
  2745. body << YAML::Key << "Looter" << YAML::Value << "true";
  2746. if (mode & 0x4)
  2747. body << YAML::Key << "Aggressive" << YAML::Value << "true";
  2748. if (mode & 0x8)
  2749. body << YAML::Key << "Assist" << YAML::Value << "true";
  2750. if (mode & 0x20)
  2751. body << YAML::Key << "NoRandomWalk" << YAML::Value << "true";
  2752. if (mode & 0x200)
  2753. body << YAML::Key << "CastSensorChase" << YAML::Value << "true";
  2754. if (mode & 0x10)
  2755. body << YAML::Key << "CastSensorIdle" << YAML::Value << "true";
  2756. if (mode & 0x800)
  2757. body << YAML::Key << "Angry" << YAML::Value << "true";
  2758. if (mode & 0x400)
  2759. body << YAML::Key << "ChangeChase" << YAML::Value << "true";
  2760. if (mode & 0x1000)
  2761. body << YAML::Key << "ChangeTargetMelee" << YAML::Value << "true";
  2762. if (mode & 0x2000)
  2763. body << YAML::Key << "ChangeTargetChase" << YAML::Value << "true";
  2764. if (mode & 0x4000)
  2765. body << YAML::Key << "TargetWeak" << YAML::Value << "true";
  2766. if (mode & 0x8000)
  2767. body << YAML::Key << "RandomTarget" << YAML::Value << "true";
  2768. if (mode & 0x20000)
  2769. body << YAML::Key << "IgnoreMagic" << YAML::Value << "true";
  2770. if (mode & 0x10000)
  2771. body << YAML::Key << "IgnoreMelee" << YAML::Value << "true";
  2772. if (mode & 0x100000)
  2773. body << YAML::Key << "IgnoreMisc" << YAML::Value << "true";
  2774. if (mode & 0x40000)
  2775. body << YAML::Key << "IgnoreRanged" << YAML::Value << "true";
  2776. if (mode & 0x400000)
  2777. body << YAML::Key << "TeleportBlock" << YAML::Value << "true";
  2778. if (mode & 0x1000000)
  2779. body << YAML::Key << "FixedItemDrop" << YAML::Value << "true";
  2780. if (mode & 0x2000000)
  2781. body << YAML::Key << "Detector" << YAML::Value << "true";
  2782. if (mode & 0x200000)
  2783. body << YAML::Key << "KnockBackImmune" << YAML::Value << "true";
  2784. if (mode & 0x4000000)
  2785. body << YAML::Key << "StatusImmune" << YAML::Value << "true";
  2786. if (mode & 0x8000000)
  2787. body << YAML::Key << "SkillImmune" << YAML::Value << "true";
  2788. if (mode & 0x80000)
  2789. body << YAML::Key << "Mvp" << YAML::Value << "true";
  2790. body << YAML::EndMap;
  2791. }
  2792. }
  2793. bool has_mvp_drops = false;
  2794. for (uint8 d = 31; d < (31 + MAX_MVP_DROP * 2); d += 2) {
  2795. if (strtoul(fields[d], nullptr, 10) > 0) {
  2796. has_mvp_drops = true;
  2797. break;
  2798. }
  2799. }
  2800. if (has_mvp_drops) {
  2801. body << YAML::Key << "MvpDrops";
  2802. body << YAML::BeginSeq;
  2803. for (uint8 i = 0; i < MAX_MVP_DROP; i++) {
  2804. t_itemid nameid = strtoul(fields[31 + i * 2], nullptr, 10);
  2805. if (nameid > 0) {
  2806. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  2807. if (!item_name) {
  2808. ShowWarning("Monster \"%s\"(id: %d) is dropping an unknown item \"%u\"(MVP-Drop %d)\n", fields[1], mob_id, nameid, (i / 2) + 1);
  2809. continue;
  2810. }
  2811. body << YAML::BeginMap;
  2812. body << YAML::Key << "Item" << YAML::Value << *item_name;
  2813. body << YAML::Key << "Rate" << YAML::Value << cap_value(std::stoi(fields[32 + i * 2]), 1, 10000);
  2814. body << YAML::EndMap;
  2815. }
  2816. if (i < MAX_MVP_DROP - 1)
  2817. continue;
  2818. // Insert at end
  2819. for (const auto &it : mob_drop) {
  2820. if (it.first != mob_id)
  2821. continue;
  2822. for (const auto &drop : it.second) {
  2823. if (drop.mvp) {
  2824. std::string *item_name = util::umap_find(aegis_itemnames, drop.nameid);
  2825. if (!item_name) {
  2826. ShowWarning("Monster \"%s\"(id: %d) is dropping an unknown item \"%u\"(MVP-Drop %d)\n", fields[1], mob_id, drop.nameid, (i / 2) + 1);
  2827. continue;
  2828. }
  2829. body << YAML::BeginMap;
  2830. body << YAML::Key << "Item" << YAML::Value << *item_name;
  2831. body << YAML::Key << "Rate" << YAML::Value << cap_value(drop.rate, 1, 10000);
  2832. body << YAML::Key << "RandomOptionGroup" << YAML::Value << drop.group_string;
  2833. body << YAML::EndMap;
  2834. }
  2835. }
  2836. }
  2837. }
  2838. body << YAML::EndSeq;
  2839. }
  2840. bool has_drops = false;
  2841. for (uint8 d = 31 + MAX_MVP_DROP * 2; d < ((31 + MAX_MVP_DROP * 2) + MAX_MOB_DROP * 2); d += 2) {
  2842. if (strtoul(fields[d], nullptr, 10) > 0) {
  2843. has_drops = true;
  2844. break;
  2845. }
  2846. }
  2847. if (has_drops) {
  2848. body << YAML::Key << "Drops";
  2849. body << YAML::BeginSeq;
  2850. for (uint8 i = 0; i < MAX_MOB_DROP; i++) {
  2851. int k = 31 + MAX_MVP_DROP * 2 + i * 2;
  2852. t_itemid nameid = strtoul(fields[k], nullptr, 10);
  2853. if (nameid > 0) {
  2854. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  2855. if (!item_name) {
  2856. ShowWarning("Monster \"%s\"(id: %d) is dropping an unknown item \"%s\"\n", fields[1], mob_id, fields[k]);
  2857. continue;
  2858. }
  2859. body << YAML::BeginMap;
  2860. body << YAML::Key << "Item" << YAML::Value << *item_name;
  2861. body << YAML::Key << "Rate" << YAML::Value << cap_value(std::stoi(fields[k + 1]), 1, 10000);
  2862. if (i > 6) // Slots 8, 9, and 10 are inherently protected
  2863. body << YAML::Key << "StealProtected" << YAML::Value << "true";
  2864. body << YAML::EndMap;
  2865. }
  2866. if (i < MAX_MOB_DROP - 2 || i == MAX_MOB_DROP - 1)
  2867. continue;
  2868. // Insert before card
  2869. for (const auto &it : mob_drop) {
  2870. if (it.first != mob_id)
  2871. continue;
  2872. for (const auto &drop : it.second) {
  2873. if (!drop.mvp) {
  2874. std::string *item_name = util::umap_find(aegis_itemnames, drop.nameid);
  2875. if (!item_name) {
  2876. ShowWarning("Monster \"%s\"(id: %d) is dropping an unknown item \"%u\"\n", fields[1], mob_id, drop.nameid);
  2877. continue;
  2878. }
  2879. body << YAML::BeginMap;
  2880. body << YAML::Key << "Item" << YAML::Value << *item_name;
  2881. body << YAML::Key << "Rate" << YAML::Value << cap_value(drop.rate, 1, 10000);
  2882. body << YAML::Key << "RandomOptionGroup" << YAML::Value << drop.group_string;
  2883. if (drop.steal_protected == 1)
  2884. body << YAML::Key << "StealProtected" << YAML::Value << "true";
  2885. body << YAML::EndMap;
  2886. }
  2887. }
  2888. }
  2889. }
  2890. body << YAML::EndSeq;
  2891. }
  2892. body << YAML::EndMap;
  2893. return true;
  2894. }
  2895. // Copied and adjusted from mob.cpp
  2896. static bool mob_parse_row_chatdb(char* fields[], int columns, int current) {
  2897. int msg_id = atoi(fields[0]);
  2898. if (msg_id <= 0){
  2899. ShowError("Invalid chat ID '%d' in line %d\n", msg_id, current);
  2900. return false;
  2901. }
  2902. char* msg = fields[2];
  2903. size_t len = strlen(msg);
  2904. while( len && ( msg[len-1] == '\r' || msg[len-1] == '\n' ) ) {// find EOL to strip
  2905. len--;
  2906. }
  2907. if (len > (CHAT_SIZE_MAX-1)) {
  2908. ShowError("Message too long! Line %d, id: %d\n", current, msg_id);
  2909. return false;
  2910. }
  2911. else if (len == 0) {
  2912. ShowWarning("Empty message for id %d.\n", msg_id);
  2913. return false;
  2914. }
  2915. msg[len] = 0; // strip previously found EOL
  2916. body << YAML::BeginMap;
  2917. body << YAML::Key << "Id" << YAML::Value << msg_id;
  2918. if (strcmp(fields[1], "0xFF0000") != 0) // default color
  2919. body << YAML::Key << "Color" << YAML::Value << fields[1];
  2920. body << YAML::Key << "Dialog" << YAML::Value << msg;
  2921. body << YAML::EndMap;
  2922. return true;
  2923. }
  2924. // Copied and adjusted from homunculus.cpp
  2925. static bool read_homunculus_expdb(const char* file) {
  2926. FILE* fp = fopen( file, "r" );
  2927. if( fp == nullptr ){
  2928. ShowError( "Can't read %s\n", file );
  2929. return false;
  2930. }
  2931. uint32 lines = 0, count = 0;
  2932. char line[1024];
  2933. while (fgets(line, sizeof(line), fp)) {
  2934. lines++;
  2935. if (line[0] == '/' && line[1] == '/') // Ignore comments
  2936. continue;
  2937. t_exp exp = strtoull(line, nullptr, 10);
  2938. if( exp > 0 ){
  2939. body << YAML::BeginMap;
  2940. body << YAML::Key << "Level" << YAML::Value << (count+1);
  2941. body << YAML::Key << "Exp" << YAML::Value << exp;
  2942. body << YAML::EndMap;
  2943. }
  2944. count++;
  2945. }
  2946. fclose(fp);
  2947. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
  2948. return true;
  2949. }
  2950. // Copied and adjusted from mob.cpp
  2951. static bool mob_readdb_group(char* str[], int columns, int current) {
  2952. if (strncasecmp(str[0], "MOBG_", 5) != 0) {
  2953. ShowError("The group %s must start with 'MOBG_'.\n", str[0]);
  2954. return false;
  2955. }
  2956. uint16 mob_id = static_cast<uint16>(strtol(str[1], nullptr, 10));
  2957. bool is_default = mob_id == 0;
  2958. std::string group_name = str[0];
  2959. group_name.erase(0, 5);
  2960. std::transform(group_name.begin(), group_name.end(), group_name.begin(), ::toupper);
  2961. s_randomsummon_group_csv2yaml *group = util::map_find(summon_group, group_name);
  2962. bool exists = group != nullptr;
  2963. s_randomsummon_group_csv2yaml group_entry;
  2964. if (is_default)
  2965. mob_id = static_cast<uint16>(strtol(str[3], nullptr, 10));
  2966. std::string *mob_name = util::umap_find(aegis_mobnames, mob_id);
  2967. if (!mob_name) {
  2968. ShowError("Unknown mob id %d for group %s.\n", mob_id, str[0]);
  2969. return false;
  2970. }
  2971. if (!exists) {
  2972. group_entry.default_mob = *mob_name;
  2973. group_entry.group_name = group_name;
  2974. }
  2975. if (is_default) {
  2976. if (exists)
  2977. group->default_mob = *mob_name;
  2978. else
  2979. summon_group.insert({ group_name, group_entry });
  2980. }
  2981. else {
  2982. std::shared_ptr<s_randomsummon_entry_csv2yaml> entry = std::make_shared<s_randomsummon_entry_csv2yaml>();
  2983. entry->mob_name = *mob_name;
  2984. entry->rate = strtol(str[3], nullptr, 10);
  2985. if (exists)
  2986. group->list.push_back(entry);
  2987. else {
  2988. group_entry.list.push_back(entry);
  2989. summon_group.insert({ group_name, group_entry });
  2990. }
  2991. }
  2992. return true;
  2993. }
  2994. static bool mob_readdb_group_yaml(void) {
  2995. for (const auto &it : summon_group) {
  2996. body << YAML::BeginMap;
  2997. body << YAML::Key << "Group" << YAML::Value << it.first;
  2998. body << YAML::Key << "Default" << YAML::Value << it.second.default_mob;
  2999. body << YAML::Key << "Summon";
  3000. body << YAML::BeginSeq;
  3001. for (const auto &sumit : it.second.list) {
  3002. body << YAML::BeginMap;
  3003. body << YAML::Key << "Mob" << YAML::Value << sumit->mob_name;
  3004. body << YAML::Key << "Rate" << YAML::Value << sumit->rate;
  3005. body << YAML::EndMap;
  3006. }
  3007. body << YAML::EndSeq;
  3008. body << YAML::EndMap;
  3009. }
  3010. return true;
  3011. }
  3012. // Copied and adjusted from skill.cpp
  3013. static bool skill_parse_row_createarrowdb(char* split[], int columns, int current)
  3014. {
  3015. t_itemid nameid = static_cast<t_itemid>(strtoul(split[0], nullptr, 10));
  3016. if (nameid == 0)
  3017. return true;
  3018. std::string *material_name = util::umap_find(aegis_itemnames, nameid);
  3019. if (!material_name) {
  3020. ShowError("skill_parse_row_createarrowdb: Invalid item %u.\n", nameid);
  3021. return false;
  3022. }
  3023. // Import just for clearing/disabling from original data
  3024. if (strtoul(split[1], nullptr, 10) == 0) {
  3025. body << YAML::BeginMap;
  3026. body << YAML::Key << "Remove" << YAML::Value << *material_name;
  3027. body << YAML::EndMap;
  3028. return true;
  3029. }
  3030. std::map<std::string, uint32> item_created;
  3031. for (uint16 x = 1; x+1 < columns && split[x] && split[x+1]; x += 2) {
  3032. nameid = static_cast<t_itemid>(strtoul(split[x], nullptr, 10));
  3033. std::string* item_name = util::umap_find(aegis_itemnames, nameid);
  3034. if (!item_name) {
  3035. ShowError("skill_parse_row_createarrowdb: Invalid item %u.\n", nameid);
  3036. return false;
  3037. }
  3038. item_created.insert({ *item_name, strtoul(split[x+1], nullptr, 10) });
  3039. }
  3040. body << YAML::BeginMap;
  3041. body << YAML::Key << "Source" << YAML::Value << *material_name;
  3042. body << YAML::Key << "Make";
  3043. body << YAML::BeginSeq;
  3044. for (const auto &it : item_created) {
  3045. body << YAML::BeginMap;
  3046. body << YAML::Key << "Item" << YAML::Value << it.first;
  3047. body << YAML::Key << "Amount" << YAML::Value << it.second;
  3048. body << YAML::EndMap;
  3049. }
  3050. body << YAML::EndSeq;
  3051. body << YAML::EndMap;
  3052. return true;
  3053. }
  3054. // Copied and adjusted from pc.cpp
  3055. static bool pc_read_statsdb(const char* file) {
  3056. FILE* fp = fopen( file, "r" );
  3057. if( fp == nullptr ){
  3058. ShowError( "Can't read %s\n", file );
  3059. return false;
  3060. }
  3061. uint32 lines = 0, count = 0;
  3062. char line[1024];
  3063. while (fgets(line, sizeof(line), fp)) {
  3064. lines++;
  3065. trim(line);
  3066. if (line[0] == '/' && line[1] == '/') // Ignore comments
  3067. continue;
  3068. body << YAML::BeginMap;
  3069. body << YAML::Key << "Level" << YAML::Value << (count+1);
  3070. body << YAML::Key << "Points" << YAML::Value << static_cast<uint32>(strtoul(line, nullptr, 10));
  3071. body << YAML::EndMap;
  3072. count++;
  3073. }
  3074. fclose(fp);
  3075. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
  3076. return true;
  3077. }
  3078. // Copied and adjusted from guild.cpp
  3079. static bool guild_read_castledb(char* str[], int columns, int current) {
  3080. body << YAML::BeginMap;
  3081. body << YAML::Key << "Id" << YAML::Value << str[0];
  3082. body << YAML::Key << "Map" << YAML::Value << str[1];
  3083. body << YAML::Key << "Name" << YAML::Value << trim(str[2]);
  3084. body << YAML::Key << "Npc" << YAML::Value << trim(str[3]);
  3085. body << YAML::EndMap;
  3086. return true;
  3087. }
  3088. // Copied and adjusted from int_guild.cpp
  3089. static bool exp_guild_parse_row(char* split[], int column, int current) {
  3090. t_exp exp = strtoull(split[0], nullptr, 10);
  3091. if (exp > MAX_GUILD_EXP) {
  3092. ShowError("exp_guild: Invalid exp %" PRIu64 " at line %d, exceeds max of %" PRIu64 "\n", exp, current, MAX_GUILD_EXP);
  3093. return false;
  3094. }
  3095. body << YAML::BeginMap;
  3096. body << YAML::Key << "Level" << YAML::Value << (current+1);
  3097. body << YAML::Key << "Exp" << YAML::Value << exp;
  3098. body << YAML::EndMap;
  3099. return true;
  3100. }