itemdb.cpp 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "itemdb.hpp"
  4. #include <iostream>
  5. #include <stdlib.h>
  6. #include "../common/nullpo.hpp"
  7. #include "../common/random.hpp"
  8. #include "../common/showmsg.hpp"
  9. #include "../common/strlib.hpp"
  10. #include "../common/utils.hpp"
  11. #include "../common/utilities.hpp"
  12. #include "battle.hpp" // struct battle_config
  13. #include "cashshop.hpp"
  14. #include "clif.hpp"
  15. #include "intif.hpp"
  16. #include "log.hpp"
  17. #include "mob.hpp"
  18. #include "pc.hpp"
  19. #include "status.hpp"
  20. using namespace rathena;
  21. ComboDatabase itemdb_combo;
  22. ItemGroupDatabase itemdb_group;
  23. struct s_roulette_db rd;
  24. static void itemdb_jobid2mapid(uint64 bclass[3], e_mapid jobmask, bool active);
  25. const std::string ItemDatabase::getDefaultLocation() {
  26. return std::string(db_path) + "/item_db.yml";
  27. }
  28. /**
  29. * Reads and parses an entry from the item_db.
  30. * @param node: YAML node containing the entry.
  31. * @return count of successfully parsed rows
  32. */
  33. uint64 ItemDatabase::parseBodyNode(const ryml::NodeRef& node) {
  34. t_itemid nameid;
  35. if (!this->asUInt32(node, "Id", nameid))
  36. return 0;
  37. std::shared_ptr<item_data> item = this->find(nameid);
  38. bool exists = item != nullptr;
  39. if (!exists) {
  40. if (!this->nodesExist(node, { "AegisName", "Name" }))
  41. return 0;
  42. item = std::make_shared<item_data>();
  43. item->nameid = nameid;
  44. item->flag.available = true;
  45. }
  46. if (this->nodeExists(node, "AegisName")) {
  47. std::string name;
  48. if (!this->asString(node, "AegisName", name))
  49. return 0;
  50. if (name.length() > ITEM_NAME_LENGTH) {
  51. this->invalidWarning(node["AegisName"], "AegisName \"%s\" exceeds maximum of %d characters, capping...\n", name.c_str(), ITEM_NAME_LENGTH - 1);
  52. }
  53. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  54. if (id != nullptr && id->nameid != nameid) {
  55. this->invalidWarning(node["AegisName"], "Found duplicate item Aegis name for %s, skipping.\n", name.c_str());
  56. return 0;
  57. }
  58. if( exists ){
  59. // Create a copy
  60. std::string aegisname = item->name;
  61. // Convert it to lower
  62. util::tolower( aegisname );
  63. // Remove old AEGIS name from lookup
  64. this->aegisNameToItemDataMap.erase( aegisname );
  65. }
  66. item->name.resize(ITEM_NAME_LENGTH);
  67. item->name = name.c_str();
  68. // Create a copy
  69. std::string aegisname = name;
  70. // Convert it to lower
  71. util::tolower( aegisname );
  72. this->aegisNameToItemDataMap[aegisname] = item;
  73. }
  74. if (this->nodeExists(node, "Name")) {
  75. std::string name;
  76. if (!this->asString(node, "Name", name))
  77. return 0;
  78. if (name.length() > ITEM_NAME_LENGTH) {
  79. this->invalidWarning(node["Name"], "Name \"%s\" exceeds maximum of %d characters, capping...\n", name.c_str(), ITEM_NAME_LENGTH - 1);
  80. }
  81. if( exists ){
  82. // Create a copy
  83. std::string ename = item->ename;
  84. // Convert it to lower
  85. util::tolower( ename );
  86. // Remove old name from lookup
  87. this->nameToItemDataMap.erase( ename );
  88. }
  89. item->ename.resize(ITEM_NAME_LENGTH);
  90. item->ename = name.c_str();
  91. // Create a copy
  92. std::string ename = name;
  93. // Convert it to lower
  94. util::tolower( ename );
  95. this->nameToItemDataMap[ename] = item;
  96. }
  97. if (this->nodeExists(node, "Type")) {
  98. std::string type;
  99. if (!this->asString(node, "Type", type))
  100. return 0;
  101. std::string type_constant = "IT_" + type;
  102. int64 constant;
  103. if (!script_get_constant(type_constant.c_str(), &constant) || constant < IT_HEALING || constant >= IT_MAX) {
  104. this->invalidWarning(node["Type"], "Invalid item type %s, defaulting to IT_ETC.\n", type.c_str());
  105. constant = IT_ETC;
  106. }
  107. item->type = static_cast<item_types>(constant);
  108. } else {
  109. if (!exists)
  110. item->type = IT_ETC;
  111. }
  112. if (this->nodeExists(node, "SubType")) {
  113. std::string type;
  114. if (!this->asString(node, "SubType", type))
  115. return 0;
  116. if (item->type == IT_WEAPON) {
  117. std::string type_constant = "W_" + type;
  118. int64 constant;
  119. if (!script_get_constant(type_constant.c_str(), &constant) || constant < W_FIST || constant >= MAX_WEAPON_TYPE) {
  120. this->invalidWarning(node["SubType"], "Invalid weapon type %s, defaulting to W_FIST.\n", type.c_str());
  121. item->subtype = W_FIST;
  122. }
  123. item->subtype = static_cast<weapon_type>(constant);
  124. } else if (item->type == IT_AMMO) {
  125. std::string type_constant = "AMMO_" + type;
  126. int64 constant;
  127. if (!script_get_constant(type_constant.c_str(), &constant) || constant <= AMMO_NONE || constant >= MAX_AMMO_TYPE) {
  128. this->invalidWarning(node["SubType"], "Invalid ammo type %s, defaulting to AMMO_NONE.\n", type.c_str());
  129. item->subtype = AMMO_NONE;
  130. }
  131. item->subtype = static_cast<e_ammo_type>(constant);
  132. } else if (item->type == IT_CARD) {
  133. std::string type_constant = "CARD_" + type;
  134. int64 constant;
  135. if (!script_get_constant(type_constant.c_str(), &constant) || constant < CARD_NORMAL || constant >= MAX_CARD_TYPE) {
  136. this->invalidWarning(node["SubType"], "Invalid card type %s, defaulting to CARD_NORMAL.\n", type.c_str());
  137. item->subtype = CARD_NORMAL;
  138. }
  139. item->subtype = static_cast<e_card_type>(constant);
  140. } else {
  141. this->invalidWarning(node["SubType"], "Item sub type is not supported for this item type.\n");
  142. return 0;
  143. }
  144. } else {
  145. if (!exists)
  146. item->subtype = 0;
  147. }
  148. if (this->nodeExists(node, "Buy")) {
  149. uint32 buy;
  150. if (!this->asUInt32(node, "Buy", buy))
  151. return 0;
  152. if( buy > MAX_ZENY ){
  153. this->invalidWarning( node["Buy"], "Buying price exceeds MAX_ZENY. Capping...\n" );
  154. buy = MAX_ZENY;
  155. }
  156. item->value_buy = buy;
  157. } else {
  158. if (!exists) {
  159. item->value_buy = 0;
  160. }
  161. }
  162. if (this->nodeExists(node, "Sell")) {
  163. uint32 sell;
  164. if (!this->asUInt32(node, "Sell", sell))
  165. return 0;
  166. if( sell > MAX_ZENY ){
  167. this->invalidWarning( node["Sell"], "Sell price exceeds MAX_ZENY. Capping...\n" );
  168. sell = MAX_ZENY;
  169. }
  170. item->value_sell = sell;
  171. } else {
  172. if (!exists) {
  173. item->value_sell = 0;
  174. }
  175. }
  176. if (this->nodeExists(node, "Weight")) {
  177. uint32 weight;
  178. if (!this->asUInt32(node, "Weight", weight))
  179. return 0;
  180. item->weight = weight;
  181. } else {
  182. if (!exists)
  183. item->weight = 0;
  184. }
  185. if (this->nodeExists(node, "Attack")) {
  186. uint32 atk;
  187. if (!this->asUInt32(node, "Attack", atk))
  188. return 0;
  189. item->atk = atk;
  190. } else {
  191. if (!exists)
  192. item->atk = 0;
  193. }
  194. #ifdef RENEWAL
  195. if (this->nodeExists(node, "MagicAttack")) {
  196. uint32 matk;
  197. if (!this->asUInt32(node, "MagicAttack", matk))
  198. return 0;
  199. item->matk = matk;
  200. } else {
  201. if (!exists)
  202. item->matk = 0;
  203. }
  204. #endif
  205. if (this->nodeExists(node, "Defense")) {
  206. uint32 def;
  207. if (!this->asUInt32(node, "Defense", def))
  208. return 0;
  209. if (def > DEFTYPE_MAX) {
  210. this->invalidWarning(node["Defense"], "Item defense %d exceeds DEFTYPE_MAX (%d), capping to DEFTYPE_MAX.\n", def, DEFTYPE_MAX);
  211. def = DEFTYPE_MAX;
  212. }
  213. item->def = def;
  214. } else {
  215. if (!exists)
  216. item->def = 0;
  217. }
  218. if (this->nodeExists(node, "Range")) {
  219. uint16 range;
  220. if (!this->asUInt16(node, "Range", range))
  221. return 0;
  222. if (range > AREA_SIZE) {
  223. this->invalidWarning(node["Range"], "Item attack range %d exceeds AREA_SIZE (%d), capping to AREA_SIZE.\n", range, AREA_SIZE);
  224. range = AREA_SIZE;
  225. }
  226. item->range = range;
  227. } else {
  228. if (!exists)
  229. item->range = 0;
  230. }
  231. if (this->nodeExists(node, "Slots")) {
  232. uint16 slots;
  233. if (!this->asUInt16(node, "Slots", slots))
  234. return 0;
  235. if (slots > MAX_SLOTS) {
  236. this->invalidWarning(node["Slots"], "Item slots %d exceeds MAX_SLOTS (%d), capping to MAX_SLOTS.\n", slots, MAX_SLOTS);
  237. slots = MAX_SLOTS;
  238. }
  239. item->slots = slots;
  240. } else {
  241. if (!exists)
  242. item->slots = 0;
  243. }
  244. if (this->nodeExists(node, "Jobs")) {
  245. const ryml::NodeRef& jobNode = node["Jobs"];
  246. item->class_base[0] = item->class_base[1] = item->class_base[2] = 0;
  247. if (this->nodeExists(jobNode, "All")) {
  248. bool active;
  249. if (!this->asBool(jobNode, "All", active))
  250. return 0;
  251. itemdb_jobid2mapid(item->class_base, MAPID_ALL, active);
  252. }
  253. for (const auto& jobit : jobNode) {
  254. std::string jobName;
  255. c4::from_chars(jobit.key(), &jobName);
  256. // Skipped because processed above the loop
  257. if (jobName.compare("All") == 0)
  258. continue;
  259. std::string jobName_constant = "EAJ_" + jobName;
  260. int64 constant;
  261. if (!script_get_constant(jobName_constant.c_str(), &constant)) {
  262. this->invalidWarning(jobNode[jobit.key()], "Invalid item job %s, defaulting to All.\n", jobName.c_str());
  263. itemdb_jobid2mapid(item->class_base, MAPID_ALL, true);
  264. break;
  265. }
  266. bool active;
  267. if (!this->asBool(jobNode, jobName, active))
  268. return 0;
  269. itemdb_jobid2mapid(item->class_base, static_cast<e_mapid>(constant), active);
  270. }
  271. } else {
  272. if (!exists) {
  273. item->class_base[0] = item->class_base[1] = item->class_base[2] = 0;
  274. itemdb_jobid2mapid(item->class_base, MAPID_ALL, true);
  275. }
  276. }
  277. if (this->nodeExists(node, "Classes")) {
  278. const auto& classNode = node["Classes"];
  279. if (this->nodeExists(classNode, "All")) {
  280. bool active;
  281. if (!this->asBool(classNode, "All", active))
  282. return 0;
  283. if (active)
  284. item->class_upper |= ITEMJ_ALL;
  285. else
  286. item->class_upper &= ~ITEMJ_ALL;
  287. }
  288. for (const auto& classit : classNode) {
  289. std::string className;
  290. c4::from_chars(classit.key(), &className);
  291. // Skipped because processed above the loop
  292. if (className.compare("All") == 0)
  293. continue;
  294. std::string className_constant = "ITEMJ_" + className;
  295. int64 constant;
  296. if (!script_get_constant(className_constant.c_str(), &constant)) {
  297. this->invalidWarning(classNode[classit.key()], "Invalid class upper %s, defaulting to All.\n", className.c_str());
  298. item->class_upper |= ITEMJ_ALL;
  299. break;
  300. }
  301. bool active;
  302. if (!this->asBool(classNode, className, active))
  303. return 0;
  304. if (active)
  305. item->class_upper |= constant;
  306. else
  307. item->class_upper &= ~constant;
  308. }
  309. } else {
  310. if (!exists)
  311. item->class_upper = ITEMJ_ALL;
  312. }
  313. if (this->nodeExists(node, "Gender")) {
  314. std::string gender;
  315. if (!this->asString(node, "Gender", gender))
  316. return 0;
  317. std::string gender_constant = "SEX_" + gender;
  318. int64 constant;
  319. if (!script_get_constant(gender_constant.c_str(), &constant) || constant < SEX_FEMALE || constant > SEX_BOTH) {
  320. this->invalidWarning(node["Gender"], "Invalid item gender %s, defaulting to SEX_BOTH.\n", gender.c_str());
  321. constant = SEX_BOTH;
  322. }
  323. item->sex = static_cast<e_sex>(constant);
  324. item->sex = this->defaultGender( node, item );
  325. } else {
  326. if (!exists) {
  327. item->sex = SEX_BOTH;
  328. item->sex = this->defaultGender( node, item );
  329. }
  330. }
  331. if (this->nodeExists(node, "Locations")) {
  332. const auto& locationNode = node["Locations"];
  333. for (const auto& locit : locationNode) {
  334. std::string equipName;
  335. c4::from_chars(locit.key(), &equipName);
  336. std::string equipName_constant = "EQP_" + equipName;
  337. int64 constant;
  338. if (!script_get_constant(equipName_constant.c_str(), &constant)) {
  339. this->invalidWarning(locationNode[locit.key()], "Invalid equip location %s, defaulting to IT_ETC.\n", equipName.c_str());
  340. item->type = IT_ETC;
  341. break;
  342. }
  343. bool active;
  344. if (!this->asBool(locationNode, equipName, active))
  345. return 0;
  346. if (active) {
  347. if (constant & EQP_SHADOW_GEAR && item->type != IT_SHADOWGEAR) {
  348. this->invalidWarning(node, "Invalid item equip location %s as it's not a Shadow Gear item type, defaulting to IT_ETC.\n", equipName.c_str());
  349. item->type = IT_ETC;
  350. }
  351. item->equip |= constant;
  352. } else
  353. item->equip &= ~constant;
  354. }
  355. } else {
  356. if (!exists) {
  357. if (itemdb_isequip2(item.get())) {
  358. this->invalidWarning(node, "Invalid item equip location as it has no equip location, defaulting to IT_ETC.\n");
  359. item->type = IT_ETC;
  360. } else
  361. item->equip = 0;
  362. }
  363. }
  364. if (this->nodeExists(node, "WeaponLevel")) {
  365. uint16 lv;
  366. if (!this->asUInt16(node, "WeaponLevel", lv))
  367. return 0;
  368. if (lv > MAX_WEAPON_LEVEL) {
  369. this->invalidWarning(node["WeaponLevel"], "Invalid weapon level %d, defaulting to 0.\n", lv);
  370. lv = 0;
  371. }
  372. if (item->type != IT_WEAPON) {
  373. this->invalidWarning(node["WeaponLevel"], "Item type is not a weapon, defaulting to 0.\n");
  374. lv = 0;
  375. }
  376. item->weapon_level = lv;
  377. } else {
  378. if (!exists)
  379. item->weapon_level = 0;
  380. }
  381. if( this->nodeExists( node, "ArmorLevel" ) ){
  382. uint16 level;
  383. if( !this->asUInt16( node, "ArmorLevel", level ) ){
  384. return 0;
  385. }
  386. if( level > MAX_ARMOR_LEVEL ){
  387. this->invalidWarning( node["ArmorLevel"], "Invalid armor level %d, defaulting to 0.\n", level );
  388. level = 0;
  389. }
  390. if( item->type != IT_ARMOR ){
  391. this->invalidWarning( node["ArmorLevel"], "Item type is not an armor, defaulting to 0.\n" );
  392. level = 0;
  393. }
  394. item->armor_level = level;
  395. }else{
  396. if( !exists ){
  397. item->armor_level = 0;
  398. }
  399. }
  400. if (this->nodeExists(node, "EquipLevelMin")) {
  401. uint16 lv;
  402. if (!this->asUInt16(node, "EquipLevelMin", lv))
  403. return 0;
  404. if (lv > MAX_LEVEL) {
  405. this->invalidWarning(node["EquipLevelMin"], "Minimum equip level %d exceeds MAX_LEVEL (%d), capping to MAX_LEVEL.\n", lv, MAX_LEVEL);
  406. lv = MAX_LEVEL;
  407. }
  408. item->elv = lv;
  409. } else {
  410. if (!exists)
  411. item->elv = 0;
  412. }
  413. if (this->nodeExists(node, "EquipLevelMax")) {
  414. uint16 lv;
  415. if (!this->asUInt16(node, "EquipLevelMax", lv))
  416. return 0;
  417. if (lv < item->elv) {
  418. this->invalidWarning(node["EquipLevelMax"], "Maximum equip level %d is less than minimum equip level %d, capping to minimum equip level.\n", lv, item->elv);
  419. lv = item->elv;
  420. }
  421. if (lv > MAX_LEVEL) {
  422. this->invalidWarning(node["EquipLevelMax"], "Maximum equip level %d exceeds MAX_LEVEL (%d), capping to MAX_LEVEL.\n", lv, MAX_LEVEL);
  423. lv = MAX_LEVEL;
  424. }
  425. item->elvmax = lv;
  426. } else {
  427. if (!exists)
  428. item->elvmax = MAX_LEVEL;
  429. }
  430. if (this->nodeExists(node, "Refineable")) {
  431. bool refine;
  432. if (!this->asBool(node, "Refineable", refine))
  433. return 0;
  434. item->flag.no_refine = !refine;
  435. } else {
  436. if (!exists)
  437. item->flag.no_refine = true;
  438. }
  439. if (this->nodeExists(node, "Gradable")) {
  440. bool gradable;
  441. if (!this->asBool(node, "Gradable", gradable))
  442. return 0;
  443. item->flag.gradable = gradable;
  444. } else {
  445. if (!exists)
  446. item->flag.gradable = false;
  447. }
  448. if (this->nodeExists(node, "View")) {
  449. uint32 look;
  450. if (!this->asUInt32(node, "View", look))
  451. return 0;
  452. item->look = look;
  453. } else {
  454. if (!exists)
  455. item->look = 0;
  456. }
  457. if (this->nodeExists(node, "AliasName")) {
  458. std::string view;
  459. if (!this->asString(node, "AliasName", view))
  460. return 0;
  461. std::shared_ptr<item_data> view_data = item_db.search_aegisname( view.c_str() );
  462. if (view_data == nullptr) {
  463. this->invalidWarning(node["AliasName"], "Unable to change the alias because %s is an unknown item.\n", view.c_str());
  464. return 0;
  465. }
  466. item->view_id = view_data->nameid;
  467. } else {
  468. if (!exists)
  469. item->view_id = 0;
  470. }
  471. if (this->nodeExists(node, "Flags")) {
  472. const auto& flagNode = node["Flags"];
  473. if (this->nodeExists(flagNode, "BuyingStore")) {
  474. bool active;
  475. if (!this->asBool(flagNode, "BuyingStore", active))
  476. return 0;
  477. if (!itemdb_isstackable2(item.get()) && active) {
  478. this->invalidWarning(flagNode["BuyingStore"], "Non-stackable item cannot be enabled for buying store.\n");
  479. active = false;
  480. }
  481. item->flag.buyingstore = active;
  482. } else {
  483. if (!exists)
  484. item->flag.buyingstore = false;
  485. }
  486. if (this->nodeExists(flagNode, "DeadBranch")) {
  487. bool active;
  488. if (!this->asBool(flagNode, "DeadBranch", active))
  489. return 0;
  490. item->flag.dead_branch = active;
  491. } else {
  492. if (!exists)
  493. item->flag.dead_branch = false;
  494. }
  495. if (this->nodeExists(flagNode, "Container")) {
  496. bool active;
  497. if (!this->asBool(flagNode, "Container", active))
  498. return 0;
  499. item->flag.group = active;
  500. } else {
  501. if (!exists)
  502. item->flag.group = false;
  503. }
  504. if (this->nodeExists(flagNode, "UniqueId")) {
  505. bool active;
  506. if (!this->asBool(flagNode, "UniqueId", active))
  507. return 0;
  508. if (!itemdb_isstackable2(item.get()) && active) {
  509. this->invalidWarning(flagNode["UniqueId"], "Non-stackable item cannot be enabled for UniqueId.\n");
  510. active = false;
  511. }
  512. item->flag.guid = active;
  513. } else {
  514. if (!exists)
  515. item->flag.guid = false;
  516. }
  517. if (this->nodeExists(flagNode, "BindOnEquip")) {
  518. bool active;
  519. if (!this->asBool(flagNode, "BindOnEquip", active))
  520. return 0;
  521. item->flag.bindOnEquip = active;
  522. } else {
  523. if (!exists)
  524. item->flag.bindOnEquip = false;
  525. }
  526. if (this->nodeExists(flagNode, "DropAnnounce")) {
  527. bool active;
  528. if (!this->asBool(flagNode, "DropAnnounce", active))
  529. return 0;
  530. item->flag.broadcast = active;
  531. } else {
  532. if (!exists)
  533. item->flag.broadcast = false;
  534. }
  535. if (this->nodeExists(flagNode, "NoConsume")) {
  536. bool active;
  537. if (!this->asBool(flagNode, "NoConsume", active))
  538. return 0;
  539. if (active)
  540. item->flag.delay_consume |= DELAYCONSUME_NOCONSUME;
  541. else
  542. item->flag.delay_consume &= ~DELAYCONSUME_NOCONSUME;
  543. } else {
  544. if (!exists) {
  545. if (!(item->flag.delay_consume & DELAYCONSUME_TEMP))
  546. item->flag.delay_consume = DELAYCONSUME_NONE;
  547. }
  548. }
  549. if (this->nodeExists(flagNode, "DropEffect")) {
  550. std::string effect;
  551. if (!this->asString(flagNode, "DropEffect", effect))
  552. return 0;
  553. std::string effect_constant = "DROPEFFECT_" + effect;
  554. int64 constant;
  555. if (!script_get_constant(effect_constant.c_str(), &constant) || constant < DROPEFFECT_NONE || constant > DROPEFFECT_MAX) {
  556. this->invalidWarning(flagNode["DropEffect"], "Invalid item drop effect %s, defaulting to DROPEFFECT_NONE.\n", effect.c_str());
  557. constant = DROPEFFECT_NONE;
  558. }
  559. item->flag.dropEffect = static_cast<e_item_drop_effect>(constant);
  560. } else {
  561. if (!exists)
  562. item->flag.dropEffect = DROPEFFECT_NONE;
  563. }
  564. } else {
  565. if (!exists) {
  566. item->flag.buyingstore = false;
  567. item->flag.dead_branch = false;
  568. item->flag.group = false;
  569. item->flag.guid = false;
  570. item->flag.bindOnEquip = false;
  571. item->flag.broadcast = false;
  572. if (!(item->flag.delay_consume & DELAYCONSUME_TEMP))
  573. item->flag.delay_consume = DELAYCONSUME_NONE;
  574. item->flag.dropEffect = DROPEFFECT_NONE;
  575. }
  576. }
  577. if (this->nodeExists(node, "Delay")) {
  578. const auto& delayNode = node["Delay"];
  579. if (this->nodeExists(delayNode, "Duration")) {
  580. uint32 duration;
  581. if (!this->asUInt32(delayNode, "Duration", duration))
  582. return 0;
  583. item->delay.duration = duration;
  584. } else {
  585. if (!exists)
  586. item->delay.duration = 0;
  587. }
  588. if (this->nodeExists(delayNode, "Status")) {
  589. std::string status;
  590. if (!this->asString(delayNode, "Status", status))
  591. return 0;
  592. std::string status_constant = "SC_" + status;
  593. int64 constant;
  594. if (!script_get_constant(status_constant.c_str(), &constant) || constant < SC_NONE || constant >= SC_MAX) {
  595. this->invalidWarning(delayNode[c4::to_csubstr(status)], "Invalid item delay status %s, defaulting to SC_NONE.\n", status.c_str());
  596. constant = SC_NONE;
  597. }
  598. item->delay.sc = static_cast<sc_type>(constant);
  599. } else {
  600. if (!exists)
  601. item->delay.sc = SC_NONE;
  602. }
  603. } else {
  604. if (!exists) {
  605. item->delay.duration = 0;
  606. item->delay.sc = SC_NONE;
  607. }
  608. }
  609. if (this->nodeExists(node, "Stack")) {
  610. const auto& stackNode = node["Stack"];
  611. if (this->nodeExists(stackNode, "Amount")) {
  612. uint16 amount;
  613. if (!this->asUInt16(stackNode, "Amount", amount))
  614. return 0;
  615. if (!itemdb_isstackable2(item.get())) {
  616. this->invalidWarning(stackNode["Amount"], "Non-stackable item cannot be enabled for stacking.\n");
  617. amount = 0;
  618. }
  619. item->stack.amount = amount;
  620. } else {
  621. if (!exists)
  622. item->stack.amount = 0;
  623. }
  624. if (this->nodeExists(stackNode, "Inventory")) {
  625. bool active;
  626. if (!this->asBool(stackNode, "Inventory", active))
  627. return 0;
  628. item->stack.inventory = active;
  629. } else {
  630. if (!exists)
  631. item->stack.inventory = false;
  632. }
  633. if (this->nodeExists(stackNode, "Cart")) {
  634. bool active;
  635. if (!this->asBool(stackNode, "Cart", active))
  636. return 0;
  637. item->stack.cart = active;
  638. } else {
  639. if (!exists)
  640. item->stack.cart = false;
  641. }
  642. if (this->nodeExists(stackNode, "Storage")) {
  643. bool active;
  644. if (!this->asBool(stackNode, "Storage", active))
  645. return 0;
  646. item->stack.storage = active;
  647. } else {
  648. if (!exists)
  649. item->stack.storage = false;
  650. }
  651. if (this->nodeExists(stackNode, "GuildStorage")) {
  652. bool active;
  653. if (!this->asBool(stackNode, "GuildStorage", active))
  654. return 0;
  655. item->stack.guild_storage = active;
  656. } else {
  657. if (!exists)
  658. item->stack.guild_storage = false;
  659. }
  660. } else {
  661. if (!exists) {
  662. item->stack.amount = 0;
  663. item->stack.inventory = false;
  664. item->stack.cart = false;
  665. item->stack.storage = false;
  666. item->stack.guild_storage = false;
  667. }
  668. }
  669. if (this->nodeExists(node, "NoUse")) {
  670. const auto& nouseNode = node["NoUse"];
  671. if (this->nodeExists(nouseNode, "Override")) {
  672. uint16 override;
  673. if (!this->asUInt16(nouseNode, "Override", override))
  674. return 0;
  675. if (override > 100) {
  676. this->invalidWarning(nouseNode["Override"], "Item no use override level %d exceeds 100, capping to 100.\n", override);
  677. override = 100;
  678. }
  679. item->item_usage.override = override;
  680. } else {
  681. if (!exists)
  682. item->item_usage.override = 100;
  683. }
  684. if (this->nodeExists(nouseNode, "Sitting")) {
  685. bool active;
  686. if (!this->asBool(nouseNode, "Sitting", active))
  687. return 0;
  688. item->item_usage.sitting = active;
  689. } else {
  690. if (!exists)
  691. item->item_usage.sitting = false;
  692. }
  693. } else {
  694. if (!exists) {
  695. item->item_usage.override = 100;
  696. item->item_usage.sitting = false;
  697. }
  698. }
  699. if (this->nodeExists(node, "Trade")) {
  700. const auto& tradeNode = node["Trade"];
  701. if (this->nodeExists(tradeNode, "Override")) {
  702. uint16 override;
  703. if (!this->asUInt16(tradeNode, "Override", override))
  704. return 0;
  705. if (override > 100) {
  706. this->invalidWarning(tradeNode["Override"], "Item trade override level %d exceeds 100, capping to 100.\n", override);
  707. override = 100;
  708. }
  709. item->gm_lv_trade_override = override;
  710. } else {
  711. if (!exists)
  712. item->gm_lv_trade_override = 100;
  713. }
  714. if (this->nodeExists(tradeNode, "NoDrop")) {
  715. bool active;
  716. if (!this->asBool(tradeNode, "NoDrop", active))
  717. return 0;
  718. item->flag.trade_restriction.drop = active;
  719. } else {
  720. if (!exists)
  721. item->flag.trade_restriction.drop = false;
  722. }
  723. if (this->nodeExists(tradeNode, "NoTrade")) {
  724. bool active;
  725. if (!this->asBool(tradeNode, "NoTrade", active))
  726. return 0;
  727. item->flag.trade_restriction.trade = active;
  728. } else {
  729. if (!exists)
  730. item->flag.trade_restriction.trade = false;
  731. }
  732. if (this->nodeExists(tradeNode, "TradePartner")) {
  733. bool active;
  734. if (!this->asBool(tradeNode, "TradePartner", active))
  735. return 0;
  736. item->flag.trade_restriction.trade_partner = active;
  737. } else {
  738. if (!exists)
  739. item->flag.trade_restriction.trade_partner = false;
  740. }
  741. if (this->nodeExists(tradeNode, "NoSell")) {
  742. bool active;
  743. if (!this->asBool(tradeNode, "NoSell", active))
  744. return 0;
  745. item->flag.trade_restriction.sell = active;
  746. } else {
  747. if (!exists)
  748. item->flag.trade_restriction.sell = false;
  749. }
  750. if (this->nodeExists(tradeNode, "NoCart")) {
  751. bool active;
  752. if (!this->asBool(tradeNode, "NoCart", active))
  753. return 0;
  754. item->flag.trade_restriction.cart = active;
  755. } else {
  756. if (!exists)
  757. item->flag.trade_restriction.cart = false;
  758. }
  759. if (this->nodeExists(tradeNode, "NoStorage")) {
  760. bool active;
  761. if (!this->asBool(tradeNode, "NoStorage", active))
  762. return 0;
  763. item->flag.trade_restriction.storage = active;
  764. } else {
  765. if (!exists)
  766. item->flag.trade_restriction.storage = false;
  767. }
  768. if (this->nodeExists(tradeNode, "NoGuildStorage")) {
  769. bool active;
  770. if (!this->asBool(tradeNode, "NoGuildStorage", active))
  771. return 0;
  772. item->flag.trade_restriction.guild_storage = active;
  773. } else {
  774. if (!exists)
  775. item->flag.trade_restriction.guild_storage = false;
  776. }
  777. if (this->nodeExists(tradeNode, "NoMail")) {
  778. bool active;
  779. if (!this->asBool(tradeNode, "NoMail", active))
  780. return 0;
  781. item->flag.trade_restriction.mail = active;
  782. } else {
  783. if (!exists)
  784. item->flag.trade_restriction.mail = false;
  785. }
  786. if (this->nodeExists(tradeNode, "NoAuction")) {
  787. bool active;
  788. if (!this->asBool(tradeNode, "NoAuction", active))
  789. return 0;
  790. item->flag.trade_restriction.auction = active;
  791. } else {
  792. if (!exists)
  793. item->flag.trade_restriction.auction = false;
  794. }
  795. } else {
  796. if (!exists) {
  797. item->gm_lv_trade_override = 100;
  798. item->flag.trade_restriction.drop = false;
  799. item->flag.trade_restriction.trade = false;
  800. item->flag.trade_restriction.trade_partner = false;
  801. item->flag.trade_restriction.sell = false;
  802. item->flag.trade_restriction.cart = false;
  803. item->flag.trade_restriction.storage = false;
  804. item->flag.trade_restriction.guild_storage = false;
  805. item->flag.trade_restriction.mail = false;
  806. item->flag.trade_restriction.auction = false;
  807. }
  808. }
  809. if (this->nodeExists(node, "Script")) {
  810. std::string script;
  811. if (!this->asString(node, "Script", script))
  812. return 0;
  813. if (exists && item->script) {
  814. script_free_code(item->script);
  815. item->script = nullptr;
  816. }
  817. item->script = parse_script(script.c_str(), this->getCurrentFile().c_str(), this->getLineNumber(node["Script"]), SCRIPT_IGNORE_EXTERNAL_BRACKETS);
  818. } else {
  819. if (!exists)
  820. item->script = nullptr;
  821. }
  822. if (this->nodeExists(node, "EquipScript")) {
  823. std::string script;
  824. if (!this->asString(node, "EquipScript", script))
  825. return 0;
  826. if (exists && item->equip_script) {
  827. script_free_code(item->equip_script);
  828. item->equip_script = nullptr;
  829. }
  830. item->equip_script = parse_script(script.c_str(), this->getCurrentFile().c_str(), this->getLineNumber(node["EquipScript"]), SCRIPT_IGNORE_EXTERNAL_BRACKETS);
  831. } else {
  832. if (!exists)
  833. item->equip_script = nullptr;
  834. }
  835. if (this->nodeExists(node, "UnEquipScript")) {
  836. std::string script;
  837. if (!this->asString(node, "UnEquipScript", script))
  838. return 0;
  839. if (exists && item->unequip_script) {
  840. script_free_code(item->unequip_script);
  841. item->unequip_script = nullptr;
  842. }
  843. item->unequip_script = parse_script(script.c_str(), this->getCurrentFile().c_str(), this->getLineNumber(node["UnEquipScript"]), SCRIPT_IGNORE_EXTERNAL_BRACKETS);
  844. } else {
  845. if (!exists)
  846. item->unequip_script = nullptr;
  847. }
  848. if (!exists)
  849. this->put(nameid, item);
  850. return 1;
  851. }
  852. void ItemDatabase::loadingFinished(){
  853. for (auto &tmp_item : item_db) {
  854. std::shared_ptr<item_data> item = tmp_item.second;
  855. // Items that are consumed only after target confirmation
  856. if (item->type == IT_DELAYCONSUME) {
  857. item->type = IT_USABLE;
  858. item->flag.delay_consume |= DELAYCONSUME_TEMP;
  859. } else {
  860. item->flag.delay_consume &= ~DELAYCONSUME_TEMP; // Remove delayed consumption flag if switching types
  861. }
  862. if( item->type == IT_WEAPON ){
  863. if( item->weapon_level == 0 ){
  864. ShowWarning( "Item %s is a weapon, but does not have a weapon level. Consider adding it. Defaulting to 1.\n", item->name.c_str() );
  865. item->weapon_level = 1;
  866. }
  867. if( item->armor_level != 0 ){
  868. ShowWarning( "Item %s is a weapon, but has an armor level. Defaulting to 0.\n", item->name.c_str() );
  869. item->armor_level = 0;
  870. }
  871. }else if( item->type == IT_ARMOR ){
  872. if( item->armor_level == 0 ){
  873. ShowWarning( "Item %s is an armor, but does not have an armor level. Consider adding it. Defaulting to 1.\n", item->name.c_str() );
  874. item->armor_level = 1;
  875. }
  876. if( item->weapon_level != 0 ){
  877. ShowWarning( "Item %s is an armor, but has a weapon level. Defaulting to 0.\n", item->name.c_str() );
  878. item->weapon_level = 0;
  879. }
  880. }else{
  881. if( item->weapon_level != 0 ){
  882. ShowWarning( "Item %s is not a weapon, but has a weapon level. Defaulting to 0.\n", item->name.c_str() );
  883. item->weapon_level = 0;
  884. }
  885. if( item->armor_level != 0 ){
  886. ShowWarning( "Item %s is not an armor, but has an armor level. Defaulting to 0.\n", item->name.c_str() );
  887. item->armor_level = 0;
  888. }
  889. }
  890. // When a particular price is not given, we should base it off the other one
  891. if (item->value_buy == 0 && item->value_sell > 0)
  892. item->value_buy = item->value_sell * 2;
  893. else if (item->value_buy > 0 && item->value_sell == 0)
  894. item->value_sell = item->value_buy / 2;
  895. if (item->value_buy / 124. < item->value_sell / 75.) {
  896. ShowWarning("Buying/Selling [%d/%d] price of %s (%u) allows Zeny making exploit through buying/selling at discounted/overcharged prices! Defaulting Sell to 1 Zeny.\n", item->value_buy, item->value_sell, item->name.c_str(), item->nameid);
  897. item->value_sell = 1;
  898. }
  899. // Shields need to have a view ID to be able to be recognized by ST_SHIELD check in skill.cpp
  900. if( item->type == IT_ARMOR && ( item->equip & EQP_SHIELD ) != 0 && item->look == 0 ){
  901. ShowWarning( "Item %s (%u) is a shield and should have a view id. Defaulting to Guard...\n", item->name.c_str(), item->nameid );
  902. item->look = 1;
  903. }
  904. }
  905. if( !this->exists( ITEMID_DUMMY ) ){
  906. // Create dummy item
  907. std::shared_ptr<item_data> dummy_item = std::make_shared<item_data>();
  908. dummy_item->nameid = ITEMID_DUMMY;
  909. dummy_item->weight = 1;
  910. dummy_item->value_sell = 1;
  911. dummy_item->type = IT_ETC;
  912. dummy_item->name = "UNKNOWN_ITEM";
  913. dummy_item->ename = "Unknown Item";
  914. dummy_item->view_id = UNKNOWN_ITEM_ID;
  915. item_db.put( ITEMID_DUMMY, dummy_item );
  916. }
  917. TypesafeCachedYamlDatabase::loadingFinished();
  918. }
  919. /**
  920. * Applies gender restrictions according to settings.
  921. * @param node: YAML node containing the entry.
  922. * @param node: the already parsed item data.
  923. * @return gender that should be used.
  924. */
  925. e_sex ItemDatabase::defaultGender( const ryml::NodeRef& node, std::shared_ptr<item_data> id ){
  926. if (id->nameid == WEDDING_RING_M) //Grom Ring
  927. return SEX_MALE;
  928. if (id->nameid == WEDDING_RING_F) //Bride Ring
  929. return SEX_FEMALE;
  930. if( id->type == IT_WEAPON ){
  931. if( id->subtype == W_MUSICAL ){
  932. if( id->sex != SEX_MALE ){
  933. this->invalidWarning( node, "Musical instruments are always male-only, defaulting to SEX_MALE.\n" );
  934. }
  935. return SEX_MALE;
  936. }
  937. if( id->subtype == W_WHIP ){
  938. if( id->sex != SEX_FEMALE ){
  939. this->invalidWarning( node, "Whips are always female-only, defaulting to SEX_FEMALE.\n" );
  940. }
  941. return SEX_FEMALE;
  942. }
  943. }
  944. return static_cast<e_sex>( id->sex );
  945. }
  946. std::shared_ptr<item_data> ItemDatabase::search_aegisname( const char* name ){
  947. // Create a copy
  948. std::string lowername = name;
  949. // Convert it to lower
  950. util::tolower( lowername );
  951. return util::umap_find( this->aegisNameToItemDataMap, lowername );
  952. }
  953. std::shared_ptr<item_data> ItemDatabase::searchname( const char *name ){
  954. // Create a copy
  955. std::string lowername = name;
  956. // Convert it to lower
  957. util::tolower( lowername );
  958. std::shared_ptr<item_data> result = util::umap_find( this->aegisNameToItemDataMap, lowername );
  959. if( result != nullptr ){
  960. return result;
  961. }
  962. return util::umap_find( this->nameToItemDataMap, lowername );
  963. }
  964. ItemDatabase item_db;
  965. /**
  966. * Check if an item exists in a group
  967. * @param group_id: Item Group ID
  968. * @param nameid: Item to check for in group
  969. * @return True if item is in group, else false
  970. */
  971. bool ItemGroupDatabase::item_exists(uint16 group_id, t_itemid nameid)
  972. {
  973. std::shared_ptr<s_item_group_db> group = this->find(group_id);
  974. if (group == nullptr)
  975. return false;
  976. for (const auto &random : group->random) {
  977. for (const auto &it : random.second->data) {
  978. if (it.second->nameid == nameid)
  979. return true;
  980. }
  981. }
  982. return false;
  983. }
  984. /**
  985. * Check if an item exists from a group in a player's inventory
  986. * @param group_id: Item Group ID
  987. * @return Item's index if found or -1 otherwise
  988. */
  989. int16 ItemGroupDatabase::item_exists_pc(map_session_data *sd, uint16 group_id)
  990. {
  991. std::shared_ptr<s_item_group_db> group = this->find(group_id);
  992. if (group == nullptr || group->random.empty())
  993. return -1;
  994. for (const auto &random : group->random) {
  995. for (const auto &it : random.second->data) {
  996. int16 item_position = pc_search_inventory(sd, it.second->nameid);
  997. if (item_position != -1)
  998. return item_position;
  999. }
  1000. }
  1001. return -1;
  1002. }
  1003. const std::string LaphineSynthesisDatabase::getDefaultLocation(){
  1004. return std::string( db_path ) + "/laphine_synthesis.yml";
  1005. }
  1006. uint64 LaphineSynthesisDatabase::parseBodyNode( const ryml::NodeRef& node ){
  1007. t_itemid item_id;
  1008. {
  1009. std::string name;
  1010. if( !this->asString( node, "Item", name ) ){
  1011. return 0;
  1012. }
  1013. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  1014. if( id == nullptr ){
  1015. this->invalidWarning( node["Item"], "Unknown item \"%s\".\n", name.c_str() );
  1016. return 0;
  1017. }
  1018. item_id = id->nameid;
  1019. }
  1020. std::shared_ptr<s_laphine_synthesis> entry = this->find( item_id );
  1021. bool exists = entry != nullptr;
  1022. if( !exists ){
  1023. if( !this->nodesExist( node, { "RewardGroup", "Requirements" } ) ){
  1024. return 0;
  1025. }
  1026. entry = std::make_shared<s_laphine_synthesis>();
  1027. entry->item_id = item_id;
  1028. }
  1029. if( this->nodeExists( node, "RewardGroup" ) ){
  1030. std::string name;
  1031. if( !this->asString( node, "RewardGroup", name ) ){
  1032. return 0;
  1033. }
  1034. int64 constant;
  1035. if( !script_get_constant( ( "IG_" + name ).c_str(), &constant ) ){
  1036. this->invalidWarning( node["RewardGroup"], "Unknown reward group \"%s\".\n", name.c_str() );
  1037. return 0;
  1038. }
  1039. if( !itemdb_group.exists( (uint16)constant ) ){
  1040. this->invalidWarning( node["RewardGroup"], "Unknown reward group ID \"%" PRId64 "\".\n", constant );
  1041. return 0;
  1042. }
  1043. entry->rewardGroupId = (uint16)constant;
  1044. }else{
  1045. if( !exists ){
  1046. entry->rewardGroupId = 0;
  1047. }
  1048. }
  1049. if( this->nodeExists( node, "RequiredRequirementsCount" ) ){
  1050. uint16 amount;
  1051. if( !this->asUInt16( node, "RequiredRequirementsCount", amount ) ){
  1052. return 0;
  1053. }
  1054. entry->requiredRequirements = amount;
  1055. }else{
  1056. if( !exists ){
  1057. entry->requiredRequirements = 1;
  1058. }
  1059. }
  1060. if( this->nodeExists( node, "Requirements" ) ){
  1061. for( const ryml::NodeRef& requirementNode : node["Requirements"] ){
  1062. std::string name;
  1063. if( !this->asString( requirementNode, "Item", name ) ){
  1064. return 0;
  1065. }
  1066. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  1067. if( id == nullptr ){
  1068. this->invalidWarning( requirementNode["Item"], "Unknown item \"%s\".\n", name.c_str() );
  1069. return 0;
  1070. }
  1071. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( entry->requirements, id->nameid );
  1072. bool requirement_exists = requirement != nullptr;
  1073. if( !requirement_exists ){
  1074. requirement = std::make_shared<s_laphine_synthesis_requirement>();
  1075. requirement->item_id = id->nameid;
  1076. }
  1077. if( this->nodeExists( requirementNode, "Amount" ) ){
  1078. uint16 amount;
  1079. if( !this->asUInt16( requirementNode, "Amount", amount ) ){
  1080. return 0;
  1081. }
  1082. if( amount > MAX_AMOUNT ){
  1083. this->invalidWarning( requirementNode["Amount"], "Amount %hu is too high, capping to MAX_AMOUNT...\n", amount );
  1084. amount = MAX_AMOUNT;
  1085. }
  1086. requirement->amount = amount;
  1087. }else{
  1088. if( !requirement_exists ){
  1089. requirement->amount = 1;
  1090. }
  1091. }
  1092. if( !requirement_exists ){
  1093. entry->requirements[id->nameid] = requirement;
  1094. }
  1095. }
  1096. }
  1097. if( this->nodeExists( node, "MinimumRefine" ) ){
  1098. uint16 refine;
  1099. if( !this->asUInt16( node, "MinimumRefine", refine ) ){
  1100. return 0;
  1101. }
  1102. if( refine > MAX_REFINE ){
  1103. this->invalidWarning( node["MinimumRefine"], "Minimum refine %hu is too high, capping to MAX_REFINE...\n", refine );
  1104. refine = MAX_REFINE;
  1105. }
  1106. entry->minimumRefine = refine;
  1107. }else{
  1108. if( !exists ){
  1109. entry->minimumRefine = 0;
  1110. }
  1111. }
  1112. if( this->nodeExists( node, "MaximumRefine" ) ){
  1113. uint16 refine;
  1114. if( !this->asUInt16( node, "MaximumRefine", refine ) ){
  1115. return 0;
  1116. }
  1117. if( refine > MAX_REFINE ){
  1118. this->invalidWarning( node["MaximumRefine"], "Maximum refine %hu is too high, capping to MAX_REFINE...\n", refine );
  1119. refine = MAX_REFINE;
  1120. }
  1121. entry->maximumRefine = refine;
  1122. }else{
  1123. if( !exists ){
  1124. entry->maximumRefine = MAX_REFINE;
  1125. }
  1126. }
  1127. if( !exists ){
  1128. this->put( entry->item_id, entry );
  1129. }
  1130. return 1;
  1131. }
  1132. LaphineSynthesisDatabase laphine_synthesis_db;
  1133. const std::string LaphineUpgradeDatabase::getDefaultLocation(){
  1134. return std::string( db_path ) + "/laphine_upgrade.yml";
  1135. }
  1136. uint64 LaphineUpgradeDatabase::parseBodyNode( const ryml::NodeRef& node ){
  1137. t_itemid item_id;
  1138. {
  1139. std::string name;
  1140. if( !this->asString( node, "Item", name ) ){
  1141. return 0;
  1142. }
  1143. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  1144. if( id == nullptr ){
  1145. this->invalidWarning( node["Item"], "Unknown item \"%s\".\n", name.c_str() );
  1146. return 0;
  1147. }
  1148. item_id = id->nameid;
  1149. }
  1150. std::shared_ptr<s_laphine_upgrade> entry = this->find( item_id );
  1151. bool exists = entry != nullptr;
  1152. if( !exists ){
  1153. if( !this->nodesExist( node, { "TargetItems" } ) ){
  1154. return 0;
  1155. }
  1156. entry = std::make_shared<s_laphine_upgrade>();
  1157. entry->item_id = item_id;
  1158. }
  1159. if( this->nodeExists( node, "RandomOptionGroup" ) ){
  1160. std::string name;
  1161. if( !this->asString( node, "RandomOptionGroup", name ) ){
  1162. return 0;
  1163. }
  1164. uint16 id;
  1165. if( !random_option_group.option_get_id( name, id ) ){
  1166. this->invalidWarning( node["RandomOptionGroup"], "Unknown random option group \"%s\".\n", name.c_str() );
  1167. return 0;
  1168. }
  1169. entry->randomOptionGroup = random_option_group.find( id );
  1170. }else{
  1171. if( !exists ){
  1172. entry->randomOptionGroup = nullptr;
  1173. }
  1174. }
  1175. if( this->nodeExists( node, "TargetItems" ) ){
  1176. for( const ryml::NodeRef& targetNode : node["TargetItems"] ){
  1177. std::string name;
  1178. if( !this->asString( targetNode, "Item", name ) ){
  1179. return 0;
  1180. }
  1181. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  1182. if( id == nullptr ){
  1183. this->invalidWarning( targetNode["Item"], "Unknown item \"%s\".\n", name.c_str() );
  1184. return 0;
  1185. }
  1186. if( !util::vector_exists( entry->target_item_ids, id->nameid ) ){
  1187. entry->target_item_ids.push_back( id->nameid );
  1188. }
  1189. }
  1190. }
  1191. if( this->nodeExists( node, "MinimumRefine" ) ){
  1192. uint16 refine;
  1193. if( !this->asUInt16( node, "MinimumRefine", refine ) ){
  1194. return 0;
  1195. }
  1196. if( refine > MAX_REFINE ){
  1197. this->invalidWarning( node["MinimumRefine"], "Minimum refine %hu is too high, capping to MAX_REFINE...\n", refine );
  1198. refine = MAX_REFINE;
  1199. }
  1200. entry->minimumRefine = refine;
  1201. }else{
  1202. if( !exists ){
  1203. entry->minimumRefine = 0;
  1204. }
  1205. }
  1206. if( this->nodeExists( node, "MaximumRefine" ) ){
  1207. uint16 refine;
  1208. if( !this->asUInt16( node, "MaximumRefine", refine ) ){
  1209. return 0;
  1210. }
  1211. if( refine > MAX_REFINE ){
  1212. this->invalidWarning( node["MaximumRefine"], "Maximum refine %hu is too high, capping to MAX_REFINE...\n", refine );
  1213. refine = MAX_REFINE;
  1214. }
  1215. entry->maximumRefine = refine;
  1216. }else{
  1217. if( !exists ){
  1218. entry->maximumRefine = MAX_REFINE;
  1219. }
  1220. }
  1221. if( this->nodeExists( node, "RequiredRandomOptions" ) ){
  1222. uint16 amount;
  1223. if( !this->asUInt16( node, "RequiredRandomOptions", amount ) ){
  1224. return 0;
  1225. }
  1226. if( amount > MAX_ITEM_RDM_OPT ){
  1227. this->invalidWarning( node["RequiredRandomOptions"], "Required random option amount %hu is too high, capping to MAX_ITEM_RDM_OPT...\n", amount );
  1228. amount = MAX_ITEM_RDM_OPT;
  1229. }
  1230. entry->requiredRandomOptions = amount;
  1231. }else{
  1232. if( !exists ){
  1233. entry->requiredRandomOptions = 0;
  1234. }
  1235. }
  1236. if( this->nodeExists( node, "CardsAllowed" ) ){
  1237. bool allowed;
  1238. if( !this->asBool( node, "CardsAllowed", allowed ) ){
  1239. return 0;
  1240. }
  1241. entry->cardsAllowed = allowed;
  1242. }else{
  1243. if( !exists ){
  1244. entry->cardsAllowed = false;
  1245. }
  1246. }
  1247. if( this->nodeExists( node, "ResultRefine" ) ){
  1248. uint16 refine;
  1249. if( !this->asUInt16( node, "ResultRefine", refine ) ){
  1250. return 0;
  1251. }
  1252. if( refine > MAX_REFINE ){
  1253. this->invalidWarning( node["ResultRefine"], "Result refine %hu is too high, capping to MAX_REFINE...\n", refine );
  1254. refine = MAX_REFINE;
  1255. }
  1256. entry->resultRefine = refine;
  1257. }else{
  1258. if( !exists ){
  1259. entry->resultRefine = 0;
  1260. }
  1261. }
  1262. if( this->nodeExists( node, "ResultRefineMinimum" ) ){
  1263. uint16 refine;
  1264. if( !this->asUInt16( node, "ResultRefineMinimum", refine ) ){
  1265. return 0;
  1266. }
  1267. if( refine > MAX_REFINE ){
  1268. this->invalidWarning( node["ResultRefineMinimum"], "Result refine minimum %hu is too high, capping to MAX_REFINE...\n", refine );
  1269. refine = MAX_REFINE;
  1270. }
  1271. entry->resultRefineMinimum = refine;
  1272. }else{
  1273. if( !exists ){
  1274. entry->resultRefineMinimum = 0;
  1275. }
  1276. }
  1277. if( this->nodeExists( node, "ResultRefineMaximum" ) ){
  1278. uint16 refine;
  1279. if( !this->asUInt16( node, "ResultRefineMaximum", refine ) ){
  1280. return 0;
  1281. }
  1282. if( refine > MAX_REFINE ){
  1283. this->invalidWarning( node["ResultRefineMaximum"], "Result refine maximum %hu is too high, capping to MAX_REFINE...\n", refine );
  1284. refine = MAX_REFINE;
  1285. }
  1286. entry->resultRefineMaximum = refine;
  1287. }else{
  1288. if( !exists ){
  1289. entry->resultRefineMaximum = 0;
  1290. }
  1291. }
  1292. if( !exists ){
  1293. this->put( entry->item_id, entry );
  1294. }
  1295. return 1;
  1296. }
  1297. LaphineUpgradeDatabase laphine_upgrade_db;
  1298. const std::string ItemReformDatabase::getDefaultLocation(){
  1299. return std::string( db_path ) + "/item_reform.yml";
  1300. }
  1301. uint64 ItemReformDatabase::parseBodyNode( const ryml::NodeRef& node ){
  1302. t_itemid item_id;
  1303. {
  1304. std::string name;
  1305. if( !this->asString( node, "Item", name ) ){
  1306. return 0;
  1307. }
  1308. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  1309. if( id == nullptr ){
  1310. this->invalidWarning( node["Item"], "Unknown item \"%s\".\n", name.c_str() );
  1311. return 0;
  1312. }
  1313. item_id = id->nameid;
  1314. }
  1315. std::shared_ptr<s_item_reform> entry = this->find( item_id );
  1316. bool exists = entry != nullptr;
  1317. if( !exists ){
  1318. if( !this->nodesExist( node, { "BaseItems" } ) ){
  1319. return 0;
  1320. }
  1321. entry = std::make_shared<s_item_reform>();
  1322. entry->item_id = item_id;
  1323. }
  1324. if( this->nodeExists( node, "BaseItems" ) ){
  1325. for( const ryml::NodeRef& baseNode : node["BaseItems"] ){
  1326. t_itemid base_itemid;
  1327. {
  1328. std::string name;
  1329. if( !this->asString( baseNode, "BaseItem", name ) ){
  1330. return 0;
  1331. }
  1332. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  1333. if( id == nullptr ){
  1334. this->invalidWarning( baseNode["BaseItem"], "Unknown item \"%s\".\n", name.c_str() );
  1335. return 0;
  1336. }
  1337. base_itemid = id->nameid;
  1338. }
  1339. std::shared_ptr<s_item_reform_base> base = util::umap_find( entry->base_items, base_itemid );
  1340. bool base_exists = base != nullptr;
  1341. if( !base_exists ){
  1342. if( !this->nodesExist( baseNode, { "ResultItem" } ) ){
  1343. return 0;
  1344. }
  1345. base = std::make_shared<s_item_reform_base>();
  1346. base->item_id = base_itemid;
  1347. }
  1348. if( this->nodeExists( baseNode, "MinimumRefine" ) ){
  1349. uint16 refine;
  1350. if( !this->asUInt16( baseNode, "MinimumRefine", refine ) ){
  1351. return 0;
  1352. }
  1353. if( refine > MAX_REFINE ){
  1354. this->invalidWarning( baseNode["MinimumRefine"], "Minimum refine %hu is too high, capping to MAX_REFINE...\n", refine );
  1355. refine = MAX_REFINE;
  1356. }
  1357. base->minimumRefine = refine;
  1358. }else{
  1359. if( !base_exists ){
  1360. base->minimumRefine = 0;
  1361. }
  1362. }
  1363. if( this->nodeExists( baseNode, "MaximumRefine" ) ){
  1364. uint16 refine;
  1365. if( !this->asUInt16( baseNode, "MaximumRefine", refine ) ){
  1366. return 0;
  1367. }
  1368. if( refine > MAX_REFINE ){
  1369. this->invalidWarning( baseNode["MaximumRefine"], "Maximum refine %hu is too high, capping to MAX_REFINE...\n", refine );
  1370. refine = MAX_REFINE;
  1371. }
  1372. base->maximumRefine = refine;
  1373. }else{
  1374. if( !base_exists ){
  1375. base->maximumRefine = MAX_REFINE;
  1376. }
  1377. }
  1378. if( this->nodeExists( baseNode, "RequiredRandomOptions" ) ){
  1379. uint16 amount;
  1380. if( !this->asUInt16( baseNode, "RequiredRandomOptions", amount ) ){
  1381. return 0;
  1382. }
  1383. if( amount > MAX_ITEM_RDM_OPT ){
  1384. this->invalidWarning( baseNode["RequiredRandomOptions"], "Required random option amount %hu is too high, capping to MAX_ITEM_RDM_OPT...\n", amount );
  1385. amount = MAX_ITEM_RDM_OPT;
  1386. }
  1387. base->requiredRandomOptions = amount;
  1388. }else{
  1389. if( !base_exists ){
  1390. base->requiredRandomOptions = 0;
  1391. }
  1392. }
  1393. if( this->nodeExists( baseNode, "CardsAllowed" ) ){
  1394. bool allowed;
  1395. if( !this->asBool( baseNode, "CardsAllowed", allowed ) ){
  1396. return 0;
  1397. }
  1398. base->cardsAllowed = allowed;
  1399. }else{
  1400. if( !base_exists ){
  1401. base->cardsAllowed = true;
  1402. }
  1403. }
  1404. if( this->nodeExists( baseNode, "Materials" ) ){
  1405. for( const ryml::NodeRef& materialNode : baseNode["Materials"] ){
  1406. std::string name;
  1407. if( !this->asString( materialNode, "Material", name ) ){
  1408. return 0;
  1409. }
  1410. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  1411. if( id == nullptr ){
  1412. this->invalidWarning( materialNode["Material"], "Unknown item \"%s\".\n", name.c_str() );
  1413. return 0;
  1414. }
  1415. t_itemid material_id = id->nameid;
  1416. bool material_exists = util::umap_find( base->materials, material_id ) != nullptr;
  1417. uint16 amount;
  1418. if( this->nodeExists( materialNode, "Amount" ) ){
  1419. if( !this->asUInt16( materialNode, "Amount", amount ) ){
  1420. return 0;
  1421. }
  1422. if( amount > MAX_AMOUNT ){
  1423. this->invalidWarning( materialNode["Amount"], "Amount %hu is too high, capping to MAX_AMOUNT...\n", amount );
  1424. amount = MAX_AMOUNT;
  1425. }
  1426. }else{
  1427. if( !material_exists ){
  1428. amount = 1;
  1429. }
  1430. }
  1431. if( amount > 0 ){
  1432. base->materials[material_id] = amount;
  1433. }else{
  1434. base->materials.erase( material_id );
  1435. }
  1436. }
  1437. }
  1438. if( this->nodeExists( baseNode, "ResultItem" ) ){
  1439. std::string name;
  1440. if( !this->asString( baseNode, "ResultItem", name ) ){
  1441. return 0;
  1442. }
  1443. std::shared_ptr<item_data> id = item_db.search_aegisname( name.c_str() );
  1444. if( id == nullptr ){
  1445. this->invalidWarning( baseNode["ResultItem"], "Unknown item \"%s\".\n", name.c_str() );
  1446. return 0;
  1447. }
  1448. base->resultItemId = id->nameid;
  1449. }
  1450. if( this->nodeExists( baseNode, "ChangeRefine" ) ){
  1451. int16 refine;
  1452. if( !this->asInt16( baseNode, "ChangeRefine", refine ) ){
  1453. return 0;
  1454. }
  1455. if( refine > MAX_REFINE ){
  1456. this->invalidWarning( baseNode["MaximumRefine"], "Refine change %hu is too high, capping to MAX_REFINE...\n", refine );
  1457. refine = MAX_REFINE;
  1458. }else if( refine < -MAX_REFINE ){
  1459. this->invalidWarning( baseNode["MaximumRefine"], "Refine change %hu is too low, capping to -MAX_REFINE...\n", refine );
  1460. refine = -MAX_REFINE;
  1461. }
  1462. base->refineChange = refine;
  1463. }else{
  1464. if( !base_exists ){
  1465. base->refineChange = 0;
  1466. }
  1467. }
  1468. if( this->nodeExists( baseNode, "RandomOptionGroup" ) ){
  1469. std::string name;
  1470. if( !this->asString( baseNode, "RandomOptionGroup", name ) ){
  1471. return 0;
  1472. }
  1473. uint16 id;
  1474. if( !random_option_group.option_get_id( name, id ) ){
  1475. this->invalidWarning( baseNode["RandomOptionGroup"], "Unknown random option group \"%s\".\n", name.c_str() );
  1476. return 0;
  1477. }
  1478. base->randomOptionGroup = random_option_group.find( id );
  1479. }else{
  1480. if( !base_exists ){
  1481. base->randomOptionGroup = nullptr;
  1482. }
  1483. }
  1484. if( this->nodeExists( baseNode, "ClearSlots" ) ){
  1485. bool clear;
  1486. if( !this->asBool( baseNode, "ClearSlots", clear ) ){
  1487. return 0;
  1488. }
  1489. base->clearSlots = clear;
  1490. }else{
  1491. if( !base_exists ){
  1492. base->clearSlots = false;
  1493. }
  1494. }
  1495. if( this->nodeExists( baseNode, "RemoveEnchantgrade" ) ){
  1496. bool clear;
  1497. if( !this->asBool( baseNode, "RemoveEnchantgrade", clear ) ){
  1498. return 0;
  1499. }
  1500. base->removeEnchantgrade = clear;
  1501. }else{
  1502. if( !base_exists ){
  1503. base->removeEnchantgrade = false;
  1504. }
  1505. }
  1506. if( !base_exists ){
  1507. entry->base_items[base_itemid] = base;
  1508. }
  1509. }
  1510. }
  1511. if( !exists ){
  1512. this->put( entry->item_id, entry );
  1513. }
  1514. return 1;
  1515. }
  1516. ItemReformDatabase item_reform_db;
  1517. /*==========================================
  1518. * Finds up to N matches. Returns number of matches [Skotlex]
  1519. * @param *data
  1520. * @param size
  1521. * @param str
  1522. * @return Number of matches item
  1523. *------------------------------------------*/
  1524. uint16 itemdb_searchname_array(std::map<t_itemid, std::shared_ptr<item_data>> &data, uint16 size, const char *str)
  1525. {
  1526. for (const auto &item : item_db) {
  1527. std::shared_ptr<item_data> id = item.second;
  1528. if (id == nullptr)
  1529. continue;
  1530. if (stristr(id->name.c_str(), str) != nullptr || stristr(id->ename.c_str(), str) != nullptr || strcmpi(id->ename.c_str(), str) == 0)
  1531. data[id->nameid] = id;
  1532. }
  1533. if (data.size() > size)
  1534. util::map_resize(data, size);
  1535. return static_cast<uint16>(data.size());
  1536. }
  1537. std::shared_ptr<s_item_group_entry> get_random_itemsubgroup(std::shared_ptr<s_item_group_random> random) {
  1538. if (random == nullptr)
  1539. return nullptr;
  1540. for (size_t j = 0, max = random->data.size() * 3; j < max; j++) {
  1541. std::shared_ptr<s_item_group_entry> entry = util::umap_random(random->data);
  1542. if (entry->rate == 0 || rnd() % random->total_rate < entry->rate) // always return entry for rate 0 ('must' item)
  1543. return entry;
  1544. }
  1545. return util::umap_random(random->data);
  1546. }
  1547. /**
  1548. * Return a random group entry from Item Group
  1549. * @param group_id
  1550. * @param sub_group: 0 is 'must' item group, random groups start from 1
  1551. * @return Item group entry or NULL on fail
  1552. */
  1553. std::shared_ptr<s_item_group_entry> ItemGroupDatabase::get_random_entry(uint16 group_id, uint8 sub_group) {
  1554. std::shared_ptr<s_item_group_db> group = this->find(group_id);
  1555. if (group == nullptr) {
  1556. ShowError("get_random_entry: Invalid group id %hu.\n", group_id);
  1557. return nullptr;
  1558. }
  1559. if (group->random.empty()) {
  1560. ShowError("get_random_entry: No item entries for group id %hu.\n", group_id);
  1561. return nullptr;
  1562. }
  1563. if (group->random.count(sub_group) == 0) {
  1564. ShowError("get_random_entry: No item entries for group id %hu and sub group %hu.\n", group_id, sub_group);
  1565. return nullptr;
  1566. }
  1567. return get_random_itemsubgroup(group->random[sub_group]);
  1568. }
  1569. /**
  1570. * Return a random Item ID from Item Group
  1571. * @param group_id
  1572. * @param sub_group: 0 is 'must' item group, random groups start from 1
  1573. * @return Item ID or UNKNOWN_ITEM_ID on fail
  1574. */
  1575. t_itemid ItemGroupDatabase::get_random_item_id(uint16 group_id, uint8 sub_group) {
  1576. std::shared_ptr<s_item_group_entry> entry = this->get_random_entry(group_id, sub_group);
  1577. return entry != nullptr ? entry->nameid : UNKNOWN_ITEM_ID;
  1578. }
  1579. /** [Cydh]
  1580. * Gives item(s) to the player based on item group
  1581. * @param sd: Player that obtains item from item group
  1582. * @param group_id: The group ID of item that obtained by player
  1583. * @param *group: struct s_item_group from itemgroup_db[group_id].random[idx] or itemgroup_db[group_id].must[sub_group][idx]
  1584. */
  1585. static void itemdb_pc_get_itemgroup_sub(map_session_data *sd, bool identify, std::shared_ptr<s_item_group_entry> data) {
  1586. if (data == nullptr)
  1587. return;
  1588. item tmp = {};
  1589. tmp.nameid = data->nameid;
  1590. tmp.bound = data->bound;
  1591. tmp.identify = identify ? identify : itemdb_isidentified(data->nameid);
  1592. tmp.expire_time = (data->duration) ? (unsigned int)(time(NULL) + data->duration*60) : 0;
  1593. if (data->isNamed) {
  1594. tmp.card[0] = itemdb_isequip(data->nameid) ? CARD0_FORGE : CARD0_CREATE;
  1595. tmp.card[1] = 0;
  1596. tmp.card[2] = GetWord(sd->status.char_id, 0);
  1597. tmp.card[3] = GetWord(sd->status.char_id, 1);
  1598. }
  1599. uint16 get_amt = 0;
  1600. if (itemdb_isstackable(data->nameid) && data->isStacked)
  1601. get_amt = data->amount;
  1602. else
  1603. get_amt = 1;
  1604. tmp.amount = get_amt;
  1605. // Do loop for non-stackable item
  1606. for (uint16 i = 0; i < data->amount; i += get_amt) {
  1607. char flag = 0;
  1608. tmp.unique_id = data->GUID ? pc_generate_unique_id(sd) : 0; // Generate GUID
  1609. if( itemdb_isequip( data->nameid ) ){
  1610. if( data->refineMinimum > 0 && data->refineMaximum > 0 ){
  1611. tmp.refine = rnd_value( data->refineMinimum, data->refineMaximum );
  1612. }else if( data->refineMinimum > 0 ){
  1613. tmp.refine = rnd_value( data->refineMinimum, MAX_REFINE );
  1614. }else if( data->refineMaximum > 0 ){
  1615. tmp.refine = rnd_value( 1, data->refineMaximum );
  1616. }else{
  1617. tmp.refine = 0;
  1618. }
  1619. if( data->randomOptionGroup != nullptr ){
  1620. memset( tmp.option, 0, sizeof( tmp.option ) );
  1621. data->randomOptionGroup->apply( tmp );
  1622. }
  1623. }
  1624. if ((flag = pc_additem(sd, &tmp, get_amt, LOG_TYPE_SCRIPT))) {
  1625. clif_additem(sd, 0, 0, flag);
  1626. if (pc_candrop(sd, &tmp))
  1627. map_addflooritem(&tmp, tmp.amount, sd->bl.m, sd->bl.x,sd->bl.y, 0, 0, 0, 0, 0);
  1628. }
  1629. else if (!flag && data->isAnnounced)
  1630. intif_broadcast_obtain_special_item(sd, data->nameid, sd->itemid, ITEMOBTAIN_TYPE_BOXITEM);
  1631. }
  1632. }
  1633. /** [Cydh]
  1634. * Find item(s) that will be obtained by player based on Item Group
  1635. * @param group_id: The group ID that will be gained by player
  1636. * @param nameid: The item that trigger this item group
  1637. * @return val: 0:success, 1:no sd, 2:invalid item group
  1638. */
  1639. uint8 ItemGroupDatabase::pc_get_itemgroup(uint16 group_id, bool identify, map_session_data *sd) {
  1640. nullpo_retr(1,sd);
  1641. std::shared_ptr<s_item_group_db> group = this->find(group_id);
  1642. if (group == nullptr) {
  1643. ShowError("pc_get_itemgroup: Invalid group id '%d' specified.\n",group_id);
  1644. return 2;
  1645. }
  1646. if (group->random.empty())
  1647. return 0;
  1648. // Get all the 'must' item(s) (subgroup 0)
  1649. uint16 subgroup = 0;
  1650. std::shared_ptr<s_item_group_random> random = util::umap_find(group->random, subgroup);
  1651. if (random != nullptr && !random->data.empty()) {
  1652. for (const auto &it : random->data)
  1653. itemdb_pc_get_itemgroup_sub(sd, identify, it.second);
  1654. }
  1655. // Get 1 'random' item from each subgroup
  1656. for (const auto &random : group->random) {
  1657. if (random.first == 0 || random.second->data.empty())
  1658. continue;
  1659. itemdb_pc_get_itemgroup_sub(sd, identify, get_random_itemsubgroup(random.second));
  1660. }
  1661. return 0;
  1662. }
  1663. /** Searches for the item_data. Use this to check if item exists or not.
  1664. * @param nameid
  1665. * @return *item_data if item is exist, or NULL if not
  1666. */
  1667. std::shared_ptr<item_data> itemdb_exists(t_itemid nameid) {
  1668. return item_db.find(nameid);
  1669. }
  1670. /// Returns name type of ammunition [Cydh]
  1671. const char *itemdb_typename_ammo (e_ammo_type ammo) {
  1672. switch (ammo) {
  1673. case AMMO_ARROW: return "Arrow";
  1674. case AMMO_DAGGER: return "Throwable Dagger";
  1675. case AMMO_BULLET: return "Bullet";
  1676. case AMMO_SHELL: return "Shell";
  1677. case AMMO_GRENADE: return "Grenade";
  1678. case AMMO_SHURIKEN: return "Shuriken";
  1679. case AMMO_KUNAI: return "Kunai";
  1680. case AMMO_CANNONBALL: return "Cannonball";
  1681. case AMMO_THROWWEAPON: return "Throwable Item/Sling Item";
  1682. }
  1683. return "Ammunition";
  1684. }
  1685. /// Returns human readable name for given item type.
  1686. /// @param type Type id to retrieve name for ( IT_* ).
  1687. const char* itemdb_typename(enum item_types type)
  1688. {
  1689. switch(type)
  1690. {
  1691. case IT_HEALING: return "Potion/Food";
  1692. case IT_USABLE: return "Usable";
  1693. case IT_ETC: return "Etc.";
  1694. case IT_WEAPON: return "Weapon";
  1695. case IT_ARMOR: return "Armor";
  1696. case IT_CARD: return "Card";
  1697. case IT_PETEGG: return "Pet Egg";
  1698. case IT_PETARMOR: return "Pet Accessory";
  1699. case IT_AMMO: return "Arrow/Ammunition";
  1700. case IT_DELAYCONSUME: return "Delay-Consume Usable";
  1701. case IT_SHADOWGEAR: return "Shadow Equipment";
  1702. case IT_CASH: return "Cash Usable";
  1703. }
  1704. return "Unknown Type";
  1705. }
  1706. /**
  1707. * Converts the jobmask from the format in itemdb to the format used by the map server.
  1708. * @param bclass: Pointer to store itemdb format
  1709. * @param jobmask: Job Mask to convert
  1710. * @param active: Whether the flag is active or not
  1711. * @author: Skotlex
  1712. */
  1713. static void itemdb_jobid2mapid(uint64 bclass[3], e_mapid jobmask, bool active)
  1714. {
  1715. uint64 temp_mask[3] = { 0 };
  1716. if (jobmask != MAPID_ALL) {
  1717. // Calculate the required bit to set
  1718. uint64 job = 1ULL << ( jobmask & MAPID_BASEMASK );
  1719. // 2-1
  1720. if( ( jobmask & JOBL_2_1 ) != 0 ){
  1721. temp_mask[1] |= job;
  1722. // 2-2
  1723. }else if( ( jobmask & JOBL_2_2 ) != 0 ){
  1724. temp_mask[2] |= job;
  1725. // Basejob
  1726. }else{
  1727. temp_mask[0] |= job;
  1728. }
  1729. } else {
  1730. temp_mask[0] = temp_mask[1] = temp_mask[2] = MAPID_ALL;
  1731. }
  1732. for (int i = 0; i < ARRAYLENGTH(temp_mask); i++) {
  1733. if (temp_mask[i] == 0)
  1734. continue;
  1735. if (active)
  1736. bclass[i] |= temp_mask[i];
  1737. else
  1738. bclass[i] &= ~temp_mask[i];
  1739. }
  1740. }
  1741. /*==========================================
  1742. * Loads an item from the db. If not found, it will return the dummy item.
  1743. * @param nameid
  1744. * @return *item_data or *dummy_item if item not found
  1745. *------------------------------------------*/
  1746. struct item_data* itemdb_search(t_itemid nameid) {
  1747. std::shared_ptr<item_data> id;
  1748. if (!(id = item_db.find(nameid))) {
  1749. ShowWarning("itemdb_search: Item ID %u does not exists in the item_db. Using dummy data.\n", nameid);
  1750. id = item_db.find(ITEMID_DUMMY);
  1751. }
  1752. return id.get();
  1753. }
  1754. /** Checks if item is equip type or not
  1755. * @param id Item data
  1756. * @return True if item is equip, false otherwise
  1757. */
  1758. bool itemdb_isequip2(struct item_data *id) {
  1759. nullpo_ret(id);
  1760. switch (id->type) {
  1761. case IT_WEAPON:
  1762. case IT_ARMOR:
  1763. case IT_AMMO:
  1764. case IT_SHADOWGEAR:
  1765. return true;
  1766. default:
  1767. return false;
  1768. }
  1769. }
  1770. /** Checks if item is stackable or not
  1771. * @param id Item data
  1772. * @return True if item is stackable, false otherwise
  1773. */
  1774. bool itemdb_isstackable2(struct item_data *id)
  1775. {
  1776. nullpo_ret(id);
  1777. return id->isStackable();
  1778. }
  1779. /*==========================================
  1780. * Trade Restriction functions [Skotlex]
  1781. *------------------------------------------*/
  1782. bool itemdb_isdropable_sub(struct item_data *item, int gmlv, int unused) {
  1783. return (item && (!(item->flag.trade_restriction.drop) || gmlv >= item->gm_lv_trade_override));
  1784. }
  1785. bool itemdb_cantrade_sub(struct item_data* item, int gmlv, int gmlv2) {
  1786. return (item && (!(item->flag.trade_restriction.trade) || gmlv >= item->gm_lv_trade_override || gmlv2 >= item->gm_lv_trade_override));
  1787. }
  1788. bool itemdb_canpartnertrade_sub(struct item_data* item, int gmlv, int gmlv2) {
  1789. return (item && (item->flag.trade_restriction.trade_partner || gmlv >= item->gm_lv_trade_override || gmlv2 >= item->gm_lv_trade_override));
  1790. }
  1791. bool itemdb_cansell_sub(struct item_data* item, int gmlv, int unused) {
  1792. return (item && (!(item->flag.trade_restriction.sell) || gmlv >= item->gm_lv_trade_override));
  1793. }
  1794. bool itemdb_cancartstore_sub(struct item_data* item, int gmlv, int unused) {
  1795. return (item && (!(item->flag.trade_restriction.cart) || gmlv >= item->gm_lv_trade_override));
  1796. }
  1797. bool itemdb_canstore_sub(struct item_data* item, int gmlv, int unused) {
  1798. return (item && (!(item->flag.trade_restriction.storage) || gmlv >= item->gm_lv_trade_override));
  1799. }
  1800. bool itemdb_canguildstore_sub(struct item_data* item, int gmlv, int unused) {
  1801. return (item && (!(item->flag.trade_restriction.guild_storage) || gmlv >= item->gm_lv_trade_override));
  1802. }
  1803. bool itemdb_canmail_sub(struct item_data* item, int gmlv, int unused) {
  1804. return (item && (!(item->flag.trade_restriction.mail) || gmlv >= item->gm_lv_trade_override));
  1805. }
  1806. bool itemdb_canauction_sub(struct item_data* item, int gmlv, int unused) {
  1807. return (item && (!(item->flag.trade_restriction.auction) || gmlv >= item->gm_lv_trade_override));
  1808. }
  1809. bool itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, bool (*func)(struct item_data*, int, int))
  1810. {
  1811. struct item_data* item_data = itemdb_search(item->nameid);
  1812. int i;
  1813. if (!func(item_data, gmlv, gmlv2))
  1814. return false;
  1815. if(item_data->slots == 0 || itemdb_isspecial(item->card[0]))
  1816. return true;
  1817. for(i = 0; i < item_data->slots; i++) {
  1818. if (!item->card[i]) continue;
  1819. if (!func(itemdb_search(item->card[i]), gmlv, gmlv2))
  1820. return false;
  1821. }
  1822. return true;
  1823. }
  1824. bool itemdb_ishatched_egg(struct item* item) {
  1825. if (item && item->card[0] == CARD0_PET && item->attribute == 1)
  1826. return true;
  1827. return false;
  1828. }
  1829. /** Specifies if item-type should drop unidentified.
  1830. * @param nameid ID of item
  1831. */
  1832. char itemdb_isidentified(t_itemid nameid) {
  1833. int type=itemdb_type(nameid);
  1834. switch (type) {
  1835. case IT_WEAPON:
  1836. case IT_ARMOR:
  1837. case IT_PETARMOR:
  1838. case IT_SHADOWGEAR:
  1839. return 0;
  1840. default:
  1841. return 1;
  1842. }
  1843. }
  1844. const std::string ItemGroupDatabase::getDefaultLocation() {
  1845. return std::string(db_path) + "/item_group_db.yml";
  1846. }
  1847. /**
  1848. * Reads and parses an entry from the item_group_db.
  1849. * @param node: YAML node containing the entry.
  1850. * @return count of successfully parsed rows
  1851. */
  1852. uint64 ItemGroupDatabase::parseBodyNode(const ryml::NodeRef& node) {
  1853. std::string group_name;
  1854. if (!this->asString(node, "Group", group_name))
  1855. return 0;
  1856. std::string group_name_constant = "IG_" + group_name;
  1857. int64 constant;
  1858. if (!script_get_constant(group_name_constant.c_str(), &constant) || constant < IG_BLUEBOX) {
  1859. if (strncasecmp(group_name.c_str(), "IG_", 3) != 0)
  1860. this->invalidWarning(node["Group"], "Invalid group %s.\n", group_name.c_str());
  1861. else
  1862. this->invalidWarning(node["Group"], "Invalid group %s. Note that 'IG_' is automatically appended to the group name.\n", group_name.c_str());
  1863. return 0;
  1864. }
  1865. uint16 id = static_cast<uint16>(constant);
  1866. std::shared_ptr<s_item_group_db> group = this->find(id);
  1867. bool exists = group != nullptr;
  1868. if (!exists) {
  1869. group = std::make_shared<s_item_group_db>();
  1870. group->id = id;
  1871. }
  1872. if (this->nodeExists(node, "SubGroups")) {
  1873. const auto& subNode = node["SubGroups"];
  1874. for (const auto& subit : subNode) {
  1875. if (this->nodeExists(subit, "Clear")) {
  1876. uint16 id;
  1877. if (!this->asUInt16(subit, "Clear", id))
  1878. continue;
  1879. if (group->random.erase(id) == 0)
  1880. this->invalidWarning(subit["Clear"], "The SubGroup %hu doesn't exist in the group %s. Clear failed.\n", id, group_name.c_str());
  1881. continue;
  1882. }
  1883. if (!this->nodesExist(subit, { "SubGroup", "List" })) {
  1884. continue;
  1885. }
  1886. uint16 subgroup;
  1887. if (this->nodeExists(subit, "SubGroup")) {
  1888. if (!this->asUInt16(subit, "SubGroup", subgroup))
  1889. continue;
  1890. } else {
  1891. subgroup = 1;
  1892. }
  1893. std::shared_ptr<s_item_group_random> random = util::umap_find(group->random, subgroup);
  1894. if (random == nullptr) {
  1895. random = std::make_shared<s_item_group_random>();
  1896. group->random[subgroup] = random;
  1897. }
  1898. const auto& listNode = subit["List"];
  1899. for (const auto& listit : listNode) {
  1900. if (this->nodeExists(listit, "Clear")) {
  1901. std::string item_name;
  1902. if (!this->asString(listit, "Clear", item_name))
  1903. continue;
  1904. std::shared_ptr<item_data> item = item_db.search_aegisname( item_name.c_str() );
  1905. if (item == nullptr) {
  1906. this->invalidWarning(listit["Clear"], "Unknown Item %s. Clear failed.\n", item_name.c_str());
  1907. continue;
  1908. }
  1909. if (random->data.erase(item->nameid) == 0)
  1910. this->invalidWarning(listit["Clear"], "Item %hu doesn't exist in the SubGroup %hu (group %s). Clear failed.\n", item->nameid, subgroup, group_name.c_str());
  1911. continue;
  1912. }
  1913. std::string item_name;
  1914. if (!this->asString(listit, "Item", item_name))
  1915. continue;
  1916. std::shared_ptr<item_data> item = item_db.search_aegisname( item_name.c_str() );
  1917. if (item == nullptr) {
  1918. this->invalidWarning(listit["Item"], "Unknown Item %s.\n", item_name.c_str());
  1919. continue;
  1920. }
  1921. std::shared_ptr<s_item_group_entry> entry = util::umap_find(random->data, item->nameid);
  1922. bool entry_exists = entry != nullptr;
  1923. if (!entry_exists) {
  1924. entry = std::make_shared<s_item_group_entry>();
  1925. random->data[item->nameid] = entry;
  1926. }
  1927. entry->nameid = item->nameid;
  1928. if (this->nodeExists(listit, "Rate")) {
  1929. uint16 rate;
  1930. if (!this->asUInt16(listit, "Rate", rate))
  1931. continue;
  1932. entry->rate = rate;
  1933. } else {
  1934. if (!entry_exists)
  1935. entry->rate = 0;
  1936. }
  1937. if (subgroup == 0 && entry->rate > 0) {
  1938. this->invalidWarning(listit["Item"], "SubGroup 0 is reserved for item without Rate ('must' item). Defaulting Rate to 0.\n");
  1939. entry->rate = 0;
  1940. }
  1941. if (subgroup != 0 && entry->rate == 0) {
  1942. this->invalidWarning(listit["Item"], "Entry must have a Rate for group above 0, skipping.\n");
  1943. continue;
  1944. }
  1945. if (this->nodeExists(listit, "Amount")) {
  1946. uint16 amount;
  1947. if (!this->asUInt16(listit, "Amount", amount))
  1948. continue;
  1949. entry->amount = cap_value(amount, 1, MAX_AMOUNT);
  1950. } else {
  1951. if (!entry_exists)
  1952. entry->amount = 1;
  1953. }
  1954. if (this->nodeExists(listit, "Duration")) {
  1955. uint16 duration;
  1956. if (!this->asUInt16(listit, "Duration", duration))
  1957. continue;
  1958. entry->duration = duration;
  1959. } else {
  1960. if (!entry_exists)
  1961. entry->duration = 0;
  1962. }
  1963. if (this->nodeExists(listit, "Announced")) {
  1964. bool isAnnounced;
  1965. if (!this->asBool(listit, "Announced", isAnnounced))
  1966. continue;
  1967. entry->isAnnounced = isAnnounced;
  1968. } else {
  1969. if (!entry_exists)
  1970. entry->isAnnounced = false;
  1971. }
  1972. if (this->nodeExists(listit, "UniqueId")) {
  1973. bool guid;
  1974. if (!this->asBool(listit, "UniqueId", guid))
  1975. continue;
  1976. entry->GUID = guid;
  1977. } else {
  1978. if (!entry_exists)
  1979. entry->GUID = item->flag.guid;
  1980. }
  1981. if (this->nodeExists(listit, "Stacked")) {
  1982. bool isStacked;
  1983. if (!this->asBool(listit, "Stacked", isStacked))
  1984. continue;
  1985. entry->isStacked = isStacked;
  1986. } else {
  1987. if (!entry_exists)
  1988. entry->isStacked = true;
  1989. }
  1990. if (this->nodeExists(listit, "Named")) {
  1991. bool named;
  1992. if (!this->asBool(listit, "Named", named))
  1993. continue;
  1994. entry->isNamed = named;
  1995. } else {
  1996. if (!entry_exists)
  1997. entry->isNamed = false;
  1998. }
  1999. if (this->nodeExists(listit, "Bound")) {
  2000. std::string bound_name;
  2001. if (!this->asString(listit, "Bound", bound_name))
  2002. continue;
  2003. std::string bound_name_constant = "BOUND_" + bound_name;
  2004. int64 bound;
  2005. if (!script_get_constant(bound_name_constant.c_str(), &bound) || bound < BOUND_NONE || bound >= BOUND_MAX) {
  2006. this->invalidWarning(listit["Group"], "Invalid Bound %s.\n", bound_name.c_str());
  2007. continue;
  2008. }
  2009. entry->bound = static_cast<uint8>(bound);
  2010. } else {
  2011. if (!entry_exists)
  2012. entry->bound = BOUND_NONE;
  2013. }
  2014. if( this->nodeExists( listit, "RandomOptionGroup" ) ){
  2015. std::string name;
  2016. if( !this->asString( listit, "RandomOptionGroup", name ) ){
  2017. return 0;
  2018. }
  2019. uint16 id;
  2020. if( !random_option_group.option_get_id( name, id ) ){
  2021. this->invalidWarning( listit["RandomOptionGroup"], "Unknown random option group \"%s\".\n", name.c_str() );
  2022. return 0;
  2023. }
  2024. entry->randomOptionGroup = random_option_group.find( id );
  2025. }else{
  2026. if( !entry_exists ){
  2027. entry->randomOptionGroup = nullptr;
  2028. }
  2029. }
  2030. if( this->nodeExists( listit, "RefineMinimum" ) ){
  2031. uint16 refine;
  2032. if( !this->asUInt16( listit, "RefineMinimum", refine ) ){
  2033. return 0;
  2034. }
  2035. if( refine > MAX_REFINE ){
  2036. this->invalidWarning( listit["RefineMinimum"], "Minimum refine % hu is too high, capping to MAX_REFINE...\n", refine );
  2037. refine = MAX_REFINE;
  2038. }
  2039. entry->refineMinimum = refine;
  2040. }else{
  2041. if( !exists ){
  2042. entry->refineMinimum = 0;
  2043. }
  2044. }
  2045. if( this->nodeExists( listit, "RefineMaximum" ) ){
  2046. uint16 refine;
  2047. if( !this->asUInt16( listit, "RefineMaximum", refine ) ){
  2048. return 0;
  2049. }
  2050. if( refine > MAX_REFINE ){
  2051. this->invalidWarning( listit["RefineMaximum"], "Maximum refine %hu is too high, capping to MAX_REFINE...\n", refine );
  2052. refine = MAX_REFINE;
  2053. }
  2054. entry->refineMaximum = refine;
  2055. }else{
  2056. if( !exists ){
  2057. entry->refineMaximum = 0;
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. if (!exists)
  2064. this->put(id, group);
  2065. return 1;
  2066. }
  2067. void ItemGroupDatabase::loadingFinished() {
  2068. for (const auto &group : *this) {
  2069. for (const auto &random : group.second->random) {
  2070. random.second->total_rate = 0;
  2071. for (const auto &it : random.second->data) {
  2072. random.second->total_rate += it.second->rate;
  2073. }
  2074. }
  2075. }
  2076. TypesafeYamlDatabase::loadingFinished();
  2077. }
  2078. /** Read item forbidden by mapflag (can't equip item)
  2079. * Structure: <nameid>,<mode>
  2080. */
  2081. static bool itemdb_read_noequip(char* str[], int columns, int current) {
  2082. t_itemid nameid;
  2083. int flag;
  2084. nameid = strtoul(str[0], nullptr, 10);
  2085. flag = atoi(str[1]);
  2086. std::shared_ptr<item_data> id = item_db.find(nameid);
  2087. if( id == nullptr )
  2088. {
  2089. ShowWarning("itemdb_read_noequip: Invalid item id %u.\n", nameid);
  2090. return false;
  2091. }
  2092. if (flag >= 0)
  2093. id->flag.no_equip |= flag;
  2094. else
  2095. id->flag.no_equip &= ~abs(flag);
  2096. return true;
  2097. }
  2098. const std::string ComboDatabase::getDefaultLocation() {
  2099. return std::string(db_path) + "/item_combos.yml";
  2100. }
  2101. uint16 ComboDatabase::find_combo_id( const std::vector<t_itemid>& items ){
  2102. for (const auto &it : *this) {
  2103. if (it.second->nameid == items) {
  2104. return it.first;
  2105. }
  2106. }
  2107. return 0;
  2108. }
  2109. /**
  2110. * Reads and parses an entry from the item_combos.
  2111. * @param node: YAML node containing the entry.
  2112. * @return count of successfully parsed rows
  2113. */
  2114. uint64 ComboDatabase::parseBodyNode(const ryml::NodeRef& node) {
  2115. std::vector<std::vector<t_itemid>> items_list;
  2116. if( !this->nodesExist( node, { "Combos" } ) ){
  2117. return 0;
  2118. }
  2119. const ryml::NodeRef& combosNode = node["Combos"];
  2120. for (const auto& comboit : combosNode) {
  2121. static const std::string nodeName = "Combo";
  2122. if (!this->nodesExist(comboit, { nodeName })) {
  2123. return 0;
  2124. }
  2125. const ryml::NodeRef& comboNode = comboit["Combo"];
  2126. if (!comboNode.is_seq()) {
  2127. this->invalidWarning(comboNode, "%s should be a sequence.\n", nodeName.c_str());
  2128. return 0;
  2129. }
  2130. std::vector<t_itemid> items = {};
  2131. for (const auto it : comboNode) {
  2132. std::string item_name;
  2133. c4::from_chars(it.val(), &item_name);
  2134. std::shared_ptr<item_data> item = item_db.search_aegisname(item_name.c_str());
  2135. if (item == nullptr) {
  2136. this->invalidWarning(it, "Invalid item %s, skipping.\n", item_name.c_str());
  2137. return 0;
  2138. }
  2139. items.push_back(item->nameid);
  2140. }
  2141. if (items.empty()) {
  2142. this->invalidWarning(comboNode, "Empty combo, skipping.\n");
  2143. return 0;
  2144. }
  2145. if (items.size() < 2) {
  2146. this->invalidWarning(comboNode, "Not enough item to make a combo (need at least 2). Skipping.\n");
  2147. return 0;
  2148. }
  2149. std::sort(items.begin(), items.end());
  2150. items_list.push_back(items);
  2151. }
  2152. if (items_list.empty()) {
  2153. this->invalidWarning(combosNode, "No combos defined, skipping.\n");
  2154. return 0;
  2155. }
  2156. if (this->nodeExists(node, "Clear")) {
  2157. bool clear = false;
  2158. if (!this->asBool(node, "Clear", clear))
  2159. return 0;
  2160. // Remove the combo (if exists)
  2161. if (clear) {
  2162. for (const auto& itemsit : items_list) {
  2163. uint16 id = this->find_combo_id(itemsit);
  2164. if (id == 0) {
  2165. this->invalidWarning(node["Clear"], "Unable to clear the combo.\n");
  2166. return 0;
  2167. }
  2168. this->erase(id);
  2169. }
  2170. return 1;
  2171. }
  2172. }
  2173. uint64 count = 0;
  2174. for (const auto &itemsit : items_list) {
  2175. // Find the id when the combo exists
  2176. uint16 id = this->find_combo_id(itemsit);
  2177. std::shared_ptr<s_item_combo> combo = this->find(id);
  2178. bool exists = combo != nullptr;
  2179. if (!exists) {
  2180. combo = std::make_shared<s_item_combo>();
  2181. combo->nameid.insert(combo->nameid.begin(), itemsit.begin(), itemsit.end());
  2182. combo->id = ++this->combo_num;
  2183. }
  2184. if (this->nodeExists(node, "Script")) {
  2185. std::string script;
  2186. if (!this->asString(node, "Script", script))
  2187. return 0;
  2188. if (exists) {
  2189. script_free_code(combo->script);
  2190. combo->script = nullptr;
  2191. }
  2192. combo->script = parse_script(script.c_str(), this->getCurrentFile().c_str(), this->getLineNumber(node["Script"]), SCRIPT_IGNORE_EXTERNAL_BRACKETS);
  2193. } else {
  2194. if (!exists) {
  2195. combo->script = nullptr;
  2196. }
  2197. }
  2198. if (!exists)
  2199. this->put( combo->id, combo );
  2200. count++;
  2201. }
  2202. return count;
  2203. }
  2204. void ComboDatabase::loadingFinished() {
  2205. // Populate item_data to refer to the combo
  2206. for (const auto &combo : *this) {
  2207. for (const auto &itm : combo.second->nameid) {
  2208. std::shared_ptr<item_data> it = item_db.find(itm);
  2209. if (it != nullptr)
  2210. it->combos.push_back(combo.second);
  2211. }
  2212. }
  2213. TypesafeYamlDatabase::loadingFinished();
  2214. }
  2215. /**
  2216. * Process Roulette items
  2217. */
  2218. bool itemdb_parse_roulette_db(void)
  2219. {
  2220. int i, j;
  2221. uint32 count = 0;
  2222. // retrieve all rows from the item database
  2223. if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", roulette_table)) {
  2224. Sql_ShowDebug(mmysql_handle);
  2225. return false;
  2226. }
  2227. for (i = 0; i < MAX_ROULETTE_LEVEL; i++)
  2228. rd.items[i] = 0;
  2229. for (i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  2230. int k, limit = MAX_ROULETTE_COLUMNS - i;
  2231. for (k = 0; k < limit && SQL_SUCCESS == Sql_NextRow(mmysql_handle); k++) {
  2232. char* data;
  2233. t_itemid item_id;
  2234. unsigned short amount;
  2235. int level, flag;
  2236. Sql_GetData(mmysql_handle, 1, &data, NULL); level = atoi(data);
  2237. Sql_GetData(mmysql_handle, 2, &data, NULL); item_id = strtoul(data, nullptr, 10);
  2238. Sql_GetData(mmysql_handle, 3, &data, NULL); amount = atoi(data);
  2239. Sql_GetData(mmysql_handle, 4, &data, NULL); flag = atoi(data);
  2240. if (!itemdb_exists(item_id)) {
  2241. ShowWarning("itemdb_parse_roulette_db: Unknown item ID '%u' in level '%d'\n", item_id, level);
  2242. continue;
  2243. }
  2244. if (amount < 1 || amount > MAX_AMOUNT){
  2245. ShowWarning("itemdb_parse_roulette_db: Unsupported amount '%hu' for item ID '%u' in level '%d'\n", amount, item_id, level);
  2246. continue;
  2247. }
  2248. if (flag < 0 || flag > 1) {
  2249. ShowWarning("itemdb_parse_roulette_db: Unsupported flag '%d' for item ID '%u' in level '%d'\n", flag, item_id, level);
  2250. continue;
  2251. }
  2252. j = rd.items[i];
  2253. RECREATE(rd.nameid[i], t_itemid, ++rd.items[i]);
  2254. RECREATE(rd.qty[i], unsigned short, rd.items[i]);
  2255. RECREATE(rd.flag[i], int, rd.items[i]);
  2256. rd.nameid[i][j] = item_id;
  2257. rd.qty[i][j] = amount;
  2258. rd.flag[i][j] = flag;
  2259. ++count;
  2260. }
  2261. }
  2262. // free the query result
  2263. Sql_FreeResult(mmysql_handle);
  2264. for (i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  2265. int limit = MAX_ROULETTE_COLUMNS - i;
  2266. if (rd.items[i] == limit)
  2267. continue;
  2268. if (rd.items[i] > limit) {
  2269. ShowWarning("itemdb_parse_roulette_db: level %d has %d items, only %d supported, capping...\n", i + 1, rd.items[i], limit);
  2270. rd.items[i] = limit;
  2271. continue;
  2272. }
  2273. /** this scenario = rd.items[i] < limit **/
  2274. ShowWarning("itemdb_parse_roulette_db: Level %d has %d items, %d are required. Filling with Apples...\n", i + 1, rd.items[i], limit);
  2275. rd.items[i] = limit;
  2276. RECREATE(rd.nameid[i], t_itemid, rd.items[i]);
  2277. RECREATE(rd.qty[i], unsigned short, rd.items[i]);
  2278. RECREATE(rd.flag[i], int, rd.items[i]);
  2279. for (j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  2280. if (rd.qty[i][j])
  2281. continue;
  2282. rd.nameid[i][j] = ITEMID_APPLE;
  2283. rd.qty[i][j] = 1;
  2284. rd.flag[i][j] = 0;
  2285. }
  2286. }
  2287. ShowStatus("Done reading '" CL_WHITE "%u" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, roulette_table);
  2288. return true;
  2289. }
  2290. /**
  2291. * Free Roulette items
  2292. */
  2293. static void itemdb_roulette_free(void) {
  2294. int i;
  2295. for (i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  2296. if (rd.nameid[i])
  2297. aFree(rd.nameid[i]);
  2298. if (rd.qty[i])
  2299. aFree(rd.qty[i]);
  2300. if (rd.flag[i])
  2301. aFree(rd.flag[i]);
  2302. rd.nameid[i] = NULL;
  2303. rd.qty[i] = NULL;
  2304. rd.flag[i] = NULL;
  2305. rd.items[i] = 0;
  2306. }
  2307. }
  2308. /**
  2309. * Convert SQL data to YAML Node
  2310. * @param str: Array of parsed SQL data
  2311. * @return True on success or false otherwise
  2312. */
  2313. static bool itemdb_read_sqldb_sub(std::vector<std::string> str) {
  2314. ryml::Tree tree;
  2315. ryml::NodeRef rootNode = tree.rootref();
  2316. rootNode |= ryml::MAP;
  2317. int32 index = -1;
  2318. rootNode["Id"] << str[++index];
  2319. if (!str[++index].empty())
  2320. rootNode["AegisName"] << str[index];
  2321. if (!str[++index].empty())
  2322. rootNode["Name"] << str[index];
  2323. if (!str[++index].empty())
  2324. rootNode["Type"] << str[index];
  2325. if (!str[++index].empty())
  2326. rootNode["SubType"] << str[index];
  2327. if (!str[++index].empty())
  2328. rootNode["Buy"] << str[index];
  2329. if (!str[++index].empty())
  2330. rootNode["Sell"] << str[index];
  2331. if (!str[++index].empty())
  2332. rootNode["Weight"] << str[index];
  2333. if (!str[++index].empty())
  2334. rootNode["Attack"] << str[index];
  2335. if (!str[++index].empty())
  2336. rootNode["Defense"] << str[index];
  2337. if (!str[++index].empty())
  2338. rootNode["Range"] << str[index];
  2339. if (!str[++index].empty())
  2340. rootNode["Slots"] << str[index];
  2341. ryml::NodeRef jobs = rootNode["Jobs"];
  2342. jobs |= ryml::MAP;
  2343. if (!str[++index].empty())
  2344. jobs["All"] << (std::stoi(str[index]) ? "true" : "false");
  2345. if (!str[++index].empty())
  2346. jobs["Acolyte"] << (std::stoi(str[index]) ? "true" : "false");
  2347. if (!str[++index].empty())
  2348. jobs["Alchemist"] << (std::stoi(str[index]) ? "true" : "false");
  2349. if (!str[++index].empty())
  2350. jobs["Archer"] << (std::stoi(str[index]) ? "true" : "false");
  2351. if (!str[++index].empty())
  2352. jobs["Assassin"] << (std::stoi(str[index]) ? "true" : "false");
  2353. if (!str[++index].empty())
  2354. jobs["BardDancer"] << (std::stoi(str[index]) ? "true" : "false");
  2355. if (!str[++index].empty())
  2356. jobs["Blacksmith"] << (std::stoi(str[index]) ? "true" : "false");
  2357. if (!str[++index].empty())
  2358. jobs["Crusader"] << (std::stoi(str[index]) ? "true" : "false");
  2359. if (!str[++index].empty())
  2360. jobs["Gunslinger"] << (std::stoi(str[index]) ? "true" : "false");
  2361. if (!str[++index].empty())
  2362. jobs["Hunter"] << (std::stoi(str[index]) ? "true" : "false");
  2363. if (!str[++index].empty())
  2364. jobs["Knight"] << (std::stoi(str[index]) ? "true" : "false");
  2365. if (!str[++index].empty())
  2366. jobs["Mage"] << (std::stoi(str[index]) ? "true" : "false");
  2367. if (!str[++index].empty())
  2368. jobs["Merchant"] << (std::stoi(str[index]) ? "true" : "false");
  2369. if (!str[++index].empty())
  2370. jobs["Monk"] << (std::stoi(str[index]) ? "true" : "false");
  2371. if (!str[++index].empty())
  2372. jobs["Ninja"] << (std::stoi(str[index]) ? "true" : "false");
  2373. if (!str[++index].empty())
  2374. jobs["Novice"] << (std::stoi(str[index]) ? "true" : "false");
  2375. if (!str[++index].empty())
  2376. jobs["Priest"] << (std::stoi(str[index]) ? "true" : "false");
  2377. if (!str[++index].empty())
  2378. jobs["Rogue"] << (std::stoi(str[index]) ? "true" : "false");
  2379. if (!str[++index].empty())
  2380. jobs["Sage"] << (std::stoi(str[index]) ? "true" : "false");
  2381. if (!str[++index].empty())
  2382. jobs["SoulLinker"] << (std::stoi(str[index]) ? "true" : "false");
  2383. if (!str[++index].empty())
  2384. jobs["StarGladiator"] << (std::stoi(str[index]) ? "true" : "false");
  2385. if (!str[++index].empty())
  2386. jobs["SuperNovice"] << (std::stoi(str[index]) ? "true" : "false");
  2387. if (!str[++index].empty())
  2388. jobs["Swordman"] << (std::stoi(str[index]) ? "true" : "false");
  2389. if (!str[++index].empty())
  2390. jobs["Taekwon"] << (std::stoi(str[index]) ? "true" : "false");
  2391. if (!str[++index].empty())
  2392. jobs["Thief"] << (std::stoi(str[index]) ? "true" : "false");
  2393. if (!str[++index].empty())
  2394. jobs["Wizard"] << (std::stoi(str[index]) ? "true" : "false");
  2395. ryml::NodeRef classes = rootNode["Classes"];
  2396. classes |= ryml::MAP;
  2397. if (!str[++index].empty())
  2398. classes["All"] << (std::stoi(str[index]) ? "true" : "false");
  2399. if (!str[++index].empty())
  2400. classes["Normal"] << (std::stoi(str[index]) ? "true" : "false");
  2401. if (!str[++index].empty())
  2402. classes["Upper"] << (std::stoi(str[index]) ? "true" : "false");
  2403. if (!str[++index].empty())
  2404. classes["Baby"] << (std::stoi(str[index]) ? "true" : "false");
  2405. if (!str[++index].empty())
  2406. rootNode["Gender"] << str[index];
  2407. ryml::NodeRef locations = rootNode["Locations"];
  2408. locations |= ryml::MAP;
  2409. if (!str[++index].empty())
  2410. locations["Head_Top"] << (std::stoi(str[index]) ? "true" : "false");
  2411. if (!str[++index].empty())
  2412. locations["Head_Mid"] << (std::stoi(str[index]) ? "true" : "false");
  2413. if (!str[++index].empty())
  2414. locations["Head_Low"] << (std::stoi(str[index]) ? "true" : "false");
  2415. if (!str[++index].empty())
  2416. locations["Armor"] << (std::stoi(str[index]) ? "true" : "false");
  2417. if (!str[++index].empty())
  2418. locations["Right_Hand"] << (std::stoi(str[index]) ? "true" : "false");
  2419. if (!str[++index].empty())
  2420. locations["Left_Hand"] << (std::stoi(str[index]) ? "true" : "false");
  2421. if (!str[++index].empty())
  2422. locations["Garment"] << (std::stoi(str[index]) ? "true" : "false");
  2423. if (!str[++index].empty())
  2424. locations["Shoes"] << (std::stoi(str[index]) ? "true" : "false");
  2425. if (!str[++index].empty())
  2426. locations["Right_Accessory"] << (std::stoi(str[index]) ? "true" : "false");
  2427. if (!str[++index].empty())
  2428. locations["Left_Accessory"] << (std::stoi(str[index]) ? "true" : "false");
  2429. if (!str[++index].empty())
  2430. locations["Costume_Head_Top"] << (std::stoi(str[index]) ? "true" : "false");
  2431. if (!str[++index].empty())
  2432. locations["Costume_Head_Mid"] << (std::stoi(str[index]) ? "true" : "false");
  2433. if (!str[++index].empty())
  2434. locations["Costume_Head_Low"] << (std::stoi(str[index]) ? "true" : "false");
  2435. if (!str[++index].empty())
  2436. locations["Costume_Garment"] << (std::stoi(str[index]) ? "true" : "false");
  2437. if (!str[++index].empty())
  2438. locations["Ammo"] << (std::stoi(str[index]) ? "true" : "false");
  2439. if (!str[++index].empty())
  2440. locations["Shadow_Armor"] << (std::stoi(str[index]) ? "true" : "false");
  2441. if (!str[++index].empty())
  2442. locations["Shadow_Weapon"] << (std::stoi(str[index]) ? "true" : "false");
  2443. if (!str[++index].empty())
  2444. locations["Shadow_Shield"] << (std::stoi(str[index]) ? "true" : "false");
  2445. if (!str[++index].empty())
  2446. locations["Shadow_Shoes"] << (std::stoi(str[index]) ? "true" : "false");
  2447. if (!str[++index].empty())
  2448. locations["Shadow_Right_Accessory"] << (std::stoi(str[index]) ? "true" : "false");
  2449. if (!str[++index].empty())
  2450. locations["Shadow_Left_Accessory"] << (std::stoi(str[index]) ? "true" : "false");
  2451. if (!str[++index].empty())
  2452. rootNode["WeaponLevel"] << str[index];
  2453. if (!str[++index].empty())
  2454. rootNode["ArmorLevel"] << str[index];
  2455. if (!str[++index].empty())
  2456. rootNode["EquipLevelMin"] << str[index];
  2457. if (!str[++index].empty())
  2458. rootNode["EquipLevelMax"] << str[index];
  2459. if (!str[++index].empty())
  2460. rootNode["Refineable"] << (std::stoi(str[index]) ? "true" : "false");
  2461. if (!str[++index].empty())
  2462. rootNode["View"] << str[index];
  2463. if (!str[++index].empty())
  2464. rootNode["AliasName"] << str[index];
  2465. ryml::NodeRef flags = rootNode["Flags"];
  2466. flags |= ryml::MAP;
  2467. if (!str[++index].empty())
  2468. flags["BuyingStore"] << (std::stoi(str[index]) ? "true" : "false");
  2469. if (!str[++index].empty())
  2470. flags["DeadBranch"] << (std::stoi(str[index]) ? "true" : "false");
  2471. if (!str[++index].empty())
  2472. flags["Container"] << (std::stoi(str[index]) ? "true" : "false");
  2473. if (!str[++index].empty())
  2474. flags["UniqueId"] << (std::stoi(str[index]) ? "true" : "false");
  2475. if (!str[++index].empty())
  2476. flags["BindOnEquip"] << (std::stoi(str[index]) ? "true" : "false");
  2477. if (!str[++index].empty())
  2478. flags["DropAnnounce"] << (std::stoi(str[index]) ? "true" : "false");
  2479. if (!str[++index].empty())
  2480. flags["NoConsume"] << (std::stoi(str[index]) ? "true" : "false");
  2481. if (!str[++index].empty())
  2482. flags["DropEffect"] << str[index];
  2483. rootNode["Flags"] = flags;
  2484. ryml::NodeRef delay = rootNode["Delay"];
  2485. delay |= ryml::MAP;
  2486. if (!str[++index].empty())
  2487. delay["Duration"] << str[index];
  2488. if (!str[++index].empty())
  2489. delay["Status"] << str[index];
  2490. ryml::NodeRef stack = rootNode["Stack"];
  2491. stack |= ryml::MAP;
  2492. if (!str[++index].empty())
  2493. stack["Amount"] << str[index];
  2494. if (!str[++index].empty())
  2495. stack["Inventory"] << (std::stoi(str[index]) ? "true" : "false");
  2496. if (!str[++index].empty())
  2497. stack["Cart"] << (std::stoi(str[index]) ? "true" : "false");
  2498. if (!str[++index].empty())
  2499. stack["Storage"] << (std::stoi(str[index]) ? "true" : "false");
  2500. if (!str[++index].empty())
  2501. stack["GuildStorage"] << (std::stoi(str[index]) ? "true" : "false");
  2502. ryml::NodeRef nouse = rootNode["NoUse"];
  2503. nouse |= ryml::MAP;
  2504. if (!str[++index].empty())
  2505. nouse["Override"] << str[index];
  2506. if (!str[++index].empty())
  2507. nouse["Sitting"] << (std::stoi(str[index]) ? "true" : "false");
  2508. ryml::NodeRef trade = rootNode["Trade"];
  2509. trade |= ryml::MAP;
  2510. if (!str[++index].empty())
  2511. trade["Override"] << str[index];
  2512. if (!str[++index].empty())
  2513. trade["NoDrop"] << (std::stoi(str[index]) ? "true" : "false");
  2514. if (!str[++index].empty())
  2515. trade["NoTrade"] << (std::stoi(str[index]) ? "true" : "false");
  2516. if (!str[++index].empty())
  2517. trade["TradePartner"] << (std::stoi(str[index]) ? "true" : "false");
  2518. if (!str[++index].empty())
  2519. trade["NoSell"] << (std::stoi(str[index]) ? "true" : "false");
  2520. if (!str[++index].empty())
  2521. trade["NoCart"] << (std::stoi(str[index]) ? "true" : "false");
  2522. if (!str[++index].empty())
  2523. trade["NoStorage"] << (std::stoi(str[index]) ? "true" : "false");
  2524. if (!str[++index].empty())
  2525. trade["NoGuildStorage"] << (std::stoi(str[index]) ? "true" : "false");
  2526. if (!str[++index].empty())
  2527. trade["NoMail"] << (std::stoi(str[index]) ? "true" : "false");
  2528. if (!str[++index].empty())
  2529. trade["NoAuction"] << (std::stoi(str[index]) ? "true" : "false");
  2530. if (!str[++index].empty())
  2531. rootNode["Script"] << str[index];
  2532. if (!str[++index].empty())
  2533. rootNode["EquipScript"] << str[index];
  2534. if (!str[++index].empty())
  2535. rootNode["UnEquipScript"] << str[index];
  2536. #ifdef RENEWAL
  2537. if (!str[++index].empty())
  2538. rootNode["MagicAttack"] << str[index];
  2539. if (!str[++index].empty())
  2540. classes["Third"] << (std::stoi(str[index]) ? "true" : "false");
  2541. if (!str[++index].empty())
  2542. classes["Third_Upper"] << (std::stoi(str[index]) ? "true" : "false");
  2543. if (!str[++index].empty())
  2544. classes["Third_Baby"] << (std::stoi(str[index]) ? "true" : "false");
  2545. if (!str[++index].empty())
  2546. classes["Fourth"] << (std::stoi(str[index]) ? "true" : "false");
  2547. if (!str[++index].empty())
  2548. jobs["KagerouOboro"] << (std::stoi(str[index]) ? "true" : "false");
  2549. if (!str[++index].empty())
  2550. jobs["Rebellion"] << (std::stoi(str[index]) ? "true" : "false");
  2551. if (!str[++index].empty())
  2552. jobs["Summoner"] << (std::stoi(str[index]) ? "true" : "false");
  2553. if (!str[++index].empty())
  2554. jobs["Spirit_Handler"] << (std::stoi(str[index]) ? "true" : "false");
  2555. if (!str[++index].empty())
  2556. rootNode["Gradable"] << (std::stoi(str[index]) ? "true" : "false");
  2557. #endif
  2558. if( !jobs.has_children() ){
  2559. rootNode.remove_child( jobs );
  2560. }
  2561. if( !classes.has_children() ){
  2562. rootNode.remove_child( classes );
  2563. }
  2564. if( !locations.has_children() ){
  2565. rootNode.remove_child( locations );
  2566. }
  2567. if( !flags.has_children() ){
  2568. rootNode.remove_child( flags );
  2569. }
  2570. if( !delay.has_children() ){
  2571. rootNode.remove_child( delay );
  2572. }
  2573. if( !stack.has_children() ){
  2574. rootNode.remove_child( stack );
  2575. }
  2576. if( !nouse.has_children() ){
  2577. rootNode.remove_child( nouse );
  2578. }
  2579. if( !trade.has_children() ){
  2580. rootNode.remove_child( trade );
  2581. }
  2582. return item_db.parseBodyNode(rootNode) > 0;
  2583. }
  2584. /**
  2585. * Read SQL item_db table
  2586. */
  2587. static int itemdb_read_sqldb(void) {
  2588. const char* item_db_name[] = {
  2589. item_table,
  2590. item2_table
  2591. };
  2592. for( uint8 fi = 0; fi < ARRAYLENGTH(item_db_name); ++fi ) {
  2593. // retrieve all rows from the item database
  2594. if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `id`,`name_aegis`,`name_english`,`type`,`subtype`,`price_buy`,`price_sell`,`weight`,`attack`,`defense`,`range`,`slots`,"
  2595. "`job_all`,`job_acolyte`,`job_alchemist`,`job_archer`,`job_assassin`,`job_barddancer`,`job_blacksmith`,`job_crusader`,`job_gunslinger`,`job_hunter`,`job_knight`,`job_mage`,`job_merchant`,"
  2596. "`job_monk`,`job_ninja`,`job_novice`,`job_priest`,`job_rogue`,`job_sage`,`job_soullinker`,`job_stargladiator`,`job_supernovice`,`job_swordman`,`job_taekwon`,`job_thief`,`job_wizard`,"
  2597. "`class_all`,`class_normal`,`class_upper`,`class_baby`,`gender`,"
  2598. "`location_head_top`,`location_head_mid`,`location_head_low`,`location_armor`,`location_right_hand`,`location_left_hand`,`location_garment`,`location_shoes`,`location_right_accessory`,`location_left_accessory`,"
  2599. "`location_costume_head_top`,`location_costume_head_mid`,`location_costume_head_low`,`location_costume_garment`,`location_ammo`,`location_shadow_armor`,`location_shadow_weapon`,`location_shadow_shield`,`location_shadow_shoes`,`location_shadow_right_accessory`,`location_shadow_left_accessory`,"
  2600. "`weapon_level`,`armor_level`,`equip_level_min`,`equip_level_max`,`refineable`,`view`,`alias_name`,"
  2601. "`flag_buyingstore`,`flag_deadbranch`,`flag_container`,`flag_uniqueid`,`flag_bindonequip`,`flag_dropannounce`,`flag_noconsume`,`flag_dropeffect`,"
  2602. "`delay_duration`,`delay_status`,`stack_amount`,`stack_inventory`,`stack_cart`,`stack_storage`,`stack_guildstorage`,`nouse_override`,`nouse_sitting`,"
  2603. "`trade_override`,`trade_nodrop`,`trade_notrade`,`trade_tradepartner`,`trade_nosell`,`trade_nocart`,`trade_nostorage`,`trade_noguildstorage`,`trade_nomail`,`trade_noauction`,`script`,`equip_script`,`unequip_script`"
  2604. #ifdef RENEWAL
  2605. ",`magic_attack`,`class_third`,`class_third_upper`,`class_third_baby`,`class_fourth`,`job_kagerouoboro`,`job_rebellion`,`job_summoner`,`job_spirit_handler`,`gradable`"
  2606. #endif
  2607. " FROM `%s`", item_db_name[fi]) ) {
  2608. Sql_ShowDebug(mmysql_handle);
  2609. continue;
  2610. }
  2611. uint32 total_columns = Sql_NumColumns(mmysql_handle);
  2612. uint64 total_rows = Sql_NumRows(mmysql_handle), rows = 0, count = 0;
  2613. // process rows one by one
  2614. while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) {
  2615. ShowStatus( "Loading [%" PRIu64 "/%" PRIu64 "] rows from '" CL_WHITE "%s" CL_RESET "'" CL_CLL "\r", ++rows, total_rows, item_db_name[fi] );
  2616. std::vector<std::string> data = {};
  2617. for( uint32 i = 0; i < total_columns; ++i ) {
  2618. char *str;
  2619. Sql_GetData(mmysql_handle, i, &str, nullptr);
  2620. if (str == nullptr)
  2621. data.push_back("");
  2622. else
  2623. data.push_back(str);
  2624. }
  2625. if (!itemdb_read_sqldb_sub(data))
  2626. continue;
  2627. ++count;
  2628. }
  2629. // free the query result
  2630. Sql_FreeResult(mmysql_handle);
  2631. ShowStatus("Done reading '" CL_WHITE "%" PRIu64 CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, item_db_name[fi]);
  2632. }
  2633. item_db.loadingFinished();
  2634. return 0;
  2635. }
  2636. /** Check if the item is restricted by item_noequip.txt
  2637. * @param id Item that will be checked
  2638. * @param m Map ID
  2639. * @return true: can't be used; false: can be used
  2640. */
  2641. bool itemdb_isNoEquip(struct item_data *id, uint16 m) {
  2642. if (!id->flag.no_equip)
  2643. return false;
  2644. struct map_data *mapdata = map_getmapdata(m);
  2645. if ((id->flag.no_equip&1 && !mapdata_flag_vs2(mapdata)) || // Normal
  2646. (id->flag.no_equip&2 && mapdata->flag[MF_PVP]) || // PVP
  2647. (id->flag.no_equip&4 && mapdata_flag_gvg2_no_te(mapdata)) || // GVG
  2648. (id->flag.no_equip&8 && mapdata->flag[MF_BATTLEGROUND]) || // Battleground
  2649. (id->flag.no_equip&16 && mapdata_flag_gvg2_te(mapdata)) || // WOE:TE
  2650. (id->flag.no_equip&(mapdata->zone) && mapdata->flag[MF_RESTRICTED]) // Zone restriction
  2651. )
  2652. return true;
  2653. return false;
  2654. }
  2655. const std::string RandomOptionDatabase::getDefaultLocation() {
  2656. return std::string(db_path) + "/item_randomopt_db.yml";
  2657. }
  2658. /**
  2659. * Reads and parses an entry from the item_randomopt_db.
  2660. * @param node: YAML node containing the entry.
  2661. * @return count of successfully parsed rows
  2662. */
  2663. uint64 RandomOptionDatabase::parseBodyNode(const ryml::NodeRef& node) {
  2664. uint16 id;
  2665. if (!this->asUInt16(node, "Id", id))
  2666. return 0;
  2667. std::shared_ptr<s_random_opt_data> randopt = this->find(id);
  2668. bool exists = randopt != nullptr;
  2669. if (!exists) {
  2670. if (!this->nodesExist(node, { "Option", "Script" }))
  2671. return 0;
  2672. randopt = std::make_shared<s_random_opt_data>();
  2673. randopt->id = id;
  2674. }
  2675. if (this->nodeExists(node, "Option")) {
  2676. std::string name;
  2677. if (!this->asString(node, "Option", name))
  2678. return 0;
  2679. if (randopt->name.compare(name) != 0 && random_option_db.option_exists(name)) {
  2680. this->invalidWarning(node["Option"], "Found duplicate random option name for %s, skipping.\n", name.c_str());
  2681. return 0;
  2682. }
  2683. randopt->name = name;
  2684. }
  2685. if (this->nodeExists(node, "Script")) {
  2686. std::string script;
  2687. if (!this->asString(node, "Script", script))
  2688. return 0;
  2689. if (randopt->script) {
  2690. aFree(randopt->script);
  2691. randopt->script = nullptr;
  2692. }
  2693. randopt->script = parse_script(script.c_str(), this->getCurrentFile().c_str(), this->getLineNumber(node["Script"]), SCRIPT_IGNORE_EXTERNAL_BRACKETS);
  2694. }
  2695. if (!exists)
  2696. this->put(id, randopt);
  2697. return 1;
  2698. }
  2699. void RandomOptionDatabase::loadingFinished(){
  2700. const char* prefix = "RDMOPT_";
  2701. for( const auto& pair : *this ){
  2702. std::string name = prefix + pair.second->name;
  2703. int64 constant;
  2704. // Check if it has already been set
  2705. if( script_get_constant( name.c_str(), &constant ) ){
  2706. // It is already the same
  2707. if( constant == pair.first ){
  2708. continue;
  2709. }else{
  2710. // Export it to the script engine -> will issue a warning
  2711. }
  2712. }
  2713. script_set_constant( name.c_str(), pair.first, false, false );
  2714. }
  2715. TypesafeYamlDatabase::loadingFinished();
  2716. }
  2717. RandomOptionDatabase random_option_db;
  2718. /**
  2719. * Check if the given random option name exists.
  2720. * @param name: Random option name
  2721. * @return True on success or false on failure
  2722. */
  2723. bool RandomOptionDatabase::option_exists(std::string name) {
  2724. for (const auto &opt : random_option_db) {
  2725. if (opt.second->name.compare(name) == 0)
  2726. return true;
  2727. }
  2728. return false;
  2729. }
  2730. /**
  2731. * Return the constant value of the given random option.
  2732. * @param name: Random option name
  2733. * @param id: Random option ID
  2734. * @return True on success or false on failure
  2735. */
  2736. bool RandomOptionDatabase::option_get_id(std::string name, uint16 &id) {
  2737. for (const auto &opt : random_option_db) {
  2738. if (opt.second->name.compare(name) == 0) {
  2739. id = opt.first;
  2740. return true;
  2741. }
  2742. }
  2743. return false;
  2744. }
  2745. const std::string RandomOptionGroupDatabase::getDefaultLocation() {
  2746. return std::string(db_path) + "/item_randomopt_group.yml";
  2747. }
  2748. bool RandomOptionGroupDatabase::add_option(const ryml::NodeRef& node, std::shared_ptr<s_random_opt_group_entry> &entry) {
  2749. uint16 option_id;
  2750. if (this->nodeExists(node, "Option")) {
  2751. std::string opt_name;
  2752. if (!this->asString(node, "Option", opt_name))
  2753. return false;
  2754. if (!random_option_db.option_get_id(opt_name, option_id)) {
  2755. this->invalidWarning(node["Option"], "Invalid Random Option name %s given.\n", opt_name.c_str());
  2756. return false;
  2757. }
  2758. } else {
  2759. this->invalidWarning(node, "Missing Option node.\n");
  2760. return false;
  2761. }
  2762. entry = std::make_shared<s_random_opt_group_entry>();
  2763. entry->id = option_id;
  2764. if (this->nodeExists(node, "MinValue")) {
  2765. int16 value;
  2766. if (!this->asInt16(node, "MinValue", value))
  2767. return false;
  2768. entry->min_value = value;
  2769. } else {
  2770. entry->min_value = 0;
  2771. }
  2772. if (this->nodeExists(node, "MaxValue")) {
  2773. int16 value;
  2774. if (!this->asInt16(node, "MaxValue", value))
  2775. return false;
  2776. entry->max_value = value;
  2777. } else {
  2778. entry->max_value = 0;
  2779. }
  2780. if (entry->min_value > entry->max_value) {
  2781. this->invalidWarning(node["MaxValue"], "MinValue %d is greater than MaxValue %d, setting MaxValue to MinValue + 1.\n", entry->min_value, entry->max_value);
  2782. entry->max_value = entry->min_value + 1;
  2783. }
  2784. if (this->nodeExists(node, "Param")) {
  2785. int16 value;
  2786. if (!this->asInt16(node, "Param", value))
  2787. return false;
  2788. entry->param = static_cast<int8>(value);
  2789. } else {
  2790. entry->param = 0;
  2791. }
  2792. if (this->nodeExists(node, "Chance")) {
  2793. uint16 chance;
  2794. if (!this->asUInt16Rate(node, "Chance", chance))
  2795. return false;
  2796. entry->chance = chance;
  2797. } else {
  2798. entry->chance = 0;
  2799. }
  2800. return true;
  2801. }
  2802. void s_random_opt_group::apply( struct item& item ){
  2803. auto apply_sub = []( s_item_randomoption& item_option, const std::shared_ptr<s_random_opt_group_entry>& option ){
  2804. item_option.id = option->id;
  2805. item_option.value = rnd_value( option->min_value, option->max_value );
  2806. item_option.param = option->param;
  2807. };
  2808. // (Re)initialize all the options
  2809. for( size_t i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2810. item.option[i].id = 0;
  2811. item.option[i].value = 0;
  2812. item.option[i].param = 0;
  2813. };
  2814. // Apply Must options
  2815. for( size_t i = 0; i < this->slots.size(); i++ ){
  2816. // Try to apply an entry
  2817. for( size_t j = 0, max = this->slots[static_cast<uint16>(i)].size() * 3; j < max; j++ ){
  2818. std::shared_ptr<s_random_opt_group_entry> option = util::vector_random( this->slots[static_cast<uint16>(i)] );
  2819. if( rnd() % 10000 < option->chance ){
  2820. apply_sub( item.option[i], option );
  2821. break;
  2822. }
  2823. }
  2824. // If no entry was applied, assign one
  2825. if( item.option[i].id == 0 ){
  2826. std::shared_ptr<s_random_opt_group_entry> option = util::vector_random( this->slots[static_cast<uint16>(i)] );
  2827. // Apply an entry without checking the chance
  2828. apply_sub( item.option[i], option );
  2829. }
  2830. }
  2831. // Apply Random options (if available)
  2832. if( this->max_random > 0 ){
  2833. for( size_t i = 0; i < min( this->max_random, MAX_ITEM_RDM_OPT ); i++ ){
  2834. // If item already has an option in this slot, skip it
  2835. if( item.option[i].id > 0 ){
  2836. continue;
  2837. }
  2838. std::shared_ptr<s_random_opt_group_entry> option = util::vector_random( this->random_options );
  2839. if( rnd() % 10000 < option->chance ){
  2840. apply_sub( item.option[i], option );
  2841. }
  2842. }
  2843. }
  2844. }
  2845. /**
  2846. * Reads and parses an entry from the item_randomopt_group.
  2847. * @param node: YAML node containing the entry.
  2848. * @return count of successfully parsed rows
  2849. */
  2850. uint64 RandomOptionGroupDatabase::parseBodyNode(const ryml::NodeRef& node) {
  2851. uint16 id;
  2852. if (!this->asUInt16(node, "Id", id))
  2853. return 0;
  2854. std::shared_ptr<s_random_opt_group> randopt = this->find(id);
  2855. bool exists = randopt != nullptr;
  2856. if (!exists) {
  2857. if (!this->nodesExist(node, { "Group" }))
  2858. return 0;
  2859. randopt = std::make_shared<s_random_opt_group>();
  2860. randopt->id = id;
  2861. }
  2862. if (this->nodeExists(node, "Group")) {
  2863. std::string name;
  2864. if (!this->asString(node, "Group", name))
  2865. return 0;
  2866. if (randopt->name.compare(name) != 0 && random_option_group.option_exists(name)) {
  2867. this->invalidWarning(node["Group"], "Found duplicate random option group name for %s, skipping.\n", name.c_str());
  2868. return 0;
  2869. }
  2870. randopt->name = name;
  2871. }
  2872. if (this->nodeExists(node, "Slots")) {
  2873. const auto& slotsNode = node["Slots"];
  2874. for (const ryml::NodeRef& slotNode : slotsNode) {
  2875. if (randopt->slots.size() >= MAX_ITEM_RDM_OPT) {
  2876. this->invalidWarning(slotNode, "Reached maximum of %d Random Option group options. Skipping the remaining slots...\n", MAX_ITEM_RDM_OPT);
  2877. break;
  2878. }
  2879. uint16 slot;
  2880. if (!this->asUInt16(slotNode, "Slot", slot))
  2881. return 0;
  2882. if (slot < 1 || slot > MAX_ITEM_RDM_OPT) {
  2883. this->invalidWarning(slotNode["Slot"], "Invalid Random Opton Slot number %hu given, must be between 1~%d, skipping.\n", slot, MAX_ITEM_RDM_OPT);
  2884. return 0;
  2885. }
  2886. if (!this->nodeExists(slotNode, "Options")) {
  2887. this->invalidWarning(slotNode, "Random option slot does not contain Options node, skipping.\n");
  2888. return 0;
  2889. }
  2890. std::vector<std::shared_ptr<s_random_opt_group_entry>> entries;
  2891. const auto& optionsNode = slotNode["Options"];
  2892. for (const auto& optionNode : optionsNode) {
  2893. std::shared_ptr<s_random_opt_group_entry> entry;
  2894. if (!this->add_option(optionNode, entry))
  2895. return 0;
  2896. entries.push_back(entry);
  2897. }
  2898. randopt->slots[slot - 1] = entries;
  2899. }
  2900. }
  2901. if (this->nodeExists(node, "MaxRandom")) {
  2902. uint16 max;
  2903. if (!this->asUInt16(node, "MaxRandom", max))
  2904. return 0;
  2905. if (max > MAX_ITEM_RDM_OPT) {
  2906. this->invalidWarning(node["MaxRandom"], "Exceeds the maximum of %d Random Option group options, capping to MAX_ITEM_RDM_OPT.\n", MAX_ITEM_RDM_OPT);
  2907. max = MAX_ITEM_RDM_OPT;
  2908. }
  2909. randopt->max_random = max;
  2910. } else {
  2911. if (!exists)
  2912. randopt->max_random = 0;
  2913. }
  2914. if (this->nodeExists(node, "Random")) {
  2915. randopt->random_options.clear();
  2916. const auto& randomNode = node["Random"];
  2917. for (const auto& randomNode : randomNode) {
  2918. std::shared_ptr<s_random_opt_group_entry> entry;
  2919. if (!this->add_option(randomNode, entry))
  2920. return 0;
  2921. randopt->random_options.push_back(entry);
  2922. }
  2923. }
  2924. if (!exists)
  2925. this->put(id, randopt);
  2926. return 1;
  2927. }
  2928. RandomOptionGroupDatabase random_option_group;
  2929. /**
  2930. * Check if the given random option group name exists.
  2931. * @param name: Random option name
  2932. * @return True on success or false on failure
  2933. */
  2934. bool RandomOptionGroupDatabase::option_exists(std::string name) {
  2935. for (const auto &opt : random_option_group) {
  2936. if (opt.second->name.compare(name) == 0)
  2937. return true;
  2938. }
  2939. return false;
  2940. }
  2941. /**
  2942. * Return the constant value of the given random option group.
  2943. * @param name: Random option group name
  2944. * @param id: Random option group ID
  2945. * @return True on success or false on failure
  2946. */
  2947. bool RandomOptionGroupDatabase::option_get_id(std::string name, uint16 &id) {
  2948. for (const auto &opt : random_option_group) {
  2949. if (opt.second->name.compare(name) == 0) {
  2950. id = opt.first;
  2951. return true;
  2952. }
  2953. }
  2954. return false;
  2955. }
  2956. /**
  2957. * Read all item-related databases
  2958. */
  2959. static void itemdb_read(void) {
  2960. int i;
  2961. const char* dbsubpath[] = {
  2962. "",
  2963. "/" DBIMPORT,
  2964. };
  2965. if (db_use_sqldbs)
  2966. itemdb_read_sqldb();
  2967. else
  2968. item_db.load();
  2969. for(i=0; i<ARRAYLENGTH(dbsubpath); i++){
  2970. uint8 n1 = (uint8)(strlen(db_path)+strlen(dbsubpath[i])+1);
  2971. uint8 n2 = (uint8)(strlen(db_path)+strlen(DBPATH)+strlen(dbsubpath[i])+1);
  2972. char* dbsubpath1 = (char*)aMalloc(n1+1);
  2973. char* dbsubpath2 = (char*)aMalloc(n2+1);
  2974. if(i==0) {
  2975. safesnprintf(dbsubpath1,n1,"%s%s",db_path,dbsubpath[i]);
  2976. safesnprintf(dbsubpath2,n2,"%s/%s%s",db_path,DBPATH,dbsubpath[i]);
  2977. }
  2978. else {
  2979. safesnprintf(dbsubpath1,n1,"%s%s",db_path,dbsubpath[i]);
  2980. safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[i]);
  2981. }
  2982. sv_readdb(dbsubpath2, "item_noequip.txt", ',', 2, 2, -1, &itemdb_read_noequip, i > 0);
  2983. aFree(dbsubpath1);
  2984. aFree(dbsubpath2);
  2985. }
  2986. random_option_db.load();
  2987. random_option_group.load();
  2988. itemdb_group.load();
  2989. itemdb_combo.load();
  2990. laphine_synthesis_db.load();
  2991. laphine_upgrade_db.load();
  2992. item_reform_db.load();
  2993. if (battle_config.feature_roulette)
  2994. itemdb_parse_roulette_db();
  2995. }
  2996. /*==========================================
  2997. * Initialize / Finalize
  2998. *------------------------------------------*/
  2999. bool item_data::isStackable()
  3000. {
  3001. switch (this->type) {
  3002. case IT_WEAPON:
  3003. case IT_ARMOR:
  3004. case IT_PETEGG:
  3005. case IT_PETARMOR:
  3006. case IT_SHADOWGEAR:
  3007. return false;
  3008. }
  3009. return true;
  3010. }
  3011. int item_data::inventorySlotNeeded(int quantity)
  3012. {
  3013. return (this->flag.guid || !this->isStackable()) ? quantity : 1;
  3014. }
  3015. /**
  3016. * Reload Item DB
  3017. */
  3018. void itemdb_reload(void) {
  3019. struct s_mapiterator* iter;
  3020. struct map_session_data* sd;
  3021. do_final_itemdb();
  3022. // read new data
  3023. itemdb_read();
  3024. cashshop_reloaddb();
  3025. mob_reload_itemmob_data();
  3026. // readjust itemdb pointer cache for each player
  3027. iter = mapit_geteachpc();
  3028. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) ) {
  3029. memset(sd->item_delay, 0, sizeof(sd->item_delay)); // reset item delays
  3030. sd->combos.clear(); // clear combo bonuses
  3031. pc_setinventorydata(sd);
  3032. pc_check_available_item(sd, ITMCHK_ALL); // Check for invalid(ated) items.
  3033. pc_load_combo(sd); // Check to see if new combos are available
  3034. status_calc_pc(sd, SCO_FORCE); //
  3035. }
  3036. mapit_free(iter);
  3037. }
  3038. /**
  3039. * Finalizing Item DB
  3040. */
  3041. void do_final_itemdb(void) {
  3042. item_db.clear();
  3043. itemdb_combo.clear();
  3044. itemdb_group.clear();
  3045. random_option_db.clear();
  3046. random_option_group.clear();
  3047. laphine_synthesis_db.clear();
  3048. laphine_upgrade_db.clear();
  3049. item_reform_db.clear();
  3050. if (battle_config.feature_roulette)
  3051. itemdb_roulette_free();
  3052. }
  3053. /**
  3054. * Initializing Item DB
  3055. */
  3056. void do_init_itemdb(void) {
  3057. itemdb_read();
  3058. }