csv2yaml.cpp 126 KB

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