csv2yaml.cpp 174 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530
  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 <cmath>
  5. using namespace rathena::tool_csv2yaml;
  6. // Skill database data to memory
  7. static void skill_txt_data(const std::string& modePath, const std::string& fixedPath) {
  8. skill_require.clear();
  9. skill_cast.clear();
  10. skill_castnodex.clear();
  11. skill_unit.clear();
  12. skill_copyable.clear();
  13. skill_nearnpc.clear();
  14. if (fileExists(modePath + "/skill_require_db.txt"))
  15. sv_readdb(modePath.c_str(), "skill_require_db.txt", ',', 34, 34, -1, skill_parse_row_requiredb, false);
  16. if (fileExists(modePath + "/skill_cast_db.txt"))
  17. sv_readdb(modePath.c_str(), "skill_cast_db.txt", ',', 7, 8, -1, skill_parse_row_castdb, false);
  18. if (fileExists(modePath + "/skill_castnodex_db.txt"))
  19. sv_readdb(modePath.c_str(), "skill_castnodex_db.txt", ',', 2, 3, -1, skill_parse_row_castnodexdb, false);
  20. if (fileExists(modePath + "/skill_unit_db.txt"))
  21. sv_readdb(modePath.c_str(), "skill_unit_db.txt", ',', 8, 8, -1, skill_parse_row_unitdb, false);
  22. if (fileExists(fixedPath + "/skill_copyable_db.txt"))
  23. sv_readdb(fixedPath.c_str(), "skill_copyable_db.txt", ',', 2, 4, -1, skill_parse_row_copyabledb, false);
  24. if (fileExists(fixedPath + "/skill_nonearnpc_db.txt"))
  25. sv_readdb(fixedPath.c_str(), "skill_nonearnpc_db.txt", ',', 2, 3, -1, skill_parse_row_nonearnpcrangedb, false);
  26. }
  27. // Item database data to memory
  28. static void item_txt_data(const std::string& modePath, const std::string& fixedPath) {
  29. item_avail.clear();
  30. item_buyingstore.clear();
  31. item_flag.clear();
  32. item_delay.clear();
  33. item_stack.clear();
  34. item_nouse.clear();
  35. item_trade.clear();
  36. if (fileExists(fixedPath + "/item_avail.txt"))
  37. sv_readdb(fixedPath.c_str(), "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail, false);
  38. if (fileExists(modePath + "/item_buyingstore.txt"))
  39. sv_readdb(modePath.c_str(), "item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore, false);
  40. if (fileExists(modePath + "/item_flag.txt"))
  41. sv_readdb(modePath.c_str(), "item_flag.txt", ',', 2, 2, -1, &itemdb_read_flag, false);
  42. if (fileExists(modePath + "/item_delay.txt"))
  43. sv_readdb(modePath.c_str(), "item_delay.txt", ',', 2, 3, -1, &itemdb_read_itemdelay, false);
  44. if (fileExists(modePath + "/item_stack.txt"))
  45. sv_readdb(modePath.c_str(), "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack, false);
  46. if (fileExists(fixedPath + "/item_nouse.txt"))
  47. sv_readdb(fixedPath.c_str(), "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse, false);
  48. if (fileExists(modePath + "/item_trade.txt"))
  49. sv_readdb(modePath.c_str(), "item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade, false);
  50. }
  51. // Homunculus database data to memory
  52. static void homunculus_txt_data(const std::string& modePath, const std::string& fixedPath) {
  53. hom_skill_tree.clear();
  54. if (fileExists(modePath + "/homun_skill_tree.txt"))
  55. sv_readdb(modePath.c_str(), "homun_skill_tree.txt", ',', 15, 15, -1, read_homunculus_skilldb, false);
  56. }
  57. // Mob database data to memory
  58. static void mob_txt_data(const std::string &modePath, const std::string &fixedPath) {
  59. mob_race2.clear();
  60. mob_drop.clear();
  61. if (fileExists(modePath + "/mob_race2_db.txt"))
  62. sv_readdb(modePath.c_str(), "mob_race2_db.txt", ',', 2, 100, -1, mob_readdb_race2, false);
  63. if (fileExists(modePath + "/mob_drop.txt"))
  64. sv_readdb(modePath.c_str(), "mob_drop.txt", ',', 3, 5, -1, mob_readdb_drop, false);
  65. }
  66. // Branch database data to memory
  67. static void branch_txt_data(const std::string& modePath, const std::string& fixedPath) {
  68. summon_group.clear();
  69. if (fileExists(modePath + "/mob_branch.txt"))
  70. sv_readdb(modePath.c_str(), "mob_branch.txt", ',', 4, 4, -1, mob_readdb_group, false);
  71. if (fileExists(modePath + "/mob_random_db.txt"))
  72. sv_readdb(modePath.c_str(), "mob_random_db.txt", ',', 4, 4, -1, mob_readdb_group, false);
  73. if (fileExists(modePath + "/mob_poring.txt"))
  74. sv_readdb(modePath.c_str(), "mob_poring.txt", ',', 4, 4, -1, mob_readdb_group, false);
  75. if (fileExists(modePath + "/mob_boss.txt"))
  76. sv_readdb(modePath.c_str(), "mob_boss.txt", ',', 4, 4, -1, mob_readdb_group, false);
  77. if (fileExists(fixedPath + "/mob_pouch.txt"))
  78. sv_readdb(fixedPath.c_str(), "mob_pouch.txt", ',', 4, 4, -1, mob_readdb_group, false);
  79. if (fileExists(fixedPath + "/mob_mission.txt"))
  80. sv_readdb(fixedPath.c_str(), "mob_mission.txt", ',', 4, 4, -1, mob_readdb_group, false);
  81. if (fileExists(fixedPath + "/mob_classchange.txt"))
  82. sv_readdb(fixedPath.c_str(), "mob_classchange.txt", ',', 4, 4, -1, mob_readdb_group, false);
  83. }
  84. // Item Group database data to memory
  85. static void item_group_txt_data(const std::string& modePath, const std::string& fixedPath) {
  86. item_group.clear();
  87. if (fileExists(modePath + "/item_bluebox.txt"))
  88. sv_readdb(modePath.c_str(), "item_bluebox.txt", ',', 2, 10, -1, itemdb_read_group, false);
  89. if (fileExists(modePath + "/item_violetbox.txt"))
  90. sv_readdb(modePath.c_str(), "item_violetbox.txt", ',', 2, 10, -1, itemdb_read_group, false);
  91. if (fileExists(modePath + "/item_cardalbum.txt"))
  92. sv_readdb(modePath.c_str(), "item_cardalbum.txt", ',', 2, 10, -1, itemdb_read_group, false);
  93. if (fileExists(fixedPath + "/item_findingore.txt"))
  94. sv_readdb(fixedPath.c_str(), "item_findingore.txt", ',', 2, 10, -1, itemdb_read_group, false);
  95. if (fileExists(modePath + "/item_giftbox.txt"))
  96. sv_readdb(modePath.c_str(), "item_giftbox.txt", ',', 2, 10, -1, itemdb_read_group, false);
  97. if (fileExists(modePath + "/item_misc.txt"))
  98. sv_readdb(modePath.c_str(), "item_misc.txt", ',', 2, 10, -1, itemdb_read_group, false);
  99. if (fileExists(modePath + "/item_group_db.txt"))
  100. sv_readdb(modePath.c_str(), "item_group_db.txt", ',', 2, 10, -1, itemdb_read_group, false);
  101. if (fileExists(modePath + "/item_package.txt"))
  102. sv_readdb(modePath.c_str(), "item_package.txt", ',', 2, 10, -1, itemdb_read_group, false);
  103. }
  104. // Job database data to memory
  105. static void job_txt_data(const std::string &modePath, const std::string &fixedPath) {
  106. job_db2.clear();
  107. job_param.clear();
  108. exp_base_level.clear();
  109. exp_job_level.clear();
  110. if (fileExists(fixedPath + "/job_db2.txt"))
  111. sv_readdb(fixedPath.c_str(), "/job_db2.txt", ',', 1, 1 + MAX_LEVEL, CLASS_COUNT, &pc_readdb_job2, false);
  112. if (fileExists(modePath + "job_exp.txt"))
  113. sv_readdb(modePath.c_str(), "job_exp.txt", ',', 4, 1000 + 3, CLASS_COUNT * 2, &pc_readdb_job_exp_sub, false);
  114. if (fileExists(modePath + "job_param_db.txt"))
  115. sv_readdb(modePath.c_str(), "job_param_db.txt", ',', 2, PARAM_MAX + 1, CLASS_COUNT, &pc_readdb_job_param, false);
  116. }
  117. // Elemental Summons Skill Database data to memory
  118. static void elemental_skill_txt_data(const std::string& modePath, const std::string& fixedPath) {
  119. elemental_skill_tree.clear();
  120. if (fileExists(fixedPath + "/elemental_skill_db.txt"))
  121. sv_readdb(fixedPath.c_str(), "elemental_skill_db.txt", ',', 4, 4, -1, read_elemental_skilldb, false);
  122. }
  123. // Mercenary's Skill Database data to memory
  124. static void mercenary_skill_txt_data(const std::string& modePath, const std::string& fixedPath) {
  125. mercenary_skill_tree.clear();
  126. if (fileExists(fixedPath + "/mercenary_skill_db.txt"))
  127. sv_readdb(fixedPath.c_str(), "mercenary_skill_db.txt", ',', 3, 3, -1, mercenary_read_skilldb, false);
  128. }
  129. // Skill tree database data to memory
  130. static void skilltree_txt_data(const std::string &modePath, const std::string &fixedPath) {
  131. skill_tree.clear();
  132. if (fileExists(modePath + "/skill_tree.txt"))
  133. sv_readdb(modePath.c_str(), "skill_tree.txt", ',', 3 + MAX_PC_SKILL_REQUIRE * 2, 5 + MAX_PC_SKILL_REQUIRE * 2, -1, pc_readdb_skilltree, false);
  134. }
  135. // Mob Skill database data to memory
  136. static void mob_skill_txt_data(const std::string &modePath, const std::string &fixedPath) {
  137. mob_skill_db.clear();
  138. if (fileExists(modePath + "/mob_skill_db.txt"))
  139. sv_readdb(modePath.c_str(), "mob_skill_db.txt", ',', 19, 19, -1, mob_parse_row_mobskilldb, false);
  140. }
  141. template<typename Func>
  142. bool process( const std::string& type, uint32 version, const std::vector<std::string>& paths, const std::string& name, Func lambda, const std::string& rename = "" ){
  143. for( const std::string& path : paths ){
  144. const std::string name_ext = name + ".txt";
  145. const std::string from = path + "/" + name_ext;
  146. const std::string to = path + "/" + (rename.size() > 0 ? rename : name) + ".yml";
  147. if( fileExists( from ) ){
  148. #ifndef CONVERT_ALL
  149. if( !askConfirmation( "Found the file \"%s\", which requires migration to yml.\nDo you want to convert it now? (Y/N)\n", from.c_str() ) ){
  150. continue;
  151. }
  152. if (fileExists(to)) {
  153. if (!askConfirmation("The file \"%s\" already exists.\nDo you want to replace it? (Y/N)\n", to.c_str())) {
  154. continue;
  155. }
  156. }
  157. #else
  158. ShowMessage( "Found the file \"%s\", which requires migration to yml.\n", from.c_str() );
  159. #endif
  160. ShowNotice("Conversion process has begun.\n");
  161. std::ofstream outFile;
  162. body.~Emitter();
  163. new (&body) YAML::Emitter();
  164. outFile.open(to);
  165. if (!outFile.is_open()) {
  166. ShowError("Can not open file \"%s\" for writing.\n", to.c_str());
  167. return false;
  168. }
  169. prepareHeader(outFile, type, version, (rename.size() > 0 ? rename : name));
  170. prepareBody();
  171. if( !lambda( path, name_ext ) ){
  172. outFile.close();
  173. return false;
  174. }
  175. finalizeBody();
  176. outFile << body.c_str();
  177. // Make sure there is an empty line at the end of the file for git
  178. outFile << "\n";
  179. outFile.close();
  180. // TODO: do you want to delete?
  181. }
  182. }
  183. return true;
  184. }
  185. bool Csv2YamlTool::initialize( int32 argc, char* argv[] ){
  186. const std::string path_db = std::string( db_path );
  187. const std::string path_db_mode = path_db + "/" + DBPATH;
  188. const std::string path_db_import = path_db + "/" + DBIMPORT + "/";
  189. // Loads required conversion constants
  190. if (fileExists(item_db.getDefaultLocation())) {
  191. item_db.load();
  192. } else {
  193. parse_item_constants_txt( ( path_db_mode + "item_db.txt" ).c_str() );
  194. parse_item_constants_txt( ( path_db_import + "item_db.txt" ).c_str() );
  195. }
  196. if (fileExists(mob_db.getDefaultLocation())) {
  197. mob_db.load();
  198. } else {
  199. 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);
  200. 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);
  201. }
  202. if (fileExists(skill_db.getDefaultLocation())) {
  203. skill_db.load();
  204. } else {
  205. sv_readdb(path_db_mode.c_str(), "skill_db.txt", ',', 18, 18, -1, parse_skill_constants_txt, false);
  206. sv_readdb(path_db_import.c_str(), "skill_db.txt", ',', 18, 18, -1, parse_skill_constants_txt, false);
  207. }
  208. // Load constants
  209. #define export_constant_npc(a) export_constant(a)
  210. init_random_option_constants();
  211. #include <map/script_constants.hpp>
  212. // Constants that are deprecated but still needed for conversion
  213. script_set_constant(QUOTE(RC2_GUARDIAN), RC2_GUARDIAN, false, false);
  214. script_set_constant(QUOTE(RC2_BATTLEFIELD), RC2_BATTLEFIELD, false, false);
  215. std::vector<std::string> root_paths = {
  216. path_db,
  217. path_db_mode,
  218. path_db_import
  219. };
  220. if( !process( "GUILD_SKILL_TREE_DB", 1, root_paths, "guild_skill_tree", []( const std::string& path, const std::string& name_ext ) -> bool {
  221. 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 );
  222. } ) ){
  223. return false;
  224. }
  225. if( !process( "PET_DB", 1, root_paths, "pet_db", []( const std::string& path, const std::string& name_ext ) -> bool {
  226. return pet_read_db( ( path + name_ext ).c_str() );
  227. } ) ){
  228. return false;
  229. }
  230. if (!process("MAGIC_MUSHROOM_DB", 1, root_paths, "magicmushroom_db", [](const std::string &path, const std::string &name_ext) -> bool {
  231. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1, 1, -1, &skill_parse_row_magicmushroomdb, false);
  232. })) {
  233. return false;
  234. }
  235. if (!process("ABRA_DB", 1, root_paths, "abra_db", [](const std::string& path, const std::string& name_ext) -> bool {
  236. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 3, 3, -1, &skill_parse_row_abradb, false);
  237. })) {
  238. return false;
  239. }
  240. if (!process("READING_SPELLBOOK_DB", 1, root_paths, "spellbook_db", [](const std::string& path, const std::string& name_ext) -> bool {
  241. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 3, 3, -1, &skill_parse_row_spellbookdb, false);
  242. })) {
  243. return false;
  244. }
  245. if (!process("MOB_AVAIL_DB", 1, root_paths, "mob_avail", [](const std::string& path, const std::string& name_ext) -> bool {
  246. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 2, 12, -1, &mob_readdb_mobavail, false);
  247. })) {
  248. return false;
  249. }
  250. skill_txt_data( path_db_mode, path_db );
  251. if (!process("SKILL_DB", 4, { path_db_mode }, "skill_db", [](const std::string& path, const std::string& name_ext) -> bool {
  252. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 18, 18, -1, &skill_parse_row_skilldb, false);
  253. })){
  254. return false;
  255. }
  256. skill_txt_data( path_db_import, path_db_import );
  257. if (!process("SKILL_DB", 4, { path_db_import }, "skill_db", [](const std::string& path, const std::string& name_ext) -> bool {
  258. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 18, 18, -1, &skill_parse_row_skilldb, false);
  259. })){
  260. return false;
  261. }
  262. if (!process("QUEST_DB", 3, root_paths, "quest_db", [](const std::string &path, const std::string &name_ext) -> bool {
  263. 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);
  264. })) {
  265. return false;
  266. }
  267. if (!process("INSTANCE_DB", 1, root_paths, "instance_db", [](const std::string& path, const std::string& name_ext) -> bool {
  268. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 7, 7 + MAX_MAP_PER_INSTANCE, -1, &instance_readdb_sub, false);
  269. })) {
  270. return false;
  271. }
  272. item_txt_data(path_db_mode, path_db);
  273. if (!process("ITEM_DB", 3, { path_db_mode }, "item_db", [](const std::string& path, const std::string& name_ext) -> bool {
  274. return itemdb_read_db((path + name_ext).c_str());
  275. })) {
  276. return false;
  277. }
  278. item_txt_data(path_db_import, path_db_import);
  279. if (!process("ITEM_DB", 3, { path_db_import }, "item_db", [](const std::string& path, const std::string& name_ext) -> bool {
  280. return itemdb_read_db((path + name_ext).c_str());
  281. })) {
  282. return false;
  283. }
  284. rand_opt_db.clear();
  285. if (!process("RANDOM_OPTION_DB", 1, root_paths, "item_randomopt_db", [](const std::string& path, const std::string& name_ext) -> bool {
  286. return itemdb_read_randomopt((path + name_ext).c_str());
  287. })) {
  288. return false;
  289. }
  290. rand_opt_group.clear();
  291. if (!process("RANDOM_OPTION_GROUP", 1, root_paths, "item_randomopt_group", [](const std::string& path, const std::string& name_ext) -> bool {
  292. 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();
  293. })) {
  294. return false;
  295. }
  296. #ifdef RENEWAL
  297. memset( level_penalty, 0, sizeof( level_penalty ) );
  298. if (!process("PENALTY_DB", 1, { path_db_mode }, "level_penalty", [](const std::string& path, const std::string& name_ext) -> bool {
  299. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 4, 4, -1, &pc_readdb_levelpenalty, false) && pc_levelpenalty_yaml();
  300. })) {
  301. return false;
  302. }
  303. memset( level_penalty, 0, sizeof( level_penalty ) );
  304. if (!process("PENALTY_DB", 1, { path_db_import }, "level_penalty", [](const std::string& path, const std::string& name_ext) -> bool {
  305. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 4, 4, -1, &pc_readdb_levelpenalty, false) && pc_levelpenalty_yaml();
  306. })) {
  307. return false;
  308. }
  309. #endif
  310. mob_txt_data(path_db_mode, path_db);
  311. if (!process("MOB_DB", 3, { path_db_mode }, "mob_db", [](const std::string &path, const std::string &name_ext) -> bool {
  312. 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);
  313. })) {
  314. return false;
  315. }
  316. mob_txt_data(path_db_import, path_db_import);
  317. if (!process("MOB_DB", 3, { path_db_import }, "mob_db", [](const std::string &path, const std::string &name_ext) -> bool {
  318. 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);
  319. })) {
  320. return false;
  321. }
  322. if (!process("MOB_CHAT_DB", 1, root_paths, "mob_chat_db", [](const std::string& path, const std::string& name_ext) -> bool {
  323. return sv_readdb(path.c_str(), name_ext.c_str(), '#', 3, 3, -1, &mob_parse_row_chatdb, false);
  324. })) {
  325. return false;
  326. }
  327. if (!process("HOMUN_EXP_DB", 1, { path_db_mode }, "exp_homun", [](const std::string &path, const std::string &name_ext) -> bool {
  328. return read_homunculus_expdb((path + name_ext).c_str());
  329. })) {
  330. return false;
  331. }
  332. if (!process("HOMUN_EXP_DB", 1, { path_db_import }, "exp_homun", [](const std::string &path, const std::string &name_ext) -> bool {
  333. return read_homunculus_expdb((path + name_ext).c_str());
  334. })) {
  335. return false;
  336. }
  337. branch_txt_data(path_db_mode, path_db);
  338. if (!process("MOB_SUMMONABLE_DB", 1, { path_db_mode }, "mob_branch", [](const std::string &path, const std::string &name_ext) -> bool {
  339. return mob_readdb_group_yaml();
  340. }, "mob_summon")) {
  341. return false;
  342. }
  343. branch_txt_data(path_db_import, path_db_import);
  344. if (!process("MOB_SUMMONABLE_DB", 1, { path_db_import }, "mob_branch", [](const std::string &path, const std::string &name_ext) -> bool {
  345. return mob_readdb_group_yaml();
  346. }, "mob_summon")) {
  347. return false;
  348. }
  349. if (!process("CREATE_ARROW_DB", 1, root_paths, "create_arrow_db", [](const std::string& path, const std::string& name_ext) -> bool {
  350. 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);
  351. })) {
  352. return false;
  353. }
  354. if (!process("STATPOINT_DB", 1, { path_db_mode }, "statpoint", [](const std::string &path, const std::string &name_ext) -> bool {
  355. return pc_read_statsdb((path + name_ext).c_str());
  356. })) {
  357. return false;
  358. }
  359. if (!process("STATPOINT_DB", 1, { path_db_import }, "statpoint", [](const std::string &path, const std::string &name_ext) -> bool {
  360. return pc_read_statsdb((path + name_ext).c_str());
  361. })) {
  362. return false;
  363. }
  364. if (!process("CASTLE_DB", 1, root_paths, "castle_db", [](const std::string &path, const std::string &name_ext) -> bool {
  365. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 4, 4, -1, &guild_read_castledb, false);
  366. })) {
  367. return false;
  368. }
  369. if (!process("GUILD_EXP_DB", 1, { path_db_mode }, "exp_guild", [](const std::string &path, const std::string &name_ext) -> bool {
  370. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1, 1, MAX_GUILDLEVEL, &exp_guild_parse_row, false);
  371. })) {
  372. return false;
  373. }
  374. if (!process("GUILD_EXP_DB", 1, { path_db_import }, "exp_guild", [](const std::string &path, const std::string &name_ext) -> bool {
  375. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1, 1, MAX_GUILDLEVEL, &exp_guild_parse_row, false);
  376. })) {
  377. return false;
  378. }
  379. item_group_txt_data(path_db_mode, path_db);
  380. if (!process("ITEM_GROUP_DB", 4, { path_db_mode }, "item_group_db", [](const std::string &path, const std::string &name_ext) -> bool {
  381. return itemdb_read_group_yaml();
  382. })) {
  383. return false;
  384. }
  385. item_group_txt_data(path_db_import, path_db_import);
  386. if (!process("ITEM_GROUP_DB", 4, { path_db_import }, "item_group_db", [](const std::string &path, const std::string &name_ext) -> bool {
  387. return itemdb_read_group_yaml();
  388. })) {
  389. return false;
  390. }
  391. if (!process("MOB_ITEM_RATIO_DB", 1, root_paths, "mob_item_ratio", [](const std::string& path, const std::string& name_ext) -> bool {
  392. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, &mob_readdb_itemratio, false);
  393. })) {
  394. return false;
  395. }
  396. if (!process("ATTRIBUTE_DB", 1, { path_db_mode }, "attr_fix", [](const std::string &path, const std::string &name_ext) -> bool {
  397. return status_readdb_attrfix((path + name_ext).c_str());
  398. })) {
  399. return false;
  400. }
  401. if (!process("ATTRIBUTE_DB", 1, { path_db_import }, "attr_fix", [](const std::string &path, const std::string &name_ext) -> bool {
  402. return status_readdb_attrfix((path + name_ext).c_str());
  403. })) {
  404. return false;
  405. }
  406. if (!process("CONSTANT_DB", 1, root_paths, "const", [](const std::string& path, const std::string& name_ext) -> bool {
  407. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 1, 3, -1, &read_constdb, false);
  408. })) {
  409. return false;
  410. }
  411. if (!process("JOB_STATS", 3, root_paths, "job_exp", [](const std::string& path, const std::string& name_ext) -> bool {
  412. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 4, 1000 + 3, CLASS_COUNT * 2, &pc_readdb_job_exp, false);
  413. }, "job_exp")) {
  414. return false;
  415. }
  416. if (!process("JOB_STATS", 3, root_paths, "job_basehpsp_db", [](const std::string& path, const std::string& name_ext) -> bool {
  417. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 4, 4 + 500, CLASS_COUNT * 2, &pc_readdb_job_basehpsp, false);
  418. }, "job_basepoints")) {
  419. return false;
  420. }
  421. job_txt_data(path_db_mode, path_db);
  422. if (!process("JOB_STATS", 3, { path_db_mode }, "job_db1", [](const std::string& path, const std::string& name_ext) -> bool {
  423. #ifdef RENEWAL_ASPD
  424. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 6 + MAX_WEAPON_TYPE, 6 + MAX_WEAPON_TYPE, CLASS_COUNT, &pc_readdb_job1, false);
  425. #else
  426. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 5 + MAX_WEAPON_TYPE, 5 + MAX_WEAPON_TYPE, CLASS_COUNT, &pc_readdb_job1, false);
  427. #endif
  428. }, "job_stats")) {
  429. return false;
  430. }
  431. job_txt_data(path_db_import, path_db_import);
  432. if (!process("JOB_STATS", 3, { path_db_import }, "job_db1", [](const std::string& path, const std::string& name_ext) -> bool {
  433. #ifdef RENEWAL_ASPD
  434. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 6 + MAX_WEAPON_TYPE, 6 + MAX_WEAPON_TYPE, CLASS_COUNT, &pc_readdb_job1, false);
  435. #else
  436. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 5 + MAX_WEAPON_TYPE, 5 + MAX_WEAPON_TYPE, CLASS_COUNT, &pc_readdb_job1, false);
  437. #endif
  438. }, "job_stats")) {
  439. return false;
  440. }
  441. elemental_skill_txt_data(path_db_mode, path_db);
  442. if (!process("ELEMENTAL_DB", 1, root_paths, "elemental_db", [](const std::string &path, const std::string &name_ext) -> bool {
  443. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 26, 26, -1, &read_elementaldb, false);
  444. })) {
  445. return false;
  446. }
  447. mercenary_skill_txt_data(path_db_mode, path_db);
  448. if (!process("MERCENARY_DB", 1, root_paths, "mercenary_db", [](const std::string &path, const std::string &name_ext) -> bool {
  449. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 26, 26, -1, &mercenary_readdb, false);
  450. })) {
  451. return false;
  452. }
  453. skilltree_txt_data(path_db_mode, path_db);
  454. if (!process("SKILL_TREE_DB", 1, { path_db_mode }, "skill_tree", [](const std::string &path, const std::string &name_ext) -> bool {
  455. return pc_readdb_skilltree_yaml();
  456. })) {
  457. return false;
  458. }
  459. skilltree_txt_data(path_db_import, path_db_import);
  460. if (!process("SKILL_TREE_DB", 1, { path_db_import }, "skill_tree", [](const std::string &path, const std::string &name_ext) -> bool {
  461. return pc_readdb_skilltree_yaml();
  462. })) {
  463. return false;
  464. }
  465. if (!process("COMBO_DB", 1, { path_db_mode }, "item_combo_db", [](const std::string& path, const std::string& name_ext) -> bool {
  466. return itemdb_read_combos((path + name_ext).c_str());
  467. }, "item_combos")) {
  468. return false;
  469. }
  470. if (!process("COMBO_DB", 1, { path_db_import }, "item_combo_db", [](const std::string& path, const std::string& name_ext) -> bool {
  471. return itemdb_read_combos((path + name_ext).c_str());
  472. }, "item_combos")) {
  473. return false;
  474. }
  475. if( !process( "ITEM_CASH_DB", 1, root_paths, "item_cash_db", []( const std::string& path, const std::string& name_ext ) -> bool {
  476. return sv_readdb( path.c_str(), name_ext.c_str(), ',', 3, 3, -1, &cashshop_parse_dbrow, false );
  477. }, "item_cash" ) ){
  478. return 0;
  479. }
  480. homunculus_txt_data(path_db, path_db);
  481. if (!process("HOMUNCULUS_DB", 1, { path_db_mode }, "homunculus_db", [](const std::string& path, const std::string& name_ext) -> bool {
  482. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 50, 50, MAX_HOMUNCULUS_CLASS, read_homunculusdb, false);
  483. })) {
  484. return 0;
  485. }
  486. homunculus_txt_data(path_db_import, path_db_import);
  487. if (!process("HOMUNCULUS_DB", 1, { path_db_import }, "homunculus_db", [](const std::string& path, const std::string& name_ext) -> bool {
  488. return sv_readdb(path.c_str(), name_ext.c_str(), ',', 50, 50, MAX_HOMUNCULUS_CLASS, read_homunculusdb, false);
  489. })) {
  490. return 0;
  491. }
  492. mob_skill_txt_data(path_db_mode, path_db);
  493. if (!process("MOB_SKILL_DB", 1, { path_db_mode }, "mob_skill_db", [](const std::string &path, const std::string &name_ext) -> bool {
  494. return mob_parse_row_mobskilldb_yaml();
  495. })) {
  496. return 0;
  497. }
  498. mob_skill_txt_data(path_db_import, path_db_import);
  499. if (!process("MOB_SKILL_DB", 1, { path_db_import }, "mob_skill_db", [](const std::string &path, const std::string &name_ext) -> bool {
  500. return mob_parse_row_mobskilldb_yaml();
  501. })) {
  502. return 0;
  503. }
  504. // TODO: add implementations ;-)
  505. return true;
  506. }
  507. // Implementation of the conversion functions
  508. // Copied and adjusted from guild.cpp
  509. // <skill id>,<max lv>,<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>
  510. static bool guild_read_guildskill_tree_db( char* split[], size_t columns, size_t current ){
  511. uint16 skill_id = (uint16)atoi(split[0]);
  512. std::string* name = util::umap_find( aegis_skillnames, skill_id );
  513. if( name == nullptr ){
  514. ShowError( "Skill name for skill id %hu is not known.\n", skill_id );
  515. return false;
  516. }
  517. body << YAML::BeginMap;
  518. body << YAML::Key << "Id" << YAML::Value << *name;
  519. body << YAML::Key << "MaxLevel" << YAML::Value << atoi(split[1]);
  520. if (atoi(split[2]) > 0) {
  521. body << YAML::Key << "Required";
  522. body << YAML::BeginSeq;
  523. for (int32 i = 0, j = 0; i < MAX_GUILD_SKILL_REQUIRE; i++) {
  524. uint16 required_skill_id = atoi(split[i * 2 + 2]);
  525. uint16 required_skill_level = atoi(split[i * 2 + 3]);
  526. if (required_skill_id == 0 || required_skill_level == 0) {
  527. continue;
  528. }
  529. std::string* required_name = util::umap_find(aegis_skillnames, required_skill_id);
  530. if (required_name == nullptr) {
  531. ShowError("Skill name for required skill id %hu is not known.\n", required_skill_id);
  532. return false;
  533. }
  534. body << YAML::BeginMap;
  535. body << YAML::Key << "Id" << YAML::Value << *required_name;
  536. body << YAML::Key << "Level" << YAML::Value << required_skill_level;
  537. body << YAML::EndMap;
  538. }
  539. body << YAML::EndSeq;
  540. }
  541. body << YAML::EndMap;
  542. return true;
  543. }
  544. // Copied and adjusted from pet.cpp
  545. static bool pet_read_db( const char* file ){
  546. FILE* fp = fopen( file, "r" );
  547. if( fp == nullptr ){
  548. ShowError( "can't read %s\n", file );
  549. return false;
  550. }
  551. int32 lines = 0;
  552. size_t entries = 0;
  553. char line[1024];
  554. while( fgets( line, sizeof(line), fp ) ) {
  555. char *str[22], *p;
  556. unsigned k;
  557. lines++;
  558. if(line[0] == '/' && line[1] == '/')
  559. continue;
  560. memset(str, 0, sizeof(str));
  561. p = line;
  562. while( ISSPACE(*p) )
  563. ++p;
  564. if( *p == '\0' )
  565. continue; // empty line
  566. for( k = 0; k < 20; ++k ) {
  567. str[k] = p;
  568. p = strchr(p,',');
  569. if( p == nullptr )
  570. break; // comma not found
  571. *p = '\0';
  572. ++p;
  573. }
  574. if( p == nullptr ) {
  575. ShowError("read_petdb: Insufficient columns in line %d, skipping.\n", lines);
  576. continue;
  577. }
  578. // Pet Script
  579. if( *p != '{' ) {
  580. ShowError("read_petdb: Invalid format (Pet Script column) in line %d, skipping.\n", lines);
  581. continue;
  582. }
  583. str[20] = p;
  584. p = strstr(p+1,"},");
  585. if( p == nullptr ) {
  586. ShowError("read_petdb: Invalid format (Pet Script column) in line %d, skipping.\n", lines);
  587. continue;
  588. }
  589. p[1] = '\0';
  590. p += 2;
  591. // Equip Script
  592. if( *p != '{' ) {
  593. ShowError("read_petdb: Invalid format (Equip Script column) in line %d, skipping.\n", lines);
  594. continue;
  595. }
  596. str[21] = p;
  597. uint16 mob_id = atoi( str[0] );
  598. std::string* mob_name = util::umap_find( aegis_mobnames, mob_id );
  599. if( mob_name == nullptr ){
  600. ShowWarning( "pet_db reading: Invalid mob-class %hu, pet not read.\n", mob_id );
  601. continue;
  602. }
  603. body << YAML::BeginMap;
  604. body << YAML::Key << "Mob" << YAML::Value << *mob_name;
  605. t_itemid tame_item_id = strtoul( str[3], nullptr, 10 );
  606. if( tame_item_id > 0 ){
  607. std::string* tame_item_name = util::umap_find( aegis_itemnames, tame_item_id );
  608. if( tame_item_name == nullptr ){
  609. ShowError( "Item name for item id %u is not known.\n", tame_item_id );
  610. return false;
  611. }
  612. body << YAML::Key << "TameItem" << YAML::Value << *tame_item_name;
  613. }
  614. t_itemid egg_item_id = strtoul( str[4], nullptr, 10 );
  615. std::string* egg_item_name = util::umap_find( aegis_itemnames, egg_item_id );
  616. if( egg_item_name == nullptr ){
  617. ShowError( "Item name for item id %u is not known.\n", egg_item_id );
  618. return false;
  619. }
  620. body << YAML::Key << "EggItem" << YAML::Value << *egg_item_name;
  621. t_itemid equip_item_id = strtoul( str[5], nullptr, 10 );
  622. if( equip_item_id > 0 ){
  623. std::string* equip_item_name = util::umap_find( aegis_itemnames, equip_item_id );
  624. if( equip_item_name == nullptr ){
  625. ShowError( "Item name for item id %u is not known.\n", equip_item_id );
  626. return false;
  627. }
  628. body << YAML::Key << "EquipItem" << YAML::Value << *equip_item_name;
  629. }
  630. t_itemid food_item_id = strtoul( str[6], nullptr, 10 );
  631. if( food_item_id > 0 ){
  632. std::string* food_item_name = util::umap_find( aegis_itemnames, food_item_id );
  633. if( food_item_name == nullptr ){
  634. ShowError( "Item name for item id %u is not known.\n", food_item_id );
  635. return false;
  636. }
  637. body << YAML::Key << "FoodItem" << YAML::Value << *food_item_name;
  638. }
  639. body << YAML::Key << "Fullness" << YAML::Value << atoi(str[7]);
  640. // Default: 60
  641. if( atoi( str[8] ) != 60 ){
  642. body << YAML::Key << "HungryDelay" << YAML::Value << atoi(str[8]);
  643. }
  644. // Default: 250
  645. if( atoi( str[11] ) != 250 ){
  646. body << YAML::Key << "IntimacyStart" << YAML::Value << atoi(str[11]);
  647. }
  648. body << YAML::Key << "IntimacyFed" << YAML::Value << atoi(str[9]);
  649. // Default: -100
  650. if( atoi( str[10] ) != 100 ){
  651. body << YAML::Key << "IntimacyOverfed" << YAML::Value << -atoi(str[10]);
  652. }
  653. // pet_hungry_friendly_decrease battle_conf
  654. //body << YAML::Key << "IntimacyHungry" << YAML::Value << -5;
  655. // Default: -20
  656. if( atoi( str[12] ) != 20 ){
  657. body << YAML::Key << "IntimacyOwnerDie" << YAML::Value << -atoi(str[12]);
  658. }
  659. body << YAML::Key << "CaptureRate" << YAML::Value << atoi(str[13]);
  660. // Default: true
  661. if( atoi( str[15] ) == 0 ){
  662. body << YAML::Key << "SpecialPerformance" << YAML::Value << "false";
  663. }
  664. body << YAML::Key << "AttackRate" << YAML::Value << atoi(str[17]);
  665. body << YAML::Key << "RetaliateRate" << YAML::Value << atoi(str[18]);
  666. body << YAML::Key << "ChangeTargetRate" << YAML::Value << atoi(str[19]);
  667. if( *str[21] ){
  668. body << YAML::Key << "Script" << YAML::Value << YAML::Literal << str[21];
  669. }
  670. if( *str[20] ){
  671. body << YAML::Key << "SupportScript" << YAML::Value << YAML::Literal << str[20];
  672. }
  673. body << YAML::EndMap;
  674. entries++;
  675. }
  676. fclose(fp);
  677. ShowStatus("Done reading '" CL_WHITE "%zu" CL_RESET "' pets in '" CL_WHITE "%s" CL_RESET "'.\n", entries, file );
  678. return true;
  679. }
  680. // Copied and adjusted from skill.cpp
  681. static bool skill_parse_row_magicmushroomdb( char *split[], size_t column, size_t current ){
  682. uint16 skill_id = atoi(split[0]);
  683. std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
  684. if (skill_name == nullptr) {
  685. ShowError("Skill name for Magic Mushroom skill ID %hu is not known.\n", skill_id);
  686. return false;
  687. }
  688. body << YAML::BeginMap;
  689. body << YAML::Key << "Skill" << YAML::Value << *skill_name;
  690. body << YAML::EndMap;
  691. return true;
  692. }
  693. // Copied and adjusted from skill.cpp
  694. static bool skill_parse_row_abradb( char* split[], size_t columns, size_t current ){
  695. uint16 skill_id = atoi(split[0]);
  696. std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
  697. if (skill_name == nullptr) {
  698. ShowError("Skill name for Abra skill ID %hu is not known.\n", skill_id);
  699. return false;
  700. }
  701. body << YAML::BeginMap;
  702. body << YAML::Key << "Skill" << YAML::Value << *skill_name;
  703. int32 arr[MAX_SKILL_LEVEL];
  704. int32 arr_size = skill_split_atoi(split[2], arr);
  705. if (arr_size == 1) {
  706. if (arr[0] != 500)
  707. body << YAML::Key << "Probability" << YAML::Value << arr[0];
  708. } else {
  709. body << YAML::Key << "Probability";
  710. body << YAML::BeginSeq;
  711. for (int32 i = 0; i < arr_size; i++) {
  712. if (arr[i] > 0) {
  713. body << YAML::BeginMap;
  714. body << YAML::Key << "Level" << YAML::Value << i + 1;
  715. body << YAML::Key << "Probability" << YAML::Value << arr[i];
  716. body << YAML::EndMap;
  717. }
  718. }
  719. body << YAML::EndSeq;
  720. }
  721. body << YAML::EndMap;
  722. return true;
  723. }
  724. // Copied and adjusted from skill.cpp
  725. static bool skill_parse_row_spellbookdb( char* split[], size_t columns, size_t current ){
  726. uint16 skill_id = atoi(split[0]);
  727. std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
  728. if (skill_name == nullptr) {
  729. ShowError("Skill name for Spell Book skill ID %hu is not known.\n", skill_id);
  730. return false;
  731. }
  732. t_itemid nameid = strtoul(split[2], nullptr, 10);
  733. std::string *book_name = util::umap_find(aegis_itemnames, nameid);
  734. if (book_name == nullptr) {
  735. ShowError("Book name for item ID %u is not known.\n", nameid);
  736. return false;
  737. }
  738. body << YAML::BeginMap;
  739. body << YAML::Key << "Skill" << YAML::Value << *skill_name;
  740. body << YAML::Key << "Book" << YAML::Value << *book_name;
  741. body << YAML::Key << "PreservePoints" << YAML::Value << atoi(split[1]);
  742. body << YAML::EndMap;
  743. return true;
  744. }
  745. // Copied and adjusted from mob.cpp
  746. static bool mob_readdb_mobavail( char* str[], size_t columns, size_t current ){
  747. uint16 mob_id = atoi(str[0]);
  748. std::string *mob_name = util::umap_find(aegis_mobnames, mob_id);
  749. if (mob_name == nullptr) {
  750. ShowWarning("mob_avail reading: Invalid mob-class %hu, Mob not read.\n", mob_id);
  751. return false;
  752. }
  753. body << YAML::BeginMap;
  754. body << YAML::Key << "Mob" << YAML::Value << *mob_name;
  755. uint16 sprite_id = atoi(str[1]);
  756. std::string *sprite_name = util::umap_find(aegis_mobnames, sprite_id);
  757. if (sprite_name == nullptr) {
  758. char *sprite = const_cast<char *>(constant_lookup(sprite_id, "JOB_"));
  759. if (sprite == nullptr) {
  760. sprite = const_cast<char *>(constant_lookup(sprite_id, "JT_"));
  761. if (sprite == nullptr) {
  762. ShowError("Sprite name for id %d is not known.\n", sprite_id);
  763. return false;
  764. }
  765. sprite += 3; // Strip JT_ here because the script engine doesn't send this prefix for NPC.
  766. body << YAML::Key << "Sprite" << YAML::Value << sprite;
  767. } else
  768. body << YAML::Key << "Sprite" << YAML::Value << sprite;
  769. } else
  770. body << YAML::Key << "Sprite" << YAML::Value << *sprite_name;
  771. if (columns == 12) {
  772. body << YAML::Key << "Sex" << YAML::Value << (atoi(str[2]) ? "Male" : "Female");
  773. if (atoi(str[3]) != 0)
  774. body << YAML::Key << "HairStyle" << YAML::Value << atoi(str[3]);
  775. if (atoi(str[4]) != 0)
  776. body << YAML::Key << "HairColor" << YAML::Value << atoi(str[4]);
  777. if (atoi(str[11]) != 0)
  778. body << YAML::Key << "ClothColor" << YAML::Value << atoi(str[11]);
  779. if (strtoul(str[5], nullptr, 10) != 0) {
  780. t_itemid weapon_item_id = strtoul( str[5], nullptr, 10 );
  781. std::string *weapon_item_name = util::umap_find(aegis_itemnames, weapon_item_id);
  782. if (weapon_item_name == nullptr) {
  783. ShowError("Item name for item ID %u (weapon) is not known.\n", weapon_item_id);
  784. return false;
  785. }
  786. body << YAML::Key << "Weapon" << YAML::Value << *weapon_item_name;
  787. }
  788. if (strtoul(str[6], nullptr, 10) != 0) {
  789. t_itemid shield_item_id = strtoul( str[6], nullptr, 10 );
  790. std::string *shield_item_name = util::umap_find(aegis_itemnames, shield_item_id);
  791. if (shield_item_name == nullptr) {
  792. ShowError("Item name for item ID %u (shield) is not known.\n", shield_item_id);
  793. return false;
  794. }
  795. body << YAML::Key << "Shield" << YAML::Value << *shield_item_name;
  796. }
  797. if (strtoul(str[7], nullptr, 10) != 0) {
  798. t_itemid *headtop_item_id = util::umap_find(aegis_itemviewid, (uint32)strtoul(str[7], nullptr, 10));
  799. if (headtop_item_id == nullptr) {
  800. ShowError("Item ID for view ID %lu (head top) is not known.\n", strtoul(str[7], nullptr, 10));
  801. return false;
  802. }
  803. std::string *headtop_item_name = util::umap_find(aegis_itemnames, *headtop_item_id);
  804. if (headtop_item_name == nullptr) {
  805. ShowError("Item name for item ID %u (head top) is not known.\n", *headtop_item_id);
  806. return false;
  807. }
  808. body << YAML::Key << "HeadTop" << YAML::Value << *headtop_item_name;
  809. }
  810. if (strtoul(str[8], nullptr, 10) != 0) {
  811. t_itemid *headmid_item_id = util::umap_find(aegis_itemviewid, (uint32)strtoul(str[8], nullptr, 10));
  812. if (headmid_item_id == nullptr) {
  813. ShowError("Item ID for view ID %lu (head mid) is not known.\n", strtoul(str[8], nullptr, 10));
  814. return false;
  815. }
  816. std::string *headmid_item_name = util::umap_find(aegis_itemnames, *headmid_item_id);
  817. if (headmid_item_name == nullptr) {
  818. ShowError("Item name for item ID %u (head mid) is not known.\n", *headmid_item_id);
  819. return false;
  820. }
  821. body << YAML::Key << "HeadMid" << YAML::Value << *headmid_item_name;
  822. }
  823. if (strtoul(str[9], nullptr, 10) != 0) {
  824. t_itemid *headlow_item_id = util::umap_find(aegis_itemviewid, (uint32)strtoul(str[9], nullptr, 10));
  825. if (headlow_item_id == nullptr) {
  826. ShowError("Item ID for view ID %lu (head low) is not known.\n", strtoul(str[9], nullptr, 10));
  827. return false;
  828. }
  829. std::string *headlow_item_name = util::umap_find(aegis_itemnames, *headlow_item_id);
  830. if (headlow_item_name == nullptr) {
  831. ShowError("Item name for item ID %u (head low) is not known.\n", *headlow_item_id);
  832. return false;
  833. }
  834. body << YAML::Key << "HeadLow" << YAML::Value << *headlow_item_name;
  835. }
  836. if (atoi(str[10]) != 0) {
  837. uint32 options = atoi(str[10]);
  838. body << YAML::Key << "Options";
  839. body << YAML::BeginMap;
  840. while (options > OPTION_NOTHING && options <= OPTION_SUMMER2) {
  841. if (options & OPTION_SIGHT) {
  842. body << YAML::Key << "Sight" << YAML::Value << "true";
  843. options &= ~OPTION_SIGHT;
  844. } else if (options & OPTION_CART1) {
  845. body << YAML::Key << "Cart1" << YAML::Value << "true";
  846. options &= ~OPTION_CART1;
  847. } else if (options & OPTION_FALCON) {
  848. body << YAML::Key << "Falcon" << YAML::Value << "true";
  849. options &= ~OPTION_FALCON;
  850. } else if (options & OPTION_RIDING) {
  851. body << YAML::Key << "Riding" << YAML::Value << "true";
  852. options &= ~OPTION_RIDING;
  853. } else if (options & OPTION_CART2) {
  854. body << YAML::Key << "Cart2" << YAML::Value << "true";
  855. options &= ~OPTION_CART2;
  856. } else if (options & OPTION_CART3) {
  857. body << YAML::Key << "Cart2" << YAML::Value << "true";
  858. options &= ~OPTION_CART3;
  859. } else if (options & OPTION_CART4) {
  860. body << YAML::Key << "Cart4" << YAML::Value << "true";
  861. options &= ~OPTION_CART4;
  862. } else if (options & OPTION_CART5) {
  863. body << YAML::Key << "Cart5" << YAML::Value << "true";
  864. options &= ~OPTION_CART5;
  865. } else if (options & OPTION_ORCISH) {
  866. body << YAML::Key << "Orcish" << YAML::Value << "true";
  867. options &= ~OPTION_ORCISH;
  868. } else if (options & OPTION_WEDDING) {
  869. body << YAML::Key << "Wedding" << YAML::Value << "true";
  870. options &= ~OPTION_WEDDING;
  871. } else if (options & OPTION_RUWACH) {
  872. body << YAML::Key << "Ruwach" << YAML::Value << "true";
  873. options &= ~OPTION_RUWACH;
  874. } else if (options & OPTION_FLYING) {
  875. body << YAML::Key << "Flying" << YAML::Value << "true";
  876. options &= ~OPTION_FLYING;
  877. } else if (options & OPTION_XMAS) {
  878. body << YAML::Key << "Xmas" << YAML::Value << "true";
  879. options &= ~OPTION_XMAS;
  880. } else if (options & OPTION_TRANSFORM) {
  881. body << YAML::Key << "Transform" << YAML::Value << "true";
  882. options &= ~OPTION_TRANSFORM;
  883. } else if (options & OPTION_SUMMER) {
  884. body << YAML::Key << "Summer" << YAML::Value << "true";
  885. options &= ~OPTION_SUMMER;
  886. } else if (options & OPTION_DRAGON1) {
  887. body << YAML::Key << "Dragon1" << YAML::Value << "true";
  888. options &= ~OPTION_DRAGON1;
  889. } else if (options & OPTION_WUG) {
  890. body << YAML::Key << "Wug" << YAML::Value << "true";
  891. options &= ~OPTION_WUG;
  892. } else if (options & OPTION_WUGRIDER) {
  893. body << YAML::Key << "WugRider" << YAML::Value << "true";
  894. options &= ~OPTION_WUGRIDER;
  895. } else if (options & OPTION_MADOGEAR) {
  896. body << YAML::Key << "MadoGear" << YAML::Value << "true";
  897. options &= ~OPTION_MADOGEAR;
  898. } else if (options & OPTION_DRAGON2) {
  899. body << YAML::Key << "Dragon2" << YAML::Value << "true";
  900. options &= ~OPTION_DRAGON2;
  901. } else if (options & OPTION_DRAGON3) {
  902. body << YAML::Key << "Dragon3" << YAML::Value << "true";
  903. options &= ~OPTION_DRAGON3;
  904. } else if (options & OPTION_DRAGON4) {
  905. body << YAML::Key << "Dragon4" << YAML::Value << "true";
  906. options &= ~OPTION_DRAGON4;
  907. } else if (options & OPTION_DRAGON5) {
  908. body << YAML::Key << "Dragon5" << YAML::Value << "true";
  909. options &= ~OPTION_DRAGON5;
  910. } else if (options & OPTION_HANBOK) {
  911. body << YAML::Key << "Hanbok" << YAML::Value << "true";
  912. options &= ~OPTION_HANBOK;
  913. } else if (options & OPTION_OKTOBERFEST) {
  914. body << YAML::Key << "Oktoberfest" << YAML::Value << "true";
  915. options &= ~OPTION_OKTOBERFEST;
  916. } else if (options & OPTION_SUMMER2) {
  917. body << YAML::Key << "Summer2" << YAML::Value << "true";
  918. options &= ~OPTION_SUMMER2;
  919. }
  920. }
  921. body << YAML::EndMap;
  922. }
  923. } else if (columns == 3) {
  924. if (atoi(str[5]) != 0) {
  925. t_itemid peteq_item_id = strtoul( str[5], nullptr, 10 );
  926. std::string *peteq_item_name = util::umap_find(aegis_itemnames, peteq_item_id);
  927. if (peteq_item_name == nullptr) {
  928. ShowError("Item name for item ID %u (pet equip) is not known.\n", peteq_item_id);
  929. return false;
  930. }
  931. body << YAML::Key << "PetEquip" << YAML::Value << *peteq_item_name;
  932. }
  933. }
  934. body << YAML::EndMap;
  935. return true;
  936. }
  937. // skill_db.yml function
  938. //----------------------
  939. static bool skill_parse_row_requiredb( char* split[], size_t columns, size_t current ){
  940. s_skill_require entry = {};
  941. skill_split_atoi(split[1], entry.hp);
  942. skill_split_atoi(split[2], entry.mhp);
  943. skill_split_atoi(split[3], entry.sp);
  944. skill_split_atoi(split[4], entry.hp_rate);
  945. skill_split_atoi(split[5], entry.sp_rate);
  946. skill_split_atoi(split[6], entry.zeny);
  947. char *p;
  948. p = split[7];
  949. while (p) {
  950. int32 l = atoi(p);
  951. if (l == 99) { // Any weapon
  952. entry.weapon = 0;
  953. break;
  954. } else
  955. entry.weapon |= 1 << l;
  956. p = strchr(p, ':');
  957. if (!p)
  958. break;
  959. p++;
  960. }
  961. p = split[8];
  962. while (p) {
  963. int32 l = atoi(p);
  964. if (l == 99) { // Any ammo type
  965. entry.ammo = AMMO_TYPE_ALL;
  966. break;
  967. } else if (l) // 0 stands for no requirement
  968. entry.ammo |= 1 << l;
  969. p = strchr(p, ':');
  970. if (!p)
  971. break;
  972. p++;
  973. }
  974. skill_split_atoi(split[9], entry.ammo_qty);
  975. if (strcmpi(split[10], "hidden") == 0) entry.state = ST_HIDDEN;
  976. else if (strcmpi(split[10], "riding") == 0) entry.state = ST_RIDING;
  977. else if (strcmpi(split[10], "falcon") == 0) entry.state = ST_FALCON;
  978. else if (strcmpi(split[10], "cart") == 0) entry.state = ST_CART;
  979. else if (strcmpi(split[10], "shield") == 0) entry.state = ST_SHIELD;
  980. else if (strcmpi(split[10], "recover_weight_rate") == 0) entry.state = ST_RECOVER_WEIGHT_RATE;
  981. else if (strcmpi(split[10], "move_enable") == 0) entry.state = ST_MOVE_ENABLE;
  982. else if (strcmpi(split[10], "water") == 0) entry.state = ST_WATER;
  983. else if (strcmpi(split[10], "dragon") == 0) entry.state = ST_RIDINGDRAGON;
  984. else if (strcmpi(split[10], "warg") == 0) entry.state = ST_WUG;
  985. else if (strcmpi(split[10], "ridingwarg") == 0) entry.state = ST_RIDINGWUG;
  986. else if (strcmpi(split[10], "mado") == 0) entry.state = ST_MADO;
  987. else if (strcmpi(split[10], "elementalspirit") == 0) entry.state = ST_ELEMENTALSPIRIT;
  988. else if (strcmpi(split[10], "elementalspirit2") == 0) entry.state = ST_ELEMENTALSPIRIT2;
  989. else if (strcmpi(split[10], "peco") == 0) entry.state = ST_PECO;
  990. else if (strcmpi(split[10], "sunstance") == 0) entry.state = ST_SUNSTANCE;
  991. else if (strcmpi(split[10], "moonstance") == 0) entry.state = ST_MOONSTANCE;
  992. else if (strcmpi(split[10], "starstance") == 0) entry.state = ST_STARSTANCE;
  993. else if (strcmpi(split[10], "universestance") == 0) entry.state = ST_UNIVERSESTANCE;
  994. else entry.state = ST_NONE; // Unknown or no state
  995. trim(split[11]);
  996. if (split[11][0] != '\0' || atoi(split[11])) {
  997. int64 require[MAX_SKILL_STATUS_REQUIRE];
  998. int32 count;
  999. if ((count = skill_split_atoi2(split[11], require, ":", SC_STONE, ARRAYLENGTH(require)))) {
  1000. for (int32 i = 0; i < count; i++) {
  1001. entry.status.push_back((sc_type)require[i]);
  1002. }
  1003. }
  1004. }
  1005. skill_split_atoi(split[12], entry.spiritball);
  1006. for (int32 i = 0; i < MAX_SKILL_ITEM_REQUIRE; i++) {
  1007. if (atoi(split[13 + 2 * i]) > 0) {
  1008. t_itemid item_id = strtoul( split[13 + 2 * i], nullptr, 10 );
  1009. std::string *item_name = util::umap_find(aegis_itemnames, item_id);
  1010. if (item_name == nullptr) {
  1011. ShowError("Item name for item id %u is not known.\n", item_id);
  1012. return false;
  1013. }
  1014. entry.itemid[i] = item_id;
  1015. entry.amount[i] = atoi(split[14 + 2 * i]);
  1016. }
  1017. }
  1018. trim(split[33]);
  1019. if (split[33][0] != '\0' || atoi(split[33])) {
  1020. int64 require[MAX_SKILL_EQUIP_REQUIRE];
  1021. int32 count;
  1022. if ((count = skill_split_atoi2(split[33], require, ":", 500, ARRAYLENGTH(require)))) {
  1023. for (int32 i = 0; i < count; i++) {
  1024. if (require[i] > 0)
  1025. entry.eqItem.push_back(static_cast<int32>(require[i]));
  1026. }
  1027. }
  1028. }
  1029. skill_require.insert({ atoi(split[0]), entry });
  1030. return true;
  1031. }
  1032. // skill_db.yml function
  1033. //----------------------
  1034. static bool skill_parse_row_castdb( char* split[], size_t columns, size_t current ){
  1035. s_skill_db entry = {};
  1036. skill_split_atoi(split[1], entry.cast);
  1037. skill_split_atoi(split[2], entry.delay);
  1038. skill_split_atoi(split[3], entry.walkdelay);
  1039. skill_split_atoi(split[4], entry.upkeep_time);
  1040. skill_split_atoi(split[5], entry.upkeep_time2);
  1041. skill_split_atoi(split[6], entry.cooldown);
  1042. #ifdef RENEWAL_CAST
  1043. skill_split_atoi(split[7], (int32 *)entry.fixed_cast);
  1044. #endif
  1045. skill_cast.insert({ atoi(split[0]), entry });
  1046. return true;
  1047. }
  1048. // skill_db.yml function
  1049. //----------------------
  1050. static bool skill_parse_row_castnodexdb( char* split[], size_t columns, size_t current ){
  1051. s_skill_db entry = {};
  1052. entry.castnodex = atoi(split[1]);
  1053. if (split[2]) // optional column
  1054. entry.delaynodex = atoi(split[2]);
  1055. skill_castnodex.insert({ atoi(split[0]), entry });
  1056. return true;
  1057. }
  1058. // skill_db.yml function
  1059. //----------------------
  1060. static bool skill_parse_row_unitdb( char* split[], size_t columns, size_t current ){
  1061. s_skill_unit_csv entry = {};
  1062. entry.unit_id = (uint16)strtol(split[1], nullptr, 16);
  1063. entry.unit_id2 = (uint16)strtol(split[2], nullptr, 16);
  1064. skill_split_atoi(split[3], entry.unit_layout_type);
  1065. skill_split_atoi(split[4], entry.unit_range);
  1066. entry.unit_interval = atoi(split[5]);
  1067. entry.target_str = trim(split[6]);
  1068. entry.unit_flag_csv = strtol(split[7], nullptr, 16);
  1069. skill_unit.insert({ atoi(split[0]), entry });
  1070. return true;
  1071. }
  1072. // skill_db.yml function
  1073. //----------------------
  1074. static bool skill_parse_row_copyabledb( char* split[], size_t column, size_t current ){
  1075. s_skill_copyable entry = {};
  1076. int32 skill_id = -1;
  1077. trim(split[0]);
  1078. if (ISDIGIT(split[0][0]))
  1079. skill_id = atoi(split[0]);
  1080. else {
  1081. for (const auto &it : aegis_skillnames) {
  1082. if (it.second == split[0])
  1083. skill_id = it.first;
  1084. }
  1085. if (skill_id == -1) {
  1086. ShowError("Skill %s is unknown.\n", split[0]);
  1087. return false;
  1088. }
  1089. }
  1090. entry.option = atoi(split[1]);
  1091. entry.req_opt = cap_value(atoi(split[3]), 0, (0x2000) - 1);
  1092. skill_copyable.insert({ skill_id, entry });
  1093. return true;
  1094. }
  1095. // skill_db.yml function
  1096. //----------------------
  1097. static bool skill_parse_row_nonearnpcrangedb( char* split[], size_t column, size_t current ){
  1098. s_skill_db entry = {};
  1099. int32 skill_id = -1;
  1100. trim(split[0]);
  1101. if (ISDIGIT(split[0][0]))
  1102. skill_id = atoi(split[0]);
  1103. else {
  1104. for (const auto &it : aegis_skillnames) {
  1105. if (it.second == split[0])
  1106. skill_id = it.first;
  1107. }
  1108. if (skill_id == -1) {
  1109. ShowError("Skill %s is unknown.\n", split[0]);
  1110. return false;
  1111. }
  1112. }
  1113. entry.unit_nonearnpc_range = max(atoi(split[1]), 0);
  1114. entry.unit_nonearnpc_type = (atoi(split[2])) ? cap_value(atoi(split[2]), 1, 15) : 15;
  1115. skill_nearnpc.insert({ skill_id, entry });
  1116. return true;
  1117. }
  1118. // Copied and adjusted from skill.cpp
  1119. static bool skill_parse_row_skilldb( char* split[], size_t columns, size_t current ){
  1120. int32 arr[MAX_SKILL_LEVEL], arr_size, skill_id = atoi(split[0]);
  1121. body << YAML::BeginMap;
  1122. body << YAML::Key << "Id" << YAML::Value << skill_id;
  1123. body << YAML::Key << "Name" << YAML::Value << trim(split[16]);
  1124. body << YAML::Key << "Description" << YAML::Value << trim(split[17]);
  1125. body << YAML::Key << "MaxLevel" << YAML::Value << atoi(split[7]);
  1126. if (strcmpi(split[13], "weapon") == 0)
  1127. body << YAML::Key << "Type" << YAML::Value << "Weapon";
  1128. else if (strcmpi(split[13], "magic") == 0)
  1129. body << YAML::Key << "Type" << YAML::Value << "Magic";
  1130. else if (strcmpi(split[13], "misc") == 0)
  1131. body << YAML::Key << "Type" << YAML::Value << "Misc";
  1132. std::string constant;
  1133. if (atoi(split[3]) != 0) {
  1134. constant = constant_lookup(atoi(split[3]), "INF_");
  1135. constant.erase(0, 4);
  1136. constant.erase(constant.size() - 6);
  1137. body << YAML::Key << "TargetType" << YAML::Value << name2Upper(constant);
  1138. }
  1139. uint64 nk_val = strtol(split[5], nullptr, 0);
  1140. if (nk_val) {
  1141. body << YAML::Key << "DamageFlags";
  1142. body << YAML::BeginMap;
  1143. if (nk_val & 0x1)
  1144. body << YAML::Key << "NoDamage" << YAML::Value << "true";
  1145. if (nk_val & 0x2)
  1146. body << YAML::Key << "Splash" << YAML::Value << "true";
  1147. if (nk_val & 0x4)
  1148. body << YAML::Key << "SplashSplit" << YAML::Value << "true";
  1149. if (nk_val & 0x8)
  1150. body << YAML::Key << "IgnoreAtkCard" << YAML::Value << "true";
  1151. if (nk_val & 0x10)
  1152. body << YAML::Key << "IgnoreElement" << YAML::Value << "true";
  1153. if (nk_val & 0x20)
  1154. body << YAML::Key << "IgnoreDefense" << YAML::Value << "true";
  1155. if (nk_val & 0x40)
  1156. body << YAML::Key << "IgnoreFlee" << YAML::Value << "true";
  1157. if (nk_val & 0x80)
  1158. body << YAML::Key << "IgnoreDefCard" << YAML::Value << "true";
  1159. if (nk_val & 0x100)
  1160. body << YAML::Key << "Critical" << YAML::Value << "true";
  1161. body << YAML::EndMap;
  1162. }
  1163. uint64 inf2_val = strtol(split[11], nullptr, 0);
  1164. uint64 inf3_val = strtol(split[15], nullptr, 0);
  1165. if (inf2_val || inf3_val) {
  1166. body << YAML::Key << "Flags";
  1167. body << YAML::BeginMap;
  1168. if (inf2_val & 0x1)
  1169. body << YAML::Key << "IsQuest" << YAML::Value << "true";
  1170. if (inf2_val & 0x2)
  1171. body << YAML::Key << "IsNpc" << YAML::Value << "true";
  1172. if (inf2_val & 0x4)
  1173. body << YAML::Key << "IsWedding" << YAML::Value << "true";
  1174. if (inf2_val & 0x8)
  1175. body << YAML::Key << "IsSpirit" << YAML::Value << "true";
  1176. if (inf2_val & 0x10)
  1177. body << YAML::Key << "IsGuild" << YAML::Value << "true";
  1178. if (inf2_val & 0x20)
  1179. body << YAML::Key << "IsSong" << YAML::Value << "true";
  1180. if (inf2_val & 0x40)
  1181. body << YAML::Key << "IsEnsemble" << YAML::Value << "true";
  1182. if (inf2_val & 0x80)
  1183. body << YAML::Key << "IsTrap" << YAML::Value << "true";
  1184. if (inf2_val & 0x100)
  1185. body << YAML::Key << "TargetSelf" << YAML::Value << "true";
  1186. if (inf2_val & 0x200)
  1187. body << YAML::Key << "NoTargetSelf" << YAML::Value << "true";
  1188. if (inf2_val & 0x400)
  1189. body << YAML::Key << "PartyOnly" << YAML::Value << "true";
  1190. if (inf2_val & 0x800)
  1191. body << YAML::Key << "GuildOnly" << YAML::Value << "true";
  1192. if (inf2_val & 0x1000)
  1193. body << YAML::Key << "NoTargetEnemy" << YAML::Value << "true";
  1194. if (inf2_val & 0x2000)
  1195. body << YAML::Key << "IsAutoShadowSpell" << YAML::Value << "true";
  1196. if (inf2_val & 0x4000)
  1197. body << YAML::Key << "IsChorus" << YAML::Value << "true";
  1198. if (inf2_val & 0x8000)
  1199. body << YAML::Key << "IgnoreBgReduction" << YAML::Value << "true";
  1200. if (inf2_val & 0x10000)
  1201. body << YAML::Key << "IgnoreGvgReduction" << YAML::Value << "true";
  1202. if (inf2_val & 0x20000)
  1203. body << YAML::Key << "DisableNearNpc" << YAML::Value << "true";
  1204. if (inf2_val & 0x40000)
  1205. body << YAML::Key << "TargetTrap" << YAML::Value << "true"; // ?
  1206. if (inf3_val & 0x1)
  1207. body << YAML::Key << "IgnoreLandProtector" << YAML::Value << "true";
  1208. if (inf3_val & 0x4)
  1209. body << YAML::Key << "AllowWhenHidden" << YAML::Value << "true";
  1210. if (inf3_val & 0x8)
  1211. body << YAML::Key << "AllowWhenPerforming" << YAML::Value << "true";
  1212. if (inf3_val & 0x10)
  1213. body << YAML::Key << "TargetEmperium" << YAML::Value << "true";
  1214. if (inf3_val & 0x40)
  1215. body << YAML::Key << "IgnoreKagehumi" << YAML::Value << "true";
  1216. if (inf3_val & 0x80)
  1217. body << YAML::Key << "AlterRangeVulture" << YAML::Value << "true";
  1218. if (inf3_val & 0x100)
  1219. body << YAML::Key << "AlterRangeSnakeEye" << YAML::Value << "true";
  1220. if (inf3_val & 0x200)
  1221. body << YAML::Key << "AlterRangeShadowJump" << YAML::Value << "true";
  1222. if (inf3_val & 0x400)
  1223. body << YAML::Key << "AlterRangeRadius" << YAML::Value << "true";
  1224. if (inf3_val & 0x800)
  1225. body << YAML::Key << "AlterRangeResearchTrap" << YAML::Value << "true";
  1226. if (inf3_val & 0x1000)
  1227. body << YAML::Key << "IgnoreHovering" << YAML::Value << "true";
  1228. if (inf3_val & 0x2000)
  1229. body << YAML::Key << "AllowOnWarg" << YAML::Value << "true";
  1230. if (inf3_val & 0x4000)
  1231. body << YAML::Key << "AllowOnMado" << YAML::Value << "true";
  1232. if (inf3_val & 0x8000)
  1233. body << YAML::Key << "TargetManHole" << YAML::Value << "true";
  1234. if (inf3_val & 0x10000)
  1235. body << YAML::Key << "TargetHidden" << YAML::Value << "true";
  1236. if (inf3_val & 0x40000)
  1237. body << YAML::Key << "IncreaseDanceWithWugDamage" << YAML::Value << "true";
  1238. if (inf3_val & 0x80000)
  1239. body << YAML::Key << "IgnoreWugBite" << YAML::Value << "true";
  1240. if (inf3_val & 0x100000)
  1241. body << YAML::Key << "IgnoreAutoGuard" << YAML::Value << "true";
  1242. if (inf3_val & 0x200000)
  1243. body << YAML::Key << "IgnoreCicada" << YAML::Value << "true";
  1244. body << YAML::EndMap;
  1245. }
  1246. memset(arr, 0, sizeof(arr));
  1247. arr_size = skill_split_atoi(split[1], arr);
  1248. if (arr_size != 0) {
  1249. if (arr_size == 1) {
  1250. if (arr[0] != 0) {
  1251. body << YAML::Key << "Range";
  1252. body << YAML::Value << arr[0];
  1253. }
  1254. } else {
  1255. body << YAML::Key << "Range";
  1256. body << YAML::BeginSeq;
  1257. for (int32 i = 0; i < arr_size; i++) {
  1258. body << YAML::BeginMap;
  1259. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1260. body << YAML::Key << "Size" << YAML::Value << arr[i];
  1261. body << YAML::EndMap;
  1262. }
  1263. body << YAML::EndSeq;
  1264. }
  1265. }
  1266. if (atoi(split[2]) != 0) {
  1267. constant = constant_lookup(atoi(split[2]), "DMG_");
  1268. constant.erase(0, 4);
  1269. body << YAML::Key << "Hit" << YAML::Value << name2Upper(constant);
  1270. }
  1271. memset(arr, 0, sizeof(arr));
  1272. arr_size = skill_split_atoi(split[8], arr);
  1273. if (arr_size != 0) {
  1274. if (arr_size == 1) {
  1275. if (arr[0] != 0) {
  1276. body << YAML::Key << "HitCount";
  1277. body << YAML::Value << arr[0];
  1278. }
  1279. } else {
  1280. body << YAML::Key << "HitCount";
  1281. body << YAML::BeginSeq;
  1282. for (int32 i = 0; i < arr_size; i++) {
  1283. body << YAML::BeginMap;
  1284. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1285. body << YAML::Key << "Count" << YAML::Value << arr[i];
  1286. body << YAML::EndMap;
  1287. }
  1288. body << YAML::EndSeq;
  1289. }
  1290. }
  1291. memset(arr, 0, sizeof(arr));
  1292. arr_size = skill_split_atoi(split[4], arr);
  1293. if (arr_size != 0) {
  1294. if (arr_size == 1) {
  1295. if (arr[0] != 0){
  1296. body << YAML::Key << "Element";
  1297. if (arr[0] == -1)
  1298. body << YAML::Value << "Weapon";
  1299. else if (arr[0] == -2)
  1300. body << YAML::Value << "Endowed";
  1301. else if (arr[0] == -3)
  1302. body << YAML::Value << "Random";
  1303. else {
  1304. constant = constant_lookup(arr[0], "ELE_");
  1305. constant.erase(0, 4);
  1306. body << YAML::Value << name2Upper(constant);
  1307. }
  1308. }
  1309. } else {
  1310. body << YAML::Key << "Element";
  1311. body << YAML::BeginSeq;
  1312. for (int32 i = 0; i < arr_size; i++) {
  1313. body << YAML::BeginMap;
  1314. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1315. if (arr[i] == -1)
  1316. body << YAML::Key << "Element" << YAML::Value << "Weapon";
  1317. else if (arr[i] == -2)
  1318. body << YAML::Key << "Element" << YAML::Value << "Endowed";
  1319. else if (arr[i] == -3)
  1320. body << YAML::Key << "Element" << YAML::Value << "Random";
  1321. else {
  1322. constant = constant_lookup(arr[i], "ELE_");
  1323. constant.erase(0, 4);
  1324. body << YAML::Key << "Element" << YAML::Value << name2Upper(constant);
  1325. }
  1326. body << YAML::EndMap;
  1327. }
  1328. body << YAML::EndSeq;
  1329. }
  1330. }
  1331. memset(arr, 0, sizeof(arr));
  1332. arr_size = skill_split_atoi(split[6], arr);
  1333. if (arr_size != 0) {
  1334. if (arr_size == 1) {
  1335. if (arr[0] != 0) {
  1336. body << YAML::Key << "SplashArea";
  1337. body << YAML::Value << arr[0];
  1338. }
  1339. } else {
  1340. body << YAML::Key << "SplashArea";
  1341. body << YAML::BeginSeq;
  1342. for (int32 i = 0; i < arr_size; i++) {
  1343. body << YAML::BeginMap;
  1344. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1345. body << YAML::Key << "Area" << YAML::Value << arr[i];
  1346. body << YAML::EndMap;
  1347. }
  1348. body << YAML::EndSeq;
  1349. }
  1350. }
  1351. memset(arr, 0, sizeof(arr));
  1352. arr_size = skill_split_atoi(split[12], arr);
  1353. if (arr_size != 0) {
  1354. if (arr_size == 1) {
  1355. if (arr[0] != 0) {
  1356. body << YAML::Key << "ActiveInstance";
  1357. body << YAML::Value << arr[0];
  1358. }
  1359. } else {
  1360. body << YAML::Key << "ActiveInstance";
  1361. body << YAML::BeginSeq;
  1362. for (int32 i = 0; i < arr_size; i++) {
  1363. body << YAML::BeginMap;
  1364. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1365. body << YAML::Key << "Max" << YAML::Value << arr[i];
  1366. body << YAML::EndMap;
  1367. }
  1368. body << YAML::EndSeq;
  1369. }
  1370. }
  1371. memset(arr, 0, sizeof(arr));
  1372. arr_size = skill_split_atoi(split[14], arr);
  1373. if (arr_size != 0) {
  1374. if (arr_size == 1) {
  1375. if (arr[0] != 0) {
  1376. body << YAML::Key << "Knockback";
  1377. body << YAML::Value << arr[0];
  1378. }
  1379. } else {
  1380. body << YAML::Key << "Knockback";
  1381. body << YAML::BeginSeq;
  1382. for (int32 i = 0; i < arr_size; i++) {
  1383. body << YAML::BeginMap;
  1384. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1385. body << YAML::Key << "Amount" << YAML::Value << arr[i];
  1386. body << YAML::EndMap;
  1387. }
  1388. body << YAML::EndSeq;
  1389. }
  1390. }
  1391. auto it_copyable = skill_copyable.find(skill_id);
  1392. if (it_copyable != skill_copyable.end()) {
  1393. body << YAML::Key << "CopyFlags";
  1394. body << YAML::BeginMap;
  1395. body << YAML::Key << "Skill";
  1396. body << YAML::BeginMap;
  1397. if (it_copyable->second.option & 1)
  1398. body << YAML::Key << "Plagiarism" << YAML::Value << "true";
  1399. if (it_copyable->second.option & 2)
  1400. body << YAML::Key << "Reproduce" << YAML::Value << "true";
  1401. body << YAML::EndMap;
  1402. if (it_copyable->second.req_opt > 0) {
  1403. body << YAML::Key << "RemoveRequirement";
  1404. body << YAML::BeginMap;
  1405. if (it_copyable->second.req_opt & 0x1)
  1406. body << YAML::Key << "HpCost" << YAML::Value << "true";
  1407. if (it_copyable->second.req_opt & 0x4)
  1408. body << YAML::Key << "SpCost" << YAML::Value << "true";
  1409. if (it_copyable->second.req_opt & 0x8)
  1410. body << YAML::Key << "HpRateCost" << YAML::Value << "true";
  1411. if (it_copyable->second.req_opt & 0x10)
  1412. body << YAML::Key << "SpRateCost" << YAML::Value << "true";
  1413. if (it_copyable->second.req_opt & 0x2)
  1414. body << YAML::Key << "MaxHpTrigger" << YAML::Value << "true";
  1415. if (it_copyable->second.req_opt & 0x20)
  1416. body << YAML::Key << "ZenyCost" << YAML::Value << "true";
  1417. if (it_copyable->second.req_opt & 0x40)
  1418. body << YAML::Key << "Weapon" << YAML::Value << "true";
  1419. if (it_copyable->second.req_opt & 0x80)
  1420. body << YAML::Key << "Ammo" << YAML::Value << "true";
  1421. if (it_copyable->second.req_opt & 0x100)
  1422. body << YAML::Key << "State" << YAML::Value << "true";
  1423. if (it_copyable->second.req_opt & 0x200)
  1424. body << YAML::Key << "Status" << YAML::Value << "true";
  1425. if (it_copyable->second.req_opt & 0x400)
  1426. body << YAML::Key << "SpiritSphereCost" << YAML::Value << "true";
  1427. if (it_copyable->second.req_opt & 0x800)
  1428. body << YAML::Key << "ItemCost" << YAML::Value << "true";
  1429. if (it_copyable->second.req_opt & 0x1000)
  1430. body << YAML::Key << "Equipment" << YAML::Value << "true";
  1431. body << YAML::EndMap;
  1432. }
  1433. body << YAML::EndMap;
  1434. }
  1435. auto it_nearnpc = skill_nearnpc.find(skill_id);
  1436. if (it_nearnpc != skill_nearnpc.end()) {
  1437. body << YAML::Key << "NoNearNPC";
  1438. body << YAML::BeginMap;
  1439. if (it_nearnpc->second.unit_nonearnpc_range > 0)
  1440. body << YAML::Key << "AdditionalRange" << YAML::Value << it_nearnpc->second.unit_nonearnpc_range;
  1441. if (it_nearnpc->second.unit_nonearnpc_type > 0) {
  1442. body << YAML::Key << "Type";
  1443. body << YAML::BeginMap;
  1444. if (it_nearnpc->second.unit_nonearnpc_type & 1)
  1445. body << YAML::Key << "WarpPortal" << YAML::Value << "true";
  1446. if (it_nearnpc->second.unit_nonearnpc_type & 2)
  1447. body << YAML::Key << "Shop" << YAML::Value << "true";
  1448. if (it_nearnpc->second.unit_nonearnpc_type & 4)
  1449. body << YAML::Key << "Npc" << YAML::Value << "true";
  1450. if (it_nearnpc->second.unit_nonearnpc_type & 8)
  1451. body << YAML::Key << "Tomb" << YAML::Value << "true";
  1452. body << YAML::EndMap;
  1453. }
  1454. body << YAML::EndMap;
  1455. }
  1456. if (strcmpi(split[9], "yes") != 0)
  1457. body << YAML::Key << "CastCancel" << YAML::Value << "false";
  1458. if (atoi(split[10]) != 0)
  1459. body << YAML::Key << "CastDefenseReduction" << YAML::Value << atoi(split[10]);
  1460. auto it_cast = skill_cast.find(skill_id);
  1461. if (it_cast != skill_cast.end()) {
  1462. if (!isMultiLevel(it_cast->second.cast)) {
  1463. if (it_cast->second.cast[0] > 0)
  1464. body << YAML::Key << "CastTime" << YAML::Value << it_cast->second.cast[0];
  1465. } else {
  1466. body << YAML::Key << "CastTime";
  1467. body << YAML::BeginSeq;
  1468. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.cast); i++) {
  1469. if (it_cast->second.cast[i] > 0) {
  1470. body << YAML::BeginMap;
  1471. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1472. body << YAML::Key << "Time" << YAML::Value << it_cast->second.cast[i];
  1473. body << YAML::EndMap;
  1474. }
  1475. }
  1476. body << YAML::EndSeq;
  1477. }
  1478. if (!isMultiLevel(it_cast->second.delay)) {
  1479. if (it_cast->second.delay[0] > 0)
  1480. body << YAML::Key << "AfterCastActDelay" << YAML::Value << it_cast->second.delay[0];
  1481. } else {
  1482. body << YAML::Key << "AfterCastActDelay";
  1483. body << YAML::BeginSeq;
  1484. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.delay); i++) {
  1485. if (it_cast->second.delay[i] > 0) {
  1486. body << YAML::BeginMap;
  1487. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1488. body << YAML::Key << "Time" << YAML::Value << it_cast->second.delay[i];
  1489. body << YAML::EndMap;
  1490. }
  1491. }
  1492. body << YAML::EndSeq;
  1493. }
  1494. if (!isMultiLevel(it_cast->second.walkdelay)) {
  1495. if (it_cast->second.walkdelay[0] > 0)
  1496. body << YAML::Key << "AfterCastWalkDelay" << YAML::Value << it_cast->second.walkdelay[0];
  1497. } else {
  1498. body << YAML::Key << "AfterCastWalkDelay";
  1499. body << YAML::BeginSeq;
  1500. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.walkdelay); i++) {
  1501. if (it_cast->second.walkdelay[i] > 0) {
  1502. body << YAML::BeginMap;
  1503. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1504. body << YAML::Key << "Time" << YAML::Value << it_cast->second.walkdelay[i];
  1505. body << YAML::EndMap;
  1506. }
  1507. }
  1508. body << YAML::EndSeq;
  1509. }
  1510. if (!isMultiLevel(it_cast->second.upkeep_time)) {
  1511. if (it_cast->second.upkeep_time[0] != 0)
  1512. body << YAML::Key << "Duration1" << YAML::Value << it_cast->second.upkeep_time[0];
  1513. } else {
  1514. body << YAML::Key << "Duration1";
  1515. body << YAML::BeginSeq;
  1516. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.upkeep_time); i++) {
  1517. if (it_cast->second.upkeep_time[i] != 0) {
  1518. body << YAML::BeginMap;
  1519. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1520. body << YAML::Key << "Time" << YAML::Value << it_cast->second.upkeep_time[i];
  1521. body << YAML::EndMap;
  1522. }
  1523. }
  1524. body << YAML::EndSeq;
  1525. }
  1526. if (!isMultiLevel(it_cast->second.upkeep_time2)) {
  1527. if (it_cast->second.upkeep_time2[0] != 0)
  1528. body << YAML::Key << "Duration2" << YAML::Value << it_cast->second.upkeep_time2[0];
  1529. } else {
  1530. body << YAML::Key << "Duration2";
  1531. body << YAML::BeginSeq;
  1532. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.upkeep_time2); i++) {
  1533. if (it_cast->second.upkeep_time2[i] != 0) {
  1534. body << YAML::BeginMap;
  1535. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1536. body << YAML::Key << "Time" << YAML::Value << it_cast->second.upkeep_time2[i];
  1537. body << YAML::EndMap;
  1538. }
  1539. }
  1540. body << YAML::EndSeq;
  1541. }
  1542. if (!isMultiLevel(it_cast->second.cooldown)) {
  1543. if (it_cast->second.cooldown[0] > 0)
  1544. body << YAML::Key << "Cooldown" << YAML::Value << it_cast->second.cooldown[0];
  1545. } else {
  1546. body << YAML::Key << "Cooldown";
  1547. body << YAML::BeginSeq;
  1548. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.cooldown); i++) {
  1549. if (it_cast->second.cooldown[i] > 0) {
  1550. body << YAML::BeginMap;
  1551. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1552. body << YAML::Key << "Time" << YAML::Value << it_cast->second.cooldown[i];
  1553. body << YAML::EndMap;
  1554. }
  1555. }
  1556. body << YAML::EndSeq;
  1557. }
  1558. #ifdef RENEWAL_CAST
  1559. if (!isMultiLevel(it_cast->second.fixed_cast)) {
  1560. if (it_cast->second.fixed_cast[0] != 0)
  1561. body << YAML::Key << "FixedCastTime" << YAML::Value << it_cast->second.fixed_cast[0];
  1562. } else {
  1563. body << YAML::Key << "FixedCastTime";
  1564. body << YAML::BeginSeq;
  1565. for (size_t i = 0; i < ARRAYLENGTH(it_cast->second.fixed_cast); i++) {
  1566. if (it_cast->second.fixed_cast[i] != 0) {
  1567. body << YAML::BeginMap;
  1568. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1569. body << YAML::Key << "Time" << YAML::Value << it_cast->second.fixed_cast[i];
  1570. body << YAML::EndMap;
  1571. }
  1572. }
  1573. body << YAML::EndSeq;
  1574. }
  1575. #endif
  1576. }
  1577. auto it_castdex = skill_castnodex.find(skill_id);
  1578. if (it_castdex != skill_castnodex.end()) {
  1579. if (it_castdex->second.castnodex > 0) {
  1580. body << YAML::Key << "CastTimeFlags";
  1581. body << YAML::BeginMap;
  1582. if (it_castdex->second.castnodex & 1)
  1583. body << YAML::Key << "IgnoreDex" << YAML::Value << "true";
  1584. if (it_castdex->second.castnodex & 2)
  1585. body << YAML::Key << "IgnoreStatus" << YAML::Value << "true";
  1586. if (it_castdex->second.castnodex & 4)
  1587. body << YAML::Key << "IgnoreItemBonus" << YAML::Value << "true";
  1588. body << YAML::EndMap;
  1589. }
  1590. if (it_castdex->second.delaynodex > 0) {
  1591. body << YAML::Key << "CastDelayFlags";
  1592. body << YAML::BeginMap;
  1593. if (it_castdex->second.delaynodex & 1)
  1594. body << YAML::Key << "IgnoreDex" << YAML::Value << "true";
  1595. if (it_castdex->second.delaynodex & 2)
  1596. body << YAML::Key << "IgnoreStatus" << YAML::Value << "true";
  1597. if (it_castdex->second.delaynodex & 4)
  1598. body << YAML::Key << "IgnoreItemBonus" << YAML::Value << "true";
  1599. body << YAML::EndMap;
  1600. }
  1601. }
  1602. auto it_req = skill_require.find(skill_id);
  1603. if (it_req != skill_require.end()) {
  1604. body << YAML::Key << "Requires";
  1605. body << YAML::BeginMap;
  1606. if (!isMultiLevel(it_req->second.hp)) {
  1607. if (it_req->second.hp[0] > 0)
  1608. body << YAML::Key << "HpCost" << YAML::Value << it_req->second.hp[0];
  1609. } else {
  1610. body << YAML::Key << "HpCost";
  1611. body << YAML::BeginSeq;
  1612. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.hp); i++) {
  1613. if (it_req->second.hp[i] > 0) {
  1614. body << YAML::BeginMap;
  1615. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1616. body << YAML::Key << "Amount" << YAML::Value << it_req->second.hp[i];
  1617. body << YAML::EndMap;
  1618. }
  1619. }
  1620. body << YAML::EndSeq;
  1621. }
  1622. if (!isMultiLevel(it_req->second.sp)) {
  1623. if (it_req->second.sp[0] > 0)
  1624. body << YAML::Key << "SpCost" << YAML::Value << it_req->second.sp[0];
  1625. } else {
  1626. body << YAML::Key << "SpCost";
  1627. body << YAML::BeginSeq;
  1628. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.sp); i++) {
  1629. if (it_req->second.sp[i] > 0) {
  1630. body << YAML::BeginMap;
  1631. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1632. body << YAML::Key << "Amount" << YAML::Value << it_req->second.sp[i];
  1633. body << YAML::EndMap;
  1634. }
  1635. }
  1636. body << YAML::EndSeq;
  1637. }
  1638. if (!isMultiLevel(it_req->second.hp_rate)) {
  1639. if (it_req->second.hp_rate[0] != 0)
  1640. body << YAML::Key << "HpRateCost" << YAML::Value << it_req->second.hp_rate[0];
  1641. } else {
  1642. body << YAML::Key << "HpRateCost";
  1643. body << YAML::BeginSeq;
  1644. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.hp_rate); i++) {
  1645. if (it_req->second.hp_rate[i] != 0) {
  1646. body << YAML::BeginMap;
  1647. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1648. body << YAML::Key << "Amount" << YAML::Value << it_req->second.hp_rate[i];
  1649. body << YAML::EndMap;
  1650. }
  1651. }
  1652. body << YAML::EndSeq;
  1653. }
  1654. if (!isMultiLevel(it_req->second.sp_rate)) {
  1655. if (it_req->second.sp_rate[0] != 0)
  1656. body << YAML::Key << "SpRateCost" << YAML::Value << it_req->second.sp_rate[0];
  1657. } else {
  1658. body << YAML::Key << "SpRateCost";
  1659. body << YAML::BeginSeq;
  1660. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.sp_rate); i++) {
  1661. if (it_req->second.sp_rate[i] != 0) {
  1662. body << YAML::BeginMap;
  1663. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1664. body << YAML::Key << "Amount" << YAML::Value << it_req->second.sp_rate[i];
  1665. body << YAML::EndMap;
  1666. }
  1667. }
  1668. body << YAML::EndSeq;
  1669. }
  1670. if (!isMultiLevel(it_req->second.mhp)) {
  1671. if (it_req->second.mhp[0] > 0)
  1672. body << YAML::Key << "MaxHpTrigger" << YAML::Value << it_req->second.mhp[0];
  1673. } else {
  1674. body << YAML::Key << "MaxHpTrigger";
  1675. body << YAML::BeginSeq;
  1676. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.mhp); i++) {
  1677. if (it_req->second.mhp[i] > 0) {
  1678. body << YAML::BeginMap;
  1679. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1680. body << YAML::Key << "Amount" << YAML::Value << it_req->second.mhp[i];
  1681. body << YAML::EndMap;
  1682. }
  1683. }
  1684. body << YAML::EndSeq;
  1685. }
  1686. if (!isMultiLevel(it_req->second.zeny)) {
  1687. if (it_req->second.zeny[0] > 0)
  1688. body << YAML::Key << "ZenyCost" << YAML::Value << it_req->second.zeny[0];
  1689. } else {
  1690. body << YAML::Key << "ZenyCost";
  1691. body << YAML::BeginSeq;
  1692. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.zeny); i++) {
  1693. if (it_req->second.zeny[i] > 0) {
  1694. body << YAML::BeginMap;
  1695. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1696. body << YAML::Key << "Amount" << YAML::Value << it_req->second.zeny[i];
  1697. body << YAML::EndMap;
  1698. }
  1699. }
  1700. body << YAML::EndSeq;
  1701. }
  1702. if (it_req->second.weapon != 0) {
  1703. body << YAML::Key << "Weapon";
  1704. body << YAML::BeginMap;
  1705. int32 temp = it_req->second.weapon;
  1706. if (temp != 99) { // Not "All"
  1707. for (int32 i = 0; i < MAX_WEAPON_TYPE_ALL; i++) {
  1708. if (i == MAX_WEAPON_TYPE)
  1709. continue;
  1710. if (temp & 1 << i) {
  1711. constant = constant_lookup(i, "W_");
  1712. constant.erase(0, 2);
  1713. body << YAML::Key << name2Upper(constant) << YAML::Value << "true";
  1714. temp ^= 1 << i;
  1715. }
  1716. }
  1717. }
  1718. body << YAML::EndMap;
  1719. }
  1720. if (it_req->second.ammo != 0) {
  1721. body << YAML::Key << "Ammo";
  1722. body << YAML::BeginMap;
  1723. int32 temp = it_req->second.ammo;
  1724. for (int32 i = 1; i < MAX_AMMO_TYPE; i++) {
  1725. if (temp & 1 << i) {
  1726. constant = constant_lookup(i, "AMMO_");
  1727. constant.erase(0, 5);
  1728. body << YAML::Key << name2Upper(constant) << YAML::Value << "true";
  1729. temp ^= 1 << i;
  1730. }
  1731. }
  1732. body << YAML::EndMap;
  1733. }
  1734. if (!isMultiLevel(it_req->second.ammo_qty)) {
  1735. if (it_req->second.ammo_qty[0] > 0)
  1736. body << YAML::Key << "AmmoAmount" << YAML::Value << it_req->second.ammo_qty[0];
  1737. } else {
  1738. body << YAML::Key << "AmmoAmount";
  1739. body << YAML::BeginSeq;
  1740. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.ammo_qty); i++) {
  1741. if (it_req->second.ammo_qty[i] > 0) {
  1742. body << YAML::BeginMap;
  1743. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1744. body << YAML::Key << "Amount" << YAML::Value << it_req->second.ammo_qty[i];
  1745. body << YAML::EndMap;
  1746. }
  1747. }
  1748. body << YAML::EndSeq;
  1749. }
  1750. if (it_req->second.state) {
  1751. constant = constant_lookup(it_req->second.state, "ST_");
  1752. constant.erase(0, 3);
  1753. body << YAML::Key << "State" << YAML::Value << name2Upper(constant);
  1754. }
  1755. if (it_req->second.status.size() > 0) {
  1756. body << YAML::Key << "Status";
  1757. body << YAML::BeginMap;
  1758. for (const auto &it : it_req->second.status) {
  1759. constant = constant_lookup(it, "SC_");
  1760. constant.erase(0, 3);
  1761. body << YAML::Key << name2Upper(constant) << YAML::Value << "true";
  1762. }
  1763. body << YAML::EndMap;
  1764. }
  1765. if (!isMultiLevel(it_req->second.spiritball)) {
  1766. if (it_req->second.spiritball[0] != 0)
  1767. body << YAML::Key << "SpiritSphereCost" << YAML::Value << it_req->second.spiritball[0];
  1768. } else {
  1769. body << YAML::Key << "SpiritSphereCost";
  1770. body << YAML::BeginSeq;
  1771. for (size_t i = 0; i < ARRAYLENGTH(it_req->second.spiritball); i++) {
  1772. if (it_req->second.spiritball[i] != 0) {
  1773. body << YAML::BeginMap;
  1774. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1775. body << YAML::Key << "Amount" << YAML::Value << it_req->second.spiritball[i];
  1776. body << YAML::EndMap;
  1777. }
  1778. }
  1779. body << YAML::EndSeq;
  1780. }
  1781. if (it_req->second.itemid[0] > 0) {
  1782. body << YAML::Key << "ItemCost";
  1783. body << YAML::BeginSeq;
  1784. for (uint8 i = 0; i < ARRAYLENGTH(it_req->second.itemid); i++) {
  1785. if (it_req->second.itemid[i] > 0) {
  1786. body << YAML::BeginMap;
  1787. std::string *item_name = util::umap_find(aegis_itemnames, it_req->second.itemid[i]);
  1788. if (item_name == nullptr) {
  1789. ShowError("Item name for item id %hu is not known (itemcost).\n", it_req->second.itemid[i]);
  1790. return false;
  1791. }
  1792. body << YAML::Key << "Item" << YAML::Value << *item_name;
  1793. body << YAML::Key << "Amount" << YAML::Value << it_req->second.amount[i];
  1794. switch (skill_id) { // List of level dependent item costs
  1795. case WZ_FIREPILLAR:
  1796. if (i < 6)
  1797. break; // Levels 1-5 have no cost
  1798. case NC_SHAPESHIFT:
  1799. case NC_REPAIR:
  1800. if (skill_id == NC_SHAPESHIFT || (skill_id == NC_REPAIR && i >= 5))
  1801. break; // Don't add level 5 label as it exceeds the max level of these skills
  1802. case GN_FIRE_EXPANSION:
  1803. case SO_SUMMON_AGNI:
  1804. case SO_SUMMON_AQUA:
  1805. case SO_SUMMON_VENTUS:
  1806. case SO_SUMMON_TERA:
  1807. case SO_WATER_INSIGNIA:
  1808. case SO_FIRE_INSIGNIA:
  1809. case SO_WIND_INSIGNIA:
  1810. case SO_EARTH_INSIGNIA:
  1811. case KO_MAKIBISHI:
  1812. body << YAML::Key << "Level" << YAML::Value << i;
  1813. }
  1814. body << YAML::EndMap;
  1815. }
  1816. }
  1817. body << YAML::EndSeq;
  1818. }
  1819. if (it_req->second.eqItem.size() > 0) {
  1820. body << YAML::Key << "Equipment";
  1821. body << YAML::BeginMap;
  1822. for (const auto &it : it_req->second.eqItem) {
  1823. std::string *item_name = util::umap_find(aegis_itemnames, it);
  1824. if (item_name == nullptr) {
  1825. ShowError("Item name for item id %u is not known (equipment).\n", it);
  1826. return false;
  1827. }
  1828. body << YAML::Key << *item_name << YAML::Value << "true";
  1829. }
  1830. body << YAML::EndMap;
  1831. }
  1832. body << YAML::EndMap;
  1833. }
  1834. auto it_unit = skill_unit.find(skill_id);
  1835. if (it_unit != skill_unit.end()) {
  1836. body << YAML::Key << "Unit";
  1837. body << YAML::BeginMap;
  1838. constant = constant_lookup(it_unit->second.unit_id, "UNT_");
  1839. constant.erase(0, 4);
  1840. body << YAML::Key << "Id" << YAML::Value << name2Upper(constant);
  1841. if (it_unit->second.unit_id2 > 0) {
  1842. constant = constant_lookup(it_unit->second.unit_id2, "UNT_");
  1843. constant.erase(0, 4);
  1844. body << YAML::Key << "AlternateId" << YAML::Value << name2Upper(constant);
  1845. }
  1846. if (!isMultiLevel(it_unit->second.unit_layout_type)) {
  1847. if (it_unit->second.unit_layout_type[0] != 0)
  1848. body << YAML::Key << "Layout" << YAML::Value << it_unit->second.unit_layout_type[0];
  1849. } else {
  1850. body << YAML::Key << "Layout";
  1851. body << YAML::BeginSeq;
  1852. for (size_t i = 0; i < ARRAYLENGTH(it_unit->second.unit_layout_type); i++) {
  1853. if (it_unit->second.unit_layout_type[i] == 0 && i + 1 > 5)
  1854. continue;
  1855. body << YAML::BeginMap;
  1856. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1857. body << YAML::Key << "Size" << YAML::Value << it_unit->second.unit_layout_type[i];
  1858. body << YAML::EndMap;
  1859. }
  1860. body << YAML::EndSeq;
  1861. }
  1862. if (!isMultiLevel(it_unit->second.unit_range)) {
  1863. if (it_unit->second.unit_range[0] != 0)
  1864. body << YAML::Key << "Range" << YAML::Value << it_unit->second.unit_range[0];
  1865. } else {
  1866. body << YAML::Key << "Range";
  1867. body << YAML::BeginSeq;
  1868. for (size_t i = 0; i < ARRAYLENGTH(it_unit->second.unit_range); i++) {
  1869. if (it_unit->second.unit_range[i] == 0 && i + 1 > 5)
  1870. continue;
  1871. body << YAML::BeginMap;
  1872. body << YAML::Key << "Level" << YAML::Value << i + 1;
  1873. body << YAML::Key << "Size" << YAML::Value << it_unit->second.unit_range[i];
  1874. body << YAML::EndMap;
  1875. }
  1876. body << YAML::EndSeq;
  1877. }
  1878. if (it_unit->second.unit_interval != 0)
  1879. body << YAML::Key << "Interval" << YAML::Value << it_unit->second.unit_interval;
  1880. if (it_unit->second.target_str.size() > 0) {
  1881. if (it_unit->second.target_str.compare("noenemy") == 0 || it_unit->second.target_str.compare("friend") == 0)
  1882. body << YAML::Key << "Target" << YAML::Value << "Friend";
  1883. //else if (it_unit->second.target_str.compare("noenemy") == 0) // Same as Friend
  1884. // body << YAML::Key << "Target" << YAML::Value << "NoEnemy";
  1885. else if (it_unit->second.target_str.compare("party") == 0)
  1886. body << YAML::Key << "Target" << YAML::Value << "Party";
  1887. else if (it_unit->second.target_str.compare("ally") == 0)
  1888. body << YAML::Key << "Target" << YAML::Value << "Ally";
  1889. else if (it_unit->second.target_str.compare("guild") == 0)
  1890. body << YAML::Key << "Target" << YAML::Value << "Guild";
  1891. //else if (it_unit->second.target_str.compare("all") == 0)
  1892. // body << YAML::Key << "Target" << YAML::Value << "All";
  1893. else if (it_unit->second.target_str.compare("enemy") == 0)
  1894. body << YAML::Key << "Target" << YAML::Value << "Enemy";
  1895. else if (it_unit->second.target_str.compare("self") == 0)
  1896. body << YAML::Key << "Target" << YAML::Value << "Self";
  1897. else if (it_unit->second.target_str.compare("sameguild") == 0)
  1898. body << YAML::Key << "Target" << YAML::Value << "SameGuild";
  1899. }
  1900. if (it_unit->second.unit_flag_csv > 0) {
  1901. body << YAML::Key << "Flag";
  1902. body << YAML::BeginMap;
  1903. if (it_unit->second.unit_flag_csv & 0x1)
  1904. body << YAML::Value << "NoEnemy" << YAML::Value << "true";
  1905. if (it_unit->second.unit_flag_csv & 0x2)
  1906. body << YAML::Value << "NoReiteration" << YAML::Value << "true";
  1907. if (it_unit->second.unit_flag_csv & 0x4)
  1908. body << YAML::Value << "NoFootSet" << YAML::Value << "true";
  1909. if (it_unit->second.unit_flag_csv & 0x8)
  1910. body << YAML::Value << "NoOverlap" << YAML::Value << "true";
  1911. if (it_unit->second.unit_flag_csv & 0x10)
  1912. body << YAML::Value << "PathCheck" << YAML::Value << "true";
  1913. if (it_unit->second.unit_flag_csv & 0x20)
  1914. body << YAML::Value << "NoPc" << YAML::Value << "true";
  1915. if (it_unit->second.unit_flag_csv & 0x40)
  1916. body << YAML::Value << "NoMob" << YAML::Value << "true";
  1917. if (it_unit->second.unit_flag_csv & 0x80)
  1918. body << YAML::Value << "Skill" << YAML::Value << "true";
  1919. if (it_unit->second.unit_flag_csv & 0x100)
  1920. body << YAML::Value << "Dance" << YAML::Value << "true";
  1921. if (it_unit->second.unit_flag_csv & 0x200)
  1922. body << YAML::Value << "Ensemble" << YAML::Value << "true";
  1923. if (it_unit->second.unit_flag_csv & 0x400)
  1924. body << YAML::Value << "Song" << YAML::Value << "true";
  1925. if (it_unit->second.unit_flag_csv & 0x800)
  1926. body << YAML::Value << "DualMode" << YAML::Value << "true";
  1927. if (it_unit->second.unit_flag_csv & 0x1000)
  1928. body << YAML::Value << "NoKnockback" << YAML::Value << "true";
  1929. if (it_unit->second.unit_flag_csv & 0x2000)
  1930. body << YAML::Value << "RangedSingleUnit" << YAML::Value << "true";
  1931. if (it_unit->second.unit_flag_csv & 0x4000)
  1932. body << YAML::Value << "CrazyWeedImmune" << YAML::Value << "true";
  1933. if (it_unit->second.unit_flag_csv & 0x8000)
  1934. body << YAML::Value << "RemovedByFireRain" << YAML::Value << "true";
  1935. if (it_unit->second.unit_flag_csv & 0x10000)
  1936. body << YAML::Value << "KnockbackGroup" << YAML::Value << "true";
  1937. if (it_unit->second.unit_flag_csv & 0x20000)
  1938. body << YAML::Value << "HiddenTrap" << YAML::Value << "true";
  1939. body << YAML::EndMap;
  1940. }
  1941. body << YAML::EndMap;
  1942. }
  1943. body << YAML::EndMap;
  1944. return true;
  1945. }
  1946. // Copied and adjusted from quest.cpp
  1947. static bool quest_read_db( char *split[], size_t columns, size_t current ){
  1948. int32 quest_id = atoi(split[0]);
  1949. if (quest_id < 0 || quest_id >= INT_MAX) {
  1950. ShowError("quest_read_db: Invalid quest ID '%d'.\n", quest_id);
  1951. return false;
  1952. }
  1953. body << YAML::BeginMap;
  1954. body << YAML::Key << "Id" << YAML::Value << quest_id;
  1955. std::string title = split[17];
  1956. if (columns > 18) { // If the title has a comma in it, concatenate
  1957. size_t col = 18;
  1958. while (col < columns) {
  1959. title += ',' + std::string(split[col]);
  1960. col++;
  1961. }
  1962. }
  1963. title.erase(std::remove(title.begin(), title.end(), '"'), title.end()); // Strip double quotes out
  1964. body << YAML::Key << "Title" << YAML::Value << title;
  1965. if (strchr(split[1], ':') == nullptr) {
  1966. uint32 time = atoi(split[1]);
  1967. if (time > 0) {
  1968. int32 day = time / 86400;
  1969. time %= (24 * 3600);
  1970. int32 hour = time / 3600;
  1971. time %= 3600;
  1972. int32 minute = time / 60;
  1973. time %= 60;
  1974. int32 second = time;
  1975. std::string output = "+";
  1976. if (day > 0)
  1977. output += std::to_string(day) + "d";
  1978. if (hour > 0)
  1979. output += std::to_string(hour) + "h";
  1980. if (minute > 0)
  1981. output += std::to_string(minute) + "mn";
  1982. if (second > 0)
  1983. output += std::to_string(second) + "s";
  1984. body << YAML::Key << "TimeLimit" << YAML::Value << output;
  1985. }
  1986. } else {
  1987. if (*split[1]) {
  1988. std::string time_str(split[1]), hour = time_str.substr(0, time_str.find(':')), output = {};
  1989. time_str.erase(0, 3); // Remove "HH:"
  1990. if (std::stoi(hour) > 0)
  1991. output = std::to_string(std::stoi(hour)) + "h";
  1992. if (std::stoi(time_str) > 0)
  1993. output += std::to_string(std::stoi(time_str)) + "mn";
  1994. body << YAML::Key << "TimeLimit" << YAML::Value << output; // No quests in TXT format had days, default to 0
  1995. }
  1996. }
  1997. if (atoi(split[2]) > 0) {
  1998. body << YAML::Key << "Targets";
  1999. body << YAML::BeginSeq;
  2000. for (size_t i = 0; i < MAX_QUEST_OBJECTIVES; i++) {
  2001. int32 mob_id = (int32)atoi(split[i * 2 + 2]), count = atoi(split[i * 2 + 3]);
  2002. if (!mob_id || !count)
  2003. continue;
  2004. std::string *mob_name = util::umap_find(aegis_mobnames, static_cast<uint16>(mob_id));
  2005. if (!mob_name) {
  2006. ShowError("quest_read_db: Invalid mob-class %hu, target not read.\n", mob_id);
  2007. continue;
  2008. }
  2009. body << YAML::BeginMap;
  2010. body << YAML::Key << "Mob" << YAML::Value << *mob_name;
  2011. body << YAML::Key << "Count" << YAML::Value << count;
  2012. body << YAML::EndMap;
  2013. }
  2014. body << YAML::EndSeq;
  2015. }
  2016. if (atoi(split[2 * MAX_QUEST_OBJECTIVES + 2]) > 0) {
  2017. body << YAML::Key << "Drops";
  2018. body << YAML::BeginSeq;
  2019. for (size_t i = 0; i < MAX_QUEST_DROPS; i++) {
  2020. int32 mob_id = (int32)atoi(split[3 * i + (2 * MAX_QUEST_OBJECTIVES + 2)]);
  2021. t_itemid nameid = strtoul(split[3 * i + (2 * MAX_QUEST_OBJECTIVES + 3)], nullptr, 10);
  2022. if (!mob_id || !nameid)
  2023. continue;
  2024. std::string *mob_name = util::umap_find(aegis_mobnames, static_cast<uint16>(mob_id));
  2025. if (!mob_name) {
  2026. ShowError("quest_read_db: Invalid mob-class %hu, drop not read.\n", mob_id);
  2027. continue;
  2028. }
  2029. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  2030. if (!item_name) {
  2031. ShowError("quest_read_db: Invalid item name %u, drop not read.\n", nameid);
  2032. return false;
  2033. }
  2034. body << YAML::BeginMap;
  2035. body << YAML::Key << "Mob" << YAML::Value << *mob_name;
  2036. body << YAML::Key << "Item" << YAML::Value << *item_name;
  2037. //body << YAML::Key << "Count" << YAML::Value << 1; // Default is 1
  2038. body << YAML::Key << "Rate" << YAML::Value << atoi(split[3 * i + (2 * MAX_QUEST_OBJECTIVES + 4)]);
  2039. body << YAML::EndMap;
  2040. }
  2041. body << YAML::EndSeq;
  2042. }
  2043. body << YAML::EndMap;
  2044. return true;
  2045. }
  2046. // Copied and adjusted from instance.cpp
  2047. static bool instance_readdb_sub( char* str[], size_t columns, size_t current ){
  2048. body << YAML::BeginMap;
  2049. body << YAML::Key << "Id" << YAML::Value << atoi(str[0]);
  2050. body << YAML::Key << "Name" << YAML::Value << str[1];
  2051. if (atoi(str[2]) != 3600)
  2052. body << YAML::Key << "TimeLimit" << YAML::Value << atoi(str[2]);
  2053. if (atoi(str[3]) != 300)
  2054. body << YAML::Key << "IdleTimeOut" << YAML::Value << atoi(str[3]);
  2055. body << YAML::Key << "Enter";
  2056. body << YAML::BeginMap;
  2057. body << YAML::Key << "Map" << YAML::Value << str[4];
  2058. body << YAML::Key << "X" << YAML::Value << atoi(str[5]);
  2059. body << YAML::Key << "Y" << YAML::Value << atoi(str[6]);
  2060. body << YAML::EndMap;
  2061. if (columns > 7) {
  2062. body << YAML::Key << "AdditionalMaps";
  2063. body << YAML::BeginMap;
  2064. for( size_t i = 7; i < columns; i++ ){
  2065. if (!strlen(str[i]))
  2066. continue;
  2067. if (strcmpi(str[4], str[i]) == 0)
  2068. continue;
  2069. body << YAML::Key << str[i] << YAML::Value << "true";
  2070. }
  2071. body << YAML::EndMap;
  2072. }
  2073. body << YAML::EndMap;
  2074. return true;
  2075. }
  2076. // item_db.yml function
  2077. //---------------------
  2078. static bool itemdb_read_itemavail( char *str[], size_t columns, size_t current ){
  2079. item_avail.insert({ strtoul(str[0], nullptr, 10), strtoul(str[1], nullptr, 10) });
  2080. return true;
  2081. }
  2082. // item_db.yml function
  2083. //---------------------
  2084. static bool itemdb_read_buyingstore( char* fields[], size_t columns, size_t current ){
  2085. item_buyingstore.insert({ strtoul(fields[0], nullptr, 10), true });
  2086. return true;
  2087. }
  2088. // item_db.yml function
  2089. //---------------------
  2090. static bool itemdb_read_flag( char* fields[], size_t columns, size_t current ){
  2091. s_item_flag_csv2yaml item = { 0 };
  2092. uint16 flag = abs(atoi(fields[1]));
  2093. if (flag & 1)
  2094. item.dead_branch = true;
  2095. if (flag & 2)
  2096. item.group = true;
  2097. if (flag & 4)
  2098. item.guid = true;
  2099. if (flag & 8)
  2100. item.bindOnEquip = true;
  2101. if (flag & 16)
  2102. item.broadcast = true;
  2103. if (flag & 32)
  2104. item.delay_consume = true;
  2105. if (flag & 64)
  2106. item.dropEffect = DROPEFFECT_CLIENT;
  2107. else if (flag & 128)
  2108. item.dropEffect = DROPEFFECT_WHITE_PILLAR;
  2109. else if (flag & 256)
  2110. item.dropEffect = DROPEFFECT_BLUE_PILLAR;
  2111. else if (flag & 512)
  2112. item.dropEffect = DROPEFFECT_YELLOW_PILLAR;
  2113. else if (flag & 1024)
  2114. item.dropEffect = DROPEFFECT_PURPLE_PILLAR;
  2115. else if (flag & 2048)
  2116. item.dropEffect = DROPEFFECT_ORANGE_PILLAR;
  2117. item_flag.insert({ strtoul(fields[0], nullptr, 10), item });
  2118. return true;
  2119. }
  2120. // item_db.yml function
  2121. //---------------------
  2122. static bool itemdb_read_itemdelay( char* str[], size_t columns, size_t current ){
  2123. s_item_delay_csv2yaml item = { 0 };
  2124. item.delay = atoi(str[1]);
  2125. if (columns == 3)
  2126. item.sc = trim(str[2]);
  2127. item_delay.insert({ strtoul(str[0], nullptr, 10), item });
  2128. return true;
  2129. }
  2130. // item_db.yml function
  2131. //---------------------
  2132. static bool itemdb_read_stack( char* fields[], size_t columns, size_t current ){
  2133. s_item_stack_csv2yaml item = { 0 };
  2134. item.amount = atoi(fields[1]);
  2135. int32 type = strtoul(fields[2], nullptr, 10);
  2136. if (type & 1)
  2137. item.inventory = true;
  2138. if (type & 2)
  2139. item.cart = true;
  2140. if (type & 4)
  2141. item.storage = true;
  2142. if (type & 8)
  2143. item.guild_storage = true;
  2144. item_stack.insert({ strtoul(fields[0], nullptr, 10), item });
  2145. return true;
  2146. }
  2147. // item_db.yml function
  2148. //---------------------
  2149. static bool itemdb_read_nouse( char* fields[], size_t columns, size_t current ){
  2150. s_item_nouse_csv2yaml item = { 0 };
  2151. item.sitting = "true";
  2152. item.override = atoi(fields[2]);
  2153. item_nouse.insert({ strtoul(fields[0], nullptr, 10), item });
  2154. return true;
  2155. }
  2156. // item_db.yml function
  2157. //---------------------
  2158. static bool itemdb_read_itemtrade( char* str[], size_t columns, size_t current ){
  2159. s_item_trade_csv2yaml item = { 0 };
  2160. int32 flag = atoi(str[1]);
  2161. if (flag & 1)
  2162. item.drop = true;
  2163. if (flag & 2)
  2164. item.trade = true;
  2165. if (flag & 4)
  2166. item.trade_partner = true;
  2167. if (flag & 8)
  2168. item.sell = true;
  2169. if (flag & 16)
  2170. item.cart = true;
  2171. if (flag & 32)
  2172. item.storage = true;
  2173. if (flag & 64)
  2174. item.guild_storage = true;
  2175. if (flag & 128)
  2176. item.mail = true;
  2177. if (flag & 256)
  2178. item.auction = true;
  2179. item.override = atoi(str[2]);
  2180. item_trade.insert({ strtoul(str[0], nullptr, 10), item });
  2181. return true;
  2182. }
  2183. // Copied and adjusted from itemdb.cpp
  2184. static bool itemdb_read_db(const char* file) {
  2185. FILE* fp = fopen(file, "r");
  2186. if (fp == nullptr) {
  2187. ShowError("can't read %s\n", file);
  2188. return false;
  2189. }
  2190. int32 lines = 0;
  2191. size_t entries = 0;
  2192. char line[1024];
  2193. while (fgets(line, sizeof(line), fp)) {
  2194. char* str[32], * p;
  2195. int32 i;
  2196. lines++;
  2197. if (line[0] == '/' && line[1] == '/')
  2198. continue;
  2199. memset(str, 0, sizeof(str));
  2200. p = strstr(line, "//");
  2201. if (p != nullptr) {
  2202. *p = '\0';
  2203. }
  2204. p = line;
  2205. while (ISSPACE(*p))
  2206. ++p;
  2207. if (*p == '\0')
  2208. continue;// empty line
  2209. for (i = 0; i < 19; ++i) {
  2210. str[i] = p;
  2211. p = strchr(p, ',');
  2212. if (p == nullptr)
  2213. break;// comma not found
  2214. *p = '\0';
  2215. ++p;
  2216. }
  2217. if (p == nullptr) {
  2218. ShowError("itemdb_read_db: Insufficient columns in line %d (item with id %lu), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2219. continue;
  2220. }
  2221. // Script
  2222. if (*p != '{') {
  2223. ShowError("itemdb_read_db: Invalid format (Script column) in line %d (item with id %lu), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2224. continue;
  2225. }
  2226. str[19] = p + 1;
  2227. p = strstr(p + 1, "},");
  2228. if (p == nullptr) {
  2229. ShowError("itemdb_read_db: Invalid format (Script column) in line %d (item with id %lu), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2230. continue;
  2231. }
  2232. *p = '\0';
  2233. p += 2;
  2234. // OnEquip_Script
  2235. if (*p != '{') {
  2236. ShowError("itemdb_read_db: Invalid format (OnEquip_Script column) in line %d (item with id %lu), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2237. continue;
  2238. }
  2239. str[20] = p + 1;
  2240. p = strstr(p + 1, "},");
  2241. if (p == nullptr) {
  2242. ShowError("itemdb_read_db: Invalid format (OnEquip_Script column) in line %d (item with id %lu), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2243. continue;
  2244. }
  2245. *p = '\0';
  2246. p += 2;
  2247. // OnUnequip_Script (last column)
  2248. if (*p != '{') {
  2249. ShowError("itemdb_read_db: Invalid format (OnUnequip_Script column) in line %d (item with id %lu), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2250. continue;
  2251. }
  2252. str[21] = p;
  2253. p = &str[21][strlen(str[21]) - 2];
  2254. if (*p != '}') {
  2255. /* lets count to ensure it's not something silly e.g. a extra space at line ending */
  2256. int32 lcurly = 0, rcurly = 0;
  2257. for (size_t v = 0; v < strlen(str[21]); v++) {
  2258. if (str[21][v] == '{')
  2259. lcurly++;
  2260. else if (str[21][v] == '}') {
  2261. rcurly++;
  2262. p = &str[21][v];
  2263. }
  2264. }
  2265. if (lcurly != rcurly) {
  2266. ShowError("itemdb_read_db: Mismatching curly braces in line %d (item with id %lu), skipping.\n", lines, strtoul(str[0], nullptr, 10));
  2267. continue;
  2268. }
  2269. }
  2270. str[21] = str[21] + 1; //skip the first left curly
  2271. *p = '\0'; //null the last right curly
  2272. t_itemid nameid = strtoul(str[0], nullptr, 10);
  2273. body << YAML::BeginMap;
  2274. body << YAML::Key << "Id" << YAML::Value << nameid;
  2275. body << YAML::Key << "AegisName" << YAML::Value << str[1];
  2276. body << YAML::Key << "Name" << YAML::Value << str[2];
  2277. int32 type = atoi(str[3]), subtype = atoi(str[18]);
  2278. const char* constant = constant_lookup( type, "IT_" );
  2279. if( constant == nullptr ){
  2280. ShowError( "itemdb_read_db: Unknown item type %d for item %u, skipping.\n", type, nameid );
  2281. continue;
  2282. }
  2283. body << YAML::Key << "Type" << YAML::Value << name2Upper( constant + 3 );
  2284. if( type == IT_WEAPON && subtype ){
  2285. constant = constant_lookup( subtype, "W_" );
  2286. if( constant == nullptr ){
  2287. ShowError( "itemdb_read_db: Unknown weapon type %d for item %u, skipping.\n", subtype, nameid );
  2288. continue;
  2289. }
  2290. body << YAML::Key << "SubType" << YAML::Value << name2Upper( constant + 2 );
  2291. }else if( type == IT_AMMO && subtype ){
  2292. constant = constant_lookup( subtype, "AMMO_" );
  2293. if( constant == nullptr ){
  2294. ShowError( "itemdb_read_db: Unknown ammo type %d for item %u, skipping.\n", subtype, nameid );
  2295. continue;
  2296. }
  2297. body << YAML::Key << "SubType" << YAML::Value << name2Upper(constant + 5);
  2298. }
  2299. if (atoi(str[4]) > 0)
  2300. body << YAML::Key << "Buy" << YAML::Value << atoi(str[4]);
  2301. if (atoi(str[5]) > 0) {
  2302. if (atoi(str[4]) / 2 != atoi(str[5]))
  2303. body << YAML::Key << "Sell" << YAML::Value << atoi(str[5]);
  2304. }
  2305. if (atoi(str[6]) > 0)
  2306. body << YAML::Key << "Weight" << YAML::Value << atoi(str[6]);
  2307. #ifdef RENEWAL
  2308. int32 atk = 0, matk = 0;
  2309. itemdb_re_split_atoi(str[7], &atk, &matk);
  2310. if (atk > 0)
  2311. body << YAML::Key << "Attack" << YAML::Value << atk;
  2312. if (matk > 0)
  2313. body << YAML::Key << "MagicAttack" << YAML::Value << matk;
  2314. #else
  2315. if (atoi(str[7]) > 0)
  2316. body << YAML::Key << "Attack" << YAML::Value << atoi(str[7]);
  2317. #endif
  2318. if (atoi(str[8]) > 0)
  2319. body << YAML::Key << "Defense" << YAML::Value << atoi(str[8]);
  2320. if (atoi(str[9]) > 0)
  2321. body << YAML::Key << "Range" << YAML::Value << atoi(str[9]);
  2322. if (atoi(str[10]) > 0)
  2323. body << YAML::Key << "Slots" << YAML::Value << atoi(str[10]);
  2324. 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;
  2325. if (equippable) {
  2326. uint64 temp_mask = strtoull(str[11], nullptr, 0);
  2327. if (temp_mask == 0) {
  2328. //body << YAML::Key << "Jobs";
  2329. //body << YAML::BeginMap << YAML::Key << "All" << YAML::Value << "false" << YAML::EndMap;
  2330. } else if (temp_mask == 0xFFFFFFFF) { // Commented out because it's the default value
  2331. //body << YAML::Key << "Jobs";
  2332. //body << YAML::BeginMap << YAML::Key << "All" << YAML::Value << "true" << YAML::EndMap;
  2333. } else if (temp_mask == 0xFFFFFFFE) {
  2334. body << YAML::Key << "Jobs";
  2335. body << YAML::BeginMap;
  2336. body << YAML::Key << "All" << YAML::Value << "true";
  2337. body << YAML::Key << "Novice" << YAML::Value << "false";
  2338. body << YAML::Key << "SuperNovice" << YAML::Value << "false";
  2339. body << YAML::EndMap;
  2340. } else {
  2341. body << YAML::Key << "Jobs";
  2342. body << YAML::BeginMap;
  2343. for (const auto &it : um_mapid2jobname) {
  2344. uint64 job_mask = 1ULL << it.second;
  2345. if ((temp_mask & job_mask) == job_mask)
  2346. body << YAML::Key << it.first << YAML::Value << "true";
  2347. }
  2348. body << YAML::EndMap;
  2349. }
  2350. int32 temp_class = atoi(str[12]);
  2351. if (temp_class == ITEMJ_NONE) {
  2352. body << YAML::Key << "Classes";
  2353. body << YAML::BeginMap << YAML::Key << "All" << YAML::Value << "false" << YAML::EndMap;
  2354. } else if (temp_class == ITEMJ_ALL) { // Commented out because it's the default value
  2355. //body << YAML::Key << "Classes";
  2356. //body << YAML::BeginMap << YAML::Key << "All" << YAML::Value << "true" << YAML::EndMap;
  2357. } else {
  2358. body << YAML::Key << "Classes";
  2359. body << YAML::BeginMap;
  2360. if ((ITEMJ_THIRD & temp_class) && (ITEMJ_THIRD_UPPER & temp_class) && (ITEMJ_THIRD_BABY & temp_class)) {
  2361. temp_class &= ~ITEMJ_ALL_THIRD;
  2362. body << YAML::Key << "All_Third" << YAML::Value << "true";
  2363. }
  2364. if ((ITEMJ_UPPER & temp_class) && (ITEMJ_THIRD_UPPER & temp_class)) {
  2365. temp_class &= ~ITEMJ_ALL_UPPER;
  2366. body << YAML::Key << "All_Upper" << YAML::Value << "true";
  2367. }
  2368. if ((ITEMJ_BABY & temp_class) && (ITEMJ_THIRD_BABY & temp_class)) {
  2369. temp_class &= ~ITEMJ_ALL_BABY;
  2370. body << YAML::Key << "All_Baby" << YAML::Value << "true";
  2371. }
  2372. for (int32 i = ITEMJ_NONE; i <= ITEMJ_THIRD_BABY; i++) {
  2373. if (i & temp_class) {
  2374. const char* class_ = constant_lookup(i, "ITEMJ_");
  2375. if (class_ != nullptr)
  2376. body << YAML::Key << name2Upper(class_ + 6) << YAML::Value << "true";
  2377. }
  2378. }
  2379. body << YAML::EndMap;
  2380. }
  2381. switch (atoi(str[13])) {
  2382. case SEX_FEMALE:
  2383. body << YAML::Key << "Gender" << YAML::Value << "Female";
  2384. break;
  2385. case SEX_MALE:
  2386. body << YAML::Key << "Gender" << YAML::Value << "Male";
  2387. break;
  2388. //case SEX_BOTH: // Commented out because it's the default value
  2389. // body << YAML::Key << "Gender" << YAML::Value << "Both";
  2390. // break;
  2391. }
  2392. }
  2393. if (atoi(str[14]) > 0) {
  2394. int32 temp_loc = atoi(str[14]);
  2395. body << YAML::Key << "Locations";
  2396. body << YAML::BeginMap;
  2397. if ((EQP_HAND_R & temp_loc) && (EQP_HAND_L & temp_loc)) {
  2398. temp_loc &= ~EQP_ARMS;
  2399. body << YAML::Key << "Both_Hand" << YAML::Value << "true";
  2400. }
  2401. if ((EQP_ACC_R & temp_loc) && (EQP_ACC_L & temp_loc)) {
  2402. temp_loc &= ~EQP_ACC_RL;
  2403. body << YAML::Key << "Both_Accessory" << YAML::Value << "true";
  2404. }
  2405. for (const auto &it : um_equipnames) {
  2406. if (it.second & temp_loc)
  2407. body << YAML::Key << it.first << YAML::Value << "true";
  2408. }
  2409. body << YAML::EndMap;
  2410. }
  2411. if (atoi(str[15]) > 0)
  2412. body << YAML::Key << "WeaponLevel" << YAML::Value << atoi(str[15]);
  2413. int32 elv = 0, elvmax = 0;
  2414. itemdb_re_split_atoi(str[16], &elv, &elvmax);
  2415. if (elv > 0)
  2416. body << YAML::Key << "EquipLevelMin" << YAML::Value << elv;
  2417. if (elvmax > 0)
  2418. body << YAML::Key << "EquipLevelMax" << YAML::Value << elvmax;
  2419. if (atoi(str[17]) > 0)
  2420. body << YAML::Key << "Refineable" << YAML::Value << "true";
  2421. if (strtoul(str[18], nullptr, 10) > 0 && type != IT_WEAPON && type != IT_AMMO)
  2422. body << YAML::Key << "View" << YAML::Value << strtoul(str[18], nullptr, 10);
  2423. auto it_avail = item_avail.find(nameid);
  2424. if (it_avail != item_avail.end()) {
  2425. std::string *item_name = util::umap_find(aegis_itemnames, static_cast<t_itemid>(it_avail->second));
  2426. if (item_name == nullptr)
  2427. ShowError("Item name for item id %u is not known (item_avail).\n", it_avail->second);
  2428. else
  2429. body << YAML::Key << "AliasName" << YAML::Value << *item_name;
  2430. }
  2431. auto it_flag = item_flag.find(nameid);
  2432. auto it_buying = item_buyingstore.find(nameid);
  2433. if (it_flag != item_flag.end() || it_buying != item_buyingstore.end()) {
  2434. body << YAML::Key << "Flags";
  2435. body << YAML::BeginMap;
  2436. if (it_buying != item_buyingstore.end())
  2437. body << YAML::Key << "BuyingStore" << YAML::Value << "true";
  2438. if (it_flag != item_flag.end() && it_flag->second.dead_branch)
  2439. body << YAML::Key << "DeadBranch" << YAML::Value << it_flag->second.dead_branch;
  2440. if (it_flag != item_flag.end() && it_flag->second.group)
  2441. body << YAML::Key << "Container" << YAML::Value << it_flag->second.group;
  2442. if (it_flag != item_flag.end() && it_flag->second.guid)
  2443. body << YAML::Key << "UniqueId" << YAML::Value << it_flag->second.guid;
  2444. if (it_flag != item_flag.end() && it_flag->second.bindOnEquip)
  2445. body << YAML::Key << "BindOnEquip" << YAML::Value << it_flag->second.bindOnEquip;
  2446. if (it_flag != item_flag.end() && it_flag->second.broadcast)
  2447. body << YAML::Key << "DropAnnounce" << YAML::Value << it_flag->second.broadcast;
  2448. if (it_flag != item_flag.end() && it_flag->second.delay_consume)
  2449. body << YAML::Key << "NoConsume" << YAML::Value << it_flag->second.delay_consume;
  2450. if (it_flag != item_flag.end() && it_flag->second.dropEffect)
  2451. body << YAML::Key << "DropEffect" << YAML::Value << name2Upper(constant_lookup(it_flag->second.dropEffect, "DROPEFFECT_") + 11);
  2452. body << YAML::EndMap;
  2453. }
  2454. auto it_delay = item_delay.find(nameid);
  2455. if (it_delay != item_delay.end()) {
  2456. body << YAML::Key << "Delay";
  2457. body << YAML::BeginMap;
  2458. body << YAML::Key << "Duration" << YAML::Value << it_delay->second.delay;
  2459. if (it_delay->second.sc.size() > 0)
  2460. body << YAML::Key << "Status" << YAML::Value << name2Upper(it_delay->second.sc.erase(0, 3));
  2461. body << YAML::EndMap;
  2462. }
  2463. auto it_stack = item_stack.find(nameid);
  2464. if (it_stack != item_stack.end()) {
  2465. body << YAML::Key << "Stack";
  2466. body << YAML::BeginMap;
  2467. body << YAML::Key << "Amount" << YAML::Value << it_stack->second.amount;
  2468. if (it_stack->second.inventory)
  2469. body << YAML::Key << "Inventory" << YAML::Value << it_stack->second.inventory;
  2470. if (it_stack->second.cart)
  2471. body << YAML::Key << "Cart" << YAML::Value << it_stack->second.cart;
  2472. if (it_stack->second.storage)
  2473. body << YAML::Key << "Storage" << YAML::Value << it_stack->second.storage;
  2474. if (it_stack->second.guild_storage)
  2475. body << YAML::Key << "GuildStorage" << YAML::Value << it_stack->second.guild_storage;
  2476. body << YAML::EndMap;
  2477. }
  2478. auto it_nouse = item_nouse.find(nameid);
  2479. if (it_nouse != item_nouse.end()) {
  2480. body << YAML::Key << "NoUse";
  2481. body << YAML::BeginMap;
  2482. if (it_nouse->second.override != 100)
  2483. body << YAML::Key << "Override" << YAML::Value << it_nouse->second.override;
  2484. body << YAML::Key << "Sitting" << YAML::Value << "true";
  2485. body << YAML::EndMap;
  2486. }
  2487. auto it_trade = item_trade.find(nameid);
  2488. if (it_trade != item_trade.end()) {
  2489. body << YAML::Key << "Trade";
  2490. body << YAML::BeginMap;
  2491. if (it_trade->second.override != 100)
  2492. body << YAML::Key << "Override" << YAML::Value << it_trade->second.override;
  2493. if (it_trade->second.drop)
  2494. body << YAML::Key << "NoDrop" << YAML::Value << it_trade->second.drop;
  2495. if (it_trade->second.trade)
  2496. body << YAML::Key << "NoTrade" << YAML::Value << it_trade->second.trade;
  2497. if (it_trade->second.trade_partner)
  2498. body << YAML::Key << "TradePartner" << YAML::Value << it_trade->second.trade_partner;
  2499. if (it_trade->second.sell)
  2500. body << YAML::Key << "NoSell" << YAML::Value << it_trade->second.sell;
  2501. if (it_trade->second.cart)
  2502. body << YAML::Key << "NoCart" << YAML::Value << it_trade->second.cart;
  2503. if (it_trade->second.storage)
  2504. body << YAML::Key << "NoStorage" << YAML::Value << it_trade->second.storage;
  2505. if (it_trade->second.guild_storage)
  2506. body << YAML::Key << "NoGuildStorage" << YAML::Value << it_trade->second.guild_storage;
  2507. if (it_trade->second.mail)
  2508. body << YAML::Key << "NoMail" << YAML::Value << it_trade->second.mail;
  2509. if (it_trade->second.auction)
  2510. body << YAML::Key << "NoAuction" << YAML::Value << it_trade->second.auction;
  2511. body << YAML::EndMap;
  2512. }
  2513. if (*str[19])
  2514. body << YAML::Key << "Script" << YAML::Value << YAML::Literal << trim(str[19]);
  2515. if (*str[20])
  2516. body << YAML::Key << "EquipScript" << YAML::Value << YAML::Literal << trim(str[20]);
  2517. if (*str[21])
  2518. body << YAML::Key << "UnEquipScript" << YAML::Value << YAML::Literal << trim(str[21]);
  2519. body << YAML::EndMap;
  2520. entries++;
  2521. }
  2522. fclose(fp);
  2523. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' items in '" CL_WHITE "%s" CL_RESET "'.\n", entries, file);
  2524. return true;
  2525. }
  2526. // Copied and adjusted from itemdb.cpp
  2527. static bool itemdb_read_randomopt(const char* file) {
  2528. FILE* fp = fopen( file, "r" );
  2529. if( fp == nullptr ){
  2530. ShowError( "Can't read %s\n", file );
  2531. return 0;
  2532. }
  2533. uint32 lines = 0, count = 0;
  2534. char line[1024];
  2535. char path[256];
  2536. while (fgets(line, sizeof(line), fp)) {
  2537. char *str[2], *p;
  2538. lines++;
  2539. if (line[0] == '/' && line[1] == '/') // Ignore comments
  2540. continue;
  2541. memset(str, 0, sizeof(str));
  2542. p = trim(line);
  2543. if (*p == '\0')
  2544. continue;// empty line
  2545. if (!strchr(p, ','))
  2546. {
  2547. ShowError("itemdb_read_randomopt: Insufficient columns in line %d of \"%s\", skipping.\n", lines, path);
  2548. continue;
  2549. }
  2550. str[0] = p;
  2551. p = strchr(p, ',');
  2552. *p = '\0';
  2553. p++;
  2554. str[1] = p;
  2555. if (str[1][0] != '{') {
  2556. ShowError("itemdb_read_randomopt(#1): Invalid format (Script column) in line %d of \"%s\", skipping.\n", lines, path);
  2557. continue;
  2558. }
  2559. /* no ending key anywhere (missing \}\) */
  2560. if (str[1][strlen(str[1]) - 1] != '}') {
  2561. ShowError("itemdb_read_randomopt(#2): Invalid format (Script column) in line %d of \"%s\", skipping.\n", lines, path);
  2562. continue;
  2563. } else {
  2564. str[0] = trim(str[0]);
  2565. int64 id = constant_lookup_int(str[0]);
  2566. if (id == -100) {
  2567. ShowError("itemdb_read_randomopt: Unknown random option '%s' constant, skipping.\n", str[0]);
  2568. continue;
  2569. }
  2570. body << YAML::BeginMap;
  2571. body << YAML::Key << "Id" << YAML::Value << id;
  2572. body << YAML::Key << "Option" << YAML::Value << str[0] + 7;
  2573. body << YAML::Key << "Script" << YAML::Literal << str[1];
  2574. body << YAML::EndMap;
  2575. rand_opt_db.insert({ count, str[0] + 7 });
  2576. }
  2577. count++;
  2578. }
  2579. fclose(fp);
  2580. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
  2581. return true;
  2582. }
  2583. // Copied and adjusted from itemdb.cpp
  2584. static bool itemdb_read_randomopt_group( char* str[], size_t columns, size_t current ){
  2585. if ((columns - 2) % 3 != 0) {
  2586. ShowError("itemdb_read_randomopt_group: Invalid column entries '%d'.\n", columns);
  2587. return false;
  2588. }
  2589. uint16 id = static_cast<uint16>(rand_opt_group.size() + 1);
  2590. s_random_opt_group_csv *group = util::umap_find(rand_opt_group, id);
  2591. s_random_opt_group_csv group_entry;
  2592. if (group == nullptr)
  2593. group_entry.rate.push_back((uint16)strtoul(str[1], nullptr, 10));
  2594. uint16 j = 0;
  2595. for( size_t k = 2; k < columns && j < MAX_ITEM_RDM_OPT; k += 3 ){
  2596. int32 randid_tmp = -1;
  2597. for (const auto &opt : rand_opt_db) {
  2598. if (opt.second.compare(str[k]) == 0) {
  2599. randid_tmp = opt.first;
  2600. break;
  2601. }
  2602. }
  2603. if (randid_tmp < 0) {
  2604. ShowError("itemdb_read_randomopt_group: Invalid random group id '%s' in column %d!\n", str[k], k + 1);
  2605. continue;
  2606. }
  2607. std::vector<std::shared_ptr<s_random_opt_group_entry>> entries = {};
  2608. if (group != nullptr)
  2609. entries = group->slots[j];
  2610. std::shared_ptr<s_random_opt_group_entry> entry = std::make_shared<s_random_opt_group_entry>();
  2611. entry->id = static_cast<uint16>(randid_tmp);
  2612. entry->min_value = (int16)strtoul(str[k + 1], nullptr, 10);
  2613. entry->max_value = 0;
  2614. entry->param = (int8)strtoul(str[k + 2], nullptr, 10);
  2615. entry->chance = 0;
  2616. entries.push_back(entry);
  2617. if (group == nullptr)
  2618. group_entry.slots[j] = entries;
  2619. else
  2620. group->slots[j] = entries;
  2621. j++;
  2622. }
  2623. if (group == nullptr)
  2624. rand_opt_group.insert({ id, group_entry });
  2625. return true;
  2626. }
  2627. static bool itemdb_randomopt_group_yaml(void) {
  2628. for (const auto &it : rand_opt_group) {
  2629. body << YAML::BeginMap;
  2630. body << YAML::Key << "Id" << YAML::Value << it.first;
  2631. body << YAML::Key << "Group" << YAML::Value << it.second.name;
  2632. body << YAML::Key << "Slots";
  2633. body << YAML::BeginSeq;
  2634. for (size_t i = 0; i < it.second.rate.size(); i++) {
  2635. body << YAML::BeginMap;
  2636. body << YAML::Key << "Slot" << YAML::Value << i + 1;
  2637. body << YAML::Key << "Options";
  2638. body << YAML::BeginSeq;
  2639. for (size_t j = 0; j < it.second.slots.size(); j++) {
  2640. std::vector<std::shared_ptr<s_random_opt_group_entry>> options = it.second.slots.at(static_cast<uint16>(j));
  2641. for (const auto &opt_it : options) {
  2642. body << YAML::BeginMap;
  2643. for (const auto &opt : rand_opt_db) {
  2644. if (opt.first == opt_it->id) {
  2645. body << YAML::Key << "Option" << YAML::Value << opt.second;
  2646. break;
  2647. }
  2648. }
  2649. if (opt_it->min_value != 0)
  2650. body << YAML::Key << "MinValue" << YAML::Value << opt_it->min_value;
  2651. if (opt_it->param != 0)
  2652. body << YAML::Key << "Param" << YAML::Value << opt_it->param;
  2653. body << YAML::Key << "Chance" << YAML::Value << it.second.rate[i];
  2654. body << YAML::EndMap;
  2655. }
  2656. }
  2657. body << YAML::EndSeq;
  2658. body << YAML::EndMap;
  2659. }
  2660. body << YAML::EndSeq;
  2661. body << YAML::EndMap;
  2662. }
  2663. return true;
  2664. }
  2665. static bool pc_readdb_levelpenalty( char* fields[], size_t columns, size_t current ){
  2666. // 1=experience, 2=item drop
  2667. int32 type = atoi( fields[0] );
  2668. if( type != 1 && type != 2 ){
  2669. ShowWarning( "pc_readdb_levelpenalty: Invalid type %d specified.\n", type );
  2670. return false;
  2671. }
  2672. int64 val = constant_lookup_int( fields[1] );
  2673. if( val == -100 ){
  2674. ShowWarning("pc_readdb_levelpenalty: Unknown class constant %s specified.\n", fields[1] );
  2675. return false;
  2676. }
  2677. int32 class_ = atoi( fields[1] );
  2678. if( !CHK_CLASS( class_ ) ){
  2679. ShowWarning( "pc_readdb_levelpenalty: Invalid class %d specified.\n", class_ );
  2680. return false;
  2681. }
  2682. int32 diff = atoi( fields[2] );
  2683. if( std::abs( diff ) > MAX_LEVEL ){
  2684. ShowWarning( "pc_readdb_levelpenalty: Level difference %d is too high.\n", diff );
  2685. return false;
  2686. }
  2687. diff += MAX_LEVEL - 1;
  2688. level_penalty[type][class_][diff] = atoi(fields[3]);
  2689. return true;
  2690. }
  2691. void pc_levelpenalty_yaml_sub( int32 type, const std::string& name ){
  2692. body << YAML::BeginMap;
  2693. body << YAML::Key << "Type" << YAML::Value << name;
  2694. body << YAML::Key << "LevelDifferences";
  2695. body << YAML::BeginSeq;
  2696. for( int32 i = ARRAYLENGTH( level_penalty[type][CLASS_NORMAL] ); i >= 0; i-- ){
  2697. if( level_penalty[type][CLASS_NORMAL][i] > 0 && level_penalty[type][CLASS_NORMAL][i] != 100 ){
  2698. body << YAML::BeginMap;
  2699. body << YAML::Key << "Difference" << YAML::Value << ( i - MAX_LEVEL + 1 );
  2700. body << YAML::Key << "Rate" << YAML::Value << level_penalty[type][CLASS_NORMAL][i];
  2701. body << YAML::EndMap;
  2702. }
  2703. }
  2704. body << YAML::EndSeq;
  2705. body << YAML::EndMap;
  2706. }
  2707. bool pc_levelpenalty_yaml(){
  2708. pc_levelpenalty_yaml_sub( 1, "Exp" );
  2709. pc_levelpenalty_yaml_sub( 2, "Drop" );
  2710. return true;
  2711. }
  2712. // mob_db.yml function
  2713. //--------------------
  2714. static bool mob_readdb_race2( char *fields[], size_t columns, size_t current ){
  2715. int64 race;
  2716. if (ISDIGIT(fields[0][0]))
  2717. race = strtoll(fields[0], nullptr, 10);
  2718. else if ((race = constant_lookup_int(fields[0])) == -100) {
  2719. ShowWarning("mob_readdb_race2: Unknown race2 constant \"%s\".\n", fields[0]);
  2720. return false;
  2721. }
  2722. std::vector<uint32> mobs;
  2723. for (uint16 i = 1; i < columns; i++) {
  2724. uint32 mob_id = strtol(fields[i], nullptr, 10);
  2725. std::string *mob_name = util::umap_find(aegis_mobnames, static_cast<uint16>(mob_id));
  2726. if (!mob_name) {
  2727. ShowWarning("mob_readdb_race2: Unknown mob id %u for race2 %lld.\n", mob_id, race);
  2728. continue;
  2729. }
  2730. mobs.push_back(mob_id);
  2731. }
  2732. mob_race2.insert({ static_cast<uint16>(race), mobs });
  2733. return true;
  2734. }
  2735. // mob_db.yml function
  2736. //--------------------
  2737. static bool mob_readdb_drop( char *str[], size_t columns, size_t current ){
  2738. uint32 mob_id = strtoul(str[0], nullptr, 10);
  2739. std::string *mob_name = util::umap_find(aegis_mobnames, static_cast<uint16>(mob_id));
  2740. if (!mob_name) {
  2741. ShowWarning("mob_readdb_drop: Unknown mob ID %s.\n", str[0]);
  2742. return false;
  2743. }
  2744. t_itemid nameid = strtoul(str[1], nullptr, 10);
  2745. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  2746. if (!item_name) {
  2747. ShowWarning("mob_readdb_drop: Invalid item ID %s.\n", str[1]);
  2748. return false;
  2749. }
  2750. int32 rate = atoi(str[2]);
  2751. s_mob_drop_csv entry = {};
  2752. uint8 flag = 0;
  2753. if (columns > 4)
  2754. flag = atoi(str[4]);
  2755. entry.nameid = nameid;
  2756. entry.rate = rate;
  2757. entry.steal_protected = (flag & 1) ? 1 : 0;
  2758. entry.mvp = (flag & 2) ? true : false;
  2759. if (columns > 3)
  2760. entry.group_string = trim(str[3]);
  2761. const auto &exists = mob_drop.find(mob_id);
  2762. if (exists != mob_drop.end())
  2763. exists->second.push_back(entry);
  2764. else {
  2765. std::vector<s_mob_drop_csv> drop;
  2766. drop.push_back(entry);
  2767. mob_drop.insert({ mob_id, drop });
  2768. }
  2769. return true;
  2770. }
  2771. // Copied and adjusted from mob.cpp
  2772. static bool mob_readdb_sub( char *fields[], size_t columns, size_t current ){
  2773. uint32 mob_id = strtoul(fields[0], nullptr, 10);
  2774. body << YAML::BeginMap;
  2775. body << YAML::Key << "Id" << YAML::Value << mob_id;
  2776. body << YAML::Key << "AegisName" << YAML::Value << fields[1];
  2777. body << YAML::Key << "Name" << YAML::Value << fields[3];
  2778. if (strcmp(fields[3], fields[2]) != 0)
  2779. body << YAML::Key << "JapaneseName" << YAML::Value << fields[2];
  2780. if (strtol(fields[4], nullptr, 10) > 0)
  2781. body << YAML::Key << "Level" << YAML::Value << fields[4];
  2782. if (strtol(fields[5], nullptr, 10) > 1)
  2783. body << YAML::Key << "Hp" << YAML::Value << fields[5];
  2784. if (strtol(fields[6], nullptr, 10) > 1)
  2785. body << YAML::Key << "Sp" << YAML::Value << fields[6];
  2786. if (strtol(fields[7], nullptr, 10) > 0)
  2787. body << YAML::Key << "BaseExp" << YAML::Value << fields[7];
  2788. if (strtol(fields[8], nullptr, 10) > 0)
  2789. body << YAML::Key << "JobExp" << YAML::Value << fields[8];
  2790. if (strtol(fields[30], nullptr, 10) > 0)
  2791. body << YAML::Key << "MvpExp" << YAML::Value << fields[30];
  2792. if (strtol(fields[10], nullptr, 10) > 0)
  2793. body << YAML::Key << "Attack" << YAML::Value << fields[10];
  2794. if (strtol(fields[11], nullptr, 10) > 0)
  2795. body << YAML::Key << "Attack2" << YAML::Value << fields[11];
  2796. if (strtol(fields[12], nullptr, 10) > 0)
  2797. body << YAML::Key << "Defense" << YAML::Value << cap_value(std::stoi(fields[12]), DEFTYPE_MIN, DEFTYPE_MAX);
  2798. if (strtol(fields[13], nullptr, 10) > 0)
  2799. body << YAML::Key << "MagicDefense" << YAML::Value << cap_value(std::stoi(fields[13]), DEFTYPE_MIN, DEFTYPE_MAX);
  2800. if (strtol(fields[14], nullptr, 10) != 1)
  2801. body << YAML::Key << "Str" << YAML::Value << fields[14];
  2802. if (strtol(fields[15], nullptr, 10) != 1)
  2803. body << YAML::Key << "Agi" << YAML::Value << fields[15];
  2804. if (strtol(fields[16], nullptr, 10) != 1)
  2805. body << YAML::Key << "Vit" << YAML::Value << fields[16];
  2806. if (strtol(fields[17], nullptr, 10) != 1)
  2807. body << YAML::Key << "Int" << YAML::Value << fields[17];
  2808. if (strtol(fields[18], nullptr, 10) != 1)
  2809. body << YAML::Key << "Dex" << YAML::Value << fields[18];
  2810. if (strtol(fields[19], nullptr, 10) != 1)
  2811. body << YAML::Key << "Luk" << YAML::Value << fields[19];
  2812. if (strtol(fields[9], nullptr, 10) > 0)
  2813. body << YAML::Key << "AttackRange" << YAML::Value << fields[9];
  2814. if (strtol(fields[20], nullptr, 10) > 0)
  2815. body << YAML::Key << "SkillRange" << YAML::Value << fields[20];
  2816. if (strtol(fields[21], nullptr, 10) > 0)
  2817. body << YAML::Key << "ChaseRange" << YAML::Value << fields[21];
  2818. if (fields[22])
  2819. body << YAML::Key << "Size" << YAML::Value << constant_lookup(strtol(fields[22], nullptr, 10), "Size_") + 5;
  2820. if (fields[23])
  2821. body << YAML::Key << "Race" << YAML::Value << name2Upper(constant_lookup(strtol(fields[23], nullptr, 10), "RC_") + 3);
  2822. std::string class_ = "Normal";
  2823. bool header = false;
  2824. for (const auto &race2 : mob_race2) {
  2825. for (const auto &mobit : race2.second) {
  2826. if (mobit == mob_id) {
  2827. // These two races are now Class types
  2828. if (race2.first == RC2_GUARDIAN) {
  2829. class_ = "Guardian";
  2830. continue;
  2831. } else if (race2.first == RC2_BATTLEFIELD) {
  2832. class_ = "Battlefield";
  2833. continue;
  2834. }
  2835. if (!header) {
  2836. body << YAML::Key << "RaceGroups";
  2837. body << YAML::BeginMap;
  2838. header = true;
  2839. }
  2840. body << YAML::Key << name2Upper(constant_lookup(race2.first, "RC2_") + 4) << YAML::Value << "true";
  2841. }
  2842. }
  2843. }
  2844. if (header)
  2845. body << YAML::EndMap;
  2846. if (fields[24]) {
  2847. int32 ele = strtol(fields[24], nullptr, 10);
  2848. body << YAML::Key << "Element" << YAML::Value << name2Upper(constant_lookup(ele % 20, "ELE_") + 4);
  2849. body << YAML::Key << "ElementLevel" << YAML::Value << floor(ele / 20.);
  2850. }
  2851. if (strtol(fields[26], nullptr, 10) > 0)
  2852. body << YAML::Key << "WalkSpeed" << YAML::Value << cap_value(std::stoi(fields[26]), MIN_WALK_SPEED, MAX_WALK_SPEED);
  2853. if (strtol(fields[27], nullptr, 10) > 0)
  2854. body << YAML::Key << "AttackDelay" << YAML::Value << fields[27];
  2855. if (strtol(fields[28], nullptr, 10) > 0)
  2856. body << YAML::Key << "AttackMotion" << YAML::Value << fields[28];
  2857. if (strtol(fields[29], nullptr, 10) > 0)
  2858. body << YAML::Key << "DamageMotion" << YAML::Value << fields[29];
  2859. if (fields[25]) {
  2860. uint32 mode = static_cast<e_mode>(strtoul(fields[25], nullptr, 0));
  2861. std::string ai = "06";
  2862. if ((mode & 0xC000000) == 0xC000000) {
  2863. mode &= ~0xC000000;
  2864. class_ = "Battlefield";
  2865. } else if (class_.compare("Normal") == 0 && (mode & 0x6200000) == 0x6200000) { // Check for normal because class would have been changed above in RaceGroups
  2866. mode &= ~0x6200000;
  2867. class_ = "Boss";
  2868. } else if ((mode & 0x4000000) == 0x4000000) {
  2869. mode &= ~0x4000000;
  2870. class_ = "Guardian";
  2871. } else if ((mode & 0x1000000) == 0x1000000) {
  2872. mode &= ~0x1000000;
  2873. class_ = "Event";
  2874. }
  2875. if ((mode & MONSTER_TYPE_26) == MONSTER_TYPE_26) {
  2876. mode &= ~MONSTER_TYPE_26;
  2877. ai = "26";
  2878. } else if ((mode & MONSTER_TYPE_27) == MONSTER_TYPE_27) {
  2879. mode &= ~MONSTER_TYPE_27;
  2880. ai = "27";
  2881. } else if ((mode & MONSTER_TYPE_08) == MONSTER_TYPE_08) {
  2882. mode &= ~MONSTER_TYPE_08;
  2883. ai = "08";
  2884. } else if ((mode & MONSTER_TYPE_04) == MONSTER_TYPE_04) {
  2885. mode &= ~MONSTER_TYPE_04;
  2886. ai = "04";
  2887. } else if ((mode & MONSTER_TYPE_21) == MONSTER_TYPE_21) {
  2888. mode &= ~MONSTER_TYPE_21;
  2889. ai = "21";
  2890. } else if ((mode & MONSTER_TYPE_20) == MONSTER_TYPE_20) {
  2891. mode &= ~MONSTER_TYPE_20;
  2892. ai = "20";
  2893. } else if ((mode & MONSTER_TYPE_09) == MONSTER_TYPE_09) { // 9, 19
  2894. mode &= ~MONSTER_TYPE_09;
  2895. ai = "09";
  2896. } else if ((mode & MONSTER_TYPE_13) == MONSTER_TYPE_13) {
  2897. mode &= ~MONSTER_TYPE_13;
  2898. ai = "13";
  2899. } else if ((mode & MONSTER_TYPE_05) == MONSTER_TYPE_05) { // 5, 12
  2900. mode &= ~MONSTER_TYPE_05;
  2901. ai = "05";
  2902. } else if ((mode & MONSTER_TYPE_07) == MONSTER_TYPE_07) {
  2903. mode &= ~MONSTER_TYPE_07;
  2904. ai = "07";
  2905. } else if ((mode & MONSTER_TYPE_03) == MONSTER_TYPE_03) {
  2906. mode &= ~MONSTER_TYPE_03;
  2907. ai = "03";
  2908. } else if ((mode & MONSTER_TYPE_24) == MONSTER_TYPE_24) {
  2909. mode &= ~MONSTER_TYPE_24;
  2910. ai = "24";
  2911. } else if ((mode & MONSTER_TYPE_17) == MONSTER_TYPE_17) {
  2912. mode &= ~MONSTER_TYPE_17;
  2913. ai = "17";
  2914. } else if ((mode & MONSTER_TYPE_10) == MONSTER_TYPE_10) { // 10, 11
  2915. mode &= ~MONSTER_TYPE_10;
  2916. ai = "10";
  2917. } else if ((mode & MONSTER_TYPE_02) == MONSTER_TYPE_02) {
  2918. mode &= ~MONSTER_TYPE_02;
  2919. ai = "02";
  2920. } else if ((mode & MONSTER_TYPE_01) == MONSTER_TYPE_01) {
  2921. mode &= ~MONSTER_TYPE_01;
  2922. ai = "01";
  2923. } else if ((mode & MONSTER_TYPE_25) == MONSTER_TYPE_25) {
  2924. mode &= ~MONSTER_TYPE_25;
  2925. ai = "25";
  2926. } else if ((mode & MONSTER_TYPE_06) == MONSTER_TYPE_06)
  2927. ai = "06";
  2928. if (ai.compare("06") != 0)
  2929. body << YAML::Key << "Ai" << YAML::Value << ai;
  2930. if (class_.compare("Normal") != 0)
  2931. body << YAML::Key << "Class" << YAML::Value << class_;
  2932. if (mode > 0) {
  2933. body << YAML::Key << "Modes";
  2934. body << YAML::BeginMap;
  2935. if (mode & 0x1)
  2936. body << YAML::Key << "CanMove" << YAML::Value << "true";
  2937. if (mode & 0x80)
  2938. body << YAML::Key << "CanAttack" << YAML::Value << "true";
  2939. if (mode & 0x40)
  2940. body << YAML::Key << "NoCast" << YAML::Value << "true";
  2941. if (mode & 0x2)
  2942. body << YAML::Key << "Looter" << YAML::Value << "true";
  2943. if (mode & 0x4)
  2944. body << YAML::Key << "Aggressive" << YAML::Value << "true";
  2945. if (mode & 0x8)
  2946. body << YAML::Key << "Assist" << YAML::Value << "true";
  2947. if (mode & 0x20)
  2948. body << YAML::Key << "NoRandomWalk" << YAML::Value << "true";
  2949. if (mode & 0x200)
  2950. body << YAML::Key << "CastSensorChase" << YAML::Value << "true";
  2951. if (mode & 0x10)
  2952. body << YAML::Key << "CastSensorIdle" << YAML::Value << "true";
  2953. if (mode & 0x800)
  2954. body << YAML::Key << "Angry" << YAML::Value << "true";
  2955. if (mode & 0x400)
  2956. body << YAML::Key << "ChangeChase" << YAML::Value << "true";
  2957. if (mode & 0x1000)
  2958. body << YAML::Key << "ChangeTargetMelee" << YAML::Value << "true";
  2959. if (mode & 0x2000)
  2960. body << YAML::Key << "ChangeTargetChase" << YAML::Value << "true";
  2961. if (mode & 0x4000)
  2962. body << YAML::Key << "TargetWeak" << YAML::Value << "true";
  2963. if (mode & 0x8000)
  2964. body << YAML::Key << "RandomTarget" << YAML::Value << "true";
  2965. if (mode & 0x20000)
  2966. body << YAML::Key << "IgnoreMagic" << YAML::Value << "true";
  2967. if (mode & 0x10000)
  2968. body << YAML::Key << "IgnoreMelee" << YAML::Value << "true";
  2969. if (mode & 0x100000)
  2970. body << YAML::Key << "IgnoreMisc" << YAML::Value << "true";
  2971. if (mode & 0x40000)
  2972. body << YAML::Key << "IgnoreRanged" << YAML::Value << "true";
  2973. if (mode & 0x400000)
  2974. body << YAML::Key << "TeleportBlock" << YAML::Value << "true";
  2975. if (mode & 0x1000000)
  2976. body << YAML::Key << "FixedItemDrop" << YAML::Value << "true";
  2977. if (mode & 0x2000000)
  2978. body << YAML::Key << "Detector" << YAML::Value << "true";
  2979. if (mode & 0x200000)
  2980. body << YAML::Key << "KnockBackImmune" << YAML::Value << "true";
  2981. if (mode & 0x4000000)
  2982. body << YAML::Key << "StatusImmune" << YAML::Value << "true";
  2983. if (mode & 0x8000000)
  2984. body << YAML::Key << "SkillImmune" << YAML::Value << "true";
  2985. if (mode & 0x80000)
  2986. body << YAML::Key << "Mvp" << YAML::Value << "true";
  2987. body << YAML::EndMap;
  2988. }
  2989. }
  2990. bool has_mvp_drops = false;
  2991. for (uint8 d = 31; d < (31 + MAX_MVP_DROP * 2); d += 2) {
  2992. if (strtoul(fields[d], nullptr, 10) > 0) {
  2993. has_mvp_drops = true;
  2994. break;
  2995. }
  2996. }
  2997. if (has_mvp_drops) {
  2998. body << YAML::Key << "MvpDrops";
  2999. body << YAML::BeginSeq;
  3000. for (uint8 i = 0; i < MAX_MVP_DROP; i++) {
  3001. t_itemid nameid = strtoul(fields[31 + i * 2], nullptr, 10);
  3002. if (nameid > 0) {
  3003. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  3004. if (!item_name) {
  3005. ShowWarning("Monster \"%s\"(id: %u) is dropping an unknown item \"%u\"(MVP-Drop %d)\n", fields[1], mob_id, nameid, (i / 2) + 1);
  3006. continue;
  3007. }
  3008. body << YAML::BeginMap;
  3009. body << YAML::Key << "Item" << YAML::Value << *item_name;
  3010. body << YAML::Key << "Rate" << YAML::Value << cap_value(std::stoi(fields[32 + i * 2]), 1, 10000);
  3011. body << YAML::EndMap;
  3012. }
  3013. if (i < MAX_MVP_DROP - 1)
  3014. continue;
  3015. // Insert at end
  3016. for (const auto &it : mob_drop) {
  3017. if (it.first != mob_id)
  3018. continue;
  3019. for (const auto &drop : it.second) {
  3020. if (drop.mvp) {
  3021. std::string *item_name = util::umap_find(aegis_itemnames, drop.nameid);
  3022. if (!item_name) {
  3023. ShowWarning("Monster \"%s\"(id: %u) is dropping an unknown item \"%u\"(MVP-Drop %d)\n", fields[1], mob_id, drop.nameid, (i / 2) + 1);
  3024. continue;
  3025. }
  3026. body << YAML::BeginMap;
  3027. body << YAML::Key << "Item" << YAML::Value << *item_name;
  3028. body << YAML::Key << "Rate" << YAML::Value << cap_value(drop.rate, 1, 10000);
  3029. body << YAML::Key << "RandomOptionGroup" << YAML::Value << drop.group_string;
  3030. body << YAML::EndMap;
  3031. }
  3032. }
  3033. }
  3034. }
  3035. body << YAML::EndSeq;
  3036. }
  3037. bool has_drops = false;
  3038. for (uint8 d = 31 + MAX_MVP_DROP * 2; d < ((31 + MAX_MVP_DROP * 2) + MAX_MOB_DROP * 2); d += 2) {
  3039. if (strtoul(fields[d], nullptr, 10) > 0) {
  3040. has_drops = true;
  3041. break;
  3042. }
  3043. }
  3044. if (has_drops) {
  3045. body << YAML::Key << "Drops";
  3046. body << YAML::BeginSeq;
  3047. for (uint8 i = 0; i < MAX_MOB_DROP; i++) {
  3048. int32 k = 31 + MAX_MVP_DROP * 2 + i * 2;
  3049. t_itemid nameid = strtoul(fields[k], nullptr, 10);
  3050. if (nameid > 0) {
  3051. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  3052. if (!item_name) {
  3053. ShowWarning("Monster \"%s\"(id: %u) is dropping an unknown item \"%s\"\n", fields[1], mob_id, fields[k]);
  3054. continue;
  3055. }
  3056. body << YAML::BeginMap;
  3057. body << YAML::Key << "Item" << YAML::Value << *item_name;
  3058. body << YAML::Key << "Rate" << YAML::Value << cap_value(std::stoi(fields[k + 1]), 1, 10000);
  3059. if (i > 6) // Slots 8, 9, and 10 are inherently protected
  3060. body << YAML::Key << "StealProtected" << YAML::Value << "true";
  3061. body << YAML::EndMap;
  3062. }
  3063. if (i < MAX_MOB_DROP - 2 || i == MAX_MOB_DROP - 1)
  3064. continue;
  3065. // Insert before card
  3066. for (const auto &it : mob_drop) {
  3067. if (it.first != mob_id)
  3068. continue;
  3069. for (const auto &drop : it.second) {
  3070. if (!drop.mvp) {
  3071. std::string *item_name = util::umap_find(aegis_itemnames, drop.nameid);
  3072. if (!item_name) {
  3073. ShowWarning("Monster \"%s\"(id: %u) is dropping an unknown item \"%u\"\n", fields[1], mob_id, drop.nameid);
  3074. continue;
  3075. }
  3076. body << YAML::BeginMap;
  3077. body << YAML::Key << "Item" << YAML::Value << *item_name;
  3078. body << YAML::Key << "Rate" << YAML::Value << cap_value(drop.rate, 1, 10000);
  3079. body << YAML::Key << "RandomOptionGroup" << YAML::Value << drop.group_string;
  3080. if (drop.steal_protected == 1)
  3081. body << YAML::Key << "StealProtected" << YAML::Value << "true";
  3082. body << YAML::EndMap;
  3083. }
  3084. }
  3085. }
  3086. }
  3087. body << YAML::EndSeq;
  3088. }
  3089. body << YAML::EndMap;
  3090. return true;
  3091. }
  3092. // Copied and adjusted from mob.cpp
  3093. static bool mob_parse_row_chatdb( char* fields[], size_t columns, size_t current ){
  3094. int32 msg_id = atoi(fields[0]);
  3095. if (msg_id <= 0){
  3096. ShowError("Invalid chat ID '%d' in line %d\n", msg_id, current);
  3097. return false;
  3098. }
  3099. char* msg = fields[2];
  3100. size_t len = strlen(msg);
  3101. while( len && ( msg[len-1] == '\r' || msg[len-1] == '\n' ) ) {// find EOL to strip
  3102. len--;
  3103. }
  3104. if (len > (CHAT_SIZE_MAX-1)) {
  3105. ShowError("Message too long! Line %d, id: %d\n", current, msg_id);
  3106. return false;
  3107. }
  3108. else if (len == 0) {
  3109. ShowWarning("Empty message for id %d.\n", msg_id);
  3110. return false;
  3111. }
  3112. msg[len] = 0; // strip previously found EOL
  3113. body << YAML::BeginMap;
  3114. body << YAML::Key << "Id" << YAML::Value << msg_id;
  3115. if (strcmp(fields[1], "0xFF0000") != 0) // default color
  3116. body << YAML::Key << "Color" << YAML::Value << fields[1];
  3117. body << YAML::Key << "Dialog" << YAML::Value << msg;
  3118. body << YAML::EndMap;
  3119. return true;
  3120. }
  3121. // Copied and adjusted from homunculus.cpp
  3122. static bool read_homunculus_expdb(const char* file) {
  3123. FILE* fp = fopen( file, "r" );
  3124. if( fp == nullptr ){
  3125. ShowError( "Can't read %s\n", file );
  3126. return false;
  3127. }
  3128. uint32 lines = 0, count = 0;
  3129. char line[1024];
  3130. while (fgets(line, sizeof(line), fp)) {
  3131. lines++;
  3132. if (line[0] == '/' && line[1] == '/') // Ignore comments
  3133. continue;
  3134. t_exp exp = strtoull(line, nullptr, 10);
  3135. if( exp > 0 ){
  3136. body << YAML::BeginMap;
  3137. body << YAML::Key << "Level" << YAML::Value << (count+1);
  3138. body << YAML::Key << "Exp" << YAML::Value << exp;
  3139. body << YAML::EndMap;
  3140. }
  3141. count++;
  3142. }
  3143. fclose(fp);
  3144. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
  3145. return true;
  3146. }
  3147. // Copied and adjusted from mob.cpp
  3148. static bool mob_readdb_group( char* str[], size_t columns, size_t current ){
  3149. if (strncasecmp(str[0], "MOBG_", 5) != 0) {
  3150. ShowError("The group %s must start with 'MOBG_'.\n", str[0]);
  3151. return false;
  3152. }
  3153. uint16 mob_id = static_cast<uint16>(strtol(str[1], nullptr, 10));
  3154. bool is_default = mob_id == 0;
  3155. std::string group_name = str[0];
  3156. group_name.erase(0, 5);
  3157. std::transform(group_name.begin(), group_name.end(), group_name.begin(), ::toupper);
  3158. s_randomsummon_group_csv2yaml *group = util::map_find(summon_group, group_name);
  3159. bool exists = group != nullptr;
  3160. s_randomsummon_group_csv2yaml group_entry;
  3161. if (is_default)
  3162. mob_id = static_cast<uint16>(strtol(str[3], nullptr, 10));
  3163. std::string *mob_name = util::umap_find(aegis_mobnames, mob_id);
  3164. if (!mob_name) {
  3165. ShowError("Unknown mob id %d for group %s.\n", mob_id, str[0]);
  3166. return false;
  3167. }
  3168. if (!exists) {
  3169. group_entry.default_mob = *mob_name;
  3170. group_entry.group_name = group_name;
  3171. }
  3172. if (is_default) {
  3173. if (exists)
  3174. group->default_mob = *mob_name;
  3175. else
  3176. summon_group.insert({ group_name, group_entry });
  3177. }
  3178. else {
  3179. std::shared_ptr<s_randomsummon_entry_csv2yaml> entry = std::make_shared<s_randomsummon_entry_csv2yaml>();
  3180. entry->mob_name = *mob_name;
  3181. entry->rate = strtol(str[3], nullptr, 10);
  3182. if (exists)
  3183. group->list.push_back(entry);
  3184. else {
  3185. group_entry.list.push_back(entry);
  3186. summon_group.insert({ group_name, group_entry });
  3187. }
  3188. }
  3189. return true;
  3190. }
  3191. static bool mob_readdb_group_yaml(void) {
  3192. for (const auto &it : summon_group) {
  3193. body << YAML::BeginMap;
  3194. body << YAML::Key << "Group" << YAML::Value << it.first;
  3195. body << YAML::Key << "Default" << YAML::Value << it.second.default_mob;
  3196. body << YAML::Key << "Summon";
  3197. body << YAML::BeginSeq;
  3198. for (const auto &sumit : it.second.list) {
  3199. body << YAML::BeginMap;
  3200. body << YAML::Key << "Mob" << YAML::Value << sumit->mob_name;
  3201. body << YAML::Key << "Rate" << YAML::Value << sumit->rate;
  3202. body << YAML::EndMap;
  3203. }
  3204. body << YAML::EndSeq;
  3205. body << YAML::EndMap;
  3206. }
  3207. return true;
  3208. }
  3209. // Copied and adjusted from skill.cpp
  3210. static bool skill_parse_row_createarrowdb( char* split[], size_t columns, size_t current ){
  3211. t_itemid nameid = static_cast<t_itemid>(strtoul(split[0], nullptr, 10));
  3212. if (nameid == 0)
  3213. return true;
  3214. std::string *material_name = util::umap_find(aegis_itemnames, nameid);
  3215. if (!material_name) {
  3216. ShowError("skill_parse_row_createarrowdb: Invalid item %u.\n", nameid);
  3217. return false;
  3218. }
  3219. // Import just for clearing/disabling from original data
  3220. if (strtoul(split[1], nullptr, 10) == 0) {
  3221. body << YAML::BeginMap;
  3222. body << YAML::Key << "Remove" << YAML::Value << *material_name;
  3223. body << YAML::EndMap;
  3224. return true;
  3225. }
  3226. std::map<std::string, uint32> item_created;
  3227. for( size_t x = 1; x + 1 < columns && split[x] && split[x + 1]; x += 2 ){
  3228. nameid = static_cast<t_itemid>(strtoul(split[x], nullptr, 10));
  3229. std::string* item_name = util::umap_find(aegis_itemnames, nameid);
  3230. if (!item_name) {
  3231. ShowError("skill_parse_row_createarrowdb: Invalid item %u.\n", nameid);
  3232. return false;
  3233. }
  3234. item_created.insert({ *item_name, strtoul(split[x+1], nullptr, 10) });
  3235. }
  3236. body << YAML::BeginMap;
  3237. body << YAML::Key << "Source" << YAML::Value << *material_name;
  3238. body << YAML::Key << "Make";
  3239. body << YAML::BeginSeq;
  3240. for (const auto &it : item_created) {
  3241. body << YAML::BeginMap;
  3242. body << YAML::Key << "Item" << YAML::Value << it.first;
  3243. body << YAML::Key << "Amount" << YAML::Value << it.second;
  3244. body << YAML::EndMap;
  3245. }
  3246. body << YAML::EndSeq;
  3247. body << YAML::EndMap;
  3248. return true;
  3249. }
  3250. // Copied and adjusted from pc.cpp
  3251. static bool pc_read_statsdb(const char* file) {
  3252. FILE* fp = fopen( file, "r" );
  3253. if( fp == nullptr ){
  3254. ShowError( "Can't read %s\n", file );
  3255. return false;
  3256. }
  3257. uint32 lines = 0, count = 0;
  3258. char line[1024];
  3259. while (fgets(line, sizeof(line), fp)) {
  3260. lines++;
  3261. trim(line);
  3262. if (line[0] == '/' && line[1] == '/') // Ignore comments
  3263. continue;
  3264. body << YAML::BeginMap;
  3265. body << YAML::Key << "Level" << YAML::Value << (count+1);
  3266. body << YAML::Key << "Points" << YAML::Value << static_cast<uint32>(strtoul(line, nullptr, 10));
  3267. body << YAML::EndMap;
  3268. count++;
  3269. }
  3270. fclose(fp);
  3271. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
  3272. return true;
  3273. }
  3274. // Copied and adjusted from guild.cpp
  3275. static bool guild_read_castledb( char* str[], size_t columns, size_t current ){
  3276. body << YAML::BeginMap;
  3277. body << YAML::Key << "Id" << YAML::Value << str[0];
  3278. body << YAML::Key << "Map" << YAML::Value << str[1];
  3279. body << YAML::Key << "Name" << YAML::Value << trim(str[2]);
  3280. body << YAML::Key << "Npc" << YAML::Value << trim(str[3]);
  3281. body << YAML::EndMap;
  3282. return true;
  3283. }
  3284. // Copied and adjusted from int_guild.cpp
  3285. static bool exp_guild_parse_row( char* split[], size_t column, size_t current ){
  3286. t_exp exp = strtoull(split[0], nullptr, 10);
  3287. if (exp > MAX_GUILD_EXP) {
  3288. ShowError("exp_guild: Invalid exp %" PRIu64 " at line %d, exceeds max of %" PRIu64 "\n", exp, current, MAX_GUILD_EXP);
  3289. return false;
  3290. }
  3291. body << YAML::BeginMap;
  3292. body << YAML::Key << "Level" << YAML::Value << (current+1);
  3293. body << YAML::Key << "Exp" << YAML::Value << exp;
  3294. body << YAML::EndMap;
  3295. return true;
  3296. }
  3297. // Copied and adjusted from itemdb.cpp
  3298. static bool itemdb_read_group( char* str[], size_t columns, size_t current ){
  3299. if (strncasecmp(str[0], "IG_", 3) != 0) {
  3300. ShowError("The group %s must start with 'IG_'.\n", str[0]);
  3301. return false;
  3302. }
  3303. if (columns < 3) {
  3304. ShowError("itemdb_read_group: Insufficient columns (found %d, need at least 3).\n", columns);
  3305. return false;
  3306. }
  3307. std::string group_name = trim(str[0]);
  3308. group_name.erase(0, 3);
  3309. std::transform(group_name.begin(), group_name.end(), group_name.begin(), ::toupper);
  3310. if (strcmpi( str[1], "clear" ) == 0) {
  3311. item_group.erase(group_name);
  3312. return true;
  3313. }
  3314. // check item name
  3315. str[1] = trim(str[1]);
  3316. t_itemid nameid = strtoul(str[1], nullptr, 10);
  3317. std::string *name = util::umap_find(aegis_itemnames, nameid);
  3318. std::string item_name;
  3319. if (name)
  3320. item_name = *name;
  3321. else {
  3322. std::string tmp = str[1];
  3323. auto it = aegis_itemnames.begin();
  3324. for (; it != aegis_itemnames.end(); ++it) {
  3325. if (it->second == tmp)
  3326. break;
  3327. }
  3328. if (it == std::end(aegis_itemnames)) {
  3329. ShowWarning( "itemdb_read_group: Non-existant item '%s'\n", str[1] );
  3330. return false;
  3331. }
  3332. item_name = it->second;
  3333. }
  3334. // Checking sub group
  3335. uint32 prob = atoi(str[2]);
  3336. uint32 rand_group;
  3337. if (columns < 5)
  3338. rand_group = 1; // default
  3339. else
  3340. rand_group = atoi(str[4]);
  3341. if (rand_group > 0 && prob == 0) {
  3342. ShowWarning( "itemdb_read_group: Random item must have a probability. Group '%s'\n", str[0] );
  3343. return false;
  3344. }
  3345. // update group
  3346. s_item_group_db_csv2yaml *group = util::map_find(item_group, group_name);
  3347. s_item_group_db_csv2yaml group_entry;
  3348. bool exists = group != nullptr;
  3349. if (!exists)
  3350. group_entry.group_name = group_name;
  3351. s_item_group_entry_csv2yaml entry = {};
  3352. entry.item_name = item_name;
  3353. if (columns > 3) {
  3354. int32 amount = cap_value(atoi(str[3]),1,MAX_AMOUNT);
  3355. if (amount > 1)
  3356. entry.amount = amount;
  3357. }
  3358. if (columns > 5) entry.isAnnounced = atoi(str[5]) > 0;
  3359. if (columns > 6) entry.duration = cap_value(atoi(str[6]),0,UINT16_MAX);
  3360. if (columns > 7) entry.GUID = atoi(str[7]) > 0;
  3361. if (columns > 8) {
  3362. int32 bound = cap_value(atoi(str[8]),BOUND_NONE,BOUND_MAX-1);
  3363. if (bound > 0) {
  3364. std::string constant = constant_lookup(bound, "BOUND_");
  3365. constant.erase(0, 6);
  3366. entry.bound = constant;
  3367. }
  3368. }
  3369. if (columns > 9) entry.isNamed = atoi(str[9]) > 0;
  3370. // 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)
  3371. if (rand_group == 0 && prob > 0) {
  3372. if (exists)
  3373. group->item[rand_group].push_back(entry);
  3374. else
  3375. group_entry.item[rand_group].push_back(entry);
  3376. rand_group = 1;
  3377. }
  3378. entry.rate = prob;
  3379. if (exists)
  3380. group->item[rand_group].push_back(entry);
  3381. else {
  3382. group_entry.item[rand_group].push_back(entry);
  3383. item_group.insert({ group_name, group_entry });
  3384. }
  3385. return true;
  3386. }
  3387. static bool itemdb_read_group_yaml(void) {
  3388. for (const auto &it : item_group) {
  3389. body << YAML::BeginMap;
  3390. body << YAML::Key << "Group" << YAML::Value << it.first;
  3391. body << YAML::Key << "SubGroups";
  3392. body << YAML::BeginSeq;
  3393. for (const auto &item : it.second.item) { // subgroup
  3394. body << YAML::BeginMap;
  3395. body << YAML::Key << "SubGroup" << YAML::Value << item.first;
  3396. if (item.first == 0)
  3397. body << YAML::Key << "Algorithm" << YAML::Value << "All";
  3398. else if (item.first == 6)
  3399. body << YAML::Key << "Algorithm" << YAML::Value << "Random";
  3400. body << YAML::Key << "List";
  3401. body << YAML::BeginSeq;
  3402. for (const auto &listit : item.second) {
  3403. body << YAML::BeginMap;
  3404. body << YAML::Key << "Item" << YAML::Value << listit.item_name;
  3405. if (listit.rate > 0)
  3406. body << YAML::Key << "Rate" << YAML::Value << listit.rate;
  3407. if (listit.amount > 1)
  3408. body << YAML::Key << "Amount" << YAML::Value << listit.amount;
  3409. if (listit.duration > 0)
  3410. body << YAML::Key << "Duration" << YAML::Value << listit.duration;
  3411. if (listit.isAnnounced)
  3412. body << YAML::Key << "Announced" << YAML::Value << "true";
  3413. if (listit.GUID)
  3414. body << YAML::Key << "UniqueId" << YAML::Value << "true";
  3415. if (listit.isNamed)
  3416. body << YAML::Key << "Named" << YAML::Value << "true";
  3417. if (!listit.bound.empty())
  3418. body << YAML::Key << "Bound" << YAML::Value << listit.bound;
  3419. body << YAML::EndMap;
  3420. }
  3421. body << YAML::EndSeq;
  3422. body << YAML::EndMap;
  3423. }
  3424. body << YAML::EndSeq;
  3425. body << YAML::EndMap;
  3426. }
  3427. return true;
  3428. }
  3429. // Copied and adjusted from mob.cpp
  3430. static bool mob_readdb_itemratio( char* str[], size_t columns, size_t current ){
  3431. t_itemid nameid = strtoul(str[0], nullptr, 10);
  3432. std::string *item_name = util::umap_find(aegis_itemnames, nameid);
  3433. if (!item_name) {
  3434. ShowWarning("mob_readdb_itemratio: Invalid item id %u.\n", nameid);
  3435. return false;
  3436. }
  3437. body << YAML::BeginMap;
  3438. body << YAML::Key << "Item" << YAML::Value << *item_name;
  3439. body << YAML::Key << "Ratio" << YAML::Value << strtoul(str[1], nullptr, 10);
  3440. if (columns-2 > 0) {
  3441. body << YAML::Key << "List";
  3442. body << YAML::BeginMap;
  3443. for( size_t i = 0; i < columns - 2; i++ ){
  3444. uint16 mob_id = static_cast<uint16>(strtoul(str[i+2], nullptr, 10));
  3445. std::string* mob_name = util::umap_find( aegis_mobnames, mob_id );
  3446. if (mob_name == nullptr) {
  3447. ShowWarning( "mob_readdb_itemratio: Invalid monster with ID %hu.\n", mob_id );
  3448. continue;
  3449. }
  3450. body << YAML::Key << *mob_name << YAML::Value << "true";
  3451. }
  3452. body << YAML::EndMap;
  3453. }
  3454. body << YAML::EndMap;
  3455. return true;
  3456. }
  3457. // Copied and adjusted from status.cpp
  3458. static bool status_readdb_attrfix(const char* file) {
  3459. FILE* fp = fopen( file, "r" );
  3460. if( fp == nullptr ){
  3461. ShowError( "Can't read %s\n", file );
  3462. return false;
  3463. }
  3464. uint32 lines = 0, count = 0;
  3465. char line[1024];
  3466. int32 lv, i, j;
  3467. std::string constant;
  3468. while (fgets(line, sizeof(line), fp)) {
  3469. lines++;
  3470. if (line[0] == '/' && line[1] == '/')
  3471. continue;
  3472. lv = strtoul(line, nullptr, 10);
  3473. if (!CHK_ELEMENT_LEVEL(lv))
  3474. continue;
  3475. body << YAML::BeginMap;
  3476. body << YAML::Key << "Level" << YAML::Value << (count+1);
  3477. for (i = 0; i < ELE_ALL; ) {
  3478. char *p;
  3479. if (!fgets(line, sizeof(line), fp))
  3480. break;
  3481. if (line[0] == '/' && line[1] == '/')
  3482. continue;
  3483. constant = constant_lookup(i, "Ele_");
  3484. constant.erase(0, 4);
  3485. body << YAML::Key << name2Upper(constant);
  3486. body << YAML::BeginMap;
  3487. for (j = 0, p = line; j < ELE_ALL && p; j++) {
  3488. while (*p == 32) //skipping space (32=' ')
  3489. p++;
  3490. constant = constant_lookup(j, "Ele_");
  3491. constant.erase(0, 4);
  3492. body << YAML::Key << name2Upper(constant) << YAML::Value << atoi(p);
  3493. p = strchr(p, ',');
  3494. if (p)
  3495. *p++=0;
  3496. }
  3497. body << YAML::EndMap;
  3498. i++;
  3499. }
  3500. body << YAML::EndMap;
  3501. count++;
  3502. }
  3503. fclose(fp);
  3504. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
  3505. return true;
  3506. }
  3507. // Copied and adjusted from script.cpp
  3508. static bool read_constdb( char* fields[], size_t columns, size_t current ){
  3509. char name[1024], val[1024];
  3510. int32 type = 0;
  3511. if( columns > 1 ){
  3512. if( sscanf(fields[0], "%1023[A-Za-z0-9/_]", name) != 1 ||
  3513. sscanf(fields[1], "%1023[A-Za-z0-9/_]", val) != 1 ||
  3514. ( columns >= 2 && sscanf(fields[2], "%11d", &type) != 1 ) ){
  3515. ShowWarning("Skipping line '" CL_WHITE "%d" CL_RESET "', invalid constant definition\n", current);
  3516. return false;
  3517. }
  3518. }else{
  3519. if( sscanf(fields[0], "%1023[A-Za-z0-9/_] %1023[A-Za-z0-9/_-] %11d", name, val, &type) < 2 ){
  3520. ShowWarning( "Skipping line '" CL_WHITE "%d" CL_RESET "', invalid constant definition\n", current );
  3521. return false;
  3522. }
  3523. }
  3524. body << YAML::BeginMap;
  3525. body << YAML::Key << "Name" << YAML::Value << name;
  3526. body << YAML::Key << "Value" << YAML::Value << val;
  3527. if (type != 0)
  3528. body << YAML::Key << "Parameter" << YAML::Value << "true";
  3529. body << YAML::EndMap;
  3530. return true;
  3531. }
  3532. // job_db.yml function
  3533. //----------------------
  3534. static bool pc_readdb_job2( char* fields[], size_t columns, size_t current ){
  3535. std::vector<int32> stats;
  3536. stats.resize(MAX_LEVEL);
  3537. std::fill(stats.begin(), stats.end(), 0); // Fill with 0 so we don't produce arbitrary stats
  3538. for( size_t i = 1; i < columns; i++ ){
  3539. stats[i - 1] = atoi(fields[i]);
  3540. }
  3541. job_db2.insert({ atoi(fields[0]), stats });
  3542. return true;
  3543. }
  3544. // job_db.yml function
  3545. //----------------------
  3546. static bool pc_readdb_job_param( char* fields[], size_t columns, size_t current ){
  3547. int32 job_id = atoi(fields[0]);
  3548. s_job_param entry = {};
  3549. entry.str = atoi(fields[1]);
  3550. entry.agi = atoi(fields[2]) ? atoi(fields[2]) : entry.str;
  3551. entry.vit = atoi(fields[3]) ? atoi(fields[3]) : entry.str;
  3552. entry.int_ = atoi(fields[4]) ? atoi(fields[4]) : entry.str;
  3553. entry.dex = atoi(fields[5]) ? atoi(fields[5]) : entry.str;
  3554. entry.luk = atoi(fields[6]) ? atoi(fields[6]) : entry.str;
  3555. job_param.insert({ job_id, entry });
  3556. return true;
  3557. }
  3558. // job_basehpsp_db.yml function
  3559. //----------------------
  3560. static bool pc_readdb_job_exp_sub( char* fields[], size_t columns, size_t current ){
  3561. int32 level = atoi(fields[0]), jobs[CLASS_COUNT], job_count = skill_split_atoi(fields[1], jobs, CLASS_COUNT), type = atoi(fields[2]);
  3562. for (int32 i = 0; i < job_count; i++) {
  3563. if (type == 0)
  3564. exp_base_level.insert({ jobs[i], level });
  3565. else
  3566. exp_job_level.insert({ jobs[i], level });
  3567. }
  3568. return true;
  3569. }
  3570. // Copied and adjusted from pc.cpp
  3571. static bool pc_readdb_job_exp( char* fields[], size_t columns, size_t current ){
  3572. int32 level = atoi(fields[0]), jobs[CLASS_COUNT], job_count = skill_split_atoi(fields[1], jobs, CLASS_COUNT), type = atoi(fields[2]);
  3573. body << YAML::BeginMap;
  3574. body << YAML::Key << "Jobs";
  3575. body << YAML::BeginMap;
  3576. for (int32 i = 0; i < job_count; i++) {
  3577. body << YAML::Key << name2Upper(constant_lookup(jobs[i], "JOB_") + 4) << YAML::Value << "true";
  3578. if (type == 0)
  3579. exp_base_level.insert({ jobs[i], level });
  3580. else
  3581. exp_job_level.insert({ jobs[i], level });
  3582. }
  3583. body << YAML::EndMap;
  3584. if (type == 0) {
  3585. body << YAML::Key << "MaxBaseLevel" << YAML::Value << level;
  3586. body << YAML::Key << "BaseExp";
  3587. } else {
  3588. body << YAML::Key << "MaxJobLevel" << YAML::Value << level;
  3589. body << YAML::Key << "JobExp";
  3590. }
  3591. body << YAML::BeginSeq;
  3592. for (int32 i = 0; i < level; i++) {
  3593. body << YAML::BeginMap;
  3594. body << YAML::Key << "Level" << YAML::Value << i + 1;
  3595. body << YAML::Key << "Exp" << YAML::Value << strtoll(fields[3 + i], nullptr, 10);
  3596. body << YAML::EndMap;
  3597. }
  3598. body << YAML::EndSeq;
  3599. body << YAML::EndMap;
  3600. return true;
  3601. }
  3602. // Copied and adjusted from pc.cpp
  3603. static bool pc_readdb_job_basehpsp( char* fields[], size_t columns, size_t current ){
  3604. int32 type = atoi(fields[3]), jobs[CLASS_COUNT], job_count = skill_split_atoi(fields[2], jobs, CLASS_COUNT);
  3605. body << YAML::BeginMap;
  3606. body << YAML::Key << "Jobs";
  3607. body << YAML::BeginMap;
  3608. for (int32 i = 0; i < job_count; i++)
  3609. body << YAML::Key << name2Upper(constant_lookup(jobs[i], "JOB_") + 4) << YAML::Value << "true";
  3610. body << YAML::EndMap;
  3611. if (type == 0)
  3612. body << YAML::Key << "BaseHp";
  3613. else
  3614. body << YAML::Key << "BaseSp";
  3615. body << YAML::BeginSeq;
  3616. int32 j = 0, job_id = jobs[0], endlvl = 0;
  3617. // Find the highest level in the group of jobs
  3618. for (int32 i = 0; i < job_count; i++) {
  3619. auto it_level = exp_base_level.find(jobs[i]);
  3620. int32 tmplvl;
  3621. if (it_level != exp_base_level.end())
  3622. tmplvl = it_level->second;
  3623. else {
  3624. ShowError("pc_readdb_job_basehpsp: The job_exp database needs to be imported into memory before converting the job_basehpsp_db database.\n");
  3625. return false;
  3626. }
  3627. if (endlvl < tmplvl)
  3628. endlvl = tmplvl;
  3629. }
  3630. // These jobs don't have values less than level 99
  3631. if ((job_id >= JOB_RUNE_KNIGHT && job_id <= JOB_BABY_MECHANIC2) || job_id == JOB_KAGEROU || job_id == JOB_OBORO || job_id == JOB_REBELLION || job_id == JOB_BABY_KAGEROU || job_id == JOB_BABY_OBORO || job_id == JOB_BABY_REBELLION || job_id >= JOB_STAR_EMPEROR)
  3632. j = 98;
  3633. if (type == 0) { // HP
  3634. for (; j < endlvl; j++) {
  3635. if (atoi(fields[j + 4])) {
  3636. body << YAML::BeginMap;
  3637. body << YAML::Key << "Level" << YAML::Value << j + 1;
  3638. body << YAML::Key << "Hp" << YAML::Value << strtoll(fields[j + 4], nullptr, 10);
  3639. body << YAML::EndMap;
  3640. }
  3641. }
  3642. } else { // SP
  3643. for (; j < endlvl; j++) {
  3644. if (atoi(fields[j + 4])) {
  3645. body << YAML::BeginMap;
  3646. body << YAML::Key << "Level" << YAML::Value << j + 1;
  3647. body << YAML::Key << "Sp" << YAML::Value << strtoll(fields[j + 4], nullptr, 10);
  3648. body << YAML::EndMap;
  3649. }
  3650. }
  3651. }
  3652. body << YAML::EndSeq;
  3653. body << YAML::EndMap;
  3654. return true;
  3655. }
  3656. // Copied and adjusted from pc.cpp
  3657. static bool pc_readdb_job1( char* fields[], size_t columns, size_t current ){
  3658. int32 job_id = atoi(fields[0]);
  3659. if (job_id == JOB_WEDDING)
  3660. return true;
  3661. body << YAML::BeginMap;
  3662. body << YAML::Key << "Jobs";
  3663. body << YAML::BeginMap;
  3664. body << YAML::Key << name2Upper(constant_lookup(job_id, "JOB_") + 4) << YAML::Value << "true";
  3665. body << YAML::EndMap;
  3666. if (atoi(fields[1]) != 20000)
  3667. body << YAML::Key << "MaxWeight" << YAML::Value << atoi(fields[1]);
  3668. if (atoi(fields[2]) != 0)
  3669. body << YAML::Key << "HpFactor" << YAML::Value << atoi(fields[2]);
  3670. if (atoi(fields[3]) != 500)
  3671. body << YAML::Key << "HpIncrease" << YAML::Value << atoi(fields[3]);
  3672. if (atoi(fields[4]) != 100)
  3673. body << YAML::Key << "SpIncrease" << YAML::Value << atoi(fields[4]);
  3674. body << YAML::Key << "BaseASPD";
  3675. body << YAML::BeginMap;
  3676. #ifdef RENEWAL_ASPD
  3677. for (int32 i = 0; i <= MAX_WEAPON_TYPE; i++) {
  3678. if (atoi(fields[i + 5]) != 200) {
  3679. #else
  3680. for (int32 i = 0, j = 0; i < MAX_WEAPON_TYPE; i++) {
  3681. if (atoi(fields[i + 5]) != 2000) {
  3682. #endif
  3683. const char *weapon = constant_lookup(i, "W_");
  3684. if (weapon == nullptr) {
  3685. ShowError("pc_readdb_job1: Invalid weapon type found, skipping.\n");
  3686. continue;
  3687. }
  3688. body << YAML::Key << name2Upper(weapon + 2) << YAML::Value << atoi(fields[i + 5]);
  3689. }
  3690. }
  3691. body << YAML::EndMap;
  3692. auto job_bonus = job_db2.find(job_id);
  3693. auto jlvl = exp_job_level.find(job_id);
  3694. if (job_bonus != job_db2.end() && job_id != JOB_BABY) {
  3695. body << YAML::Key << "BonusStats";
  3696. body << YAML::BeginSeq;
  3697. for (int32 i = 1; i <= jlvl->second; i++) {
  3698. auto value = job_bonus->second[i - 1];
  3699. if( value == 0 ){
  3700. continue;
  3701. }
  3702. const char *bonus = constant_lookup( value - 1, "PARAM_" );
  3703. if (bonus != nullptr) {
  3704. body << YAML::BeginMap;
  3705. body << YAML::Key << "Level" << YAML::Value << i;
  3706. body << YAML::Key << name2Upper(bonus + 6) << YAML::Value << "1";
  3707. body << YAML::EndMap;
  3708. }
  3709. }
  3710. body << YAML::EndSeq;
  3711. }
  3712. auto param = job_param.find(job_id);
  3713. if (param != job_param.end()) {
  3714. body << YAML::Key << "MaxStats";
  3715. body << YAML::BeginMap;
  3716. if (param->second.str > 0)
  3717. body << YAML::Key << "Str" << YAML::Value << param->second.str;
  3718. if (param->second.agi > 0)
  3719. body << YAML::Key << "Agi" << YAML::Value << param->second.agi;
  3720. if (param->second.vit > 0)
  3721. body << YAML::Key << "Vit" << YAML::Value << param->second.vit;
  3722. if (param->second.int_ > 0)
  3723. body << YAML::Key << "Int" << YAML::Value << param->second.int_;
  3724. if (param->second.dex > 0)
  3725. body << YAML::Key << "Dex" << YAML::Value << param->second.dex;
  3726. if (param->second.luk > 0)
  3727. body << YAML::Key << "Luk" << YAML::Value << param->second.luk;
  3728. body << YAML::EndMap;
  3729. }
  3730. body << YAML::EndMap;
  3731. return true;
  3732. }
  3733. // elemental_db.yml function
  3734. //---------------------------
  3735. static bool read_elemental_skilldb( char* str[], size_t columns, size_t current ){
  3736. uint16 skill_id = atoi(str[1]);
  3737. std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
  3738. if (skill_name == nullptr) {
  3739. ShowError("read_elemental_skilldb: Invalid skill '%hu'.\n", skill_id);
  3740. return false;
  3741. }
  3742. uint16 skillmode = atoi(str[3]);
  3743. std::string constant = constant_lookup(skillmode, "EL_SKILLMODE_");
  3744. constant.erase(0, 13);
  3745. std::string mode_name = name2Upper(constant);
  3746. s_elemental_skill_csv entry = {};
  3747. entry.skill_name = *skill_name;
  3748. entry.lv = atoi(str[2]);
  3749. entry.mode_name = mode_name;
  3750. uint16 class_ = atoi(str[0]);
  3751. if (util::umap_find(elemental_skill_tree, class_))
  3752. elemental_skill_tree[class_].push_back(entry);
  3753. else {
  3754. elemental_skill_tree[class_] = std::vector<s_elemental_skill_csv>();
  3755. elemental_skill_tree[class_].push_back(entry);
  3756. }
  3757. return true;
  3758. }
  3759. // Copied and adjusted from elemental.cpp
  3760. static bool read_elementaldb( char* str[], size_t columns, size_t current ){
  3761. body << YAML::BeginMap;
  3762. body << YAML::Key << "Id" << YAML::Value << str[0];
  3763. body << YAML::Key << "AegisName" << YAML::Value << str[1];
  3764. body << YAML::Key << "Name" << YAML::Value << str[2];
  3765. body << YAML::Key << "Level" << YAML::Value << str[3];
  3766. if (atoi(str[4]) != 0)
  3767. body << YAML::Key << "Hp" << YAML::Value << str[4];
  3768. if (atoi(str[5]) != 1)
  3769. body << YAML::Key << "Sp" << YAML::Value << str[5];
  3770. if (atoi(str[7]) != 0)
  3771. body << YAML::Key << "Attack" << YAML::Value << str[7];
  3772. if (atoi(str[8]) != 0)
  3773. body << YAML::Key << "Attack2" << YAML::Value << str[8];
  3774. if (atoi(str[9]) != 0)
  3775. body << YAML::Key << "Defense" << YAML::Value << str[9];
  3776. if (atoi(str[10]) != 0)
  3777. body << YAML::Key << "MagicDefense" << YAML::Value << str[10];
  3778. if (atoi(str[11]) != 0)
  3779. body << YAML::Key << "Str" << YAML::Value << str[11];
  3780. if (atoi(str[12]) != 0)
  3781. body << YAML::Key << "Agi" << YAML::Value << str[12];
  3782. if (atoi(str[13]) != 0)
  3783. body << YAML::Key << "Vit" << YAML::Value << str[13];
  3784. if (atoi(str[14]) != 0)
  3785. body << YAML::Key << "Int" << YAML::Value << str[14];
  3786. if (atoi(str[15]) != 0)
  3787. body << YAML::Key << "Dex" << YAML::Value << str[15];
  3788. if (atoi(str[16]) != 0)
  3789. body << YAML::Key << "Luk" << YAML::Value << str[16];
  3790. if (atoi(str[6]) != 1)
  3791. body << YAML::Key << "AttackRange" << YAML::Value << str[6];
  3792. if (atoi(str[17]) != 5)
  3793. body << YAML::Key << "SkillRange" << YAML::Value << str[17];
  3794. if (atoi(str[18]) != 12)
  3795. body << YAML::Key << "ChaseRange" << YAML::Value << str[18];
  3796. body << YAML::Key << "Size" << YAML::Value << constant_lookup(strtol(str[19], nullptr, 10), "Size_") + 5;
  3797. if (atoi(str[20]) != 0)
  3798. body << YAML::Key << "Race" << YAML::Value << name2Upper(constant_lookup(atoi(str[20]), "RC_") + 3);
  3799. int32 ele = strtol(str[21], nullptr, 10);
  3800. body << YAML::Key << "Element" << YAML::Value << name2Upper(constant_lookup(ele % 20, "ELE_") + 4);
  3801. body << YAML::Key << "ElementLevel" << YAML::Value << floor(ele / 20.);
  3802. if (atoi(str[22]) != 200)
  3803. body << YAML::Key << "WalkSpeed" << YAML::Value << str[22];
  3804. if (atoi(str[23]) != 504)
  3805. body << YAML::Key << "AttackDelay" << YAML::Value << str[23];
  3806. if (atoi(str[24]) != 1020)
  3807. body << YAML::Key << "AttackMotion" << YAML::Value << str[24];
  3808. if (atoi(str[25]) != 360)
  3809. body << YAML::Key << "DamageMotion" << YAML::Value << str[25];
  3810. auto list = elemental_skill_tree.find( atoi(str[0]) );
  3811. if (list != elemental_skill_tree.end()) {
  3812. body << YAML::Key << "Mode";
  3813. body << YAML::BeginMap;
  3814. for (const auto &it : list->second) {
  3815. body << YAML::Key << it.mode_name;
  3816. body << YAML::BeginMap;
  3817. body << YAML::Key << "Skill" << YAML::Value << it.skill_name;
  3818. if (it.lv != 1)
  3819. body << YAML::Key << "Level" << YAML::Value << it.lv;
  3820. body << YAML::EndMap;
  3821. }
  3822. body << YAML::EndMap;
  3823. }
  3824. body << YAML::EndMap;
  3825. return true;
  3826. }
  3827. // mercenary_db.yml function
  3828. //---------------------------
  3829. static bool mercenary_read_skilldb( char* str[], size_t columns, size_t current ){
  3830. uint16 skill_id = atoi(str[1]);
  3831. std::string *skill_name = util::umap_find(aegis_skillnames, skill_id);
  3832. if (skill_name == nullptr) {
  3833. ShowError("mercenary_read_skilldb: Invalid skill '%hu'.\n", skill_id);
  3834. return false;
  3835. }
  3836. s_mercenary_skill_csv entry = {};
  3837. entry.skill_name = *skill_name;
  3838. entry.max_lv = atoi(str[2]);
  3839. uint16 class_ = atoi(str[0]);
  3840. if (util::umap_find(mercenary_skill_tree, class_))
  3841. mercenary_skill_tree[class_].push_back(entry);
  3842. else {
  3843. mercenary_skill_tree[class_] = std::vector<s_mercenary_skill_csv>();
  3844. mercenary_skill_tree[class_].push_back(entry);
  3845. }
  3846. return true;
  3847. }
  3848. // Copied and adjusted from mercenary.cpp
  3849. static bool mercenary_readdb( char* str[], size_t columns, size_t current ){
  3850. body << YAML::BeginMap;
  3851. body << YAML::Key << "Id" << YAML::Value << str[0];
  3852. body << YAML::Key << "AegisName" << YAML::Value << str[1];
  3853. body << YAML::Key << "Name" << YAML::Value << str[2];
  3854. if (atoi(str[3]) != 1)
  3855. body << YAML::Key << "Level" << YAML::Value << str[3];
  3856. if (atoi(str[4]) != 1)
  3857. body << YAML::Key << "Hp" << YAML::Value << str[4];
  3858. if (atoi(str[5]) != 1)
  3859. body << YAML::Key << "Sp" << YAML::Value << str[5];
  3860. if (atoi(str[7]) != 0)
  3861. body << YAML::Key << "Attack" << YAML::Value << str[7];
  3862. if (atoi(str[8]) != 0)
  3863. body << YAML::Key << "Attack2" << YAML::Value << str[8];
  3864. if (atoi(str[9]) != 0)
  3865. body << YAML::Key << "Defense" << YAML::Value << str[9];
  3866. if (atoi(str[10]) != 0)
  3867. body << YAML::Key << "MagicDefense" << YAML::Value << str[10];
  3868. if (atoi(str[11]) != 1)
  3869. body << YAML::Key << "Str" << YAML::Value << str[11];
  3870. if (atoi(str[12]) != 1)
  3871. body << YAML::Key << "Agi" << YAML::Value << str[12];
  3872. if (atoi(str[13]) != 1)
  3873. body << YAML::Key << "Vit" << YAML::Value << str[13];
  3874. if (atoi(str[14]) != 1)
  3875. body << YAML::Key << "Int" << YAML::Value << str[14];
  3876. if (atoi(str[15]) != 1)
  3877. body << YAML::Key << "Dex" << YAML::Value << str[15];
  3878. if (atoi(str[16]) != 1)
  3879. body << YAML::Key << "Luk" << YAML::Value << str[16];
  3880. if (atoi(str[6]) != 0)
  3881. body << YAML::Key << "AttackRange" << YAML::Value << str[6];
  3882. if (atoi(str[17]) != 0)
  3883. body << YAML::Key << "SkillRange" << YAML::Value << str[17];
  3884. if (atoi(str[18]) != 0)
  3885. body << YAML::Key << "ChaseRange" << YAML::Value << str[18];
  3886. if (atoi(str[19]) != 0)
  3887. body << YAML::Key << "Size" << YAML::Value << constant_lookup(strtol(str[19], nullptr, 10), "Size_") + 5;
  3888. if (atoi(str[20]) != 0)
  3889. body << YAML::Key << "Race" << YAML::Value << name2Upper(constant_lookup(atoi(str[20]), "RC_") + 3);
  3890. int32 ele = strtol(str[21], nullptr, 10);
  3891. if (atoi(str[21]) != 0)
  3892. body << YAML::Key << "Element" << YAML::Value << name2Upper(constant_lookup(ele % 20, "ELE_") + 4);
  3893. if (atoi(str[21]) != 1)
  3894. body << YAML::Key << "ElementLevel" << YAML::Value << floor(ele / 20.);
  3895. if (atoi(str[22]) != 0)
  3896. body << YAML::Key << "WalkSpeed" << YAML::Value << cap_value(std::stoi(str[22]), MIN_WALK_SPEED, MAX_WALK_SPEED);
  3897. if (atoi(str[23]) != 0)
  3898. body << YAML::Key << "AttackDelay" << YAML::Value << str[23];
  3899. if (atoi(str[24]) != 0)
  3900. body << YAML::Key << "AttackMotion" << YAML::Value << str[24];
  3901. if (atoi(str[25]) != 0)
  3902. body << YAML::Key << "DamageMotion" << YAML::Value << str[25];
  3903. for (const auto &skillit : mercenary_skill_tree) {
  3904. if (skillit.first != atoi(str[0]))
  3905. continue;
  3906. body << YAML::Key << "Skills";
  3907. body << YAML::BeginSeq;
  3908. for (const auto &it : skillit.second) {
  3909. body << YAML::BeginMap;
  3910. body << YAML::Key << "Name" << YAML::Value << it.skill_name;
  3911. body << YAML::Key << "MaxLevel" << YAML::Value << it.max_lv;
  3912. body << YAML::EndMap;
  3913. }
  3914. body << YAML::EndSeq;
  3915. }
  3916. body << YAML::EndMap;
  3917. return true;
  3918. }
  3919. // Copied and adjusted from pc.cpp
  3920. static bool pc_readdb_skilltree( char* fields[], size_t columns, size_t current ){
  3921. uint16 baselv, joblv, offset;
  3922. uint16 class_ = (uint16)atoi(fields[0]);
  3923. uint16 skill_id = (uint16)atoi(fields[1]);
  3924. if (columns == 5 + MAX_PC_SKILL_REQUIRE * 2) { // Base/Job level requirement extra columns
  3925. baselv = (uint16)atoi(fields[3]);
  3926. joblv = (uint16)atoi(fields[4]);
  3927. offset = 5;
  3928. }
  3929. else if (columns == 3 + MAX_PC_SKILL_REQUIRE * 2) {
  3930. baselv = joblv = 0;
  3931. offset = 3;
  3932. }
  3933. else {
  3934. ShowWarning("pc_readdb_skilltree: Invalid number of colums in skill %hu of job %d's tree.\n", skill_id, class_);
  3935. return false;
  3936. }
  3937. const char* constant = constant_lookup(class_, "JOB_");
  3938. if (constant == nullptr) {
  3939. ShowWarning("pc_readdb_skilltree: Invalid job class %d specified.\n", class_);
  3940. return false;
  3941. }
  3942. std::string job_name(constant);
  3943. std::string* skill_name = util::umap_find( aegis_skillnames, skill_id );
  3944. if( skill_name == nullptr ){
  3945. ShowWarning("pc_readdb_skilltree: Unable to load skill %hu into job %d's tree.\n", skill_id, class_);
  3946. return false;
  3947. }
  3948. uint16 skill_lv = (uint16)atoi(fields[2]);
  3949. std::vector<s_skill_tree_entry_csv> *job = util::map_find(skill_tree, class_);
  3950. bool exists = job != nullptr;
  3951. s_skill_tree_entry_csv entry;
  3952. entry.skill_name = *skill_name;
  3953. entry.skill_id = skill_id;
  3954. entry.skill_lv = skill_lv;
  3955. entry.baselv = baselv;
  3956. entry.joblv = joblv;
  3957. for (uint16 i = 0; i < MAX_PC_SKILL_REQUIRE; i++) {
  3958. uint16 req_skill_id = (uint16)atoi(fields[i * 2 + offset]);
  3959. skill_lv = (uint16)atoi(fields[i * 2 + offset + 1]);
  3960. if (req_skill_id == 0)
  3961. continue;
  3962. skill_name = util::umap_find( aegis_skillnames, req_skill_id );
  3963. if( skill_name == nullptr ){
  3964. ShowWarning("pc_readdb_skilltree: Unable to load requirement skill %hu into job %d's tree.", req_skill_id, class_);
  3965. return false;
  3966. }
  3967. entry.need.insert({ *skill_name, skill_lv });
  3968. }
  3969. if (exists)
  3970. job->push_back(entry);
  3971. else {
  3972. std::vector<s_skill_tree_entry_csv> tree;
  3973. tree.push_back(entry);
  3974. skill_tree.insert({ class_, tree });
  3975. }
  3976. return true;
  3977. }
  3978. static bool pc_readdb_skilltree_yaml(void) {
  3979. for (const auto &it : skill_tree) {
  3980. body << YAML::BeginMap;
  3981. std::string job = constant_lookup(it.first, "JOB_");
  3982. job.erase( 0, 4 );
  3983. body << YAML::Key << "Job" << YAML::Value << name2Upper( job );
  3984. body << YAML::Key << "Tree";
  3985. body << YAML::BeginSeq;
  3986. for (const auto &subit : it.second) {
  3987. body << YAML::BeginMap;
  3988. body << YAML::Key << "Name" << YAML::Value << subit.skill_name;
  3989. body << YAML::Key << "MaxLevel" << YAML::Value << subit.skill_lv;
  3990. if (!subit.need.empty()) {
  3991. body << YAML::Key << "Requires";
  3992. body << YAML::BeginSeq;
  3993. for (const auto &terit : subit.need) {
  3994. body << YAML::BeginMap;
  3995. body << YAML::Key << "Name" << YAML::Value << terit.first;
  3996. body << YAML::Key << "Level" << YAML::Value << terit.second;
  3997. body << YAML::EndMap;
  3998. }
  3999. body << YAML::EndSeq;
  4000. }
  4001. if (subit.baselv > 0)
  4002. body << YAML::Key << "BaseLevel" << YAML::Value << subit.baselv;
  4003. if (subit.joblv > 0)
  4004. body << YAML::Key << "JobLevel" << YAML::Value << subit.joblv;
  4005. body << YAML::EndMap;
  4006. }
  4007. body << YAML::EndSeq;
  4008. body << YAML::EndMap;
  4009. }
  4010. return true;
  4011. }
  4012. // Copied and adjusted from itemdb.cpp
  4013. static int32 itemdb_combo_split_atoi (char *str, t_itemid *val) {
  4014. int32 i;
  4015. for (i = 0; i < MAX_ITEMS_PER_COMBO; i++) {
  4016. if (!str)
  4017. break;
  4018. val[i] = strtoul(str, nullptr, 10);
  4019. str = strchr(str,':');
  4020. if (str)
  4021. *str++=0;
  4022. }
  4023. if (i == 0) //No data found.
  4024. return 0;
  4025. return i;
  4026. }
  4027. // Copied and adjusted from itemdb.cpp
  4028. static bool itemdb_read_combos(const char* file) {
  4029. FILE* fp = fopen( file, "r" );
  4030. if( fp == nullptr ){
  4031. ShowError( "Can't read %s\n", file );
  4032. return 0;
  4033. }
  4034. uint32 lines = 0, count = 0;
  4035. char line[1024];
  4036. char path[256];
  4037. // process rows one by one
  4038. while (fgets(line, sizeof(line), fp)) {
  4039. char *str[2], *p;
  4040. lines++;
  4041. if (line[0] == '/' && line[1] == '/')
  4042. continue;
  4043. memset(str, 0, sizeof(str));
  4044. p = line;
  4045. p = trim(p);
  4046. if (*p == '\0')
  4047. continue;// empty line
  4048. if (!strchr(p,',')) {
  4049. ShowError("itemdb_read_combos: Insufficient columns in line %d of \"%s\", skipping.\n", lines, path);
  4050. continue;
  4051. }
  4052. str[0] = p;
  4053. p = strchr(p,',');
  4054. *p = '\0';
  4055. p++;
  4056. str[1] = p;
  4057. p = strchr(p,',');
  4058. p++;
  4059. if (str[1][0] != '{') {
  4060. ShowError("itemdb_read_combos(#1): Invalid format (Script column) in line %d of \"%s\", skipping.\n", lines, path);
  4061. continue;
  4062. }
  4063. if ( str[1][strlen(str[1])-1] != '}' ) {
  4064. ShowError("itemdb_read_combos(#2): Invalid format (Script column) in line %d of \"%s\", skipping.\n", lines, path);
  4065. continue;
  4066. }
  4067. t_itemid items[MAX_ITEMS_PER_COMBO];
  4068. int32 v = 0, retcount = 0;
  4069. if ((retcount = itemdb_combo_split_atoi(str[0], items)) < 2) {
  4070. ShowError("itemdb_read_combos: line %d of \"%s\" doesn't have enough items to make for a combo (min:2), skipping.\n", lines, path);
  4071. continue;
  4072. }
  4073. for (v = 0; v < retcount; v++) {
  4074. std::string *item_name = util::umap_find(aegis_itemnames, items[v]);
  4075. if (item_name == nullptr) {
  4076. ShowWarning("itemdb_read_combos: Invalid item ID %" PRIu32 ".\n", items[v]);
  4077. break;
  4078. }
  4079. }
  4080. if (v < retcount)
  4081. continue;
  4082. body << YAML::BeginMap;
  4083. body << YAML::Key << "Combos";
  4084. body << YAML::BeginSeq;
  4085. body << YAML::BeginMap;
  4086. body << YAML::Key << "Combo";
  4087. body << YAML::BeginSeq;
  4088. for (v = 0; v < retcount; v++) {
  4089. body << YAML::BeginMap;
  4090. std::string *item_name = util::umap_find(aegis_itemnames, items[v]);
  4091. body << YAML::Key << *item_name;
  4092. body << YAML::EndMap;
  4093. }
  4094. body << YAML::EndSeq;
  4095. body << YAML::EndMap;
  4096. str[1] = str[1] + 1; //skip the first left curly
  4097. str[1][strlen(str[1])-1] = '\0'; //null the last right curly
  4098. body << YAML::EndSeq;
  4099. body << YAML::Key << "Script" << YAML::Literal << trim(str[1]);
  4100. body << YAML::EndMap;
  4101. count++;
  4102. }
  4103. fclose(fp);
  4104. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, file);
  4105. return true;
  4106. }
  4107. // Copied and adjusted from cashshop.cpp
  4108. static bool cashshop_parse_dbrow( char* fields[], size_t columns, size_t current ){
  4109. uint16 tab = atoi( fields[0] );
  4110. t_itemid nameid = strtoul( fields[1], nullptr, 10 );
  4111. uint32 price = atoi( fields[2] );
  4112. std::string* item_name = util::umap_find( aegis_itemnames, nameid );
  4113. if( item_name == nullptr ){
  4114. ShowWarning( "cashshop_parse_dbrow: Invalid item id %u.\n", nameid );
  4115. return false;
  4116. }
  4117. if( tab >= CASHSHOP_TAB_MAX ){
  4118. ShowWarning( "cashshop_parse_dbrow: Invalid tab %d in line '%d', skipping...\n", tab, current );
  4119. return false;
  4120. }else if( price < 1 ){
  4121. ShowWarning( "cashshop_parse_dbrow: Invalid price %d in line '%d', skipping...\n", price, current );
  4122. return false;
  4123. }
  4124. const char* constant_ptr = constant_lookup( tab, "CASHSHOP_TAB_" );
  4125. if( constant_ptr == nullptr ){
  4126. ShowError( "cashshop_parse_dbrow: CASHSHOP_TAB constant for tab %hu was not found, skipping...\n", tab );
  4127. return false;
  4128. }
  4129. std::string constant = constant_ptr;
  4130. constant.erase( 0, 13 );
  4131. constant = name2Upper( constant );
  4132. body << YAML::BeginMap;
  4133. body << YAML::Key << "Tab" << YAML::Value << constant;
  4134. body << YAML::Key << "Items";
  4135. body << YAML::BeginSeq;
  4136. body << YAML::BeginMap;
  4137. body << YAML::Key << "Item" << YAML::Value << *item_name;
  4138. body << YAML::Key << "Price" << YAML::Value << price;
  4139. body << YAML::EndMap;
  4140. body << YAML::EndSeq;
  4141. body << YAML::EndMap;
  4142. return true;
  4143. }
  4144. // homunculus_db.yml function
  4145. //---------------------------
  4146. static bool read_homunculus_skilldb( char* split[], size_t columns, size_t current ){
  4147. s_homun_skill_tree_entry entry = {};
  4148. entry.id = atoi(split[1]);
  4149. entry.max = atoi(split[2]);
  4150. entry.need_level = atoi(split[3]);
  4151. entry.intimacy = cap_value(atoi(split[14]), 0, 1000);
  4152. for (int32 i = 0; i < MAX_HOM_SKILL_REQUIRE; i++) {
  4153. if (atoi(split[4 + i * 2]) > 0)
  4154. entry.need.emplace(atoi(split[4 + i * 2]), atoi(split[4 + i * 2 + 1]));
  4155. }
  4156. if (util::umap_find(hom_skill_tree, atoi(split[0])))
  4157. hom_skill_tree[(uint16)atoi(split[0])].push_back(entry);
  4158. else {
  4159. hom_skill_tree[(uint16)atoi(split[0])] = std::vector<s_homun_skill_tree_entry>();
  4160. hom_skill_tree[(uint16)atoi(split[0])].push_back(entry);
  4161. }
  4162. return true;
  4163. }
  4164. static bool compareHomSkillId(const s_homun_skill_tree_entry &a, const s_homun_skill_tree_entry &b) {
  4165. return a.id < b.id;
  4166. }
  4167. // Copied and adjusted from homunculus.cpp
  4168. static bool read_homunculusdb( char* str[], size_t columns, size_t current ){
  4169. bool has_evo = false;
  4170. body << YAML::BeginMap;
  4171. body << YAML::Key << "Class" << YAML::Value << name2Upper(constant_lookup(atoi(str[0]), "MER_") + 4);
  4172. body << YAML::Key << "Name" << YAML::Value << str[2];
  4173. if (atoi(str[0]) != atoi(str[1])) {
  4174. body << YAML::Key << "EvolutionClass" << YAML::Value << name2Upper(constant_lookup(atoi(str[1]), "MER_") + 4);
  4175. has_evo = true;
  4176. }
  4177. if (atoi(str[3]) != ITEMID_PET_FOOD)
  4178. body << YAML::Key << "Food" << YAML::Value << name2Upper(*util::umap_find(aegis_itemnames, (t_itemid)atoi(str[3])));
  4179. if (atoi(str[4]) != 60000)
  4180. body << YAML::Key << "HungryDelay" << YAML::Value << atoi(str[4]);
  4181. if (atoi(str[7]) != RC_DEMIHUMAN)
  4182. body << YAML::Key << "Race" << YAML::Value << name2Upper(constant_lookup(atoi(str[7]), "RC_") + 3);
  4183. if (atoi(str[8]) != ELE_NEUTRAL)
  4184. body << YAML::Key << "Element" << YAML::Value << name2Upper(constant_lookup(atoi(str[8]), "ELE_") + 4);
  4185. if (atoi(str[5]) != SZ_SMALL)
  4186. body << YAML::Key << "Size" << YAML::Value << name2Upper(constant_lookup(atoi(str[5]), "Size_") + 5);
  4187. if (atoi(str[6]) != SZ_MEDIUM)
  4188. body << YAML::Key << "EvolutionSize" << YAML::Value << name2Upper(constant_lookup(atoi(str[6]), "Size_") + 5);
  4189. if (atoi(str[9]) != 700)
  4190. body << YAML::Key << "AttackDelay" << YAML::Value << atoi(str[9]);
  4191. body << YAML::Key << "Status";
  4192. body << YAML::BeginSeq;
  4193. body << YAML::BeginMap;
  4194. body << YAML::Key << "Type" << YAML::Value << "Hp";
  4195. body << YAML::Key << "Base" << YAML::Value << atoi(str[10]);
  4196. body << YAML::Key << "GrowthMinimum" << YAML::Value << atoi(str[18]);
  4197. body << YAML::Key << "GrowthMaximum" << YAML::Value << atoi(str[19]);
  4198. if (has_evo) {
  4199. body << YAML::Key << "EvolutionMinimum" << YAML::Value << atoi(str[34]);
  4200. body << YAML::Key << "EvolutionMaximum" << YAML::Value << atoi(str[35]);
  4201. }
  4202. body << YAML::EndMap;
  4203. body << YAML::BeginMap;
  4204. body << YAML::Key << "Type" << YAML::Value << "Sp";
  4205. body << YAML::Key << "Base" << YAML::Value << atoi(str[11]);
  4206. body << YAML::Key << "GrowthMinimum" << YAML::Value << atoi(str[20]);
  4207. body << YAML::Key << "GrowthMaximum" << YAML::Value << atoi(str[21]);
  4208. if (has_evo) {
  4209. body << YAML::Key << "EvolutionMinimum" << YAML::Value << atoi(str[36]);
  4210. body << YAML::Key << "EvolutionMaximum" << YAML::Value << atoi(str[37]);
  4211. }
  4212. body << YAML::EndMap;
  4213. body << YAML::BeginMap;
  4214. body << YAML::Key << "Type" << YAML::Value << "Str";
  4215. body << YAML::Key << "Base" << YAML::Value << atoi(str[12]);
  4216. body << YAML::Key << "GrowthMinimum" << YAML::Value << atoi(str[22]);
  4217. body << YAML::Key << "GrowthMaximum" << YAML::Value << atoi(str[23]);
  4218. if (has_evo) {
  4219. body << YAML::Key << "EvolutionMinimum" << YAML::Value << atoi(str[38]);
  4220. body << YAML::Key << "EvolutionMaximum" << YAML::Value << atoi(str[39]);
  4221. }
  4222. body << YAML::EndMap;
  4223. body << YAML::BeginMap;
  4224. body << YAML::Key << "Type" << YAML::Value << "Agi";
  4225. body << YAML::Key << "Base" << YAML::Value << atoi(str[13]);
  4226. body << YAML::Key << "GrowthMinimum" << YAML::Value << atoi(str[24]);
  4227. body << YAML::Key << "GrowthMaximum" << YAML::Value << atoi(str[25]);
  4228. if (has_evo) {
  4229. body << YAML::Key << "EvolutionMinimum" << YAML::Value << atoi(str[40]);
  4230. body << YAML::Key << "EvolutionMaximum" << YAML::Value << atoi(str[41]);
  4231. }
  4232. body << YAML::EndMap;
  4233. body << YAML::BeginMap;
  4234. body << YAML::Key << "Type" << YAML::Value << "Vit";
  4235. body << YAML::Key << "Base" << YAML::Value << atoi(str[14]);
  4236. body << YAML::Key << "GrowthMinimum" << YAML::Value << atoi(str[26]);
  4237. body << YAML::Key << "GrowthMaximum" << YAML::Value << atoi(str[27]);
  4238. if (has_evo) {
  4239. body << YAML::Key << "EvolutionMinimum" << YAML::Value << atoi(str[42]);
  4240. body << YAML::Key << "EvolutionMaximum" << YAML::Value << atoi(str[43]);
  4241. }
  4242. body << YAML::EndMap;
  4243. body << YAML::BeginMap;
  4244. body << YAML::Key << "Type" << YAML::Value << "Int";
  4245. body << YAML::Key << "Base" << YAML::Value << atoi(str[15]);
  4246. body << YAML::Key << "GrowthMinimum" << YAML::Value << atoi(str[28]);
  4247. body << YAML::Key << "GrowthMaximum" << YAML::Value << atoi(str[29]);
  4248. if (has_evo) {
  4249. body << YAML::Key << "EvolutionMinimum" << YAML::Value << atoi(str[44]);
  4250. body << YAML::Key << "EvolutionMaximum" << YAML::Value << atoi(str[45]);
  4251. }
  4252. body << YAML::EndMap;
  4253. body << YAML::BeginMap;
  4254. body << YAML::Key << "Type" << YAML::Value << "Dex";
  4255. body << YAML::Key << "Base" << YAML::Value << atoi(str[16]);
  4256. body << YAML::Key << "GrowthMinimum" << YAML::Value << atoi(str[30]);
  4257. body << YAML::Key << "GrowthMaximum" << YAML::Value << atoi(str[31]);
  4258. if (has_evo) {
  4259. body << YAML::Key << "EvolutionMinimum" << YAML::Value << atoi(str[46]);
  4260. body << YAML::Key << "EvolutionMaximum" << YAML::Value << atoi(str[47]);
  4261. }
  4262. body << YAML::EndMap;
  4263. body << YAML::BeginMap;
  4264. body << YAML::Key << "Type" << YAML::Value << "Luk";
  4265. body << YAML::Key << "Base" << YAML::Value << atoi(str[17]);
  4266. body << YAML::Key << "GrowthMinimum" << YAML::Value << atoi(str[32]);
  4267. body << YAML::Key << "GrowthMaximum" << YAML::Value << atoi(str[33]);
  4268. if (has_evo) {
  4269. body << YAML::Key << "EvolutionMinimum" << YAML::Value << atoi(str[48]);
  4270. body << YAML::Key << "EvolutionMaximum" << YAML::Value << atoi(str[49]);
  4271. }
  4272. body << YAML::EndMap;
  4273. body << YAML::EndSeq;
  4274. // Gather and sort skill tree data
  4275. std::vector<s_homun_skill_tree_entry> *skill_tree_base = nullptr, *skill_tree_evo = nullptr;
  4276. skill_tree_base = util::umap_find(hom_skill_tree, atoi(str[0]));
  4277. std::sort(skill_tree_base->begin(), skill_tree_base->end(), compareHomSkillId);
  4278. if (has_evo) {
  4279. skill_tree_evo = util::umap_find(hom_skill_tree, atoi(str[1]));
  4280. std::sort(skill_tree_evo->begin(), skill_tree_evo->end(), compareHomSkillId);
  4281. }
  4282. // Get a difference between the base class and evo class skill tree to find skills granted through evolution
  4283. std::vector<s_homun_skill_tree_entry> tree_diff;
  4284. if (skill_tree_evo != nullptr) {
  4285. for (const auto &evoit : *skill_tree_evo) {
  4286. bool contains = false;
  4287. for (const auto &baseit : *skill_tree_base) {
  4288. if (baseit.id == evoit.id) {
  4289. contains = true;
  4290. break;
  4291. }
  4292. }
  4293. if (!contains) {
  4294. // Skill is not part of the base tree, we can only assume it's an evolution granted skill thanks to brilliant formatting of our TXT homun_db!
  4295. tree_diff.push_back(evoit);
  4296. }
  4297. }
  4298. }
  4299. if (skill_tree_base != nullptr) {
  4300. body << YAML::Key << "SkillTree";
  4301. body << YAML::BeginSeq;
  4302. for (const auto &skillit : *skill_tree_base) {
  4303. std::string *skill_name = util::umap_find(aegis_skillnames, skillit.id);
  4304. if (skill_name == nullptr) {
  4305. ShowError("Skill name for homunculus skill ID %hu is not known.\n", skillit.id);
  4306. return false;
  4307. }
  4308. body << YAML::BeginMap;
  4309. body << YAML::Key << "Skill" << YAML::Value << *skill_name;
  4310. body << YAML::Key << "MaxLevel" << YAML::Value << (int32)skillit.max;
  4311. if (skillit.need_level > 0)
  4312. body << YAML::Key << "RequiredLevel" << YAML::Value << (int32)skillit.need_level;
  4313. if (skillit.intimacy > 0)
  4314. body << YAML::Key << "RequiredIntimacy" << YAML::Value << skillit.intimacy;
  4315. if (!skillit.need.empty()) {
  4316. body << YAML::Key << "Required";
  4317. body << YAML::BeginSeq;
  4318. for (const auto &it : skillit.need) {
  4319. uint16 required_skill_id = it.first;
  4320. uint16 required_skill_level = it.second;
  4321. if (required_skill_id == 0 || required_skill_level == 0)
  4322. continue;
  4323. std::string *required_name = util::umap_find(aegis_skillnames, required_skill_id);
  4324. if (required_name == nullptr) {
  4325. ShowError("Skill name for required skill id %hu is not known.\n", required_skill_id);
  4326. return false;
  4327. }
  4328. body << YAML::BeginMap;
  4329. body << YAML::Key << "Skill" << YAML::Value << *required_name;
  4330. body << YAML::Key << "Level" << YAML::Value << required_skill_level;
  4331. body << YAML::EndMap;
  4332. }
  4333. body << YAML::EndSeq;
  4334. }
  4335. body << YAML::EndMap;
  4336. }
  4337. for (const auto &skillit : tree_diff) {
  4338. std::string *skill_name = util::umap_find(aegis_skillnames, skillit.id);
  4339. if (skill_name == nullptr) {
  4340. ShowError("Skill name for homunculus skill ID %hu is not known.\n", skillit.id);
  4341. return false;
  4342. }
  4343. body << YAML::BeginMap;
  4344. body << YAML::Key << "Skill" << YAML::Value << *skill_name;
  4345. body << YAML::Key << "MaxLevel" << YAML::Value << (int32)skillit.max;
  4346. if (skillit.need_level > 0)
  4347. body << YAML::Key << "RequiredLevel" << YAML::Value << (int32)skillit.need_level;
  4348. if (skillit.intimacy > 0)
  4349. body << YAML::Key << "RequiredIntimacy" << YAML::Value << skillit.intimacy;
  4350. body << YAML::Key << "RequireEvolution" << YAML::Value << "true";
  4351. if (!skillit.need.empty()) {
  4352. body << YAML::Key << "Required";
  4353. body << YAML::BeginSeq;
  4354. for (const auto &it : skillit.need) {
  4355. uint16 required_skill_id = it.first;
  4356. uint16 required_skill_level = it.second;
  4357. if (required_skill_id == 0 || required_skill_level == 0)
  4358. continue;
  4359. std::string *required_name = util::umap_find(aegis_skillnames, required_skill_id);
  4360. if (required_name == nullptr) {
  4361. ShowError("Skill name for required skill id %hu is not known.\n", required_skill_id);
  4362. return false;
  4363. }
  4364. body << YAML::BeginMap;
  4365. body << YAML::Key << "Skill" << YAML::Value << *required_name;
  4366. body << YAML::Key << "Level" << YAML::Value << required_skill_level;
  4367. body << YAML::EndMap;
  4368. }
  4369. body << YAML::EndSeq;
  4370. }
  4371. body << YAML::EndMap;
  4372. }
  4373. body << YAML::EndSeq;
  4374. }
  4375. body << YAML::EndMap;
  4376. return true;
  4377. }
  4378. static bool mob_parse_row_mobskilldb(char** str, size_t columns, size_t current) {
  4379. int32 id = strtol(str[0], nullptr, 10);
  4380. std::string mob_name;
  4381. if (id == -3)
  4382. mob_name = "ALL";
  4383. else if (id == -2)
  4384. mob_name = "ALL_NORMAL";
  4385. else if (id == -1)
  4386. mob_name = "ALL_BOSS";
  4387. else {
  4388. uint16 mob_id = static_cast<uint16>(id);
  4389. std::string* name = util::umap_find( aegis_mobnames, mob_id );
  4390. if (name == nullptr) {
  4391. ShowWarning( "mob_parse_row_mobskilldb: Non existant Mob id %hu.\n", mob_id );
  4392. return true;
  4393. }
  4394. mob_name = *name;
  4395. }
  4396. if (strcmp(str[1], "clear") == 0) {
  4397. body << YAML::BeginMap;
  4398. body << YAML::Key << "Remove" << YAML::Value << mob_name;
  4399. body << YAML::EndMap;
  4400. return true;
  4401. }
  4402. std::vector<s_mob_skill_csv> *skills = util::umap_find(mob_skill_db, mob_name);
  4403. bool exists = skills != nullptr;
  4404. s_mob_skill_csv entry;
  4405. std::string state_name = str[2];
  4406. std::transform(state_name.begin(), state_name.end(), state_name.begin(), ::toupper);
  4407. entry.state_name = state_name;
  4408. // Skill ID
  4409. uint16 skill_id = atoi(str[3]);
  4410. std::string* skill_name = util::umap_find( aegis_skillnames, skill_id );
  4411. if( skill_name == nullptr ){
  4412. ShowError( "Skill name for skill id %hu is not known.\n", atoi(str[3]) );
  4413. return false;
  4414. }
  4415. entry.skill_name = *skill_name;
  4416. entry.skill_lv = static_cast<uint16>(atoi(str[4]));
  4417. entry.permillage = static_cast<int16>(atoi(str[5]));
  4418. entry.casttime = static_cast<int32>(atoi(str[6]));
  4419. entry.delay = static_cast<int32>(atoi(str[7]));
  4420. if (strcmp(str[8],"yes") == 0)
  4421. entry.cancel = true;
  4422. else
  4423. entry.cancel = false;
  4424. // Target
  4425. std::string target_name = str[9];
  4426. std::transform(target_name.begin(), target_name.end(), target_name.begin(), ::toupper);
  4427. entry.target_name = target_name;
  4428. // Cond1
  4429. std::string cond1 = str[10];
  4430. std::transform(cond1.begin(), cond1.end(), cond1.begin(), ::toupper);
  4431. entry.cond1_name = cond1;
  4432. // Cond2
  4433. std::string cond2(str[11]);
  4434. if (cond1 == "MYSTATUSON" || cond1 == "MYSTATUSOFF" || cond1 == "FRIENDSTATUSON" || cond1 == "FRIENDSTATUSOFF") { // SC_ status
  4435. std::transform(cond2.begin(), cond2.end(), cond2.begin(), ::toupper);
  4436. entry.cond2_name = "SC_" + cond2;
  4437. }
  4438. else if (atoi(str[11]) > 0) {
  4439. if (cond1 != "SKILLUSED" && cond1 != "AFTERSKILL") // Number
  4440. entry.cond2_name = cond2;
  4441. else { // Aegis skill name
  4442. uint16 tmp_skill_id = atoi(str[11]);
  4443. std::string* tmp_skill_name = util::umap_find( aegis_skillnames, tmp_skill_id );
  4444. if( tmp_skill_name == nullptr ){
  4445. ShowError( "Invalid specified skill %hu for %s (source: skill id %hu).\n", tmp_skill_id, cond1.c_str(), atoi(str[3]) );
  4446. return false;
  4447. }
  4448. entry.cond2_name = *tmp_skill_name;
  4449. }
  4450. }
  4451. entry.cond3 = 0;
  4452. for (uint16 i = 0; i < 5; ++i) {
  4453. uint16 index = 12 + i;
  4454. if (*str[index]) {
  4455. int32 val = (int)strtol(str[index],NULL,0);
  4456. if (val < 1)
  4457. continue;
  4458. std::string val_name = std::to_string(val);
  4459. if (i == 0 && (cond1 == "MYHPINRATE" || cond1 == "FRIENDHPINRATE")) { // Upper bound now stored in cond3 instead of val 1
  4460. entry.cond3 = val;
  4461. continue;
  4462. }
  4463. switch( skill_id ) {
  4464. case NPC_METAMORPHOSIS:
  4465. case NPC_SUMMONSLAVE:
  4466. case NPC_SUMMONMONSTER:
  4467. case NPC_DEATHSUMMON: {
  4468. std::string* mob_name_val = util::umap_find( aegis_mobnames, static_cast<uint16>(val) );
  4469. if (mob_name_val == nullptr) {
  4470. ShowError( "Mob name for skill id %hu is not known.\n", val );
  4471. return false;
  4472. }
  4473. val_name = *mob_name_val;
  4474. entry.val.insert({ i, val_name });
  4475. continue;
  4476. }
  4477. case NPC_EMOTION:
  4478. case NPC_EMOTION_ON:
  4479. if (i == 0) { // Emoticon is now stored in entry.emotion instead of val 1
  4480. char *constant = const_cast<char *>(constant_lookup(val, "ET_"));
  4481. if (constant != nullptr)
  4482. entry.emotion = constant;
  4483. else {
  4484. std::string emotion(str[val]);
  4485. entry.emotion = emotion;
  4486. }
  4487. continue;
  4488. }
  4489. break;
  4490. default:
  4491. break;
  4492. }
  4493. // In any case the remain values should be the ai
  4494. std::string *ai = util::umap_find( um_mob_mode2ai, val );
  4495. if (ai == nullptr || strncasecmp(str[index], "0x", 2) != 0) {
  4496. ShowError( "Unknown Ai for mode %s.\n", str[index] );
  4497. return false;
  4498. }
  4499. entry.mob_ai = *ai;
  4500. }
  4501. }
  4502. if (*str[17]) {
  4503. char *constant = const_cast<char *>(constant_lookup(atoi(str[17]), "ET_"));
  4504. if (constant != nullptr)
  4505. entry.emotion = constant;
  4506. else {
  4507. std::string emotion(str[17]);
  4508. entry.emotion = emotion;
  4509. }
  4510. }
  4511. entry.msg_id = static_cast<uint16>(atoi(str[18]));
  4512. if (exists)
  4513. skills->push_back(entry);
  4514. else {
  4515. std::vector<s_mob_skill_csv> skill;
  4516. skill.push_back(entry);
  4517. mob_skill_db.insert({ mob_name, skill });
  4518. }
  4519. return true;
  4520. }
  4521. static bool mob_parse_row_mobskilldb_yaml(void) {
  4522. for (const auto &mobit : mob_skill_db) {
  4523. body << YAML::BeginMap;
  4524. body << YAML::Key << "Mob" << YAML::Value << mobit.first;
  4525. body << YAML::Key << "Skills";
  4526. body << YAML::BeginSeq;
  4527. uint16 count = 0;
  4528. for (const auto &mob_skill : mobit.second) {
  4529. body << YAML::BeginMap;
  4530. body << YAML::Key << "Index" << YAML::Value << count;
  4531. body << YAML::Key << "Name" << YAML::Value << mob_skill.skill_name;
  4532. body << YAML::Key << "Level" << YAML::Value << mob_skill.skill_lv;
  4533. body << YAML::Key << "State" << YAML::Value << mob_skill.state_name;
  4534. body << YAML::Key << "CastRate" << YAML::Value << mob_skill.permillage;
  4535. body << YAML::Key << "CastTime" << YAML::Value << mob_skill.casttime;
  4536. body << YAML::Key << "CastDelay" << YAML::Value << mob_skill.delay;
  4537. body << YAML::Key << "CastCancel" << YAML::Value << ( !mob_skill.cancel ? "false" : "true" );
  4538. body << YAML::Key << "Target" << YAML::Value << mob_skill.target_name;
  4539. body << YAML::Key << "Condition" << YAML::Value << mob_skill.cond1_name;
  4540. if (!mob_skill.cond2_name.empty())
  4541. body << YAML::Key << "ConditionValue1" << YAML::Value << mob_skill.cond2_name;
  4542. if (mob_skill.cond3 > 0)
  4543. body << YAML::Key << "ConditionValue2" << YAML::Value << mob_skill.cond3;
  4544. if (!mob_skill.mob_ai.empty())
  4545. body << YAML::Key << "Ai" << YAML::Value << mob_skill.mob_ai;
  4546. if (!mob_skill.val.empty()) {
  4547. body << YAML::Key << "Summon";
  4548. body << YAML::BeginSeq;
  4549. for (const auto &valit : mob_skill.val) {
  4550. body << YAML::BeginMap;
  4551. body << YAML::Key << "Index" << YAML::Value << valit.first;
  4552. body << YAML::Key << "Mob" << YAML::Value << valit.second;
  4553. body << YAML::EndMap;
  4554. }
  4555. body << YAML::EndSeq;
  4556. }
  4557. if (!mob_skill.emotion.empty())
  4558. body << YAML::Key << "Emotion" << YAML::Value << mob_skill.emotion;
  4559. if (mob_skill.msg_id > 0)
  4560. body << YAML::Key << "Chat" << YAML::Value << mob_skill.msg_id;
  4561. body << YAML::EndMap;
  4562. count++;
  4563. }
  4564. body << YAML::EndSeq;
  4565. body << YAML::EndMap;
  4566. }
  4567. return true;
  4568. }
  4569. int32 main( int32 argc, char *argv[] ){
  4570. return main_core<Csv2YamlTool>( argc, argv );
  4571. }