script.c 335 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. //#define DEBUG_FUNCIN
  4. //#define DEBUG_DISP
  5. //#define DEBUG_RUN
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <math.h>
  11. #include <limits.h>
  12. #ifndef _WIN32
  13. #include <sys/time.h>
  14. #endif
  15. #include <time.h>
  16. #include <setjmp.h>
  17. #include "../common/socket.h"
  18. #include "../common/timer.h"
  19. #include "../common/malloc.h"
  20. #include "../common/lock.h"
  21. #include "../common/nullpo.h"
  22. #include "../common/showmsg.h"
  23. #include "../common/strlib.h"
  24. #include "map.h"
  25. #include "clif.h"
  26. #include "chrif.h"
  27. #include "itemdb.h"
  28. #include "pc.h"
  29. #include "status.h"
  30. #include "script.h"
  31. #include "storage.h"
  32. #include "mob.h"
  33. #include "npc.h"
  34. #include "pet.h"
  35. #include "mercenary.h" //[orn]
  36. #include "intif.h"
  37. #include "skill.h"
  38. #include "chat.h"
  39. #include "battle.h"
  40. #include "party.h"
  41. #include "guild.h"
  42. #include "atcommand.h"
  43. #include "charcommand.h"
  44. #include "log.h"
  45. #include "unit.h"
  46. #include "irc.h"
  47. #include "pet.h"
  48. #define FETCH(n, t) \
  49. if(st->end>st->start+(n)) \
  50. (t)=conv_num(st,&(st->stack->stack_data[st->start+(n)]));
  51. #define SCRIPT_BLOCK_SIZE 512
  52. enum { LABEL_NEXTLINE=1,LABEL_START };
  53. static unsigned char * script_buf = NULL;
  54. static int script_pos,script_size;
  55. static char *str_buf;
  56. static int str_pos,str_size;
  57. static struct str_data_struct {
  58. int type;
  59. int str;
  60. int backpatch;
  61. int label;
  62. int (*func)(struct script_state *st);
  63. int val;
  64. int next;
  65. } *str_data = NULL;
  66. int str_num=LABEL_START,str_data_size;
  67. int str_hash[16];
  68. static struct dbt *mapreg_db=NULL;
  69. static struct dbt *mapregstr_db=NULL;
  70. static int mapreg_dirty=-1;
  71. char mapreg_txt[256]="save/mapreg.txt";
  72. #define MAPREG_AUTOSAVE_INTERVAL (300*1000)
  73. static struct dbt *scriptlabel_db=NULL;
  74. static struct dbt *userfunc_db=NULL;
  75. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  76. struct dbt* script_get_userfunc_db(){ return userfunc_db; }
  77. static char pos[11][100] = {"頭","体","左手","右手","ローブ","靴","アクセサリー1","アクセサリー2","頭2","頭3","装着していない"};
  78. struct Script_Config script_config;
  79. static int parse_cmd;
  80. static jmp_buf error_jump;
  81. static char* error_msg;
  82. static char* error_pos;
  83. // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
  84. // [Eoe / jA 1080, 1081, 1094, 1164]
  85. enum { TYPE_NULL = 0 , TYPE_IF , TYPE_SWITCH , TYPE_WHILE , TYPE_FOR , TYPE_DO , TYPE_USERFUNC};
  86. static struct {
  87. struct {
  88. int type;
  89. int index;
  90. int count;
  91. int flag;
  92. } curly[256]; // 右カッコの情報
  93. int curly_count; // 右カッコの数
  94. int index; // スクリプト内で使用した構文の数
  95. } syntax;
  96. unsigned char* parse_curly_close(unsigned char *p);
  97. unsigned char* parse_syntax_close(unsigned char *p);
  98. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag);
  99. unsigned char* parse_syntax(unsigned char *p);
  100. static int parse_syntax_for_flag = 0;
  101. extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
  102. int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
  103. int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
  104. int potion_target=0;
  105. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  106. // [zBuffer] SQL Mapreg Saving/Loading Database Declaration
  107. char mapregsql_db[32] = "mapreg";
  108. char mapregsql_db_varname[32] = "varname";
  109. char mapregsql_db_index[32] = "index";
  110. char mapregsql_db_value[32] = "value";
  111. char tmp_sql[65535];
  112. // --------------------------------------------------------
  113. #endif
  114. int get_com(unsigned char *script,int *pos);
  115. int get_num(unsigned char *script,int *pos);
  116. extern struct script_function {
  117. int (*func)(struct script_state *st);
  118. char *name;
  119. char *arg;
  120. } buildin_func[];
  121. static struct linkdb_node *sleep_db;
  122. #define not_server_variable(prefix) (prefix != '$' && prefix != '.')
  123. /*==========================================
  124. * ローカルプロトタイプ宣言 (必要な物のみ)
  125. *------------------------------------------
  126. */
  127. unsigned char* parse_subexpr(unsigned char *,int);
  128. void push_val(struct script_stack *stack,int type,int val);
  129. int run_func(struct script_state *st);
  130. int mapreg_setreg(int num,int val);
  131. int mapreg_setregstr(int num,const char *str);
  132. static void disp_error_message(const char *mes,unsigned char *pos);
  133. enum {
  134. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  135. C_NAME,C_EOL, C_RETINFO,
  136. C_USERFUNC, C_USERFUNC_POS, // user defined functions
  137. C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  138. C_XOR,C_OR,C_AND,C_ADD,C_SUB,C_MUL,C_DIV,C_MOD,C_NEG,C_LNOT,C_NOT,C_R_SHIFT,C_L_SHIFT
  139. };
  140. enum {
  141. MF_NOMEMO,
  142. MF_NOTELEPORT,
  143. MF_NOSAVE,
  144. MF_NOBRANCH,
  145. MF_NOPENALTY,
  146. MF_NOZENYPENALTY,
  147. MF_PVP,
  148. MF_PVP_NOPARTY,
  149. MF_PVP_NOGUILD,
  150. MF_GVG,
  151. MF_GVG_NOPARTY,
  152. MF_NOTRADE,
  153. MF_NOSKILL,
  154. MF_NOWARP,
  155. MF_FREE,
  156. MF_NOICEWALL,
  157. MF_SNOW,
  158. MF_FOG,
  159. MF_SAKURA,
  160. MF_LEAVES,
  161. MF_RAIN,
  162. MF_INDOORS,
  163. MF_NOGO,
  164. MF_CLOUDS,
  165. MF_CLOUDS2,
  166. MF_FIREWORKS,
  167. MF_GVG_CASTLE,
  168. MF_GVG_DUNGEON,
  169. MF_NIGHTENABLED,
  170. MF_NOBASEEXP,
  171. MF_NOJOBEXP,
  172. MF_NOMOBLOOT,
  173. MF_NOMVPLOOT,
  174. MF_NORETURN,
  175. MF_NOWARPTO,
  176. MF_NIGHTMAREDROP,
  177. MF_RESTRICTED,
  178. MF_NOCOMMAND,
  179. MF_NODROP,
  180. MF_JEXP,
  181. MF_BEXP,
  182. MF_NOVENDING,
  183. MF_LOADEVENT,
  184. MF_NOCHAT
  185. };
  186. //Reports on the console the src of an script error.
  187. static void report_src(struct script_state *st) {
  188. struct block_list *bl;
  189. if (!st->oid) return; //Can't report source.
  190. bl = map_id2bl(st->oid);
  191. if (!bl) return;
  192. switch (bl->type) {
  193. case BL_NPC:
  194. if (bl->m >=0)
  195. ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
  196. else
  197. ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
  198. break;
  199. default:
  200. if (bl->m >=0)
  201. ShowDebug("Source (Non-NPC): type %d at %s (%d,%d)\n", bl->type, map[bl->m].name, bl->x, bl->y);
  202. else
  203. ShowDebug("Source (Non-NPC): type %d (invisible/not on a map)\n", bl->type);
  204. break;
  205. }
  206. }
  207. static void check_event(struct script_state *st, unsigned char *event){
  208. if(event != NULL && event[0] != '\0' && !strstr(event,"::")){
  209. ShowError("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n",event);
  210. report_src(st);
  211. }
  212. return;
  213. }
  214. /*==========================================
  215. * 文字列のハッシュを計算
  216. *------------------------------------------
  217. */
  218. static int calc_hash(const unsigned char *p)
  219. {
  220. int h=0;
  221. while(*p){
  222. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  223. h+=*p++;
  224. }
  225. return h&15;
  226. }
  227. /*==========================================
  228. * str_dataの中に名前があるか検索する
  229. *------------------------------------------
  230. */
  231. // 既存のであれば番号、無ければ-1
  232. static int search_str(const unsigned char *p)
  233. {
  234. int i;
  235. i=str_hash[calc_hash(p)];
  236. while(i){
  237. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  238. return i;
  239. }
  240. i=str_data[i].next;
  241. }
  242. return -1;
  243. }
  244. /*==========================================
  245. * str_dataに名前を登録
  246. *------------------------------------------
  247. */
  248. // 既存のであれば番号、無ければ登録して新規番号
  249. int add_str(const unsigned char *p)
  250. {
  251. int i;
  252. char *lowcase;
  253. lowcase=aStrdup((char *) p);
  254. for(i=0;lowcase[i];i++)
  255. lowcase[i]=tolower(lowcase[i]);
  256. if((i=search_str((unsigned char *) lowcase))>=0){
  257. aFree(lowcase);
  258. return i;
  259. }
  260. aFree(lowcase);
  261. i=calc_hash(p);
  262. if(str_hash[i]==0){
  263. str_hash[i]=str_num;
  264. } else {
  265. i=str_hash[i];
  266. for(;;){
  267. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  268. return i;
  269. }
  270. if(str_data[i].next==0)
  271. break;
  272. i=str_data[i].next;
  273. }
  274. str_data[i].next=str_num;
  275. }
  276. if(str_num>=str_data_size){
  277. str_data_size+=128;
  278. str_data=aRealloc(str_data,sizeof(str_data[0])*str_data_size);
  279. memset(str_data + (str_data_size - 128), '\0', 128);
  280. }
  281. while(str_pos+(int)strlen((char *) p)+1>=str_size){
  282. str_size+=256;
  283. str_buf=(char *)aRealloc(str_buf,str_size);
  284. memset(str_buf + (str_size - 256), '\0', 256);
  285. }
  286. strcpy(str_buf+str_pos, (char *) p);
  287. str_data[str_num].type=C_NOP;
  288. str_data[str_num].str=str_pos;
  289. str_data[str_num].next=0;
  290. str_data[str_num].func=NULL;
  291. str_data[str_num].backpatch=-1;
  292. str_data[str_num].label=-1;
  293. str_pos+=(int)strlen( (char *) p)+1;
  294. return str_num++;
  295. }
  296. /*==========================================
  297. * スクリプトバッファサイズの確認と拡張
  298. *------------------------------------------
  299. */
  300. static void check_script_buf(int size)
  301. {
  302. if(script_pos+size>=script_size){
  303. script_size+=SCRIPT_BLOCK_SIZE;
  304. script_buf=(unsigned char *)aRealloc(script_buf,script_size);
  305. memset(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  306. SCRIPT_BLOCK_SIZE);
  307. }
  308. }
  309. /*==========================================
  310. * スクリプトバッファに1バイト書き込む
  311. *------------------------------------------
  312. */
  313. #define add_scriptb(a) if( script_pos+1>=script_size ) check_script_buf(1); script_buf[script_pos++]=(a);
  314. #if 0
  315. static void add_scriptb(int a)
  316. {
  317. check_script_buf(1);
  318. script_buf[script_pos++]=a;
  319. }
  320. #endif
  321. /*==========================================
  322. * スクリプトバッファにデータタイプを書き込む
  323. *------------------------------------------
  324. */
  325. static void add_scriptc(int a)
  326. {
  327. while(a>=0x40){
  328. add_scriptb((a&0x3f)|0x40);
  329. a=(a-0x40)>>6;
  330. }
  331. add_scriptb(a&0x3f);
  332. }
  333. /*==========================================
  334. * スクリプトバッファに整数を書き込む
  335. *------------------------------------------
  336. */
  337. static void add_scripti(int a)
  338. {
  339. while(a>=0x40){
  340. add_scriptb(a|0xc0);
  341. a=(a-0x40)>>6;
  342. }
  343. add_scriptb(a|0x80);
  344. }
  345. /*==========================================
  346. * スクリプトバッファにラベル/変数/関数を書き込む
  347. *------------------------------------------
  348. */
  349. // 最大16Mまで
  350. static void add_scriptl(int l)
  351. {
  352. int backpatch = str_data[l].backpatch;
  353. switch(str_data[l].type){
  354. case C_POS:
  355. case C_USERFUNC_POS:
  356. add_scriptc(C_POS);
  357. add_scriptb(str_data[l].label);
  358. add_scriptb(str_data[l].label>>8);
  359. add_scriptb(str_data[l].label>>16);
  360. break;
  361. case C_NOP:
  362. case C_USERFUNC:
  363. // ラベルの可能性があるのでbackpatch用データ埋め込み
  364. add_scriptc(C_NAME);
  365. str_data[l].backpatch=script_pos;
  366. add_scriptb(backpatch);
  367. add_scriptb(backpatch>>8);
  368. add_scriptb(backpatch>>16);
  369. break;
  370. case C_INT:
  371. add_scripti(str_data[l].val);
  372. break;
  373. default:
  374. // もう他の用途と確定してるので数字をそのまま
  375. add_scriptc(C_NAME);
  376. add_scriptb(l);
  377. add_scriptb(l>>8);
  378. add_scriptb(l>>16);
  379. break;
  380. }
  381. }
  382. /*==========================================
  383. * ラベルを解決する
  384. *------------------------------------------
  385. */
  386. void set_label(int l,int pos, unsigned char *script_pos)
  387. {
  388. int i,next;
  389. if(str_data[l].type==C_INT || str_data[l].type==C_PARAM)
  390. { //Prevent overwriting constants values and parameters [Skotlex]
  391. disp_error_message("invalid label name",script_pos);
  392. return;
  393. }
  394. if(str_data[l].label!=-1){
  395. disp_error_message("dup label ",script_pos);
  396. return;
  397. }
  398. str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  399. str_data[l].label=pos;
  400. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  401. next=(*(int*)(script_buf+i)) & 0x00ffffff;
  402. script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  403. script_buf[i]=pos;
  404. script_buf[i+1]=pos>>8;
  405. script_buf[i+2]=pos>>16;
  406. i=next;
  407. }
  408. }
  409. /*==========================================
  410. * スペース/コメント読み飛ばし
  411. *------------------------------------------
  412. */
  413. static unsigned char *skip_space(unsigned char *p)
  414. {
  415. while(1){
  416. while(isspace(*p))
  417. p++;
  418. if(p[0]=='/' && p[1]=='/'){
  419. while(*p && *p!='\n')
  420. p++;
  421. } else if(p[0]=='/' && p[1]=='*'){
  422. p++;
  423. while(*p && (p[-1]!='*' || p[0]!='/'))
  424. p++;
  425. if(*p) p++;
  426. } else
  427. break;
  428. }
  429. return p;
  430. }
  431. /*==========================================
  432. * 1単語スキップ
  433. *------------------------------------------
  434. */
  435. static unsigned char *skip_word(unsigned char *p)
  436. {
  437. // prefix
  438. if(*p=='.') p++;
  439. if(*p=='$') p++; // MAP鯖内共有変数用
  440. if(*p=='@') p++; // 一時的変数用(like weiss)
  441. if(*p=='#') p++; // account変数用
  442. if(*p=='#') p++; // ワールドaccount変数用
  443. while(isalnum(*p)||*p=='_'|| *p>=0x81) {
  444. if(*p>=0x81 && p[1]){
  445. p+=2;
  446. } else
  447. p++;
  448. }
  449. // postfix
  450. if(*p=='$') p++; // 文字列変数
  451. return p;
  452. }
  453. /*==========================================
  454. * エラーメッセージ出力
  455. *------------------------------------------
  456. */
  457. static void disp_error_message(const char *mes,unsigned char *pos)
  458. {
  459. error_msg = aStrdup(mes);
  460. error_pos = pos;
  461. longjmp( error_jump, 1 );
  462. }
  463. /*==========================================
  464. * 項の解析
  465. *------------------------------------------
  466. */
  467. unsigned char* parse_simpleexpr(unsigned char *p)
  468. {
  469. int i;
  470. p=skip_space(p);
  471. #ifdef DEBUG_FUNCIN
  472. if(battle_config.etc_log)
  473. ShowDebug("parse_simpleexpr %s\n",p);
  474. #endif
  475. if(*p==';' || *p==','){
  476. disp_error_message("unexpected expr end",p);
  477. exit(1);
  478. }
  479. if(*p=='('){
  480. p=parse_subexpr(p+1,-1);
  481. p=skip_space(p);
  482. if((*p++)!=')'){
  483. disp_error_message("unmatch ')'",p);
  484. exit(1);
  485. }
  486. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  487. char *np;
  488. i=strtoul((char *) p,&np,0);
  489. add_scripti(i);
  490. p=(unsigned char *) np;
  491. } else if(*p=='"'){
  492. add_scriptc(C_STR);
  493. p++;
  494. while(*p && *p!='"'){
  495. if(p[-1]<=0x7e && *p=='\\')
  496. p++;
  497. else if(*p=='\n'){
  498. disp_error_message("unexpected newline @ string",p);
  499. exit(1);
  500. }
  501. add_scriptb(*p++);
  502. }
  503. if(!*p){
  504. disp_error_message("unexpected eof @ string",p);
  505. exit(1);
  506. }
  507. add_scriptb(0);
  508. p++; //'"'
  509. } else {
  510. int c,l;
  511. char *p2;
  512. // label , register , function etc
  513. //From what I read, jA figured a better way to handle empty parenthesis '()'
  514. if(skip_word(p)==p/* && !(*p==')' && p[-1]=='(')*/){
  515. disp_error_message("unexpected character",p);
  516. exit(1);
  517. }
  518. p2=(char *) skip_word(p);
  519. c=*p2; *p2=0; // 名前をadd_strする
  520. l=add_str(p);
  521. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  522. *p2=c;
  523. p=(unsigned char *) p2;
  524. if(str_data[l].type!=C_FUNC && c=='['){
  525. // array(name[i] => getelementofarray(name,i) )
  526. add_scriptl(search_str((unsigned char *) "getelementofarray"));
  527. add_scriptc(C_ARG);
  528. add_scriptl(l);
  529. p=parse_subexpr(p+1,-1);
  530. p=skip_space(p);
  531. if((*p++)!=']'){
  532. disp_error_message("unmatch ']'",p);
  533. exit(1);
  534. }
  535. add_scriptc(C_FUNC);
  536. } else if(str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS) {
  537. add_scriptl(search_str((unsigned char*)"callsub"));
  538. add_scriptc(C_ARG);
  539. add_scriptl(l);
  540. }else
  541. add_scriptl(l);
  542. }
  543. #ifdef DEBUG_FUNCIN
  544. if(battle_config.etc_log)
  545. ShowDebug("parse_simpleexpr end %s\n",p);
  546. #endif
  547. return p;
  548. }
  549. /*==========================================
  550. * 式の解析
  551. *------------------------------------------
  552. */
  553. unsigned char* parse_subexpr(unsigned char *p,int limit)
  554. {
  555. int op,opl,len;
  556. char *tmpp;
  557. #ifdef DEBUG_FUNCIN
  558. if(battle_config.etc_log)
  559. ShowDebug("parse_subexpr %s\n",p);
  560. #endif
  561. p=skip_space(p);
  562. if(*p=='-'){
  563. tmpp=(char *) skip_space((unsigned char *) (p+1));
  564. if(*tmpp==';' || *tmpp==','){
  565. add_scriptl(LABEL_NEXTLINE);
  566. p++;
  567. return p;
  568. }
  569. }
  570. tmpp=(char *) p;
  571. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  572. p=parse_subexpr(p+1,8);
  573. add_scriptc(op);
  574. } else
  575. p=parse_simpleexpr(p);
  576. p=skip_space(p);
  577. while((
  578. (op=C_ADD,opl=6,len=1,*p=='+') ||
  579. (op=C_SUB,opl=6,len=1,*p=='-') ||
  580. (op=C_MUL,opl=7,len=1,*p=='*') ||
  581. (op=C_DIV,opl=7,len=1,*p=='/') ||
  582. (op=C_MOD,opl=7,len=1,*p=='%') ||
  583. (op=C_FUNC,opl=9,len=1,*p=='(') ||
  584. (op=C_LAND,opl=1,len=2,*p=='&' && p[1]=='&') ||
  585. (op=C_AND,opl=5,len=1,*p=='&') ||
  586. (op=C_LOR,opl=0,len=2,*p=='|' && p[1]=='|') ||
  587. (op=C_OR,opl=4,len=1,*p=='|') ||
  588. (op=C_XOR,opl=3,len=1,*p=='^') ||
  589. (op=C_EQ,opl=2,len=2,*p=='=' && p[1]=='=') ||
  590. (op=C_NE,opl=2,len=2,*p=='!' && p[1]=='=') ||
  591. (op=C_R_SHIFT,opl=5,len=2,*p=='>' && p[1]=='>') ||
  592. (op=C_GE,opl=2,len=2,*p=='>' && p[1]=='=') ||
  593. (op=C_GT,opl=2,len=1,*p=='>') ||
  594. (op=C_L_SHIFT,opl=5,len=2,*p=='<' && p[1]=='<') ||
  595. (op=C_LE,opl=2,len=2,*p=='<' && p[1]=='=') ||
  596. (op=C_LT,opl=2,len=1,*p=='<')) && opl>limit){
  597. p+=len;
  598. if(op==C_FUNC){
  599. int i=0,func=parse_cmd;
  600. const char *plist[128];
  601. if(str_data[parse_cmd].type == C_FUNC){
  602. // 通常の関数
  603. add_scriptc(C_ARG);
  604. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  605. // ユーザー定義関数呼び出し
  606. parse_cmd = search_str((unsigned char*)"callsub");
  607. i++;
  608. } else {
  609. disp_error_message(
  610. "expect command, missing function name or calling undeclared function",(unsigned char *) tmpp
  611. );
  612. exit(0);
  613. }
  614. func=parse_cmd;
  615. while(*p && *p!=')' && i<128) {
  616. plist[i]=(char *) p;
  617. p=parse_subexpr(p,-1);
  618. p=skip_space(p);
  619. if(*p==',') p++;
  620. else if(*p!=')' && script_config.warn_func_no_comma){
  621. disp_error_message("expect ',' or ')' at func params",p);
  622. }
  623. p=skip_space(p);
  624. i++;
  625. };
  626. plist[i]=(char *) p;
  627. if(*(p++)!=')'){
  628. disp_error_message("func request '(' ')'",p);
  629. exit(1);
  630. }
  631. if( str_data[func].type==C_FUNC && script_config.warn_func_mismatch_paramnum){
  632. const char *arg = buildin_func[str_data[func].val].arg;
  633. int j = 0;
  634. for (; arg[j]; j++) if (arg[j] == '*') break;
  635. if (!(i <= 1 && j == 0) && ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j))) {
  636. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  637. }
  638. }
  639. } else {
  640. p=parse_subexpr(p,opl);
  641. }
  642. add_scriptc(op);
  643. p=skip_space(p);
  644. }
  645. #ifdef DEBUG_FUNCIN
  646. if(battle_config.etc_log)
  647. ShowDebug("parse_subexpr end %s\n",p);
  648. #endif
  649. return p; /* return first untreated operator */
  650. }
  651. /*==========================================
  652. * 式の評価
  653. *------------------------------------------
  654. */
  655. unsigned char* parse_expr(unsigned char *p)
  656. {
  657. #ifdef DEBUG_FUNCIN
  658. if(battle_config.etc_log)
  659. ShowDebug("parse_expr %s\n",p);
  660. #endif
  661. switch(*p){
  662. case ')': case ';': case ':': case '[': case ']':
  663. case '}':
  664. disp_error_message("unexpected char",p);
  665. exit(1);
  666. }
  667. if(*p == '(') {
  668. unsigned char *p2 = skip_space(p + 1);
  669. if(*p2 == ')') {
  670. return p2 + 1;
  671. }
  672. }
  673. p=parse_subexpr(p,-1);
  674. #ifdef DEBUG_FUNCIN
  675. if(battle_config.etc_log)
  676. ShowDebug("parse_expr end %s\n",p);
  677. #endif
  678. return p;
  679. }
  680. /*==========================================
  681. * 行の解析
  682. *------------------------------------------
  683. */
  684. unsigned char* parse_line(unsigned char *p)
  685. {
  686. int i=0,cmd;
  687. const char *plist[128];
  688. unsigned char *p2;
  689. char end;
  690. p=skip_space(p);
  691. if(*p==';') {
  692. // if(); for(); while(); のために閉じ判定
  693. p = parse_syntax_close(p);
  694. return p+1;
  695. }
  696. if(*p==')' && parse_syntax_for_flag)
  697. return p+1;
  698. p = skip_space(p);
  699. if(p[0] == '{') {
  700. syntax.curly[syntax.curly_count].type = TYPE_NULL;
  701. syntax.curly[syntax.curly_count].count = -1;
  702. syntax.curly[syntax.curly_count].index = -1;
  703. syntax.curly_count++;
  704. return p + 1;
  705. } else if(p[0] == '}') {
  706. return parse_curly_close(p);
  707. }
  708. // 構文関連の処理
  709. p2 = parse_syntax(p);
  710. if(p2 != NULL) { return p2; }
  711. // 最初は関数名
  712. p2=(char *) p;
  713. p=parse_simpleexpr(p);
  714. p=skip_space(p);
  715. if(str_data[parse_cmd].type == C_FUNC){
  716. // 通常の関数
  717. add_scriptc(C_ARG);
  718. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  719. // ユーザー定義関数呼び出し
  720. parse_cmd = search_str((unsigned char*)"callsub");
  721. i++;
  722. } else {
  723. disp_error_message(
  724. "expect command, missing function name or calling undeclared function", (unsigned char *)p2
  725. );
  726. // exit(0);
  727. }
  728. cmd=parse_cmd;
  729. if(parse_syntax_for_flag) {
  730. end = ')';
  731. } else {
  732. end = ';';
  733. }
  734. while(p && *p && *p != end && i<128){
  735. plist[i]=(char *) p;
  736. p=parse_expr(p);
  737. p=skip_space(p);
  738. // 引数区切りの,処理
  739. if(*p==',') p++;
  740. else if(*p!=end && script_config.warn_cmd_no_comma && 0 <= i ){
  741. if(parse_syntax_for_flag) {
  742. disp_error_message("expect ',' or ')' at cmd params",p);
  743. } else {
  744. disp_error_message("expect ',' or ';' at cmd params",p);
  745. }
  746. }
  747. p=skip_space(p);
  748. i++;
  749. }
  750. plist[i]=(char *) p;
  751. if(!p || *(p++)!=end){
  752. if(parse_syntax_for_flag) {
  753. disp_error_message("need ')'",p);
  754. } else {
  755. disp_error_message("need ';'",p);
  756. }
  757. exit(1);
  758. }
  759. add_scriptc(C_FUNC);
  760. // if, for , while の閉じ判定
  761. p = parse_syntax_close(p);
  762. if( str_data[cmd].type==C_FUNC && script_config.warn_cmd_mismatch_paramnum){
  763. const char *arg=buildin_func[str_data[cmd].val].arg;
  764. int j=0;
  765. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  766. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  767. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  768. }
  769. }
  770. return p;
  771. }
  772. // { ... } の閉じ処理
  773. unsigned char* parse_curly_close(unsigned char *p) {
  774. if(syntax.curly_count <= 0) {
  775. disp_error_message("unexpected string",p);
  776. return p + 1;
  777. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
  778. syntax.curly_count--;
  779. // if, for , while の閉じ判定
  780. p = parse_syntax_close(p + 1);
  781. return p;
  782. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
  783. // switch() 閉じ判定
  784. int pos = syntax.curly_count-1;
  785. unsigned char label[256];
  786. int l;
  787. // 一時変数を消す
  788. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  789. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  790. parse_line(label);
  791. syntax.curly_count--;
  792. // 無条件で終了ポインタに移動
  793. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  794. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  795. parse_line(label);
  796. syntax.curly_count--;
  797. // 現在地のラベルを付ける
  798. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  799. l=add_str(label);
  800. set_label(l,script_pos, p);
  801. if(syntax.curly[pos].flag) {
  802. // default が存在する
  803. sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
  804. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  805. parse_line(label);
  806. syntax.curly_count--;
  807. }
  808. // 終了ラベルを付ける
  809. sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
  810. l=add_str(label);
  811. set_label(l,script_pos, p);
  812. syntax.curly_count--;
  813. return p+1;
  814. } else {
  815. disp_error_message("unexpected string",p);
  816. return p + 1;
  817. }
  818. }
  819. // 構文関連の処理
  820. // break, case, continue, default, do, for, function,
  821. // if, switch, while をこの内部で処理します。
  822. unsigned char* parse_syntax(unsigned char *p) {
  823. switch(p[0]) {
  824. case 'b':
  825. if(!strncmp(p,"break",5) && !isalpha(*(p + 5))) {
  826. // break の処理
  827. char label[256];
  828. int pos = syntax.curly_count - 1;
  829. while(pos >= 0) {
  830. if(syntax.curly[pos].type == TYPE_DO) {
  831. sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
  832. break;
  833. } else if(syntax.curly[pos].type == TYPE_FOR) {
  834. sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
  835. break;
  836. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  837. sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
  838. break;
  839. } else if(syntax.curly[pos].type == TYPE_SWITCH) {
  840. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  841. break;
  842. }
  843. pos--;
  844. }
  845. if(pos < 0) {
  846. disp_error_message("unexpected 'break'",p);
  847. } else {
  848. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  849. parse_line(label);
  850. syntax.curly_count--;
  851. }
  852. p = skip_word(p);
  853. p++;
  854. // if, for , while の閉じ判定
  855. p = parse_syntax_close(p + 1);
  856. return p;
  857. }
  858. break;
  859. case 'c':
  860. if(!strncmp(p,"case",4) && !isalpha(*(p + 4))) {
  861. // case の処理
  862. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  863. disp_error_message("unexpected 'case' ",p);
  864. return p+1;
  865. } else {
  866. char *p2;
  867. char label[256];
  868. int l;
  869. int pos = syntax.curly_count-1;
  870. if(syntax.curly[pos].count != 1) {
  871. // FALLTHRU 用のジャンプ
  872. sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
  873. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  874. parse_line(label);
  875. syntax.curly_count--;
  876. // 現在地のラベルを付ける
  877. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  878. l=add_str(label);
  879. set_label(l,script_pos, p);
  880. }
  881. // switch 判定文
  882. p = skip_word(p);
  883. p = skip_space(p);
  884. p2 = p;
  885. p = skip_word(p);
  886. p = skip_space(p);
  887. if(*p != ':') {
  888. disp_error_message("expect ':'",p);
  889. exit(1);
  890. }
  891. *p = 0;
  892. sprintf(label,"if(%s != $@__SW%x_VAL) goto __SW%x_%x;",
  893. p2,syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
  894. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  895. *p = ':';
  896. // 2回parse しないとダメ
  897. p2 = parse_line(label);
  898. parse_line(p2);
  899. syntax.curly_count--;
  900. if(syntax.curly[pos].count != 1) {
  901. // FALLTHRU 終了後のラベル
  902. sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
  903. l=add_str(label);
  904. set_label(l,script_pos,p);
  905. }
  906. // 一時変数を消す
  907. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  908. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  909. parse_line(label);
  910. syntax.curly_count--;
  911. syntax.curly[pos].count++;
  912. }
  913. return p + 1;
  914. } else if(!strncmp(p,"continue",8) && !isalpha(*(p + 8))) {
  915. // continue の処理
  916. char label[256];
  917. int pos = syntax.curly_count - 1;
  918. while(pos >= 0) {
  919. if(syntax.curly[pos].type == TYPE_DO) {
  920. sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
  921. syntax.curly[pos].flag = 1; // continue 用のリンク張るフラグ
  922. break;
  923. } else if(syntax.curly[pos].type == TYPE_FOR) {
  924. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  925. break;
  926. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  927. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  928. break;
  929. }
  930. pos--;
  931. }
  932. if(pos < 0) {
  933. disp_error_message("unexpected 'continue'",p);
  934. } else {
  935. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  936. parse_line(label);
  937. syntax.curly_count--;
  938. }
  939. p = skip_word(p);
  940. p++;
  941. // if, for , while の閉じ判定
  942. p = parse_syntax_close(p + 1);
  943. return p;
  944. }
  945. break;
  946. case 'd':
  947. if(!strncmp(p,"default",7) && !isalpha(*(p + 7))) {
  948. // switch - default の処理
  949. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  950. disp_error_message("unexpected 'default'",p);
  951. return p+1;
  952. } else if(syntax.curly[syntax.curly_count - 1].flag) {
  953. disp_error_message("dup 'default'",p);
  954. return p+1;
  955. } else {
  956. char label[256];
  957. int l;
  958. int pos = syntax.curly_count-1;
  959. // 現在地のラベルを付ける
  960. p = skip_word(p);
  961. p = skip_space(p);
  962. if(*p != ':') {
  963. disp_error_message("need ':'",p);
  964. }
  965. p++;
  966. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  967. l=add_str(label);
  968. set_label(l,script_pos,p);
  969. // 無条件で次のリンクに飛ばす
  970. sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
  971. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  972. parse_line(label);
  973. syntax.curly_count--;
  974. // default のラベルを付ける
  975. sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
  976. l=add_str(label);
  977. set_label(l,script_pos,p);
  978. syntax.curly[syntax.curly_count - 1].flag = 1;
  979. syntax.curly[pos].count++;
  980. p = skip_word(p);
  981. return p + 1;
  982. }
  983. } else if(!strncmp(p,"do",2) && !isalpha(*(p + 2))) {
  984. int l;
  985. char label[256];
  986. p=skip_word(p);
  987. p=skip_space(p);
  988. syntax.curly[syntax.curly_count].type = TYPE_DO;
  989. syntax.curly[syntax.curly_count].count = 1;
  990. syntax.curly[syntax.curly_count].index = syntax.index++;
  991. syntax.curly[syntax.curly_count].flag = 0;
  992. // 現在地のラベル形成する
  993. sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
  994. l=add_str(label);
  995. set_label(l,script_pos,p);
  996. syntax.curly_count++;
  997. return p;
  998. }
  999. break;
  1000. case 'f':
  1001. if(!strncmp(p,"for",3) && !isalpha(*(p + 3))) {
  1002. int l;
  1003. unsigned char label[256];
  1004. int pos = syntax.curly_count;
  1005. syntax.curly[syntax.curly_count].type = TYPE_FOR;
  1006. syntax.curly[syntax.curly_count].count = 1;
  1007. syntax.curly[syntax.curly_count].index = syntax.index++;
  1008. syntax.curly[syntax.curly_count].flag = 0;
  1009. syntax.curly_count++;
  1010. p=skip_word(p);
  1011. p=skip_space(p);
  1012. if(*p != '(') {
  1013. disp_error_message("need '('",p);
  1014. return p+1;
  1015. }
  1016. p++;
  1017. // 初期化文を実行する
  1018. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1019. p=parse_line(p);
  1020. syntax.curly_count--;
  1021. // 条件判断開始のラベル形成する
  1022. sprintf(label,"__FR%x_J",syntax.curly[pos].index);
  1023. l=add_str(label);
  1024. set_label(l,script_pos,p);
  1025. p=skip_space(p);
  1026. if(*p == ';') {
  1027. // for(;;) のパターンなので必ず真
  1028. ;
  1029. } else {
  1030. // 条件が偽なら終了地点に飛ばす
  1031. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1032. add_scriptl(add_str("jump_zero"));
  1033. add_scriptc(C_ARG);
  1034. p=parse_expr(p);
  1035. p=skip_space(p);
  1036. add_scriptl(add_str(label));
  1037. add_scriptc(C_FUNC);
  1038. }
  1039. if(*p != ';') {
  1040. disp_error_message("need ';'",p);
  1041. return p+1;
  1042. }
  1043. p++;
  1044. // ループ開始に飛ばす
  1045. sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
  1046. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1047. parse_line(label);
  1048. syntax.curly_count--;
  1049. // 次のループへのラベル形成する
  1050. sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
  1051. l=add_str(label);
  1052. set_label(l,script_pos,p);
  1053. // 次のループに入る時の処理
  1054. // for 最後の ')' を ';' として扱うフラグ
  1055. parse_syntax_for_flag = 1;
  1056. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1057. p=parse_line(p);
  1058. syntax.curly_count--;
  1059. parse_syntax_for_flag = 0;
  1060. // 条件判定処理に飛ばす
  1061. sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
  1062. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1063. parse_line(label);
  1064. syntax.curly_count--;
  1065. // ループ開始のラベル付け
  1066. sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
  1067. l=add_str(label);
  1068. set_label(l,script_pos,p);
  1069. return p;
  1070. } else if(!strncmp(p,"function",8) && !isalpha(*(p + 8))) {
  1071. unsigned char *func_name;
  1072. // function
  1073. p=skip_word(p);
  1074. p=skip_space(p);
  1075. // function - name
  1076. func_name = p;
  1077. p=skip_word(p);
  1078. if(*skip_space(p) == ';') {
  1079. // 関数の宣言 - 名前を登録して終わり
  1080. unsigned char c = *p;
  1081. int l;
  1082. *p = 0;
  1083. l=add_str(func_name);
  1084. *p = c;
  1085. if(str_data[l].type == C_NOP) {
  1086. str_data[l].type = C_USERFUNC;
  1087. }
  1088. return skip_space(p) + 1;
  1089. } else {
  1090. // 関数の中身
  1091. char label[256];
  1092. unsigned char c = *p;
  1093. int l;
  1094. syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
  1095. syntax.curly[syntax.curly_count].count = 1;
  1096. syntax.curly[syntax.curly_count].index = syntax.index++;
  1097. syntax.curly[syntax.curly_count].flag = 0;
  1098. syntax.curly_count++;
  1099. // 関数終了まで飛ばす
  1100. sprintf(label,"goto __FN%x_FIN;",syntax.curly[syntax.curly_count-1].index);
  1101. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1102. parse_line(label);
  1103. syntax.curly_count--;
  1104. // 関数名のラベルを付ける
  1105. *p = 0;
  1106. l=add_str(func_name);
  1107. if(str_data[l].type == C_NOP)
  1108. str_data[l].type = C_USERFUNC;
  1109. *p = c;
  1110. set_label(l,script_pos,p);
  1111. strdb_put(scriptlabel_db,func_name,(void*)script_pos);
  1112. return skip_space(p);
  1113. }
  1114. }
  1115. break;
  1116. case 'i':
  1117. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1118. // if() の処理
  1119. char label[256];
  1120. p=skip_word(p);
  1121. p=skip_space(p);
  1122. syntax.curly[syntax.curly_count].type = TYPE_IF;
  1123. syntax.curly[syntax.curly_count].count = 1;
  1124. syntax.curly[syntax.curly_count].index = syntax.index++;
  1125. syntax.curly[syntax.curly_count].flag = 0;
  1126. sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
  1127. syntax.curly_count++;
  1128. add_scriptl(add_str("jump_zero"));
  1129. add_scriptc(C_ARG);
  1130. p=parse_expr(p);
  1131. p=skip_space(p);
  1132. add_scriptl(add_str(label));
  1133. add_scriptc(C_FUNC);
  1134. return p;
  1135. }
  1136. break;
  1137. case 's':
  1138. if(!strncmp(p,"switch",6) && !isalpha(*(p + 6))) {
  1139. // switch() の処理
  1140. char label[256];
  1141. syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
  1142. syntax.curly[syntax.curly_count].count = 1;
  1143. syntax.curly[syntax.curly_count].index = syntax.index++;
  1144. syntax.curly[syntax.curly_count].flag = 0;
  1145. sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
  1146. syntax.curly_count++;
  1147. add_scriptl(add_str((unsigned char*)"set"));
  1148. add_scriptc(C_ARG);
  1149. add_scriptl(add_str(label));
  1150. p=skip_word(p);
  1151. p=skip_space(p);
  1152. p=parse_expr(p);
  1153. p=skip_space(p);
  1154. if(*p != '{') {
  1155. disp_error_message("need '{'",p);
  1156. }
  1157. add_scriptc(C_FUNC);
  1158. return p + 1;
  1159. }
  1160. break;
  1161. case 'w':
  1162. if(!strncmp(p,"while",5) && !isalpha(*(p + 5))) {
  1163. int l;
  1164. char label[256];
  1165. p=skip_word(p);
  1166. p=skip_space(p);
  1167. syntax.curly[syntax.curly_count].type = TYPE_WHILE;
  1168. syntax.curly[syntax.curly_count].count = 1;
  1169. syntax.curly[syntax.curly_count].index = syntax.index++;
  1170. syntax.curly[syntax.curly_count].flag = 0;
  1171. // 条件判断開始のラベル形成する
  1172. sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
  1173. l=add_str(label);
  1174. set_label(l,script_pos,p);
  1175. // 条件が偽なら終了地点に飛ばす
  1176. sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
  1177. add_scriptl(add_str("jump_zero"));
  1178. add_scriptc(C_ARG);
  1179. p=parse_expr(p);
  1180. p=skip_space(p);
  1181. add_scriptl(add_str(label));
  1182. add_scriptc(C_FUNC);
  1183. syntax.curly_count++;
  1184. return p;
  1185. }
  1186. break;
  1187. }
  1188. return NULL;
  1189. }
  1190. unsigned char* parse_syntax_close(unsigned char *p) {
  1191. // if(...) for(...) hoge(); のように、1度閉じられたら再度閉じられるか確認する
  1192. int flag;
  1193. do {
  1194. p = parse_syntax_close_sub(p,&flag);
  1195. } while(flag);
  1196. return p;
  1197. }
  1198. // if, for , while , do の閉じ判定
  1199. // flag == 1 : 閉じられた
  1200. // flag == 0 : 閉じられない
  1201. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
  1202. unsigned char label[256];
  1203. int pos = syntax.curly_count - 1;
  1204. int l;
  1205. *flag = 1;
  1206. if(syntax.curly_count <= 0) {
  1207. *flag = 0;
  1208. return p;
  1209. } else if(syntax.curly[pos].type == TYPE_IF) {
  1210. char *p2 = p;
  1211. // if 最終場所へ飛ばす
  1212. sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
  1213. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1214. parse_line(label);
  1215. syntax.curly_count--;
  1216. // 現在地のラベルを付ける
  1217. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1218. l=add_str(label);
  1219. set_label(l,script_pos,p);
  1220. syntax.curly[pos].count++;
  1221. p = skip_space(p);
  1222. if(!syntax.curly[pos].flag && !strncmp(p,"else",4) && !isalpha(*(p + 4))) {
  1223. // else or else - if
  1224. p = skip_word(p);
  1225. p = skip_space(p);
  1226. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1227. // else - if
  1228. p=skip_word(p);
  1229. p=skip_space(p);
  1230. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1231. add_scriptl(add_str("jump_zero"));
  1232. add_scriptc(C_ARG);
  1233. p=parse_expr(p);
  1234. p=skip_space(p);
  1235. add_scriptl(add_str(label));
  1236. add_scriptc(C_FUNC);
  1237. *flag = 0;
  1238. return p;
  1239. } else {
  1240. // else
  1241. if(!syntax.curly[pos].flag) {
  1242. syntax.curly[pos].flag = 1;
  1243. *flag = 0;
  1244. return p;
  1245. }
  1246. }
  1247. }
  1248. // if 閉じ
  1249. syntax.curly_count--;
  1250. // 最終地のラベルを付ける
  1251. sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
  1252. l=add_str(label);
  1253. set_label(l,script_pos,p);
  1254. if(syntax.curly[pos].flag == 1) {
  1255. // このifに対するelseじゃないのでポインタの位置は同じ
  1256. return p2;
  1257. }
  1258. return p;
  1259. } else if(syntax.curly[pos].type == TYPE_DO) {
  1260. int l;
  1261. char label[256];
  1262. unsigned char *p2;
  1263. if(syntax.curly[pos].flag) {
  1264. // 現在地のラベル形成する(continue でここに来る)
  1265. sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
  1266. l=add_str(label);
  1267. set_label(l,script_pos,p);
  1268. }
  1269. // 条件が偽なら終了地点に飛ばす
  1270. p = skip_space(p);
  1271. p2 = skip_word(p);
  1272. if(p2 - p != 5 || strncmp("while",p,5)) {
  1273. disp_error_message("need 'while'",p);
  1274. }
  1275. p = p2;
  1276. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1277. add_scriptl(add_str("jump_zero"));
  1278. add_scriptc(C_ARG);
  1279. p=parse_expr(p);
  1280. p=skip_space(p);
  1281. add_scriptl(add_str(label));
  1282. add_scriptc(C_FUNC);
  1283. // 開始地点に飛ばす
  1284. sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
  1285. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1286. parse_line(label);
  1287. syntax.curly_count--;
  1288. // 条件終了地点のラベル形成する
  1289. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1290. l=add_str(label);
  1291. set_label(l,script_pos,p);
  1292. p = skip_space(p);
  1293. if(*p != ';') {
  1294. disp_error_message("need ';'",p);
  1295. return p+1;
  1296. }
  1297. p++;
  1298. syntax.curly_count--;
  1299. return p;
  1300. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1301. // 次のループに飛ばす
  1302. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1303. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1304. parse_line(label);
  1305. syntax.curly_count--;
  1306. // for 終了のラベル付け
  1307. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1308. l=add_str(label);
  1309. set_label(l,script_pos,p);
  1310. syntax.curly_count--;
  1311. return p;
  1312. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1313. // while 条件判断へ飛ばす
  1314. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1315. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1316. parse_line(label);
  1317. syntax.curly_count--;
  1318. // while 終了のラベル付け
  1319. sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
  1320. l=add_str(label);
  1321. set_label(l,script_pos,p);
  1322. syntax.curly_count--;
  1323. return p;
  1324. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
  1325. int pos = syntax.curly_count-1;
  1326. char label[256];
  1327. int l;
  1328. // 戻す
  1329. sprintf(label,"return;");
  1330. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1331. parse_line(label);
  1332. syntax.curly_count--;
  1333. // 現在地のラベルを付ける
  1334. sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
  1335. l=add_str(label);
  1336. set_label(l,script_pos,p);
  1337. syntax.curly_count--;
  1338. return p + 1;
  1339. } else {
  1340. *flag = 0;
  1341. return p;
  1342. }
  1343. }
  1344. /*==========================================
  1345. * 組み込み関数の追加
  1346. *------------------------------------------
  1347. */
  1348. static void add_buildin_func(void)
  1349. {
  1350. int i,n;
  1351. for(i=0;buildin_func[i].func;i++){
  1352. n=add_str((unsigned char *) buildin_func[i].name);
  1353. str_data[n].type=C_FUNC;
  1354. str_data[n].val=i;
  1355. str_data[n].func=buildin_func[i].func;
  1356. }
  1357. }
  1358. /*==========================================
  1359. * 定数データベースの読み込み
  1360. *------------------------------------------
  1361. */
  1362. static void read_constdb(void)
  1363. {
  1364. FILE *fp;
  1365. char line[1024],name[1024];
  1366. int val,n,i,type;
  1367. sprintf(line, "%s/const.txt", db_path);
  1368. fp=fopen(line, "r");
  1369. if(fp==NULL){
  1370. ShowError("can't read %s\n", line);
  1371. return ;
  1372. }
  1373. while(fgets(line,1020,fp)){
  1374. if(line[0]=='/' && line[1]=='/')
  1375. continue;
  1376. type=0;
  1377. if(sscanf(line,"%[A-Za-z0-9_],%d,%d",name,&val,&type)>=2 ||
  1378. sscanf(line,"%[A-Za-z0-9_] %d %d",name,&val,&type)>=2){
  1379. for(i=0;name[i];i++)
  1380. name[i]=tolower(name[i]);
  1381. n=add_str((const unsigned char *) name);
  1382. if(type==0)
  1383. str_data[n].type=C_INT;
  1384. else
  1385. str_data[n].type=C_PARAM;
  1386. str_data[n].val=val;
  1387. }
  1388. }
  1389. fclose(fp);
  1390. }
  1391. /*==========================================
  1392. * エラー表示
  1393. *------------------------------------------
  1394. */
  1395. const char* script_print_line( const char *p, const char *mark, int line );
  1396. void script_error(char *src,const char *file,int start_line, const char *error_msg, const char *error_pos) {
  1397. // エラーが発生した行を求める
  1398. int j;
  1399. int line = start_line;
  1400. const char *p;
  1401. const char *linestart[5] = { NULL, NULL, NULL, NULL, NULL };
  1402. for(p=src;p && *p;line++){
  1403. char *lineend=strchr(p,'\n');
  1404. if(lineend==NULL || error_pos<lineend){
  1405. break;
  1406. }
  1407. for( j = 0; j < 4; j++ ) {
  1408. linestart[j] = linestart[j+1];
  1409. }
  1410. linestart[4] = p;
  1411. p=lineend+1;
  1412. }
  1413. printf("\a\n");
  1414. printf("script error on %s line %d\n", file, line);
  1415. printf(" %s\n", error_msg);
  1416. for(j = 0; j < 5; j++ ) {
  1417. script_print_line( linestart[j], NULL, line + j - 5);
  1418. }
  1419. p = script_print_line( p, error_pos, -line);
  1420. for(j = 0; j < 5; j++) {
  1421. p = script_print_line( p, NULL, line + j + 1 );
  1422. }
  1423. }
  1424. const char* script_print_line( const char *p, const char *mark, int line ) {
  1425. int i;
  1426. if( p == NULL || !p[0] ) return NULL;
  1427. if( line < 0 )
  1428. printf("*% 5d : ", -line);
  1429. else
  1430. printf(" % 5d : ", line);
  1431. for(i=0;p[i] && p[i] != '\n';i++){
  1432. if(p + i != mark)
  1433. printf("%c",p[i]);
  1434. else
  1435. printf("\'%c\'",p[i]);
  1436. }
  1437. printf("\n");
  1438. return p+i+(p[i] == '\n' ? 1 : 0);
  1439. }
  1440. /*==========================================
  1441. * スクリプトの解析
  1442. *------------------------------------------
  1443. */
  1444. struct script_code* parse_script(unsigned char *src,const char *file,int line)
  1445. {
  1446. unsigned char *p,*tmpp;
  1447. int i;
  1448. struct script_code *code;
  1449. static int first=1;
  1450. memset(&syntax,0,sizeof(syntax));
  1451. if(first){
  1452. add_buildin_func();
  1453. read_constdb();
  1454. }
  1455. first=0;
  1456. script_buf=(unsigned char *)aCalloc(SCRIPT_BLOCK_SIZE,sizeof(unsigned char));
  1457. script_pos=0;
  1458. script_size=SCRIPT_BLOCK_SIZE;
  1459. str_data[LABEL_NEXTLINE].type=C_NOP;
  1460. str_data[LABEL_NEXTLINE].backpatch=-1;
  1461. str_data[LABEL_NEXTLINE].label=-1;
  1462. for(i=LABEL_START;i<str_num;i++){
  1463. if(
  1464. str_data[i].type==C_POS || str_data[i].type==C_NAME ||
  1465. str_data[i].type==C_USERFUNC || str_data[i].type == C_USERFUNC_POS
  1466. ){
  1467. str_data[i].type=C_NOP;
  1468. str_data[i].backpatch=-1;
  1469. str_data[i].label=-1;
  1470. }
  1471. }
  1472. //Labels must be reparsed for the script....
  1473. scriptlabel_db->clear(scriptlabel_db, NULL);
  1474. if( setjmp( error_jump ) != 0 ) {
  1475. //Restore program state when script has problems. [from jA]
  1476. script_error(src,file,line,error_msg,error_pos);
  1477. aFree( error_msg );
  1478. aFree( script_buf );
  1479. script_pos = 0;
  1480. script_size = 0;
  1481. script_buf = NULL;
  1482. for(i=LABEL_START;i<str_num;i++){
  1483. if(str_data[i].type == C_NOP) str_data[i].type = C_NAME;
  1484. }
  1485. return NULL;
  1486. }
  1487. p=src;
  1488. p=skip_space(p);
  1489. if(*p!='{'){
  1490. disp_error_message("not found '{'",p);
  1491. exit(1);
  1492. }
  1493. p++;
  1494. p = skip_space(p);
  1495. if (p && *p == '}') {
  1496. // an empty function, just return
  1497. aFree( script_buf );
  1498. script_pos = 0;
  1499. script_size = 0;
  1500. script_buf = NULL;
  1501. return NULL;
  1502. }
  1503. while (p && *p && (*p!='}' || syntax.curly_count != 0)) {
  1504. p=skip_space(p);
  1505. // labelだけ特殊処理
  1506. tmpp=skip_space(skip_word(p));
  1507. if(*tmpp==':' && !(!strncmp(p,"default:",8) && p + 7 == tmpp)){
  1508. int l,c;
  1509. c=*skip_word(p);
  1510. *skip_word(p)=0;
  1511. if(*p == 0) {
  1512. *skip_word(p)=c;
  1513. disp_error_message("label length 0 ",p);
  1514. exit(1);
  1515. }
  1516. l=add_str(p);
  1517. /* FIXME: How much does it breaks to not restore skipword(p)=c when an error occurs here?
  1518. if(str_data[l].label!=-1){
  1519. *skip_word(p)=c;
  1520. disp_error_message("dup label ",p);
  1521. exit(1);
  1522. }
  1523. */
  1524. set_label(l,script_pos,p);
  1525. strdb_put(scriptlabel_db, p, (void*)script_pos);
  1526. *skip_word(p)=c;
  1527. p=tmpp+1;
  1528. continue;
  1529. }
  1530. // 他は全部一緒くた
  1531. p=parse_line(p);
  1532. p=skip_space(p);
  1533. add_scriptc(C_EOL);
  1534. set_label(LABEL_NEXTLINE,script_pos,p);
  1535. str_data[LABEL_NEXTLINE].type=C_NOP;
  1536. str_data[LABEL_NEXTLINE].backpatch=-1;
  1537. str_data[LABEL_NEXTLINE].label=-1;
  1538. }
  1539. add_scriptc(C_NOP);
  1540. script_size = script_pos;
  1541. script_buf=(unsigned char *)aRealloc(script_buf,script_pos);
  1542. // 未解決のラベルを解決
  1543. for(i=LABEL_START;i<str_num;i++){
  1544. if(str_data[i].type==C_NOP){
  1545. int j,next;
  1546. str_data[i].type=C_NAME;
  1547. str_data[i].label=i;
  1548. for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
  1549. next=(*(int*)(script_buf+j)) & 0x00ffffff;
  1550. script_buf[j]=i;
  1551. script_buf[j+1]=i>>8;
  1552. script_buf[j+2]=i>>16;
  1553. j=next;
  1554. }
  1555. }
  1556. }
  1557. #ifdef DEBUG_DISP
  1558. for(i=0;i<script_pos;i++){
  1559. if((i&15)==0) printf("%04x : ",i);
  1560. printf("%02x ",script_buf[i]);
  1561. if((i&15)==15) printf("\n");
  1562. }
  1563. printf("\n");
  1564. #endif
  1565. code = aCalloc(1, sizeof(struct script_code));
  1566. code->script_buf = script_buf;
  1567. code->script_size = script_size;
  1568. code->script_vars = NULL;
  1569. return code;
  1570. }
  1571. //
  1572. // 実行系
  1573. //
  1574. enum {RUN = 0,STOP,END,RERUNLINE,GOTO,RETFUNC};
  1575. /*==========================================
  1576. * ridからsdへの解決
  1577. *------------------------------------------
  1578. */
  1579. struct map_session_data *script_rid2sd(struct script_state *st)
  1580. {
  1581. struct map_session_data *sd=map_id2sd(st->rid);
  1582. if(!sd){
  1583. ShowError("script_rid2sd: fatal error ! player not attached!\n");
  1584. report_src(st);
  1585. }
  1586. return sd;
  1587. }
  1588. /*==========================================
  1589. * 変数の読み取り
  1590. *------------------------------------------
  1591. */
  1592. int get_val(struct script_state*st,struct script_data* data)
  1593. {
  1594. struct map_session_data *sd=NULL;
  1595. if(data->type==C_NAME){
  1596. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  1597. char prefix=*name;
  1598. char postfix=name[strlen(name)-1];
  1599. if(not_server_variable(prefix)){
  1600. if((sd=script_rid2sd(st))==NULL)
  1601. ShowError("get_val error name?:%s\n",name);
  1602. }
  1603. if(postfix=='$'){
  1604. data->type=C_CONSTSTR;
  1605. if( prefix=='@'){
  1606. if(sd)
  1607. data->u.str = pc_readregstr(sd,data->u.num);
  1608. }else if(prefix=='$'){
  1609. data->u.str = (char *)idb_get(mapregstr_db,data->u.num);
  1610. }else if(prefix=='#'){
  1611. if( name[1]=='#'){
  1612. if(sd)
  1613. data->u.str = pc_readaccountreg2str(sd,name);
  1614. }else{
  1615. if(sd)
  1616. data->u.str = pc_readaccountregstr(sd,name);
  1617. }
  1618. }else if(prefix=='.') {
  1619. struct linkdb_node **n;
  1620. if( data->ref ) {
  1621. n = data->ref;
  1622. } else if( name[1] == '@' ) {
  1623. n = st->stack->var_function;
  1624. } else {
  1625. n = &st->script->script_vars;
  1626. }
  1627. data->u.str = linkdb_search(n, (void*)data->u.num );
  1628. }else{
  1629. if(sd)
  1630. data->u.str = pc_readglobalreg_str(sd,name);
  1631. } // [zBuffer]
  1632. /*else{
  1633. ShowWarning("script: get_val: illegal scope string variable.\n");
  1634. data->u.str = "!!ERROR!!";
  1635. }*/
  1636. if( data->u.str == NULL )
  1637. data->u.str ="";
  1638. }else{
  1639. data->type=C_INT;
  1640. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  1641. data->u.num = str_data[data->u.num&0x00ffffff].val;
  1642. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  1643. if(sd)
  1644. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  1645. }else if(prefix=='@'){
  1646. if(sd)
  1647. data->u.num = pc_readreg(sd,data->u.num);
  1648. }else if(prefix=='$'){
  1649. data->u.num = (int)idb_get(mapreg_db,data->u.num);
  1650. }else if(prefix=='#'){
  1651. if( name[1]=='#'){
  1652. if(sd)
  1653. data->u.num = pc_readaccountreg2(sd,name);
  1654. }else{
  1655. if(sd)
  1656. data->u.num = pc_readaccountreg(sd,name);
  1657. }
  1658. }else if(prefix=='.'){
  1659. struct linkdb_node **n;
  1660. if( data->ref ) {
  1661. n = data->ref;
  1662. } else if( name[1] == '@' ) {
  1663. n = st->stack->var_function;
  1664. } else {
  1665. n = &st->script->script_vars;
  1666. }
  1667. data->u.num = (int)linkdb_search(n, (void*)data->u.num);
  1668. }else{
  1669. if(sd)
  1670. data->u.num = pc_readglobalreg(sd,name);
  1671. }
  1672. }
  1673. }
  1674. return 0;
  1675. }
  1676. /*==========================================
  1677. * 変数の読み取り2
  1678. *------------------------------------------
  1679. */
  1680. void* get_val2(struct script_state*st,int num,struct linkdb_node **ref)
  1681. {
  1682. struct script_data dat;
  1683. dat.type=C_NAME;
  1684. dat.u.num=num;
  1685. dat.ref=ref;
  1686. get_val(st,&dat);
  1687. if( dat.type==C_INT ) return (void*)dat.u.num;
  1688. else return (void*)dat.u.str;
  1689. }
  1690. /*==========================================
  1691. * 変数設定用
  1692. *------------------------------------------
  1693. */
  1694. static int set_reg(struct script_state*st,struct map_session_data *sd,int num,char *name,void *v,struct linkdb_node** ref)
  1695. {
  1696. char prefix=*name;
  1697. char postfix=name[strlen(name)-1];
  1698. if( postfix=='$' ){
  1699. char *str=(char*)v;
  1700. if( prefix=='@'){
  1701. pc_setregstr(sd,num,str);
  1702. }else if(prefix=='$') {
  1703. mapreg_setregstr(num,str);
  1704. }else if(prefix=='#') {
  1705. if( name[1]=='#' )
  1706. pc_setaccountreg2str(sd,name,str);
  1707. else
  1708. pc_setaccountregstr(sd,name,str);
  1709. }else if(prefix=='.') {
  1710. char *p;
  1711. struct linkdb_node **n;
  1712. if( ref ) {
  1713. n = ref;
  1714. } else if( name[1] == '@' ) {
  1715. n = st->stack->var_function;
  1716. } else {
  1717. n = &st->script->script_vars;
  1718. }
  1719. p = linkdb_search(n, (void*)num);
  1720. if(p) {
  1721. linkdb_erase(n, (void*)num);
  1722. aFree(p);
  1723. }
  1724. if( ((char*)v)[0] )
  1725. linkdb_insert(n, (void*)num, aStrdup(v));
  1726. }else{
  1727. pc_setglobalreg_str(sd,name,str);
  1728. } // [zBuffer]
  1729. }else{
  1730. // 数値
  1731. int val = (int)v;
  1732. if(str_data[num&0x00ffffff].type==C_PARAM){
  1733. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  1734. }else if(prefix=='@') {
  1735. pc_setreg(sd,num,val);
  1736. }else if(prefix=='$') {
  1737. mapreg_setreg(num,val);
  1738. }else if(prefix=='#') {
  1739. if( name[1]=='#' )
  1740. pc_setaccountreg2(sd,name,val);
  1741. else
  1742. pc_setaccountreg(sd,name,val);
  1743. }else if(prefix == '.') {
  1744. struct linkdb_node **n;
  1745. if( ref ) {
  1746. n = ref;
  1747. } else if( name[1] == '@' ) {
  1748. n = st->stack->var_function;
  1749. } else {
  1750. n = &st->script->script_vars;
  1751. }
  1752. if( val == 0 ) {
  1753. linkdb_erase(n, (void*)num);
  1754. } else {
  1755. linkdb_replace(n, (void*)num, (void*)val);
  1756. }
  1757. }else{
  1758. pc_setglobalreg(sd,name,val);
  1759. }
  1760. }
  1761. return 0;
  1762. }
  1763. int set_var(struct map_session_data *sd, char *name, void *val)
  1764. {
  1765. return set_reg(NULL, sd, add_str((unsigned char *) name), name, val, NULL);
  1766. }
  1767. /*==========================================
  1768. * 文字列への変換
  1769. *------------------------------------------
  1770. */
  1771. char* conv_str(struct script_state *st,struct script_data *data)
  1772. {
  1773. get_val(st,data);
  1774. if(data->type==C_INT){
  1775. char *buf;
  1776. buf=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  1777. snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
  1778. data->type=C_STR;
  1779. data->u.str=buf;
  1780. #if 1
  1781. } else if(data->type==C_NAME){
  1782. // テンポラリ。本来無いはず
  1783. data->type=C_CONSTSTR;
  1784. data->u.str=str_buf+str_data[data->u.num].str;
  1785. #endif
  1786. }
  1787. return data->u.str;
  1788. }
  1789. /*==========================================
  1790. * 数値へ変換
  1791. *------------------------------------------
  1792. */
  1793. int conv_num(struct script_state *st,struct script_data *data)
  1794. {
  1795. char *p;
  1796. get_val(st,data);
  1797. if(data->type==C_STR || data->type==C_CONSTSTR){
  1798. p=data->u.str;
  1799. data->u.num = atoi(p);
  1800. if(data->type==C_STR)
  1801. aFree(p);
  1802. data->type=C_INT;
  1803. }
  1804. return data->u.num;
  1805. }
  1806. /*==========================================
  1807. * スタックへ数値をプッシュ
  1808. *------------------------------------------
  1809. */
  1810. void push_val(struct script_stack *stack,int type,int val)
  1811. {
  1812. if(stack->sp >= stack->sp_max){
  1813. stack->sp_max += 64;
  1814. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1815. sizeof(stack->stack_data[0]) * stack->sp_max);
  1816. memset(stack->stack_data + (stack->sp_max - 64), 0,
  1817. 64 * sizeof(*(stack->stack_data)));
  1818. }
  1819. // if(battle_config.etc_log)
  1820. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  1821. stack->stack_data[stack->sp].type=type;
  1822. stack->stack_data[stack->sp].u.num=val;
  1823. stack->stack_data[stack->sp].ref = NULL;
  1824. stack->sp++;
  1825. }
  1826. /*==========================================
  1827. * スタックへ数値+リファレンスをプッシュ
  1828. *------------------------------------------
  1829. */
  1830. void push_val2(struct script_stack *stack,int type,int val,struct linkdb_node** ref) {
  1831. push_val(stack,type,val);
  1832. stack->stack_data[stack->sp-1].ref = ref;
  1833. }
  1834. /*==========================================
  1835. * スタックへ文字列をプッシュ
  1836. *------------------------------------------
  1837. */
  1838. void push_str(struct script_stack *stack,int type,unsigned char *str)
  1839. {
  1840. if(stack->sp>=stack->sp_max){
  1841. stack->sp_max += 64;
  1842. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1843. sizeof(stack->stack_data[0]) * stack->sp_max);
  1844. memset(stack->stack_data + (stack->sp_max - 64), '\0',
  1845. 64 * sizeof(*(stack->stack_data)));
  1846. }
  1847. // if(battle_config.etc_log)
  1848. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  1849. stack->stack_data[stack->sp].type=type;
  1850. stack->stack_data[stack->sp].u.str=(char *) str;
  1851. stack->stack_data[stack->sp].ref = NULL;
  1852. stack->sp++;
  1853. }
  1854. /*==========================================
  1855. * スタックへ複製をプッシュ
  1856. *------------------------------------------
  1857. */
  1858. void push_copy(struct script_stack *stack,int pos)
  1859. {
  1860. switch(stack->stack_data[pos].type){
  1861. case C_CONSTSTR:
  1862. push_str(stack,C_CONSTSTR,(unsigned char *) stack->stack_data[pos].u.str);
  1863. break;
  1864. case C_STR:
  1865. push_str(stack,C_STR,(unsigned char *) aStrdup(stack->stack_data[pos].u.str));
  1866. break;
  1867. default:
  1868. push_val2(
  1869. stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num,
  1870. stack->stack_data[pos].ref
  1871. );
  1872. break;
  1873. }
  1874. }
  1875. /*==========================================
  1876. * スタックからポップ
  1877. *------------------------------------------
  1878. */
  1879. void pop_stack(struct script_stack* stack,int start,int end)
  1880. {
  1881. int i;
  1882. for(i=start;i<end;i++){
  1883. if(stack->stack_data[i].type==C_STR){
  1884. aFree(stack->stack_data[i].u.str);
  1885. stack->stack_data[i].type=C_INT; //Might not be correct, but it's done in case to prevent pointer errors later on. [Skotlex]
  1886. }
  1887. }
  1888. if(stack->sp>end){
  1889. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  1890. }
  1891. stack->sp-=end-start;
  1892. }
  1893. /*==========================================
  1894. * スクリプト依存変数、関数依存変数の解放
  1895. *------------------------------------------
  1896. */
  1897. void script_free_vars(struct linkdb_node **node) {
  1898. struct linkdb_node *n = *node;
  1899. while(n) {
  1900. char *name = str_buf + str_data[(int)(n->key)&0x00ffffff].str;
  1901. char postfix = name[strlen(name)-1];
  1902. if( postfix == '$' ) {
  1903. // 文字型変数なので、データ削除
  1904. aFree(n->data);
  1905. }
  1906. n = n->next;
  1907. }
  1908. linkdb_final( node );
  1909. }
  1910. /*==========================================
  1911. * Free's the whole stack. Invoked when clearing a character. [Skotlex]
  1912. *------------------------------------------
  1913. */
  1914. void script_free_stack(struct script_stack *stack) {
  1915. int i;
  1916. for(i = 0; i < stack->sp; i++) {
  1917. if( stack->stack_data[i].type == C_STR ) {
  1918. aFree(stack->stack_data[i].u.str);
  1919. stack->stack_data[i].type = C_INT;
  1920. } else if( i > 0 && stack->stack_data[i].type == C_RETINFO ) {
  1921. struct linkdb_node** n = (struct linkdb_node**)stack->stack_data[i-1].u.num;
  1922. script_free_vars( n );
  1923. aFree( n );
  1924. }
  1925. }
  1926. script_free_vars( stack->var_function );
  1927. aFree(stack->var_function);
  1928. aFree(stack->stack_data);
  1929. aFree(stack);
  1930. }
  1931. void script_free_code(struct script_code* code) {
  1932. script_free_vars( &code->script_vars );
  1933. aFree( code->script_buf );
  1934. aFree( code );
  1935. }
  1936. //
  1937. // 実行部main
  1938. //
  1939. /*==========================================
  1940. * コマンドの読み取り
  1941. *------------------------------------------
  1942. */
  1943. static int unget_com_data=-1;
  1944. int get_com(unsigned char *script,int *pos)
  1945. {
  1946. int i,j;
  1947. if(unget_com_data>=0){
  1948. i=unget_com_data;
  1949. unget_com_data=-1;
  1950. return i;
  1951. }
  1952. if(script[*pos]>=0x80){
  1953. return C_INT;
  1954. }
  1955. i=0; j=0;
  1956. while(script[*pos]>=0x40){
  1957. i=script[(*pos)++]<<j;
  1958. j+=6;
  1959. }
  1960. return i+(script[(*pos)++]<<j);
  1961. }
  1962. /*==========================================
  1963. * コマンドのプッシュバック
  1964. *------------------------------------------
  1965. */
  1966. void unget_com(int c)
  1967. {
  1968. if(unget_com_data!=-1){
  1969. if(battle_config.error_log)
  1970. ShowError("unget_com can back only 1 data\n");
  1971. }
  1972. unget_com_data=c;
  1973. }
  1974. /*==========================================
  1975. * 数値の所得
  1976. *------------------------------------------
  1977. */
  1978. int get_num(unsigned char *script,int *pos)
  1979. {
  1980. int i,j;
  1981. i=0; j=0;
  1982. while(script[*pos]>=0xc0){
  1983. i+=(script[(*pos)++]&0x7f)<<j;
  1984. j+=6;
  1985. }
  1986. return i+((script[(*pos)++]&0x7f)<<j);
  1987. }
  1988. /*==========================================
  1989. * スタックから値を取り出す
  1990. *------------------------------------------
  1991. */
  1992. int pop_val(struct script_state* st)
  1993. {
  1994. if(st->stack->sp<=0)
  1995. return 0;
  1996. st->stack->sp--;
  1997. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  1998. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  1999. return st->stack->stack_data[st->stack->sp].u.num;
  2000. return 0;
  2001. }
  2002. int isstr(struct script_data *c) {
  2003. if( c->type == C_STR || c->type == C_CONSTSTR )
  2004. return 1;
  2005. else if( c->type == C_NAME ) {
  2006. char *p = str_buf + str_data[c->u.num & 0xffffff].str;
  2007. char postfix = p[strlen(p)-1];
  2008. return (postfix == '$');
  2009. }
  2010. return 0;
  2011. }
  2012. /*==========================================
  2013. * 加算演算子
  2014. *------------------------------------------
  2015. */
  2016. void op_add(struct script_state* st)
  2017. {
  2018. st->stack->sp--;
  2019. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  2020. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  2021. if(isstr(&st->stack->stack_data[st->stack->sp]) || isstr(&st->stack->stack_data[st->stack->sp-1])){
  2022. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  2023. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  2024. }
  2025. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  2026. int *i1 = &st->stack->stack_data[st->stack->sp-1].u.num;
  2027. int *i2 = &st->stack->stack_data[st->stack->sp].u.num;
  2028. int ret = *i1 + *i2;
  2029. double ret_double = (double)*i1 + (double)*i2;
  2030. if(ret_double > INT_MAX|| ret_double < INT_MIN) {
  2031. ShowWarning("script::op_add overflow detected op:%d\n",C_ADD);
  2032. report_src(st);
  2033. ret = cap_value(ret, INT_MIN, INT_MAX);
  2034. }
  2035. *i1 = ret;
  2036. } else { // ssの予定
  2037. char *buf;
  2038. buf=(char *)aMallocA((strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  2039. strlen(st->stack->stack_data[st->stack->sp].u.str)+1)*sizeof(char));
  2040. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  2041. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  2042. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  2043. {
  2044. aFree(st->stack->stack_data[st->stack->sp-1].u.str);
  2045. st->stack->stack_data[st->stack->sp-1].type=C_INT;
  2046. }
  2047. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  2048. {
  2049. aFree(st->stack->stack_data[st->stack->sp].u.str);
  2050. st->stack->stack_data[st->stack->sp].type=C_INT;
  2051. }
  2052. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  2053. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  2054. }
  2055. st->stack->stack_data[st->stack->sp-1].ref = NULL;
  2056. }
  2057. /*==========================================
  2058. * 二項演算子(文字列)
  2059. *------------------------------------------
  2060. */
  2061. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  2062. {
  2063. char *s1=st->stack->stack_data[sp1].u.str,
  2064. *s2=st->stack->stack_data[sp2].u.str;
  2065. int a=0;
  2066. switch(op){
  2067. case C_EQ:
  2068. a= (strcmp(s1,s2)==0);
  2069. break;
  2070. case C_NE:
  2071. a= (strcmp(s1,s2)!=0);
  2072. break;
  2073. case C_GT:
  2074. a= (strcmp(s1,s2)> 0);
  2075. break;
  2076. case C_GE:
  2077. a= (strcmp(s1,s2)>=0);
  2078. break;
  2079. case C_LT:
  2080. a= (strcmp(s1,s2)< 0);
  2081. break;
  2082. case C_LE:
  2083. a= (strcmp(s1,s2)<=0);
  2084. break;
  2085. default:
  2086. ShowWarning("script: illegal string operator\n");
  2087. break;
  2088. }
  2089. // Because push_val() overwrite stack_data[sp1], C_STR on stack_data[sp1] won't be freed.
  2090. // So, call push_val() after freeing strings. [jA1783]
  2091. // push_val(st->stack,C_INT,a);
  2092. if(st->stack->stack_data[sp1].type==C_STR)
  2093. {
  2094. aFree(s1);
  2095. st->stack->stack_data[sp1].type=C_INT;
  2096. }
  2097. if(st->stack->stack_data[sp2].type==C_STR)
  2098. {
  2099. aFree(s2);
  2100. st->stack->stack_data[sp2].type=C_INT;
  2101. }
  2102. push_val(st->stack,C_INT,a);
  2103. }
  2104. /*==========================================
  2105. * 二項演算子(数値)
  2106. *------------------------------------------
  2107. */
  2108. void op_2num(struct script_state *st,int op,int i1,int i2)
  2109. {
  2110. int ret = 0;
  2111. double ret_double = 0;
  2112. switch(op){
  2113. case C_MOD: ret = i1 % i2; break;
  2114. case C_AND: ret = i1 & i2; break;
  2115. case C_OR: ret = i1 | i2; break;
  2116. case C_XOR: ret = i1 ^ i2; break;
  2117. case C_LAND: ret = (i1 && i2); break;
  2118. case C_LOR: ret = (i1 || i2); break;
  2119. case C_EQ: ret = (i1 == i2); break;
  2120. case C_NE: ret = (i1 != i2); break;
  2121. case C_GT: ret = (i1 > i2); break;
  2122. case C_GE: ret = (i1 >= i2); break;
  2123. case C_LT: ret = (i1 < i2); break;
  2124. case C_LE: ret = (i1 <= i2); break;
  2125. case C_R_SHIFT: ret = i1>>i2; break;
  2126. case C_L_SHIFT: ret = i1<<i2; break;
  2127. default:
  2128. switch(op) {
  2129. case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
  2130. case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
  2131. case C_DIV:
  2132. if(i2 == 0) {
  2133. printf("script::op_2num division by zero.\n");
  2134. ret = INT_MAX;
  2135. ret_double = 0; // doubleの精度が怪しいのでオーバーフロー対策を飛ばす
  2136. } else {
  2137. ret = i1 / i2; ret_double = (double)i1 / (double)i2;
  2138. }
  2139. break;
  2140. }
  2141. if(ret_double > INT_MAX || ret_double < INT_MIN) {
  2142. printf("script::op_2num overflow detected op:%d\n",op);
  2143. report_src(st);
  2144. ret = (int)cap_value(ret_double,INT_MAX,INT_MIN);
  2145. }
  2146. }
  2147. push_val(st->stack,C_INT,ret);
  2148. }
  2149. /*==========================================
  2150. * 二項演算子
  2151. *------------------------------------------
  2152. */
  2153. void op_2(struct script_state *st,int op)
  2154. {
  2155. int i1,i2;
  2156. char *s1=NULL,*s2=NULL;
  2157. i2=pop_val(st);
  2158. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2159. s2=st->stack->stack_data[st->stack->sp].u.str;
  2160. i1=pop_val(st);
  2161. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2162. s1=st->stack->stack_data[st->stack->sp].u.str;
  2163. if( s1!=NULL && s2!=NULL ){
  2164. // ss => op_2str
  2165. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  2166. }else if( s1==NULL && s2==NULL ){
  2167. // ii => op_2num
  2168. op_2num(st,op,i1,i2);
  2169. }else{
  2170. // si,is => error
  2171. ShowWarning("script: op_2: int&str, str&int not allow.\n");
  2172. report_src(st);
  2173. if(s1 && st->stack->stack_data[st->stack->sp].type == C_STR)
  2174. {
  2175. aFree(s1);
  2176. st->stack->stack_data[st->stack->sp].type = C_INT;
  2177. }
  2178. if(s2 && st->stack->stack_data[st->stack->sp+1].type == C_STR)
  2179. {
  2180. aFree(s2);
  2181. st->stack->stack_data[st->stack->sp+1].type = C_INT;
  2182. }
  2183. push_val(st->stack,C_INT,0);
  2184. }
  2185. }
  2186. /*==========================================
  2187. * 単項演算子
  2188. *------------------------------------------
  2189. */
  2190. void op_1num(struct script_state *st,int op)
  2191. {
  2192. int i1;
  2193. i1=pop_val(st);
  2194. switch(op){
  2195. case C_NEG:
  2196. i1=-i1;
  2197. break;
  2198. case C_NOT:
  2199. i1=~i1;
  2200. break;
  2201. case C_LNOT:
  2202. i1=!i1;
  2203. break;
  2204. }
  2205. push_val(st->stack,C_INT,i1);
  2206. }
  2207. /*==========================================
  2208. * 関数の実行
  2209. *------------------------------------------
  2210. */
  2211. int run_func(struct script_state *st)
  2212. {
  2213. int i,start_sp,end_sp,func;
  2214. end_sp=st->stack->sp;
  2215. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  2216. if(i==0){
  2217. if(battle_config.error_log)
  2218. ShowError("function not found\n");
  2219. // st->stack->sp=0;
  2220. st->state=END;
  2221. report_src(st);
  2222. return 1;
  2223. }
  2224. start_sp=i-1;
  2225. st->start=i-1;
  2226. st->end=end_sp;
  2227. func=st->stack->stack_data[st->start].u.num;
  2228. #ifdef DEBUG_RUN
  2229. if(battle_config.etc_log) {
  2230. ShowDebug("run_func : %s? (%d(%d)) sp=%d (%d...%d)\n",str_buf+str_data[func].str, func, str_data[func].type, st->stack->sp, st->start, st->end);
  2231. ShowDebug("stack dump :");
  2232. for(i=0;i<end_sp;i++){
  2233. switch(st->stack->stack_data[i].type){
  2234. case C_INT:
  2235. printf(" int(%d)",st->stack->stack_data[i].u.num);
  2236. break;
  2237. case C_NAME:
  2238. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num & 0xffffff].str);
  2239. break;
  2240. case C_ARG:
  2241. printf(" arg");
  2242. break;
  2243. case C_POS:
  2244. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  2245. break;
  2246. case C_STR:
  2247. printf(" str(%s)",st->stack->stack_data[i].u.str);
  2248. break;
  2249. case C_CONSTSTR:
  2250. printf(" cstr(%s)",st->stack->stack_data[i].u.str);
  2251. break;
  2252. default:
  2253. printf(" etc(%d,%d)",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  2254. }
  2255. }
  2256. printf("\n");
  2257. }
  2258. #endif
  2259. if(str_data[func].type!=C_FUNC ){
  2260. ShowMessage ("run_func: '"CL_WHITE"%s"CL_RESET"' (type %d) is not function and command!\n", str_buf+str_data[func].str, str_data[func].type);
  2261. // st->stack->sp=0;
  2262. st->state=END;
  2263. report_src(st);
  2264. return 1;
  2265. }
  2266. #ifdef DEBUG_RUN
  2267. ShowDebug("run_func : %s (func_no : %d , func_type : %d pos : 0x%x)\n",
  2268. str_buf+str_data[func].str,func,str_data[func].type,st->pos
  2269. );
  2270. #endif
  2271. if(str_data[func].func){
  2272. if (str_data[func].func(st)) //Report error
  2273. report_src(st);
  2274. } else {
  2275. if(battle_config.error_log)
  2276. ShowError("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  2277. push_val(st->stack,C_INT,0);
  2278. report_src(st);
  2279. }
  2280. // Stack's datum are used when re-run functions [Eoe]
  2281. if(st->state != RERUNLINE) {
  2282. pop_stack(st->stack,start_sp,end_sp);
  2283. }
  2284. if(st->state==RETFUNC){
  2285. // ユーザー定義関数からの復帰
  2286. int olddefsp=st->stack->defsp;
  2287. int i;
  2288. pop_stack(st->stack,st->stack->defsp,start_sp); // 復帰に邪魔なスタック削除
  2289. if(st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO){
  2290. ShowWarning("script:run_func(return) return without callfunc or callsub!\n");
  2291. st->state=END;
  2292. report_src(st);
  2293. return 1;
  2294. }
  2295. script_free_vars( st->stack->var_function );
  2296. aFree(st->stack->var_function);
  2297. i = conv_num(st,& (st->stack->stack_data[st->stack->defsp-5])); // 引数の数所得
  2298. st->pos=conv_num(st,& (st->stack->stack_data[st->stack->defsp-1])); // スクリプト位置の復元
  2299. st->script=(struct script_code*)conv_num(st,& (st->stack->stack_data[st->stack->defsp-3])); // スクリプトを復元
  2300. st->stack->var_function = (struct linkdb_node**)st->stack->stack_data[st->stack->defsp-2].u.num; // 関数依存変数
  2301. st->stack->defsp=conv_num(st,& (st->stack->stack_data[st->stack->defsp-4])); // 基準スタックポインタを復元
  2302. pop_stack(st->stack,olddefsp-5-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  2303. st->state=GOTO;
  2304. }
  2305. return 0;
  2306. }
  2307. /*==========================================
  2308. * スクリプトの実行
  2309. *------------------------------------------
  2310. */
  2311. void run_script_main(struct script_state *st);
  2312. //FIXME: Temporary replacement to locate the leak source.
  2313. //void run_script(struct script_code *rootscript,int pos,int rid,int oid)
  2314. void run_script_sub(struct script_code *rootscript,int pos,int rid,int oid, char* file, int lineno)
  2315. {
  2316. struct script_state *st;
  2317. struct map_session_data *sd=NULL;
  2318. if(rootscript==NULL || pos<0)
  2319. return;
  2320. if (rid) sd = map_id2sd(rid);
  2321. if (sd && sd->st && sd->st->scriptroot == rootscript && sd->st->pos == pos){
  2322. //Resume script.
  2323. st = sd->st;
  2324. } else {
  2325. // st = aCalloc(sizeof(struct script_state), 1);
  2326. st = _mcalloc(sizeof(struct script_state), 1, file, lineno, __func__);
  2327. // the script is different, make new script_state and stack
  2328. // st->stack = aMalloc (sizeof(struct script_stack));
  2329. st->stack = _mmalloc(sizeof(struct script_stack), file, lineno, __func__);
  2330. st->stack->sp=0;
  2331. st->stack->sp_max=64;
  2332. // st->stack->stack_data = (struct script_data *)aCalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]));
  2333. st->stack->stack_data = (struct script_data *)_mcalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]), file, lineno, __func__);
  2334. st->stack->defsp = st->stack->sp;
  2335. // st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
  2336. st->stack->var_function = _mcalloc(1, sizeof(struct linkdb_node*), file, lineno, __func__);
  2337. st->state = RUN;
  2338. st->script = rootscript;
  2339. }
  2340. st->pos = pos;
  2341. st->rid = rid;
  2342. st->oid = oid;
  2343. st->sleep.timer = -1;
  2344. run_script_main(st);
  2345. }
  2346. /*==========================================
  2347. * 指定ノードをsleep_dbから削除
  2348. *------------------------------------------
  2349. */
  2350. struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n)
  2351. {
  2352. struct linkdb_node *retnode;
  2353. if( n == NULL)
  2354. return NULL;
  2355. if( n->prev == NULL )
  2356. sleep_db = n->next;
  2357. else
  2358. n->prev->next = n->next;
  2359. if( n->next )
  2360. n->next->prev = n->prev;
  2361. retnode = n->next;
  2362. aFree( n );
  2363. return retnode; // 次のノードを返す
  2364. }
  2365. /*==========================================
  2366. * sleep用タイマー関数
  2367. *------------------------------------------
  2368. */
  2369. int run_script_timer(int tid, unsigned int tick, int id, int data)
  2370. {
  2371. struct script_state *st = (struct script_state *)data;
  2372. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  2373. struct map_session_data *sd = map_id2sd(st->rid);
  2374. if((sd && sd->char_id != id) || (st->rid && !sd))
  2375. { //Character mismatch. Cancel execution.
  2376. st->rid = 0;
  2377. st->state = END;
  2378. }
  2379. while( node && st->sleep.timer != -1 ) {
  2380. if( (int)node->key == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
  2381. script_erase_sleepdb(node);
  2382. st->sleep.timer = -1;
  2383. break;
  2384. }
  2385. node = node->next;
  2386. }
  2387. //Cancel tick value or run_script_main can get into an infinite loop by always delaying execution. [Skotlex]
  2388. st->sleep.tick = 0;
  2389. run_script_main(st);
  2390. return 0;
  2391. }
  2392. /*==========================================
  2393. * スクリプトの実行メイン部分
  2394. *------------------------------------------
  2395. */
  2396. void run_script_main(struct script_state *st)
  2397. {
  2398. int c;
  2399. int cmdcount=script_config.check_cmdcount;
  2400. int gotocount=script_config.check_gotocount;
  2401. struct map_session_data *sd;
  2402. //For backing up purposes
  2403. struct script_state *bk_st = NULL;
  2404. int bk_npcid = 0;
  2405. struct script_stack *stack=st->stack;
  2406. sd = st->rid?map_id2sd(st->rid):NULL;
  2407. if(sd){
  2408. if(sd->st != st){
  2409. bk_st = sd->st;
  2410. bk_npcid = sd->npc_id;
  2411. }
  2412. sd->st = st;
  2413. sd->npc_id = st->oid;
  2414. }
  2415. if(st->state == RERUNLINE) {
  2416. st->state = RUN;
  2417. run_func(st);
  2418. if(st->state == GOTO)
  2419. st->state = RUN;
  2420. } else if(st->state != END)
  2421. st->state = RUN;
  2422. while(st->state == RUN){
  2423. c= get_com((unsigned char *) st->script->script_buf,&st->pos);
  2424. switch(c){
  2425. case C_EOL:
  2426. if(stack->sp!=stack->defsp){
  2427. if(stack->sp > stack->defsp)
  2428. { //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex]
  2429. //Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded.
  2430. if (battle_config.etc_log)
  2431. ShowWarning("Clearing unused stack stack.sp(%d) -> default(%d)\n",stack->sp,stack->defsp);
  2432. pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section.
  2433. } else if(battle_config.error_log)
  2434. ShowError("stack.sp(%d) != default(%d)\n",stack->sp,stack->defsp);
  2435. stack->sp=stack->defsp;
  2436. }
  2437. break;
  2438. case C_INT:
  2439. push_val(stack,C_INT,get_num((unsigned char *) st->script->script_buf,&st->pos));
  2440. break;
  2441. case C_POS:
  2442. case C_NAME:
  2443. push_val(stack,c,(*(int*)(st->script->script_buf+st->pos))&0xffffff);
  2444. st->pos+=3;
  2445. break;
  2446. case C_ARG:
  2447. push_val(stack,c,0);
  2448. break;
  2449. case C_STR:
  2450. push_str(stack,C_CONSTSTR,(unsigned char *) (st->script->script_buf+st->pos));
  2451. while(st->script->script_buf[st->pos++]);
  2452. break;
  2453. case C_FUNC:
  2454. run_func(st);
  2455. if(st->state==GOTO){
  2456. st->state = RUN;
  2457. if( gotocount>0 && (--gotocount)<=0 ){
  2458. ShowError("run_script: infinity loop !\n");
  2459. st->state=END;
  2460. }
  2461. }
  2462. break;
  2463. case C_ADD:
  2464. op_add(st);
  2465. break;
  2466. case C_SUB:
  2467. case C_MUL:
  2468. case C_DIV:
  2469. case C_MOD:
  2470. case C_EQ:
  2471. case C_NE:
  2472. case C_GT:
  2473. case C_GE:
  2474. case C_LT:
  2475. case C_LE:
  2476. case C_AND:
  2477. case C_OR:
  2478. case C_XOR:
  2479. case C_LAND:
  2480. case C_LOR:
  2481. case C_R_SHIFT:
  2482. case C_L_SHIFT:
  2483. op_2(st,c);
  2484. break;
  2485. case C_NEG:
  2486. case C_NOT:
  2487. case C_LNOT:
  2488. op_1num(st,c);
  2489. break;
  2490. case C_NOP:
  2491. st->state=END;
  2492. break;
  2493. default:
  2494. if(battle_config.error_log)
  2495. ShowError("unknown command : %d @ %d\n",c,pos);
  2496. st->state=END;
  2497. break;
  2498. }
  2499. if( cmdcount>0 && (--cmdcount)<=0 ){
  2500. ShowError("run_script: infinity loop !\n");
  2501. st->state=END;
  2502. }
  2503. }
  2504. if(st->sleep.tick > 0) {
  2505. //Delay execution
  2506. st->sleep.charid = sd?sd->char_id:0;
  2507. st->sleep.timer = add_timer(gettick()+st->sleep.tick,
  2508. run_script_timer, st->sleep.charid, (int)st);
  2509. linkdb_insert(&sleep_db, (void*)st->oid, st);
  2510. //Restore previous script
  2511. if (sd) {
  2512. sd->st = bk_st;
  2513. sd->npc_id = bk_npcid;
  2514. bk_st = NULL; //Remove tag for removal.
  2515. }
  2516. }
  2517. else if(st->state != END && sd){
  2518. //Resume later (st is already attached to player).
  2519. if(bk_st)
  2520. ShowWarning("Unable to restore stack! Double continuation!\n");
  2521. } else {
  2522. //Dispose of script.
  2523. if (sd)
  2524. { //Restore previous stack and save char.
  2525. if(sd->state.using_fake_npc){
  2526. clif_clearchar_id(sd->npc_id, 0, sd->fd);
  2527. sd->state.using_fake_npc = 0;
  2528. }
  2529. //Restore previous script if any.
  2530. sd->st = bk_st;
  2531. sd->npc_id = bk_npcid;
  2532. if (!bk_st)
  2533. npc_event_dequeue(sd);
  2534. else
  2535. bk_st = NULL; //Remove tag for removal.
  2536. if (sd->state.reg_dirty&2)
  2537. intif_saveregistry(sd,2);
  2538. if (sd->state.reg_dirty&1)
  2539. intif_saveregistry(sd,1);
  2540. }
  2541. st->pos = -1;
  2542. script_free_stack (st->stack);
  2543. aFree(st);
  2544. }
  2545. if (bk_st)
  2546. { //Remove previous script
  2547. bk_st->pos = -1;
  2548. script_free_stack(bk_st->stack);
  2549. aFree(bk_st);
  2550. bk_st = NULL;
  2551. }
  2552. }
  2553. /*==========================================
  2554. * マップ変数の変更
  2555. *------------------------------------------
  2556. */
  2557. int mapreg_setreg(int num,int val)
  2558. {
  2559. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2560. int i=num>>24;
  2561. char *name=str_buf+str_data[num&0x00ffffff].str;
  2562. char tmp_str[64];
  2563. #endif
  2564. if(val!=0) {
  2565. if(idb_put(mapreg_db,num,(void*)val))
  2566. ;
  2567. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2568. else if(name[1] != '@') {
  2569. sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%d')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,val);
  2570. if(mysql_query(&mmysql_handle,tmp_sql)){
  2571. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2572. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2573. }
  2574. }
  2575. #endif
  2576. // else
  2577. } else { // [zBuffer]
  2578. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2579. if(name[1] != '@') { // Remove from database because it is unused.
  2580. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2581. if(mysql_query(&mmysql_handle,tmp_sql)){
  2582. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2583. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2584. }
  2585. }
  2586. #endif
  2587. idb_remove(mapreg_db,num);
  2588. }
  2589. mapreg_dirty=1;
  2590. return 0;
  2591. }
  2592. /*==========================================
  2593. * 文字列型マップ変数の変更
  2594. *------------------------------------------
  2595. */
  2596. int mapreg_setregstr(int num,const char *str)
  2597. {
  2598. char *p;
  2599. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2600. char tmp_str[64];
  2601. char tmp_str2[512];
  2602. int i=num>>24; // [zBuffer]
  2603. char *name=str_buf+str_data[num&0x00ffffff].str;
  2604. #endif
  2605. if( str==NULL || *str==0 ){
  2606. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2607. if(name[1] != '@') {
  2608. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2609. if(mysql_query(&mmysql_handle,tmp_sql)){
  2610. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2611. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2612. }
  2613. }
  2614. #endif
  2615. idb_remove(mapregstr_db,num);
  2616. mapreg_dirty=1;
  2617. return 0;
  2618. }
  2619. p=(char *)aMallocA((strlen(str)+1)*sizeof(char));
  2620. strcpy(p,str);
  2621. if (idb_put(mapregstr_db,num,p))
  2622. ;
  2623. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2624. else if(name[1] != '@'){ //put returned null, so we must insert.
  2625. // Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
  2626. sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%s')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,jstrescapecpy(tmp_str2,p));
  2627. if(mysql_query(&mmysql_handle,tmp_sql)){
  2628. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2629. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2630. }
  2631. }
  2632. #endif
  2633. mapreg_dirty=1;
  2634. return 0;
  2635. }
  2636. /*==========================================
  2637. * 永続的マップ変数の読み込み
  2638. *------------------------------------------
  2639. */
  2640. static int script_load_mapreg(void)
  2641. {
  2642. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2643. FILE *fp;
  2644. char line[1024];
  2645. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  2646. return -1;
  2647. while(fgets(line,sizeof(line),fp)){
  2648. char buf1[256],buf2[1024],*p;
  2649. int n,v,s,i;
  2650. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  2651. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  2652. continue;
  2653. if( buf1[strlen(buf1)-1]=='$' ){
  2654. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  2655. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2656. continue;
  2657. }
  2658. p=(char *)aMallocA((strlen(buf2) + 1)*sizeof(char));
  2659. strcpy(p,buf2);
  2660. s= add_str((unsigned char *) buf1);
  2661. idb_put(mapregstr_db,(i<<24)|s,p);
  2662. }else{
  2663. if( sscanf(line+n,"%d",&v)!=1 ){
  2664. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2665. continue;
  2666. }
  2667. s= add_str((unsigned char *) buf1);
  2668. idb_put(mapreg_db,(i<<24)|s,(void*)v);
  2669. }
  2670. }
  2671. fclose(fp);
  2672. mapreg_dirty=0;
  2673. return 0;
  2674. #else
  2675. // SQL mapreg code start [zBuffer]
  2676. /*
  2677. 0 1 2
  2678. +-------------------------+
  2679. | varname | index | value |
  2680. +-------------------------+
  2681. */
  2682. unsigned int perfomance = (unsigned int)time(NULL);
  2683. sprintf(tmp_sql,"SELECT * FROM `%s`",mapregsql_db);
  2684. ShowInfo("Querying script_load_mapreg ...\n");
  2685. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2686. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2687. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2688. return -1;
  2689. }
  2690. ShowInfo("Success! Returning results ...\n");
  2691. sql_res = mysql_store_result(&mmysql_handle);
  2692. if (sql_res) {
  2693. while ((sql_row = mysql_fetch_row(sql_res))) {
  2694. char buf1[33], *p = NULL;
  2695. int i,v,s;
  2696. strcpy(buf1,sql_row[0]);
  2697. if( buf1[strlen(buf1)-1]=='$' ){
  2698. i = atoi(sql_row[1]);
  2699. p=(char *)aMallocA((strlen(sql_row[2]) + 1)*sizeof(char));
  2700. strcpy(p,sql_row[2]);
  2701. s= add_str((unsigned char *) buf1);
  2702. idb_put(mapregstr_db,(i<<24)|s,p);
  2703. }else{
  2704. s= add_str((unsigned char *) buf1);
  2705. v= atoi(sql_row[2]);
  2706. i = atoi(sql_row[1]);
  2707. idb_put(mapreg_db,(i<<24)|s,(void *)v);
  2708. }
  2709. }
  2710. }
  2711. ShowInfo("Freeing results...\n");
  2712. mysql_free_result(sql_res);
  2713. mapreg_dirty=0;
  2714. perfomance = ((unsigned int)time(NULL) - perfomance);
  2715. ShowInfo("SQL Mapreg Loading Completed Under %d Seconds.\n",perfomance);
  2716. return 0;
  2717. #endif /* TXT_ONLY */
  2718. }
  2719. /*==========================================
  2720. * 永続的マップ変数の書き込み
  2721. *------------------------------------------
  2722. */
  2723. static int script_save_mapreg_intsub(DBKey key,void *data,va_list ap)
  2724. {
  2725. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2726. FILE *fp=va_arg(ap,FILE*);
  2727. int num=key.i&0x00ffffff, i=key.i>>24;
  2728. char *name=str_buf+str_data[num].str;
  2729. if( name[1]!='@' ){
  2730. if(i==0)
  2731. fprintf(fp,"%s\t%d\n", name, (int)data);
  2732. else
  2733. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  2734. }
  2735. return 0;
  2736. #else
  2737. int num=key.i&0x00ffffff, i=key.i>>24; // [zBuffer]
  2738. char *name=str_buf+str_data[num].str;
  2739. if ( name[1] != '@') {
  2740. sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%d' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,(int)data,mapregsql_db_varname,name,mapregsql_db_index,i);
  2741. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2742. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2743. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2744. }
  2745. }
  2746. return 0;
  2747. #endif
  2748. }
  2749. static int script_save_mapreg_strsub(DBKey key,void *data,va_list ap)
  2750. {
  2751. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2752. FILE *fp=va_arg(ap,FILE*);
  2753. int num=key.i&0x00ffffff, i=key.i>>24;
  2754. char *name=str_buf+str_data[num].str;
  2755. if( name[1]!='@' ){
  2756. if(i==0)
  2757. fprintf(fp,"%s\t%s\n", name, (char *)data);
  2758. else
  2759. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  2760. }
  2761. return 0;
  2762. #else
  2763. char tmp_str2[512];
  2764. int num=key.i&0x00ffffff, i=key.i>>24;
  2765. char *name=str_buf+str_data[num].str;
  2766. if ( name[1] != '@') {
  2767. sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%s' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,jstrescapecpy(tmp_str2,(char *)data),mapregsql_db_varname,name,mapregsql_db_index,i);
  2768. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2769. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2770. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2771. }
  2772. }
  2773. return 0;
  2774. #endif
  2775. }
  2776. static int script_save_mapreg(void)
  2777. {
  2778. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2779. FILE *fp;
  2780. int lock;
  2781. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL ) {
  2782. ShowError("script_save_mapreg: Unable to lock-open file [%s]\n",mapreg_txt);
  2783. return -1;
  2784. }
  2785. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub,fp);
  2786. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  2787. lock_fclose(fp,mapreg_txt,&lock);
  2788. #else
  2789. unsigned int perfomance = (unsigned int)time(NULL);
  2790. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub); // [zBuffer]
  2791. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub);
  2792. perfomance = ((unsigned int)time(NULL) - perfomance);
  2793. if(perfomance > 2)
  2794. ShowWarning("Slow Query: MapregSQL Saving @ %d second(s).\n", perfomance);
  2795. #endif
  2796. mapreg_dirty=0;
  2797. return 0;
  2798. }
  2799. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  2800. {
  2801. if(mapreg_dirty)
  2802. if (script_save_mapreg() == -1)
  2803. ShowError("Failed to save the mapreg data!\n");
  2804. return 0;
  2805. }
  2806. /*==========================================
  2807. *
  2808. *------------------------------------------
  2809. */
  2810. static int set_posword(char *p)
  2811. {
  2812. char* np,* str[15];
  2813. int i=0;
  2814. for(i=0;i<11;i++) {
  2815. if((np=strchr(p,','))!=NULL) {
  2816. str[i]=p;
  2817. *np=0;
  2818. p=np+1;
  2819. } else {
  2820. str[i]=p;
  2821. p+=strlen(p);
  2822. }
  2823. if(str[i])
  2824. strcpy(pos[i],str[i]);
  2825. }
  2826. return 0;
  2827. }
  2828. int script_config_read_sub(char *cfgName)
  2829. {
  2830. int i;
  2831. char line[1024],w1[1024],w2[1024];
  2832. FILE *fp;
  2833. fp=fopen(cfgName,"r");
  2834. if(fp==NULL){
  2835. ShowError("file not found: [%s]\n", cfgName);
  2836. return 1;
  2837. }
  2838. while(fgets(line,sizeof(line)-1,fp)){
  2839. if(line[0] == '/' && line[1] == '/')
  2840. continue;
  2841. i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  2842. if(i!=2)
  2843. continue;
  2844. if(strcmpi(w1,"refine_posword")==0) {
  2845. set_posword(w2);
  2846. }
  2847. else if(strcmpi(w1,"verbose_mode")==0) {
  2848. script_config.verbose_mode = battle_config_switch(w2);
  2849. }
  2850. else if(strcmpi(w1,"warn_func_no_comma")==0) {
  2851. script_config.warn_func_no_comma = battle_config_switch(w2);
  2852. }
  2853. else if(strcmpi(w1,"warn_cmd_no_comma")==0) {
  2854. script_config.warn_cmd_no_comma = battle_config_switch(w2);
  2855. }
  2856. else if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
  2857. script_config.warn_func_mismatch_paramnum = battle_config_switch(w2);
  2858. }
  2859. else if(strcmpi(w1,"warn_cmd_mismatch_paramnum")==0) {
  2860. script_config.warn_cmd_mismatch_paramnum = battle_config_switch(w2);
  2861. }
  2862. else if(strcmpi(w1,"check_cmdcount")==0) {
  2863. script_config.check_cmdcount = battle_config_switch(w2);
  2864. }
  2865. else if(strcmpi(w1,"check_gotocount")==0) {
  2866. script_config.check_gotocount = battle_config_switch(w2);
  2867. }
  2868. else if(strcmpi(w1,"event_script_type")==0) {
  2869. script_config.event_script_type = battle_config_switch(w2);
  2870. }
  2871. else if(strcmpi(w1,"event_requires_trigger")==0) {
  2872. script_config.event_requires_trigger = battle_config_switch(w2);
  2873. }
  2874. else if(strcmpi(w1,"die_event_name")==0) {
  2875. strncpy(script_config.die_event_name, w2, NAME_LENGTH-1);
  2876. if (strlen(script_config.die_event_name) != strlen(w2))
  2877. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.die_event_name);
  2878. }
  2879. else if(strcmpi(w1,"kill_pc_event_name")==0) {
  2880. strncpy(script_config.kill_pc_event_name, w2, NAME_LENGTH-1);
  2881. if (strlen(script_config.kill_pc_event_name) != strlen(w2))
  2882. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_pc_event_name);
  2883. }
  2884. else if(strcmpi(w1,"kill_mob_event_name")==0) {
  2885. strncpy(script_config.kill_mob_event_name, w2, NAME_LENGTH-1);
  2886. if (strlen(script_config.kill_mob_event_name) != strlen(w2))
  2887. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_mob_event_name);
  2888. }
  2889. else if(strcmpi(w1,"login_event_name")==0) {
  2890. strncpy(script_config.login_event_name, w2, NAME_LENGTH-1);
  2891. if (strlen(script_config.login_event_name) != strlen(w2))
  2892. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.login_event_name);
  2893. }
  2894. else if(strcmpi(w1,"logout_event_name")==0) {
  2895. strncpy(script_config.logout_event_name, w2, NAME_LENGTH-1);
  2896. if (strlen(script_config.logout_event_name) != strlen(w2))
  2897. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.logout_event_name);
  2898. }
  2899. else if(strcmpi(w1,"loadmap_event_name")==0) {
  2900. strncpy(script_config.loadmap_event_name, w2, NAME_LENGTH-1);
  2901. if (strlen(script_config.loadmap_event_name) != strlen(w2))
  2902. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.loadmap_event_name);
  2903. }
  2904. else if(strcmpi(w1,"baselvup_event_name")==0) {
  2905. strncpy(script_config.baselvup_event_name, w2, NAME_LENGTH-1);
  2906. if (strlen(script_config.baselvup_event_name) != strlen(w2))
  2907. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.baselvup_event_name);
  2908. }
  2909. else if(strcmpi(w1,"joblvup_event_name")==0) {
  2910. strncpy(script_config.joblvup_event_name, w2, NAME_LENGTH-1);
  2911. if (strlen(script_config.joblvup_event_name) != strlen(w2))
  2912. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.joblvup_event_name);
  2913. }
  2914. else if(strcmpi(w1,"import")==0){
  2915. script_config_read_sub(w2);
  2916. }
  2917. }
  2918. fclose(fp);
  2919. return 0;
  2920. }
  2921. int script_config_read(char *cfgName)
  2922. { //Script related variables should be initialized once! [Skotlex]
  2923. memset (&script_config, 0, sizeof(script_config));
  2924. script_config.verbose_mode = 0;
  2925. script_config.warn_func_no_comma = 1;
  2926. script_config.warn_cmd_no_comma = 1;
  2927. script_config.warn_func_mismatch_paramnum = 1;
  2928. script_config.warn_cmd_mismatch_paramnum = 1;
  2929. script_config.check_cmdcount = 65535;
  2930. script_config.check_gotocount = 2048;
  2931. script_config.event_script_type = 0;
  2932. script_config.event_requires_trigger = 1;
  2933. return script_config_read_sub(cfgName);
  2934. }
  2935. static int do_final_userfunc_sub (DBKey key,void *data,va_list ap){
  2936. struct script_code *code = (struct script_code *)data;
  2937. if(code){
  2938. script_free_vars( &code->script_vars );
  2939. aFree( code->script_buf );
  2940. }
  2941. return 0;
  2942. }
  2943. /*==========================================
  2944. * 終了
  2945. *------------------------------------------
  2946. */
  2947. int do_final_script()
  2948. {
  2949. if(mapreg_dirty>=0)
  2950. script_save_mapreg();
  2951. mapreg_db->destroy(mapreg_db,NULL);
  2952. mapregstr_db->destroy(mapregstr_db,NULL);
  2953. scriptlabel_db->destroy(scriptlabel_db,NULL);
  2954. userfunc_db->destroy(userfunc_db,do_final_userfunc_sub);
  2955. if(sleep_db) {
  2956. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  2957. while(n) {
  2958. struct script_state *st = (struct script_state *)n->data;
  2959. script_free_stack(st->stack);
  2960. aFree(st);
  2961. n = n->next;
  2962. }
  2963. linkdb_final(&sleep_db);
  2964. }
  2965. if (str_data)
  2966. aFree(str_data);
  2967. if (str_buf)
  2968. aFree(str_buf);
  2969. return 0;
  2970. }
  2971. /*==========================================
  2972. * 初期化
  2973. *------------------------------------------
  2974. */
  2975. int do_init_script()
  2976. {
  2977. mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
  2978. mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
  2979. userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_RELEASE_BOTH,50);
  2980. scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_ALLOW_NULL_DATA,50);
  2981. script_load_mapreg();
  2982. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  2983. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  2984. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  2985. return 0;
  2986. }
  2987. int script_reload()
  2988. {
  2989. if(mapreg_dirty>=0)
  2990. script_save_mapreg();
  2991. mapreg_db->clear(mapreg_db, NULL);
  2992. mapregstr_db->clear(mapregstr_db, NULL);
  2993. userfunc_db->clear(userfunc_db,do_final_userfunc_sub);
  2994. scriptlabel_db->clear(scriptlabel_db, NULL);
  2995. if(sleep_db) {
  2996. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  2997. while(n) {
  2998. struct script_state *st = (struct script_state *)n->data;
  2999. script_free_stack(st->stack);
  3000. aFree(st);
  3001. n = n->next;
  3002. }
  3003. linkdb_final(&sleep_db);
  3004. }
  3005. script_load_mapreg();
  3006. return 0;
  3007. }
  3008. int buildin_mes(struct script_state *st);
  3009. int buildin_goto(struct script_state *st);
  3010. int buildin_callsub(struct script_state *st);
  3011. int buildin_callfunc(struct script_state *st);
  3012. int buildin_return(struct script_state *st);
  3013. int buildin_getarg(struct script_state *st);
  3014. int buildin_next(struct script_state *st);
  3015. int buildin_close(struct script_state *st);
  3016. int buildin_close2(struct script_state *st);
  3017. int buildin_menu(struct script_state *st);
  3018. int buildin_rand(struct script_state *st);
  3019. int buildin_warp(struct script_state *st);
  3020. int buildin_areawarp(struct script_state *st);
  3021. int buildin_warpchar(struct script_state *st); // [LuzZza]
  3022. int buildin_warpparty(struct script_state *st); //[Fredzilla]
  3023. int buildin_warpguild(struct script_state *st); //[Fredzilla]
  3024. int buildin_heal(struct script_state *st);
  3025. int buildin_itemheal(struct script_state *st);
  3026. int buildin_percentheal(struct script_state *st);
  3027. int buildin_jobchange(struct script_state *st);
  3028. int buildin_input(struct script_state *st);
  3029. int buildin_setlook(struct script_state *st);
  3030. int buildin_set(struct script_state *st);
  3031. int buildin_setarray(struct script_state *st);
  3032. int buildin_cleararray(struct script_state *st);
  3033. int buildin_copyarray(struct script_state *st);
  3034. int buildin_getarraysize(struct script_state *st);
  3035. int buildin_deletearray(struct script_state *st);
  3036. int buildin_getelementofarray(struct script_state *st);
  3037. int buildin_getitem(struct script_state *st);
  3038. int buildin_getitem2(struct script_state *st);
  3039. int buildin_getnameditem(struct script_state *st);
  3040. int buildin_grouprandomitem(struct script_state *st);
  3041. int buildin_makeitem(struct script_state *st);
  3042. int buildin_delitem(struct script_state *st);
  3043. int buildin_delitem2(struct script_state *st);
  3044. int buildin_enableitemuse(struct script_state *st);
  3045. int buildin_disableitemuse(struct script_state *st);
  3046. int buildin_viewpoint(struct script_state *st);
  3047. int buildin_countitem(struct script_state *st);
  3048. int buildin_countitem2(struct script_state *st);
  3049. int buildin_checkweight(struct script_state *st);
  3050. int buildin_readparam(struct script_state *st);
  3051. int buildin_getcharid(struct script_state *st);
  3052. int buildin_getpartyname(struct script_state *st);
  3053. int buildin_getpartymember(struct script_state *st);
  3054. int buildin_getpartyleader(struct script_state *st);
  3055. int buildin_getguildname(struct script_state *st);
  3056. int buildin_getguildmaster(struct script_state *st);
  3057. int buildin_getguildmasterid(struct script_state *st);
  3058. int buildin_strcharinfo(struct script_state *st);
  3059. int buildin_getequipid(struct script_state *st);
  3060. int buildin_getequipname(struct script_state *st);
  3061. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  3062. int buildin_repair(struct script_state *st); // [Valaris]
  3063. int buildin_getequipisequiped(struct script_state *st);
  3064. int buildin_getequipisenableref(struct script_state *st);
  3065. int buildin_getequipisidentify(struct script_state *st);
  3066. int buildin_getequiprefinerycnt(struct script_state *st);
  3067. int buildin_getequipweaponlv(struct script_state *st);
  3068. int buildin_getequippercentrefinery(struct script_state *st);
  3069. int buildin_successrefitem(struct script_state *st);
  3070. int buildin_failedrefitem(struct script_state *st);
  3071. int buildin_cutin(struct script_state *st);
  3072. int buildin_cutincard(struct script_state *st);
  3073. int buildin_statusup(struct script_state *st);
  3074. int buildin_statusup2(struct script_state *st);
  3075. int buildin_bonus(struct script_state *st);
  3076. int buildin_bonus2(struct script_state *st);
  3077. int buildin_bonus3(struct script_state *st);
  3078. int buildin_bonus4(struct script_state *st);
  3079. int buildin_skill(struct script_state *st);
  3080. int buildin_addtoskill(struct script_state *st); // [Valaris]
  3081. int buildin_guildskill(struct script_state *st);
  3082. int buildin_getskilllv(struct script_state *st);
  3083. int buildin_getgdskilllv(struct script_state *st);
  3084. int buildin_basicskillcheck(struct script_state *st);
  3085. int buildin_getgmlevel(struct script_state *st);
  3086. int buildin_end(struct script_state *st);
  3087. int buildin_checkoption(struct script_state *st);
  3088. int buildin_setoption(struct script_state *st);
  3089. int buildin_setcart(struct script_state *st);
  3090. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  3091. int buildin_setfalcon(struct script_state *st);
  3092. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  3093. int buildin_setriding(struct script_state *st);
  3094. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  3095. int buildin_savepoint(struct script_state *st);
  3096. int buildin_gettimetick(struct script_state *st);
  3097. int buildin_gettime(struct script_state *st);
  3098. int buildin_gettimestr(struct script_state *st);
  3099. int buildin_openstorage(struct script_state *st);
  3100. int buildin_guildopenstorage(struct script_state *st);
  3101. int buildin_itemskill(struct script_state *st);
  3102. int buildin_produce(struct script_state *st);
  3103. int buildin_monster(struct script_state *st);
  3104. int buildin_areamonster(struct script_state *st);
  3105. int buildin_killmonster(struct script_state *st);
  3106. int buildin_killmonsterall(struct script_state *st);
  3107. int buildin_clone(struct script_state *st);
  3108. int buildin_doevent(struct script_state *st);
  3109. int buildin_donpcevent(struct script_state *st);
  3110. int buildin_addtimer(struct script_state *st);
  3111. int buildin_deltimer(struct script_state *st);
  3112. int buildin_addtimercount(struct script_state *st);
  3113. int buildin_initnpctimer(struct script_state *st);
  3114. int buildin_stopnpctimer(struct script_state *st);
  3115. int buildin_startnpctimer(struct script_state *st);
  3116. int buildin_setnpctimer(struct script_state *st);
  3117. int buildin_getnpctimer(struct script_state *st);
  3118. int buildin_attachnpctimer(struct script_state *st); // [celest]
  3119. int buildin_detachnpctimer(struct script_state *st); // [celest]
  3120. int buildin_playerattached(struct script_state *st); // [Skotlex]
  3121. int buildin_announce(struct script_state *st);
  3122. int buildin_mapannounce(struct script_state *st);
  3123. int buildin_areaannounce(struct script_state *st);
  3124. int buildin_getusers(struct script_state *st);
  3125. int buildin_getmapusers(struct script_state *st);
  3126. int buildin_getareausers(struct script_state *st);
  3127. int buildin_getareadropitem(struct script_state *st);
  3128. int buildin_enablenpc(struct script_state *st);
  3129. int buildin_disablenpc(struct script_state *st);
  3130. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  3131. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  3132. int buildin_hideoffnpc(struct script_state *st);
  3133. int buildin_hideonnpc(struct script_state *st);
  3134. int buildin_sc_start(struct script_state *st);
  3135. int buildin_sc_start2(struct script_state *st);
  3136. int buildin_sc_start4(struct script_state *st);
  3137. int buildin_sc_end(struct script_state *st);
  3138. int buildin_getscrate(struct script_state *st);
  3139. int buildin_debugmes(struct script_state *st);
  3140. int buildin_catchpet(struct script_state *st);
  3141. int buildin_birthpet(struct script_state *st);
  3142. int buildin_resetlvl(struct script_state *st);
  3143. int buildin_resetstatus(struct script_state *st);
  3144. int buildin_resetskill(struct script_state *st);
  3145. int buildin_skillpointcount(struct script_state *st);
  3146. int buildin_changebase(struct script_state *st);
  3147. int buildin_changesex(struct script_state *st);
  3148. int buildin_waitingroom(struct script_state *st);
  3149. int buildin_delwaitingroom(struct script_state *st);
  3150. int buildin_waitingroomkickall(struct script_state *st);
  3151. int buildin_enablewaitingroomevent(struct script_state *st);
  3152. int buildin_disablewaitingroomevent(struct script_state *st);
  3153. int buildin_getwaitingroomstate(struct script_state *st);
  3154. int buildin_warpwaitingpc(struct script_state *st);
  3155. int buildin_attachrid(struct script_state *st);
  3156. int buildin_detachrid(struct script_state *st);
  3157. int buildin_isloggedin(struct script_state *st);
  3158. int buildin_setmapflagnosave(struct script_state *st);
  3159. int buildin_setmapflag(struct script_state *st);
  3160. int buildin_removemapflag(struct script_state *st);
  3161. int buildin_pvpon(struct script_state *st);
  3162. int buildin_pvpoff(struct script_state *st);
  3163. int buildin_gvgon(struct script_state *st);
  3164. int buildin_gvgoff(struct script_state *st);
  3165. int buildin_emotion(struct script_state *st);
  3166. int buildin_maprespawnguildid(struct script_state *st);
  3167. int buildin_agitstart(struct script_state *st); // <Agit>
  3168. int buildin_agitend(struct script_state *st);
  3169. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  3170. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  3171. int buildin_getcastlename(struct script_state *st);
  3172. int buildin_getcastledata(struct script_state *st);
  3173. int buildin_setcastledata(struct script_state *st);
  3174. int buildin_requestguildinfo(struct script_state *st);
  3175. int buildin_getequipcardcnt(struct script_state *st);
  3176. int buildin_successremovecards(struct script_state *st);
  3177. int buildin_failedremovecards(struct script_state *st);
  3178. int buildin_marriage(struct script_state *st);
  3179. int buildin_wedding_effect(struct script_state *st);
  3180. int buildin_divorce(struct script_state *st);
  3181. int buildin_ispartneron(struct script_state *st); // MouseJstr
  3182. int buildin_getpartnerid(struct script_state *st); // MouseJstr
  3183. int buildin_getchildid(struct script_state *st); // Skotlex
  3184. int buildin_getmotherid(struct script_state *st); // Lupus
  3185. int buildin_getfatherid(struct script_state *st); // Lupus
  3186. int buildin_warppartner(struct script_state *st); // MouseJstr
  3187. int buildin_getitemname(struct script_state *st);
  3188. int buildin_getitemslots(struct script_state *st);
  3189. int buildin_makepet(struct script_state *st);
  3190. int buildin_getexp(struct script_state *st);
  3191. int buildin_getinventorylist(struct script_state *st);
  3192. int buildin_getskilllist(struct script_state *st);
  3193. int buildin_clearitem(struct script_state *st);
  3194. int buildin_classchange(struct script_state *st);
  3195. int buildin_misceffect(struct script_state *st);
  3196. int buildin_soundeffect(struct script_state *st);
  3197. int buildin_soundeffectall(struct script_state *st);
  3198. int buildin_setcastledata(struct script_state *st);
  3199. int buildin_mapwarp(struct script_state *st);
  3200. int buildin_inittimer(struct script_state *st);
  3201. int buildin_stoptimer(struct script_state *st);
  3202. int buildin_cmdothernpc(struct script_state *st);
  3203. int buildin_mobcount(struct script_state *st);
  3204. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3205. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  3206. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3207. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  3208. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  3209. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  3210. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  3211. //int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  3212. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Skotlex]
  3213. int buildin_petskillattack2(struct script_state *st); // pet skill attacks [Skotlex]
  3214. int buildin_petskillsupport(struct script_state *st); // pet support skill [Valaris]
  3215. int buildin_skilleffect(struct script_state *st); // skill effects [Celest]
  3216. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  3217. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  3218. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  3219. int buildin_nude(struct script_state *st); // nude [Valaris]
  3220. int buildin_atcommand(struct script_state *st); // [MouseJstr]
  3221. int buildin_charcommand(struct script_state *st); // [MouseJstr]
  3222. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  3223. int buildin_message(struct script_state *st); // [MouseJstr]
  3224. int buildin_npctalk(struct script_state *st); // [Valaris]
  3225. int buildin_hasitems(struct script_state *st); // [Valaris]
  3226. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  3227. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  3228. int buildin_npcspeed(struct script_state *st); // [Valaris]
  3229. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  3230. int buildin_npcstop(struct script_state *st); // [Valaris]
  3231. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  3232. int buildin_checkoption1(struct script_state *st); // [celest]
  3233. int buildin_checkoption2(struct script_state *st); // [celest]
  3234. int buildin_guildgetexp(struct script_state *st); // [celest]
  3235. int buildin_guildchangegm(struct script_state *st); // [Skotlex]
  3236. int buildin_logmes(struct script_state *st); // [Lupus]
  3237. int buildin_summon(struct script_state *st); // [celest]
  3238. int buildin_isnight(struct script_state *st); // [celest]
  3239. int buildin_isday(struct script_state *st); // [celest]
  3240. int buildin_isequipped(struct script_state *st); // [celest]
  3241. int buildin_isequippedcnt(struct script_state *st); // [celest]
  3242. int buildin_cardscnt(struct script_state *st); // [Lupus]
  3243. int buildin_getrefine(struct script_state *st); // [celest]
  3244. int buildin_adopt(struct script_state *st);
  3245. int buildin_night(struct script_state *st);
  3246. int buildin_day(struct script_state *st);
  3247. int buildin_getusersname(struct script_state *st); //jA commands added [Lupus]
  3248. int buildin_dispbottom(struct script_state *st);
  3249. int buildin_recovery(struct script_state *st);
  3250. int buildin_getpetinfo(struct script_state *st);
  3251. int buildin_checkequipedcard(struct script_state *st);
  3252. int buildin_globalmes(struct script_state *st);
  3253. int buildin_jump_zero(struct script_state *st);
  3254. int buildin_select(struct script_state *st);
  3255. int buildin_getmapmobs(struct script_state *st); //jA addition end
  3256. int buildin_unequip(struct script_state *st); // unequip [Spectre]
  3257. int buildin_getstrlen(struct script_state *st); //strlen [valaris]
  3258. int buildin_charisalpha(struct script_state *st);//isalpha [valaris]
  3259. int buildin_fakenpcname(struct script_state *st); // [Lance]
  3260. int buildin_compare(struct script_state *st); // Lordalfa, to bring strstr to Scripting Engine
  3261. int buildin_getiteminfo(struct script_state *st); //[Lupus] returns Items Buy / sell Price, etc info
  3262. int buildin_getequipcardid(struct script_state *st); //[Lupus] returns card id from quipped item card slot N
  3263. // [zBuffer] List of mathematics commands --->
  3264. int buildin_sqrt(struct script_state *st);
  3265. int buildin_pow(struct script_state *st);
  3266. int buildin_distance(struct script_state *st);
  3267. int buildin_checkcell(struct script_state *st);
  3268. // <--- [zBuffer] List of mathematics commands
  3269. // [zBuffer] List of dynamic var commands --->
  3270. int buildin_getd(struct script_state *st);
  3271. int buildin_setd(struct script_state *st);
  3272. // <--- [zBuffer] List of dynamic var commands
  3273. int buildin_petstat(struct script_state *st); // [Lance] Pet Stat Rq: Dubby
  3274. int buildin_callshop(struct script_state *st); // [Skotlex]
  3275. int buildin_npcshopitem(struct script_state *st); // [Lance]
  3276. int buildin_npcshopadditem(struct script_state *st);
  3277. int buildin_npcshopdelitem(struct script_state *st);
  3278. int buildin_equip(struct script_state *st);
  3279. int buildin_autoequip(struct script_state *st);
  3280. int buildin_setbattleflag(struct script_state *st);
  3281. int buildin_getbattleflag(struct script_state *st);
  3282. #ifndef TXT_ONLY
  3283. int buildin_query_sql(struct script_state *st);
  3284. int buildin_escape_sql(struct script_state *st);
  3285. #endif
  3286. int buildin_atoi(struct script_state *st);
  3287. int buildin_axtoi(struct script_state *st);
  3288. // [zBuffer] List of player cont commands --->
  3289. int buildin_rid2name(struct script_state *st);
  3290. int buildin_pcfollow(struct script_state *st);
  3291. int buildin_pcstopfollow(struct script_state *st);
  3292. int buildin_pcblockmove(struct script_state *st);
  3293. // <--- [zBuffer] List of player cont commands
  3294. // [zBuffer] List of mob control commands --->
  3295. int buildin_mobspawn(struct script_state *st);
  3296. int buildin_mobremove(struct script_state *st);
  3297. int buildin_getmobdata(struct script_state *st);
  3298. int buildin_setmobdata(struct script_state *st);
  3299. int buildin_mobassist(struct script_state *st);
  3300. int buildin_mobattach(struct script_state *st);
  3301. int buildin_unitwalk(struct script_state *st);
  3302. int buildin_unitkill(struct script_state *st);
  3303. int buildin_unitwarp(struct script_state *st);
  3304. int buildin_unitattack(struct script_state *st);
  3305. int buildin_unitstop(struct script_state *st);
  3306. int buildin_unittalk(struct script_state *st);
  3307. int buildin_unitemote(struct script_state *st);
  3308. int buildin_unitdeadsit(struct script_state *st);
  3309. int buildin_unitskilluseid(struct script_state *st); // originally by Qamera [celest]
  3310. int buildin_unitskillusepos(struct script_state *st); // originally by Qamera [celest]
  3311. // <--- [zBuffer] List of mob control commands
  3312. int buildin_sleep(struct script_state *st);
  3313. int buildin_sleep2(struct script_state *st);
  3314. int buildin_awake(struct script_state *st);
  3315. int buildin_getvariableofnpc(struct script_state *st);
  3316. // [blackhole89] -->
  3317. int buildin_warpportal(struct script_state *st);
  3318. // <-- [blackhole89]
  3319. int buildin_homunculus_evolution(struct script_state *st) ; //[orn]
  3320. int buildin_setitemscript(struct script_state *st);
  3321. int buildin_disguise(struct script_state *st);
  3322. int buildin_undisguise(struct script_state *st);
  3323. int buildin_getmonsterinfo(struct script_state *st); // [Lupus]
  3324. #ifdef PCRE_SUPPORT
  3325. int buildin_defpattern(struct script_state *st); // MouseJstr
  3326. int buildin_activatepset(struct script_state *st); // MouseJstr
  3327. int buildin_deactivatepset(struct script_state *st); // MouseJstr
  3328. int buildin_deletepset(struct script_state *st); // MouseJstr
  3329. #endif
  3330. struct script_function buildin_func[] = {
  3331. {buildin_mes,"mes","s"},
  3332. {buildin_next,"next",""},
  3333. {buildin_close,"close",""},
  3334. {buildin_close2,"close2",""},
  3335. {buildin_menu,"menu","*"},
  3336. {buildin_goto,"goto","l"},
  3337. {buildin_callsub,"callsub","i*"},
  3338. {buildin_callfunc,"callfunc","s*"},
  3339. {buildin_return,"return","*"},
  3340. {buildin_getarg,"getarg","i"},
  3341. {buildin_jobchange,"jobchange","i*"},
  3342. {buildin_input,"input","*"},
  3343. {buildin_warp,"warp","sii"},
  3344. {buildin_areawarp,"areawarp","siiiisii"},
  3345. {buildin_warpchar,"warpchar","siii"}, // [LuzZza]
  3346. {buildin_warpparty,"warpparty","siii"}, // [Fredzilla]
  3347. {buildin_warpguild,"warpguild","siii"}, // [Fredzilla]
  3348. {buildin_setlook,"setlook","ii"},
  3349. {buildin_set,"set","ii"},
  3350. {buildin_setarray,"setarray","ii*"},
  3351. {buildin_cleararray,"cleararray","iii"},
  3352. {buildin_copyarray,"copyarray","iii"},
  3353. {buildin_getarraysize,"getarraysize","i"},
  3354. {buildin_deletearray,"deletearray","ii"},
  3355. {buildin_getelementofarray,"getelementofarray","ii"},
  3356. {buildin_getitem,"getitem","ii**"},
  3357. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  3358. {buildin_getnameditem,"getnameditem","is"},
  3359. {buildin_grouprandomitem,"groupranditem","i"},
  3360. {buildin_makeitem,"makeitem","iisii"},
  3361. {buildin_delitem,"delitem","ii"},
  3362. {buildin_delitem2,"delitem2","iiiiiiiii"},
  3363. {buildin_enableitemuse,"enable_items",""},
  3364. {buildin_disableitemuse,"disable_items",""},
  3365. {buildin_cutin,"cutin","si"},
  3366. {buildin_cutincard,"cutincard","i"},
  3367. {buildin_viewpoint,"viewpoint","iiiii"},
  3368. {buildin_heal,"heal","ii"},
  3369. {buildin_itemheal,"itemheal","ii"},
  3370. {buildin_percentheal,"percentheal","ii"},
  3371. {buildin_rand,"rand","i*"},
  3372. {buildin_countitem,"countitem","i"},
  3373. {buildin_countitem2,"countitem2","iiiiiiii"},
  3374. {buildin_checkweight,"checkweight","ii"},
  3375. {buildin_readparam,"readparam","i*"},
  3376. {buildin_getcharid,"getcharid","i*"},
  3377. {buildin_getpartyname,"getpartyname","i"},
  3378. {buildin_getpartymember,"getpartymember","i*"},
  3379. {buildin_getpartyleader,"getpartyleader","i*"},
  3380. {buildin_getguildname,"getguildname","i"},
  3381. {buildin_getguildmaster,"getguildmaster","i"},
  3382. {buildin_getguildmasterid,"getguildmasterid","i"},
  3383. {buildin_strcharinfo,"strcharinfo","i"},
  3384. {buildin_getequipid,"getequipid","i"},
  3385. {buildin_getequipname,"getequipname","i"},
  3386. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  3387. {buildin_repair,"repair","i"}, // [Valaris]
  3388. {buildin_getequipisequiped,"getequipisequiped","i"},
  3389. {buildin_getequipisenableref,"getequipisenableref","i"},
  3390. {buildin_getequipisidentify,"getequipisidentify","i"},
  3391. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  3392. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  3393. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  3394. {buildin_successrefitem,"successrefitem","i"},
  3395. {buildin_failedrefitem,"failedrefitem","i"},
  3396. {buildin_statusup,"statusup","i"},
  3397. {buildin_statusup2,"statusup2","ii"},
  3398. {buildin_bonus,"bonus","ii"},
  3399. {buildin_bonus2,"bonus2","iii"},
  3400. {buildin_bonus3,"bonus3","iiii"},
  3401. {buildin_bonus4,"bonus4","iiiii"},
  3402. {buildin_skill,"skill","ii*"},
  3403. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  3404. {buildin_guildskill,"guildskill","ii"},
  3405. {buildin_getskilllv,"getskilllv","i"},
  3406. {buildin_getgdskilllv,"getgdskilllv","ii"},
  3407. {buildin_basicskillcheck,"basicskillcheck","*"},
  3408. {buildin_getgmlevel,"getgmlevel","*"},
  3409. {buildin_end,"end",""},
  3410. // {buildin_end,"break",""}, this might confuse advanced scripting support [Eoe]
  3411. {buildin_checkoption,"checkoption","i"},
  3412. {buildin_setoption,"setoption","i*"},
  3413. {buildin_setcart,"setcart",""},
  3414. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  3415. {buildin_setfalcon,"setfalcon",""},
  3416. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3417. {buildin_setriding,"setriding",""},
  3418. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3419. {buildin_savepoint,"save","sii"},
  3420. {buildin_savepoint,"savepoint","sii"},
  3421. {buildin_gettimetick,"gettimetick","i"},
  3422. {buildin_gettime,"gettime","i"},
  3423. {buildin_gettimestr,"gettimestr","si"},
  3424. {buildin_openstorage,"openstorage",""},
  3425. {buildin_guildopenstorage,"guildopenstorage","*"},
  3426. {buildin_itemskill,"itemskill","iis"},
  3427. {buildin_produce,"produce","i"},
  3428. {buildin_monster,"monster","siisii*"},
  3429. {buildin_areamonster,"areamonster","siiiisii*"},
  3430. {buildin_killmonster,"killmonster","ss"},
  3431. {buildin_killmonsterall,"killmonsterall","s"},
  3432. {buildin_clone,"clone","siisi*"},
  3433. {buildin_doevent,"doevent","s"},
  3434. {buildin_donpcevent,"donpcevent","s"},
  3435. {buildin_addtimer,"addtimer","is"},
  3436. {buildin_deltimer,"deltimer","s"},
  3437. {buildin_addtimercount,"addtimercount","si"},
  3438. {buildin_initnpctimer,"initnpctimer","*"},
  3439. {buildin_stopnpctimer,"stopnpctimer","*"},
  3440. {buildin_startnpctimer,"startnpctimer","*"},
  3441. {buildin_setnpctimer,"setnpctimer","*"},
  3442. {buildin_getnpctimer,"getnpctimer","i*"},
  3443. {buildin_attachnpctimer,"attachnpctimer","*"}, // attached the player id to the npc timer [Celest]
  3444. {buildin_detachnpctimer,"detachnpctimer","*"}, // detached the player id from the npc timer [Celest]
  3445. {buildin_playerattached,"playerattached",""}, // returns id of the current attached player. [Skotlex]
  3446. {buildin_announce,"announce","si*"},
  3447. {buildin_mapannounce,"mapannounce","ssi*"},
  3448. {buildin_areaannounce,"areaannounce","siiiisi*"},
  3449. {buildin_getusers,"getusers","i"},
  3450. {buildin_getmapusers,"getmapusers","s"},
  3451. {buildin_getareausers,"getareausers","siiii"},
  3452. {buildin_getareadropitem,"getareadropitem","siiiii"},
  3453. {buildin_enablenpc,"enablenpc","s"},
  3454. {buildin_disablenpc,"disablenpc","s"},
  3455. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  3456. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  3457. {buildin_hideoffnpc,"hideoffnpc","s"},
  3458. {buildin_hideonnpc,"hideonnpc","s"},
  3459. {buildin_sc_start,"sc_start","iii*"},
  3460. {buildin_sc_start2,"sc_start2","iiii*"},
  3461. {buildin_sc_start4,"sc_start4","iiiiii*"},
  3462. {buildin_sc_end,"sc_end","i"},
  3463. {buildin_getscrate,"getscrate","ii*"},
  3464. {buildin_debugmes,"debugmes","s"},
  3465. {buildin_catchpet,"pet","i"},
  3466. {buildin_birthpet,"bpet",""},
  3467. {buildin_resetlvl,"resetlvl","i"},
  3468. {buildin_resetstatus,"resetstatus",""},
  3469. {buildin_resetskill,"resetskill",""},
  3470. {buildin_skillpointcount,"skillpointcount",""},
  3471. {buildin_changebase,"changebase","i"},
  3472. {buildin_changesex,"changesex",""},
  3473. {buildin_waitingroom,"waitingroom","si*"},
  3474. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  3475. {buildin_delwaitingroom,"delwaitingroom","*"},
  3476. {buildin_waitingroomkickall,"kickwaitingroomall","*"},
  3477. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  3478. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  3479. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  3480. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  3481. {buildin_attachrid,"attachrid","i"},
  3482. {buildin_detachrid,"detachrid",""},
  3483. {buildin_isloggedin,"isloggedin","i"},
  3484. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  3485. {buildin_setmapflag,"setmapflag","si*"},
  3486. {buildin_removemapflag,"removemapflag","si"},
  3487. {buildin_pvpon,"pvpon","s"},
  3488. {buildin_pvpoff,"pvpoff","s"},
  3489. {buildin_gvgon,"gvgon","s"},
  3490. {buildin_gvgoff,"gvgoff","s"},
  3491. {buildin_emotion,"emotion","i*"},
  3492. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  3493. {buildin_agitstart,"agitstart",""}, // <Agit>
  3494. {buildin_agitend,"agitend",""},
  3495. {buildin_agitcheck,"agitcheck","i"}, // <Agitcheck>
  3496. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  3497. {buildin_getcastlename,"getcastlename","s"},
  3498. {buildin_getcastledata,"getcastledata","si*"},
  3499. {buildin_setcastledata,"setcastledata","sii"},
  3500. {buildin_requestguildinfo,"requestguildinfo","i*"},
  3501. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  3502. {buildin_successremovecards,"successremovecards","i"},
  3503. {buildin_failedremovecards,"failedremovecards","ii"},
  3504. {buildin_marriage,"marriage","s"},
  3505. {buildin_wedding_effect,"wedding",""},
  3506. {buildin_divorce,"divorce",""},
  3507. {buildin_ispartneron,"ispartneron",""},
  3508. {buildin_getpartnerid,"getpartnerid",""},
  3509. {buildin_getchildid,"getchildid",""},
  3510. {buildin_getmotherid,"getmotherid",""},
  3511. {buildin_getfatherid,"getfatherid",""},
  3512. {buildin_warppartner,"warppartner","sii"},
  3513. {buildin_getitemname,"getitemname","i"},
  3514. {buildin_getitemslots,"getitemslots","i"},
  3515. {buildin_makepet,"makepet","i"},
  3516. {buildin_getexp,"getexp","ii"},
  3517. {buildin_getinventorylist,"getinventorylist",""},
  3518. {buildin_getskilllist,"getskilllist",""},
  3519. {buildin_clearitem,"clearitem",""},
  3520. {buildin_classchange,"classchange","ii"},
  3521. {buildin_misceffect,"misceffect","i"},
  3522. {buildin_soundeffect,"soundeffect","si"},
  3523. {buildin_soundeffectall,"soundeffectall","si*"}, // SoundEffectAll [Codemaster]
  3524. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  3525. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  3526. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  3527. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  3528. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  3529. {buildin_petloot,"petloot","i"}, // [Valaris]
  3530. {buildin_petheal,"petheal","iiii"}, // [Valaris]
  3531. // {buildin_petmag,"petmag","iiii"}, // [Valaris]
  3532. {buildin_petskillattack,"petskillattack","iiii"}, // [Skotlex]
  3533. {buildin_petskillattack2,"petskillattack2","iiiii"}, // [Valaris]
  3534. {buildin_petskillsupport,"petskillsupport","iiiii"}, // [Skotlex]
  3535. {buildin_skilleffect,"skilleffect","ii"}, // skill effect [Celest]
  3536. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  3537. {buildin_specialeffect,"specialeffect","i*"}, // npc skill effect [Valaris]
  3538. {buildin_specialeffect2,"specialeffect2","i*"}, // skill effect on players[Valaris]
  3539. {buildin_nude,"nude",""}, // nude command [Valaris]
  3540. {buildin_mapwarp,"mapwarp","ssii"}, // Added by RoVeRT
  3541. {buildin_inittimer,"inittimer",""},
  3542. {buildin_stoptimer,"stoptimer",""},
  3543. {buildin_cmdothernpc,"cmdothernpc","ss"},
  3544. {buildin_atcommand,"atcommand","*"}, // [MouseJstr]
  3545. {buildin_charcommand,"charcommand","*"}, // [MouseJstr]
  3546. {buildin_movenpc,"movenpc","sii"}, // [MouseJstr]
  3547. {buildin_message,"message","s*"}, // [MouseJstr]
  3548. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  3549. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  3550. {buildin_mobcount,"mobcount","ss"},
  3551. {buildin_getlook,"getlook","i"},
  3552. {buildin_getsavepoint,"getsavepoint","i"},
  3553. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  3554. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  3555. {buildin_npcstop,"npcstop",""}, // [Valaris]
  3556. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  3557. {buildin_checkoption1,"checkoption1","i"},
  3558. {buildin_checkoption2,"checkoption2","i"},
  3559. {buildin_guildgetexp,"guildgetexp","i"},
  3560. {buildin_guildchangegm,"guildchangegm","is"},
  3561. {buildin_logmes,"logmes","s"}, //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
  3562. {buildin_summon,"summon","si*"}, // summons a slave monster [Celest]
  3563. {buildin_isnight,"isnight",""}, // check whether it is night time [Celest]
  3564. {buildin_isday,"isday",""}, // check whether it is day time [Celest]
  3565. {buildin_isequipped,"isequipped","i*"}, // check whether another item/card has been equipped [Celest]
  3566. {buildin_isequippedcnt,"isequippedcnt","i*"}, // check how many items/cards are being equipped [Celest]
  3567. {buildin_cardscnt,"cardscnt","i*"}, // check how many items/cards are being equipped in the same arm [Lupus]
  3568. {buildin_getrefine,"getrefine","*"}, // returns the refined number of the current item, or an item with index specified [celest]
  3569. {buildin_adopt,"adopt","sss"}, // allows 2 parents to adopt a child
  3570. {buildin_night,"night",""}, // sets the server to night time
  3571. {buildin_day,"day",""}, // sets the server to day time
  3572. #ifdef PCRE_SUPPORT
  3573. {buildin_defpattern, "defpattern", "iss"}, // Define pattern to listen for [MouseJstr]
  3574. {buildin_activatepset, "activatepset", "i"}, // Activate a pattern set [MouseJstr]
  3575. {buildin_deactivatepset, "deactivatepset", "i"}, // Deactive a pattern set [MouseJstr]
  3576. {buildin_deletepset, "deletepset", "i"}, // Delete a pattern set [MouseJstr]
  3577. #endif
  3578. {buildin_dispbottom,"dispbottom","s"}, //added from jA [Lupus]
  3579. {buildin_getusersname,"getusersname","*"},
  3580. {buildin_recovery,"recovery",""},
  3581. {buildin_getpetinfo,"getpetinfo","i"},
  3582. {buildin_checkequipedcard,"checkequipedcard","i"},
  3583. {buildin_jump_zero,"jump_zero","ii"}, //for future jA script compatibility
  3584. {buildin_select,"select","*"}, //for future jA script compatibility
  3585. {buildin_globalmes,"globalmes","s*"},
  3586. {buildin_getmapmobs,"getmapmobs","s"}, //end jA addition
  3587. {buildin_unequip,"unequip","i"}, // unequip command [Spectre]
  3588. {buildin_getstrlen,"getstrlen","s"}, //strlen [Valaris]
  3589. {buildin_charisalpha,"charisalpha","si"}, //isalpha [Valaris]
  3590. {buildin_fakenpcname,"fakenpcname","ssi"}, // [Lance]
  3591. {buildin_compare,"compare","ss"}, // Lordalfa - To bring strstr to scripting Engine.
  3592. {buildin_getiteminfo,"getiteminfo","ii"}, //[Lupus] returns Items Buy / sell Price, etc info
  3593. {buildin_getequipcardid,"getequipcardid","ii"}, //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
  3594. // [zBuffer] List of mathematics commands --->
  3595. {buildin_sqrt,"sqrt","i"},
  3596. {buildin_pow,"pow","ii"},
  3597. {buildin_distance,"distance","iiii"},
  3598. {buildin_checkcell,"checkcell","siii"},
  3599. // <--- [zBuffer] List of mathematics commands
  3600. // [zBuffer] List of dynamic var commands --->
  3601. {buildin_getd,"getd","*"},
  3602. {buildin_setd,"setd","*"},
  3603. // <--- [zBuffer] List of dynamic var commands
  3604. {buildin_petstat,"petstat","i"},
  3605. {buildin_callshop,"callshop","si"}, // [Skotlex]
  3606. {buildin_npcshopitem,"npcshopitem","sii*"}, // [Lance]
  3607. {buildin_npcshopadditem,"npcshopadditem","sii*"},
  3608. {buildin_npcshopdelitem,"npcshopdelitem","si*"},
  3609. {buildin_equip,"equip","i"},
  3610. {buildin_autoequip,"autoequip","ii"},
  3611. {buildin_setbattleflag,"setbattleflag","ss"},
  3612. {buildin_getbattleflag,"getbattleflag","s"},
  3613. {buildin_setitemscript,"setitemscript","is"}, //Set NEW item bonus script. Lupus
  3614. {buildin_disguise,"disguise","i"}, //disguise player. Lupus
  3615. {buildin_undisguise,"undisguise","i"}, //undisguise player. Lupus
  3616. {buildin_getmonsterinfo,"getmonsterinfo","ii"}, //Lupus
  3617. {buildin_axtoi,"axtoi","s"},
  3618. #ifndef TXT_ONLY
  3619. {buildin_query_sql, "query_sql", "s*"},
  3620. {buildin_escape_sql, "escape_sql", "s"},
  3621. #endif
  3622. {buildin_atoi,"atoi","s"},
  3623. // [zBuffer] List of player cont commands --->
  3624. {buildin_rid2name,"rid2name","i"},
  3625. {buildin_pcfollow,"pcfollow","ii"},
  3626. {buildin_pcstopfollow,"pcstopfollow","i"},
  3627. {buildin_pcblockmove,"pcblockmove","ii"},
  3628. // <--- [zBuffer] List of player cont commands
  3629. // [zBuffer] List of mob control commands --->
  3630. {buildin_mobspawn,"mobspawn","*"},
  3631. {buildin_mobremove,"mobremove","i"},
  3632. {buildin_getmobdata,"getmobdata","i*"},
  3633. {buildin_setmobdata,"setmobdata","iii"},
  3634. {buildin_mobassist,"mobassist","i*"},
  3635. {buildin_mobattach,"mobattach","i*"},
  3636. {buildin_unitwalk,"unitwalk","i*"},
  3637. {buildin_unitkill,"unitkill","i"},
  3638. {buildin_unitwarp,"unitwarp","isii"},
  3639. {buildin_unitattack,"unitattack","i*"},
  3640. {buildin_unitstop,"unitstop","i"},
  3641. {buildin_unittalk,"unittalk","is"},
  3642. {buildin_unitemote,"unitemote","ii"},
  3643. {buildin_unitdeadsit,"unitdeadsit","ii"},
  3644. {buildin_unitskilluseid,"unitskilluseid","iii*"}, // originally by Qamera [Celest]
  3645. {buildin_unitskillusepos,"unitskillusepos","iiiii"}, // [Celest]
  3646. // <--- [zBuffer] List of mob control commands
  3647. {buildin_sleep,"sleep","i"},
  3648. {buildin_sleep2,"sleep2","i"},
  3649. {buildin_awake,"awake","s"},
  3650. {buildin_getvariableofnpc,"getvariableofnpc","is"},
  3651. // [blackhole89] -->
  3652. {buildin_warpportal,"warpportal","iisii"},
  3653. // <--- [blackhole89]
  3654. {buildin_homunculus_evolution,"homevolution",""}, //[orn]
  3655. {NULL,NULL,NULL},
  3656. };
  3657. /*==========================================
  3658. *
  3659. *------------------------------------------
  3660. */
  3661. int buildin_mes(struct script_state *st)
  3662. {
  3663. conv_str(st,& (st->stack->stack_data[st->start+2]));
  3664. clif_scriptmes(script_rid2sd(st),st->oid,st->stack->stack_data[st->start+2].u.str);
  3665. return 0;
  3666. }
  3667. /*==========================================
  3668. *
  3669. *------------------------------------------
  3670. */
  3671. int buildin_goto(struct script_state *st)
  3672. {
  3673. int pos;
  3674. if( st->stack->stack_data[st->start+2].type!=C_POS){
  3675. ShowMessage("script: goto: not label!\n");
  3676. st->state=END;
  3677. return 1;
  3678. }
  3679. pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3680. st->pos=pos;
  3681. st->state=GOTO;
  3682. return 0;
  3683. }
  3684. /*==========================================
  3685. * ユーザー定義関数の呼び出し
  3686. *------------------------------------------
  3687. */
  3688. int buildin_callfunc(struct script_state *st)
  3689. {
  3690. struct script_code *scr, *oldscr;
  3691. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3692. if( (scr=strdb_get(userfunc_db,(unsigned char*)str)) ){
  3693. int i,j;
  3694. struct linkdb_node **oldval = st->stack->var_function;
  3695. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3696. push_copy(st->stack,i);
  3697. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3698. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3699. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3700. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3701. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3702. oldscr = st->script;
  3703. st->pos=0;
  3704. st->script=scr;
  3705. st->stack->defsp=st->start+5+j;
  3706. st->state=GOTO;
  3707. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3708. // ' 変数の引き継ぎ
  3709. for(i = 0; i < j; i++) {
  3710. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3711. if( s->type == C_NAME && !s->ref ) {
  3712. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3713. // '@ 変数の引き継ぎ
  3714. if( name[0] == '.' && name[1] == '@' ) {
  3715. s->ref = oldval;
  3716. } else if( name[0] == '.' ) {
  3717. s->ref = &oldscr->script_vars;
  3718. }
  3719. }
  3720. }
  3721. }else{
  3722. ShowWarning("script:callfunc: function not found! [%s]\n",str);
  3723. st->state=END;
  3724. return 1;
  3725. }
  3726. return 0;
  3727. }
  3728. /*==========================================
  3729. * サブルーティンの呼び出し
  3730. *------------------------------------------
  3731. */
  3732. int buildin_callsub(struct script_state *st)
  3733. {
  3734. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3735. int i,j;
  3736. if(st->stack->stack_data[st->start+2].type != C_POS && st->stack->stack_data[st->start+2].type != C_USERFUNC_POS) {
  3737. ShowError("script: callsub: not label !\n");
  3738. st->state=END;
  3739. return 1;
  3740. } else {
  3741. struct linkdb_node **oldval = st->stack->var_function;
  3742. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3743. push_copy(st->stack,i);
  3744. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3745. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3746. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3747. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3748. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3749. st->pos=pos;
  3750. st->stack->defsp=st->start+5+j;
  3751. st->state=GOTO;
  3752. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3753. // ' 変数の引き継ぎ
  3754. for(i = 0; i < j; i++) {
  3755. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3756. if( s->type == C_NAME && !s->ref ) {
  3757. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3758. // '@ 変数の引き継ぎ
  3759. if( name[0] == '.' && name[1] == '@' ) {
  3760. s->ref = oldval;
  3761. }
  3762. }
  3763. }
  3764. }
  3765. return 0;
  3766. }
  3767. /*==========================================
  3768. * 引数の所得
  3769. *------------------------------------------
  3770. */
  3771. int buildin_getarg(struct script_state *st)
  3772. {
  3773. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3774. int max,stsp;
  3775. if( st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO ){
  3776. ShowWarning("script:getarg without callfunc or callsub!\n");
  3777. st->state=END;
  3778. return 1;
  3779. }
  3780. max=conv_num(st,& (st->stack->stack_data[st->stack->defsp-5]));
  3781. stsp=st->stack->defsp - max -5;
  3782. if( num >= max ){
  3783. ShowWarning("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  3784. st->state=END;
  3785. return 1;
  3786. }
  3787. push_copy(st->stack,stsp+num);
  3788. return 0;
  3789. }
  3790. /*==========================================
  3791. * サブルーチン/ユーザー定義関数の終了
  3792. *------------------------------------------
  3793. */
  3794. int buildin_return(struct script_state *st)
  3795. {
  3796. if(st->end>st->start+2){ // 戻り値有り
  3797. struct script_data *sd;
  3798. push_copy(st->stack,st->start+2);
  3799. sd = &st->stack->stack_data[st->stack->sp-1];
  3800. if(sd->type == C_NAME) {
  3801. char *name = str_buf + str_data[sd->u.num&0x00ffffff].str;
  3802. if( name[0] == '.' && name[1] == '@') {
  3803. // '@ 変数を参照渡しにすると危険なので値渡しにする
  3804. get_val(st,sd);
  3805. } else if( name[0] == '.' && !sd->ref) {
  3806. // ' 変数は参照渡しでも良いが、参照元が設定されていないと
  3807. // 元のスクリプトの値を差してしまうので補正する。
  3808. sd->ref = &st->script->script_vars;
  3809. }
  3810. }
  3811. }
  3812. st->state=RETFUNC;
  3813. return 0;
  3814. }
  3815. /*==========================================
  3816. *
  3817. *------------------------------------------
  3818. */
  3819. int buildin_next(struct script_state *st)
  3820. {
  3821. st->state=STOP;
  3822. clif_scriptnext(script_rid2sd(st),st->oid);
  3823. return 0;
  3824. }
  3825. /*==========================================
  3826. *
  3827. *------------------------------------------
  3828. */
  3829. int buildin_close(struct script_state *st)
  3830. {
  3831. st->state=END;
  3832. clif_scriptclose(script_rid2sd(st),st->oid);
  3833. return 0;
  3834. }
  3835. int buildin_close2(struct script_state *st)
  3836. {
  3837. st->state=STOP;
  3838. clif_scriptclose(script_rid2sd(st),st->oid);
  3839. return 0;
  3840. }
  3841. /*==========================================
  3842. *
  3843. *------------------------------------------
  3844. */
  3845. int buildin_menu(struct script_state *st)
  3846. {
  3847. char *buf;
  3848. int len,i;
  3849. struct map_session_data *sd = script_rid2sd(st);
  3850. nullpo_retr(0, sd);
  3851. if(sd->state.menu_or_input==0){
  3852. st->state=RERUNLINE;
  3853. sd->state.menu_or_input=1;
  3854. if( (st->end - st->start - 2) % 2 == 1 ) {
  3855. // 引数の数が奇数なのでエラー扱い
  3856. ShowError("buildin_menu: illigal argument count(%d).\n", st->end - st->start - 2);
  3857. sd->state.menu_or_input=0;
  3858. st->state=END;
  3859. return 1;
  3860. }
  3861. for(i=st->start+2,len=0;i<st->end;i+=2){
  3862. conv_str(st,& (st->stack->stack_data[i]));
  3863. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  3864. }
  3865. buf=(char *)aMallocA((len+1)*sizeof(char));
  3866. buf[0]=0;
  3867. for(i=st->start+2,len=0;i<st->end;i+=2){
  3868. if( st->stack->stack_data[i].u.str[0] ) {
  3869. strcat(buf,st->stack->stack_data[i].u.str);
  3870. strcat(buf,":");
  3871. }
  3872. }
  3873. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  3874. aFree(buf);
  3875. } else if(sd->npc_menu==0xff){ // cansel
  3876. sd->state.menu_or_input=0;
  3877. st->state=END;
  3878. } else { // goto動作
  3879. sd->state.menu_or_input=0;
  3880. if(sd->npc_menu>0){
  3881. //Skip empty menu entries which weren't displayed on the client (blackhole89)
  3882. for(i=st->start+2;i<=(st->start+sd->npc_menu*2) && sd->npc_menu<(st->end-st->start)/2;i+=2) {
  3883. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  3884. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  3885. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  3886. }
  3887. if(sd->npc_menu >= (st->end-st->start)/2) {
  3888. //Invalid selection.
  3889. st->state=END;
  3890. return 0;
  3891. }
  3892. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  3893. ShowError("script: menu: not label !\n");
  3894. st->state=END;
  3895. return 1;
  3896. }
  3897. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  3898. st->pos=conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  3899. st->state=GOTO;
  3900. }
  3901. }
  3902. return 0;
  3903. }
  3904. /*==========================================
  3905. *
  3906. *------------------------------------------
  3907. */
  3908. int buildin_rand(struct script_state *st)
  3909. {
  3910. int range,min,max;
  3911. if (st->end > st->start+3){
  3912. min = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3913. max = conv_num(st,& (st->stack->stack_data[st->start+3]));
  3914. if (max == min){ //Why would someone do this?
  3915. push_val(st->stack,C_INT,min);
  3916. return 0;
  3917. }
  3918. if(max<min){
  3919. int tmp = min;
  3920. min = max;
  3921. max = tmp;
  3922. }
  3923. range = max - min + 1;
  3924. if (range == 0) range = 1;
  3925. push_val(st->stack,C_INT,rand()%range+min);
  3926. } else {
  3927. range = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3928. if (range == 0) range = 1;
  3929. push_val(st->stack,C_INT,rand()%range);
  3930. }
  3931. return 0;
  3932. }
  3933. /*==========================================
  3934. *
  3935. *------------------------------------------
  3936. */
  3937. int buildin_warp(struct script_state *st)
  3938. {
  3939. int x,y;
  3940. char *str;
  3941. struct map_session_data *sd=script_rid2sd(st);
  3942. nullpo_retr(0, sd);
  3943. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3944. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3945. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3946. if(strcmp(str,"Random")==0)
  3947. pc_randomwarp(sd,3);
  3948. else if(strcmp(str,"SavePoint")==0){
  3949. pc_setpos(sd,sd->status.save_point.map,
  3950. sd->status.save_point.x,sd->status.save_point.y,3);
  3951. }else if(strcmp(str,"Save")==0){
  3952. pc_setpos(sd,sd->status.save_point.map,
  3953. sd->status.save_point.x,sd->status.save_point.y,3);
  3954. }else
  3955. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  3956. return 0;
  3957. }
  3958. /*==========================================
  3959. * エリア指定ワープ
  3960. *------------------------------------------
  3961. */
  3962. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  3963. {
  3964. int x,y;
  3965. unsigned int map;
  3966. map=va_arg(ap, unsigned int);
  3967. x=va_arg(ap,int);
  3968. y=va_arg(ap,int);
  3969. if(map == 0)
  3970. pc_randomwarp((struct map_session_data *)bl,3);
  3971. else
  3972. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  3973. return 0;
  3974. }
  3975. int buildin_areawarp(struct script_state *st)
  3976. {
  3977. int x,y,m;
  3978. unsigned int index;
  3979. char *str;
  3980. char *mapname;
  3981. int x0,y0,x1,y1;
  3982. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3983. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3984. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3985. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3986. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3987. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  3988. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3989. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3990. if( (m=map_mapname2mapid(mapname))< 0)
  3991. return 0;
  3992. if(strcmp(str,"Random")==0)
  3993. index = 0;
  3994. else if(!(index=mapindex_name2id(str)))
  3995. return 0;
  3996. map_foreachinarea(buildin_areawarp_sub,
  3997. m,x0,y0,x1,y1,BL_PC, index,x,y );
  3998. return 0;
  3999. }
  4000. /*==========================================
  4001. * warpchar [LuzZza]
  4002. * Useful for warp one player from
  4003. * another player npc-session.
  4004. * Using: warpchar "mapname.gat",x,y,Char_ID;
  4005. *------------------------------------------
  4006. */
  4007. int buildin_warpchar(struct script_state *st)
  4008. {
  4009. int x,y,a,i;
  4010. char *str;
  4011. struct map_session_data *sd, **pl_allsd;
  4012. int users;
  4013. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4014. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4015. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4016. a=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4017. pl_allsd = map_getallusers(&users);
  4018. for(i=0; i<users; i++) {
  4019. sd = pl_allsd[i];
  4020. if(sd->status.char_id == a) {
  4021. if(strcmp(str, "Random") == 0)
  4022. pc_randomwarp(sd, 3);
  4023. else if(strcmp(str, "SavePoint") == 0)
  4024. pc_setpos(sd, sd->status.save_point.map,
  4025. sd->status.save_point.x, sd->status.save_point.y, 3);
  4026. else
  4027. pc_setpos(sd, mapindex_name2id(str), x, y, 3);
  4028. }
  4029. }
  4030. return 0;
  4031. }
  4032. /*==========================================
  4033. * Warpparty - [Fredzilla]
  4034. * Syntax: warpparty "mapname.gat",x,y,Party_ID;
  4035. *------------------------------------------
  4036. */
  4037. int buildin_warpparty(struct script_state *st)
  4038. {
  4039. int x,y;
  4040. char *str;
  4041. int p_id;
  4042. int i;
  4043. unsigned short mapindex;
  4044. struct map_session_data *pl_sd;
  4045. struct party_data *p=NULL;
  4046. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4047. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4048. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4049. p_id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4050. if(p_id < 1)
  4051. return 0;
  4052. p = party_search(p_id);
  4053. if (!p)
  4054. return 0;
  4055. if(strcmp(str,"Random")==0)
  4056. {
  4057. for (i = 0; i < MAX_PARTY; i++)
  4058. {
  4059. if ((pl_sd = p->data[i].sd))
  4060. {
  4061. if(map[pl_sd->bl.m].flag.nowarp)
  4062. continue;
  4063. pc_randomwarp(pl_sd,3);
  4064. }
  4065. }
  4066. }
  4067. else if(strcmp(str,"SavePointAll")==0)
  4068. {
  4069. for (i = 0; i < MAX_PARTY; i++)
  4070. {
  4071. if ((pl_sd = p->data[i].sd))
  4072. {
  4073. if(map[pl_sd->bl.m].flag.noreturn)
  4074. continue;
  4075. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4076. }
  4077. }
  4078. }
  4079. else if(strcmp(str,"SavePoint")==0)
  4080. {
  4081. pl_sd=script_rid2sd(st);
  4082. if (!pl_sd) return 0;
  4083. mapindex=pl_sd->status.save_point.map;
  4084. x=pl_sd->status.save_point.x;
  4085. y=pl_sd->status.save_point.y;
  4086. for (i = 0; i < MAX_PARTY; i++)
  4087. {
  4088. if ((pl_sd = p->data[i].sd))
  4089. {
  4090. if(map[pl_sd->bl.m].flag.noreturn)
  4091. continue;
  4092. pc_setpos(pl_sd,mapindex,x,y,3);
  4093. }
  4094. }
  4095. }
  4096. else
  4097. {
  4098. mapindex = mapindex_name2id(str);
  4099. if (!mapindex) //Show source of npc error.
  4100. return 1;
  4101. for (i = 0; i < MAX_PARTY; i++)
  4102. {
  4103. if ((pl_sd = p->data[i].sd))
  4104. {
  4105. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4106. continue;
  4107. pc_setpos(pl_sd,mapindex,x,y,3);
  4108. }
  4109. }
  4110. }
  4111. return 0;
  4112. }
  4113. /*==========================================
  4114. * Warpguild - [Fredzilla]
  4115. * Syntax: warpguild "mapname.gat",x,y,Guild_ID;
  4116. *------------------------------------------
  4117. */
  4118. int buildin_warpguild(struct script_state *st)
  4119. {
  4120. int x,y;
  4121. unsigned short mapindex;
  4122. char *str;
  4123. int g;
  4124. int i;
  4125. struct map_session_data *pl_sd, **pl_allsd;
  4126. int users;
  4127. struct map_session_data *sd;
  4128. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4129. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4130. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4131. g=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4132. sd=script_rid2sd(st);
  4133. if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
  4134. return 0;
  4135. if(g < 1)
  4136. return 0;
  4137. pl_allsd = map_getallusers(&users);
  4138. if(strcmp(str,"Random")==0)
  4139. {
  4140. for (i = 0; i < users; i++)
  4141. {
  4142. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4143. {
  4144. if(map[pl_sd->bl.m].flag.nowarp)
  4145. continue;
  4146. pc_randomwarp(pl_sd,3);
  4147. }
  4148. }
  4149. }
  4150. else if(strcmp(str,"SavePointAll")==0)
  4151. {
  4152. if(map[sd->bl.m].flag.noreturn)
  4153. return 0;
  4154. for (i = 0; i < users; i++)
  4155. {
  4156. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4157. {
  4158. if(map[pl_sd->bl.m].flag.noreturn)
  4159. continue;
  4160. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4161. }
  4162. }
  4163. }
  4164. else if(strcmp(str,"SavePoint")==0)
  4165. {
  4166. if(map[sd->bl.m].flag.noreturn)
  4167. return 0;
  4168. mapindex=sd->status.save_point.map;
  4169. x=sd->status.save_point.x;
  4170. y=sd->status.save_point.y;
  4171. for (i = 0; i < users; i++)
  4172. {
  4173. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4174. {
  4175. if(map[pl_sd->bl.m].flag.noreturn)
  4176. continue;
  4177. pc_setpos(pl_sd,mapindex,x,y,3);
  4178. }
  4179. }
  4180. }
  4181. else
  4182. {
  4183. mapindex = mapindex_name2id(str);
  4184. for (i = 0; i < users; i++)
  4185. {
  4186. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4187. {
  4188. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4189. continue;
  4190. pc_setpos(pl_sd,mapindex,x,y,3);
  4191. }
  4192. }
  4193. }
  4194. return 0;
  4195. }
  4196. /*==========================================
  4197. *
  4198. *------------------------------------------
  4199. */
  4200. int buildin_heal(struct script_state *st)
  4201. {
  4202. struct map_session_data *sd;
  4203. int hp,sp;
  4204. sd = script_rid2sd(st);
  4205. if (!sd) return 0;
  4206. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4207. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4208. status_heal(&sd->bl, hp, sp, 1);
  4209. return 0;
  4210. }
  4211. /*==========================================
  4212. *
  4213. *------------------------------------------
  4214. */
  4215. int buildin_itemheal(struct script_state *st)
  4216. {
  4217. struct map_session_data *sd;
  4218. int hp,sp;
  4219. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4220. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4221. if(potion_flag==1) {
  4222. potion_hp = hp;
  4223. potion_sp = sp;
  4224. return 0;
  4225. }
  4226. sd = script_rid2sd(st);
  4227. if (!sd) return 0;
  4228. pc_itemheal(sd,sd->itemid,hp,sp);
  4229. return 0;
  4230. }
  4231. /*==========================================
  4232. *
  4233. *------------------------------------------
  4234. */
  4235. int buildin_percentheal(struct script_state *st)
  4236. {
  4237. int hp,sp;
  4238. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4239. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4240. if(potion_flag==1) {
  4241. potion_per_hp = hp;
  4242. potion_per_sp = sp;
  4243. return 0;
  4244. }
  4245. pc_percentheal(script_rid2sd(st),hp,sp);
  4246. return 0;
  4247. }
  4248. /*==========================================
  4249. *
  4250. *------------------------------------------
  4251. */
  4252. int buildin_jobchange(struct script_state *st)
  4253. {
  4254. int job, upper=-1;
  4255. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4256. if( st->end>st->start+3 )
  4257. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4258. if ((job >= 0 && job < MAX_PC_CLASS)){
  4259. pc_jobchange(script_rid2sd(st),job, upper);
  4260. if(use_irc && irc_announce_jobchange_flag)
  4261. irc_announce_jobchange(script_rid2sd(st));
  4262. }
  4263. return 0;
  4264. }
  4265. /*==========================================
  4266. *
  4267. *------------------------------------------
  4268. */
  4269. int buildin_input(struct script_state *st)
  4270. {
  4271. struct map_session_data *sd = script_rid2sd(st);
  4272. int num = (st->end>st->start+2)? st->stack->stack_data[st->start+2].u.num: 0;
  4273. char *name = (st->end>st->start+2)? str_buf+str_data[num&0x00ffffff].str: "";
  4274. char postfix=name[strlen(name)-1];
  4275. nullpo_retr(0, sd);
  4276. if(sd->state.menu_or_input){
  4277. sd->state.menu_or_input=0;
  4278. if( postfix=='$' ){
  4279. // 文字列
  4280. if(st->end>st->start+2){ // 引数1個
  4281. set_reg(st,sd,num,name,(void*)sd->npc_str,st->stack->stack_data[st->start+2].ref);
  4282. }else{
  4283. ShowError("buildin_input: string discarded !!\n");
  4284. return 1;
  4285. }
  4286. return 0;
  4287. }
  4288. // commented by Lupus (check Value Number Input fix in clif.c)
  4289. // readded by Yor: set ammount to 0 instead of cancel trade.
  4290. // ** Fix by fritz :X keeps people from abusing old input bugs
  4291. if (sd->npc_amount < 0) { //** If input amount is less then 0
  4292. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  4293. // buildin_close(st); // ** close
  4294. sd->npc_amount = 0;
  4295. } else if ((unsigned int)sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  4296. sd->npc_amount = battle_config.vending_max_value;
  4297. // 数値
  4298. if(st->end>st->start+2){ // 引数1個
  4299. set_reg(st,sd,num,name,(void*)sd->npc_amount,st->stack->stack_data[st->start+2].ref);
  4300. } else {
  4301. // ragemu互換のため
  4302. //pc_setreg(sd,add_str((unsigned char *) "l14"),sd->npc_amount);
  4303. }
  4304. return 0;
  4305. }
  4306. //state.menu_or_input = 0
  4307. st->state=RERUNLINE;
  4308. if(postfix=='$')
  4309. clif_scriptinputstr(sd,st->oid);
  4310. else
  4311. clif_scriptinput(sd,st->oid);
  4312. sd->state.menu_or_input=1;
  4313. return 0;
  4314. }
  4315. /*==========================================
  4316. * 変数設定
  4317. *------------------------------------------
  4318. */
  4319. int buildin_set(struct script_state *st)
  4320. {
  4321. struct map_session_data *sd=NULL;
  4322. int num=st->stack->stack_data[st->start+2].u.num;
  4323. char *name=str_buf+str_data[num&0x00ffffff].str;
  4324. char prefix=*name;
  4325. char postfix=name[strlen(name)-1];
  4326. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  4327. ShowError("script: buildin_set: not name\n");
  4328. return 1;
  4329. }
  4330. if(not_server_variable(prefix))
  4331. sd=script_rid2sd(st);
  4332. if( postfix=='$' ){
  4333. // 文字列
  4334. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  4335. set_reg(st,sd,num,name,(void*)str,st->stack->stack_data[st->start+2].ref);
  4336. }else{
  4337. // 数値
  4338. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  4339. set_reg(st,sd,num,name,(void*)val,st->stack->stack_data[st->start+2].ref);
  4340. }
  4341. return 0;
  4342. }
  4343. /*==========================================
  4344. * 配列変数設定
  4345. *------------------------------------------
  4346. */
  4347. int buildin_setarray(struct script_state *st)
  4348. {
  4349. struct map_session_data *sd=NULL;
  4350. int num=st->stack->stack_data[st->start+2].u.num;
  4351. char *name=str_buf+str_data[num&0x00ffffff].str;
  4352. char prefix=*name;
  4353. char postfix=name[strlen(name)-1];
  4354. int i,j;
  4355. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4356. ShowWarning("buildin_setarray: illegal scope !\n");
  4357. return 1;
  4358. }
  4359. if(not_server_variable(prefix))
  4360. sd=script_rid2sd(st);
  4361. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  4362. void *v;
  4363. if( postfix=='$' )
  4364. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  4365. else
  4366. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  4367. set_reg(st, sd, num+(j<<24), name, v, st->stack->stack_data[st->start+2].ref);
  4368. }
  4369. return 0;
  4370. }
  4371. /*==========================================
  4372. * 配列変数クリア
  4373. *------------------------------------------
  4374. */
  4375. int buildin_cleararray(struct script_state *st)
  4376. {
  4377. struct map_session_data *sd=NULL;
  4378. int num=st->stack->stack_data[st->start+2].u.num;
  4379. char *name=str_buf+str_data[num&0x00ffffff].str;
  4380. char prefix=*name;
  4381. char postfix=name[strlen(name)-1];
  4382. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4383. int i;
  4384. void *v;
  4385. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4386. ShowWarning("buildin_cleararray: illegal scope !\n");
  4387. return 1;
  4388. }
  4389. if( not_server_variable(prefix) )
  4390. sd=script_rid2sd(st);
  4391. if( postfix=='$' )
  4392. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  4393. else
  4394. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  4395. for(i=0;i<sz;i++)
  4396. set_reg(st,sd,num+(i<<24),name,v,st->stack->stack_data[st->start+2].ref);
  4397. return 0;
  4398. }
  4399. /*==========================================
  4400. * 配列変数コピー
  4401. *------------------------------------------
  4402. */
  4403. int buildin_copyarray(struct script_state *st)
  4404. {
  4405. struct map_session_data *sd=NULL;
  4406. int num=st->stack->stack_data[st->start+2].u.num;
  4407. char *name=str_buf+str_data[num&0x00ffffff].str;
  4408. char prefix=*name;
  4409. char postfix=name[strlen(name)-1];
  4410. int num2=st->stack->stack_data[st->start+3].u.num;
  4411. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  4412. char prefix2=*name2;
  4413. char postfix2=name2[strlen(name2)-1];
  4414. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4415. int i;
  4416. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4417. printf("buildin_copyarray: illeagal scope !\n");
  4418. return 0;
  4419. }
  4420. if( prefix2!='$' && prefix2!='@' && prefix2!='.' ) {
  4421. printf("buildin_copyarray: illeagal scope !\n");
  4422. return 0;
  4423. }
  4424. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  4425. printf("buildin_copyarray: type mismatch !\n");
  4426. return 0;
  4427. }
  4428. if( not_server_variable(prefix) || not_server_variable(prefix2) )
  4429. sd=script_rid2sd(st);
  4430. if((num & 0x00FFFFFF) == (num2 & 0x00FFFFFF) && (num & 0xFF000000) > (num2 & 0xFF000000)) {
  4431. // 同じ配列で、num > num2 の場合大きい方からコピーしないといけない
  4432. for(i=sz-1;i>=0;i--)
  4433. set_reg(
  4434. st,sd,num+(i<<24),name,
  4435. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4436. st->stack->stack_data[st->start+2].ref
  4437. );
  4438. } else {
  4439. for(i=0;i<sz;i++)
  4440. set_reg(
  4441. st,sd,num+(i<<24),name,
  4442. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4443. st->stack->stack_data[st->start+2].ref
  4444. );
  4445. }
  4446. return 0;
  4447. }
  4448. /*==========================================
  4449. * 配列変数のサイズ所得
  4450. *------------------------------------------
  4451. */
  4452. static int getarraysize(struct script_state *st,int num,int postfix,struct linkdb_node** ref)
  4453. {
  4454. int i=(num>>24),c=(i==0? -1:i); // Moded to -1 because even if the first element is 0, it will still report as 1 [Lance]
  4455. if(postfix == '$'){
  4456. for(;i<128;i++){
  4457. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4458. if(*((char*)v)) c=i;
  4459. }
  4460. }else{
  4461. for(;i<128;i++){
  4462. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4463. if((int)v) c=i;
  4464. }
  4465. }
  4466. return c+1;
  4467. }
  4468. int buildin_getarraysize(struct script_state *st)
  4469. {
  4470. int num=st->stack->stack_data[st->start+2].u.num;
  4471. char *name=str_buf+str_data[num&0x00ffffff].str;
  4472. char prefix=*name;
  4473. char postfix=name[strlen(name)-1];
  4474. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4475. ShowWarning("buildin_copyarray: illegal scope !\n");
  4476. return 1;
  4477. }
  4478. push_val(st->stack,C_INT,getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref));
  4479. return 0;
  4480. }
  4481. /*==========================================
  4482. * 配列変数から要素削除
  4483. *------------------------------------------
  4484. */
  4485. int buildin_deletearray(struct script_state *st)
  4486. {
  4487. struct map_session_data *sd=NULL;
  4488. int num=st->stack->stack_data[st->start+2].u.num;
  4489. char *name=str_buf+str_data[num&0x00ffffff].str;
  4490. char prefix=*name;
  4491. char postfix=name[strlen(name)-1];
  4492. int count=1;
  4493. int i,sz=getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref)-(num>>24)-count+1;
  4494. if( (st->end > st->start+3) )
  4495. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4496. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4497. ShowWarning("buildin_deletearray: illegal scope !\n");
  4498. return 1;
  4499. }
  4500. if( not_server_variable(prefix) )
  4501. sd=script_rid2sd(st);
  4502. for(i=0;i<sz;i++){
  4503. set_reg(
  4504. st,sd,num+(i<<24),name,
  4505. get_val2(st,num+((i+count)<<24),st->stack->stack_data[st->start+2].ref),
  4506. st->stack->stack_data[st->start+2].ref
  4507. );
  4508. }
  4509. if(postfix != '$'){
  4510. for(;i<(128-(num>>24));i++)
  4511. set_reg(st,sd,num+(i<<24),name, 0,st->stack->stack_data[st->start+2].ref);
  4512. } else {
  4513. for(;i<(128-(num>>24));i++)
  4514. set_reg(st,sd,num+(i<<24),name, (void *) "",st->stack->stack_data[st->start+2].ref);
  4515. }
  4516. return 0;
  4517. }
  4518. /*==========================================
  4519. * 指定要素を表す値(キー)を所得する
  4520. *------------------------------------------
  4521. */
  4522. int buildin_getelementofarray(struct script_state *st)
  4523. {
  4524. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  4525. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4526. if(i>127 || i<0){
  4527. ShowWarning("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  4528. push_val(st->stack,C_INT,0);
  4529. return 1;
  4530. }else{
  4531. push_val2(st->stack,C_NAME,
  4532. (i<<24) | st->stack->stack_data[st->start+2].u.num, st->stack->stack_data[st->start+2].ref );
  4533. }
  4534. }else{
  4535. ShowError("script: getelementofarray (operator[]): param1 not name !\n");
  4536. push_val(st->stack,C_INT,0);
  4537. }
  4538. return 0;
  4539. }
  4540. /*==========================================
  4541. *
  4542. *------------------------------------------
  4543. */
  4544. int buildin_setlook(struct script_state *st)
  4545. {
  4546. int type,val;
  4547. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4548. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4549. pc_changelook(script_rid2sd(st),type,val);
  4550. return 0;
  4551. }
  4552. /*==========================================
  4553. *
  4554. *------------------------------------------
  4555. */
  4556. int buildin_cutin(struct script_state *st)
  4557. {
  4558. int type;
  4559. conv_str(st,& (st->stack->stack_data[st->start+2]));
  4560. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4561. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  4562. return 0;
  4563. }
  4564. /*==========================================
  4565. * カードのイラストを表示する
  4566. *------------------------------------------
  4567. */
  4568. int buildin_cutincard(struct script_state *st)
  4569. {
  4570. int itemid;
  4571. struct item_data *i_data;
  4572. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4573. i_data = itemdb_exists(itemid);
  4574. if (i_data)
  4575. clif_cutin(script_rid2sd(st),i_data->cardillustname,4);
  4576. return 0;
  4577. }
  4578. /*==========================================
  4579. *
  4580. *------------------------------------------
  4581. */
  4582. int buildin_viewpoint(struct script_state *st)
  4583. {
  4584. int type,x,y,id,color;
  4585. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4586. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4587. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4588. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4589. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4590. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  4591. return 0;
  4592. }
  4593. /*==========================================
  4594. *
  4595. *------------------------------------------
  4596. */
  4597. int buildin_countitem(struct script_state *st)
  4598. {
  4599. int nameid=0,count=0,i;
  4600. struct map_session_data *sd;
  4601. struct script_data *data;
  4602. sd = script_rid2sd(st);
  4603. data=&(st->stack->stack_data[st->start+2]);
  4604. get_val(st,data);
  4605. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4606. const char *name=conv_str(st,data);
  4607. struct item_data *item_data;
  4608. if( (item_data = itemdb_searchname(name)) != NULL)
  4609. nameid=item_data->nameid;
  4610. }else
  4611. nameid=conv_num(st,data);
  4612. if (nameid>=500) //if no such ID then skip this iteration
  4613. for(i=0;i<MAX_INVENTORY;i++){
  4614. if(sd->status.inventory[i].nameid==nameid)
  4615. count+=sd->status.inventory[i].amount;
  4616. }
  4617. else{
  4618. if(battle_config.error_log)
  4619. ShowError("wrong item ID : countitem(%i)\n",nameid);
  4620. push_val(st->stack,C_INT,0);
  4621. return 1;
  4622. }
  4623. push_val(st->stack,C_INT,count);
  4624. return 0;
  4625. }
  4626. /*==========================================
  4627. * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
  4628. * returns number of items that met the conditions
  4629. *------------------------------------------
  4630. */
  4631. int buildin_countitem2(struct script_state *st)
  4632. {
  4633. int nameid=0,count=0,i;
  4634. int iden,ref,attr,c1,c2,c3,c4;
  4635. struct map_session_data *sd;
  4636. struct script_data *data;
  4637. sd = script_rid2sd(st);
  4638. data=&(st->stack->stack_data[st->start+2]);
  4639. get_val(st,data);
  4640. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4641. const char *name=conv_str(st,data);
  4642. struct item_data *item_data;
  4643. if( (item_data = itemdb_searchname(name)) != NULL)
  4644. nameid=item_data->nameid;
  4645. }else
  4646. nameid=conv_num(st,data);
  4647. iden=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4648. ref=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4649. attr=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4650. c1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4651. c2=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4652. c3=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4653. c4=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4654. if (nameid>=500) //if no such ID then skip this iteration
  4655. for(i=0;i<MAX_INVENTORY;i++){
  4656. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  4657. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  4658. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  4659. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  4660. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  4661. sd->status.inventory[i].card[3]!=c4)
  4662. continue;
  4663. count+=sd->status.inventory[i].amount;
  4664. }
  4665. else{
  4666. if(battle_config.error_log)
  4667. ShowError("wrong item ID : countitem2(%i)\n",nameid);
  4668. push_val(st->stack,C_INT,0);
  4669. return 1;
  4670. }
  4671. push_val(st->stack,C_INT,count);
  4672. return 0;
  4673. }
  4674. /*==========================================
  4675. * 重量チェック
  4676. *------------------------------------------
  4677. */
  4678. int buildin_checkweight(struct script_state *st)
  4679. {
  4680. int nameid=0,amount,i;
  4681. unsigned long weight;
  4682. struct map_session_data *sd;
  4683. struct script_data *data;
  4684. sd = script_rid2sd(st);
  4685. data=&(st->stack->stack_data[st->start+2]);
  4686. get_val(st,data);
  4687. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4688. const char *name=conv_str(st,data);
  4689. struct item_data *item_data = itemdb_searchname(name);
  4690. if( item_data )
  4691. nameid=item_data->nameid;
  4692. }else
  4693. nameid=conv_num(st,data);
  4694. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4695. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  4696. push_val(st->stack,C_INT,0);
  4697. ShowError("buildin_checkweight: Wrong item ID or amount.\n");
  4698. return 1;
  4699. }
  4700. weight = itemdb_weight(nameid)*amount;
  4701. if(amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight){
  4702. push_val(st->stack,C_INT,0);
  4703. } else {
  4704. //Check if the inventory ain't full.
  4705. //TODO: Currently does not checks if you can just stack it on top of another item you already have....
  4706. i = pc_search_inventory(sd,0);
  4707. if (i >= 0) //Empty slot available.
  4708. push_val(st->stack,C_INT,1);
  4709. else //Inventory full
  4710. push_val(st->stack,C_INT,0);
  4711. }
  4712. return 0;
  4713. }
  4714. /*==========================================
  4715. *
  4716. *------------------------------------------
  4717. */
  4718. int buildin_getitem(struct script_state *st)
  4719. {
  4720. int nameid,amount,flag = 0;
  4721. struct item item_tmp;
  4722. struct map_session_data *sd;
  4723. struct script_data *data;
  4724. sd = script_rid2sd(st);
  4725. data=&(st->stack->stack_data[st->start+2]);
  4726. get_val(st,data);
  4727. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4728. const char *name=conv_str(st,data);
  4729. struct item_data *item_data = itemdb_searchname(name);
  4730. if( item_data == NULL) {
  4731. ShowWarning("buildin_getitem: Nonexistant item %s requested.\n", name);
  4732. return 1; //No item created.
  4733. }
  4734. nameid=item_data->nameid;
  4735. }else
  4736. nameid=conv_num(st,data);
  4737. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0)
  4738. return 0; //return if amount <=0, skip the useles iteration
  4739. //Violet Box, Blue Box, etc - random item pick
  4740. if(nameid <0) {
  4741. nameid=itemdb_searchrandomid(-nameid);
  4742. flag = 1;
  4743. }
  4744. if(nameid <= 0 || !itemdb_exists(nameid)) {
  4745. ShowWarning("buildin_getitem: Nonexistant item %d requested.\n", nameid);
  4746. return 1; //No item created.
  4747. }
  4748. memset(&item_tmp,0,sizeof(item_tmp));
  4749. item_tmp.nameid=nameid;
  4750. if(!flag)
  4751. item_tmp.identify=1;
  4752. else
  4753. item_tmp.identify=itemdb_isidentified(nameid);
  4754. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  4755. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  4756. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4757. return 0;
  4758. if(pet_create_egg(sd, nameid))
  4759. amount = 1; //This is a pet!
  4760. else
  4761. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4762. clif_additem(sd,0,0,flag);
  4763. if (pc_candrop(sd, &item_tmp))
  4764. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4765. }
  4766. //Logs items, got from (N)PC scripts [Lupus]
  4767. if(log_config.enable_logs&0x40)
  4768. log_pick(sd, "N", 0, nameid, amount, NULL);
  4769. return 0;
  4770. }
  4771. /*==========================================
  4772. *
  4773. *------------------------------------------
  4774. */
  4775. int buildin_getitem2(struct script_state *st)
  4776. {
  4777. int nameid,amount,flag = 0;
  4778. int iden,ref,attr,c1,c2,c3,c4;
  4779. struct item_data *item_data;
  4780. struct item item_tmp;
  4781. struct map_session_data *sd;
  4782. struct script_data *data;
  4783. sd = script_rid2sd(st);
  4784. data=&(st->stack->stack_data[st->start+2]);
  4785. get_val(st,data);
  4786. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4787. const char *name=conv_str(st,data);
  4788. struct item_data *item_data = itemdb_searchname(name);
  4789. nameid=UNKNOWN_ITEM_ID;
  4790. if( item_data )
  4791. nameid=item_data->nameid;
  4792. }else
  4793. nameid=conv_num(st,data);
  4794. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4795. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4796. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4797. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4798. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4799. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4800. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4801. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  4802. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  4803. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  4804. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4805. return 0;
  4806. if(nameid<0) { // ランダム
  4807. nameid=itemdb_searchrandomid(-nameid);
  4808. flag = 1;
  4809. }
  4810. if(nameid > 0) {
  4811. memset(&item_tmp,0,sizeof(item_tmp));
  4812. item_data=itemdb_exists(nameid);
  4813. if (item_data == NULL)
  4814. return -1;
  4815. if(item_data->type==4 || item_data->type==5){
  4816. if(ref > 10) ref = 10;
  4817. }
  4818. else if(item_data->type==7) {
  4819. iden = 1;
  4820. ref = 0;
  4821. }
  4822. else {
  4823. iden = 1;
  4824. ref = attr = 0;
  4825. }
  4826. item_tmp.nameid=nameid;
  4827. if(!flag)
  4828. item_tmp.identify=iden;
  4829. else if(item_data->type==4 || item_data->type==5)
  4830. item_tmp.identify=0;
  4831. item_tmp.refine=ref;
  4832. item_tmp.attribute=attr;
  4833. item_tmp.card[0]=c1;
  4834. item_tmp.card[1]=c2;
  4835. item_tmp.card[2]=c3;
  4836. item_tmp.card[3]=c4;
  4837. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4838. clif_additem(sd,0,0,flag);
  4839. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4840. }
  4841. //Logs items, got from (N)PC scripts [Lupus]
  4842. if(log_config.enable_logs&0x40)
  4843. log_pick(sd, "N", 0, nameid, amount, &item_tmp);
  4844. }
  4845. return 0;
  4846. }
  4847. /*==========================================
  4848. * gets an item with someone's name inscribed [Skotlex]
  4849. * getinscribeditem item_num, character_name
  4850. * Returned Qty is always 1, only works on equip-able
  4851. * equipment
  4852. *------------------------------------------
  4853. */
  4854. int buildin_getnameditem(struct script_state *st)
  4855. {
  4856. int nameid;
  4857. struct item item_tmp;
  4858. struct map_session_data *sd, *tsd;
  4859. struct script_data *data;
  4860. sd = script_rid2sd(st);
  4861. if (sd == NULL)
  4862. { //Player not attached!
  4863. push_val(st->stack,C_INT,0);
  4864. return 0;
  4865. }
  4866. data=&(st->stack->stack_data[st->start+2]);
  4867. get_val(st,data);
  4868. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4869. const char *name=conv_str(st,data);
  4870. struct item_data *item_data = itemdb_searchname(name);
  4871. if( item_data == NULL)
  4872. { //Failed
  4873. push_val(st->stack,C_INT,0);
  4874. return 0;
  4875. }
  4876. nameid = item_data->nameid;
  4877. }else
  4878. nameid = conv_num(st,data);
  4879. if(!itemdb_exists(nameid) || itemdb_isstackable(nameid))
  4880. { //We don't allow non-equipable/stackable items to be named
  4881. //to avoid any qty exploits that could happen because of it.
  4882. push_val(st->stack,C_INT,0);
  4883. return 0;
  4884. }
  4885. data=&(st->stack->stack_data[st->start+3]);
  4886. get_val(st,data);
  4887. if( data->type==C_STR || data->type==C_CONSTSTR ) //Char Name
  4888. tsd=map_nick2sd(conv_str(st,data));
  4889. else //Char Id was given
  4890. tsd=map_charid2sd(conv_num(st,data));
  4891. if( tsd == NULL )
  4892. { //Failed
  4893. push_val(st->stack,C_INT,0);
  4894. return 0;
  4895. }
  4896. memset(&item_tmp,0,sizeof(item_tmp));
  4897. item_tmp.nameid=nameid;
  4898. item_tmp.amount=1;
  4899. item_tmp.identify=1;
  4900. item_tmp.card[0]=254; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
  4901. item_tmp.card[2]=tsd->status.char_id;
  4902. item_tmp.card[3]=tsd->status.char_id >> 16;
  4903. if(pc_additem(sd,&item_tmp,1)) {
  4904. push_val(st->stack,C_INT,0);
  4905. return 0; //Failed to add item, we will not drop if they don't fit
  4906. }
  4907. //Logs items, got from (N)PC scripts [Lupus]
  4908. if(log_config.enable_logs&0x40)
  4909. log_pick(sd, "N", 0, item_tmp.nameid, item_tmp.amount, &item_tmp);
  4910. push_val(st->stack,C_INT,1);
  4911. return 0;
  4912. }
  4913. /*==========================================
  4914. * gets a random item ID from an item group [Skotlex]
  4915. * groupranditem group_num
  4916. *------------------------------------------
  4917. */
  4918. int buildin_grouprandomitem(struct script_state *st)
  4919. {
  4920. int group;
  4921. group = conv_num(st,& (st->stack->stack_data[st->start+2]));
  4922. push_val(st->stack, C_INT, itemdb_searchrandomid(group));
  4923. return 0;
  4924. }
  4925. /*==========================================
  4926. *
  4927. *------------------------------------------
  4928. */
  4929. int buildin_makeitem(struct script_state *st)
  4930. {
  4931. int nameid,amount,flag = 0;
  4932. int x,y,m;
  4933. char *mapname;
  4934. struct item item_tmp;
  4935. struct script_data *data;
  4936. data=&(st->stack->stack_data[st->start+2]);
  4937. get_val(st,data);
  4938. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4939. const char *name=conv_str(st,data);
  4940. struct item_data *item_data = itemdb_searchname(name);
  4941. nameid=UNKNOWN_ITEM_ID;
  4942. if( item_data )
  4943. nameid=item_data->nameid;
  4944. }else
  4945. nameid=conv_num(st,data);
  4946. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4947. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  4948. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  4949. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  4950. if(strcmp(mapname,"this")==0)
  4951. {
  4952. struct map_session_data *sd;
  4953. sd = script_rid2sd(st);
  4954. if (!sd) return 0; //Failed...
  4955. m=sd->bl.m;
  4956. } else
  4957. m=map_mapname2mapid(mapname);
  4958. if(nameid<0) { // ランダム
  4959. nameid=itemdb_searchrandomid(-nameid);
  4960. flag = 1;
  4961. }
  4962. if(nameid > 0) {
  4963. memset(&item_tmp,0,sizeof(item_tmp));
  4964. item_tmp.nameid=nameid;
  4965. if(!flag)
  4966. item_tmp.identify=1;
  4967. else
  4968. item_tmp.identify=itemdb_isidentified(nameid);
  4969. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  4970. }
  4971. return 0;
  4972. }
  4973. /*==========================================
  4974. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  4975. *------------------------------------------
  4976. */
  4977. int buildin_delitem(struct script_state *st)
  4978. {
  4979. int nameid=0,amount,i,important_item=0;
  4980. struct map_session_data *sd;
  4981. struct script_data *data;
  4982. sd = script_rid2sd(st);
  4983. data=&(st->stack->stack_data[st->start+2]);
  4984. get_val(st,data);
  4985. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4986. const char *name=conv_str(st,data);
  4987. struct item_data *item_data = itemdb_searchname(name);
  4988. //nameid=UNKNOWN_ITEM_ID;
  4989. if( item_data )
  4990. nameid=item_data->nameid;
  4991. }else
  4992. nameid=conv_num(st,data);
  4993. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4994. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  4995. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  4996. return 0;
  4997. }
  4998. //1st pass
  4999. //here we won't delete items with CARDS, named items but we count them
  5000. for(i=0;i<MAX_INVENTORY;i++){
  5001. //we don't delete wrong item or equipped item
  5002. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5003. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid)
  5004. continue;
  5005. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5006. if(sd->inventory_data[i]->type==IT_PETEGG &&
  5007. sd->status.inventory[i].card[0] == CARD0_PET)
  5008. {
  5009. if (intif_delete_petdata(MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5010. continue; //pet couldn't be sent for deletion.
  5011. }
  5012. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  5013. if(itemdb_isspecial(sd->status.inventory[i].card[0]) ||
  5014. sd->status.inventory[i].card[1] ||
  5015. sd->status.inventory[i].card[2] ||
  5016. sd->status.inventory[i].card[3] ||
  5017. sd->status.inventory[i].refine) {
  5018. //this is important item, count it (except for pet eggs)
  5019. if(sd->status.inventory[i].card[0] != CARD0_PET)
  5020. important_item++;
  5021. continue;
  5022. }
  5023. if(sd->status.inventory[i].amount>=amount){
  5024. //Logs items, got from (N)PC scripts [Lupus]
  5025. if(log_config.enable_logs&0x40)
  5026. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5027. pc_delitem(sd,i,amount,0);
  5028. return 0; //we deleted exact amount of items. now exit
  5029. } else {
  5030. amount-=sd->status.inventory[i].amount;
  5031. //Logs items, got from (N)PC scripts [Lupus]
  5032. if(log_config.enable_logs&0x40) {
  5033. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5034. }
  5035. //Logs
  5036. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5037. }
  5038. }
  5039. //2nd pass
  5040. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  5041. if (important_item>0 && amount>0)
  5042. for(i=0;i<MAX_INVENTORY;i++){
  5043. //we don't delete wrong item
  5044. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5045. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  5046. continue;
  5047. if(sd->status.inventory[i].amount>=amount){
  5048. //Logs items, got from (N)PC scripts [Lupus]
  5049. if(log_config.enable_logs&0x40)
  5050. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5051. pc_delitem(sd,i,amount,0);
  5052. return 0; //we deleted exact amount of items. now exit
  5053. } else {
  5054. amount-=sd->status.inventory[i].amount;
  5055. //Logs items, got from (N)PC scripts [Lupus]
  5056. if(log_config.enable_logs&0x40)
  5057. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5058. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5059. }
  5060. }
  5061. return 0;
  5062. }
  5063. /*==========================================
  5064. * advanced version of delitem [modified by Mihilion]
  5065. *------------------------------------------
  5066. */
  5067. int buildin_delitem2(struct script_state *st)
  5068. {
  5069. int nameid=0,amount,i=0;
  5070. int iden,ref,attr,c1,c2,c3,c4;
  5071. struct map_session_data *sd;
  5072. struct script_data *data;
  5073. sd = script_rid2sd(st);
  5074. data=&(st->stack->stack_data[st->start+2]);
  5075. get_val(st,data);
  5076. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5077. const char *name=conv_str(st,data);
  5078. struct item_data *item_data = itemdb_searchname(name);
  5079. //nameid=UNKNOWN_ITEM_ID;
  5080. if( item_data )
  5081. nameid=item_data->nameid;
  5082. }else
  5083. nameid=conv_num(st,data);
  5084. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5085. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5086. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5087. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5088. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5089. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5090. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5091. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  5092. if (!itemdb_exists(nameid) || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5093. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5094. return 0;
  5095. }
  5096. for(i=0;i<MAX_INVENTORY;i++){
  5097. //we don't delete wrong item or equipped item
  5098. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5099. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  5100. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  5101. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  5102. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  5103. sd->status.inventory[i].card[3]!=c4)
  5104. continue;
  5105. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5106. if(sd->inventory_data[i]->type==IT_PETEGG && sd->status.inventory[i].card[0] == CARD0_PET)
  5107. {
  5108. if (!intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5109. continue; //Failed to send delete the pet.
  5110. }
  5111. if(sd->status.inventory[i].amount>=amount){
  5112. //Logs items, got from (N)PC scripts [Lupus]
  5113. if(log_config.enable_logs&0x40)
  5114. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5115. pc_delitem(sd,i,amount,0);
  5116. return 0; //we deleted exact amount of items. now exit
  5117. } else {
  5118. amount-=sd->status.inventory[i].amount;
  5119. //Logs items, got from (N)PC scripts [Lupus]
  5120. if(log_config.enable_logs&0x40)
  5121. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5122. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5123. }
  5124. }
  5125. return 0;
  5126. }
  5127. /*==========================================
  5128. * Enables/Disables use of items while in an NPC [Skotlex]
  5129. *------------------------------------------
  5130. */
  5131. int buildin_enableitemuse(struct script_state *st) {
  5132. struct map_session_data *sd;
  5133. sd=script_rid2sd(st);
  5134. if (sd)
  5135. sd->npc_item_flag = st->oid;
  5136. return 0;
  5137. }
  5138. int buildin_disableitemuse(struct script_state *st) {
  5139. struct map_session_data *sd;
  5140. sd=script_rid2sd(st);
  5141. if (sd)
  5142. sd->npc_item_flag = 0;
  5143. return 0;
  5144. }
  5145. /*==========================================
  5146. *キャラ関係のパラメータ取得
  5147. *------------------------------------------
  5148. */
  5149. int buildin_readparam(struct script_state *st)
  5150. {
  5151. int type;
  5152. struct map_session_data *sd;
  5153. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5154. if( st->end>st->start+3 )
  5155. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5156. else
  5157. sd=script_rid2sd(st);
  5158. if(sd==NULL){
  5159. push_val(st->stack,C_INT,-1);
  5160. return 0;
  5161. }
  5162. push_val(st->stack,C_INT,pc_readparam(sd,type));
  5163. return 0;
  5164. }
  5165. /*==========================================
  5166. *キャラ関係のID取得
  5167. *------------------------------------------
  5168. */
  5169. int buildin_getcharid(struct script_state *st)
  5170. {
  5171. int num;
  5172. struct map_session_data *sd;
  5173. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5174. if( st->end>st->start+3 )
  5175. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5176. else
  5177. sd=script_rid2sd(st);
  5178. if(sd==NULL){
  5179. push_val(st->stack,C_INT,-1);
  5180. return 0;
  5181. }
  5182. if(num==0)
  5183. push_val(st->stack,C_INT,sd->status.char_id);
  5184. if(num==1)
  5185. push_val(st->stack,C_INT,sd->status.party_id);
  5186. if(num==2)
  5187. push_val(st->stack,C_INT,sd->status.guild_id);
  5188. if(num==3)
  5189. push_val(st->stack,C_INT,sd->status.account_id);
  5190. return 0;
  5191. }
  5192. /*==========================================
  5193. *指定IDのPT名取得
  5194. *------------------------------------------
  5195. */
  5196. char *buildin_getpartyname_sub(int party_id)
  5197. {
  5198. struct party_data *p;
  5199. p=party_search(party_id);
  5200. if(p!=NULL){
  5201. char *buf;
  5202. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5203. memcpy(buf, p->party.name, NAME_LENGTH-1);
  5204. buf[NAME_LENGTH-1] = '\0';
  5205. return buf;
  5206. }
  5207. return 0;
  5208. }
  5209. int buildin_getpartyname(struct script_state *st)
  5210. {
  5211. char *name;
  5212. int party_id;
  5213. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5214. name=buildin_getpartyname_sub(party_id);
  5215. if(name != NULL)
  5216. push_str(st->stack,C_STR,(unsigned char *)name);
  5217. else
  5218. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  5219. return 0;
  5220. }
  5221. /*==========================================
  5222. *指定IDのPT人数とメンバーID取得
  5223. *------------------------------------------
  5224. */
  5225. int buildin_getpartymember(struct script_state *st)
  5226. {
  5227. struct party_data *p;
  5228. int i,j=0,type=0;
  5229. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  5230. if( st->end>st->start+3 )
  5231. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5232. if(p!=NULL){
  5233. for(i=0;i<MAX_PARTY;i++){
  5234. if(p->party.member[i].account_id){
  5235. switch (type) {
  5236. case 2:
  5237. mapreg_setreg(add_str((unsigned char *) "$@partymemberaid")+(j<<24),p->party.member[i].account_id);
  5238. break;
  5239. case 1:
  5240. mapreg_setreg(add_str((unsigned char *) "$@partymembercid")+(j<<24),p->party.member[i].char_id);
  5241. break;
  5242. default:
  5243. mapreg_setregstr(add_str((unsigned char *) "$@partymembername$")+(j<<24),p->party.member[i].name);
  5244. }
  5245. j++;
  5246. }
  5247. }
  5248. }
  5249. mapreg_setreg(add_str((unsigned char *) "$@partymembercount"),j);
  5250. return 0;
  5251. }
  5252. /*==========================================
  5253. * Retrieves party leader. if flag is specified,
  5254. * return some of the leader data. Otherwise, return name.
  5255. *------------------------------------------
  5256. */
  5257. int buildin_getpartyleader(struct script_state *st)
  5258. {
  5259. int party_id, type = 0, i;
  5260. struct party_data *p;
  5261. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5262. if( st->end>st->start+3 )
  5263. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5264. p=party_search(party_id);
  5265. if (p) //Search leader
  5266. for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++);
  5267. if (!p || i == MAX_PARTY) { //leader not found
  5268. if (type)
  5269. push_val(st->stack,C_INT,-1);
  5270. else
  5271. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  5272. return 0;
  5273. }
  5274. switch (type) {
  5275. case 1:
  5276. push_val(st->stack,C_INT,p->party.member[i].account_id);
  5277. break;
  5278. case 2:
  5279. push_val(st->stack,C_INT,p->party.member[i].char_id);
  5280. break;
  5281. case 3:
  5282. push_val(st->stack,C_INT,p->party.member[i].class_);
  5283. break;
  5284. case 4:
  5285. push_val(st->stack,C_INT,p->party.member[i].map);
  5286. break;
  5287. case 5:
  5288. push_val(st->stack,C_INT,p->party.member[i].lv);
  5289. break;
  5290. default:
  5291. push_str(st->stack,C_STR,(unsigned char *)p->party.member[i].name);
  5292. break;
  5293. }
  5294. return 0;
  5295. }
  5296. /*==========================================
  5297. *指定IDのギルド名取得
  5298. *------------------------------------------
  5299. */
  5300. char *buildin_getguildname_sub(int guild_id)
  5301. {
  5302. struct guild *g=NULL;
  5303. g=guild_search(guild_id);
  5304. if(g!=NULL){
  5305. char *buf;
  5306. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5307. memcpy(buf, g->name, NAME_LENGTH-1);
  5308. buf[NAME_LENGTH-1] = '\0';
  5309. return buf;
  5310. }
  5311. return NULL;
  5312. }
  5313. int buildin_getguildname(struct script_state *st)
  5314. {
  5315. char *name;
  5316. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5317. name=buildin_getguildname_sub(guild_id);
  5318. if(name != NULL)
  5319. push_str(st->stack,C_STR,(unsigned char *) name);
  5320. else
  5321. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  5322. return 0;
  5323. }
  5324. /*==========================================
  5325. *指定IDのGuildMaster名取得
  5326. *------------------------------------------
  5327. */
  5328. char *buildin_getguildmaster_sub(int guild_id)
  5329. {
  5330. struct guild *g=NULL;
  5331. g=guild_search(guild_id);
  5332. if(g!=NULL){
  5333. char *buf;
  5334. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5335. memcpy(buf, g->master, NAME_LENGTH-1);
  5336. buf[NAME_LENGTH-1] = '\0';
  5337. return buf;
  5338. }
  5339. return 0;
  5340. }
  5341. int buildin_getguildmaster(struct script_state *st)
  5342. {
  5343. char *master;
  5344. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5345. master=buildin_getguildmaster_sub(guild_id);
  5346. if(master!=0)
  5347. push_str(st->stack,C_STR,(unsigned char *) master);
  5348. else
  5349. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  5350. return 0;
  5351. }
  5352. int buildin_getguildmasterid(struct script_state *st)
  5353. {
  5354. char *master;
  5355. struct map_session_data *sd=NULL;
  5356. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5357. master=buildin_getguildmaster_sub(guild_id);
  5358. if(master!=0){
  5359. if((sd=map_nick2sd(master)) == NULL){
  5360. push_val(st->stack,C_INT,0);
  5361. return 0;
  5362. }
  5363. push_val(st->stack,C_INT,sd->status.char_id);
  5364. }else{
  5365. push_val(st->stack,C_INT,0);
  5366. }
  5367. return 0;
  5368. }
  5369. /*==========================================
  5370. * キャラクタの名前
  5371. *------------------------------------------
  5372. */
  5373. int buildin_strcharinfo(struct script_state *st)
  5374. {
  5375. struct map_session_data *sd;
  5376. int num;
  5377. char *buf;
  5378. sd=script_rid2sd(st);
  5379. if (!sd) { //Avoid crashing....
  5380. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5381. return 0;
  5382. }
  5383. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5384. switch(num){
  5385. case 0:
  5386. push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->status.name);
  5387. break;
  5388. case 1:
  5389. buf=buildin_getpartyname_sub(sd->status.party_id);
  5390. if(buf!=0)
  5391. push_str(st->stack,C_STR,(unsigned char *) buf);
  5392. else
  5393. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5394. break;
  5395. case 2:
  5396. buf=buildin_getguildname_sub(sd->status.guild_id);
  5397. if(buf != NULL)
  5398. push_str(st->stack,C_STR,(unsigned char *) buf);
  5399. else
  5400. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5401. break;
  5402. default:
  5403. ShowWarning("buildin_strcharinfo: unknown parameter.");
  5404. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5405. break;
  5406. }
  5407. return 0;
  5408. }
  5409. unsigned int equip[10]={EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW};
  5410. /*==========================================
  5411. * GetEquipID(Pos); Pos: 1-10
  5412. *------------------------------------------
  5413. */
  5414. int buildin_getequipid(struct script_state *st)
  5415. {
  5416. int i,num;
  5417. struct map_session_data *sd;
  5418. struct item_data* item;
  5419. sd=script_rid2sd(st);
  5420. if(sd == NULL)
  5421. {
  5422. ShowError("getequipid: sd == NULL\n");
  5423. return 0;
  5424. }
  5425. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5426. i=pc_checkequip(sd,equip[num-1]);
  5427. if(i >= 0){
  5428. item=sd->inventory_data[i];
  5429. if(item)
  5430. push_val(st->stack,C_INT,item->nameid);
  5431. else
  5432. push_val(st->stack,C_INT,0);
  5433. }else{
  5434. push_val(st->stack,C_INT,-1);
  5435. }
  5436. return 0;
  5437. }
  5438. /*==========================================
  5439. * 装備名文字列(精錬メニュー用)
  5440. *------------------------------------------
  5441. */
  5442. int buildin_getequipname(struct script_state *st)
  5443. {
  5444. int i,num;
  5445. struct map_session_data *sd;
  5446. struct item_data* item;
  5447. char *buf;
  5448. buf=(char *)aMallocA(64*sizeof(char));
  5449. sd=script_rid2sd(st);
  5450. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5451. i=pc_checkequip(sd,equip[num-1]);
  5452. if(i >= 0){
  5453. item=sd->inventory_data[i];
  5454. if(item)
  5455. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  5456. else
  5457. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5458. }else{
  5459. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5460. }
  5461. push_str(st->stack,C_STR,(unsigned char *) buf);
  5462. return 0;
  5463. }
  5464. /*==========================================
  5465. * getbrokenid [Valaris]
  5466. *------------------------------------------
  5467. */
  5468. int buildin_getbrokenid(struct script_state *st)
  5469. {
  5470. int i,num,id=0,brokencounter=0;
  5471. struct map_session_data *sd;
  5472. sd=script_rid2sd(st);
  5473. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5474. for(i=0; i<MAX_INVENTORY; i++) {
  5475. if(sd->status.inventory[i].attribute==1){
  5476. brokencounter++;
  5477. if(num==brokencounter){
  5478. id=sd->status.inventory[i].nameid;
  5479. break;
  5480. }
  5481. }
  5482. }
  5483. push_val(st->stack,C_INT,id);
  5484. return 0;
  5485. }
  5486. /*==========================================
  5487. * repair [Valaris]
  5488. *------------------------------------------
  5489. */
  5490. int buildin_repair(struct script_state *st)
  5491. {
  5492. int i,num;
  5493. int repaircounter=0;
  5494. struct map_session_data *sd;
  5495. sd=script_rid2sd(st);
  5496. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5497. for(i=0; i<MAX_INVENTORY; i++) {
  5498. if(sd->status.inventory[i].attribute==1){
  5499. repaircounter++;
  5500. if(num==repaircounter){
  5501. sd->status.inventory[i].attribute=0;
  5502. clif_equiplist(sd);
  5503. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  5504. clif_misceffect(&sd->bl, 3);
  5505. clif_displaymessage(sd->fd,"Item has been repaired.");
  5506. break;
  5507. }
  5508. }
  5509. }
  5510. return 0;
  5511. }
  5512. /*==========================================
  5513. * 装備チェック
  5514. *------------------------------------------
  5515. */
  5516. int buildin_getequipisequiped(struct script_state *st)
  5517. {
  5518. int i,num;
  5519. struct map_session_data *sd;
  5520. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5521. sd=script_rid2sd(st);
  5522. if ((num - 1) >= (sizeof(equip) / sizeof(equip[0])))
  5523. i = -1;
  5524. else
  5525. i=pc_checkequip(sd,equip[num-1]);
  5526. if(i >= 0)
  5527. push_val(st->stack,C_INT,1);
  5528. else
  5529. push_val(st->stack,C_INT,0);
  5530. return 0;
  5531. }
  5532. /*==========================================
  5533. * 装備品精錬可能チェック
  5534. *------------------------------------------
  5535. */
  5536. int buildin_getequipisenableref(struct script_state *st)
  5537. {
  5538. int i,num;
  5539. struct map_session_data *sd;
  5540. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5541. sd=script_rid2sd(st);
  5542. i=pc_checkequip(sd,equip[num-1]);
  5543. if(i >= 0 && num<7 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
  5544. {
  5545. push_val(st->stack,C_INT,1);
  5546. } else {
  5547. push_val(st->stack,C_INT,0);
  5548. }
  5549. return 0;
  5550. }
  5551. /*==========================================
  5552. * 装備品鑑定チェック
  5553. *------------------------------------------
  5554. */
  5555. int buildin_getequipisidentify(struct script_state *st)
  5556. {
  5557. int i,num;
  5558. struct map_session_data *sd;
  5559. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5560. sd=script_rid2sd(st);
  5561. i=pc_checkequip(sd,equip[num-1]);
  5562. if(i >= 0)
  5563. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  5564. else
  5565. push_val(st->stack,C_INT,0);
  5566. return 0;
  5567. }
  5568. /*==========================================
  5569. * 装備品精錬度
  5570. *------------------------------------------
  5571. */
  5572. int buildin_getequiprefinerycnt(struct script_state *st)
  5573. {
  5574. int i,num;
  5575. struct map_session_data *sd;
  5576. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5577. sd=script_rid2sd(st);
  5578. i=pc_checkequip(sd,equip[num-1]);
  5579. if(i >= 0)
  5580. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  5581. else
  5582. push_val(st->stack,C_INT,0);
  5583. return 0;
  5584. }
  5585. /*==========================================
  5586. * 装備品武器LV
  5587. *------------------------------------------
  5588. */
  5589. int buildin_getequipweaponlv(struct script_state *st)
  5590. {
  5591. int i,num;
  5592. struct map_session_data *sd;
  5593. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5594. sd=script_rid2sd(st);
  5595. i=pc_checkequip(sd,equip[num-1]);
  5596. if(i >= 0 && sd->inventory_data[i])
  5597. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  5598. else
  5599. push_val(st->stack,C_INT,0);
  5600. return 0;
  5601. }
  5602. /*==========================================
  5603. * 装備品精錬成功率
  5604. *------------------------------------------
  5605. */
  5606. int buildin_getequippercentrefinery(struct script_state *st)
  5607. {
  5608. int i,num;
  5609. struct map_session_data *sd;
  5610. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5611. sd=script_rid2sd(st);
  5612. i=pc_checkequip(sd,equip[num-1]);
  5613. if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
  5614. push_val(st->stack,C_INT,percentrefinery[itemdb_wlv(sd->status.inventory[i].nameid)][(int)sd->status.inventory[i].refine]);
  5615. else
  5616. push_val(st->stack,C_INT,0);
  5617. return 0;
  5618. }
  5619. /*==========================================
  5620. * 精錬成功
  5621. *------------------------------------------
  5622. */
  5623. int buildin_successrefitem(struct script_state *st)
  5624. {
  5625. int i,num,ep;
  5626. struct map_session_data *sd;
  5627. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5628. sd=script_rid2sd(st);
  5629. i=pc_checkequip(sd,equip[num-1]);
  5630. if(i >= 0) {
  5631. ep=sd->status.inventory[i].equip;
  5632. //Logs items, got from (N)PC scripts [Lupus]
  5633. if(log_config.enable_logs&0x40)
  5634. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5635. sd->status.inventory[i].refine++;
  5636. pc_unequipitem(sd,i,2);
  5637. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  5638. clif_delitem(sd,i,1);
  5639. //Logs items, got from (N)PC scripts [Lupus]
  5640. if(log_config.enable_logs&0x40)
  5641. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]);
  5642. clif_additem(sd,i,1,0);
  5643. pc_equipitem(sd,i,ep);
  5644. clif_misceffect(&sd->bl,3);
  5645. if(sd->status.inventory[i].refine == MAX_REFINE &&
  5646. sd->status.inventory[i].card[0] == CARD0_FORGE &&
  5647. sd->char_id == MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])
  5648. ){ // Fame point system [DracoRPG]
  5649. switch (sd->inventory_data[i]->wlv){
  5650. case 1:
  5651. pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
  5652. break;
  5653. case 2:
  5654. pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
  5655. break;
  5656. case 3:
  5657. pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
  5658. break;
  5659. }
  5660. }
  5661. }
  5662. return 0;
  5663. }
  5664. /*==========================================
  5665. * 精錬失敗
  5666. *------------------------------------------
  5667. */
  5668. int buildin_failedrefitem(struct script_state *st)
  5669. {
  5670. int i,num;
  5671. struct map_session_data *sd;
  5672. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5673. sd=script_rid2sd(st);
  5674. i=pc_checkequip(sd,equip[num-1]);
  5675. if(i >= 0) {
  5676. //Logs items, got from (N)PC scripts [Lupus]
  5677. if(log_config.enable_logs&0x40)
  5678. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5679. sd->status.inventory[i].refine = 0;
  5680. pc_unequipitem(sd,i,3);
  5681. // 精錬失敗エフェクトのパケット
  5682. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  5683. pc_delitem(sd,i,1,0);
  5684. // 他の人にも失敗を通知
  5685. clif_misceffect(&sd->bl,2);
  5686. }
  5687. return 0;
  5688. }
  5689. /*==========================================
  5690. *
  5691. *------------------------------------------
  5692. */
  5693. int buildin_statusup(struct script_state *st)
  5694. {
  5695. int type;
  5696. struct map_session_data *sd;
  5697. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5698. sd=script_rid2sd(st);
  5699. pc_statusup(sd,type);
  5700. return 0;
  5701. }
  5702. /*==========================================
  5703. *
  5704. *------------------------------------------
  5705. */
  5706. int buildin_statusup2(struct script_state *st)
  5707. {
  5708. int type,val;
  5709. struct map_session_data *sd;
  5710. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5711. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5712. sd=script_rid2sd(st);
  5713. pc_statusup2(sd,type,val);
  5714. return 0;
  5715. }
  5716. /*==========================================
  5717. * 装備品による能力値ボーナス
  5718. *------------------------------------------
  5719. */
  5720. int buildin_bonus(struct script_state *st)
  5721. {
  5722. int type,val;
  5723. struct map_session_data *sd;
  5724. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5725. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5726. sd=script_rid2sd(st);
  5727. pc_bonus(sd,type,val);
  5728. return 0;
  5729. }
  5730. /*==========================================
  5731. * 装備品による能力値ボーナス
  5732. *------------------------------------------
  5733. */
  5734. int buildin_bonus2(struct script_state *st)
  5735. {
  5736. int type,type2,val;
  5737. struct map_session_data *sd;
  5738. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5739. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5740. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5741. sd=script_rid2sd(st);
  5742. pc_bonus2(sd,type,type2,val);
  5743. return 0;
  5744. }
  5745. /*==========================================
  5746. * 装備品による能力値ボーナス
  5747. *------------------------------------------
  5748. */
  5749. int buildin_bonus3(struct script_state *st)
  5750. {
  5751. int type,type2,type3,val;
  5752. struct map_session_data *sd;
  5753. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5754. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5755. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5756. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5757. sd=script_rid2sd(st);
  5758. pc_bonus3(sd,type,type2,type3,val);
  5759. return 0;
  5760. }
  5761. int buildin_bonus4(struct script_state *st)
  5762. {
  5763. int type,type2,type3,type4,val;
  5764. struct map_session_data *sd;
  5765. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5766. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5767. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5768. type4=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5769. val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5770. sd=script_rid2sd(st);
  5771. pc_bonus4(sd,type,type2,type3,type4,val);
  5772. return 0;
  5773. }
  5774. /*==========================================
  5775. * スキル所得
  5776. *------------------------------------------
  5777. */
  5778. int buildin_skill(struct script_state *st)
  5779. {
  5780. int id,level,flag=1;
  5781. struct map_session_data *sd;
  5782. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5783. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5784. if( st->end>st->start+4 )
  5785. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5786. sd=script_rid2sd(st);
  5787. pc_skill(sd,id,level,flag);
  5788. return 0;
  5789. }
  5790. // add x levels of skill (stackable) [Valaris]
  5791. int buildin_addtoskill(struct script_state *st)
  5792. {
  5793. int id,level,flag=2;
  5794. struct map_session_data *sd;
  5795. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5796. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5797. if( st->end>st->start+4 )
  5798. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5799. sd=script_rid2sd(st);
  5800. pc_skill(sd,id,level,flag);
  5801. return 0;
  5802. }
  5803. /*==========================================
  5804. * ギルドスキル取得
  5805. *------------------------------------------
  5806. */
  5807. int buildin_guildskill(struct script_state *st)
  5808. {
  5809. int id,level,flag=0;
  5810. struct map_session_data *sd;
  5811. int i=0;
  5812. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5813. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5814. if( st->end>st->start+4 )
  5815. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5816. sd=script_rid2sd(st);
  5817. for(i=0;i<level;i++)
  5818. guild_skillup(sd,id,flag);
  5819. return 0;
  5820. }
  5821. /*==========================================
  5822. * スキルレベル所得
  5823. *------------------------------------------
  5824. */
  5825. int buildin_getskilllv(struct script_state *st)
  5826. {
  5827. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5828. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  5829. return 0;
  5830. }
  5831. /*==========================================
  5832. * getgdskilllv(Guild_ID, Skill_ID);
  5833. * skill_id = 10000 : GD_APPROVAL
  5834. * 10001 : GD_KAFRACONTRACT
  5835. * 10002 : GD_GUARDIANRESEARCH
  5836. * 10003 : GD_GUARDUP
  5837. * 10004 : GD_EXTENSION
  5838. *------------------------------------------
  5839. */
  5840. int buildin_getgdskilllv(struct script_state *st)
  5841. {
  5842. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5843. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5844. struct guild *g=guild_search(guild_id);
  5845. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  5846. return 0;
  5847. /*
  5848. struct map_session_data *sd=NULL;
  5849. struct guild *g=NULL;
  5850. int skill_id;
  5851. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5852. sd=script_rid2sd(st);
  5853. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  5854. if(sd && g) {
  5855. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  5856. } else {
  5857. push_val(st->stack,C_INT,-1);
  5858. }
  5859. return 0;
  5860. */
  5861. }
  5862. /*==========================================
  5863. *
  5864. *------------------------------------------
  5865. */
  5866. int buildin_basicskillcheck(struct script_state *st)
  5867. {
  5868. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  5869. return 0;
  5870. }
  5871. /*==========================================
  5872. *
  5873. *------------------------------------------
  5874. */
  5875. int buildin_getgmlevel(struct script_state *st)
  5876. {
  5877. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  5878. return 0;
  5879. }
  5880. /*==========================================
  5881. *
  5882. *------------------------------------------
  5883. */
  5884. int buildin_end(struct script_state *st)
  5885. {
  5886. st->state = END;
  5887. return 0;
  5888. }
  5889. /*==========================================
  5890. *
  5891. *------------------------------------------
  5892. */
  5893. int buildin_checkoption(struct script_state *st)
  5894. {
  5895. int type;
  5896. struct map_session_data *sd;
  5897. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5898. sd=script_rid2sd(st);
  5899. if(sd->sc.option & type){
  5900. push_val(st->stack,C_INT,1);
  5901. } else {
  5902. push_val(st->stack,C_INT,0);
  5903. }
  5904. return 0;
  5905. }
  5906. /*==========================================
  5907. *
  5908. *------------------------------------------
  5909. */
  5910. int buildin_checkoption1(struct script_state *st)
  5911. {
  5912. int type;
  5913. struct map_session_data *sd;
  5914. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5915. sd=script_rid2sd(st);
  5916. if(sd->sc.opt1 & type){
  5917. push_val(st->stack,C_INT,1);
  5918. } else {
  5919. push_val(st->stack,C_INT,0);
  5920. }
  5921. return 0;
  5922. }
  5923. /*==========================================
  5924. *
  5925. *------------------------------------------
  5926. */
  5927. int buildin_checkoption2(struct script_state *st)
  5928. {
  5929. int type;
  5930. struct map_session_data *sd;
  5931. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5932. sd=script_rid2sd(st);
  5933. if(sd->sc.opt2 & type){
  5934. push_val(st->stack,C_INT,1);
  5935. } else {
  5936. push_val(st->stack,C_INT,0);
  5937. }
  5938. return 0;
  5939. }
  5940. /*==========================================
  5941. *
  5942. *------------------------------------------
  5943. */
  5944. int buildin_setoption(struct script_state *st)
  5945. {
  5946. int type;
  5947. struct map_session_data *sd;
  5948. int flag=1;
  5949. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5950. if(st->end>st->start+3 )
  5951. flag=conv_num(st,&(st->stack->stack_data[st->start+3]) );
  5952. else if (!type) { //Request to remove everything.
  5953. flag = 0;
  5954. type = OPTION_CART|OPTION_FALCON|OPTION_RIDING;
  5955. }
  5956. sd=script_rid2sd(st);
  5957. if (!sd) return 0;
  5958. if (flag) {//Add option
  5959. if (type&OPTION_WEDDING && !battle_config.wedding_modifydisplay)
  5960. type&=~OPTION_WEDDING; //Do not show the wedding sprites
  5961. pc_setoption(sd,sd->sc.option|type);
  5962. } else//Remove option
  5963. pc_setoption(sd,sd->sc.option&~type);
  5964. return 0;
  5965. }
  5966. /*==========================================
  5967. * Checkcart [Valaris]
  5968. *------------------------------------------
  5969. */
  5970. int buildin_checkcart(struct script_state *st)
  5971. {
  5972. struct map_session_data *sd;
  5973. sd=script_rid2sd(st);
  5974. if(pc_iscarton(sd)){
  5975. push_val(st->stack,C_INT,1);
  5976. } else {
  5977. push_val(st->stack,C_INT,0);
  5978. }
  5979. return 0;
  5980. }
  5981. /*==========================================
  5982. * カートを付ける
  5983. *------------------------------------------
  5984. */
  5985. int buildin_setcart(struct script_state *st)
  5986. {
  5987. struct map_session_data *sd;
  5988. sd=script_rid2sd(st);
  5989. pc_setcart(sd,1);
  5990. return 0;
  5991. }
  5992. /*==========================================
  5993. * checkfalcon [Valaris]
  5994. *------------------------------------------
  5995. */
  5996. int buildin_checkfalcon(struct script_state *st)
  5997. {
  5998. struct map_session_data *sd;
  5999. sd=script_rid2sd(st);
  6000. if(pc_isfalcon(sd)){
  6001. push_val(st->stack,C_INT,1);
  6002. } else {
  6003. push_val(st->stack,C_INT,0);
  6004. }
  6005. return 0;
  6006. }
  6007. /*==========================================
  6008. * 鷹を付ける
  6009. *------------------------------------------
  6010. */
  6011. int buildin_setfalcon(struct script_state *st)
  6012. {
  6013. struct map_session_data *sd;
  6014. sd=script_rid2sd(st);
  6015. pc_setfalcon(sd);
  6016. return 0;
  6017. }
  6018. /*==========================================
  6019. * Checkcart [Valaris]
  6020. *------------------------------------------
  6021. */
  6022. int buildin_checkriding(struct script_state *st)
  6023. {
  6024. struct map_session_data *sd;
  6025. sd=script_rid2sd(st);
  6026. if(pc_isriding(sd)){
  6027. push_val(st->stack,C_INT,1);
  6028. } else {
  6029. push_val(st->stack,C_INT,0);
  6030. }
  6031. return 0;
  6032. }
  6033. /*==========================================
  6034. * ペコペコ乗り
  6035. *------------------------------------------
  6036. */
  6037. int buildin_setriding(struct script_state *st)
  6038. {
  6039. struct map_session_data *sd;
  6040. sd=script_rid2sd(st);
  6041. pc_setriding(sd);
  6042. return 0;
  6043. }
  6044. /*==========================================
  6045. * セーブポイントの保存
  6046. *------------------------------------------
  6047. */
  6048. int buildin_savepoint(struct script_state *st)
  6049. {
  6050. int x,y;
  6051. short map;
  6052. char *str;
  6053. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6054. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6055. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6056. map = mapindex_name2id(str);
  6057. if (map)
  6058. pc_setsavepoint(script_rid2sd(st),map,x,y);
  6059. return 0;
  6060. }
  6061. /*==========================================
  6062. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  6063. *------------------------------------------
  6064. */
  6065. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  6066. {
  6067. int type;
  6068. time_t timer;
  6069. struct tm *t;
  6070. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6071. switch(type){
  6072. case 2:
  6073. //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
  6074. // from the system clock.)
  6075. push_val(st->stack,C_INT,(int)time(NULL));
  6076. break;
  6077. case 1:
  6078. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  6079. time(&timer);
  6080. t=localtime(&timer);
  6081. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  6082. break;
  6083. case 0:
  6084. default:
  6085. //type 0:(System Ticks)
  6086. push_val(st->stack,C_INT,gettick());
  6087. break;
  6088. }
  6089. return 0;
  6090. }
  6091. /*==========================================
  6092. * GetTime(Type);
  6093. * 1: Sec 2: Min 3: Hour
  6094. * 4: WeekDay 5: MonthDay 6: Month
  6095. * 7: Year
  6096. *------------------------------------------
  6097. */
  6098. int buildin_gettime(struct script_state *st) /* Asgard Version */
  6099. {
  6100. int type;
  6101. time_t timer;
  6102. struct tm *t;
  6103. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6104. time(&timer);
  6105. t=localtime(&timer);
  6106. switch(type){
  6107. case 1://Sec(0~59)
  6108. push_val(st->stack,C_INT,t->tm_sec);
  6109. break;
  6110. case 2://Min(0~59)
  6111. push_val(st->stack,C_INT,t->tm_min);
  6112. break;
  6113. case 3://Hour(0~23)
  6114. push_val(st->stack,C_INT,t->tm_hour);
  6115. break;
  6116. case 4://WeekDay(0~6)
  6117. push_val(st->stack,C_INT,t->tm_wday);
  6118. break;
  6119. case 5://MonthDay(01~31)
  6120. push_val(st->stack,C_INT,t->tm_mday);
  6121. break;
  6122. case 6://Month(01~12)
  6123. push_val(st->stack,C_INT,t->tm_mon+1);
  6124. break;
  6125. case 7://Year(20xx)
  6126. push_val(st->stack,C_INT,t->tm_year+1900);
  6127. break;
  6128. case 8://Year Day(01~366)
  6129. push_val(st->stack,C_INT,t->tm_yday+1);
  6130. break;
  6131. default://(format error)
  6132. push_val(st->stack,C_INT,-1);
  6133. break;
  6134. }
  6135. return 0;
  6136. }
  6137. /*==========================================
  6138. * GetTimeStr("TimeFMT", Length);
  6139. *------------------------------------------
  6140. */
  6141. int buildin_gettimestr(struct script_state *st)
  6142. {
  6143. char *tmpstr;
  6144. char *fmtstr;
  6145. int maxlen;
  6146. time_t now = time(NULL);
  6147. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6148. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6149. tmpstr=(char *)aMallocA((maxlen+1)*sizeof(char));
  6150. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  6151. tmpstr[maxlen]='\0';
  6152. push_str(st->stack,C_STR,(unsigned char *) tmpstr);
  6153. return 0;
  6154. }
  6155. /*==========================================
  6156. * カプラ倉庫を開く
  6157. *------------------------------------------
  6158. */
  6159. int buildin_openstorage(struct script_state *st)
  6160. {
  6161. storage_storageopen(script_rid2sd(st));
  6162. return 0;
  6163. }
  6164. int buildin_guildopenstorage(struct script_state *st)
  6165. {
  6166. struct map_session_data *sd=script_rid2sd(st);
  6167. int ret;
  6168. ret = storage_guild_storageopen(sd);
  6169. push_val(st->stack,C_INT,ret);
  6170. return 0;
  6171. }
  6172. /*==========================================
  6173. * アイテムによるスキル発動
  6174. *------------------------------------------
  6175. */
  6176. int buildin_itemskill(struct script_state *st)
  6177. {
  6178. int id,lv;
  6179. char *str;
  6180. struct map_session_data *sd=script_rid2sd(st);
  6181. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6182. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6183. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6184. // 詠唱中にスキルアイテムは使用できない
  6185. if(sd->ud.skilltimer != -1)
  6186. return 0;
  6187. sd->skillitem=id;
  6188. sd->skillitemlv=lv;
  6189. clif_item_skill(sd,id,lv,str);
  6190. return 0;
  6191. }
  6192. /*==========================================
  6193. * アイテム作成
  6194. *------------------------------------------
  6195. */
  6196. int buildin_produce(struct script_state *st)
  6197. {
  6198. int trigger;
  6199. struct map_session_data *sd=script_rid2sd(st);
  6200. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6201. clif_skill_produce_mix_list(sd, trigger);
  6202. return 0;
  6203. }
  6204. /*==========================================
  6205. * NPCでペット作る
  6206. *------------------------------------------
  6207. */
  6208. int buildin_makepet(struct script_state *st)
  6209. {
  6210. struct map_session_data *sd = script_rid2sd(st);
  6211. struct script_data *data;
  6212. int id,pet_id;
  6213. data=&(st->stack->stack_data[st->start+2]);
  6214. get_val(st,data);
  6215. id=conv_num(st,data);
  6216. pet_id = search_petDB_index(id, PET_CLASS);
  6217. if (pet_id < 0)
  6218. pet_id = search_petDB_index(id, PET_EGG);
  6219. if (pet_id >= 0 && sd) {
  6220. sd->catch_target_class = pet_db[pet_id].class_;
  6221. intif_create_pet(
  6222. sd->status.account_id, sd->status.char_id,
  6223. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  6224. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  6225. 100, 0, 1, pet_db[pet_id].jname);
  6226. }
  6227. return 0;
  6228. }
  6229. /*==========================================
  6230. * NPCで経験値上げる
  6231. *------------------------------------------
  6232. */
  6233. int buildin_getexp(struct script_state *st)
  6234. {
  6235. struct map_session_data *sd = script_rid2sd(st);
  6236. int base=0,job=0;
  6237. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6238. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6239. if(base<0 || job<0)
  6240. return 0;
  6241. if(sd)
  6242. pc_gainexp(sd,NULL,base,job);
  6243. return 0;
  6244. }
  6245. /*==========================================
  6246. * Gain guild exp [Celest]
  6247. *------------------------------------------
  6248. */
  6249. int buildin_guildgetexp(struct script_state *st)
  6250. {
  6251. struct map_session_data *sd = script_rid2sd(st);
  6252. int exp;
  6253. exp = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6254. if(exp < 0)
  6255. return 0;
  6256. if(sd && sd->status.guild_id > 0)
  6257. guild_getexp (sd, exp);
  6258. return 0;
  6259. }
  6260. /*==========================================
  6261. * Changes the guild master of a guild [Skotlex]
  6262. *------------------------------------------
  6263. */
  6264. int buildin_guildchangegm(struct script_state *st)
  6265. {
  6266. struct map_session_data *sd;
  6267. int guild_id;
  6268. char *name;
  6269. guild_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6270. name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  6271. sd=map_nick2sd(name);
  6272. if (!sd)
  6273. push_val(st->stack,C_INT,0);
  6274. else
  6275. push_val(st->stack,C_INT,guild_gm_change(guild_id, sd));
  6276. return 0;
  6277. }
  6278. /*==========================================
  6279. * モンスター発生
  6280. *------------------------------------------
  6281. */
  6282. int buildin_monster(struct script_state *st)
  6283. {
  6284. int class_,amount,x,y;
  6285. char *str,*map,*event="";
  6286. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6287. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6288. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6289. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  6290. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6291. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6292. if( st->end>st->start+8 ){
  6293. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  6294. check_event(st, event);
  6295. }
  6296. if (class_ >= 0 && !mobdb_checkid(class_)) {
  6297. ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
  6298. return 1;
  6299. }
  6300. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
  6301. return 0;
  6302. }
  6303. /*==========================================
  6304. * モンスター発生
  6305. *------------------------------------------
  6306. */
  6307. int buildin_areamonster(struct script_state *st)
  6308. {
  6309. int class_,amount,x0,y0,x1,y1;
  6310. char *str,*map,*event="";
  6311. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6312. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6313. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6314. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  6315. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  6316. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  6317. class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6318. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6319. if( st->end>st->start+10 ){
  6320. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  6321. check_event(st, event);
  6322. }
  6323. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
  6324. return 0;
  6325. }
  6326. /*==========================================
  6327. * モンスター削除
  6328. *------------------------------------------
  6329. */
  6330. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  6331. {
  6332. TBL_MOB* md = (TBL_MOB*)bl;
  6333. char *event=va_arg(ap,char *);
  6334. int allflag=va_arg(ap,int);
  6335. if(!allflag){
  6336. if(strcmp(event,md->npc_event)==0)
  6337. status_kill(bl);
  6338. return 0;
  6339. }else{
  6340. if(!md->spawn)
  6341. status_kill(bl);
  6342. return 0;
  6343. }
  6344. return 0;
  6345. }
  6346. int buildin_killmonster(struct script_state *st)
  6347. {
  6348. char *mapname,*event;
  6349. int m,allflag=0;
  6350. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6351. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6352. if(strcmp(event,"All")==0)
  6353. allflag = 1;
  6354. else
  6355. check_event(st, event);
  6356. if( (m=map_mapname2mapid(mapname))<0 )
  6357. return 0;
  6358. map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
  6359. return 0;
  6360. }
  6361. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  6362. {
  6363. status_kill(bl);
  6364. return 0;
  6365. }
  6366. int buildin_killmonsterall(struct script_state *st)
  6367. {
  6368. char *mapname;
  6369. int m;
  6370. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6371. if( (m=map_mapname2mapid(mapname))<0 )
  6372. return 0;
  6373. map_foreachinmap(buildin_killmonsterall_sub,
  6374. m,BL_MOB);
  6375. return 0;
  6376. }
  6377. /*==========================================
  6378. * Creates a clone of a player.
  6379. * clone map, x, y, event, char_id, master_id, mode, flag, duration
  6380. *------------------------------------------
  6381. */
  6382. int buildin_clone(struct script_state *st) {
  6383. struct map_session_data *sd, *msd=NULL;
  6384. int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
  6385. unsigned int duration = 0;
  6386. char *map,*event="";
  6387. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6388. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6389. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6390. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6391. char_id=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6392. if( st->end>st->start+7 )
  6393. master_id=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6394. if( st->end>st->start+8 )
  6395. mode=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6396. if( st->end>st->start+9 )
  6397. flag=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6398. if( st->end>st->start+10 )
  6399. duration=conv_num(st,& (st->stack->stack_data[st->start+10]));
  6400. check_event(st, event);
  6401. m = map_mapname2mapid(map);
  6402. if (m < 0) return 0;
  6403. sd = map_charid2sd(char_id);
  6404. if (master_id) {
  6405. msd = map_charid2sd(master_id);
  6406. if (msd)
  6407. master_id = msd->bl.id;
  6408. else
  6409. master_id = 0;
  6410. }
  6411. if (sd) //Return ID of newly crafted clone.
  6412. push_val(st->stack,C_INT,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
  6413. else //Failed to create clone.
  6414. push_val(st->stack,C_INT,0);
  6415. return 0;
  6416. }
  6417. /*==========================================
  6418. * イベント実行
  6419. *------------------------------------------
  6420. */
  6421. int buildin_doevent(struct script_state *st)
  6422. {
  6423. char *event;
  6424. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6425. check_event(st, event);
  6426. npc_event(map_id2sd(st->rid),event,0);
  6427. return 0;
  6428. }
  6429. /*==========================================
  6430. * NPC主体イベント実行
  6431. *------------------------------------------
  6432. */
  6433. int buildin_donpcevent(struct script_state *st)
  6434. {
  6435. char *event;
  6436. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6437. check_event(st, event);
  6438. npc_event_do(event);
  6439. return 0;
  6440. }
  6441. /*==========================================
  6442. * イベントタイマー追加
  6443. *------------------------------------------
  6444. */
  6445. int buildin_addtimer(struct script_state *st)
  6446. {
  6447. char *event;
  6448. int tick;
  6449. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6450. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6451. check_event(st, event);
  6452. pc_addeventtimer(script_rid2sd(st),tick,event);
  6453. return 0;
  6454. }
  6455. /*==========================================
  6456. * イベントタイマー削除
  6457. *------------------------------------------
  6458. */
  6459. int buildin_deltimer(struct script_state *st)
  6460. {
  6461. char *event;
  6462. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6463. check_event(st, event);
  6464. pc_deleventtimer(script_rid2sd(st),event);
  6465. return 0;
  6466. }
  6467. /*==========================================
  6468. * イベントタイマーのカウント値追加
  6469. *------------------------------------------
  6470. */
  6471. int buildin_addtimercount(struct script_state *st)
  6472. {
  6473. char *event;
  6474. int tick;
  6475. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6476. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6477. check_event(st, event);
  6478. pc_addeventtimercount(script_rid2sd(st),event,tick);
  6479. return 0;
  6480. }
  6481. /*==========================================
  6482. * NPCタイマー初期化
  6483. *------------------------------------------
  6484. */
  6485. int buildin_initnpctimer(struct script_state *st)
  6486. {
  6487. struct npc_data *nd;
  6488. if( st->end > st->start+2 )
  6489. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6490. else
  6491. nd=(struct npc_data *)map_id2bl(st->oid);
  6492. //nd->u.scr.rid = st->rid; //NO, use npcattachtimer if you want a player-attached timer! [Skotlex]
  6493. npc_settimerevent_tick(nd,0);
  6494. npc_timerevent_start(nd, st->rid);
  6495. return 0;
  6496. }
  6497. /*==========================================
  6498. * NPCタイマー開始
  6499. *------------------------------------------
  6500. */
  6501. int buildin_startnpctimer(struct script_state *st)
  6502. {
  6503. struct npc_data *nd;
  6504. if( st->end > st->start+2 )
  6505. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6506. else
  6507. nd=(struct npc_data *)map_id2bl(st->oid);
  6508. npc_timerevent_start(nd, st->rid);
  6509. return 0;
  6510. }
  6511. /*==========================================
  6512. * NPCタイマー停止
  6513. *------------------------------------------
  6514. */
  6515. int buildin_stopnpctimer(struct script_state *st)
  6516. {
  6517. struct npc_data *nd;
  6518. if( st->end > st->start+2 )
  6519. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6520. else
  6521. nd=(struct npc_data *)map_id2bl(st->oid);
  6522. npc_timerevent_stop(nd);
  6523. return 0;
  6524. }
  6525. /*==========================================
  6526. * NPCタイマー情報所得
  6527. *------------------------------------------
  6528. */
  6529. int buildin_getnpctimer(struct script_state *st)
  6530. {
  6531. struct npc_data *nd;
  6532. struct map_session_data *sd;
  6533. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6534. int val=0;
  6535. if( st->end > st->start+3 )
  6536. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6537. else
  6538. nd=(struct npc_data *)map_id2bl(st->oid);
  6539. switch(type){
  6540. case 0: val=npc_gettimerevent_tick(nd); break;
  6541. case 1:
  6542. if (nd->u.scr.rid) {
  6543. sd = map_id2sd(nd->u.scr.rid);
  6544. if (!sd) {
  6545. if(battle_config.error_log)
  6546. ShowError("buildin_getnpctimer: Attached player not found!\n");
  6547. break;
  6548. }
  6549. val = (sd->npc_timer_id != -1);
  6550. } else
  6551. val= (nd->u.scr.timerid !=-1);
  6552. break;
  6553. case 2: val= nd->u.scr.timeramount; break;
  6554. }
  6555. push_val(st->stack,C_INT,val);
  6556. return 0;
  6557. }
  6558. /*==========================================
  6559. * NPCタイマー値設定
  6560. *------------------------------------------
  6561. */
  6562. int buildin_setnpctimer(struct script_state *st)
  6563. {
  6564. int tick;
  6565. struct npc_data *nd;
  6566. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6567. if( st->end > st->start+3 )
  6568. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6569. else
  6570. nd=(struct npc_data *)map_id2bl(st->oid);
  6571. npc_settimerevent_tick(nd,tick);
  6572. return 0;
  6573. }
  6574. /*==========================================
  6575. * attaches the player rid to the timer [Celest]
  6576. *------------------------------------------
  6577. */
  6578. int buildin_attachnpctimer(struct script_state *st)
  6579. {
  6580. struct map_session_data *sd;
  6581. struct npc_data *nd;
  6582. nd=(struct npc_data *)map_id2bl(st->oid);
  6583. if( st->end > st->start+2 ) {
  6584. char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  6585. sd=map_nick2sd(name);
  6586. } else {
  6587. sd = script_rid2sd(st);
  6588. }
  6589. if (sd==NULL)
  6590. return 0;
  6591. nd->u.scr.rid = sd->bl.id;
  6592. return 0;
  6593. }
  6594. /*==========================================
  6595. * detaches a player rid from the timer [Celest]
  6596. *------------------------------------------
  6597. */
  6598. int buildin_detachnpctimer(struct script_state *st)
  6599. {
  6600. struct npc_data *nd;
  6601. if( st->end > st->start+2 )
  6602. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6603. else
  6604. nd=(struct npc_data *)map_id2bl(st->oid);
  6605. nd->u.scr.rid = 0;
  6606. return 0;
  6607. }
  6608. /*==========================================
  6609. * To avoid "player not attached" script errors, this function is provided,
  6610. * it checks if there is a player attached to the current script. [Skotlex]
  6611. * If no, returns 0, if yes, returns the char_id of the attached player.
  6612. *------------------------------------------
  6613. */
  6614. int buildin_playerattached(struct script_state *st)
  6615. {
  6616. struct map_session_data *sd;
  6617. if (st->rid == 0 || (sd = map_id2sd(st->rid)) == NULL)
  6618. push_val(st->stack,C_INT,0);
  6619. else
  6620. push_val(st->stack,C_INT,st->rid);
  6621. return 0;
  6622. }
  6623. /*==========================================
  6624. * 天の声アナウンス
  6625. *------------------------------------------
  6626. */
  6627. int buildin_announce(struct script_state *st)
  6628. {
  6629. char *str, *color=NULL;
  6630. int flag;
  6631. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6632. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6633. if (st->end>st->start+4)
  6634. color=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6635. if(flag&0x0f){
  6636. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  6637. (struct block_list *)script_rid2sd(st);
  6638. if (color)
  6639. clif_announce(bl,str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0),flag);
  6640. else
  6641. clif_GMmessage(bl,str,(int)strlen(str)+1,flag);
  6642. }else {
  6643. if (color)
  6644. intif_announce(str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0), flag);
  6645. else
  6646. intif_GMmessage(str,(int)strlen(str)+1,flag);
  6647. }
  6648. return 0;
  6649. }
  6650. /*==========================================
  6651. * 天の声アナウンス(特定マップ)
  6652. *------------------------------------------
  6653. */
  6654. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  6655. {
  6656. char *str, *color;
  6657. int len,flag;
  6658. str=va_arg(ap,char *);
  6659. len=va_arg(ap,int);
  6660. flag=va_arg(ap,int);
  6661. color=va_arg(ap,char *);
  6662. if (color)
  6663. clif_announce(bl,str,len, strtol(color, (char **)NULL, 0), flag|3);
  6664. else
  6665. clif_GMmessage(bl,str,len,flag|3);
  6666. return 0;
  6667. }
  6668. int buildin_mapannounce(struct script_state *st)
  6669. {
  6670. char *mapname,*str, *color=NULL;
  6671. int flag,m;
  6672. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6673. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6674. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6675. if (st->end>st->start+5)
  6676. color=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6677. if( (m=map_mapname2mapid(mapname))<0 )
  6678. return 0;
  6679. map_foreachinmap(buildin_mapannounce_sub,
  6680. m, BL_PC, str,strlen(str)+1,flag&0x10, color);
  6681. return 0;
  6682. }
  6683. /*==========================================
  6684. * 天の声アナウンス(特定エリア)
  6685. *------------------------------------------
  6686. */
  6687. int buildin_areaannounce(struct script_state *st)
  6688. {
  6689. char *map,*str,*color=NULL;
  6690. int flag,m;
  6691. int x0,y0,x1,y1;
  6692. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6693. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6694. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6695. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6696. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6697. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  6698. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6699. if (st->end>st->start+9)
  6700. color=conv_str(st,& (st->stack->stack_data[st->start+9]));
  6701. if( (m=map_mapname2mapid(map))<0 )
  6702. return 0;
  6703. map_foreachinarea(buildin_mapannounce_sub,
  6704. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10, color);
  6705. return 0;
  6706. }
  6707. /*==========================================
  6708. * ユーザー数所得
  6709. *------------------------------------------
  6710. */
  6711. int buildin_getusers(struct script_state *st)
  6712. {
  6713. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6714. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  6715. int val=0;
  6716. switch(flag&0x07){
  6717. case 0: val=map[bl->m].users; break;
  6718. case 1: val=map_getusers(); break;
  6719. }
  6720. push_val(st->stack,C_INT,val);
  6721. return 0;
  6722. }
  6723. /*==========================================
  6724. * Works like @WHO - displays all online users names in window
  6725. *------------------------------------------
  6726. */
  6727. int buildin_getusersname(struct script_state *st)
  6728. {
  6729. struct map_session_data *pl_sd = NULL, **pl_allsd;
  6730. int i=0,disp_num=1, users;
  6731. pl_allsd = map_getallusers(&users);
  6732. for (i=0;i<users;i++)
  6733. {
  6734. pl_sd = pl_allsd[i];
  6735. if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) )
  6736. {
  6737. if((disp_num++)%10==0)
  6738. clif_scriptnext(script_rid2sd(st),st->oid);
  6739. clif_scriptmes(script_rid2sd(st),st->oid,pl_sd->status.name);
  6740. }
  6741. }
  6742. return 0;
  6743. }
  6744. /*==========================================
  6745. * マップ指定ユーザー数所得
  6746. *------------------------------------------
  6747. */
  6748. int buildin_getmapusers(struct script_state *st)
  6749. {
  6750. char *str;
  6751. int m;
  6752. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6753. if( (m=map_mapname2mapid(str))< 0){
  6754. push_val(st->stack,C_INT,-1);
  6755. return 0;
  6756. }
  6757. push_val(st->stack,C_INT,map[m].users);
  6758. return 0;
  6759. }
  6760. /*==========================================
  6761. * エリア指定ユーザー数所得
  6762. *------------------------------------------
  6763. */
  6764. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  6765. {
  6766. int *users=va_arg(ap,int *);
  6767. (*users)++;
  6768. return 0;
  6769. }
  6770. int buildin_getareausers(struct script_state *st)
  6771. {
  6772. char *str;
  6773. int m,x0,y0,x1,y1,users=0;
  6774. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6775. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6776. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6777. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6778. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6779. if( (m=map_mapname2mapid(str))< 0){
  6780. push_val(st->stack,C_INT,-1);
  6781. return 0;
  6782. }
  6783. map_foreachinarea(buildin_getareausers_sub,
  6784. m,x0,y0,x1,y1,BL_PC,&users);
  6785. push_val(st->stack,C_INT,users);
  6786. return 0;
  6787. }
  6788. /*==========================================
  6789. * エリア指定ドロップアイテム数所得
  6790. *------------------------------------------
  6791. */
  6792. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  6793. {
  6794. int item=va_arg(ap,int);
  6795. int *amount=va_arg(ap,int *);
  6796. struct flooritem_data *drop=(struct flooritem_data *)bl;
  6797. if(drop->item_data.nameid==item)
  6798. (*amount)+=drop->item_data.amount;
  6799. return 0;
  6800. }
  6801. int buildin_getareadropitem(struct script_state *st)
  6802. {
  6803. char *str;
  6804. int m,x0,y0,x1,y1,item,amount=0;
  6805. struct script_data *data;
  6806. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6807. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6808. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6809. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6810. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6811. data=&(st->stack->stack_data[st->start+7]);
  6812. get_val(st,data);
  6813. if( data->type==C_STR || data->type==C_CONSTSTR ){
  6814. const char *name=conv_str(st,data);
  6815. struct item_data *item_data = itemdb_searchname(name);
  6816. item=UNKNOWN_ITEM_ID;
  6817. if( item_data )
  6818. item=item_data->nameid;
  6819. }else
  6820. item=conv_num(st,data);
  6821. if( (m=map_mapname2mapid(str))< 0){
  6822. push_val(st->stack,C_INT,-1);
  6823. return 0;
  6824. }
  6825. map_foreachinarea(buildin_getareadropitem_sub,
  6826. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  6827. push_val(st->stack,C_INT,amount);
  6828. return 0;
  6829. }
  6830. /*==========================================
  6831. * NPCの有効化
  6832. *------------------------------------------
  6833. */
  6834. int buildin_enablenpc(struct script_state *st)
  6835. {
  6836. char *str;
  6837. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6838. npc_enable(str,1);
  6839. return 0;
  6840. }
  6841. /*==========================================
  6842. * NPCの無効化
  6843. *------------------------------------------
  6844. */
  6845. int buildin_disablenpc(struct script_state *st)
  6846. {
  6847. char *str;
  6848. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6849. npc_enable(str,0);
  6850. return 0;
  6851. }
  6852. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  6853. {
  6854. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6855. struct chat_data *cd;
  6856. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  6857. return 0;
  6858. npc_enable(nd->name,1);
  6859. nd->arenaflag=1;
  6860. if(cd->users>=cd->trigger && cd->npc_event[0])
  6861. npc_timer_event(cd->npc_event);
  6862. return 0;
  6863. }
  6864. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  6865. {
  6866. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6867. nd->arenaflag=0;
  6868. return 0;
  6869. }
  6870. /*==========================================
  6871. * 隠れているNPCの表示
  6872. *------------------------------------------
  6873. */
  6874. int buildin_hideoffnpc(struct script_state *st)
  6875. {
  6876. char *str;
  6877. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6878. npc_enable(str,2);
  6879. return 0;
  6880. }
  6881. /*==========================================
  6882. * NPCをハイディング
  6883. *------------------------------------------
  6884. */
  6885. int buildin_hideonnpc(struct script_state *st)
  6886. {
  6887. char *str;
  6888. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6889. npc_enable(str,4);
  6890. return 0;
  6891. }
  6892. /*==========================================
  6893. * 状態異常にかかる
  6894. *------------------------------------------
  6895. */
  6896. int buildin_sc_start(struct script_state *st)
  6897. {
  6898. struct block_list *bl;
  6899. int type,tick,val1,val4=0;
  6900. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6901. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6902. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6903. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  6904. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  6905. else
  6906. bl = map_id2bl(st->rid);
  6907. if (potion_flag==1 && potion_target) {
  6908. bl = map_id2bl(potion_target);
  6909. tick/=2; //Thrown potions only last half.
  6910. val4 = 1; //Mark that this was a thrown sc_effect
  6911. }
  6912. if (bl)
  6913. status_change_start(bl,type,10000,val1,0,0,val4,tick,11);
  6914. return 0;
  6915. }
  6916. /*==========================================
  6917. * 状態異常にかかる(確率指定)
  6918. *------------------------------------------
  6919. */
  6920. int buildin_sc_start2(struct script_state *st)
  6921. {
  6922. struct block_list *bl;
  6923. int type,tick,val1,val4=0,per;
  6924. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6925. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6926. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6927. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6928. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  6929. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  6930. else
  6931. bl = map_id2bl(st->rid);
  6932. if (potion_flag==1 && potion_target) {
  6933. bl = map_id2bl(potion_target);
  6934. tick/=2;
  6935. val4 = 1;
  6936. }
  6937. if(bl)
  6938. status_change_start(bl,type,per,val1,0,0,val4,tick,11);
  6939. return 0;
  6940. }
  6941. /*==========================================
  6942. * Starts a SC_ change with the four values passed. [Skotlex]
  6943. * Final optional argument is the ID of player to affect.
  6944. * sc_start4 type, duration, val1, val2, val3, val4, <id>;
  6945. *------------------------------------------
  6946. */
  6947. int buildin_sc_start4(struct script_state *st)
  6948. {
  6949. struct block_list *bl;
  6950. int type,tick,val1,val2,val3,val4;
  6951. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6952. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6953. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6954. val2=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6955. val3=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6956. val4=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6957. if( st->end>st->start+8 )
  6958. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+8])));
  6959. else
  6960. bl = map_id2bl(st->rid);
  6961. if (potion_flag==1 && potion_target) {
  6962. bl = map_id2bl(potion_target);
  6963. tick/=2;
  6964. }
  6965. if (bl)
  6966. status_change_start(bl,type,10000,val1,val2,val3,val4,tick,11);
  6967. return 0;
  6968. }
  6969. /*==========================================
  6970. * 状態異常が直る
  6971. *------------------------------------------
  6972. */
  6973. int buildin_sc_end(struct script_state *st)
  6974. {
  6975. struct block_list *bl;
  6976. int type;
  6977. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6978. bl = map_id2bl(st->rid);
  6979. if (potion_flag==1 && potion_target)
  6980. bl = map_id2bl(potion_target);
  6981. if (!bl) return 0;
  6982. if (type >= 0)
  6983. status_change_end(bl,type,-1);
  6984. else
  6985. status_change_clear(bl, 2);
  6986. return 0;
  6987. }
  6988. /*==========================================
  6989. * 状態異常耐性を計算した確率を返す
  6990. *------------------------------------------
  6991. */
  6992. int buildin_getscrate(struct script_state *st)
  6993. {
  6994. struct block_list *bl;
  6995. int sc_def=0,type,rate;
  6996. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6997. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6998. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  6999. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  7000. else
  7001. bl = map_id2bl(st->rid);
  7002. if (bl)
  7003. sc_def = status_get_sc_def(bl,type);
  7004. rate = rate*(10000-sc_def)/10000;
  7005. push_val(st->stack,C_INT,rate<0?0:rate);
  7006. return 0;
  7007. }
  7008. /*==========================================
  7009. *
  7010. *------------------------------------------
  7011. */
  7012. int buildin_debugmes(struct script_state *st)
  7013. {
  7014. conv_str(st,& (st->stack->stack_data[st->start+2]));
  7015. ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  7016. return 0;
  7017. }
  7018. /*==========================================
  7019. *捕獲アイテム使用
  7020. *------------------------------------------
  7021. */
  7022. int buildin_catchpet(struct script_state *st)
  7023. {
  7024. int pet_id;
  7025. struct map_session_data *sd;
  7026. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  7027. sd=script_rid2sd(st);
  7028. pet_catch_process1(sd,pet_id);
  7029. return 0;
  7030. }
  7031. /*==========================================
  7032. * [orn]
  7033. *------------------------------------------
  7034. */
  7035. int buildin_homunculus_evolution(struct script_state *st)
  7036. {
  7037. struct map_session_data *sd;
  7038. sd=script_rid2sd(st);
  7039. if ( sd->hd && sd->hd->homunculusDB->evo_class && sd->homunculus.intimacy > 91000 ) {
  7040. return merc_hom_evolution(sd->hd) ;
  7041. }
  7042. clif_emotion(&sd->hd->bl, 4) ; //swt
  7043. return 0;
  7044. }
  7045. /*==========================================
  7046. *携帯卵孵化機使用
  7047. *------------------------------------------
  7048. */
  7049. int buildin_birthpet(struct script_state *st)
  7050. {
  7051. struct map_session_data *sd;
  7052. sd=script_rid2sd(st);
  7053. clif_sendegg(sd);
  7054. return 0;
  7055. }
  7056. /*==========================================
  7057. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  7058. *------------------------------------------
  7059. */
  7060. int buildin_resetlvl(struct script_state *st)
  7061. {
  7062. struct map_session_data *sd;
  7063. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7064. sd=script_rid2sd(st);
  7065. pc_resetlvl(sd,type);
  7066. return 0;
  7067. }
  7068. /*==========================================
  7069. * ステータスリセット
  7070. *------------------------------------------
  7071. */
  7072. int buildin_resetstatus(struct script_state *st)
  7073. {
  7074. struct map_session_data *sd;
  7075. sd=script_rid2sd(st);
  7076. pc_resetstate(sd);
  7077. return 0;
  7078. }
  7079. /*==========================================
  7080. * script command resetskill
  7081. *------------------------------------------
  7082. */
  7083. int buildin_resetskill(struct script_state *st)
  7084. {
  7085. struct map_session_data *sd;
  7086. sd=script_rid2sd(st);
  7087. pc_resetskill(sd,1);
  7088. return 0;
  7089. }
  7090. /*==========================================
  7091. * Counts total amount of skill points.
  7092. *------------------------------------------
  7093. */
  7094. int buildin_skillpointcount(struct script_state *st)
  7095. {
  7096. struct map_session_data *sd;
  7097. sd=script_rid2sd(st);
  7098. push_val(st->stack,C_INT,sd->status.skill_point + pc_resetskill(sd,2));
  7099. return 0;
  7100. }
  7101. /*==========================================
  7102. *
  7103. *------------------------------------------
  7104. */
  7105. int buildin_changebase(struct script_state *st)
  7106. {
  7107. struct map_session_data *sd=NULL;
  7108. int vclass;
  7109. if( st->end>st->start+3 )
  7110. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  7111. else
  7112. sd=script_rid2sd(st);
  7113. if(sd == NULL)
  7114. return 0;
  7115. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7116. if(vclass == JOB_WEDDING)
  7117. {
  7118. if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
  7119. sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore.
  7120. )
  7121. return 0;
  7122. }
  7123. if(!sd->disguise && vclass != sd->vd.class_) {
  7124. status_set_viewdata(&sd->bl, vclass);
  7125. //Updated client view. Base, Weapon and Cloth Colors.
  7126. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_);
  7127. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7128. if (sd->vd.cloth_color)
  7129. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7130. }
  7131. return 0;
  7132. }
  7133. /*==========================================
  7134. * 性別変換
  7135. *------------------------------------------
  7136. */
  7137. int buildin_changesex(struct script_state *st) {
  7138. struct map_session_data *sd = NULL;
  7139. sd = script_rid2sd(st);
  7140. if (sd->status.sex == 0) {
  7141. sd->status.sex = 1;
  7142. sd->sex = 1;
  7143. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7144. sd->status.class_ -= 1;
  7145. } else if (sd->status.sex == 1) {
  7146. sd->status.sex = 0;
  7147. sd->sex = 0;
  7148. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7149. sd->status.class_ += 1;
  7150. }
  7151. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  7152. chrif_save(sd,0);
  7153. return 0;
  7154. }
  7155. /*==========================================
  7156. * npcチャット作成
  7157. *------------------------------------------
  7158. */
  7159. int buildin_waitingroom(struct script_state *st)
  7160. {
  7161. char *name,*ev="";
  7162. int limit, trigger = 0,pub=1;
  7163. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7164. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  7165. if(limit==0)
  7166. pub=3;
  7167. if( (st->end > st->start+5) ){
  7168. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  7169. get_val(st,data);
  7170. if(data->type==C_INT){
  7171. // 新Athena仕様(旧Athena仕様と互換性あり)
  7172. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7173. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7174. }else{
  7175. // eathena仕様
  7176. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7177. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  7178. }
  7179. }else{
  7180. // 旧Athena仕様
  7181. if( st->end > st->start+4 )
  7182. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7183. }
  7184. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  7185. limit,pub,trigger,name,(int)strlen(name)+1,ev);
  7186. return 0;
  7187. }
  7188. /*==========================================
  7189. * Works like 'announce' but outputs in the common chat window
  7190. *------------------------------------------
  7191. */
  7192. int buildin_globalmes(struct script_state *st)
  7193. {
  7194. struct block_list *bl = map_id2bl(st->oid);
  7195. struct npc_data *nd = (struct npc_data *)bl;
  7196. char *name=NULL,*mes;
  7197. mes=conv_str(st,& (st->stack->stack_data[st->start+2])); // メッセージの取得
  7198. if(mes==NULL) return 0;
  7199. if(st->end>st->start+3){ // NPC名の取得(123#456)
  7200. name=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7201. } else {
  7202. name=nd->name;
  7203. }
  7204. npc_globalmessage(name,mes); // グローバルメッセージ送信
  7205. return 0;
  7206. }
  7207. /*==========================================
  7208. * npcチャット削除
  7209. *------------------------------------------
  7210. */
  7211. int buildin_delwaitingroom(struct script_state *st)
  7212. {
  7213. struct npc_data *nd;
  7214. if( st->end > st->start+2 )
  7215. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7216. else
  7217. nd=(struct npc_data *)map_id2bl(st->oid);
  7218. chat_deletenpcchat(nd);
  7219. return 0;
  7220. }
  7221. /*==========================================
  7222. * npcチャット全員蹴り出す
  7223. *------------------------------------------
  7224. */
  7225. int buildin_waitingroomkickall(struct script_state *st)
  7226. {
  7227. struct npc_data *nd;
  7228. struct chat_data *cd;
  7229. if( st->end > st->start+2 )
  7230. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7231. else
  7232. nd=(struct npc_data *)map_id2bl(st->oid);
  7233. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7234. return 0;
  7235. chat_npckickall(cd);
  7236. return 0;
  7237. }
  7238. /*==========================================
  7239. * npcチャットイベント有効化
  7240. *------------------------------------------
  7241. */
  7242. int buildin_enablewaitingroomevent(struct script_state *st)
  7243. {
  7244. struct npc_data *nd;
  7245. struct chat_data *cd;
  7246. if( st->end > st->start+2 )
  7247. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7248. else
  7249. nd=(struct npc_data *)map_id2bl(st->oid);
  7250. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7251. return 0;
  7252. chat_enableevent(cd);
  7253. return 0;
  7254. }
  7255. /*==========================================
  7256. * npcチャットイベント無効化
  7257. *------------------------------------------
  7258. */
  7259. int buildin_disablewaitingroomevent(struct script_state *st)
  7260. {
  7261. struct npc_data *nd;
  7262. struct chat_data *cd;
  7263. if( st->end > st->start+2 )
  7264. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7265. else
  7266. nd=(struct npc_data *)map_id2bl(st->oid);
  7267. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7268. return 0;
  7269. chat_disableevent(cd);
  7270. return 0;
  7271. }
  7272. /*==========================================
  7273. * npcチャット状態所得
  7274. *------------------------------------------
  7275. */
  7276. int buildin_getwaitingroomstate(struct script_state *st)
  7277. {
  7278. struct npc_data *nd;
  7279. struct chat_data *cd;
  7280. int val=0,type;
  7281. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7282. if( st->end > st->start+3 )
  7283. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  7284. else
  7285. nd=(struct npc_data *)map_id2bl(st->oid);
  7286. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  7287. push_val(st->stack,C_INT,-1);
  7288. return 0;
  7289. }
  7290. switch(type){
  7291. case 0: val=cd->users; break;
  7292. case 1: val=cd->limit; break;
  7293. case 2: val=cd->trigger&0x7f; break;
  7294. case 3: val=((cd->trigger&0x80)>0); break;
  7295. case 32: val=(cd->users >= cd->limit); break;
  7296. case 33: val=(cd->users >= cd->trigger); break;
  7297. case 4:
  7298. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->title);
  7299. return 0;
  7300. case 5:
  7301. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->pass);
  7302. return 0;
  7303. case 16:
  7304. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->npc_event);
  7305. return 0;
  7306. }
  7307. push_val(st->stack,C_INT,val);
  7308. return 0;
  7309. }
  7310. /*==========================================
  7311. * チャットメンバー(規定人数)ワープ
  7312. *------------------------------------------
  7313. */
  7314. int buildin_warpwaitingpc(struct script_state *st)
  7315. {
  7316. int x,y,i,n;
  7317. char *str;
  7318. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7319. struct chat_data *cd;
  7320. struct map_session_data *sd;
  7321. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7322. return 0;
  7323. n=cd->trigger&0x7f;
  7324. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7325. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7326. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7327. if( st->end > st->start+5 )
  7328. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7329. for(i=0;i<n;i++){
  7330. sd=cd->usersd[0];
  7331. if (!sd) continue; //Broken npc chat room?
  7332. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpc")+(i<<24),sd->bl.id);
  7333. if(strcmp(str,"Random")==0)
  7334. pc_randomwarp(sd,3);
  7335. else if(strcmp(str,"SavePoint")==0){
  7336. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  7337. return 0;
  7338. pc_setpos(sd,sd->status.save_point.map,
  7339. sd->status.save_point.x,sd->status.save_point.y,3);
  7340. }else
  7341. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  7342. }
  7343. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpcnum"),n);
  7344. return 0;
  7345. }
  7346. /*==========================================
  7347. * RIDのアタッチ
  7348. *------------------------------------------
  7349. */
  7350. int buildin_attachrid(struct script_state *st)
  7351. {
  7352. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7353. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  7354. return 0;
  7355. }
  7356. /*==========================================
  7357. * RIDのデタッチ
  7358. *------------------------------------------
  7359. */
  7360. int buildin_detachrid(struct script_state *st)
  7361. {
  7362. st->rid=0;
  7363. return 0;
  7364. }
  7365. /*==========================================
  7366. * 存在チェック
  7367. *------------------------------------------
  7368. */
  7369. int buildin_isloggedin(struct script_state *st)
  7370. {
  7371. push_val(st->stack,C_INT, map_id2sd(
  7372. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  7373. return 0;
  7374. }
  7375. /*==========================================
  7376. *
  7377. *------------------------------------------
  7378. */
  7379. int buildin_setmapflagnosave(struct script_state *st)
  7380. {
  7381. int m,x,y;
  7382. unsigned short mapindex;
  7383. char *str,*str2;
  7384. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7385. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7386. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7387. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7388. m = map_mapname2mapid(str);
  7389. mapindex = mapindex_name2id(str2);
  7390. if(m >= 0 && mapindex) {
  7391. map[m].flag.nosave=1;
  7392. map[m].save.map=mapindex;
  7393. map[m].save.x=x;
  7394. map[m].save.y=y;
  7395. }
  7396. return 0;
  7397. }
  7398. int buildin_setmapflag(struct script_state *st)
  7399. {
  7400. int m,i;
  7401. char *str;
  7402. char *val=NULL;
  7403. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7404. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7405. if(st->end>st->start+4){
  7406. val=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7407. }
  7408. m = map_mapname2mapid(str);
  7409. if(m >= 0) {
  7410. switch(i) {
  7411. case MF_NOMEMO:
  7412. map[m].flag.nomemo=1;
  7413. break;
  7414. case MF_NOTELEPORT:
  7415. map[m].flag.noteleport=1;
  7416. break;
  7417. case MF_NOBRANCH:
  7418. map[m].flag.nobranch=1;
  7419. break;
  7420. case MF_NOPENALTY:
  7421. map[m].flag.nopenalty=1;
  7422. break;
  7423. case MF_NOZENYPENALTY:
  7424. map[m].flag.nozenypenalty=1;
  7425. break;
  7426. case MF_PVP:
  7427. map[m].flag.pvp=1;
  7428. break;
  7429. case MF_PVP_NOPARTY:
  7430. map[m].flag.pvp_noparty=1;
  7431. break;
  7432. case MF_PVP_NOGUILD:
  7433. map[m].flag.pvp_noguild=1;
  7434. break;
  7435. case MF_GVG:
  7436. map[m].flag.gvg=1;
  7437. break;
  7438. case MF_GVG_NOPARTY:
  7439. map[m].flag.gvg_noparty=1;
  7440. break;
  7441. case MF_GVG_DUNGEON:
  7442. map[m].flag.gvg_dungeon=1;
  7443. break;
  7444. case MF_GVG_CASTLE:
  7445. map[m].flag.gvg_castle=1;
  7446. break;
  7447. case MF_NOTRADE:
  7448. map[m].flag.notrade=1;
  7449. break;
  7450. case MF_NODROP:
  7451. map[m].flag.nodrop=1;
  7452. break;
  7453. case MF_NOSKILL:
  7454. map[m].flag.noskill=1;
  7455. break;
  7456. case MF_NOWARP:
  7457. map[m].flag.nowarp=1;
  7458. break;
  7459. case MF_NOICEWALL: // [Valaris]
  7460. map[m].flag.noicewall=1;
  7461. break;
  7462. case MF_SNOW: // [Valaris]
  7463. map[m].flag.snow=1;
  7464. break;
  7465. case MF_CLOUDS:
  7466. map[m].flag.clouds=1;
  7467. break;
  7468. case MF_CLOUDS2: // [Valaris]
  7469. map[m].flag.clouds2=1;
  7470. break;
  7471. case MF_FOG: // [Valaris]
  7472. map[m].flag.fog=1;
  7473. break;
  7474. case MF_FIREWORKS:
  7475. map[m].flag.fireworks=1;
  7476. break;
  7477. case MF_SAKURA: // [Valaris]
  7478. map[m].flag.sakura=1;
  7479. break;
  7480. case MF_LEAVES: // [Valaris]
  7481. map[m].flag.leaves=1;
  7482. break;
  7483. case MF_RAIN: // [Valaris]
  7484. map[m].flag.rain=1;
  7485. break;
  7486. case MF_INDOORS: // celest
  7487. map[m].flag.indoors=1;
  7488. break;
  7489. case MF_NIGHTENABLED:
  7490. map[m].flag.nightenabled=1;
  7491. break;
  7492. case MF_NOGO: // celest
  7493. map[m].flag.nogo=1;
  7494. break;
  7495. case MF_NOBASEEXP:
  7496. map[m].flag.nobaseexp=1;
  7497. break;
  7498. case MF_NOJOBEXP:
  7499. map[m].flag.nojobexp=1;
  7500. break;
  7501. case MF_NOMOBLOOT:
  7502. map[m].flag.nomobloot=1;
  7503. break;
  7504. case MF_NOMVPLOOT:
  7505. map[m].flag.nomvploot=1;
  7506. break;
  7507. case MF_NORETURN:
  7508. map[m].flag.noreturn=1;
  7509. break;
  7510. case MF_NOWARPTO:
  7511. map[m].flag.nowarpto=1;
  7512. break;
  7513. case MF_NIGHTMAREDROP:
  7514. map[m].flag.pvp_nightmaredrop=1;
  7515. break;
  7516. case MF_RESTRICTED:
  7517. map[m].flag.restricted=1;
  7518. break;
  7519. case MF_NOCOMMAND:
  7520. map[m].flag.nocommand=1;
  7521. break;
  7522. case MF_JEXP:
  7523. map[m].jexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7524. break;
  7525. case MF_BEXP:
  7526. map[m].bexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7527. break;
  7528. case MF_NOVENDING:
  7529. map[m].flag.novending=1;
  7530. break;
  7531. case MF_LOADEVENT:
  7532. map[m].flag.loadevent=1;
  7533. break;
  7534. case MF_NOCHAT:
  7535. map[m].flag.nochat=1;
  7536. }
  7537. }
  7538. return 0;
  7539. }
  7540. int buildin_removemapflag(struct script_state *st)
  7541. {
  7542. int m,i;
  7543. char *str;
  7544. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7545. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7546. m = map_mapname2mapid(str);
  7547. if(m >= 0) {
  7548. switch(i) {
  7549. case MF_NOMEMO:
  7550. map[m].flag.nomemo=0;
  7551. break;
  7552. case MF_NOTELEPORT:
  7553. map[m].flag.noteleport=0;
  7554. break;
  7555. case MF_NOSAVE:
  7556. map[m].flag.nosave=0;
  7557. break;
  7558. case MF_NOBRANCH:
  7559. map[m].flag.nobranch=0;
  7560. break;
  7561. case MF_NOPENALTY:
  7562. map[m].flag.nopenalty=0;
  7563. break;
  7564. case MF_PVP:
  7565. map[m].flag.pvp=0;
  7566. break;
  7567. case MF_PVP_NOPARTY:
  7568. map[m].flag.pvp_noparty=0;
  7569. break;
  7570. case MF_PVP_NOGUILD:
  7571. map[m].flag.pvp_noguild=0;
  7572. break;
  7573. case MF_GVG:
  7574. map[m].flag.gvg=0;
  7575. break;
  7576. case MF_GVG_NOPARTY:
  7577. map[m].flag.gvg_noparty=0;
  7578. break;
  7579. case MF_GVG_DUNGEON:
  7580. map[m].flag.gvg_dungeon=0;
  7581. break;
  7582. case MF_GVG_CASTLE:
  7583. map[m].flag.gvg_castle=0;
  7584. break;
  7585. case MF_NOZENYPENALTY:
  7586. map[m].flag.nozenypenalty=0;
  7587. break;
  7588. case MF_NOTRADE:
  7589. map[m].flag.notrade=0;
  7590. break;
  7591. case MF_NODROP:
  7592. map[m].flag.nodrop=0;
  7593. break;
  7594. case MF_NOSKILL:
  7595. map[m].flag.noskill=0;
  7596. break;
  7597. case MF_NOWARP:
  7598. map[m].flag.nowarp=0;
  7599. break;
  7600. case MF_NOICEWALL: // [Valaris]
  7601. map[m].flag.noicewall=0;
  7602. break;
  7603. case MF_SNOW: // [Valaris]
  7604. map[m].flag.snow=0;
  7605. break;
  7606. case MF_CLOUDS:
  7607. map[m].flag.clouds=0;
  7608. break;
  7609. case MF_CLOUDS2: // [Valaris]
  7610. map[m].flag.clouds2=0;
  7611. break;
  7612. case MF_FOG: // [Valaris]
  7613. map[m].flag.fog=0;
  7614. break;
  7615. case MF_FIREWORKS:
  7616. map[m].flag.fireworks=0;
  7617. break;
  7618. case MF_SAKURA: // [Valaris]
  7619. map[m].flag.sakura=0;
  7620. break;
  7621. case MF_LEAVES: // [Valaris]
  7622. map[m].flag.leaves=0;
  7623. break;
  7624. case MF_RAIN: // [Valaris]
  7625. map[m].flag.rain=0;
  7626. break;
  7627. case MF_INDOORS: // celest
  7628. map[m].flag.indoors=0;
  7629. break;
  7630. case MF_NIGHTENABLED:
  7631. map[m].flag.nightenabled=0;
  7632. break;
  7633. case MF_NOGO: // celest
  7634. map[m].flag.nogo=0;
  7635. break;
  7636. case MF_NOBASEEXP:
  7637. map[m].flag.nobaseexp=0;
  7638. break;
  7639. case MF_NOJOBEXP:
  7640. map[m].flag.nojobexp=0;
  7641. break;
  7642. case MF_NOMOBLOOT:
  7643. map[m].flag.nomobloot=0;
  7644. break;
  7645. case MF_NOMVPLOOT:
  7646. map[m].flag.nomvploot=0;
  7647. break;
  7648. case MF_NORETURN:
  7649. map[m].flag.noreturn=0;
  7650. break;
  7651. case MF_NOWARPTO:
  7652. map[m].flag.nowarpto=0;
  7653. break;
  7654. case MF_NIGHTMAREDROP:
  7655. map[m].flag.pvp_nightmaredrop=0;
  7656. break;
  7657. case MF_RESTRICTED:
  7658. map[m].flag.restricted=0;
  7659. break;
  7660. case MF_NOCOMMAND:
  7661. map[m].flag.nocommand=0;
  7662. break;
  7663. case MF_JEXP:
  7664. map[m].jexp=100;
  7665. break;
  7666. case MF_BEXP:
  7667. map[m].bexp=100;
  7668. break;
  7669. case MF_NOVENDING:
  7670. map[m].flag.novending=0;
  7671. break;
  7672. case MF_LOADEVENT:
  7673. map[m].flag.loadevent=0;
  7674. break;
  7675. case MF_NOCHAT:
  7676. map[m].flag.nochat=0;
  7677. }
  7678. }
  7679. return 0;
  7680. }
  7681. int buildin_pvpon(struct script_state *st)
  7682. {
  7683. int m,i,users;
  7684. char *str;
  7685. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7686. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7687. m = map_mapname2mapid(str);
  7688. if(m >= 0 && !map[m].flag.pvp) {
  7689. map[m].flag.pvp = 1;
  7690. clif_send0199(m,1);
  7691. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  7692. return 0;
  7693. pl_allsd = map_getallusers(&users);
  7694. for(i=0;i<users;i++)
  7695. {
  7696. if ((pl_sd = pl_allsd[i]) && m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
  7697. {
  7698. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  7699. pl_sd->pvp_rank=0;
  7700. pl_sd->pvp_lastusers=0;
  7701. pl_sd->pvp_point=5;
  7702. pl_sd->pvp_won = 0;
  7703. pl_sd->pvp_lost = 0;
  7704. }
  7705. }
  7706. }
  7707. return 0;
  7708. }
  7709. int buildin_pvpoff(struct script_state *st)
  7710. {
  7711. int m,i,users;
  7712. char *str;
  7713. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7714. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7715. m = map_mapname2mapid(str);
  7716. if(m >= 0 && map[m].flag.pvp) { //fixed Lupus
  7717. map[m].flag.pvp = 0;
  7718. clif_send0199(m,0);
  7719. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  7720. return 0;
  7721. pl_allsd = map_getallusers(&users);
  7722. for(i=0;i<users;i++)
  7723. {
  7724. if((pl_sd=pl_allsd[i]) && m == pl_sd->bl.m)
  7725. {
  7726. clif_pvpset(pl_sd,0,0,2);
  7727. if(pl_sd->pvp_timer != -1) {
  7728. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  7729. pl_sd->pvp_timer = -1;
  7730. }
  7731. }
  7732. }
  7733. }
  7734. return 0;
  7735. }
  7736. int buildin_gvgon(struct script_state *st)
  7737. {
  7738. int m;
  7739. char *str;
  7740. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7741. m = map_mapname2mapid(str);
  7742. if(m >= 0 && !map[m].flag.gvg) {
  7743. map[m].flag.gvg = 1;
  7744. clif_send0199(m,3);
  7745. }
  7746. return 0;
  7747. }
  7748. int buildin_gvgoff(struct script_state *st)
  7749. {
  7750. int m;
  7751. char *str;
  7752. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7753. m = map_mapname2mapid(str);
  7754. if(m >= 0 && map[m].flag.gvg) {
  7755. map[m].flag.gvg = 0;
  7756. clif_send0199(m,0);
  7757. }
  7758. return 0;
  7759. }
  7760. /*==========================================
  7761. * Shows an emoticon on top of the player/npc
  7762. * emotion emotion#, <target: 0 - NPC, 1 - PC>
  7763. *------------------------------------------
  7764. */
  7765. //Optional second parameter added by [Skotlex]
  7766. int buildin_emotion(struct script_state *st)
  7767. {
  7768. int type;
  7769. int player=0;
  7770. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7771. if(type < 0 || type > 100)
  7772. return 0;
  7773. if( st->end>st->start+3 )
  7774. player=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7775. if (player) {
  7776. struct map_session_data *sd = script_rid2sd(st);
  7777. if (sd)
  7778. clif_emotion(&sd->bl,type);
  7779. } else
  7780. clif_emotion(map_id2bl(st->oid),type);
  7781. return 0;
  7782. }
  7783. int buildin_maprespawnguildid_sub(struct block_list *bl,va_list ap)
  7784. {
  7785. int g_id=va_arg(ap,int);
  7786. int flag=va_arg(ap,int);
  7787. struct map_session_data *sd=NULL;
  7788. struct mob_data *md=NULL;
  7789. if(bl->type == BL_PC)
  7790. sd=(struct map_session_data*)bl;
  7791. if(bl->type == BL_MOB)
  7792. md=(struct mob_data *)bl;
  7793. if(sd){
  7794. if((sd->status.guild_id == g_id) && (flag&1))
  7795. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  7796. else if((sd->status.guild_id != g_id) && (flag&2))
  7797. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  7798. else if (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  7799. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3); // end addition [Valaris]
  7800. }
  7801. if(md && flag&4){
  7802. if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
  7803. unit_remove_map(bl,1);
  7804. }
  7805. return 0;
  7806. }
  7807. int buildin_maprespawnguildid(struct script_state *st)
  7808. {
  7809. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7810. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7811. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7812. int m=map_mapname2mapid(mapname);
  7813. if(m) map_foreachinmap(buildin_maprespawnguildid_sub,m,BL_CHAR,g_id,flag);
  7814. return 0;
  7815. }
  7816. int buildin_agitstart(struct script_state *st)
  7817. {
  7818. if(agit_flag==1) return 0; // Agit already Start.
  7819. agit_flag=1;
  7820. guild_agit_start();
  7821. return 0;
  7822. }
  7823. int buildin_agitend(struct script_state *st)
  7824. {
  7825. if(agit_flag==0) return 0; // Agit already End.
  7826. agit_flag=0;
  7827. guild_agit_end();
  7828. return 0;
  7829. }
  7830. /*==========================================
  7831. * agitcheck 1; // choice script
  7832. * if(@agit_flag == 1) goto agit;
  7833. * if(agitcheck(0) == 1) goto agit;
  7834. *------------------------------------------
  7835. */
  7836. int buildin_agitcheck(struct script_state *st)
  7837. {
  7838. struct map_session_data *sd;
  7839. int cond;
  7840. cond=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7841. if(cond == 0) {
  7842. if (agit_flag==1) push_val(st->stack,C_INT,1);
  7843. if (agit_flag==0) push_val(st->stack,C_INT,0);
  7844. } else {
  7845. sd=script_rid2sd(st);
  7846. if (agit_flag==1) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),1);
  7847. if (agit_flag==0) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),0);
  7848. }
  7849. return 0;
  7850. }
  7851. int buildin_flagemblem(struct script_state *st)
  7852. {
  7853. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7854. if(g_id < 0) return 0;
  7855. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  7856. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  7857. return 0;
  7858. }
  7859. int buildin_getcastlename(struct script_state *st)
  7860. {
  7861. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7862. struct guild_castle *gc;
  7863. int i;
  7864. for(i=0;i<MAX_GUILDCASTLE;i++){
  7865. if( (gc=guild_castle_search(i)) != NULL ){
  7866. if(strcmp(mapname,gc->map_name)==0){
  7867. break;
  7868. }
  7869. }
  7870. }
  7871. if(gc)
  7872. push_str(st->stack,C_CONSTSTR,(unsigned char *) gc->castle_name);
  7873. else
  7874. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  7875. return 0;
  7876. }
  7877. int buildin_getcastledata(struct script_state *st)
  7878. {
  7879. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7880. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7881. char *event=NULL;
  7882. struct guild_castle *gc;
  7883. int i,j;
  7884. if( st->end>st->start+4 && index==0){
  7885. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  7886. if( (gc=guild_castle_search(i)) != NULL &&
  7887. strcmp(mapname,gc->map_name)==0 )
  7888. j=i;
  7889. if(j>=0){
  7890. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7891. check_event(st, event);
  7892. guild_addcastleinfoevent(j,17,event);
  7893. }
  7894. }
  7895. for(i=0;i<MAX_GUILDCASTLE;i++){
  7896. if( (gc=guild_castle_search(i)) != NULL ){
  7897. if(strcmp(mapname,gc->map_name)==0){
  7898. switch(index){
  7899. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  7900. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  7901. case 2: push_val(st->stack,C_INT,gc->economy); break;
  7902. case 3: push_val(st->stack,C_INT,gc->defense); break;
  7903. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  7904. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  7905. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  7906. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  7907. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  7908. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  7909. case 10:
  7910. case 11:
  7911. case 12:
  7912. case 13:
  7913. case 14:
  7914. case 15:
  7915. case 16:
  7916. case 17:
  7917. push_val(st->stack,C_INT,gc->guardian[index-10].visible); break;
  7918. case 18:
  7919. case 19:
  7920. case 20:
  7921. case 21:
  7922. case 22:
  7923. case 23:
  7924. case 24:
  7925. case 25:
  7926. push_val(st->stack,C_INT,gc->guardian[index-18].hp); break;
  7927. default:
  7928. push_val(st->stack,C_INT,0); break;
  7929. }
  7930. return 0;
  7931. }
  7932. }
  7933. }
  7934. push_val(st->stack,C_INT,0);
  7935. return 0;
  7936. }
  7937. int buildin_setcastledata(struct script_state *st)
  7938. {
  7939. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7940. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7941. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7942. struct guild_castle *gc;
  7943. int i;
  7944. for(i=0;i<MAX_GUILDCASTLE;i++){
  7945. if( (gc=guild_castle_search(i)) != NULL ){
  7946. if(strcmp(mapname,gc->map_name)==0){
  7947. // Save Data byself First
  7948. switch(index){
  7949. case 1: gc->guild_id = value; break;
  7950. case 2: gc->economy = value; break;
  7951. case 3: gc->defense = value; break;
  7952. case 4: gc->triggerE = value; break;
  7953. case 5: gc->triggerD = value; break;
  7954. case 6: gc->nextTime = value; break;
  7955. case 7: gc->payTime = value; break;
  7956. case 8: gc->createTime = value; break;
  7957. case 9: gc->visibleC = value; break;
  7958. case 10:
  7959. case 11:
  7960. case 12:
  7961. case 13:
  7962. case 14:
  7963. case 15:
  7964. case 16:
  7965. case 17:
  7966. gc->guardian[index-10].visible = value; break;
  7967. case 18:
  7968. case 19:
  7969. case 20:
  7970. case 21:
  7971. case 22:
  7972. case 23:
  7973. case 24:
  7974. case 25:
  7975. gc->guardian[index-18].hp = value;
  7976. if (gc->guardian[index-18].id)
  7977. { //Update this mob's HP.
  7978. struct block_list *bl = map_id2bl(gc->guardian[index-18].id);
  7979. if (!bl)
  7980. { //Wrong target?
  7981. gc->guardian[index-18].id = 0;
  7982. break;
  7983. }
  7984. if (value < 1) {
  7985. status_kill(bl);
  7986. break;
  7987. }
  7988. status_set_hp(bl, value, 0);
  7989. }
  7990. break;
  7991. default: return 0;
  7992. }
  7993. guild_castledatasave(gc->castle_id,index,value);
  7994. return 0;
  7995. }
  7996. }
  7997. }
  7998. return 0;
  7999. }
  8000. /* =====================================================================
  8001. * ギルド情報を要求する
  8002. * ---------------------------------------------------------------------
  8003. */
  8004. int buildin_requestguildinfo(struct script_state *st)
  8005. {
  8006. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8007. char *event=NULL;
  8008. if( st->end>st->start+3 ){
  8009. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8010. check_event(st, event);
  8011. }
  8012. if(guild_id>0)
  8013. guild_npc_request_info(guild_id,event);
  8014. return 0;
  8015. }
  8016. /* =====================================================================
  8017. * カードの数を得る
  8018. * ---------------------------------------------------------------------
  8019. */
  8020. int buildin_getequipcardcnt(struct script_state *st)
  8021. {
  8022. int i,num;
  8023. struct map_session_data *sd;
  8024. int c=MAX_SLOTS;
  8025. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8026. sd=script_rid2sd(st);
  8027. i=pc_checkequip(sd,equip[num-1]);
  8028. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8029. {
  8030. push_val(st->stack,C_INT,0);
  8031. return 0;
  8032. }
  8033. do{
  8034. if(sd->status.inventory[i].card[c-1] &&
  8035. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8036. push_val(st->stack,C_INT,(c));
  8037. return 0;
  8038. }
  8039. }while(c--);
  8040. push_val(st->stack,C_INT,0);
  8041. return 0;
  8042. }
  8043. /* ================================================================
  8044. * カード取り外し成功
  8045. * ----------------------------------------------------------------
  8046. */
  8047. int buildin_successremovecards(struct script_state *st)
  8048. {
  8049. int i,j,num,cardflag=0,flag;
  8050. struct map_session_data *sd;
  8051. struct item item_tmp;
  8052. int c=MAX_SLOTS;
  8053. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8054. sd=script_rid2sd(st);
  8055. i=pc_checkequip(sd,equip[num-1]);
  8056. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8057. return 0;
  8058. do{
  8059. if(sd->status.inventory[i].card[c-1] &&
  8060. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8061. cardflag = 1;
  8062. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8063. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8064. item_tmp.attribute=0;
  8065. for (j = 0; j < MAX_SLOTS; j++)
  8066. item_tmp.card[j]=0;
  8067. //Logs items, got from (N)PC scripts [Lupus]
  8068. if(log_config.enable_logs&0x40)
  8069. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  8070. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  8071. clif_additem(sd,0,0,flag);
  8072. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8073. }
  8074. }
  8075. }while(c--);
  8076. if(cardflag == 1){ // カードを取り除いたアイテム所得
  8077. flag=0;
  8078. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8079. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8080. item_tmp.attribute=sd->status.inventory[i].attribute;
  8081. //Logs items, got from (N)PC scripts [Lupus]
  8082. if(log_config.enable_logs&0x40)
  8083. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8084. for (j = 0; j < MAX_SLOTS; j++)
  8085. item_tmp.card[j]=0;
  8086. pc_delitem(sd,i,1,0);
  8087. //Logs items, got from (N)PC scripts [Lupus]
  8088. if(log_config.enable_logs&0x40)
  8089. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  8090. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  8091. clif_additem(sd,0,0,flag);
  8092. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8093. }
  8094. clif_misceffect(&sd->bl,3);
  8095. return 0;
  8096. }
  8097. return 0;
  8098. }
  8099. /* ================================================================
  8100. * カード取り外し失敗 slot,type
  8101. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  8102. * ----------------------------------------------------------------
  8103. */
  8104. int buildin_failedremovecards(struct script_state *st)
  8105. {
  8106. int i,j,num,cardflag=0,flag,typefail;
  8107. struct map_session_data *sd;
  8108. struct item item_tmp;
  8109. int c=MAX_SLOTS;
  8110. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8111. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8112. sd=script_rid2sd(st);
  8113. i=pc_checkequip(sd,equip[num-1]);
  8114. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8115. return 0;
  8116. do{
  8117. if(sd->status.inventory[i].card[c-1] &&
  8118. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8119. cardflag = 1;
  8120. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  8121. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8122. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8123. item_tmp.attribute=0;
  8124. for (j = 0; j < MAX_SLOTS; j++)
  8125. item_tmp.card[j]=0;
  8126. //Logs items, got from (N)PC scripts [Lupus]
  8127. if(log_config.enable_logs&0x40)
  8128. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  8129. if((flag=pc_additem(sd,&item_tmp,1))){
  8130. clif_additem(sd,0,0,flag);
  8131. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8132. }
  8133. }
  8134. }
  8135. }while(c--);
  8136. if(cardflag == 1){
  8137. if(typefail == 0 || typefail == 2){ // 武具損失
  8138. //Logs items, got from (N)PC scripts [Lupus]
  8139. if(log_config.enable_logs&0x40)
  8140. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8141. pc_delitem(sd,i,1,0);
  8142. clif_misceffect(&sd->bl,2);
  8143. return 0;
  8144. }
  8145. if(typefail == 1){ // カードのみ損失(武具を返す)
  8146. flag=0;
  8147. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8148. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8149. item_tmp.attribute=sd->status.inventory[i].attribute;
  8150. //Logs items, got from (N)PC scripts [Lupus]
  8151. if(log_config.enable_logs&0x40)
  8152. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8153. for (j = 0; j < MAX_SLOTS; j++)
  8154. item_tmp.card[j]=0;
  8155. pc_delitem(sd,i,1,0);
  8156. //Logs items, got from (N)PC scripts [Lupus]
  8157. if(log_config.enable_logs&0x40)
  8158. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  8159. if((flag=pc_additem(sd,&item_tmp,1))){
  8160. clif_additem(sd,0,0,flag);
  8161. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8162. }
  8163. }
  8164. clif_misceffect(&sd->bl,2);
  8165. return 0;
  8166. }
  8167. return 0;
  8168. }
  8169. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  8170. {
  8171. int x,y,m;
  8172. char *str;
  8173. char *mapname;
  8174. unsigned int index;
  8175. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8176. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8177. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8178. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8179. if( (m=map_mapname2mapid(mapname))< 0)
  8180. return 0;
  8181. if(!(index=mapindex_name2id(str)))
  8182. return 0;
  8183. map_foreachinmap(buildin_areawarp_sub,
  8184. m,BL_PC,index,x,y);
  8185. return 0;
  8186. }
  8187. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  8188. {
  8189. char *npc,*command;
  8190. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8191. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8192. npc_command(map_id2sd(st->rid),npc,command);
  8193. return 0;
  8194. }
  8195. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  8196. {
  8197. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8198. // nd->lastaction=nd->timer=gettick();
  8199. npc_do_ontimer(st->oid, 1);
  8200. return 0;
  8201. }
  8202. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  8203. {
  8204. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8205. // nd->lastaction=nd->timer=-1;
  8206. npc_do_ontimer(st->oid, 0);
  8207. return 0;
  8208. }
  8209. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  8210. {
  8211. char *event=va_arg(ap,char *);
  8212. int *c=va_arg(ap,int *);
  8213. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  8214. (*c)++;
  8215. return 0;
  8216. }
  8217. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  8218. {
  8219. char *mapname,*event;
  8220. int m,c=0;
  8221. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8222. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8223. check_event(st, event);
  8224. if( (m=map_mapname2mapid(mapname))<0 ) {
  8225. push_val(st->stack,C_INT,-1);
  8226. return 0;
  8227. }
  8228. map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event,&c );
  8229. push_val(st->stack,C_INT, (c));
  8230. return 0;
  8231. }
  8232. int buildin_marriage(struct script_state *st)
  8233. {
  8234. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8235. struct map_session_data *sd=script_rid2sd(st);
  8236. struct map_session_data *p_sd=map_nick2sd(partner);
  8237. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  8238. push_val(st->stack,C_INT,0);
  8239. return 0;
  8240. }
  8241. push_val(st->stack,C_INT,1);
  8242. return 0;
  8243. }
  8244. int buildin_wedding_effect(struct script_state *st)
  8245. {
  8246. struct map_session_data *sd=script_rid2sd(st);
  8247. struct block_list *bl;
  8248. if(sd==NULL) {
  8249. bl=map_id2bl(st->oid);
  8250. } else
  8251. bl=&sd->bl;
  8252. clif_wedding_effect(bl);
  8253. return 0;
  8254. }
  8255. int buildin_divorce(struct script_state *st)
  8256. {
  8257. struct map_session_data *sd=script_rid2sd(st);
  8258. if(sd==NULL || pc_divorce(sd) < 0){
  8259. push_val(st->stack,C_INT,0);
  8260. return 0;
  8261. }
  8262. push_val(st->stack,C_INT,1);
  8263. return 0;
  8264. }
  8265. int buildin_ispartneron(struct script_state *st)
  8266. {
  8267. struct map_session_data *sd=script_rid2sd(st);
  8268. struct map_session_data *p_sd=NULL;
  8269. if(sd==NULL || !pc_ismarried(sd) ||
  8270. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8271. push_val(st->stack,C_INT,0);
  8272. return 0;
  8273. }
  8274. push_val(st->stack,C_INT,1);
  8275. return 0;
  8276. }
  8277. int buildin_getpartnerid(struct script_state *st)
  8278. {
  8279. struct map_session_data *sd=script_rid2sd(st);
  8280. if (sd == NULL) {
  8281. push_val(st->stack,C_INT,0);
  8282. return 0;
  8283. }
  8284. push_val(st->stack,C_INT,sd->status.partner_id);
  8285. return 0;
  8286. }
  8287. int buildin_getchildid(struct script_state *st)
  8288. {
  8289. struct map_session_data *sd=script_rid2sd(st);
  8290. if (sd == NULL) {
  8291. push_val(st->stack,C_INT,0);
  8292. return 0;
  8293. }
  8294. push_val(st->stack,C_INT,sd->status.child);
  8295. return 0;
  8296. }
  8297. int buildin_getmotherid(struct script_state *st)
  8298. {
  8299. struct map_session_data *sd=script_rid2sd(st);
  8300. if (sd == NULL) {
  8301. push_val(st->stack,C_INT,0);
  8302. return 0;
  8303. }
  8304. push_val(st->stack,C_INT,sd->status.mother);
  8305. return 0;
  8306. }
  8307. int buildin_getfatherid(struct script_state *st)
  8308. {
  8309. struct map_session_data *sd=script_rid2sd(st);
  8310. if (sd == NULL) {
  8311. push_val(st->stack,C_INT,0);
  8312. return 0;
  8313. }
  8314. push_val(st->stack,C_INT,sd->status.father);
  8315. return 0;
  8316. }
  8317. int buildin_warppartner(struct script_state *st)
  8318. {
  8319. int x,y;
  8320. unsigned short mapindex;
  8321. char *str;
  8322. struct map_session_data *sd=script_rid2sd(st);
  8323. struct map_session_data *p_sd=NULL;
  8324. if(sd==NULL || !pc_ismarried(sd) ||
  8325. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8326. push_val(st->stack,C_INT,0);
  8327. return 0;
  8328. }
  8329. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8330. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8331. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8332. mapindex = mapindex_name2id(str);
  8333. if (mapindex) {
  8334. pc_setpos(p_sd,mapindex,x,y,0);
  8335. push_val(st->stack,C_INT,1);
  8336. } else
  8337. push_val(st->stack,C_INT,0);
  8338. return 0;
  8339. }
  8340. /*================================================
  8341. * Script for Displaying MOB Information [Valaris]
  8342. *------------------------------------------------
  8343. */
  8344. int buildin_strmobinfo(struct script_state *st)
  8345. {
  8346. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8347. int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8348. if((class_>=0 && class_<=1000) || class_ >2000)
  8349. return 0;
  8350. switch (num) {
  8351. case 1:
  8352. push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->name);
  8353. break;
  8354. case 2:
  8355. push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->jname);
  8356. break;
  8357. case 3:
  8358. push_val(st->stack,C_INT,mob_db(class_)->lv);
  8359. break;
  8360. case 4:
  8361. push_val(st->stack,C_INT,mob_db(class_)->status.max_hp);
  8362. break;
  8363. case 5:
  8364. push_val(st->stack,C_INT,mob_db(class_)->status.max_sp);
  8365. break;
  8366. case 6:
  8367. push_val(st->stack,C_INT,mob_db(class_)->base_exp);
  8368. break;
  8369. case 7:
  8370. push_val(st->stack,C_INT,mob_db(class_)->job_exp);
  8371. break;
  8372. }
  8373. return 0;
  8374. }
  8375. /*==========================================
  8376. * Summon guardians [Valaris]
  8377. *------------------------------------------
  8378. */
  8379. int buildin_guardian(struct script_state *st)
  8380. {
  8381. int class_=0,amount=1,x=0,y=0,guardian=0;
  8382. char *str,*map,*event="";
  8383. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  8384. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  8385. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  8386. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  8387. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8388. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  8389. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  8390. if( st->end>st->start+9 )
  8391. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  8392. check_event(st, event);
  8393. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
  8394. return 0;
  8395. }
  8396. /*================================================
  8397. * Script for Displaying Guardian Info [Valaris]
  8398. *------------------------------------------------
  8399. */
  8400. int buildin_guardianinfo(struct script_state *st)
  8401. {
  8402. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8403. struct map_session_data *sd=script_rid2sd(st);
  8404. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  8405. if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
  8406. {
  8407. push_val(st->stack,C_INT,-1);
  8408. return 0;
  8409. }
  8410. if(gc->guardian[guardian].visible)
  8411. push_val(st->stack,C_INT,gc->guardian[guardian].hp);
  8412. else push_val(st->stack,C_INT,-1);
  8413. return 0;
  8414. }
  8415. /*==========================================
  8416. * IDからItem名
  8417. *------------------------------------------
  8418. */
  8419. int buildin_getitemname(struct script_state *st)
  8420. {
  8421. int item_id=0;
  8422. struct item_data *i_data;
  8423. char *item_name;
  8424. struct script_data *data;
  8425. data=&(st->stack->stack_data[st->start+2]);
  8426. get_val(st,data);
  8427. if( data->type==C_STR || data->type==C_CONSTSTR ){
  8428. const char *name=conv_str(st,data);
  8429. struct item_data *item_data = itemdb_searchname(name);
  8430. if( item_data )
  8431. item_id=item_data->nameid;
  8432. }else
  8433. item_id=conv_num(st,data);
  8434. i_data = itemdb_exists(item_id);
  8435. if (i_data == NULL)
  8436. {
  8437. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  8438. return 0;
  8439. }
  8440. item_name=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  8441. memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
  8442. push_str(st->stack,C_STR,(unsigned char *) item_name);
  8443. return 0;
  8444. }
  8445. /*==========================================
  8446. * Returns number of slots an item has. [Skotlex]
  8447. *------------------------------------------
  8448. */
  8449. int buildin_getitemslots(struct script_state *st)
  8450. {
  8451. int item_id;
  8452. struct item_data *i_data;
  8453. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8454. i_data = itemdb_exists(item_id);
  8455. if (i_data)
  8456. push_val(st->stack,C_INT,i_data->slot);
  8457. else
  8458. push_val(st->stack,C_INT,-1);
  8459. return 0;
  8460. }
  8461. /*==========================================
  8462. * Returns some values of an item [Lupus]
  8463. * Price, Weight, etc...
  8464. getiteminfo(itemID,n), where n
  8465. 0 value_buy;
  8466. 1 value_sell;
  8467. 2 type;
  8468. 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
  8469. if = 0, then monsters don't drop it at all (rare or a quest item)
  8470. if = 10000, then this item is sold in NPC shops only
  8471. 4 sex;
  8472. 5 equip;
  8473. 6 weight;
  8474. 7 atk;
  8475. 8 def;
  8476. 9 range;
  8477. 10 slot;
  8478. 11 look;
  8479. 12 elv;
  8480. 13 wlv;
  8481. *------------------------------------------
  8482. */
  8483. int buildin_getiteminfo(struct script_state *st)
  8484. {
  8485. int item_id,n;
  8486. int *item_arr;
  8487. struct item_data *i_data;
  8488. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8489. n = conv_num(st,& (st->stack->stack_data[st->start+3]));
  8490. i_data = itemdb_exists(item_id);
  8491. if (i_data && n>=0 && n<14) {
  8492. item_arr = (int*)&i_data->value_buy;
  8493. push_val(st->stack,C_INT,item_arr[n]);
  8494. } else
  8495. push_val(st->stack,C_INT,-1);
  8496. return 0;
  8497. }
  8498. /*==========================================
  8499. * Returns value from equipped item slot n [Lupus]
  8500. getequipcardid(num,slot)
  8501. where
  8502. num = eqip position slot
  8503. slot = 0,1,2,3 (Card Slot N)
  8504. This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
  8505. it's useful when you want to check item cards or if it's signed
  8506. Useful for such quests as "Sign this refined item with players name" etc
  8507. Hat[0] +4 -> Player's Hat[0] +4
  8508. *------------------------------------------
  8509. */
  8510. int buildin_getequipcardid(struct script_state *st)
  8511. {
  8512. int i,num,slot;
  8513. struct map_session_data *sd;
  8514. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8515. slot=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8516. sd=script_rid2sd(st);
  8517. i=pc_checkequip(sd,equip[num-1]);
  8518. if(i >= 0 && slot>=0 && slot<4)
  8519. push_val(st->stack,C_INT,sd->status.inventory[i].card[slot]);
  8520. else
  8521. push_val(st->stack,C_INT,0);
  8522. return 0;
  8523. }
  8524. /*==========================================
  8525. * petskillbonus [Valaris] //Rewritten by [Skotlex]
  8526. *------------------------------------------
  8527. */
  8528. int buildin_petskillbonus(struct script_state *st)
  8529. {
  8530. struct pet_data *pd;
  8531. struct map_session_data *sd=script_rid2sd(st);
  8532. if(sd==NULL || sd->pd==NULL)
  8533. return 0;
  8534. pd=sd->pd;
  8535. if (pd->bonus)
  8536. { //Clear previous bonus
  8537. if (pd->bonus->timer != -1)
  8538. delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
  8539. } else //init
  8540. pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
  8541. pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8542. pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8543. pd->bonus->duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8544. pd->bonus->delay=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8545. if (pd->state.skillbonus == 1)
  8546. pd->state.skillbonus=0; // waiting state
  8547. // wait for timer to start
  8548. if (battle_config.pet_equip_required && pd->equip == 0)
  8549. pd->bonus->timer=-1;
  8550. else
  8551. pd->bonus->timer=add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
  8552. return 0;
  8553. }
  8554. /*==========================================
  8555. * pet looting [Valaris] //Rewritten by [Skotlex]
  8556. *------------------------------------------
  8557. */
  8558. int buildin_petloot(struct script_state *st)
  8559. {
  8560. int max;
  8561. struct pet_data *pd;
  8562. struct map_session_data *sd=script_rid2sd(st);
  8563. if(sd==NULL || sd->pd==NULL)
  8564. return 0;
  8565. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8566. if(max < 1)
  8567. max = 1; //Let'em loot at least 1 item.
  8568. else if (max > MAX_PETLOOT_SIZE)
  8569. max = MAX_PETLOOT_SIZE;
  8570. pd = sd->pd;
  8571. if (pd->loot != NULL)
  8572. { //Release whatever was there already and reallocate memory
  8573. pet_lootitem_drop(pd, pd->msd);
  8574. aFree(pd->loot->item);
  8575. }
  8576. else
  8577. pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
  8578. pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
  8579. pd->loot->max=max;
  8580. pd->loot->count = 0;
  8581. pd->loot->weight = 0;
  8582. return 0;
  8583. }
  8584. /*==========================================
  8585. * PCの所持品情報読み取り
  8586. *------------------------------------------
  8587. */
  8588. int buildin_getinventorylist(struct script_state *st)
  8589. {
  8590. struct map_session_data *sd=script_rid2sd(st);
  8591. unsigned char card_var[NAME_LENGTH];
  8592. int i,j=0,k;
  8593. if(!sd) return 0;
  8594. for(i=0;i<MAX_INVENTORY;i++){
  8595. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  8596. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  8597. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  8598. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  8599. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  8600. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  8601. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  8602. for (k = 0; k < MAX_SLOTS; k++)
  8603. {
  8604. sprintf(card_var, "@inventorylist_card%d",k+1);
  8605. pc_setreg(sd,add_str(card_var)+(j<<24),sd->status.inventory[i].card[k]);
  8606. }
  8607. j++;
  8608. }
  8609. }
  8610. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_count"),j);
  8611. return 0;
  8612. }
  8613. int buildin_getskilllist(struct script_state *st)
  8614. {
  8615. struct map_session_data *sd=script_rid2sd(st);
  8616. int i,j=0;
  8617. if(!sd) return 0;
  8618. for(i=0;i<MAX_SKILL;i++){
  8619. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  8620. pc_setreg(sd,add_str((unsigned char *) "@skilllist_id")+(j<<24),sd->status.skill[i].id);
  8621. pc_setreg(sd,add_str((unsigned char *)"@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  8622. pc_setreg(sd,add_str((unsigned char *)"@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  8623. j++;
  8624. }
  8625. }
  8626. pc_setreg(sd,add_str((unsigned char *) "@skilllist_count"),j);
  8627. return 0;
  8628. }
  8629. int buildin_clearitem(struct script_state *st)
  8630. {
  8631. struct map_session_data *sd=script_rid2sd(st);
  8632. int i;
  8633. if(sd==NULL) return 0;
  8634. for (i=0; i<MAX_INVENTORY; i++) {
  8635. if (sd->status.inventory[i].amount) {
  8636. //Logs items, got from (N)PC scripts [Lupus]
  8637. if(log_config.enable_logs&0x40)
  8638. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  8639. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  8640. }
  8641. }
  8642. return 0;
  8643. }
  8644. /*==========================================
  8645. Disguise Player (returns Mob/NPC ID if success, 0 on fail) [Lupus]
  8646. *------------------------------------------
  8647. */
  8648. int buildin_disguise(struct script_state *st)
  8649. {
  8650. struct map_session_data *sd=script_rid2sd(st);
  8651. int id;
  8652. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8653. if (!mobdb_checkid(id) && !npcdb_checkid(id)) {
  8654. push_val(st->stack,C_INT,0);
  8655. return 0;
  8656. }
  8657. pc_disguise(sd, id);
  8658. push_val(st->stack,C_INT,id);
  8659. return 0;
  8660. }
  8661. /*==========================================
  8662. Undisguise Player (returns 1 if success, 0 on fail) [Lupus]
  8663. *------------------------------------------
  8664. */
  8665. int buildin_undisguise(struct script_state *st)
  8666. {
  8667. struct map_session_data *sd=script_rid2sd(st);
  8668. if (sd->disguise) {
  8669. pc_disguise(sd, 0);
  8670. push_val(st->stack,C_INT,0);
  8671. } else {
  8672. push_val(st->stack,C_INT,1);
  8673. }
  8674. return 0;
  8675. }
  8676. /*==========================================
  8677. * NPCクラスチェンジ
  8678. * classは変わりたいclass
  8679. * typeは通常0なのかな?
  8680. *------------------------------------------
  8681. */
  8682. int buildin_classchange(struct script_state *st)
  8683. {
  8684. int _class,type;
  8685. struct block_list *bl=map_id2bl(st->oid);
  8686. if(bl==NULL) return 0;
  8687. _class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8688. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8689. clif_class_change(bl,_class,type);
  8690. return 0;
  8691. }
  8692. /*==========================================
  8693. * NPCから発生するエフェクト
  8694. *------------------------------------------
  8695. */
  8696. int buildin_misceffect(struct script_state *st)
  8697. {
  8698. int type;
  8699. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8700. if(st->oid) {
  8701. struct block_list *bl = map_id2bl(st->oid);
  8702. if (bl)
  8703. clif_misceffect2(bl,type);
  8704. } else{
  8705. struct map_session_data *sd=script_rid2sd(st);
  8706. if(sd)
  8707. clif_misceffect2(&sd->bl,type);
  8708. }
  8709. return 0;
  8710. }
  8711. /*==========================================
  8712. * サウンドエフェクト
  8713. *------------------------------------------
  8714. */
  8715. int buildin_soundeffect(struct script_state *st)
  8716. {
  8717. // Redundn
  8718. struct map_session_data *sd=script_rid2sd(st);
  8719. char *name;
  8720. int type=0;
  8721. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8722. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8723. if(sd){
  8724. if(!st->rid)
  8725. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  8726. else{
  8727. clif_soundeffect(sd,&sd->bl,name,type);
  8728. }
  8729. }
  8730. return 0;
  8731. }
  8732. int soundeffect_sub(struct block_list* bl,va_list ap)
  8733. {
  8734. char *name;
  8735. int type;
  8736. nullpo_retr(0, bl);
  8737. nullpo_retr(0, ap);
  8738. name = va_arg(ap,char *);
  8739. type = va_arg(ap,int);
  8740. clif_soundeffect((struct map_session_data *)bl, bl, name, type);
  8741. return 0;
  8742. }
  8743. int buildin_soundeffectall(struct script_state *st)
  8744. {
  8745. // [Lance] - Improved.
  8746. char *name, *map = NULL;
  8747. struct block_list *bl;
  8748. int type, coverage, x0, y0, x1, y1;
  8749. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8750. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8751. coverage=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8752. if(!st->rid)
  8753. bl = map_id2bl(st->oid);
  8754. else
  8755. bl = &(script_rid2sd(st)->bl);
  8756. if(bl){
  8757. if(coverage < 23){
  8758. clif_soundeffectall(bl,name,type,coverage);
  8759. }else {
  8760. if(st->end > st->start+9){
  8761. map=conv_str(st,& (st->stack->stack_data[st->start+5]));
  8762. x0 = conv_num(st,& (st->stack->stack_data[st->start+6]));
  8763. y0 = conv_num(st,& (st->stack->stack_data[st->start+7]));
  8764. x1 = conv_num(st,& (st->stack->stack_data[st->start+8]));
  8765. y1 = conv_num(st,& (st->stack->stack_data[st->start+9]));
  8766. map_foreachinarea(soundeffect_sub,map_mapname2mapid(map),x0,y0,x1,y1,BL_PC,name,type);
  8767. } else {
  8768. ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
  8769. }
  8770. }
  8771. }
  8772. return 0;
  8773. }
  8774. /*==========================================
  8775. * pet status recovery [Valaris] / Rewritten by [Skotlex]
  8776. *------------------------------------------
  8777. */
  8778. int buildin_petrecovery(struct script_state *st)
  8779. {
  8780. struct pet_data *pd;
  8781. struct map_session_data *sd=script_rid2sd(st);
  8782. if(sd==NULL || sd->pd==NULL)
  8783. return 0;
  8784. pd=sd->pd;
  8785. if (pd->recovery)
  8786. { //Halt previous bonus
  8787. if (pd->recovery->timer != -1)
  8788. delete_timer(pd->recovery->timer, pet_recovery_timer);
  8789. } else //Init
  8790. pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
  8791. pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8792. pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8793. pd->recovery->timer=-1;
  8794. return 0;
  8795. }
  8796. /*==========================================
  8797. * pet healing [Valaris] //Rewritten by [Skotlex]
  8798. *------------------------------------------
  8799. */
  8800. int buildin_petheal(struct script_state *st)
  8801. {
  8802. struct pet_data *pd;
  8803. struct map_session_data *sd=script_rid2sd(st);
  8804. if(sd==NULL || sd->pd==NULL)
  8805. return 0;
  8806. pd=sd->pd;
  8807. if (pd->s_skill)
  8808. { //Clear previous skill
  8809. if (pd->s_skill->timer != -1)
  8810. {
  8811. if (pd->s_skill->id)
  8812. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  8813. else
  8814. delete_timer(pd->s_skill->timer, pet_heal_timer);
  8815. }
  8816. } else //init memory
  8817. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  8818. pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
  8819. //Use the lv as the amount to heal
  8820. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8821. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8822. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8823. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8824. //Use delay as initial offset to avoid skill/heal exploits
  8825. if (battle_config.pet_equip_required && pd->equip == 0)
  8826. pd->s_skill->timer=-1;
  8827. else
  8828. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
  8829. return 0;
  8830. }
  8831. /*==========================================
  8832. * pet attack skills [Valaris] //Rewritten by [Skotlex]
  8833. *------------------------------------------
  8834. */
  8835. int buildin_petskillattack(struct script_state *st)
  8836. {
  8837. struct pet_data *pd;
  8838. struct map_session_data *sd=script_rid2sd(st);
  8839. if(sd==NULL || sd->pd==NULL)
  8840. return 0;
  8841. pd=sd->pd;
  8842. if (pd->a_skill == NULL)
  8843. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  8844. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8845. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8846. pd->a_skill->div_ = 0;
  8847. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8848. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8849. return 0;
  8850. }
  8851. /*==========================================
  8852. * pet attack skills [Valaris]
  8853. *------------------------------------------
  8854. */
  8855. int buildin_petskillattack2(struct script_state *st)
  8856. {
  8857. struct pet_data *pd;
  8858. struct map_session_data *sd=script_rid2sd(st);
  8859. if(sd==NULL || sd->pd==NULL)
  8860. return 0;
  8861. pd=sd->pd;
  8862. if (pd->a_skill == NULL)
  8863. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  8864. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8865. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8866. pd->a_skill->div_ = conv_num(st,& (st->stack->stack_data[st->start+4]));
  8867. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8868. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8869. return 0;
  8870. }
  8871. /*==========================================
  8872. * pet support skills [Skotlex]
  8873. *------------------------------------------
  8874. */
  8875. int buildin_petskillsupport(struct script_state *st)
  8876. {
  8877. struct pet_data *pd;
  8878. struct map_session_data *sd=script_rid2sd(st);
  8879. if(sd==NULL || sd->pd==NULL)
  8880. return 0;
  8881. pd=sd->pd;
  8882. if (pd->s_skill)
  8883. { //Clear previous skill
  8884. if (pd->s_skill->timer != -1)
  8885. {
  8886. if (pd->s_skill->id)
  8887. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  8888. else
  8889. delete_timer(pd->s_skill->timer, pet_heal_timer);
  8890. }
  8891. } else //init memory
  8892. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  8893. pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8894. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8895. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8896. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8897. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8898. //Use delay as initial offset to avoid skill/heal exploits
  8899. if (battle_config.pet_equip_required && pd->equip == 0)
  8900. pd->s_skill->timer=-1;
  8901. else
  8902. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
  8903. return 0;
  8904. }
  8905. /*==========================================
  8906. * Scripted skill effects [Celest]
  8907. *------------------------------------------
  8908. */
  8909. int buildin_skilleffect(struct script_state *st)
  8910. {
  8911. struct map_session_data *sd;
  8912. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8913. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8914. sd=script_rid2sd(st);
  8915. clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
  8916. return 0;
  8917. }
  8918. /*==========================================
  8919. * NPC skill effects [Valaris]
  8920. *------------------------------------------
  8921. */
  8922. int buildin_npcskilleffect(struct script_state *st)
  8923. {
  8924. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  8925. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8926. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8927. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8928. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8929. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  8930. return 0;
  8931. }
  8932. /*==========================================
  8933. * Special effects [Valaris]
  8934. *------------------------------------------
  8935. */
  8936. int buildin_specialeffect(struct script_state *st)
  8937. {
  8938. struct block_list *bl=map_id2bl(st->oid);
  8939. if(bl==NULL)
  8940. return 0;
  8941. clif_specialeffect(bl,conv_num(st,& (st->stack->stack_data[st->start+2])), ((st->end > st->start+3)?conv_num(st,& (st->stack->stack_data[st->start+3])):AREA));
  8942. return 0;
  8943. }
  8944. int buildin_specialeffect2(struct script_state *st)
  8945. {
  8946. struct map_session_data *sd=script_rid2sd(st);
  8947. if(sd==NULL)
  8948. return 0;
  8949. clif_specialeffect(&sd->bl,conv_num(st,& (st->stack->stack_data[st->start+2])), ((st->end > st->start+3)?conv_num(st,& (st->stack->stack_data[st->start+3])):AREA));
  8950. return 0;
  8951. }
  8952. /*==========================================
  8953. * Nude [Valaris]
  8954. *------------------------------------------
  8955. */
  8956. int buildin_nude(struct script_state *st)
  8957. {
  8958. struct map_session_data *sd=script_rid2sd(st);
  8959. int i,calcflag=0;
  8960. if(sd==NULL)
  8961. return 0;
  8962. for(i=0;i<11;i++)
  8963. if(sd->equip_index[i] >= 0) {
  8964. if(!calcflag)
  8965. calcflag=1;
  8966. pc_unequipitem(sd,sd->equip_index[i],2);
  8967. }
  8968. if(calcflag)
  8969. status_calc_pc(sd,0);
  8970. return 0;
  8971. }
  8972. /*==========================================
  8973. * gmcommand [MouseJstr]
  8974. *
  8975. * suggested on the forums...
  8976. * splitted into atcommand & charcommand by [Skotlex]
  8977. *------------------------------------------
  8978. */
  8979. int buildin_atcommand(struct script_state *st)
  8980. {
  8981. struct map_session_data *sd=NULL;
  8982. char *cmd;
  8983. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8984. if (st->rid)
  8985. sd = script_rid2sd(st);
  8986. if (sd) is_atcommand(sd->fd, sd, cmd, 99);
  8987. else { //Use a dummy character.
  8988. struct map_session_data dummy_sd;
  8989. struct block_list *bl = NULL;
  8990. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  8991. if (st->oid) bl = map_id2bl(st->oid);
  8992. if (bl) {
  8993. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  8994. if (bl->type == BL_NPC)
  8995. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8996. }
  8997. is_atcommand(0, &dummy_sd, cmd, 99);
  8998. }
  8999. return 0;
  9000. }
  9001. int buildin_charcommand(struct script_state *st)
  9002. {
  9003. struct map_session_data *sd=NULL;
  9004. char *cmd;
  9005. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9006. if (st->rid)
  9007. sd = script_rid2sd(st);
  9008. if (sd) is_charcommand(sd->fd, sd, cmd, 99);
  9009. else { //Use a dummy character.
  9010. struct map_session_data dummy_sd;
  9011. struct block_list *bl = NULL;
  9012. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  9013. if (st->oid) bl = map_id2bl(st->oid);
  9014. if (bl) {
  9015. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9016. if (bl->type == BL_NPC)
  9017. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9018. }
  9019. is_charcommand(0, &dummy_sd, cmd, 99);
  9020. }
  9021. return 0;
  9022. }
  9023. /*==========================================
  9024. * Displays a message for the player only (like system messages like "you got an apple" )
  9025. *------------------------------------------
  9026. */
  9027. int buildin_dispbottom(struct script_state *st)
  9028. {
  9029. struct map_session_data *sd=script_rid2sd(st);
  9030. char *message;
  9031. message=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9032. if(sd)
  9033. clif_disp_onlyself(sd,message,(int)strlen(message));
  9034. return 0;
  9035. }
  9036. /*==========================================
  9037. * All The Players Full Recovery
  9038. (HP/SP full restore and resurrect if need)
  9039. *------------------------------------------
  9040. */
  9041. int buildin_recovery(struct script_state *st)
  9042. {
  9043. struct map_session_data *sd, **all_sd;
  9044. int i = 0, users;
  9045. all_sd = map_getallusers(&users);
  9046. for (i = 0; i < users; i++)
  9047. {
  9048. sd = all_sd[i];
  9049. if(pc_isdead(sd))
  9050. status_revive(&sd->bl, 100, 100);
  9051. else
  9052. status_percent_heal(&sd->bl, 100, 100);
  9053. clif_displaymessage(sd->fd,"You have been recovered!");
  9054. }
  9055. return 0;
  9056. }
  9057. /*==========================================
  9058. * Get your pet info: getpetinfo(n)
  9059. * n -> 0:pet_id 1:pet_class 2:pet_name
  9060. 3:friendly 4:hungry
  9061. *------------------------------------------
  9062. */
  9063. int buildin_getpetinfo(struct script_state *st)
  9064. {
  9065. struct map_session_data *sd=script_rid2sd(st);
  9066. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9067. if(sd && sd->status.pet_id){
  9068. switch(type){
  9069. case 0:
  9070. push_val(st->stack,C_INT,sd->status.pet_id);
  9071. break;
  9072. case 1:
  9073. push_val(st->stack,C_INT,sd->pet.class_);
  9074. break;
  9075. case 2:
  9076. if(sd->pet.name)
  9077. push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->pet.name);
  9078. else
  9079. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  9080. break;
  9081. case 3:
  9082. //if(sd->pet.intimate)
  9083. push_val(st->stack,C_INT,sd->pet.intimate);
  9084. break;
  9085. case 4:
  9086. //if(sd->pet.hungry)
  9087. push_val(st->stack,C_INT,sd->pet.hungry);
  9088. break;
  9089. default:
  9090. push_val(st->stack,C_INT,0);
  9091. break;
  9092. }
  9093. }else{
  9094. push_val(st->stack,C_INT,0);
  9095. }
  9096. return 0;
  9097. }
  9098. /*==========================================
  9099. * Shows wether your inventory(and equips) contain
  9100. selected card or not.
  9101. checkequipedcard(4001);
  9102. *------------------------------------------
  9103. */
  9104. int buildin_checkequipedcard(struct script_state *st)
  9105. {
  9106. struct map_session_data *sd=script_rid2sd(st);
  9107. int n,i,c=0;
  9108. c=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9109. if(sd){
  9110. for(i=0;i<MAX_INVENTORY;i++){
  9111. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount){
  9112. for(n=0;n<MAX_SLOTS;n++){
  9113. if(sd->status.inventory[i].card[n]==c){
  9114. push_val(st->stack,C_INT,1);
  9115. return 0;
  9116. }
  9117. }
  9118. }
  9119. }
  9120. }
  9121. push_val(st->stack,C_INT,0);
  9122. return 0;
  9123. }
  9124. int buildin_jump_zero(struct script_state *st) {
  9125. int sel;
  9126. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9127. if(!sel) {
  9128. int pos;
  9129. if( st->stack->stack_data[st->start+3].type!=C_POS ){
  9130. ShowError("script: jump_zero: not label !\n");
  9131. st->state=END;
  9132. return 0;
  9133. }
  9134. pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9135. st->pos=pos;
  9136. st->state=GOTO;
  9137. // printf("script: jump_zero: jumpto : %d\n",pos);
  9138. } else {
  9139. // printf("script: jump_zero: fail\n");
  9140. }
  9141. return 0;
  9142. }
  9143. int buildin_select(struct script_state *st)
  9144. {
  9145. char *buf;
  9146. int len,i;
  9147. struct map_session_data *sd;
  9148. sd=script_rid2sd(st);
  9149. if(sd->state.menu_or_input==0){
  9150. st->state=RERUNLINE;
  9151. sd->state.menu_or_input=1;
  9152. for(i=st->start+2,len=16;i<st->end;i++){
  9153. conv_str(st,& (st->stack->stack_data[i]));
  9154. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  9155. }
  9156. buf=(char *)aMalloc((len+1)*sizeof(char));
  9157. buf[0]=0;
  9158. for(i=st->start+2,len=0;i<st->end;i++){
  9159. strcat(buf,st->stack->stack_data[i].u.str);
  9160. strcat(buf,":");
  9161. }
  9162. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  9163. aFree(buf);
  9164. } else if(sd->npc_menu==0xff){ // cansel
  9165. sd->state.menu_or_input=0;
  9166. st->state=END;
  9167. } else {
  9168. // pc_setreg(sd,add_str((unsigned char *) "l15"),sd->npc_menu);
  9169. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  9170. sd->state.menu_or_input=0;
  9171. push_val(st->stack,C_INT,sd->npc_menu);
  9172. }
  9173. return 0;
  9174. }
  9175. /*==========================================
  9176. * GetMapMobs
  9177. returns mob counts on a set map:
  9178. e.g. GetMapMobs("prontera.gat")
  9179. use "this" - for player's map
  9180. *------------------------------------------
  9181. */
  9182. int buildin_getmapmobs(struct script_state *st)
  9183. {
  9184. char *str=NULL;
  9185. int m=-1,bx,by,i;
  9186. int count=0,c;
  9187. struct block_list *bl;
  9188. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9189. if(strcmp(str,"this")==0){
  9190. struct map_session_data *sd=script_rid2sd(st);
  9191. if(sd)
  9192. m=sd->bl.m;
  9193. else{
  9194. push_val(st->stack,C_INT,-1);
  9195. return 0;
  9196. }
  9197. }else
  9198. m=map_mapname2mapid(str);
  9199. if(m < 0){
  9200. push_val(st->stack,C_INT,-1);
  9201. return 0;
  9202. }
  9203. for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++){
  9204. for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++){
  9205. bl = map[m].block_mob[bx+by*map[m].bxs];
  9206. c = map[m].block_mob_count[bx+by*map[m].bxs];
  9207. for(i=0;i<c && bl;i++,bl=bl->next){
  9208. if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
  9209. count++;
  9210. }
  9211. }
  9212. }
  9213. push_val(st->stack,C_INT,count);
  9214. return 0;
  9215. }
  9216. /*==========================================
  9217. * movenpc [MouseJstr]
  9218. *------------------------------------------
  9219. */
  9220. int buildin_movenpc(struct script_state *st)
  9221. {
  9222. TBL_NPC *nd = NULL;
  9223. char *npc;
  9224. int x,y;
  9225. short m;
  9226. npc = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9227. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  9228. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9229. if ((nd = npc_name2id(npc)) == NULL)
  9230. return -1;
  9231. if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  9232. return -1; //Not on a map.
  9233. if (x < 0) x = 0;
  9234. else if (x >= map[m].xs) x = map[m].xs-1;
  9235. if (y < 0) y = 0;
  9236. else if (y >= map[m].ys) y = map[m].ys-1;
  9237. map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9238. map_moveblock(&nd->bl, x, y, gettick());
  9239. map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9240. return 0;
  9241. }
  9242. /*==========================================
  9243. * message [MouseJstr]
  9244. *------------------------------------------
  9245. */
  9246. int buildin_message(struct script_state *st)
  9247. {
  9248. struct map_session_data *sd;
  9249. char *msg,*player;
  9250. struct map_session_data *pl_sd = NULL;
  9251. sd = script_rid2sd(st);
  9252. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9253. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9254. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  9255. return 0;
  9256. clif_displaymessage(pl_sd->fd, msg);
  9257. return 0;
  9258. }
  9259. /*==========================================
  9260. * npctalk (sends message to surrounding
  9261. * area) [Valaris]
  9262. *------------------------------------------
  9263. */
  9264. int buildin_npctalk(struct script_state *st)
  9265. {
  9266. char *str;
  9267. char message[255];
  9268. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9269. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9270. if(nd) {
  9271. memcpy(message, nd->name, NAME_LENGTH);
  9272. strcat(message," : ");
  9273. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  9274. clif_message(&(nd->bl), message);
  9275. }
  9276. return 0;
  9277. }
  9278. /*==========================================
  9279. * hasitems (checks to see if player has any
  9280. * items on them, if so will return a 1)
  9281. * [Valaris]
  9282. *------------------------------------------
  9283. */
  9284. int buildin_hasitems(struct script_state *st)
  9285. {
  9286. int i;
  9287. struct map_session_data *sd;
  9288. sd=script_rid2sd(st);
  9289. for(i=0; i<MAX_INVENTORY; i++) {
  9290. if(sd->status.inventory[i].amount && sd->status.inventory[i].nameid!=2364 && sd->status.inventory[i].nameid!=2365) {
  9291. push_val(st->stack,C_INT,1);
  9292. return 0;
  9293. }
  9294. }
  9295. push_val(st->stack,C_INT,0);
  9296. return 0;
  9297. }
  9298. // change npc walkspeed [Valaris]
  9299. int buildin_npcspeed(struct script_state *st)
  9300. {
  9301. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9302. int x=0;
  9303. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9304. if(nd) {
  9305. nd->speed=x;
  9306. }
  9307. return 0;
  9308. }
  9309. // make an npc walk to a position [Valaris]
  9310. int buildin_npcwalkto(struct script_state *st)
  9311. {
  9312. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9313. int x=0,y=0;
  9314. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9315. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9316. if(nd) {
  9317. unit_walktoxy(&nd->bl,x,y,0);
  9318. }
  9319. return 0;
  9320. }
  9321. // stop an npc's movement [Valaris]
  9322. int buildin_npcstop(struct script_state *st)
  9323. {
  9324. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9325. if(nd) {
  9326. unit_stop_walking(&nd->bl,1);
  9327. }
  9328. return 0;
  9329. }
  9330. /*==========================================
  9331. * getlook char info. getlook(arg)
  9332. *------------------------------------------
  9333. */
  9334. int buildin_getlook(struct script_state *st){
  9335. int type,val;
  9336. struct map_session_data *sd;
  9337. sd=script_rid2sd(st);
  9338. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9339. val=-1;
  9340. switch(type){
  9341. case LOOK_HAIR: //1
  9342. val=sd->status.hair;
  9343. break;
  9344. case LOOK_WEAPON: //2
  9345. val=sd->status.weapon;
  9346. break;
  9347. case LOOK_HEAD_BOTTOM: //3
  9348. val=sd->status.head_bottom;
  9349. break;
  9350. case LOOK_HEAD_TOP: //4
  9351. val=sd->status.head_top;
  9352. break;
  9353. case LOOK_HEAD_MID: //5
  9354. val=sd->status.head_mid;
  9355. break;
  9356. case LOOK_HAIR_COLOR: //6
  9357. val=sd->status.hair_color;
  9358. break;
  9359. case LOOK_CLOTHES_COLOR: //7
  9360. val=sd->status.clothes_color;
  9361. break;
  9362. case LOOK_SHIELD: //8
  9363. val=sd->status.shield;
  9364. break;
  9365. case LOOK_SHOES: //9
  9366. break;
  9367. }
  9368. push_val(st->stack,C_INT,val);
  9369. return 0;
  9370. }
  9371. /*==========================================
  9372. * get char save point. argument: 0- map name, 1- x, 2- y
  9373. *------------------------------------------
  9374. */
  9375. int buildin_getsavepoint(struct script_state *st)
  9376. {
  9377. int x,y,type;
  9378. char *mapname;
  9379. struct map_session_data *sd;
  9380. sd=script_rid2sd(st);
  9381. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9382. x=sd->status.save_point.x;
  9383. y=sd->status.save_point.y;
  9384. switch(type){
  9385. case 0:
  9386. mapname=(char *) aMallocA((MAP_NAME_LENGTH+1)*sizeof(char));
  9387. memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
  9388. mapname[MAP_NAME_LENGTH]='\0';
  9389. push_str(st->stack,C_STR,(unsigned char *) mapname);
  9390. break;
  9391. case 1:
  9392. push_val(st->stack,C_INT,x);
  9393. break;
  9394. case 2:
  9395. push_val(st->stack,C_INT,y);
  9396. break;
  9397. }
  9398. return 0;
  9399. }
  9400. /*==========================================
  9401. * Get position for char/npc/pet/mob objects. Added by Lorky
  9402. *
  9403. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  9404. * where type:
  9405. * MapName$ - String variable for output map name
  9406. * MapX - Integer variable for output coord X
  9407. * MapY - Integer variable for output coord Y
  9408. * type - type of object
  9409. * 0 - Character coord
  9410. * 1 - NPC coord
  9411. * 2 - Pet coord
  9412. * 3 - Mob coord (not released)
  9413. * CharName$ - Name object. If miss or "this" the current object
  9414. *
  9415. * Return:
  9416. * 0 - success
  9417. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  9418. *------------------------------------------
  9419. */
  9420. int buildin_getmapxy(struct script_state *st){
  9421. struct map_session_data *sd=NULL;
  9422. struct npc_data *nd;
  9423. struct pet_data *pd;
  9424. int num;
  9425. char *name;
  9426. char prefix;
  9427. int x,y,type;
  9428. char mapname[MAP_NAME_LENGTH+1];
  9429. memset(mapname, 0, sizeof(mapname));
  9430. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  9431. ShowWarning("script: buildin_getmapxy: not mapname variable\n");
  9432. push_val(st->stack,C_INT,-1);
  9433. return 0;
  9434. }
  9435. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  9436. ShowWarning("script: buildin_getmapxy: not mapx variable\n");
  9437. push_val(st->stack,C_INT,-1);
  9438. return 0;
  9439. }
  9440. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  9441. ShowWarning("script: buildin_getmapxy: not mapy variable\n");
  9442. push_val(st->stack,C_INT,-1);
  9443. return 0;
  9444. }
  9445. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  9446. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9447. switch (type){
  9448. case 0: //Get Character Position
  9449. if( st->end>st->start+6 )
  9450. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9451. else
  9452. sd=script_rid2sd(st);
  9453. if ( sd==NULL ) { //wrong char name or char offline
  9454. push_val(st->stack,C_INT,-1);
  9455. return 0;
  9456. }
  9457. x=sd->bl.x;
  9458. y=sd->bl.y;
  9459. memcpy(mapname,mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  9460. break;
  9461. case 1: //Get NPC Position
  9462. if( st->end > st->start+6 )
  9463. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9464. else
  9465. nd=(struct npc_data *)map_id2bl(st->oid);
  9466. if ( nd==NULL ) { //wrong npc name or char offline
  9467. push_val(st->stack,C_INT,-1);
  9468. return 0;
  9469. }
  9470. x=nd->bl.x;
  9471. y=nd->bl.y;
  9472. memcpy(mapname, map[nd->bl.m].name, MAP_NAME_LENGTH);
  9473. break;
  9474. case 2: //Get Pet Position
  9475. if( st->end>st->start+6 )
  9476. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9477. else
  9478. sd=script_rid2sd(st);
  9479. if ( sd==NULL ) { //wrong char name or char offline
  9480. push_val(st->stack,C_INT,-1);
  9481. return 0;
  9482. }
  9483. pd=sd->pd;
  9484. if(pd==NULL){ //pet data not found
  9485. push_val(st->stack,C_INT,-1);
  9486. return 0;
  9487. }
  9488. x=pd->bl.x;
  9489. y=pd->bl.y;
  9490. memcpy(mapname, map[pd->bl.m].name, MAP_NAME_LENGTH);
  9491. break;
  9492. case 3: //Get Mob Position
  9493. push_val(st->stack,C_INT,-1);
  9494. return 0;
  9495. default: //Wrong type parameter
  9496. push_val(st->stack,C_INT,-1);
  9497. return 0;
  9498. }
  9499. //Set MapName$
  9500. num=st->stack->stack_data[st->start+2].u.num;
  9501. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9502. prefix=*name;
  9503. if(not_server_variable(prefix))
  9504. sd=script_rid2sd(st);
  9505. else
  9506. sd=NULL;
  9507. set_reg(st,sd,num,name,(void*)mapname,st->stack->stack_data[st->start+2].ref);
  9508. //Set MapX
  9509. num=st->stack->stack_data[st->start+3].u.num;
  9510. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9511. prefix=*name;
  9512. if(not_server_variable(prefix))
  9513. sd=script_rid2sd(st);
  9514. else
  9515. sd=NULL;
  9516. set_reg(st,sd,num,name,(void*)x,st->stack->stack_data[st->start+3].ref);
  9517. //Set MapY
  9518. num=st->stack->stack_data[st->start+4].u.num;
  9519. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9520. prefix=*name;
  9521. if(not_server_variable(prefix))
  9522. sd=script_rid2sd(st);
  9523. else
  9524. sd=NULL;
  9525. set_reg(st,sd,num,name,(void*)y,st->stack->stack_data[st->start+4].ref);
  9526. //Return Success value
  9527. push_val(st->stack,C_INT,0);
  9528. return 0;
  9529. }
  9530. /*==========================================
  9531. * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
  9532. *------------------------------------------
  9533. */
  9534. int buildin_logmes(struct script_state *st)
  9535. {
  9536. if (log_config.npc <= 0 ) return 0;
  9537. conv_str(st,& (st->stack->stack_data[st->start+2]));
  9538. log_npc(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str);
  9539. return 0;
  9540. }
  9541. int buildin_summon(struct script_state *st)
  9542. {
  9543. int _class, id, timeout=0;
  9544. char *str,*event="";
  9545. struct map_session_data *sd;
  9546. struct mob_data *md;
  9547. int tick = gettick();
  9548. sd=script_rid2sd(st);
  9549. if (!sd) return 0;
  9550. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  9551. _class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9552. if( st->end>st->start+4 )
  9553. timeout=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9554. if( st->end>st->start+5 ){
  9555. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  9556. check_event(st, event);
  9557. }
  9558. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
  9559. id=mob_once_spawn(sd, "this", 0, 0, str,_class,1,event);
  9560. md=(struct mob_data *)map_id2bl(id);
  9561. if (!md) return 0;
  9562. md->master_id=sd->bl.id;
  9563. md->special_state.ai=1;
  9564. md->deletetimer=add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,id,0);
  9565. clif_misceffect2(&md->bl,344);
  9566. sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  9567. return 0;
  9568. }
  9569. /*==========================================
  9570. * Checks whether it is daytime/nighttime
  9571. *------------------------------------------
  9572. */
  9573. int buildin_isnight(struct script_state *st)
  9574. {
  9575. push_val(st->stack,C_INT, (night_flag == 1));
  9576. return 0;
  9577. }
  9578. int buildin_isday(struct script_state *st)
  9579. {
  9580. push_val(st->stack,C_INT, (night_flag == 0));
  9581. return 0;
  9582. }
  9583. /*================================================
  9584. * Check whether another item/card has been
  9585. * equipped - used for 2/15's cards patch [celest]
  9586. *------------------------------------------------
  9587. */
  9588. // leave this here, just in case
  9589. #if 0
  9590. int buildin_isequipped(struct script_state *st)
  9591. {
  9592. struct map_session_data *sd;
  9593. int i, j, k, id = 1;
  9594. int ret = -1;
  9595. sd = script_rid2sd(st);
  9596. for (i=0; id!=0; i++) {
  9597. int flag = 0;
  9598. FETCH (i+2, id) else id = 0;
  9599. if (id <= 0)
  9600. continue;
  9601. for (j=0; j<EQI_MAX; j++) {
  9602. int index;
  9603. index = sd->equip_index[j];
  9604. if(index < 0) continue;
  9605. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9606. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9607. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9608. if(!sd->inventory_data[index])
  9609. continue;
  9610. if(itemdb_type(id) != IT_CARD) { //Non card
  9611. if (sd->inventory_data[index]->nameid != id)
  9612. continue;
  9613. flag = 1;
  9614. break;
  9615. } else { //Card
  9616. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9617. continue;
  9618. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9619. if (sd->status.inventory[index].card[k] == id)
  9620. {
  9621. flag = 1;
  9622. break;
  9623. }
  9624. }
  9625. }
  9626. if (flag) break;
  9627. }
  9628. if (ret == -1)
  9629. ret = flag;
  9630. else
  9631. ret &= flag;
  9632. if (!ret) break;
  9633. }
  9634. push_val(st->stack,C_INT,ret);
  9635. return 0;
  9636. }
  9637. #endif
  9638. /*================================================
  9639. * Check how many items/cards in the list are
  9640. * equipped - used for 2/15's cards patch [celest]
  9641. *------------------------------------------------
  9642. */
  9643. int buildin_isequippedcnt(struct script_state *st)
  9644. {
  9645. struct map_session_data *sd;
  9646. int i, j, k, id = 1;
  9647. int ret = 0;
  9648. sd = script_rid2sd(st);
  9649. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9650. push_val(st->stack,C_INT,0);
  9651. return 0;
  9652. }
  9653. for (i=0; id!=0; i++) {
  9654. FETCH (i+2, id) else id = 0;
  9655. if (id <= 0)
  9656. continue;
  9657. for (j=0; j<EQI_MAX; j++) {
  9658. int index;
  9659. index = sd->equip_index[j];
  9660. if(index < 0) continue;
  9661. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9662. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9663. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9664. if(!sd->inventory_data[index])
  9665. continue;
  9666. if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
  9667. if (sd->inventory_data[index]->nameid == id)
  9668. ret+= sd->status.inventory[index].amount;
  9669. } else { //Count cards.
  9670. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9671. continue; //No cards
  9672. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9673. if (sd->status.inventory[index].card[k] == id)
  9674. ret++; //[Lupus]
  9675. }
  9676. }
  9677. }
  9678. }
  9679. push_val(st->stack,C_INT,ret);
  9680. return 0;
  9681. }
  9682. /*================================================
  9683. * Check whether another card has been
  9684. * equipped - used for 2/15's cards patch [celest]
  9685. * -- Items checked cannot be reused in another
  9686. * card set to prevent exploits
  9687. *------------------------------------------------
  9688. */
  9689. int buildin_isequipped(struct script_state *st)
  9690. {
  9691. struct map_session_data *sd;
  9692. int i, j, k, id = 1;
  9693. int index, flag;
  9694. int ret = -1;
  9695. sd = script_rid2sd(st);
  9696. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9697. push_val(st->stack,C_INT,0);
  9698. return 0;
  9699. }
  9700. for (i=0; id!=0; i++)
  9701. {
  9702. FETCH (i+2, id) else id = 0;
  9703. if (id <= 0)
  9704. continue;
  9705. flag = 0;
  9706. for (j=0; j<EQI_MAX; j++)
  9707. {
  9708. index = sd->equip_index[j];
  9709. if(index < 0) continue;
  9710. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9711. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9712. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9713. if(!sd->inventory_data[index])
  9714. continue;
  9715. if (itemdb_type(id) != IT_CARD) {
  9716. if (sd->inventory_data[index]->nameid != id)
  9717. continue;
  9718. flag = 1;
  9719. break;
  9720. } else { //Cards
  9721. if (sd->inventory_data[index]->slot == 0 ||
  9722. itemdb_isspecial(sd->status.inventory[index].card[0]))
  9723. continue;
  9724. for (k = 0; k < sd->inventory_data[index]->slot; k++)
  9725. { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
  9726. unsigned int hash = 0;
  9727. if (sd->status.inventory[index].card[k] != id)
  9728. continue;
  9729. hash = 1<<((j<5?j:j-5)*4 + k);
  9730. // check if card is already used by another set
  9731. if ((j<5?sd->setitem_hash:sd->setitem_hash2) & hash)
  9732. continue;
  9733. // We have found a match
  9734. flag = 1;
  9735. // Set hash so this card cannot be used by another
  9736. if (j<5)
  9737. sd->setitem_hash |= hash;
  9738. else
  9739. sd->setitem_hash2 |= hash;
  9740. break;
  9741. }
  9742. }
  9743. if (flag) break; //Card found
  9744. }
  9745. if (ret == -1)
  9746. ret = flag;
  9747. else
  9748. ret &= flag;
  9749. if (!ret) break;
  9750. }
  9751. push_val(st->stack,C_INT,ret);
  9752. return 0;
  9753. }
  9754. /*================================================
  9755. * Check how many given inserted cards in the CURRENT
  9756. * weapon - used for 2/15's cards patch [Lupus]
  9757. *------------------------------------------------
  9758. */
  9759. int buildin_cardscnt(struct script_state *st)
  9760. {
  9761. struct map_session_data *sd;
  9762. int i, k, id = 1;
  9763. int ret = 0;
  9764. int index;
  9765. sd = script_rid2sd(st);
  9766. for (i=0; id!=0; i++) {
  9767. FETCH (i+2, id) else id = 0;
  9768. if (id <= 0)
  9769. continue;
  9770. index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
  9771. if(index < 0) continue;
  9772. if(!sd->inventory_data[index])
  9773. continue;
  9774. if(itemdb_type(id) != IT_CARD) {
  9775. if (sd->inventory_data[index]->nameid == id)
  9776. ret+= sd->status.inventory[index].amount;
  9777. } else {
  9778. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9779. continue;
  9780. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9781. if (sd->status.inventory[index].card[k] == id)
  9782. ret++;
  9783. }
  9784. }
  9785. }
  9786. push_val(st->stack,C_INT,ret);
  9787. // push_val(st->stack,C_INT,current_equip_item_index);
  9788. return 0;
  9789. }
  9790. /*=======================================================
  9791. * Returns the refined number of the current item, or an
  9792. * item with inventory index specified
  9793. *-------------------------------------------------------
  9794. */
  9795. int buildin_getrefine(struct script_state *st)
  9796. {
  9797. struct map_session_data *sd;
  9798. if ((sd = script_rid2sd(st))!= NULL)
  9799. push_val(st->stack, C_INT, sd->status.inventory[current_equip_item_index].refine);
  9800. return 0;
  9801. }
  9802. /*=======================================================
  9803. * Allows 2 Parents to adopt a character as a Baby
  9804. *-------------------------------------------------------
  9805. */
  9806. int buildin_adopt(struct script_state *st)
  9807. {
  9808. int ret;
  9809. char *parent1 = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9810. char *parent2 = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9811. char *child = conv_str(st,& (st->stack->stack_data[st->start+4]));
  9812. struct map_session_data *p1_sd = map_nick2sd(parent1);
  9813. struct map_session_data *p2_sd = map_nick2sd(parent2);
  9814. struct map_session_data *c_sd = map_nick2sd(child);
  9815. if (!p1_sd || !p2_sd || !c_sd ||
  9816. p1_sd->status.base_level < 70 ||
  9817. p2_sd->status.base_level < 70)
  9818. return 0;
  9819. ret = pc_adoption(p1_sd, p2_sd, c_sd);
  9820. push_val(st->stack, C_INT, ret);
  9821. return 0;
  9822. }
  9823. /*=======================================================
  9824. * Day/Night controls
  9825. *-------------------------------------------------------
  9826. */
  9827. int buildin_night(struct script_state *st)
  9828. {
  9829. if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
  9830. return 0;
  9831. }
  9832. int buildin_day(struct script_state *st)
  9833. {
  9834. if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
  9835. return 0;
  9836. }
  9837. //=======================================================
  9838. // Unequip [Spectre]
  9839. //-------------------------------------------------------
  9840. int buildin_unequip(struct script_state *st)
  9841. {
  9842. int i;
  9843. size_t num;
  9844. struct map_session_data *sd;
  9845. num = conv_num(st,& (st->stack->stack_data[st->start+2])) - 1;
  9846. sd=script_rid2sd(st);
  9847. if(sd!=NULL && num<10)
  9848. {
  9849. i=pc_checkequip(sd,equip[num]);
  9850. pc_unequipitem(sd,i,2);
  9851. return 0;
  9852. }
  9853. return 0;
  9854. }
  9855. int buildin_equip(struct script_state *st)
  9856. {
  9857. int nameid=0,i;
  9858. struct map_session_data *sd;
  9859. struct item_data *item_data;
  9860. sd = script_rid2sd(st);
  9861. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9862. if((item_data = itemdb_exists(nameid)) == NULL)
  9863. {
  9864. if(battle_config.error_log)
  9865. ShowError("wrong item ID : equipitem(%i)\n",nameid);
  9866. return 1;
  9867. }
  9868. for(i=0;i<MAX_INVENTORY && sd->status.inventory[i].nameid!=nameid;i++);
  9869. if(i==MAX_INVENTORY) return 0;
  9870. pc_equipitem(sd,i,item_data->equip);
  9871. return 0;
  9872. }
  9873. int buildin_autoequip(struct script_state *st){
  9874. int nameid, flag;
  9875. struct item_data *item_data;
  9876. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9877. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9878. if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
  9879. item_data->flag.autoequip = flag>0?1:0;
  9880. }
  9881. return 0;
  9882. }
  9883. int buildin_setbattleflag(struct script_state *st){
  9884. char *flag, *value;
  9885. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9886. value = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9887. if (battle_set_value(flag, value) == 0)
  9888. ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'",flag);
  9889. else
  9890. ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.",flag,value);
  9891. return 0;
  9892. }
  9893. int buildin_getbattleflag(struct script_state *st){
  9894. char *flag;
  9895. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9896. push_val(st->stack,C_INT,battle_get_value(flag));
  9897. return 0;
  9898. }
  9899. //=======================================================
  9900. // strlen [Valaris]
  9901. //-------------------------------------------------------
  9902. int buildin_getstrlen(struct script_state *st) {
  9903. char *str = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9904. int len = (str) ? (int)strlen(str) : 0;
  9905. push_val(st->stack,C_INT,len);
  9906. return 0;
  9907. }
  9908. //=======================================================
  9909. // isalpha [Valaris]
  9910. //-------------------------------------------------------
  9911. int buildin_charisalpha(struct script_state *st) {
  9912. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9913. int pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9914. int val = ( str && pos>0 && (unsigned int)pos<strlen(str) ) ? isalpha( str[pos] ) : 0;
  9915. push_val(st->stack,C_INT,val);
  9916. return 0;
  9917. }
  9918. // [Lance]
  9919. int buildin_fakenpcname(struct script_state *st)
  9920. {
  9921. char *name;
  9922. char *newname;
  9923. int look;
  9924. name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9925. newname = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9926. look = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9927. if(look > 32767 || look < -32768) {
  9928. ShowError("buildin_fakenpcname: Invalid look value %d\n",look);
  9929. return 1; // Safety measure to prevent runtime errors
  9930. }
  9931. npc_changename(name,newname,(short)look);
  9932. return 0;
  9933. }
  9934. int buildin_atoi(struct script_state *st) {
  9935. char *value;
  9936. value = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9937. push_val(st->stack, C_INT, atoi(value));
  9938. return 0;
  9939. }
  9940. //-----------------------------------------------------------------------//
  9941. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA START //
  9942. //-----------------------------------------------------------------------//
  9943. int buildin_compare(struct script_state *st) {
  9944. char *message;
  9945. char *cmpstring;
  9946. int j;
  9947. message = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9948. cmpstring = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9949. for (j = 0; message[j]; j++)
  9950. message[j] = tolower(message[j]);
  9951. for (j = 0; cmpstring[j]; j++)
  9952. cmpstring[j] = tolower(cmpstring[j]);
  9953. push_val(st->stack,C_INT,(strstr(message,cmpstring) != NULL));
  9954. return 0;
  9955. }
  9956. //-----------------------------------------------------------------------//
  9957. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA END //
  9958. //-----------------------------------------------------------------------//
  9959. // [zBuffer] List of mathematics commands --->
  9960. int buildin_sqrt(struct script_state *st){
  9961. double i, a;
  9962. i = conv_num(st, &(st->stack->stack_data[st->start+2]));
  9963. a = sqrt(i);
  9964. push_val(st->stack, C_INT, (int)a);
  9965. return 0;
  9966. }
  9967. int buildin_pow(struct script_state *st){
  9968. double i, a, b;
  9969. a = conv_num(st, &(st->stack->stack_data[st->start+2]));
  9970. b = conv_num(st, &(st->stack->stack_data[st->start+3]));
  9971. i = pow(a,b);
  9972. push_val(st->stack, C_INT, (int)i);
  9973. return 0;
  9974. }
  9975. int buildin_distance(struct script_state *st){
  9976. int x0, y0, x1, y1;
  9977. x0 = conv_num(st, &(st->stack->stack_data[st->start+2]));
  9978. y0 = conv_num(st, &(st->stack->stack_data[st->start+3]));
  9979. x1 = conv_num(st, &(st->stack->stack_data[st->start+4]));
  9980. y1 = conv_num(st, &(st->stack->stack_data[st->start+5]));
  9981. push_val(st->stack, C_INT, distance(x0-x1, y0-y1));
  9982. return 0;
  9983. }
  9984. int buildin_checkcell(struct script_state *st){
  9985. int m;
  9986. char *map = conv_str(st, &(st->stack->stack_data[st->start+2]));
  9987. m = mapindex_name2id(map);
  9988. if(m){
  9989. push_val(st->stack, C_INT, map_getcell(m, conv_num(st, &(st->stack->stack_data[st->start+3])), conv_num(st, &(st->stack->stack_data[st->start+4])),conv_num(st, &(st->stack->stack_data[st->start+5]))));
  9990. } else {
  9991. push_val(st->stack, C_INT, 0);
  9992. }
  9993. return 0;
  9994. }
  9995. // <--- [zBuffer] List of mathematics commands
  9996. // [zBuffer] List of dynamic var commands --->
  9997. void setd_sub(struct script_state *st, struct map_session_data *sd, char *varname, int elem, void *value, struct linkdb_node **ref)
  9998. {
  9999. set_reg(st, sd, add_str((unsigned char *) varname)+(elem<<24), varname, value, ref);
  10000. return;
  10001. }
  10002. int buildin_setd(struct script_state *st)
  10003. {
  10004. struct map_session_data *sd=NULL;
  10005. char varname[100], *buffer;
  10006. char *value;
  10007. int elem;
  10008. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10009. value = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10010. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10011. elem = 0;
  10012. if(st->rid)
  10013. sd = script_rid2sd(st);
  10014. if(varname[strlen(varname)-1] != '$') {
  10015. setd_sub(st,sd, varname, elem, (void *)atoi(value),NULL);
  10016. } else {
  10017. setd_sub(st,sd, varname, elem, (void *)value,NULL);
  10018. }
  10019. return 0;
  10020. }
  10021. #ifndef TXT_ONLY
  10022. int buildin_query_sql(struct script_state *st) {
  10023. char *name = NULL, *query;
  10024. int num, i = 0,j, nb_rows;
  10025. struct { char * dst_var_name; char type; } row[32];
  10026. struct map_session_data *sd = (st->rid)? script_rid2sd(st) : NULL;
  10027. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10028. strcpy(tmp_sql, query);
  10029. if(mysql_query(&mmysql_handle,tmp_sql)){
  10030. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10031. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10032. push_val(st->stack,C_INT,0);
  10033. return 1;
  10034. }
  10035. // If some data was returned
  10036. if((sql_res = mysql_store_result(&mmysql_handle))){
  10037. // Count the number of rows to store
  10038. nb_rows = mysql_num_fields(sql_res);
  10039. // Can't store more row than variable
  10040. if (nb_rows > st->end - (st->start+3))
  10041. nb_rows = st->end - (st->start+3);
  10042. if (!nb_rows)
  10043. {
  10044. push_val(st->stack,C_INT,0);
  10045. return 0; // Nothing to store
  10046. }
  10047. if (nb_rows > 32)
  10048. {
  10049. ShowWarning("buildin_query_sql: too much rows!\n");
  10050. push_val(st->stack,C_INT,0);
  10051. return 1;
  10052. }
  10053. memset(row, 0, sizeof(row));
  10054. // Verify argument types
  10055. for(j=0; j < nb_rows; j++)
  10056. {
  10057. if(st->stack->stack_data[st->start+3+j].type != C_NAME){
  10058. ShowWarning("buildin_query_sql: Parameter %d is not a variable!\n", j);
  10059. push_val(st->stack,C_INT,0);
  10060. return 0;
  10061. } else {
  10062. // Store type of variable (string = 0/int = 1)
  10063. num=st->stack->stack_data[st->start+3+j].u.num;
  10064. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10065. if(name[strlen(name)-1] != '$') {
  10066. row[j].type = 1;
  10067. }
  10068. row[j].dst_var_name = name;
  10069. }
  10070. }
  10071. // Store data
  10072. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  10073. for(j=0; j < nb_rows; j++)
  10074. {
  10075. if (row[j].type == 1)
  10076. setd_sub(st,sd, row[j].dst_var_name, i, (void *)atoi(sql_row[j]),st->stack->stack_data[st->start+3+j].ref);
  10077. else
  10078. setd_sub(st,sd, row[j].dst_var_name, i, (void *)sql_row[j],st->stack->stack_data[st->start+3+j].ref);
  10079. }
  10080. i++;
  10081. }
  10082. // Free data
  10083. mysql_free_result(sql_res);
  10084. }
  10085. push_val(st->stack, C_INT, i);
  10086. return 0;
  10087. }
  10088. //Allows escaping of a given string.
  10089. int buildin_escape_sql(struct script_state *st) {
  10090. char *t_query, *query;
  10091. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10092. t_query = aMallocA((strlen(query)*2+1)*sizeof(char));
  10093. jstrescapecpy(t_query,query);
  10094. push_str(st->stack,C_STR,(unsigned char *)t_query);
  10095. return 0;
  10096. }
  10097. #endif
  10098. int buildin_getd (struct script_state *st)
  10099. {
  10100. char varname[100], *buffer;
  10101. //struct script_data dat;
  10102. int elem;
  10103. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10104. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10105. elem = 0;
  10106. /*dat.type=C_NAME;
  10107. dat.u.num=add_str((unsigned char *) varname)+(elem<<24);
  10108. get_val(st,&dat);
  10109. if(dat.type == C_INT)
  10110. push_val(st->stack, C_INT, dat.u.num);
  10111. else if(dat.type == C_CONSTSTR){
  10112. buffer = aStrdup((char *)dat.u.str);
  10113. // dat.u.str holds the actual pointer to the data, must be duplicated.
  10114. // It will be freed later. Tested.
  10115. push_str(st->stack, C_STR, buffer);
  10116. }*/
  10117. // Push the 'pointer' so it's more flexible [Lance]
  10118. push_val(st->stack,C_NAME,
  10119. (elem<<24) | add_str((unsigned char *) varname));
  10120. return 0;
  10121. }
  10122. // <--- [zBuffer] List of dynamic var commands
  10123. // Pet stat [Lance]
  10124. int buildin_petstat(struct script_state *st){
  10125. struct map_session_data *sd = NULL;
  10126. char *tmp;
  10127. int flag = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10128. sd = script_rid2sd(st);
  10129. if(!sd || !sd->pet.pet_id){
  10130. if(flag == 2)
  10131. push_str(st->stack, C_CONSTSTR, "");
  10132. else
  10133. push_val(st->stack, C_INT, 0);
  10134. }
  10135. else {
  10136. switch(flag){
  10137. case 1:
  10138. push_val(st->stack, C_INT, (int)sd->pet.class_);
  10139. break;
  10140. case 2:
  10141. tmp = aStrdup(sd->pet.name);
  10142. push_str(st->stack, C_STR, tmp);
  10143. break;
  10144. case 3:
  10145. push_val(st->stack, C_INT, (int)sd->pet.level);
  10146. break;
  10147. case 4:
  10148. push_val(st->stack, C_INT, (int)sd->pet.hungry);
  10149. break;
  10150. case 5:
  10151. push_val(st->stack, C_INT, (int)sd->pet.intimate);
  10152. break;
  10153. default:
  10154. push_val(st->stack, C_INT, 0);
  10155. break;
  10156. }
  10157. }
  10158. return 0;
  10159. }
  10160. int buildin_callshop(struct script_state *st)
  10161. {
  10162. struct map_session_data *sd = NULL;
  10163. struct npc_data *nd;
  10164. char *shopname;
  10165. int flag = 0;
  10166. sd = script_rid2sd(st);
  10167. if (!sd) {
  10168. push_val(st->stack,C_INT,0);
  10169. return 0;
  10170. }
  10171. shopname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10172. if( st->end>st->start+3 )
  10173. flag = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10174. nd = npc_name2id(shopname);
  10175. if (!nd || nd->bl.type!=BL_NPC || nd->bl.subtype!=SHOP) {
  10176. ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)", shopname);
  10177. push_val(st->stack,C_INT,0);
  10178. return 1;
  10179. }
  10180. switch (flag) {
  10181. case 1: //Buy window
  10182. npc_buysellsel(sd,nd->bl.id,0);
  10183. break;
  10184. case 2: //Sell window
  10185. npc_buysellsel(sd,nd->bl.id,1);
  10186. break;
  10187. default: //Show menu
  10188. clif_npcbuysell(sd,nd->bl.id);
  10189. break;
  10190. }
  10191. sd->npc_shopid = nd->bl.id;
  10192. push_val(st->stack,C_INT,1);
  10193. return 0;
  10194. }
  10195. #ifndef MAX_SHOPITEM
  10196. #define MAX_SHOPITEM 100
  10197. #endif
  10198. int buildin_npcshopitem(struct script_state *st)
  10199. {
  10200. struct npc_data *nd= NULL;
  10201. int n = 0;
  10202. int i = 3;
  10203. int amount;
  10204. char* npcname = conv_str(st, & (st->stack->stack_data[st->start + 2]));
  10205. nd = npc_name2id(npcname);
  10206. if(nd && nd->bl.subtype==SHOP){
  10207. amount = ((st->end-2)/2)+1;
  10208. // st->end - 2 = nameid + value # ... / 2 = number of items ... + 1 to end it
  10209. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10210. sizeof(nd->u.shop_item[0]) * amount);
  10211. // Reset sell list.
  10212. memset(nd->u.shop_item, 0, sizeof(nd->u.shop_item[0]) * amount);
  10213. n = 0;
  10214. while (st->end > st->start + i) {
  10215. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10216. i++;
  10217. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10218. i++;
  10219. n++;
  10220. }
  10221. map_addiddb(&nd->bl);
  10222. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10223. } else {
  10224. ShowError("buildin_npcshopitem: shop not found.\n");
  10225. }
  10226. return 0;
  10227. }
  10228. int buildin_npcshopadditem(struct script_state *st) {
  10229. struct npc_data *nd=NULL;
  10230. int n = 0;
  10231. int i = 3;
  10232. int amount;
  10233. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10234. nd = npc_name2id(npcname);
  10235. if (nd && nd->bl.subtype==SHOP){
  10236. amount = ((st->end-2)/2)+1;
  10237. while (nd->u.shop_item[n].nameid && n < MAX_SHOPITEM)
  10238. n++;
  10239. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10240. sizeof(nd->u.shop_item[0]) * (amount+n));
  10241. while(st->end > st->start + i){
  10242. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10243. i++;
  10244. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10245. i++;
  10246. n++;
  10247. }
  10248. // Marks the last of our stuff..
  10249. nd->u.shop_item[n].value = 0;
  10250. nd->u.shop_item[n].nameid = 0;
  10251. map_addiddb(&nd->bl);
  10252. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10253. } else {
  10254. ShowError("buildin_npcshopadditem: shop not found.\n");
  10255. }
  10256. return 0;
  10257. }
  10258. int buildin_npcshopdelitem(struct script_state *st)
  10259. {
  10260. struct npc_data *nd=NULL;
  10261. int n=0;
  10262. int i=3;
  10263. int size = 0;
  10264. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10265. nd = npc_name2id(npcname);
  10266. if (nd && nd->bl.subtype==SHOP) {
  10267. while (nd->u.shop_item[size].nameid)
  10268. size++;
  10269. while (st->end > st->start+i) {
  10270. for(n=0;nd->u.shop_item[n].nameid && n < MAX_SHOPITEM;n++) {
  10271. if (nd->u.shop_item[n].nameid == conv_num(st, & (st->stack->stack_data[st->start+i]))) {
  10272. // We're moving 1 extra empty block. Junk data is eliminated later.
  10273. memmove(&nd->u.shop_item[n], &nd->u.shop_item[n+1], sizeof(nd->u.shop_item[0])*(size-n));
  10274. }
  10275. }
  10276. i++;
  10277. }
  10278. size = 0;
  10279. while (nd->u.shop_item[size].nameid)
  10280. size++;
  10281. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10282. sizeof(nd->u.shop_item[0]) * (size+1));
  10283. map_addiddb(&nd->bl);
  10284. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10285. } else {
  10286. ShowError("buildin_npcshopdelitem: shop not found.\n");
  10287. }
  10288. return 0;
  10289. }
  10290. /*==========================================
  10291. * Returns some values of an item [Lupus]
  10292. * Price, Weight, etc...
  10293. setiteminfo(itemID,"{new item bonus script}");
  10294. *------------------------------------------
  10295. */
  10296. int buildin_setitemscript(struct script_state *st)
  10297. {
  10298. int item_id;
  10299. char *script;
  10300. struct item_data *i_data;
  10301. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10302. script = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10303. i_data = itemdb_exists(item_id);
  10304. if (i_data && script!=NULL && script[0]=='{') {
  10305. if(i_data->script!=NULL)
  10306. script_free_code(i_data->script);
  10307. i_data->script = parse_script((unsigned char *) script, "script_setitemscript", 0);
  10308. push_val(st->stack,C_INT,1);
  10309. } else
  10310. push_val(st->stack,C_INT,0);
  10311. return 0;
  10312. }
  10313. /* Work In Progress [Lupus]
  10314. int buildin_addmonsterdrop(struct script_state *st)
  10315. {
  10316. int class_,item_id,chance;
  10317. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10318. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10319. chance=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10320. if(class_>1000 && item_id>500 && chance>0) {
  10321. push_val(st->stack,C_INT,1);
  10322. } else {
  10323. push_val(st->stack,C_INT,0);
  10324. }
  10325. }
  10326. int buildin_delmonsterdrop(struct script_state *st)
  10327. {
  10328. int class_,item_id;
  10329. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10330. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10331. if(class_>1000 && item_id>500) {
  10332. push_val(st->stack,C_INT,1);
  10333. } else {
  10334. push_val(st->stack,C_INT,0);
  10335. }
  10336. }
  10337. */
  10338. /*==========================================
  10339. * Returns some values of a monster [Lupus]
  10340. * Name, Level, race, size, etc...
  10341. getmonsterinfo(monsterID,queryIndex);
  10342. *------------------------------------------
  10343. */
  10344. int buildin_getmonsterinfo(struct script_state *st)
  10345. {
  10346. struct mob_db *mob;
  10347. int mob_id;
  10348. mob_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10349. if (!mobdb_checkid(mob_id)) {
  10350. ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i", mob_id);
  10351. push_val(st->stack, C_INT, -1);
  10352. return -1;
  10353. }
  10354. mob = mob_db(mob_id);
  10355. switch ( conv_num(st,& (st->stack->stack_data[st->start+3])) ) {
  10356. case 0: //Name
  10357. push_str(st->stack,C_CONSTSTR, (unsigned char *) mob->jname);
  10358. break;
  10359. case 1: //Lvl
  10360. push_val(st->stack,C_INT, mob->lv);
  10361. break;
  10362. case 2: //MaxHP
  10363. push_val(st->stack,C_INT, mob->status.max_hp);
  10364. break;
  10365. case 3: //Base EXP
  10366. push_val(st->stack,C_INT, mob->base_exp);
  10367. break;
  10368. case 4: //Job EXP
  10369. push_val(st->stack,C_INT, mob->job_exp);
  10370. break;
  10371. case 5: //Atk1
  10372. push_val(st->stack,C_INT, mob->status.rhw.atk);
  10373. break;
  10374. case 6: //Atk2
  10375. push_val(st->stack,C_INT, mob->status.rhw.atk2);
  10376. break;
  10377. case 7: //Def
  10378. push_val(st->stack,C_INT, mob->status.def);
  10379. break;
  10380. case 8: //Mdef
  10381. push_val(st->stack,C_INT, mob->status.mdef);
  10382. break;
  10383. case 9: //Str
  10384. push_val(st->stack,C_INT, mob->status.str);
  10385. break;
  10386. case 10: //Agi
  10387. push_val(st->stack,C_INT, mob->status.agi);
  10388. break;
  10389. case 11: //Vit
  10390. push_val(st->stack,C_INT, mob->status.vit);
  10391. break;
  10392. case 12: //Int
  10393. push_val(st->stack,C_INT, mob->status.int_);
  10394. break;
  10395. case 13: //Dex
  10396. push_val(st->stack,C_INT, mob->status.dex);
  10397. break;
  10398. case 14: //Luk
  10399. push_val(st->stack,C_INT, mob->status.luk);
  10400. break;
  10401. case 15: //Range
  10402. push_val(st->stack,C_INT, mob->status.rhw.range);
  10403. break;
  10404. case 16: //Range2
  10405. push_val(st->stack,C_INT, mob->range2);
  10406. break;
  10407. case 17: //Range3
  10408. push_val(st->stack,C_INT, mob->range3);
  10409. break;
  10410. case 18: //Size
  10411. push_val(st->stack,C_INT, mob->status.size);
  10412. break;
  10413. case 19: //Race
  10414. push_val(st->stack,C_INT, mob->status.race);
  10415. break;
  10416. case 20: //Element
  10417. push_val(st->stack,C_INT, mob->status.def_ele);
  10418. break;
  10419. case 21: //Mode
  10420. push_val(st->stack,C_INT, mob->status.mode);
  10421. break;
  10422. default: //wrong Index
  10423. push_val(st->stack,C_INT,-1);
  10424. }
  10425. return 0;
  10426. }
  10427. int axtoi(char *hexStg) {
  10428. int n = 0; // position in string
  10429. int m = 0; // position in digit[] to shift
  10430. int count; // loop index
  10431. int intValue = 0; // integer value of hex string
  10432. int digit[11]; // hold values to convert
  10433. while (n < 10) {
  10434. if (hexStg[n]=='\0')
  10435. break;
  10436. if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
  10437. digit[n] = hexStg[n] & 0x0f; //convert to int
  10438. else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
  10439. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10440. else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
  10441. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10442. else break;
  10443. n++;
  10444. }
  10445. count = n;
  10446. m = n - 1;
  10447. n = 0;
  10448. while(n < count) {
  10449. // digit[n] is value of hex digit at position n
  10450. // (m << 2) is the number of positions to shift
  10451. // OR the bits into return value
  10452. intValue = intValue | (digit[n] << (m << 2));
  10453. m--; // adjust the position to set
  10454. n++; // next digit to process
  10455. }
  10456. return (intValue);
  10457. }
  10458. // [Lance] Hex string to integer converter
  10459. int buildin_axtoi(struct script_state *st)
  10460. {
  10461. char *hex = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10462. push_val(st->stack, C_INT, axtoi(hex));
  10463. return 0;
  10464. }
  10465. // [zBuffer] List of player cont commands --->
  10466. int buildin_rid2name(struct script_state *st){
  10467. struct block_list *bl = NULL;
  10468. int rid = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10469. if((bl = map_id2bl(rid))){
  10470. switch(bl->type){
  10471. case BL_MOB:
  10472. push_str(st->stack,C_CONSTSTR,((struct mob_data *)bl)->name);
  10473. break;
  10474. case BL_PC:
  10475. push_str(st->stack,C_CONSTSTR,((struct map_session_data *)bl)->status.name);
  10476. break;
  10477. case BL_NPC:
  10478. push_str(st->stack,C_CONSTSTR,((struct npc_data *)bl)->exname);
  10479. break;
  10480. case BL_PET:
  10481. push_str(st->stack,C_CONSTSTR,((struct pet_data *)bl)->name);
  10482. break;
  10483. case BL_HOM:
  10484. push_str(st->stack,C_CONSTSTR,((struct homun_data *)bl)->master->homunculus.name);
  10485. break;
  10486. default:
  10487. ShowError("buildin_rid2name: BL type unknown.\n");
  10488. push_str(st->stack,C_CONSTSTR,"");
  10489. break;
  10490. }
  10491. } else {
  10492. ShowError("buildin_rid2name: invalid RID\n");
  10493. push_str(st->stack,C_CONSTSTR,"(null)");
  10494. }
  10495. return 0;
  10496. }
  10497. int buildin_pcblockmove(struct script_state *st){
  10498. int id, flag;
  10499. struct map_session_data *sd = NULL;
  10500. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10501. flag = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10502. if(id)
  10503. sd = map_id2sd(id);
  10504. else
  10505. sd = script_rid2sd(st);
  10506. if(sd)
  10507. sd->state.blockedmove = flag > 0;
  10508. return 0;
  10509. }
  10510. int buildin_pcfollow(struct script_state *st) {
  10511. int id, targetid;
  10512. struct map_session_data *sd = NULL;
  10513. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10514. targetid = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10515. if(id)
  10516. sd = map_id2sd(id);
  10517. else
  10518. sd = script_rid2sd(st);
  10519. if(sd)
  10520. pc_follow(sd, targetid);
  10521. return 0;
  10522. }
  10523. int buildin_pcstopfollow(struct script_state *st) {
  10524. int id;
  10525. struct map_session_data *sd = NULL;
  10526. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10527. if(id)
  10528. sd = map_id2sd(id);
  10529. else
  10530. sd = script_rid2sd(st);
  10531. if(sd)
  10532. pc_stop_following(sd);
  10533. return 0;
  10534. }
  10535. // <--- [zBuffer] List of player cont commands
  10536. // [zBuffer] List of mob control commands --->
  10537. int buildin_mobspawn(struct script_state *st){
  10538. int class_,x,y,id;
  10539. char *str,*map;
  10540. // Who?
  10541. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  10542. // What?
  10543. class_ =conv_num(st,& (st->stack->stack_data[st->start+3]));
  10544. // Where?
  10545. map =conv_str(st,& (st->stack->stack_data[st->start+4]));
  10546. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  10547. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  10548. id = mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,1,NULL);
  10549. push_val(st->stack,C_INT,id);
  10550. return 0;
  10551. }
  10552. int buildin_mobremove(struct script_state *st) {
  10553. int id;
  10554. struct block_list *bl = NULL;
  10555. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10556. bl = map_id2bl(id);
  10557. if (bl && bl->type == BL_MOB)
  10558. unit_free(bl);
  10559. return 0;
  10560. }
  10561. int buildin_getmobdata(struct script_state *st) {
  10562. int num, id;
  10563. char *name;
  10564. struct mob_data *md = NULL;
  10565. struct map_session_data *sd = st->rid?map_id2sd(st->rid):NULL;
  10566. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10567. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB || st->stack->stack_data[st->start+3].type!=C_NAME ){
  10568. ShowWarning("buildin_getmobdata: Error in argument!\n");
  10569. return -1;
  10570. }
  10571. num=st->stack->stack_data[st->start+3].u.num;
  10572. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10573. setd_sub(st,sd,name,0,(void *)(int)md->class_,st->stack->stack_data[st->start+3].ref);
  10574. setd_sub(st,sd,name,1,(void *)(int)md->level,st->stack->stack_data[st->start+3].ref);
  10575. setd_sub(st,sd,name,2,(void *)(int)md->status.hp,st->stack->stack_data[st->start+3].ref);
  10576. setd_sub(st,sd,name,3,(void *)(int)md->status.max_hp,st->stack->stack_data[st->start+3].ref);
  10577. setd_sub(st,sd,name,4,(void *)(int)md->master_id,st->stack->stack_data[st->start+3].ref);
  10578. setd_sub(st,sd,name,5,(void *)(int)md->bl.m,st->stack->stack_data[st->start+3].ref);
  10579. setd_sub(st,sd,name,6,(void *)(int)md->bl.x,st->stack->stack_data[st->start+3].ref);
  10580. setd_sub(st,sd,name,7,(void *)(int)md->bl.y,st->stack->stack_data[st->start+3].ref);
  10581. setd_sub(st,sd,name,8,(void *)(int)md->status.speed,st->stack->stack_data[st->start+3].ref);
  10582. setd_sub(st,sd,name,9,(void *)(int)md->status.mode,st->stack->stack_data[st->start+3].ref);
  10583. setd_sub(st,sd,name,10,(void *)(int)md->special_state.ai,st->stack->stack_data[st->start+3].ref);
  10584. setd_sub(st,sd,name,11,(void *)(int)md->sc.option,st->stack->stack_data[st->start+3].ref);
  10585. setd_sub(st,sd,name,12,(void *)(int)md->vd->sex,st->stack->stack_data[st->start+3].ref);
  10586. setd_sub(st,sd,name,13,(void *)(int)md->vd->class_,st->stack->stack_data[st->start+3].ref);
  10587. setd_sub(st,sd,name,14,(void *)(int)md->vd->hair_style,st->stack->stack_data[st->start+3].ref);
  10588. setd_sub(st,sd,name,15,(void *)(int)md->vd->hair_color,st->stack->stack_data[st->start+3].ref);
  10589. setd_sub(st,sd,name,16,(void *)(int)md->vd->head_bottom,st->stack->stack_data[st->start+3].ref);
  10590. setd_sub(st,sd,name,17,(void *)(int)md->vd->head_mid,st->stack->stack_data[st->start+3].ref);
  10591. setd_sub(st,sd,name,18,(void *)(int)md->vd->head_top,st->stack->stack_data[st->start+3].ref);
  10592. setd_sub(st,sd,name,19,(void *)(int)md->vd->cloth_color,st->stack->stack_data[st->start+3].ref);
  10593. setd_sub(st,sd,name,20,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10594. setd_sub(st,sd,name,21,(void *)(int)md->vd->weapon,st->stack->stack_data[st->start+3].ref);
  10595. setd_sub(st,sd,name,22,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10596. setd_sub(st,sd,name,23,(void *)(int)md->ud.dir,st->stack->stack_data[st->start+3].ref);
  10597. setd_sub(st,sd,name,24,(void *)(int)md->state.killer,st->stack->stack_data[st->start+3].ref);
  10598. setd_sub(st,sd,name,25,(void *)(int)md->callback_flag,st->stack->stack_data[st->start+3].ref);
  10599. setd_sub(st,sd,name,26,(void *)(int)md->state.no_random_walk, st->stack->stack_data[st->start+3].ref);
  10600. return 0;
  10601. }
  10602. int buildin_setmobdata(struct script_state *st){
  10603. int id, value, value2;
  10604. struct mob_data *md = NULL;
  10605. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10606. value = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10607. value2 = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10608. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB){
  10609. ShowWarning("buildin_setmobdata: Error in argument!\n");
  10610. return -1;
  10611. }
  10612. switch(value){
  10613. case 0:
  10614. md->class_ = (short)value2;
  10615. break;
  10616. case 1:
  10617. md->level = (unsigned short)value2;
  10618. break;
  10619. case 2:
  10620. md->status.hp = value2;
  10621. break;
  10622. case 3:
  10623. md->status.max_hp = value2;
  10624. break;
  10625. case 4:
  10626. md->master_id = value2;
  10627. break;
  10628. case 5:
  10629. md->bl.m = (short)value2;
  10630. break;
  10631. case 6:
  10632. md->bl.x = (short)value2;
  10633. break;
  10634. case 7:
  10635. md->bl.y = (short)value2;
  10636. break;
  10637. case 8:
  10638. md->status.speed = (short)value2;
  10639. break;
  10640. case 9:
  10641. md->status.mode = (short)value2;
  10642. break;
  10643. case 10:
  10644. md->special_state.ai = (unsigned int)value2;
  10645. break;
  10646. case 11:
  10647. md->sc.option = (short)value2;
  10648. break;
  10649. case 12:
  10650. md->vd->sex = value2;
  10651. break;
  10652. case 13:
  10653. md->vd->class_ = value2;
  10654. break;
  10655. case 14:
  10656. md->vd->hair_style = (short)value2;
  10657. break;
  10658. case 15:
  10659. md->vd->hair_color = (short)value2;
  10660. break;
  10661. case 16:
  10662. md->vd->head_bottom = (short)value2;
  10663. break;
  10664. case 17:
  10665. md->vd->head_mid = (short)value2;
  10666. break;
  10667. case 18:
  10668. md->vd->head_top = (short)value2;
  10669. break;
  10670. case 19:
  10671. md->vd->cloth_color = (short)value2;
  10672. break;
  10673. case 20:
  10674. md->vd->shield = value2;
  10675. break;
  10676. case 21:
  10677. md->vd->weapon = (short)value2;
  10678. break;
  10679. case 22:
  10680. md->vd->shield = (short)value2;
  10681. break;
  10682. case 23:
  10683. md->ud.dir = (unsigned char)value2;
  10684. break;
  10685. case 24:
  10686. md->state.killer = value2>0?1:0;
  10687. break;
  10688. case 25:
  10689. md->callback_flag = (short)value2;
  10690. break;
  10691. case 26:
  10692. md->state.no_random_walk = value2>0?1:0;
  10693. break;
  10694. default:
  10695. ShowError("buildin_setmobdata: argument id is not identified.");
  10696. return -1;
  10697. }
  10698. return 0;
  10699. }
  10700. int buildin_mobassist(struct script_state *st) {
  10701. int id;
  10702. char *target;
  10703. struct mob_data *md = NULL;
  10704. struct block_list *bl = NULL;
  10705. struct unit_data *ud;
  10706. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10707. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10708. if((bl =&(map_nick2sd(target)->bl)) || (bl = map_id2bl(atoi(target)))) {
  10709. md = (struct mob_data *)map_id2bl(id);
  10710. if(md && md->bl.type == BL_MOB) {
  10711. ud = unit_bl2ud(bl);
  10712. md->master_id = bl->id;
  10713. md->state.killer = 1;
  10714. mob_convertslave(md);
  10715. if (ud) {
  10716. if (ud->target)
  10717. md->target_id = ud->target;
  10718. else if (ud->skilltarget)
  10719. md->target_id = ud->skilltarget;
  10720. if(md->target_id)
  10721. unit_walktobl(&md->bl, map_id2bl(md->target_id), 65025, 2);
  10722. }
  10723. }
  10724. }
  10725. return 0;
  10726. }
  10727. int buildin_mobattach(struct script_state *st){
  10728. int id;
  10729. struct mob_data *md = NULL;
  10730. struct npc_data *nd = NULL;
  10731. char *npcname = NULL;
  10732. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10733. if(st->end > st->start + 3){
  10734. npcname = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10735. }
  10736. if(npcname)
  10737. nd = npc_name2id(npcname);
  10738. else
  10739. nd = (struct npc_data *)map_id2bl(st->oid);
  10740. if(nd)
  10741. if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB)
  10742. md->nd = nd;
  10743. return 0;
  10744. }
  10745. int buildin_unitwalk(struct script_state *st){
  10746. int id,x,y = 0;
  10747. struct block_list *bl = NULL;
  10748. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10749. x = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10750. if(st->end > st->start+4)
  10751. y = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10752. bl = map_id2bl(id);
  10753. if(bl){
  10754. if(y)
  10755. push_val(st->stack,C_INT,unit_walktoxy(bl,x,y,0)); // We'll use harder calculations.
  10756. else
  10757. push_val(st->stack,C_INT,unit_walktobl(bl,map_id2bl(x),65025,1));
  10758. } else {
  10759. push_val(st->stack,C_INT,0);
  10760. }
  10761. return 0;
  10762. }
  10763. int buildin_unitkill(struct script_state *st){
  10764. struct block_list *bl = map_id2bl(conv_num(st, & (st->stack->stack_data[st->start+2])));
  10765. if(bl)
  10766. status_kill(bl);
  10767. return 0;
  10768. }
  10769. int buildin_unitwarp(struct script_state *st){
  10770. int id,x,y,m = 0;
  10771. char *map;
  10772. struct block_list *bl = NULL;
  10773. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10774. map = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10775. x = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10776. y = conv_num(st, & (st->stack->stack_data[st->start+5]));
  10777. bl = map_id2bl(id);
  10778. m = map_mapname2mapid(map);
  10779. if(m && bl){
  10780. push_val(st->stack,C_INT,unit_warp(bl, m, (short)x, (short)y, 0));
  10781. } else {
  10782. push_val(st->stack,C_INT,0);
  10783. }
  10784. return 0;
  10785. }
  10786. int buildin_unitattack(struct script_state *st) {
  10787. int id = 0, actiontype = 0;
  10788. char *target = NULL;
  10789. struct map_session_data *sd = NULL;
  10790. struct block_list *bl = NULL, *tbl = NULL;
  10791. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10792. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10793. if(st->end > st->start + 4)
  10794. actiontype = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10795. sd = map_nick2sd(target);
  10796. if(!sd)
  10797. tbl = map_id2bl(atoi(target));
  10798. else
  10799. tbl = &sd->bl;
  10800. if((bl = map_id2bl(id))){
  10801. if (bl->type == BL_MOB) {
  10802. ((TBL_MOB *)bl)->state.killer = 1;
  10803. ((TBL_MOB *)bl)->target_id = tbl->id;
  10804. } else if(bl->type == BL_PC){
  10805. clif_parse_ActionRequest_sub(((TBL_PC *)bl), actiontype > 0?0x07:0x00, tbl->id, gettick());
  10806. push_val(st->stack,C_INT,1);
  10807. return 0;
  10808. }
  10809. push_val(st->stack,C_INT,unit_walktobl(bl, tbl, 65025, 2));
  10810. } else {
  10811. push_val(st->stack,C_INT,0);
  10812. }
  10813. return 0;
  10814. }
  10815. int buildin_unitstop(struct script_state *st) {
  10816. int id;
  10817. struct block_list *bl = NULL;
  10818. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10819. bl = map_id2bl(id);
  10820. if(bl){
  10821. unit_stop_attack(bl);
  10822. unit_stop_walking(bl,0);
  10823. if(bl->type == BL_MOB)
  10824. ((TBL_MOB *)bl)->target_id = 0;
  10825. }
  10826. return 0;
  10827. }
  10828. int buildin_unittalk(struct script_state *st)
  10829. {
  10830. char *str;
  10831. int id;
  10832. char message[255];
  10833. struct block_list *bl = NULL;
  10834. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10835. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  10836. bl = map_id2bl(id);
  10837. if(bl) {
  10838. switch(bl->type){
  10839. case BL_MOB:
  10840. memcpy(message, ((TBL_MOB *)bl)->name, NAME_LENGTH);
  10841. break;
  10842. case BL_PC:
  10843. if(strlen(((TBL_PC *)bl)->fakename)>0)
  10844. memcpy(message, ((TBL_PC *)bl)->fakename, NAME_LENGTH);
  10845. else
  10846. memcpy(message, ((TBL_PC *)bl)->status.name, NAME_LENGTH);
  10847. break;
  10848. case BL_NPC:
  10849. memcpy(message, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  10850. break;
  10851. case BL_HOM:
  10852. memcpy(message, ((TBL_HOM *)bl)->master->homunculus.name, NAME_LENGTH);
  10853. break;
  10854. case BL_PET:
  10855. memcpy(message, ((TBL_PET *)bl)->name, NAME_LENGTH);
  10856. break;
  10857. default:
  10858. strcpy(message, "Unknown");
  10859. }
  10860. strcat(message," : ");
  10861. strncat(message,str, 228); //Prevent overflow possibility. [Skotlex]
  10862. clif_message(bl, message);
  10863. if(bl->type == BL_PC)
  10864. clif_displaymessage(((TBL_PC*)bl)->fd, message);
  10865. }
  10866. return 0;
  10867. }
  10868. int buildin_unitemote(struct script_state *st) {
  10869. int id, emo;
  10870. struct block_list *bl= NULL;
  10871. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10872. emo = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10873. if((bl = map_id2bl(id)))
  10874. clif_emotion(bl,emo);
  10875. return 0;
  10876. }
  10877. int buildin_unitdeadsit(struct script_state *st){
  10878. int id, action;
  10879. struct block_list *bl = NULL;
  10880. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10881. action = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10882. if((bl = map_id2bl(id))){
  10883. if(action > -1 && action < 4){
  10884. unsigned char buf[61] = "";
  10885. switch(bl->type){
  10886. case BL_MOB:
  10887. ((TBL_MOB *)bl)->vd->dead_sit = action;
  10888. break;
  10889. case BL_PC:
  10890. ((TBL_PC *)bl)->vd.dead_sit = action;
  10891. break;
  10892. case BL_NPC:
  10893. ((TBL_NPC *)bl)->vd->dead_sit = action;
  10894. break;
  10895. case BL_HOM:
  10896. ((TBL_HOM *)bl)->vd->dead_sit = action;
  10897. break;
  10898. case BL_PET:
  10899. ((TBL_PET *)bl)->vd.dead_sit = action;
  10900. break;
  10901. WBUFW(buf, 0) = 0x8a;
  10902. WBUFL(buf, 2) = bl->id;
  10903. WBUFB(buf,26) = (unsigned char)action;
  10904. clif_send(buf, 61, bl, AREA);
  10905. }
  10906. }else {
  10907. ShowError("buildin_unitdeadsit: Invalid action.\n");
  10908. report_src(st);
  10909. }
  10910. }else{
  10911. ShowError("buildin_unitdeadsit: Target is not found.\n");
  10912. report_src(st);
  10913. }
  10914. return 0;
  10915. }
  10916. int buildin_unitskilluseid (struct script_state *st)
  10917. {
  10918. int id,skid,sklv;
  10919. struct block_list *bl = NULL;
  10920. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10921. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10922. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10923. if ((bl = map_id2bl(id)))
  10924. unit_skilluse_id(bl,(st->end>st->start+5)?conv_num(st,& (st->stack->stack_data[st->start+5])):bl->id,skid,sklv);
  10925. return 0;
  10926. }
  10927. int buildin_unitskillusepos(struct script_state *st)
  10928. {
  10929. int skid,sklv,x,y,id;
  10930. struct block_list *bl = NULL;
  10931. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10932. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10933. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10934. x=conv_num(st,& (st->stack->stack_data[st->start+5]));
  10935. y=conv_num(st,& (st->stack->stack_data[st->start+6]));
  10936. if ((bl=map_id2bl(id)))
  10937. unit_skilluse_pos(bl,x,y,skid,sklv);
  10938. return 0;
  10939. }
  10940. // <--- [zBuffer] List of mob control commands
  10941. // sleep <mili sec>
  10942. int buildin_sleep(struct script_state *st) {
  10943. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10944. struct map_session_data *sd = map_id2sd(st->rid);
  10945. if(sd && sd->npc_id == st->oid) {
  10946. sd->npc_id = 0;
  10947. }
  10948. st->rid = 0;
  10949. if(tick <= 0) {
  10950. // 何もしない
  10951. } else if( !st->sleep.tick ) {
  10952. // 初回実行
  10953. st->state = RERUNLINE;
  10954. st->sleep.tick = tick;
  10955. } else {
  10956. // 続行
  10957. st->sleep.tick = 0;
  10958. }
  10959. return 0;
  10960. }
  10961. // sleep2 <mili sec>
  10962. int buildin_sleep2(struct script_state *st) {
  10963. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10964. if( tick <= 0 ) {
  10965. // 0ms の待機時間を指定された
  10966. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  10967. } else if( !st->sleep.tick ) {
  10968. // 初回実行時
  10969. st->state = RERUNLINE;
  10970. st->sleep.tick = tick;
  10971. } else {
  10972. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  10973. st->sleep.tick = 0;
  10974. }
  10975. return 0;
  10976. }
  10977. /*==========================================
  10978. * 指定NPCの全てのsleepを再開する
  10979. *------------------------------------------
  10980. */
  10981. int buildin_awake(struct script_state *st)
  10982. {
  10983. struct npc_data *nd;
  10984. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  10985. nd = npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  10986. if(nd == NULL)
  10987. return 0;
  10988. while( node ) {
  10989. if( (int)node->key == nd->bl.id) {
  10990. struct script_state *tst = node->data;
  10991. struct map_session_data *sd = map_id2sd(tst->rid);
  10992. if( tst->sleep.timer == -1 ) {
  10993. node = node->next;
  10994. continue;
  10995. }
  10996. if((sd && sd->char_id != tst->sleep.charid) || (tst->rid && !sd))
  10997. { //Cancel Execution
  10998. tst->state=END;
  10999. tst->rid = 0;
  11000. }
  11001. delete_timer(tst->sleep.timer, run_script_timer);
  11002. node = script_erase_sleepdb(node);
  11003. tst->sleep.timer = -1;
  11004. tst->sleep.tick = 0;
  11005. run_script_main(tst);
  11006. } else {
  11007. node = node->next;
  11008. }
  11009. }
  11010. return 0;
  11011. }
  11012. // getvariableofnpc(<param>, <npc name>);
  11013. int buildin_getvariableofnpc(struct script_state *st)
  11014. {
  11015. if( st->stack->stack_data[st->start+2].type != C_NAME ) {
  11016. // 第一引数が変数名じゃない
  11017. printf("getvariableofnpc: param not name\n");
  11018. push_val(st->stack,C_INT,0);
  11019. } else {
  11020. int num = st->stack->stack_data[st->start+2].u.num;
  11021. char *var_name = str_buf+str_data[num&0x00ffffff].str;
  11022. char *npc_name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  11023. struct npc_data *nd = npc_name2id(npc_name);
  11024. if( var_name[0] != '.' || var_name[1] == '@' ) {
  11025. // ' 変数以外はダメ
  11026. printf("getvariableofnpc: invalid scope %s\n", var_name);
  11027. push_val(st->stack,C_INT,0);
  11028. } else if( nd == NULL || nd->bl.subtype != SCRIPT || !nd->u.scr.script) {
  11029. // NPC が見つからない or SCRIPT以外のNPC
  11030. printf("getvariableofnpc: can't find npc %s\n", npc_name);
  11031. push_val(st->stack,C_INT,0);
  11032. } else {
  11033. push_val2(st->stack,C_NAME,num, &nd->u.scr.script->script_vars );
  11034. }
  11035. }
  11036. return 0;
  11037. }
  11038. // [blackhole89] --->
  11039. // Set a warp portal.
  11040. int buildin_warpportal(struct script_state *st){
  11041. struct skill_unit_group *group;
  11042. unsigned short mapindex;
  11043. long spx,spy,tpx,tpy;
  11044. struct block_list *bl=map_id2bl(st->oid);
  11045. nullpo_retr(0,bl);
  11046. spx=conv_num(st, & (st->stack->stack_data[st->start+2]));
  11047. spy=conv_num(st, & (st->stack->stack_data[st->start+3]));
  11048. mapindex = mapindex_name2id((char*)conv_str(st,& (st->stack->stack_data[st->start+4])));
  11049. printf("mapindex: %d\n",mapindex);
  11050. tpx=conv_num(st, & (st->stack->stack_data[st->start+5]));
  11051. tpy=conv_num(st, & (st->stack->stack_data[st->start+6]));
  11052. if(!mapindex) return 0;
  11053. if((group=skill_unitsetting(bl,AL_WARP,4,spx,spy,1))==NULL) {
  11054. return 0;
  11055. }
  11056. group->val2=(tpx<<16)|tpy;
  11057. group->val3 = mapindex;
  11058. return 0;
  11059. }
  11060. // <-- [blackhole89]