script.c 206 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860
  1. // $Id: script.c 148 2004-09-30 14:05:37Z MouseJstr $
  2. //#define DEBUG_FUNCIN
  3. //#define DEBUG_DISP
  4. //#define DEBUG_RUN
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9. #ifndef _WIN32
  10. #include <sys/time.h>
  11. #endif
  12. #include <time.h>
  13. #include "../common/socket.h"
  14. #include "../common/timer.h"
  15. #include "../common/malloc.h"
  16. #include "../common/lock.h"
  17. #include "../common/db.h"
  18. #include "map.h"
  19. #include "clif.h"
  20. #include "chrif.h"
  21. #include "itemdb.h"
  22. #include "pc.h"
  23. #include "status.h"
  24. #include "script.h"
  25. #include "storage.h"
  26. #include "mob.h"
  27. #include "npc.h"
  28. #include "pet.h"
  29. #include "intif.h"
  30. #include "skill.h"
  31. #include "chat.h"
  32. #include "battle.h"
  33. #include "party.h"
  34. #include "guild.h"
  35. #include "atcommand.h"
  36. #include "log.h"
  37. #include "showmsg.h"
  38. #ifdef MEMWATCH
  39. #include "memwatch.h"
  40. #endif
  41. #define SCRIPT_BLOCK_SIZE 256
  42. #define FETCH(n, t) \
  43. if(st->end>st->start+(n)) \
  44. (t)=conv_num(st,&(st->stack->stack_data[st->start+(n)]));
  45. enum { LABEL_NEXTLINE=1,LABEL_START };
  46. static unsigned char * script_buf;
  47. static int script_pos,script_size;
  48. char *str_buf;
  49. int str_pos,str_size;
  50. static struct str_data_struct {
  51. int type;
  52. int str;
  53. int backpatch;
  54. int label;
  55. int (*func)(struct script_state *);
  56. int val;
  57. int next;
  58. } *str_data;
  59. int str_num=LABEL_START,str_data_size;
  60. int str_hash[16];
  61. static struct dbt *mapreg_db=NULL;
  62. static struct dbt *mapregstr_db=NULL;
  63. static int mapreg_dirty=-1;
  64. char mapreg_txt[256]="save/mapreg.txt";
  65. #define MAPREG_AUTOSAVE_INTERVAL (10*1000)
  66. static struct dbt *scriptlabel_db=NULL;
  67. static struct dbt *userfunc_db=NULL;
  68. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  69. struct dbt* script_get_userfunc_db(){ if(!userfunc_db) userfunc_db=strdb_init(50); return userfunc_db; }
  70. int scriptlabel_final(void *k,void *d,va_list ap){ return 0; }
  71. static char pos[11][100] = {"頭","体","左手","右手","ローブ","靴","アクセサリー1","アクセサリー2","頭2","頭3","装着していない"};
  72. struct Script_Config script_config;
  73. static int parse_cmd_if=0;
  74. static int parse_cmd;
  75. extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
  76. /*==========================================
  77. * ローカルプロトタイプ宣言 (必要な物のみ)
  78. *------------------------------------------
  79. */
  80. unsigned char* parse_subexpr(unsigned char *,int);
  81. int buildin_mes(struct script_state *st);
  82. int buildin_goto(struct script_state *st);
  83. int buildin_callsub(struct script_state *st);
  84. int buildin_callfunc(struct script_state *st);
  85. int buildin_return(struct script_state *st);
  86. int buildin_getarg(struct script_state *st);
  87. int buildin_next(struct script_state *st);
  88. int buildin_close(struct script_state *st);
  89. int buildin_close2(struct script_state *st);
  90. int buildin_menu(struct script_state *st);
  91. int buildin_rand(struct script_state *st);
  92. int buildin_warp(struct script_state *st);
  93. int buildin_areawarp(struct script_state *st);
  94. int buildin_heal(struct script_state *st);
  95. int buildin_itemheal(struct script_state *st);
  96. int buildin_percentheal(struct script_state *st);
  97. int buildin_jobchange(struct script_state *st);
  98. int buildin_input(struct script_state *st);
  99. int buildin_setlook(struct script_state *st);
  100. int buildin_set(struct script_state *st);
  101. int buildin_setarray(struct script_state *st);
  102. int buildin_cleararray(struct script_state *st);
  103. int buildin_copyarray(struct script_state *st);
  104. int buildin_getarraysize(struct script_state *st);
  105. int buildin_deletearray(struct script_state *st);
  106. int buildin_getelementofarray(struct script_state *st);
  107. int buildin_if(struct script_state *st);
  108. int buildin_getitem(struct script_state *st);
  109. int buildin_getitem2(struct script_state *st);
  110. int buildin_makeitem(struct script_state *st);
  111. int buildin_delitem(struct script_state *st);
  112. int buildin_viewpoint(struct script_state *st);
  113. int buildin_countitem(struct script_state *st);
  114. int buildin_checkweight(struct script_state *st);
  115. int buildin_readparam(struct script_state *st);
  116. int buildin_getcharid(struct script_state *st);
  117. int buildin_getpartyname(struct script_state *st);
  118. int buildin_getpartymember(struct script_state *st);
  119. int buildin_getguildname(struct script_state *st);
  120. int buildin_getguildmaster(struct script_state *st);
  121. int buildin_getguildmasterid(struct script_state *st);
  122. int buildin_strcharinfo(struct script_state *st);
  123. int buildin_getequipid(struct script_state *st);
  124. int buildin_getequipname(struct script_state *st);
  125. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  126. int buildin_repair(struct script_state *st); // [Valaris]
  127. int buildin_getequipisequiped(struct script_state *st);
  128. int buildin_getequipisenableref(struct script_state *st);
  129. int buildin_getequipisidentify(struct script_state *st);
  130. int buildin_getequiprefinerycnt(struct script_state *st);
  131. int buildin_getequipweaponlv(struct script_state *st);
  132. int buildin_getequippercentrefinery(struct script_state *st);
  133. int buildin_successrefitem(struct script_state *st);
  134. int buildin_failedrefitem(struct script_state *st);
  135. int buildin_cutin(struct script_state *st);
  136. int buildin_cutincard(struct script_state *st);
  137. int buildin_statusup(struct script_state *st);
  138. int buildin_statusup2(struct script_state *st);
  139. int buildin_bonus(struct script_state *st);
  140. int buildin_bonus2(struct script_state *st);
  141. int buildin_bonus3(struct script_state *st);
  142. int buildin_bonus4(struct script_state *st);
  143. int buildin_skill(struct script_state *st);
  144. int buildin_addtoskill(struct script_state *st); // [Valaris]
  145. int buildin_guildskill(struct script_state *st);
  146. int buildin_getskilllv(struct script_state *st);
  147. int buildin_getgdskilllv(struct script_state *st);
  148. int buildin_basicskillcheck(struct script_state *st);
  149. int buildin_getgmlevel(struct script_state *st);
  150. int buildin_end(struct script_state *st);
  151. int buildin_checkoption(struct script_state *st);
  152. int buildin_setoption(struct script_state *st);
  153. int buildin_setcart(struct script_state *st);
  154. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  155. int buildin_setfalcon(struct script_state *st);
  156. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  157. int buildin_setriding(struct script_state *st);
  158. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  159. int buildin_savepoint(struct script_state *st);
  160. int buildin_gettimetick(struct script_state *st);
  161. int buildin_gettime(struct script_state *st);
  162. int buildin_gettimestr(struct script_state *st);
  163. int buildin_openstorage(struct script_state *st);
  164. int buildin_guildopenstorage(struct script_state *st);
  165. int buildin_itemskill(struct script_state *st);
  166. int buildin_produce(struct script_state *st);
  167. int buildin_monster(struct script_state *st);
  168. int buildin_areamonster(struct script_state *st);
  169. int buildin_killmonster(struct script_state *st);
  170. int buildin_killmonsterall(struct script_state *st);
  171. int buildin_doevent(struct script_state *st);
  172. int buildin_donpcevent(struct script_state *st);
  173. int buildin_addtimer(struct script_state *st);
  174. int buildin_deltimer(struct script_state *st);
  175. int buildin_addtimercount(struct script_state *st);
  176. int buildin_initnpctimer(struct script_state *st);
  177. int buildin_stopnpctimer(struct script_state *st);
  178. int buildin_startnpctimer(struct script_state *st);
  179. int buildin_setnpctimer(struct script_state *st);
  180. int buildin_getnpctimer(struct script_state *st);
  181. int buildin_attachnpctimer(struct script_state *st); // [celest]
  182. int buildin_detachnpctimer(struct script_state *st); // [celest]
  183. int buildin_announce(struct script_state *st);
  184. int buildin_mapannounce(struct script_state *st);
  185. int buildin_areaannounce(struct script_state *st);
  186. int buildin_getusers(struct script_state *st);
  187. int buildin_getmapusers(struct script_state *st);
  188. int buildin_getareausers(struct script_state *st);
  189. int buildin_getareadropitem(struct script_state *st);
  190. int buildin_enablenpc(struct script_state *st);
  191. int buildin_disablenpc(struct script_state *st);
  192. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  193. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  194. int buildin_hideoffnpc(struct script_state *st);
  195. int buildin_hideonnpc(struct script_state *st);
  196. int buildin_sc_start(struct script_state *st);
  197. int buildin_sc_start2(struct script_state *st);
  198. int buildin_sc_end(struct script_state *st);
  199. int buildin_getscrate(struct script_state *st);
  200. int buildin_debugmes(struct script_state *st);
  201. int buildin_catchpet(struct script_state *st);
  202. int buildin_birthpet(struct script_state *st);
  203. int buildin_resetlvl(struct script_state *st);
  204. int buildin_resetstatus(struct script_state *st);
  205. int buildin_resetskill(struct script_state *st);
  206. int buildin_changebase(struct script_state *st);
  207. int buildin_changesex(struct script_state *st);
  208. int buildin_waitingroom(struct script_state *st);
  209. int buildin_delwaitingroom(struct script_state *st);
  210. int buildin_enablewaitingroomevent(struct script_state *st);
  211. int buildin_disablewaitingroomevent(struct script_state *st);
  212. int buildin_getwaitingroomstate(struct script_state *st);
  213. int buildin_warpwaitingpc(struct script_state *st);
  214. int buildin_attachrid(struct script_state *st);
  215. int buildin_detachrid(struct script_state *st);
  216. int buildin_isloggedin(struct script_state *st);
  217. int buildin_setmapflagnosave(struct script_state *st);
  218. int buildin_setmapflag(struct script_state *st);
  219. int buildin_removemapflag(struct script_state *st);
  220. int buildin_pvpon(struct script_state *st);
  221. int buildin_pvpoff(struct script_state *st);
  222. int buildin_gvgon(struct script_state *st);
  223. int buildin_gvgoff(struct script_state *st);
  224. int buildin_emotion(struct script_state *st);
  225. int buildin_maprespawnguildid(struct script_state *st);
  226. int buildin_agitstart(struct script_state *st); // <Agit>
  227. int buildin_agitend(struct script_state *st);
  228. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  229. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  230. int buildin_getcastlename(struct script_state *st);
  231. int buildin_getcastledata(struct script_state *st);
  232. int buildin_setcastledata(struct script_state *st);
  233. int buildin_requestguildinfo(struct script_state *st);
  234. int buildin_getequipcardcnt(struct script_state *st);
  235. int buildin_successremovecards(struct script_state *st);
  236. int buildin_failedremovecards(struct script_state *st);
  237. int buildin_marriage(struct script_state *st);
  238. int buildin_wedding_effect(struct script_state *st);
  239. int buildin_divorce(struct script_state *st);
  240. int buildin_ispartneron(struct script_state *st); // MouseJstr
  241. int buildin_getpartnerid(struct script_state *st); // MouseJstr
  242. int buildin_warppartner(struct script_state *st); // MouseJstr
  243. int buildin_getitemname(struct script_state *st);
  244. int buildin_makepet(struct script_state *st);
  245. int buildin_getexp(struct script_state *st);
  246. int buildin_getinventorylist(struct script_state *st);
  247. int buildin_getskilllist(struct script_state *st);
  248. int buildin_clearitem(struct script_state *st);
  249. int buildin_classchange(struct script_state *st);
  250. int buildin_misceffect(struct script_state *st);
  251. int buildin_soundeffect(struct script_state *st);
  252. int buildin_soundeffectall(struct script_state *st);
  253. int buildin_setcastledata(struct script_state *st);
  254. int buildin_mapwarp(struct script_state *st);
  255. int buildin_inittimer(struct script_state *st);
  256. int buildin_stoptimer(struct script_state *st);
  257. int buildin_cmdothernpc(struct script_state *st);
  258. int buildin_mobcount(struct script_state *st);
  259. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  260. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  261. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  262. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  263. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  264. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  265. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  266. int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  267. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Valaris]
  268. int buildin_skilleffect(struct script_state *st); // skill effects [Celest]
  269. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  270. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  271. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  272. int buildin_nude(struct script_state *st); // nude [Valaris]
  273. int buildin_gmcommand(struct script_state *st); // [MouseJstr]
  274. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  275. int buildin_message(struct script_state *st); // [MouseJstr]
  276. int buildin_npctalk(struct script_state *st); // [Valaris]
  277. int buildin_hasitems(struct script_state *st); // [Valaris]
  278. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  279. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  280. int buildin_npcspeed(struct script_state *st); // [Valaris]
  281. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  282. int buildin_npcstop(struct script_state *st); // [Valaris]
  283. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  284. int buildin_checkoption1(struct script_state *st); // [celest]
  285. int buildin_checkoption2(struct script_state *st); // [celest]
  286. int buildin_guildgetexp(struct script_state *st); // [celest]
  287. int buildin_skilluseid(struct script_state *st); // originally by Qamera [celest]
  288. int buildin_skillusepos(struct script_state *st); // originally by Qamera [celest]
  289. int buildin_logmes(struct script_state *st); // [Lupus]
  290. int buildin_summon(struct script_state *st); // [celest]
  291. int buildin_isnight(struct script_state *st); // [celest]
  292. int buildin_isday(struct script_state *st); // [celest]
  293. int buildin_isequipped(struct script_state *st); // [celest]
  294. int buildin_isequippedcnt(struct script_state *st); // [celest]
  295. int buildin_cardscnt(struct script_state *st); // [Lupus]
  296. int buildin_getrefine(struct script_state *st); // [celest]
  297. int buildin_getusersname(struct script_state *st); //jA commands added [Lupus]
  298. int buildin_dispbottom(struct script_state *st);
  299. int buildin_recovery(struct script_state *st);
  300. int buildin_getpetinfo(struct script_state *st);
  301. int buildin_checkequipedcard(struct script_state *st);
  302. int buildin_globalmes(struct script_state *st);
  303. int buildin_jump_zero(struct script_state *st);
  304. int buildin_select(struct script_state *st);
  305. int buildin_getmapmobs(struct script_state *st); //jA addition end
  306. void push_val(struct script_stack *stack,int type,int val);
  307. int run_func(struct script_state *st);
  308. int mapreg_setreg(int num,int val);
  309. int mapreg_setregstr(int num,const char *str);
  310. #ifdef PCRE_SUPPORT
  311. int buildin_defpattern(struct script_state *st); // MouseJstr
  312. int buildin_activatepset(struct script_state *st); // MouseJstr
  313. int buildin_deactivatepset(struct script_state *st); // MouseJstr
  314. int buildin_deletepset(struct script_state *st); // MouseJstr
  315. #endif
  316. struct {
  317. int (*func)(struct script_state *);
  318. char *name;
  319. char *arg;
  320. } buildin_func[]={
  321. {buildin_mes,"mes","s"},
  322. {buildin_next,"next",""},
  323. {buildin_close,"close",""},
  324. {buildin_close2,"close2",""},
  325. {buildin_menu,"menu","*"},
  326. {buildin_goto,"goto","l"},
  327. {buildin_callsub,"callsub","i*"},
  328. {buildin_callfunc,"callfunc","s*"},
  329. {buildin_return,"return","*"},
  330. {buildin_getarg,"getarg","i"},
  331. {buildin_jobchange,"jobchange","i*"},
  332. {buildin_input,"input","*"},
  333. {buildin_warp,"warp","sii"},
  334. {buildin_areawarp,"areawarp","siiiisii"},
  335. {buildin_setlook,"setlook","ii"},
  336. {buildin_set,"set","ii"},
  337. {buildin_setarray,"setarray","ii*"},
  338. {buildin_cleararray,"cleararray","iii"},
  339. {buildin_copyarray,"copyarray","iii"},
  340. {buildin_getarraysize,"getarraysize","i"},
  341. {buildin_deletearray,"deletearray","ii"},
  342. {buildin_getelementofarray,"getelementofarray","ii"},
  343. {buildin_if,"if","i*"},
  344. {buildin_getitem,"getitem","ii**"},
  345. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  346. {buildin_makeitem,"makeitem","iisii"},
  347. {buildin_delitem,"delitem","ii"},
  348. {buildin_cutin,"cutin","si"},
  349. {buildin_cutincard,"cutincard","i"},
  350. {buildin_viewpoint,"viewpoint","iiiii"},
  351. {buildin_heal,"heal","ii"},
  352. {buildin_itemheal,"itemheal","ii"},
  353. {buildin_percentheal,"percentheal","ii"},
  354. {buildin_rand,"rand","i*"},
  355. {buildin_countitem,"countitem","i"},
  356. {buildin_checkweight,"checkweight","ii"},
  357. {buildin_readparam,"readparam","i*"},
  358. {buildin_getcharid,"getcharid","i*"},
  359. {buildin_getpartyname,"getpartyname","i"},
  360. {buildin_getpartymember,"getpartymember","i"},
  361. {buildin_getguildname,"getguildname","i"},
  362. {buildin_getguildmaster,"getguildmaster","i"},
  363. {buildin_getguildmasterid,"getguildmasterid","i"},
  364. {buildin_strcharinfo,"strcharinfo","i"},
  365. {buildin_getequipid,"getequipid","i"},
  366. {buildin_getequipname,"getequipname","i"},
  367. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  368. {buildin_repair,"repair","i"}, // [Valaris]
  369. {buildin_getequipisequiped,"getequipisequiped","i"},
  370. {buildin_getequipisenableref,"getequipisenableref","i"},
  371. {buildin_getequipisidentify,"getequipisidentify","i"},
  372. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  373. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  374. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  375. {buildin_successrefitem,"successrefitem","i"},
  376. {buildin_failedrefitem,"failedrefitem","i"},
  377. {buildin_statusup,"statusup","i"},
  378. {buildin_statusup2,"statusup2","ii"},
  379. {buildin_bonus,"bonus","ii"},
  380. {buildin_bonus2,"bonus2","iii"},
  381. {buildin_bonus3,"bonus3","iiii"},
  382. {buildin_bonus4,"bonus4","iiiii"},
  383. {buildin_skill,"skill","ii*"},
  384. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  385. {buildin_guildskill,"guildskill","ii"},
  386. {buildin_getskilllv,"getskilllv","i"},
  387. {buildin_getgdskilllv,"getgdskilllv","ii"},
  388. {buildin_basicskillcheck,"basicskillcheck","*"},
  389. {buildin_getgmlevel,"getgmlevel","*"},
  390. {buildin_end,"end",""},
  391. {buildin_end,"break",""},
  392. {buildin_checkoption,"checkoption","i"},
  393. {buildin_setoption,"setoption","i"},
  394. {buildin_setcart,"setcart",""},
  395. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  396. {buildin_setfalcon,"setfalcon",""},
  397. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  398. {buildin_setriding,"setriding",""},
  399. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  400. {buildin_savepoint,"save","sii"},
  401. {buildin_savepoint,"savepoint","sii"},
  402. {buildin_gettimetick,"gettimetick","i"},
  403. {buildin_gettime,"gettime","i"},
  404. {buildin_gettimestr,"gettimestr","si"},
  405. {buildin_openstorage,"openstorage",""},
  406. {buildin_guildopenstorage,"guildopenstorage","*"},
  407. {buildin_itemskill,"itemskill","iis"},
  408. {buildin_produce,"produce","i"},
  409. {buildin_monster,"monster","siisii*"},
  410. {buildin_areamonster,"areamonster","siiiisii*"},
  411. {buildin_killmonster,"killmonster","ss"},
  412. {buildin_killmonsterall,"killmonsterall","s"},
  413. {buildin_doevent,"doevent","s"},
  414. {buildin_donpcevent,"donpcevent","s"},
  415. {buildin_addtimer,"addtimer","is"},
  416. {buildin_deltimer,"deltimer","s"},
  417. {buildin_addtimercount,"addtimercount","si"},
  418. {buildin_initnpctimer,"initnpctimer","*"},
  419. {buildin_stopnpctimer,"stopnpctimer","*"},
  420. {buildin_startnpctimer,"startnpctimer","*"},
  421. {buildin_setnpctimer,"setnpctimer","*"},
  422. {buildin_getnpctimer,"getnpctimer","i*"},
  423. {buildin_attachnpctimer,"attachnpctimer","*"}, // attached the player id to the npc timer [Celest]
  424. {buildin_detachnpctimer,"detachnpctimer","*"}, // detached the player id from the npc timer [Celest]
  425. {buildin_announce,"announce","si"},
  426. {buildin_mapannounce,"mapannounce","ssi"},
  427. {buildin_areaannounce,"areaannounce","siiiisi"},
  428. {buildin_getusers,"getusers","i"},
  429. {buildin_getmapusers,"getmapusers","s"},
  430. {buildin_getareausers,"getareausers","siiii"},
  431. {buildin_getareadropitem,"getareadropitem","siiiii"},
  432. {buildin_enablenpc,"enablenpc","s"},
  433. {buildin_disablenpc,"disablenpc","s"},
  434. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  435. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  436. {buildin_hideoffnpc,"hideoffnpc","s"},
  437. {buildin_hideonnpc,"hideonnpc","s"},
  438. {buildin_sc_start,"sc_start","iii*"},
  439. {buildin_sc_start2,"sc_start2","iiii*"},
  440. {buildin_sc_end,"sc_end","i"},
  441. {buildin_getscrate,"getscrate","ii*"},
  442. {buildin_debugmes,"debugmes","s"},
  443. {buildin_catchpet,"pet","i"},
  444. {buildin_birthpet,"bpet",""},
  445. {buildin_resetlvl,"resetlvl","i"},
  446. {buildin_resetstatus,"resetstatus",""},
  447. {buildin_resetskill,"resetskill",""},
  448. {buildin_changebase,"changebase","i"},
  449. {buildin_changesex,"changesex",""},
  450. {buildin_waitingroom,"waitingroom","si*"},
  451. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  452. {buildin_delwaitingroom,"delwaitingroom","*"},
  453. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  454. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  455. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  456. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  457. {buildin_attachrid,"attachrid","i"},
  458. {buildin_detachrid,"detachrid",""},
  459. {buildin_isloggedin,"isloggedin","i"},
  460. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  461. {buildin_setmapflag,"setmapflag","si"},
  462. {buildin_removemapflag,"removemapflag","si"},
  463. {buildin_pvpon,"pvpon","s"},
  464. {buildin_pvpoff,"pvpoff","s"},
  465. {buildin_gvgon,"gvgon","s"},
  466. {buildin_gvgoff,"gvgoff","s"},
  467. {buildin_emotion,"emotion","i"},
  468. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  469. {buildin_agitstart,"agitstart",""}, // <Agit>
  470. {buildin_agitend,"agitend",""},
  471. {buildin_agitcheck,"agitcheck","i"}, // <Agitcheck>
  472. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  473. {buildin_getcastlename,"getcastlename","s"},
  474. {buildin_getcastledata,"getcastledata","si*"},
  475. {buildin_setcastledata,"setcastledata","sii"},
  476. {buildin_requestguildinfo,"requestguildinfo","i*"},
  477. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  478. {buildin_successremovecards,"successremovecards","i"},
  479. {buildin_failedremovecards,"failedremovecards","ii"},
  480. {buildin_marriage,"marriage","s"},
  481. {buildin_wedding_effect,"wedding",""},
  482. {buildin_divorce,"divorce","*"},
  483. {buildin_ispartneron,"ispartneron","*"},
  484. {buildin_getpartnerid,"getpartnerid","*"},
  485. {buildin_warppartner,"warppartner","sii"},
  486. {buildin_getitemname,"getitemname","i"},
  487. {buildin_makepet,"makepet","i"},
  488. {buildin_getexp,"getexp","ii"},
  489. {buildin_getinventorylist,"getinventorylist",""},
  490. {buildin_getskilllist,"getskilllist",""},
  491. {buildin_clearitem,"clearitem",""},
  492. {buildin_classchange,"classchange","ii"},
  493. {buildin_misceffect,"misceffect","i"},
  494. {buildin_soundeffect,"soundeffect","si"},
  495. {buildin_soundeffectall,"soundeffectall","si"}, // SoundEffectAll [Codemaster]
  496. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  497. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  498. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  499. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  500. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  501. {buildin_petloot,"petloot","i"}, // [Valaris]
  502. {buildin_petheal,"petheal","iii"}, // [Valaris]
  503. {buildin_petmag,"petmag","iiii"}, // [Valaris]
  504. {buildin_petskillattack,"petskillattack","iiii"}, // [Valaris]
  505. {buildin_skilleffect,"skilleffect","ii"}, // skill effect [Celest]
  506. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  507. {buildin_specialeffect,"specialeffect","i"}, // npc skill effect [Valaris]
  508. {buildin_specialeffect2,"specialeffect2","i"}, // skill effect on players[Valaris]
  509. {buildin_nude,"nude",""}, // nude command [Valaris]
  510. {buildin_mapwarp,"mapwarp","ssii"}, // Added by RoVeRT
  511. {buildin_inittimer,"inittimer",""},
  512. {buildin_stoptimer,"stoptimer",""},
  513. {buildin_cmdothernpc,"cmdothernpc","ss"},
  514. {buildin_gmcommand,"gmcommand","*"}, // [MouseJstr]
  515. // {buildin_movenpc,"movenpc","siis"}, // [MouseJstr]
  516. {buildin_message,"message","s*"}, // [MouseJstr]
  517. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  518. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  519. {buildin_mobcount,"mobcount","ss"},
  520. {buildin_getlook,"getlook","i"},
  521. {buildin_getsavepoint,"getsavepoint","i"},
  522. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  523. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  524. {buildin_npcstop,"npcstop",""}, // [Valaris]
  525. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  526. {buildin_checkoption1,"checkoption1","i"},
  527. {buildin_checkoption2,"checkoption2","i"},
  528. {buildin_guildgetexp,"guildgetexp","i"},
  529. {buildin_skilluseid,"skilluseid","ii"}, // originally by Qamera [Celest]
  530. {buildin_skilluseid,"doskill","ii"}, // since a lot of scripts would already use 'doskill'...
  531. {buildin_skillusepos,"skillusepos","iiii"}, // [Celest]
  532. {buildin_logmes,"logmes","s"}, //this command actls as MES but prints info into LOG file either SQL/TXT [Lupus]
  533. {buildin_summon,"summon","si*"}, // summons a slave monster [Celest]
  534. {buildin_isnight,"isnight",""}, // check whether it is night time [Celest]
  535. {buildin_isday,"isday",""}, // check whether it is day time [Celest]
  536. {buildin_isequipped,"isequipped","i*"}, // check whether another item/card has been equipped [Celest]
  537. {buildin_isequippedcnt,"isequippedcnt","i*"}, // check how many items/cards are being equipped [Celest]
  538. {buildin_cardscnt,"cardscnt","i*"}, // check how many items/cards are being equipped in the same arm [Lupus]
  539. {buildin_getrefine,"getrefine",""}, // returns the refined number of the current item, or an item with index specified [celest]
  540. #ifdef PCRE_SUPPORT
  541. {buildin_defpattern, "defpattern", "iss"}, // Define pattern to listen for [MouseJstr]
  542. {buildin_activatepset, "activatepset", "i"}, // Activate a pattern set [MouseJstr]
  543. {buildin_deactivatepset, "deactivatepset", "i"}, // Deactive a pattern set [MouseJstr]
  544. {buildin_deletepset, "deletepset", "i"}, // Delete a pattern set [MouseJstr]
  545. #endif
  546. {buildin_dispbottom,"dispbottom","s"}, //added from jA [Lupus]
  547. {buildin_getusersname,"getusersname","*"},
  548. {buildin_recovery,"recovery",""},
  549. {buildin_getpetinfo,"getpetinfo","i"},
  550. {buildin_checkequipedcard,"checkequipedcard","i"},
  551. {buildin_jump_zero,"jump_zero","ii"}, //for future jA script compatibility
  552. {buildin_select,"select","*"}, //for future jA script compatibility
  553. {buildin_globalmes,"globalmes","s*"},
  554. {buildin_getmapmobs,"getmapmobs","s"}, //end jA addition
  555. {NULL,NULL,NULL},
  556. };
  557. enum {
  558. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  559. C_NAME,C_EOL, C_RETINFO,
  560. C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  561. 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
  562. };
  563. /*==========================================
  564. * 文字列のハッシュを計算
  565. *------------------------------------------
  566. */
  567. static int calc_hash(const unsigned char *p)
  568. {
  569. int h=0;
  570. while(*p){
  571. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  572. h+=*p++;
  573. }
  574. return h&15;
  575. }
  576. /*==========================================
  577. * str_dataの中に名前があるか検索する
  578. *------------------------------------------
  579. */
  580. // 既存のであれば番号、無ければ-1
  581. static int search_str(const unsigned char *p)
  582. {
  583. int i;
  584. i=str_hash[calc_hash(p)];
  585. while(i){
  586. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  587. return i;
  588. }
  589. i=str_data[i].next;
  590. }
  591. return -1;
  592. }
  593. /*==========================================
  594. * str_dataに名前を登録
  595. *------------------------------------------
  596. */
  597. // 既存のであれば番号、無ければ登録して新規番号
  598. static int add_str(const unsigned char *p)
  599. {
  600. int i;
  601. char *lowcase;
  602. lowcase=aStrdup((char *) p);
  603. for(i=0;lowcase[i];i++)
  604. lowcase[i]=tolower(lowcase[i]);
  605. if((i=search_str((unsigned char *) lowcase))>=0){
  606. aFree(lowcase);
  607. return i;
  608. }
  609. aFree(lowcase);
  610. i=calc_hash(p);
  611. if(str_hash[i]==0){
  612. str_hash[i]=str_num;
  613. } else {
  614. i=str_hash[i];
  615. for(;;){
  616. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  617. return i;
  618. }
  619. if(str_data[i].next==0)
  620. break;
  621. i=str_data[i].next;
  622. }
  623. str_data[i].next=str_num;
  624. }
  625. if(str_num>=str_data_size){
  626. str_data_size+=128;
  627. str_data=(struct str_data_struct *) aRealloc(str_data,sizeof(str_data[0])*str_data_size);
  628. memset(str_data + (str_data_size - 128), '\0', 128);
  629. }
  630. while(str_pos+(int)strlen((char *) p)+1>=str_size){
  631. str_size+=256;
  632. str_buf=(char *)aRealloc(str_buf,str_size);
  633. memset(str_buf + (str_size - 256), '\0', 256);
  634. }
  635. strcpy(str_buf+str_pos, (char *) p);
  636. str_data[str_num].type=C_NOP;
  637. str_data[str_num].str=str_pos;
  638. str_data[str_num].next=0;
  639. str_data[str_num].func=NULL;
  640. str_data[str_num].backpatch=-1;
  641. str_data[str_num].label=-1;
  642. str_pos+=strlen( (char *) p)+1;
  643. return str_num++;
  644. }
  645. /*==========================================
  646. * スクリプトバッファサイズの確認と拡張
  647. *------------------------------------------
  648. */
  649. static void check_script_buf(int size)
  650. {
  651. if(script_pos+size>=script_size){
  652. script_size+=SCRIPT_BLOCK_SIZE;
  653. script_buf=(unsigned char *)aRealloc(script_buf,script_size);
  654. memset(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  655. SCRIPT_BLOCK_SIZE);
  656. }
  657. }
  658. /*==========================================
  659. * スクリプトバッファに1バイト書き込む
  660. *------------------------------------------
  661. */
  662. static void add_scriptb(int a)
  663. {
  664. check_script_buf(1);
  665. script_buf[script_pos++]=a;
  666. }
  667. /*==========================================
  668. * スクリプトバッファにデータタイプを書き込む
  669. *------------------------------------------
  670. */
  671. static void add_scriptc(int a)
  672. {
  673. while(a>=0x40){
  674. add_scriptb((a&0x3f)|0x40);
  675. a=(a-0x40)>>6;
  676. }
  677. add_scriptb(a&0x3f);
  678. }
  679. /*==========================================
  680. * スクリプトバッファに整数を書き込む
  681. *------------------------------------------
  682. */
  683. static void add_scripti(int a)
  684. {
  685. while(a>=0x40){
  686. add_scriptb(a|0xc0);
  687. a=(a-0x40)>>6;
  688. }
  689. add_scriptb(a|0x80);
  690. }
  691. /*==========================================
  692. * スクリプトバッファにラベル/変数/関数を書き込む
  693. *------------------------------------------
  694. */
  695. // 最大16Mまで
  696. static void add_scriptl(int l)
  697. {
  698. int backpatch = str_data[l].backpatch;
  699. switch(str_data[l].type){
  700. case C_POS:
  701. add_scriptc(C_POS);
  702. add_scriptb(str_data[l].label);
  703. add_scriptb(str_data[l].label>>8);
  704. add_scriptb(str_data[l].label>>16);
  705. break;
  706. case C_NOP:
  707. // ラベルの可能性があるのでbackpatch用データ埋め込み
  708. add_scriptc(C_NAME);
  709. str_data[l].backpatch=script_pos;
  710. add_scriptb(backpatch);
  711. add_scriptb(backpatch>>8);
  712. add_scriptb(backpatch>>16);
  713. break;
  714. case C_INT:
  715. add_scripti(str_data[l].val);
  716. break;
  717. default:
  718. // もう他の用途と確定してるので数字をそのまま
  719. add_scriptc(C_NAME);
  720. add_scriptb(l);
  721. add_scriptb(l>>8);
  722. add_scriptb(l>>16);
  723. break;
  724. }
  725. }
  726. /*==========================================
  727. * ラベルを解決する
  728. *------------------------------------------
  729. */
  730. void set_label(int l,int pos)
  731. {
  732. int i,next;
  733. str_data[l].type=C_POS;
  734. str_data[l].label=pos;
  735. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  736. next=(*(int*)(script_buf+i)) & 0x00ffffff;
  737. script_buf[i-1]=C_POS;
  738. script_buf[i]=pos;
  739. script_buf[i+1]=pos>>8;
  740. script_buf[i+2]=pos>>16;
  741. i=next;
  742. }
  743. }
  744. /*==========================================
  745. * スペース/コメント読み飛ばし
  746. *------------------------------------------
  747. */
  748. static unsigned char *skip_space(unsigned char *p)
  749. {
  750. while(1){
  751. while(isspace(*p))
  752. p++;
  753. if(p[0]=='/' && p[1]=='/'){
  754. while(*p && *p!='\n')
  755. p++;
  756. } else if(p[0]=='/' && p[1]=='*'){
  757. p++;
  758. while(*p && (p[-1]!='*' || p[0]!='/'))
  759. p++;
  760. if(*p) p++;
  761. } else
  762. break;
  763. }
  764. return p;
  765. }
  766. /*==========================================
  767. * 1単語スキップ
  768. *------------------------------------------
  769. */
  770. static unsigned char *skip_word(unsigned char *p)
  771. {
  772. // prefix
  773. if(*p=='$') p++; // MAP鯖内共有変数用
  774. if(*p=='@') p++; // 一時的変数用(like weiss)
  775. if(*p=='#') p++; // account変数用
  776. if(*p=='#') p++; // ワールドaccount変数用
  777. if(*p=='l') p++; // 一時的変数用(like weiss)
  778. while(isalnum(*p)||*p=='_'|| *p>=0x81)
  779. if(*p>=0x81 && p[1]){
  780. p+=2;
  781. } else
  782. p++;
  783. // postfix
  784. if(*p=='$') p++; // 文字列変数
  785. return p;
  786. }
  787. static unsigned char *startptr;
  788. static int startline;
  789. /*==========================================
  790. * エラーメッセージ出力
  791. *------------------------------------------
  792. */
  793. static void disp_error_message(const char *mes,const unsigned char *pos)
  794. {
  795. int line,c=0,i;
  796. unsigned char *p,*linestart,*lineend;
  797. for(line=startline,p=startptr;p && *p;line++){
  798. linestart=p;
  799. lineend=(unsigned char *) strchr((char *) p,'\n');
  800. if(lineend){
  801. c=*lineend;
  802. *lineend=0;
  803. }
  804. if(lineend==NULL || pos<lineend){
  805. if (current_file) {
  806. printf("%s in "CL_WHITE"\'%s\'"CL_RESET" line "CL_WHITE"\'%d\'"CL_RESET" : ", mes, current_file, line);
  807. } else {
  808. printf("%s line "CL_WHITE"\'%d\'"CL_RESET" : ", mes, line);
  809. }
  810. for(i=0;(linestart[i]!='\r') && (linestart[i]!='\n') && linestart[i];i++){
  811. if(linestart+i!=pos)
  812. printf("%c",linestart[i]);
  813. else
  814. printf("\'%c\'",linestart[i]);
  815. }
  816. printf("\a\n");
  817. if(lineend)
  818. *lineend=c;
  819. return;
  820. }
  821. *lineend=c;
  822. p=lineend+1;
  823. }
  824. }
  825. /*==========================================
  826. * 項の解析
  827. *------------------------------------------
  828. */
  829. unsigned char* parse_simpleexpr(unsigned char *p)
  830. {
  831. int i;
  832. p=skip_space(p);
  833. #ifdef DEBUG_FUNCIN
  834. if(battle_config.etc_log)
  835. printf("parse_simpleexpr %s\n",p);
  836. #endif
  837. if(*p==';' || *p==','){
  838. disp_error_message("unexpected expr end",p);
  839. exit(1);
  840. }
  841. if(*p=='('){
  842. p=parse_subexpr(p+1,-1);
  843. p=skip_space(p);
  844. if((*p++)!=')'){
  845. disp_error_message("unmatch ')'",p);
  846. exit(1);
  847. }
  848. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  849. char *np;
  850. i=strtoul((char *) p,&np,0);
  851. add_scripti(i);
  852. p=(unsigned char *) np;
  853. } else if(*p=='"'){
  854. add_scriptc(C_STR);
  855. p++;
  856. while(*p && *p!='"'){
  857. if(p[-1]<=0x7e && *p=='\\')
  858. p++;
  859. else if(*p=='\n'){
  860. disp_error_message("unexpected newline @ string",p);
  861. exit(1);
  862. }
  863. add_scriptb(*p++);
  864. }
  865. if(!*p){
  866. disp_error_message("unexpected eof @ string",p);
  867. exit(1);
  868. }
  869. add_scriptb(0);
  870. p++; //'"'
  871. } else {
  872. int c,l;
  873. char *p2;
  874. // label , register , function etc
  875. if(skip_word(p)==p){
  876. disp_error_message("unexpected character",p);
  877. exit(1);
  878. }
  879. p2=(char *) skip_word(p);
  880. c=*p2; *p2=0; // 名前をadd_strする
  881. l=add_str(p);
  882. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  883. if(l== search_str((unsigned char *) "if")) // warn_cmd_no_commaのために必要
  884. parse_cmd_if++;
  885. /*
  886. // 廃止予定のl14/l15,およびプレフィックスlの警告
  887. if( strcmp(str_buf+str_data[l].str,"l14")==0 ||
  888. strcmp(str_buf+str_data[l].str,"l15")==0 ){
  889. disp_error_message("l14 and l15 is DEPRECATED. use @menu instead of l15.",p);
  890. }else if(str_buf[str_data[l].str]=='l'){
  891. disp_error_message("prefix 'l' is DEPRECATED. use prefix '@' instead.",p2);
  892. }
  893. */
  894. *p2=c;
  895. p=(unsigned char *) p2;
  896. if(str_data[l].type!=C_FUNC && c=='['){
  897. // array(name[i] => getelementofarray(name,i) )
  898. add_scriptl(search_str((unsigned char *) "getelementofarray"));
  899. add_scriptc(C_ARG);
  900. add_scriptl(l);
  901. p=parse_subexpr(p+1,-1);
  902. p=skip_space(p);
  903. if((*p++)!=']'){
  904. disp_error_message("unmatch ']'",p);
  905. exit(1);
  906. }
  907. add_scriptc(C_FUNC);
  908. }else
  909. add_scriptl(l);
  910. }
  911. #ifdef DEBUG_FUNCIN
  912. if(battle_config.etc_log)
  913. printf("parse_simpleexpr end %s\n",p);
  914. #endif
  915. return p;
  916. }
  917. /*==========================================
  918. * 式の解析
  919. *------------------------------------------
  920. */
  921. unsigned char* parse_subexpr(unsigned char *p,int limit)
  922. {
  923. int op,opl,len;
  924. char *tmpp;
  925. #ifdef DEBUG_FUNCIN
  926. if(battle_config.etc_log)
  927. printf("parse_subexpr %s\n",p);
  928. #endif
  929. p=skip_space(p);
  930. if(*p=='-'){
  931. tmpp=(char *) skip_space((unsigned char *) (p+1));
  932. if(*tmpp==';' || *tmpp==','){
  933. add_scriptl(LABEL_NEXTLINE);
  934. p++;
  935. return p;
  936. }
  937. }
  938. tmpp=(char *) p;
  939. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  940. p=parse_subexpr(p+1,100);
  941. add_scriptc(op);
  942. } else
  943. p=parse_simpleexpr(p);
  944. p=skip_space(p);
  945. while(((op=C_ADD,opl=6,len=1,*p=='+') ||
  946. (op=C_SUB,opl=6,len=1,*p=='-') ||
  947. (op=C_MUL,opl=7,len=1,*p=='*') ||
  948. (op=C_DIV,opl=7,len=1,*p=='/') ||
  949. (op=C_MOD,opl=7,len=1,*p=='%') ||
  950. (op=C_FUNC,opl=8,len=1,*p=='(') ||
  951. (op=C_LAND,opl=1,len=2,*p=='&' && p[1]=='&') ||
  952. (op=C_AND,opl=5,len=1,*p=='&') ||
  953. (op=C_LOR,opl=0,len=2,*p=='|' && p[1]=='|') ||
  954. (op=C_OR,opl=4,len=1,*p=='|') ||
  955. (op=C_XOR,opl=3,len=1,*p=='^') ||
  956. (op=C_EQ,opl=2,len=2,*p=='=' && p[1]=='=') ||
  957. (op=C_NE,opl=2,len=2,*p=='!' && p[1]=='=') ||
  958. (op=C_R_SHIFT,opl=5,len=2,*p=='>' && p[1]=='>') ||
  959. (op=C_GE,opl=2,len=2,*p=='>' && p[1]=='=') ||
  960. (op=C_GT,opl=2,len=1,*p=='>') ||
  961. (op=C_L_SHIFT,opl=5,len=2,*p=='<' && p[1]=='<') ||
  962. (op=C_LE,opl=2,len=2,*p=='<' && p[1]=='=') ||
  963. (op=C_LT,opl=2,len=1,*p=='<')) && opl>limit){
  964. p+=len;
  965. if(op==C_FUNC){
  966. int i=0,func=parse_cmd;
  967. const char *plist[128];
  968. if( str_data[func].type!=C_FUNC ){
  969. disp_error_message("expect function",(unsigned char *) tmpp);
  970. exit(0);
  971. }
  972. add_scriptc(C_ARG);
  973. do {
  974. plist[i]=(char *) p;
  975. p=parse_subexpr(p,-1);
  976. p=skip_space(p);
  977. if(*p==',') p++;
  978. else if(*p!=')' && script_config.warn_func_no_comma){
  979. disp_error_message("expect ',' or ')' at func params",p);
  980. }
  981. p=skip_space(p);
  982. i++;
  983. } while(*p && *p!=')' && i<128);
  984. plist[i]=(char *) p;
  985. if(*(p++)!=')'){
  986. disp_error_message("func request '(' ')'",p);
  987. exit(1);
  988. }
  989. if( str_data[func].type==C_FUNC && script_config.warn_func_mismatch_paramnum){
  990. const char *arg=buildin_func[str_data[func].val].arg;
  991. int j=0;
  992. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  993. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  994. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  995. }
  996. }
  997. } else {
  998. p=parse_subexpr(p,opl);
  999. }
  1000. add_scriptc(op);
  1001. p=skip_space(p);
  1002. }
  1003. #ifdef DEBUG_FUNCIN
  1004. if(battle_config.etc_log)
  1005. printf("parse_subexpr end %s\n",p);
  1006. #endif
  1007. return p; /* return first untreated operator */
  1008. }
  1009. /*==========================================
  1010. * 式の評価
  1011. *------------------------------------------
  1012. */
  1013. unsigned char* parse_expr(unsigned char *p)
  1014. {
  1015. #ifdef DEBUG_FUNCIN
  1016. if(battle_config.etc_log)
  1017. printf("parse_expr %s\n",p);
  1018. #endif
  1019. switch(*p){
  1020. case ')': case ';': case ':': case '[': case ']':
  1021. case '}':
  1022. disp_error_message("unexpected char",p);
  1023. exit(1);
  1024. }
  1025. p=parse_subexpr(p,-1);
  1026. #ifdef DEBUG_FUNCIN
  1027. if(battle_config.etc_log)
  1028. printf("parse_expr end %s\n",p);
  1029. #endif
  1030. return p;
  1031. }
  1032. /*==========================================
  1033. * 行の解析
  1034. *------------------------------------------
  1035. */
  1036. unsigned char* parse_line(unsigned char *p)
  1037. {
  1038. int i=0,cmd;
  1039. const char *plist[128];
  1040. char *p2;
  1041. p=skip_space(p);
  1042. if(*p==';')
  1043. return p;
  1044. parse_cmd_if=0; // warn_cmd_no_commaのために必要
  1045. // 最初は関数名
  1046. p2=(char *) p;
  1047. p=parse_simpleexpr(p);
  1048. p=skip_space(p);
  1049. cmd=parse_cmd;
  1050. if( str_data[cmd].type!=C_FUNC ){
  1051. disp_error_message("expect command",(unsigned char *) p2);
  1052. // exit(0);
  1053. }
  1054. add_scriptc(C_ARG);
  1055. while(p && *p && *p!=';' && i<128){
  1056. plist[i]=(char *) p;
  1057. p=parse_expr(p);
  1058. p=skip_space(p);
  1059. // 引数区切りの,処理
  1060. if(*p==',') p++;
  1061. else if(*p!=';' && script_config.warn_cmd_no_comma && parse_cmd_if*2<=i ){
  1062. disp_error_message("expect ',' or ';' at cmd params",p);
  1063. }
  1064. p=skip_space(p);
  1065. i++;
  1066. }
  1067. plist[i]=(char *) p;
  1068. if(!p || *(p++)!=';'){
  1069. disp_error_message("need ';'",p);
  1070. exit(1);
  1071. }
  1072. add_scriptc(C_FUNC);
  1073. if( str_data[cmd].type==C_FUNC && script_config.warn_cmd_mismatch_paramnum){
  1074. const char *arg=buildin_func[str_data[cmd].val].arg;
  1075. int j=0;
  1076. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  1077. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  1078. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  1079. }
  1080. }
  1081. return p;
  1082. }
  1083. /*==========================================
  1084. * 組み込み関数の追加
  1085. *------------------------------------------
  1086. */
  1087. static void add_buildin_func(void)
  1088. {
  1089. int i,n;
  1090. for(i=0;buildin_func[i].func;i++){
  1091. n=add_str((unsigned char *) buildin_func[i].name);
  1092. str_data[n].type=C_FUNC;
  1093. str_data[n].val=i;
  1094. str_data[n].func=buildin_func[i].func;
  1095. }
  1096. }
  1097. /*==========================================
  1098. * 定数データベースの読み込み
  1099. *------------------------------------------
  1100. */
  1101. static void read_constdb(void)
  1102. {
  1103. FILE *fp;
  1104. char line[1024],name[1024];
  1105. int val,n,i,type;
  1106. fp=fopen("db/const.txt","r");
  1107. if(fp==NULL){
  1108. printf("can't read db/const.txt\n");
  1109. return ;
  1110. }
  1111. while(fgets(line,1020,fp)){
  1112. if(line[0]=='/' && line[1]=='/')
  1113. continue;
  1114. type=0;
  1115. if(sscanf(line,"%[A-Za-z0-9_],%d,%d",name,&val,&type)>=2 ||
  1116. sscanf(line,"%[A-Za-z0-9_] %d %d",name,&val,&type)>=2){
  1117. for(i=0;name[i];i++)
  1118. name[i]=tolower(name[i]);
  1119. n=add_str((const unsigned char *) name);
  1120. if(type==0)
  1121. str_data[n].type=C_INT;
  1122. else
  1123. str_data[n].type=C_PARAM;
  1124. str_data[n].val=val;
  1125. }
  1126. }
  1127. fclose(fp);
  1128. }
  1129. /*==========================================
  1130. * スクリプトの解析
  1131. *------------------------------------------
  1132. */
  1133. char* parse_script(unsigned char *src,int line)
  1134. {
  1135. unsigned char *p,*tmpp;
  1136. int i;
  1137. static int first=1;
  1138. if(first){
  1139. add_buildin_func();
  1140. read_constdb();
  1141. }
  1142. first=0;
  1143. script_buf=(unsigned char *)aCallocA(SCRIPT_BLOCK_SIZE,sizeof(unsigned char));
  1144. script_pos=0;
  1145. script_size=SCRIPT_BLOCK_SIZE;
  1146. str_data[LABEL_NEXTLINE].type=C_NOP;
  1147. str_data[LABEL_NEXTLINE].backpatch=-1;
  1148. str_data[LABEL_NEXTLINE].label=-1;
  1149. for(i=LABEL_START;i<str_num;i++){
  1150. if(str_data[i].type==C_POS || str_data[i].type==C_NAME){
  1151. str_data[i].type=C_NOP;
  1152. str_data[i].backpatch=-1;
  1153. str_data[i].label=-1;
  1154. }
  1155. }
  1156. // 外部用label dbの初期化
  1157. if(scriptlabel_db!=NULL)
  1158. strdb_final(scriptlabel_db,scriptlabel_final);
  1159. scriptlabel_db=strdb_init(50);
  1160. // for error message
  1161. startptr = src;
  1162. startline = line;
  1163. p=src;
  1164. p=skip_space(p);
  1165. if(*p!='{'){
  1166. disp_error_message("not found '{'",p);
  1167. return NULL;
  1168. }
  1169. for(p++;p && *p && *p!='}';){
  1170. p=skip_space(p);
  1171. // labelだけ特殊処理
  1172. tmpp=skip_space(skip_word(p));
  1173. if(*tmpp==':'){
  1174. int l,c;
  1175. c=*skip_word(p);
  1176. *skip_word(p)=0;
  1177. l=add_str(p);
  1178. if(str_data[l].label!=-1){
  1179. *skip_word(p)=c;
  1180. disp_error_message("dup label ",p);
  1181. exit(1);
  1182. }
  1183. set_label(l,script_pos);
  1184. strdb_insert(scriptlabel_db,p,script_pos); // 外部用label db登録
  1185. *skip_word(p)=c;
  1186. p=tmpp+1;
  1187. continue;
  1188. }
  1189. // 他は全部一緒くた
  1190. p=parse_line(p);
  1191. p=skip_space(p);
  1192. add_scriptc(C_EOL);
  1193. set_label(LABEL_NEXTLINE,script_pos);
  1194. str_data[LABEL_NEXTLINE].type=C_NOP;
  1195. str_data[LABEL_NEXTLINE].backpatch=-1;
  1196. str_data[LABEL_NEXTLINE].label=-1;
  1197. }
  1198. add_scriptc(C_NOP);
  1199. script_size = script_pos;
  1200. script_buf=(unsigned char *)aRealloc(script_buf,script_pos + 1);
  1201. // 未解決のラベルを解決
  1202. for(i=LABEL_START;i<str_num;i++){
  1203. if(str_data[i].type==C_NOP){
  1204. int j,next;
  1205. str_data[i].type=C_NAME;
  1206. str_data[i].label=i;
  1207. for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
  1208. next=(*(int*)(script_buf+j)) & 0x00ffffff;
  1209. script_buf[j]=i;
  1210. script_buf[j+1]=i>>8;
  1211. script_buf[j+2]=i>>16;
  1212. j=next;
  1213. }
  1214. }
  1215. }
  1216. #ifdef DEBUG_DISP
  1217. for(i=0;i<script_pos;i++){
  1218. if((i&15)==0) printf("%04x : ",i);
  1219. printf("%02x ",script_buf[i]);
  1220. if((i&15)==15) printf("\n");
  1221. }
  1222. printf("\n");
  1223. #endif
  1224. return (char *) script_buf;
  1225. }
  1226. //
  1227. // 実行系
  1228. //
  1229. enum {STOP=1,END,RERUNLINE,GOTO,RETFUNC};
  1230. /*==========================================
  1231. * ridからsdへの解決
  1232. *------------------------------------------
  1233. */
  1234. struct map_session_data *script_rid2sd(struct script_state *st)
  1235. {
  1236. struct map_session_data *sd=map_id2sd(st->rid);
  1237. if(!sd){
  1238. printf("script_rid2sd: fatal error ! player not attached!\n");
  1239. }
  1240. return sd;
  1241. }
  1242. /*==========================================
  1243. * 変数の読み取り
  1244. *------------------------------------------
  1245. */
  1246. int get_val(struct script_state*st,struct script_data* data)
  1247. {
  1248. struct map_session_data *sd=NULL;
  1249. if(data->type==C_NAME){
  1250. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  1251. char prefix=*name;
  1252. char postfix=name[strlen(name)-1];
  1253. if(prefix!='$'){
  1254. if((sd=script_rid2sd(st))==NULL)
  1255. printf("get_val error name?:%s\n",name);
  1256. }
  1257. if(postfix=='$'){
  1258. data->type=C_CONSTSTR;
  1259. if( prefix=='@' || prefix=='l' ){
  1260. if(sd)
  1261. data->u.str = pc_readregstr(sd,data->u.num);
  1262. }else if(prefix=='$'){
  1263. data->u.str = (char *)numdb_search(mapregstr_db,data->u.num);
  1264. }else{
  1265. printf("script: get_val: illegal scope string variable.\n");
  1266. data->u.str = "!!ERROR!!";
  1267. }
  1268. if( data->u.str == NULL )
  1269. data->u.str ="";
  1270. }else{
  1271. data->type=C_INT;
  1272. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  1273. data->u.num = str_data[data->u.num&0x00ffffff].val;
  1274. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  1275. if(sd)
  1276. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  1277. }else if(prefix=='@' || prefix=='l'){
  1278. if(sd)
  1279. data->u.num = pc_readreg(sd,data->u.num);
  1280. }else if(prefix=='$'){
  1281. data->u.num = (int)numdb_search(mapreg_db,data->u.num);
  1282. }else if(prefix=='#'){
  1283. if( name[1]=='#'){
  1284. if(sd)
  1285. data->u.num = pc_readaccountreg2(sd,name);
  1286. }else{
  1287. if(sd)
  1288. data->u.num = pc_readaccountreg(sd,name);
  1289. }
  1290. }else{
  1291. if(sd)
  1292. data->u.num = pc_readglobalreg(sd,name);
  1293. }
  1294. }
  1295. }
  1296. return 0;
  1297. }
  1298. /*==========================================
  1299. * 変数の読み取り2
  1300. *------------------------------------------
  1301. */
  1302. void* get_val2(struct script_state*st,int num)
  1303. {
  1304. struct script_data dat;
  1305. dat.type=C_NAME;
  1306. dat.u.num=num;
  1307. get_val(st,&dat);
  1308. if( dat.type==C_INT ) return (void*)dat.u.num;
  1309. else return (void*)dat.u.str;
  1310. }
  1311. /*==========================================
  1312. * 変数設定用
  1313. *------------------------------------------
  1314. */
  1315. static int set_reg(struct map_session_data *sd,int num,char *name,void *v)
  1316. {
  1317. char prefix=*name;
  1318. char postfix=name[strlen(name)-1];
  1319. if( postfix=='$' ){
  1320. char *str=(char*)v;
  1321. if( prefix=='@' || prefix=='l'){
  1322. pc_setregstr(sd,num,str);
  1323. }else if(prefix=='$') {
  1324. mapreg_setregstr(num,str);
  1325. }else{
  1326. printf("script: set_reg: illegal scope string variable !");
  1327. }
  1328. }else{
  1329. // 数値
  1330. int val = (int)v;
  1331. if(str_data[num&0x00ffffff].type==C_PARAM){
  1332. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  1333. }else if(prefix=='@' || prefix=='l') {
  1334. pc_setreg(sd,num,val);
  1335. }else if(prefix=='$') {
  1336. mapreg_setreg(num,val);
  1337. }else if(prefix=='#') {
  1338. if( name[1]=='#' )
  1339. pc_setaccountreg2(sd,name,val);
  1340. else
  1341. pc_setaccountreg(sd,name,val);
  1342. }else{
  1343. pc_setglobalreg(sd,name,val);
  1344. }
  1345. }
  1346. return 0;
  1347. }
  1348. int set_var(struct map_session_data *sd, char *name, void *val)
  1349. {
  1350. return set_reg(sd, add_str((unsigned char *) name), name, val);
  1351. }
  1352. /*==========================================
  1353. * 文字列への変換
  1354. *------------------------------------------
  1355. */
  1356. char* conv_str(struct script_state *st,struct script_data *data)
  1357. {
  1358. get_val(st,data);
  1359. if(data->type==C_INT){
  1360. char *buf;
  1361. buf=(char *)aCallocA(16,sizeof(char));
  1362. sprintf(buf,"%d",data->u.num);
  1363. data->type=C_STR;
  1364. data->u.str=buf;
  1365. #if 1
  1366. } else if(data->type==C_NAME){
  1367. // テンポラリ。本来無いはず
  1368. data->type=C_CONSTSTR;
  1369. data->u.str=str_buf+str_data[data->u.num].str;
  1370. #endif
  1371. }
  1372. return data->u.str;
  1373. }
  1374. /*==========================================
  1375. * 数値へ変換
  1376. *------------------------------------------
  1377. */
  1378. int conv_num(struct script_state *st,struct script_data *data)
  1379. {
  1380. char *p;
  1381. get_val(st,data);
  1382. if(data->type==C_STR || data->type==C_CONSTSTR){
  1383. p=data->u.str;
  1384. data->u.num = atoi(p);
  1385. if(data->type==C_STR)
  1386. aFree(p);
  1387. data->type=C_INT;
  1388. }
  1389. return data->u.num;
  1390. }
  1391. /*==========================================
  1392. * スタックへ数値をプッシュ
  1393. *------------------------------------------
  1394. */
  1395. void push_val(struct script_stack *stack,int type,int val)
  1396. {
  1397. if(stack->sp >= stack->sp_max){
  1398. stack->sp_max += 64;
  1399. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1400. sizeof(stack->stack_data[0]) * stack->sp_max);
  1401. memset(stack->stack_data + (stack->sp_max - 64), 0,
  1402. 64 * sizeof(*(stack->stack_data)));
  1403. }
  1404. // if(battle_config.etc_log)
  1405. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  1406. stack->stack_data[stack->sp].type=type;
  1407. stack->stack_data[stack->sp].u.num=val;
  1408. stack->sp++;
  1409. }
  1410. /*==========================================
  1411. * スタックへ文字列をプッシュ
  1412. *------------------------------------------
  1413. */
  1414. void push_str(struct script_stack *stack,int type,unsigned char *str)
  1415. {
  1416. if(stack->sp>=stack->sp_max){
  1417. stack->sp_max += 64;
  1418. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1419. sizeof(stack->stack_data[0]) * stack->sp_max);
  1420. memset(stack->stack_data + (stack->sp_max - 64), '\0',
  1421. 64 * sizeof(*(stack->stack_data)));
  1422. }
  1423. // if(battle_config.etc_log)
  1424. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  1425. stack->stack_data[stack->sp].type=type;
  1426. stack->stack_data[stack->sp].u.str=(char *) str;
  1427. stack->sp++;
  1428. }
  1429. /*==========================================
  1430. * スタックへ複製をプッシュ
  1431. *------------------------------------------
  1432. */
  1433. void push_copy(struct script_stack *stack,int pos)
  1434. {
  1435. switch(stack->stack_data[pos].type){
  1436. case C_CONSTSTR:
  1437. push_str(stack,C_CONSTSTR,(unsigned char *) stack->stack_data[pos].u.str);
  1438. break;
  1439. case C_STR:
  1440. push_str(stack,C_STR,(unsigned char *) aStrdup(stack->stack_data[pos].u.str));
  1441. break;
  1442. default:
  1443. push_val(stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num);
  1444. break;
  1445. }
  1446. }
  1447. /*==========================================
  1448. * スタックからポップ
  1449. *------------------------------------------
  1450. */
  1451. void pop_stack(struct script_stack* stack,int start,int end)
  1452. {
  1453. int i;
  1454. for(i=start;i<end;i++){
  1455. if(stack->stack_data[i].type==C_STR){
  1456. aFree(stack->stack_data[i].u.str);
  1457. }
  1458. }
  1459. if(stack->sp>end){
  1460. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  1461. }
  1462. stack->sp-=end-start;
  1463. }
  1464. //
  1465. // 埋め込み関数
  1466. //
  1467. /*==========================================
  1468. *
  1469. *------------------------------------------
  1470. */
  1471. int buildin_mes(struct script_state *st)
  1472. {
  1473. conv_str(st,& (st->stack->stack_data[st->start+2]));
  1474. clif_scriptmes(script_rid2sd(st),st->oid,st->stack->stack_data[st->start+2].u.str);
  1475. return 0;
  1476. }
  1477. /*==========================================
  1478. *
  1479. *------------------------------------------
  1480. */
  1481. int buildin_goto(struct script_state *st)
  1482. {
  1483. int pos;
  1484. if( st->stack->stack_data[st->start+2].type!=C_POS ){
  1485. printf("script: goto: not label!\n");
  1486. st->state=END;
  1487. return 0;
  1488. }
  1489. pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1490. st->pos=pos;
  1491. st->state=GOTO;
  1492. return 0;
  1493. }
  1494. /*==========================================
  1495. * ユーザー定義関数の呼び出し
  1496. *------------------------------------------
  1497. */
  1498. int buildin_callfunc(struct script_state *st)
  1499. {
  1500. char *scr;
  1501. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  1502. if( (scr=(char *) strdb_search(script_get_userfunc_db(),str)) ){
  1503. int i,j;
  1504. for(i=st->start+3,j=0;i<st->end;i++,j++)
  1505. push_copy(st->stack,i);
  1506. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  1507. push_val(st->stack,C_INT,st->defsp); // 現在の基準スタックポインタをプッシュ
  1508. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  1509. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  1510. st->pos=0;
  1511. st->script=scr;
  1512. st->defsp=st->start+4+j;
  1513. st->state=GOTO;
  1514. }else{
  1515. printf("script:callfunc: function not found! [%s]\n",str);
  1516. st->state=END;
  1517. }
  1518. return 0;
  1519. }
  1520. /*==========================================
  1521. * サブルーティンの呼び出し
  1522. *------------------------------------------
  1523. */
  1524. int buildin_callsub(struct script_state *st)
  1525. {
  1526. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1527. int i,j;
  1528. for(i=st->start+3,j=0;i<st->end;i++,j++)
  1529. push_copy(st->stack,i);
  1530. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  1531. push_val(st->stack,C_INT,st->defsp); // 現在の基準スタックポインタをプッシュ
  1532. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  1533. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  1534. st->pos=pos;
  1535. st->defsp=st->start+4+j;
  1536. st->state=GOTO;
  1537. return 0;
  1538. }
  1539. /*==========================================
  1540. * 引数の所得
  1541. *------------------------------------------
  1542. */
  1543. int buildin_getarg(struct script_state *st)
  1544. {
  1545. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1546. int max,stsp;
  1547. if( st->defsp<4 || st->stack->stack_data[st->defsp-1].type!=C_RETINFO ){
  1548. printf("script:getarg without callfunc or callsub!\n");
  1549. st->state=END;
  1550. return 0;
  1551. }
  1552. max=conv_num(st,& (st->stack->stack_data[st->defsp-4]));
  1553. stsp=st->defsp - max -4;
  1554. if( num >= max ){
  1555. printf("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  1556. st->state=END;
  1557. return 0;
  1558. }
  1559. push_copy(st->stack,stsp+num);
  1560. return 0;
  1561. }
  1562. /*==========================================
  1563. * サブルーチン/ユーザー定義関数の終了
  1564. *------------------------------------------
  1565. */
  1566. int buildin_return(struct script_state *st)
  1567. {
  1568. if(st->end>st->start+2){ // 戻り値有り
  1569. push_copy(st->stack,st->start+2);
  1570. }
  1571. st->state=RETFUNC;
  1572. return 0;
  1573. }
  1574. /*==========================================
  1575. *
  1576. *------------------------------------------
  1577. */
  1578. int buildin_next(struct script_state *st)
  1579. {
  1580. st->state=STOP;
  1581. clif_scriptnext(script_rid2sd(st),st->oid);
  1582. return 0;
  1583. }
  1584. /*==========================================
  1585. *
  1586. *------------------------------------------
  1587. */
  1588. int buildin_close(struct script_state *st)
  1589. {
  1590. st->state=END;
  1591. clif_scriptclose(script_rid2sd(st),st->oid);
  1592. return 0;
  1593. }
  1594. int buildin_close2(struct script_state *st)
  1595. {
  1596. st->state=STOP;
  1597. clif_scriptclose(script_rid2sd(st),st->oid);
  1598. return 0;
  1599. }
  1600. /*==========================================
  1601. *
  1602. *------------------------------------------
  1603. */
  1604. int buildin_menu(struct script_state *st)
  1605. {
  1606. char *buf;
  1607. int len,i;
  1608. struct map_session_data *sd;
  1609. sd=script_rid2sd(st);
  1610. if(sd->state.menu_or_input==0){
  1611. st->state=RERUNLINE;
  1612. sd->state.menu_or_input=1;
  1613. for(i=st->start+2,len=16;i<st->end;i+=2){
  1614. conv_str(st,& (st->stack->stack_data[i]));
  1615. len+=strlen(st->stack->stack_data[i].u.str)+1;
  1616. }
  1617. buf=(char *)aCallocA(len+1,sizeof(char));
  1618. buf[0]=0;
  1619. for(i=st->start+2,len=0;i<st->end;i+=2){
  1620. strcat(buf,st->stack->stack_data[i].u.str);
  1621. strcat(buf,":");
  1622. }
  1623. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  1624. aFree(buf);
  1625. } else if(sd->npc_menu==0xff){ // cansel
  1626. sd->state.menu_or_input=0;
  1627. st->state=END;
  1628. } else { // goto動作
  1629. // ragemu互換のため
  1630. pc_setreg(sd,add_str((unsigned char *) "l15"),sd->npc_menu);
  1631. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  1632. sd->state.menu_or_input=0;
  1633. if(sd->npc_menu>0 && sd->npc_menu<(st->end-st->start)/2){
  1634. int pos;
  1635. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  1636. printf("script: menu: not label !\n");
  1637. st->state=END;
  1638. return 0;
  1639. }
  1640. pos=conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  1641. st->pos=pos;
  1642. st->state=GOTO;
  1643. }
  1644. }
  1645. return 0;
  1646. }
  1647. /*==========================================
  1648. *
  1649. *------------------------------------------
  1650. */
  1651. int buildin_rand(struct script_state *st)
  1652. {
  1653. int range,min,max;
  1654. if(st->end>st->start+3){
  1655. min=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1656. max=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1657. if(max<min){
  1658. int tmp;
  1659. tmp=min;
  1660. min=max;
  1661. max=tmp;
  1662. }
  1663. range=max-min+1;
  1664. push_val(st->stack,C_INT,rand()%range+min);
  1665. } else {
  1666. range=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1667. push_val(st->stack,C_INT,rand()%range);
  1668. }
  1669. return 0;
  1670. }
  1671. /*==========================================
  1672. *
  1673. *------------------------------------------
  1674. */
  1675. int buildin_warp(struct script_state *st)
  1676. {
  1677. int x,y;
  1678. char *str;
  1679. struct map_session_data *sd=script_rid2sd(st);
  1680. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  1681. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1682. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  1683. if(strcmp(str,"Random")==0)
  1684. pc_randomwarp(sd,3);
  1685. else if(strcmp(str,"SavePoint")==0){
  1686. if(map[sd->bl.m].flag.noreturn) // 蝶禁止
  1687. return 0;
  1688. pc_setpos(sd,sd->status.save_point.map,
  1689. sd->status.save_point.x,sd->status.save_point.y,3);
  1690. }else if(strcmp(str,"Save")==0){
  1691. if(map[sd->bl.m].flag.noreturn) // 蝶禁止
  1692. return 0;
  1693. pc_setpos(sd,sd->status.save_point.map,
  1694. sd->status.save_point.x,sd->status.save_point.y,3);
  1695. }else
  1696. pc_setpos(sd,str,x,y,0);
  1697. return 0;
  1698. }
  1699. /*==========================================
  1700. * エリア指定ワープ
  1701. *------------------------------------------
  1702. */
  1703. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  1704. {
  1705. int x,y;
  1706. char *map;
  1707. map=va_arg(ap, char *);
  1708. x=va_arg(ap,int);
  1709. y=va_arg(ap,int);
  1710. if(strcmp(map,"Random")==0)
  1711. pc_randomwarp((struct map_session_data *)bl,3);
  1712. else
  1713. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  1714. return 0;
  1715. }
  1716. int buildin_areawarp(struct script_state *st)
  1717. {
  1718. int x,y,m;
  1719. char *str;
  1720. char *mapname;
  1721. int x0,y0,x1,y1;
  1722. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  1723. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1724. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  1725. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  1726. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  1727. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  1728. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  1729. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  1730. if( (m=map_mapname2mapid(mapname))< 0)
  1731. return 0;
  1732. map_foreachinarea(buildin_areawarp_sub,
  1733. m,x0,y0,x1,y1,BL_PC, str,x,y );
  1734. return 0;
  1735. }
  1736. /*==========================================
  1737. *
  1738. *------------------------------------------
  1739. */
  1740. int buildin_heal(struct script_state *st)
  1741. {
  1742. int hp,sp;
  1743. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1744. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1745. pc_heal(script_rid2sd(st),hp,sp);
  1746. return 0;
  1747. }
  1748. /*==========================================
  1749. *
  1750. *------------------------------------------
  1751. */
  1752. int buildin_itemheal(struct script_state *st)
  1753. {
  1754. int hp,sp;
  1755. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1756. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1757. pc_itemheal(script_rid2sd(st),hp,sp);
  1758. return 0;
  1759. }
  1760. /*==========================================
  1761. *
  1762. *------------------------------------------
  1763. */
  1764. int buildin_percentheal(struct script_state *st)
  1765. {
  1766. int hp,sp;
  1767. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1768. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1769. pc_percentheal(script_rid2sd(st),hp,sp);
  1770. return 0;
  1771. }
  1772. /*==========================================
  1773. *
  1774. *------------------------------------------
  1775. */
  1776. int buildin_jobchange(struct script_state *st)
  1777. {
  1778. int job, upper=-1;
  1779. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1780. if( st->end>st->start+3 )
  1781. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1782. if ((job >= 0 && job < MAX_PC_CLASS))
  1783. pc_jobchange(script_rid2sd(st),job, upper);
  1784. return 0;
  1785. }
  1786. /*==========================================
  1787. *
  1788. *------------------------------------------
  1789. */
  1790. int buildin_input(struct script_state *st)
  1791. {
  1792. struct map_session_data *sd=NULL;
  1793. int num=(st->end>st->start+2)?st->stack->stack_data[st->start+2].u.num:0;
  1794. char *name=(char *) ((st->end>st->start+2)?str_buf+str_data[num&0x00ffffff].str:"");
  1795. // char prefix=*name;
  1796. char postfix=name[strlen(name)-1];
  1797. sd=script_rid2sd(st);
  1798. if(sd->state.menu_or_input){
  1799. sd->state.menu_or_input=0;
  1800. if( postfix=='$' ){
  1801. // 文字列
  1802. if(st->end>st->start+2){ // 引数1個
  1803. set_reg(sd,num,name,(void*)sd->npc_str);
  1804. }else{
  1805. printf("buildin_input: string discarded !!\n");
  1806. }
  1807. }else{
  1808. // commented by Lupus (check Value Number Input fix in clif.c)
  1809. // readded by Yor: set ammount to 0 instead of cancel trade.
  1810. // ** Fix by fritz :X keeps people from abusing old input bugs
  1811. if (sd->npc_amount < 0) { //** If input amount is less then 0
  1812. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  1813. // buildin_close(st); // ** close
  1814. sd->npc_amount = 0;
  1815. } else if (sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  1816. sd->npc_amount = battle_config.vending_max_value;
  1817. // 数値
  1818. if(st->end>st->start+2){ // 引数1個
  1819. set_reg(sd,num,name,(void*)sd->npc_amount);
  1820. } else {
  1821. // ragemu互換のため
  1822. pc_setreg(sd,add_str((unsigned char *) "l14"),sd->npc_amount);
  1823. }
  1824. }
  1825. } else {
  1826. st->state=RERUNLINE;
  1827. if(postfix=='$')clif_scriptinputstr(sd,st->oid);
  1828. else clif_scriptinput(sd,st->oid);
  1829. sd->state.menu_or_input=1;
  1830. }
  1831. return 0;
  1832. }
  1833. /*==========================================
  1834. *
  1835. *------------------------------------------
  1836. */
  1837. int buildin_if(struct script_state *st)
  1838. {
  1839. int sel,i;
  1840. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1841. if(!sel)
  1842. return 0;
  1843. // 関数名をコピー
  1844. push_copy(st->stack,st->start+3);
  1845. // 間に引数マーカを入れて
  1846. push_val(st->stack,C_ARG,0);
  1847. // 残りの引数をコピー
  1848. for(i=st->start+4;i<st->end;i++){
  1849. push_copy(st->stack,i);
  1850. }
  1851. run_func(st);
  1852. return 0;
  1853. }
  1854. /*==========================================
  1855. * 変数設定
  1856. *------------------------------------------
  1857. */
  1858. int buildin_set(struct script_state *st)
  1859. {
  1860. struct map_session_data *sd=NULL;
  1861. int num=st->stack->stack_data[st->start+2].u.num;
  1862. char *name=str_buf+str_data[num&0x00ffffff].str;
  1863. char prefix=*name;
  1864. char postfix=name[strlen(name)-1];
  1865. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  1866. printf("script: buildin_set: not name\n");
  1867. return 0;
  1868. }
  1869. if( prefix!='$' )
  1870. sd=script_rid2sd(st);
  1871. if( postfix=='$' ){
  1872. // 文字列
  1873. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  1874. set_reg(sd,num,name,(void*)str);
  1875. }else{
  1876. // 数値
  1877. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  1878. set_reg(sd,num,name,(void*)val);
  1879. }
  1880. return 0;
  1881. }
  1882. /*==========================================
  1883. * 配列変数設定
  1884. *------------------------------------------
  1885. */
  1886. int buildin_setarray(struct script_state *st)
  1887. {
  1888. struct map_session_data *sd=NULL;
  1889. int num=st->stack->stack_data[st->start+2].u.num;
  1890. char *name=str_buf+str_data[num&0x00ffffff].str;
  1891. char prefix=*name;
  1892. char postfix=name[strlen(name)-1];
  1893. int i,j;
  1894. if( prefix!='$' && prefix!='@' ){
  1895. printf("buildin_setarray: illegal scope !\n");
  1896. return 0;
  1897. }
  1898. if( prefix!='$' )
  1899. sd=script_rid2sd(st);
  1900. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  1901. void *v;
  1902. if( postfix=='$' )
  1903. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  1904. else
  1905. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  1906. set_reg( sd, num+(j<<24), name, v);
  1907. }
  1908. return 0;
  1909. }
  1910. /*==========================================
  1911. * 配列変数クリア
  1912. *------------------------------------------
  1913. */
  1914. int buildin_cleararray(struct script_state *st)
  1915. {
  1916. struct map_session_data *sd=NULL;
  1917. int num=st->stack->stack_data[st->start+2].u.num;
  1918. char *name=str_buf+str_data[num&0x00ffffff].str;
  1919. char prefix=*name;
  1920. char postfix=name[strlen(name)-1];
  1921. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  1922. int i;
  1923. void *v;
  1924. if( prefix!='$' && prefix!='@' ){
  1925. printf("buildin_cleararray: illegal scope !\n");
  1926. return 0;
  1927. }
  1928. if( prefix!='$' )
  1929. sd=script_rid2sd(st);
  1930. if( postfix=='$' )
  1931. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  1932. else
  1933. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  1934. for(i=0;i<sz;i++)
  1935. set_reg(sd,num+(i<<24),name,v);
  1936. return 0;
  1937. }
  1938. /*==========================================
  1939. * 配列変数コピー
  1940. *------------------------------------------
  1941. */
  1942. int buildin_copyarray(struct script_state *st)
  1943. {
  1944. struct map_session_data *sd=NULL;
  1945. int num=st->stack->stack_data[st->start+2].u.num;
  1946. char *name=str_buf+str_data[num&0x00ffffff].str;
  1947. char prefix=*name;
  1948. char postfix=name[strlen(name)-1];
  1949. int num2=st->stack->stack_data[st->start+3].u.num;
  1950. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  1951. char prefix2=*name2;
  1952. char postfix2=name2[strlen(name2)-1];
  1953. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  1954. int i;
  1955. if( prefix!='$' && prefix!='@' && prefix2!='$' && prefix2!='@' ){
  1956. printf("buildin_copyarray: illegal scope !\n");
  1957. return 0;
  1958. }
  1959. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  1960. printf("buildin_copyarray: type mismatch !\n");
  1961. return 0;
  1962. }
  1963. if( prefix!='$' || prefix2!='$' )
  1964. sd=script_rid2sd(st);
  1965. for(i=0;i<sz;i++)
  1966. set_reg(sd,num+(i<<24),name, get_val2(st,num2+(i<<24)) );
  1967. return 0;
  1968. }
  1969. /*==========================================
  1970. * 配列変数のサイズ所得
  1971. *------------------------------------------
  1972. */
  1973. static int getarraysize(struct script_state *st,int num,int postfix)
  1974. {
  1975. int i=(num>>24),c=i;
  1976. for(;i<128;i++){
  1977. void *v=get_val2(st,num+(i<<24));
  1978. if(postfix=='$' && *((char*)v) ) c=i;
  1979. if(postfix!='$' && (int)v )c=i;
  1980. }
  1981. return c+1;
  1982. }
  1983. int buildin_getarraysize(struct script_state *st)
  1984. {
  1985. int num=st->stack->stack_data[st->start+2].u.num;
  1986. char *name=str_buf+str_data[num&0x00ffffff].str;
  1987. char prefix=*name;
  1988. char postfix=name[strlen(name)-1];
  1989. if( prefix!='$' && prefix!='@' ){
  1990. printf("buildin_copyarray: illegal scope !\n");
  1991. return 0;
  1992. }
  1993. push_val(st->stack,C_INT,getarraysize(st,num,postfix) );
  1994. return 0;
  1995. }
  1996. /*==========================================
  1997. * 配列変数から要素削除
  1998. *------------------------------------------
  1999. */
  2000. int buildin_deletearray(struct script_state *st)
  2001. {
  2002. struct map_session_data *sd=NULL;
  2003. int num=st->stack->stack_data[st->start+2].u.num;
  2004. char *name=str_buf+str_data[num&0x00ffffff].str;
  2005. char prefix=*name;
  2006. char postfix=name[strlen(name)-1];
  2007. int count=1;
  2008. int i,sz=getarraysize(st,num,postfix)-(num>>24)-count+1;
  2009. if( (st->end > st->start+3) )
  2010. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2011. if( prefix!='$' && prefix!='@' ){
  2012. printf("buildin_deletearray: illegal scope !\n");
  2013. return 0;
  2014. }
  2015. if( prefix!='$' )
  2016. sd=script_rid2sd(st);
  2017. for(i=0;i<sz;i++){
  2018. set_reg(sd,num+(i<<24),name, get_val2(st,num+((i+count)<<24) ) );
  2019. }
  2020. for(;i<(128-(num>>24));i++){
  2021. if( postfix!='$' ) set_reg(sd,num+(i<<24),name, 0);
  2022. if( postfix=='$' ) set_reg(sd,num+(i<<24),name, (void *) "");
  2023. }
  2024. return 0;
  2025. }
  2026. /*==========================================
  2027. * 指定要素を表す値(キー)を所得する
  2028. *------------------------------------------
  2029. */
  2030. int buildin_getelementofarray(struct script_state *st)
  2031. {
  2032. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  2033. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2034. if(i>127 || i<0){
  2035. printf("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  2036. push_val(st->stack,C_INT,0);
  2037. }else{
  2038. push_val(st->stack,C_NAME,
  2039. (i<<24) | st->stack->stack_data[st->start+2].u.num );
  2040. }
  2041. }else{
  2042. printf("script: getelementofarray (operator[]): param1 not name !\n");
  2043. push_val(st->stack,C_INT,0);
  2044. }
  2045. return 0;
  2046. }
  2047. /*==========================================
  2048. *
  2049. *------------------------------------------
  2050. */
  2051. int buildin_setlook(struct script_state *st)
  2052. {
  2053. int type,val;
  2054. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2055. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2056. pc_changelook(script_rid2sd(st),type,val);
  2057. return 0;
  2058. }
  2059. /*==========================================
  2060. *
  2061. *------------------------------------------
  2062. */
  2063. int buildin_cutin(struct script_state *st)
  2064. {
  2065. int type;
  2066. conv_str(st,& (st->stack->stack_data[st->start+2]));
  2067. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2068. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  2069. return 0;
  2070. }
  2071. /*==========================================
  2072. * カードのイラストを表示する
  2073. *------------------------------------------
  2074. */
  2075. int buildin_cutincard(struct script_state *st)
  2076. {
  2077. int itemid;
  2078. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2079. clif_cutin(script_rid2sd(st),itemdb_search(itemid)->cardillustname,4);
  2080. return 0;
  2081. }
  2082. /*==========================================
  2083. *
  2084. *------------------------------------------
  2085. */
  2086. int buildin_viewpoint(struct script_state *st)
  2087. {
  2088. int type,x,y,id,color;
  2089. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2090. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2091. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2092. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2093. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  2094. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  2095. return 0;
  2096. }
  2097. /*==========================================
  2098. *
  2099. *------------------------------------------
  2100. */
  2101. int buildin_countitem(struct script_state *st)
  2102. {
  2103. int nameid=0,count=0,i;
  2104. struct map_session_data *sd;
  2105. struct script_data *data;
  2106. sd = script_rid2sd(st);
  2107. data=&(st->stack->stack_data[st->start+2]);
  2108. get_val(st,data);
  2109. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2110. const char *name=conv_str(st,data);
  2111. struct item_data *item_data;
  2112. if( (item_data = itemdb_searchname(name)) != NULL)
  2113. nameid=item_data->nameid;
  2114. }else
  2115. nameid=conv_num(st,data);
  2116. if (nameid>=500) //if no such ID then skip this iteration
  2117. for(i=0;i<MAX_INVENTORY;i++){
  2118. if(sd->status.inventory[i].nameid==nameid)
  2119. count+=sd->status.inventory[i].amount;
  2120. }
  2121. else{
  2122. if(battle_config.error_log)
  2123. printf("wrong item ID : countitem(%i)\n",nameid);
  2124. }
  2125. push_val(st->stack,C_INT,count);
  2126. return 0;
  2127. }
  2128. /*==========================================
  2129. * 重量チェック
  2130. *------------------------------------------
  2131. */
  2132. int buildin_checkweight(struct script_state *st)
  2133. {
  2134. int nameid=0,amount;
  2135. struct map_session_data *sd;
  2136. struct script_data *data;
  2137. sd = script_rid2sd(st);
  2138. data=&(st->stack->stack_data[st->start+2]);
  2139. get_val(st,data);
  2140. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2141. const char *name=conv_str(st,data);
  2142. struct item_data *item_data = itemdb_searchname(name);
  2143. if( item_data )
  2144. nameid=item_data->nameid;
  2145. }else
  2146. nameid=conv_num(st,data);
  2147. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2148. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  2149. push_val(st->stack,C_INT,0);
  2150. }
  2151. sd=script_rid2sd(st);
  2152. if(itemdb_weight(nameid)*amount + sd->weight > sd->max_weight){
  2153. push_val(st->stack,C_INT,0);
  2154. } else {
  2155. push_val(st->stack,C_INT,1);
  2156. }
  2157. return 0;
  2158. }
  2159. /*==========================================
  2160. *
  2161. *------------------------------------------
  2162. */
  2163. int buildin_getitem(struct script_state *st)
  2164. {
  2165. int nameid,nameidsrc,amount,flag = 0;
  2166. struct item item_tmp;
  2167. struct map_session_data *sd;
  2168. struct script_data *data;
  2169. sd = script_rid2sd(st);
  2170. data=&(st->stack->stack_data[st->start+2]);
  2171. get_val(st,data);
  2172. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2173. const char *name=conv_str(st,data);
  2174. struct item_data *item_data = itemdb_searchname(name);
  2175. nameid=512; //Apple item ID
  2176. if( item_data != NULL)
  2177. nameid=item_data->nameid;
  2178. }else
  2179. nameid=conv_num(st,data);
  2180. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0) {
  2181. return 0; //return if amount <=0, skip the useles iteration
  2182. }
  2183. //Violet Box, Blue Box, etc - random item pick
  2184. if((nameidsrc = nameid)<0) { // Save real ID of the source Box [Lupus]
  2185. nameid=itemdb_searchrandomid(-nameid);
  2186. if(log_config.present > 0)
  2187. log_present(sd, -nameidsrc, nameid); //fixed missing ID by Lupus
  2188. flag = 1;
  2189. }
  2190. if(nameid > 0) {
  2191. memset(&item_tmp,0,sizeof(item_tmp));
  2192. item_tmp.nameid=nameid;
  2193. if(!flag)
  2194. item_tmp.identify=1;
  2195. else
  2196. item_tmp.identify=!itemdb_isequip3(nameid);
  2197. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  2198. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  2199. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  2200. return 0;
  2201. if((flag = pc_additem(sd,&item_tmp,amount))) {
  2202. clif_additem(sd,0,0,flag);
  2203. if(!pc_candrop(sd,nameid))
  2204. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  2205. }
  2206. }
  2207. return 0;
  2208. }
  2209. /*==========================================
  2210. *
  2211. *------------------------------------------
  2212. */
  2213. int buildin_getitem2(struct script_state *st)
  2214. {
  2215. int nameid,amount,flag = 0;
  2216. int iden,ref,attr,c1,c2,c3,c4;
  2217. struct item_data *item_data;
  2218. struct item item_tmp;
  2219. struct map_session_data *sd;
  2220. struct script_data *data;
  2221. sd = script_rid2sd(st);
  2222. data=&(st->stack->stack_data[st->start+2]);
  2223. get_val(st,data);
  2224. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2225. const char *name=conv_str(st,data);
  2226. struct item_data *item_data = itemdb_searchname(name);
  2227. nameid=512; //Apple item ID
  2228. if( item_data )
  2229. nameid=item_data->nameid;
  2230. }else
  2231. nameid=conv_num(st,data);
  2232. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2233. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2234. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2235. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  2236. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  2237. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  2238. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  2239. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  2240. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  2241. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  2242. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  2243. return 0;
  2244. if(nameid<0) { // ランダム
  2245. nameid=itemdb_searchrandomid(-nameid);
  2246. flag = 1;
  2247. }
  2248. if(nameid > 0) {
  2249. memset(&item_tmp,0,sizeof(item_tmp));
  2250. item_data=itemdb_search(nameid);
  2251. if(item_data->type==4 || item_data->type==5){
  2252. if(ref > 10) ref = 10;
  2253. }
  2254. else if(item_data->type==7) {
  2255. iden = 1;
  2256. ref = 0;
  2257. }
  2258. else {
  2259. iden = 1;
  2260. ref = attr = 0;
  2261. }
  2262. item_tmp.nameid=nameid;
  2263. if(!flag)
  2264. item_tmp.identify=iden;
  2265. else if(item_data->type==4 || item_data->type==5)
  2266. item_tmp.identify=0;
  2267. item_tmp.refine=ref;
  2268. item_tmp.attribute=attr;
  2269. item_tmp.card[0]=c1;
  2270. item_tmp.card[1]=c2;
  2271. item_tmp.card[2]=c3;
  2272. item_tmp.card[3]=c4;
  2273. if((flag = pc_additem(sd,&item_tmp,amount))) {
  2274. clif_additem(sd,0,0,flag);
  2275. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  2276. }
  2277. }
  2278. return 0;
  2279. }
  2280. /*==========================================
  2281. *
  2282. *------------------------------------------
  2283. */
  2284. int buildin_makeitem(struct script_state *st)
  2285. {
  2286. int nameid,amount,flag = 0;
  2287. int x,y,m;
  2288. char *mapname;
  2289. struct item item_tmp;
  2290. struct map_session_data *sd;
  2291. struct script_data *data;
  2292. sd = script_rid2sd(st);
  2293. data=&(st->stack->stack_data[st->start+2]);
  2294. get_val(st,data);
  2295. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2296. const char *name=conv_str(st,data);
  2297. struct item_data *item_data = itemdb_searchname(name);
  2298. nameid=512; //Apple Item ID
  2299. if( item_data )
  2300. nameid=item_data->nameid;
  2301. }else
  2302. nameid=conv_num(st,data);
  2303. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2304. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  2305. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  2306. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  2307. if( sd && strcmp(mapname,"this")==0)
  2308. m=sd->bl.m;
  2309. else
  2310. m=map_mapname2mapid(mapname);
  2311. if(nameid<0) { // ランダム
  2312. nameid=itemdb_searchrandomid(-nameid);
  2313. flag = 1;
  2314. }
  2315. if(nameid > 0) {
  2316. memset(&item_tmp,0,sizeof(item_tmp));
  2317. item_tmp.nameid=nameid;
  2318. if(!flag)
  2319. item_tmp.identify=1;
  2320. else
  2321. item_tmp.identify=!itemdb_isequip3(nameid);
  2322. // clif_additem(sd,0,0,flag);
  2323. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  2324. }
  2325. return 0;
  2326. }
  2327. /*==========================================
  2328. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  2329. *------------------------------------------
  2330. */
  2331. int buildin_delitem(struct script_state *st)
  2332. {
  2333. int nameid=0,amount,i,important_item=0;
  2334. struct map_session_data *sd;
  2335. struct script_data *data;
  2336. sd = script_rid2sd(st);
  2337. data=&(st->stack->stack_data[st->start+2]);
  2338. get_val(st,data);
  2339. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2340. const char *name=conv_str(st,data);
  2341. struct item_data *item_data = itemdb_searchname(name);
  2342. //nameid=512;
  2343. if( item_data )
  2344. nameid=item_data->nameid;
  2345. }else
  2346. nameid=conv_num(st,data);
  2347. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2348. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  2349. //printf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  2350. return 0;
  2351. }
  2352. sd=script_rid2sd(st);
  2353. //1st pass
  2354. //here we won't delete items with CARDS, named items but we count them
  2355. for(i=0;i<MAX_INVENTORY;i++){
  2356. //we don't delete wrong item or equipped item
  2357. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  2358. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  2359. continue;
  2360. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  2361. if(sd->inventory_data[i]->type==7 && sd->status.inventory[i].card[0] == (short)0xff00 && search_petDB_index(nameid, PET_EGG) >= 0 ){
  2362. intif_delete_petdata(*((long *)(&sd->status.inventory[i].card[1])));
  2363. //clear egg flag. so it won't be put in IMPORTANT items (eggs look like item with 2 cards ^_^)
  2364. sd->status.inventory[i].card[1] = sd->status.inventory[i].card[0] = 0;
  2365. //now this egg'll be deleted as a common unimportant item
  2366. }
  2367. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  2368. if( sd->status.inventory[i].card[0] || sd->status.inventory[i].card[1] ||
  2369. sd->status.inventory[i].card[2] || sd->status.inventory[i].card[3] || sd->status.inventory[i].refine) {
  2370. //this is important item, count it
  2371. important_item++;
  2372. continue;
  2373. }
  2374. if(sd->status.inventory[i].amount>=amount){
  2375. pc_delitem(sd,i,amount,0);
  2376. return 0; //we deleted exact amount of items. now exit
  2377. } else {
  2378. amount-=sd->status.inventory[i].amount;
  2379. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  2380. }
  2381. }
  2382. //2nd pass
  2383. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  2384. if (important_item>0 && amount>0)
  2385. for(i=0;i<MAX_INVENTORY;i++){
  2386. //we don't delete wrong item
  2387. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  2388. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  2389. continue;
  2390. if(sd->status.inventory[i].amount>=amount){
  2391. pc_delitem(sd,i,amount,0);
  2392. return 0; //we deleted exact amount of items. now exit
  2393. } else {
  2394. amount-=sd->status.inventory[i].amount;
  2395. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  2396. }
  2397. }
  2398. return 0;
  2399. }
  2400. /*==========================================
  2401. *キャラ関係のパラメータ取得
  2402. *------------------------------------------
  2403. */
  2404. int buildin_readparam(struct script_state *st)
  2405. {
  2406. int type;
  2407. struct map_session_data *sd;
  2408. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2409. if( st->end>st->start+3 )
  2410. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  2411. else
  2412. sd=script_rid2sd(st);
  2413. if(sd==NULL){
  2414. push_val(st->stack,C_INT,-1);
  2415. return 0;
  2416. }
  2417. push_val(st->stack,C_INT,pc_readparam(sd,type));
  2418. return 0;
  2419. }
  2420. /*==========================================
  2421. *キャラ関係のID取得
  2422. *------------------------------------------
  2423. */
  2424. int buildin_getcharid(struct script_state *st)
  2425. {
  2426. int num;
  2427. struct map_session_data *sd;
  2428. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2429. if( st->end>st->start+3 )
  2430. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  2431. else
  2432. sd=script_rid2sd(st);
  2433. if(sd==NULL){
  2434. push_val(st->stack,C_INT,-1);
  2435. return 0;
  2436. }
  2437. if(num==0)
  2438. push_val(st->stack,C_INT,sd->status.char_id);
  2439. if(num==1)
  2440. push_val(st->stack,C_INT,sd->status.party_id);
  2441. if(num==2)
  2442. push_val(st->stack,C_INT,sd->status.guild_id);
  2443. if(num==3)
  2444. push_val(st->stack,C_INT,sd->status.account_id);
  2445. return 0;
  2446. }
  2447. /*==========================================
  2448. *指定IDのPT名取得
  2449. *------------------------------------------
  2450. */
  2451. char *buildin_getpartyname_sub(int party_id)
  2452. {
  2453. struct party *p;
  2454. p=NULL;
  2455. p=party_search(party_id);
  2456. if(p!=NULL){
  2457. char *buf;
  2458. buf=(char *)aCallocA(24,sizeof(char));
  2459. strcpy(buf,p->name);
  2460. return buf;
  2461. }
  2462. return 0;
  2463. }
  2464. int buildin_getpartyname(struct script_state *st)
  2465. {
  2466. char *name;
  2467. int party_id;
  2468. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2469. name=buildin_getpartyname_sub(party_id);
  2470. if(name!=0)
  2471. push_str(st->stack,C_STR,(unsigned char *)name);
  2472. else
  2473. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  2474. return 0;
  2475. }
  2476. /*==========================================
  2477. *指定IDのPT人数とメンバーID取得
  2478. *------------------------------------------
  2479. */
  2480. int buildin_getpartymember(struct script_state *st)
  2481. {
  2482. struct party *p;
  2483. int i,j=0;
  2484. p=NULL;
  2485. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  2486. if(p!=NULL){
  2487. for(i=0;i<MAX_PARTY;i++){
  2488. if(p->member[i].account_id){
  2489. // printf("name:%s %d\n",p->member[i].name,i);
  2490. mapreg_setregstr(add_str((unsigned char *) "$@partymembername$")+(i<<24),p->member[i].name);
  2491. j++;
  2492. }
  2493. }
  2494. }
  2495. mapreg_setreg(add_str((unsigned char *) "$@partymembercount"),j);
  2496. return 0;
  2497. }
  2498. /*==========================================
  2499. *指定IDのギルド名取得
  2500. *------------------------------------------
  2501. */
  2502. char *buildin_getguildname_sub(int guild_id)
  2503. {
  2504. struct guild *g=NULL;
  2505. g=guild_search(guild_id);
  2506. if(g!=NULL){
  2507. char *buf;
  2508. buf=(char *)aCallocA(24,sizeof(char));
  2509. strcpy(buf,g->name);
  2510. return buf;
  2511. }
  2512. return 0;
  2513. }
  2514. int buildin_getguildname(struct script_state *st)
  2515. {
  2516. char *name;
  2517. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2518. name=buildin_getguildname_sub(guild_id);
  2519. if(name!=0)
  2520. push_str(st->stack,C_STR,(unsigned char *) name);
  2521. else
  2522. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  2523. return 0;
  2524. }
  2525. /*==========================================
  2526. *指定IDのGuildMaster名取得
  2527. *------------------------------------------
  2528. */
  2529. char *buildin_getguildmaster_sub(int guild_id)
  2530. {
  2531. struct guild *g=NULL;
  2532. g=guild_search(guild_id);
  2533. if(g!=NULL){
  2534. char *buf;
  2535. buf=(char *)aCallocA(24,sizeof(char));
  2536. strncpy(buf,g->master, 23);
  2537. return buf;
  2538. }
  2539. return 0;
  2540. }
  2541. int buildin_getguildmaster(struct script_state *st)
  2542. {
  2543. char *master;
  2544. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2545. master=buildin_getguildmaster_sub(guild_id);
  2546. if(master!=0)
  2547. push_str(st->stack,C_STR,(unsigned char *) master);
  2548. else
  2549. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  2550. return 0;
  2551. }
  2552. int buildin_getguildmasterid(struct script_state *st)
  2553. {
  2554. char *master;
  2555. struct map_session_data *sd=NULL;
  2556. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2557. master=buildin_getguildmaster_sub(guild_id);
  2558. if(master!=0){
  2559. if((sd=map_nick2sd(master)) == NULL){
  2560. push_val(st->stack,C_INT,0);
  2561. return 0;
  2562. }
  2563. push_val(st->stack,C_INT,sd->status.char_id);
  2564. }else{
  2565. push_val(st->stack,C_INT,0);
  2566. }
  2567. return 0;
  2568. }
  2569. /*==========================================
  2570. * キャラクタの名前
  2571. *------------------------------------------
  2572. */
  2573. int buildin_strcharinfo(struct script_state *st)
  2574. {
  2575. struct map_session_data *sd;
  2576. int num;
  2577. sd=script_rid2sd(st);
  2578. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2579. if(num==0){
  2580. char *buf;
  2581. buf=(char *)aCallocA(24,sizeof(char));
  2582. strncpy(buf,sd->status.name, 23);
  2583. push_str(st->stack,C_STR,(unsigned char *) buf);
  2584. }
  2585. if(num==1){
  2586. char *buf;
  2587. buf=buildin_getpartyname_sub(sd->status.party_id);
  2588. if(buf!=0)
  2589. push_str(st->stack,C_STR,(unsigned char *) buf);
  2590. else
  2591. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  2592. }
  2593. if(num==2){
  2594. char *buf;
  2595. buf=buildin_getguildname_sub(sd->status.guild_id);
  2596. if(buf!=0)
  2597. push_str(st->stack,C_STR,(unsigned char *) buf);
  2598. else
  2599. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  2600. }
  2601. return 0;
  2602. }
  2603. unsigned int equip[10]={0x0100,0x0010,0x0020,0x0002,0x0004,0x0040,0x0008,0x0080,0x0200,0x0001};
  2604. /*==========================================
  2605. * GetEquipID(Pos); Pos: 1-10
  2606. *------------------------------------------
  2607. */
  2608. int buildin_getequipid(struct script_state *st)
  2609. {
  2610. int i,num;
  2611. struct map_session_data *sd;
  2612. struct item_data* item;
  2613. sd=script_rid2sd(st);
  2614. if(sd == NULL)
  2615. {
  2616. printf("getequipid: sd == NULL\n");
  2617. return 0;
  2618. }
  2619. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2620. i=pc_checkequip(sd,equip[num-1]);
  2621. if(i >= 0){
  2622. item=sd->inventory_data[i];
  2623. if(item)
  2624. push_val(st->stack,C_INT,item->nameid);
  2625. else
  2626. push_val(st->stack,C_INT,0);
  2627. }else{
  2628. push_val(st->stack,C_INT,-1);
  2629. }
  2630. return 0;
  2631. }
  2632. /*==========================================
  2633. * 装備名文字列(精錬メニュー用)
  2634. *------------------------------------------
  2635. */
  2636. int buildin_getequipname(struct script_state *st)
  2637. {
  2638. int i,num;
  2639. struct map_session_data *sd;
  2640. struct item_data* item;
  2641. char *buf;
  2642. buf=(char *)aCallocA(64,sizeof(char));
  2643. sd=script_rid2sd(st);
  2644. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2645. i=pc_checkequip(sd,equip[num-1]);
  2646. if(i >= 0){
  2647. item=sd->inventory_data[i];
  2648. if(item)
  2649. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  2650. else
  2651. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  2652. }else{
  2653. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  2654. }
  2655. push_str(st->stack,C_STR,buf);
  2656. return 0;
  2657. }
  2658. /*==========================================
  2659. * getbrokenid [Valaris]
  2660. *------------------------------------------
  2661. */
  2662. int buildin_getbrokenid(struct script_state *st)
  2663. {
  2664. int i,num,id=0,brokencounter=0;
  2665. struct map_session_data *sd;
  2666. sd=script_rid2sd(st);
  2667. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2668. for(i=0; i<MAX_INVENTORY; i++) {
  2669. if(sd->status.inventory[i].attribute==1){
  2670. brokencounter++;
  2671. if(num==brokencounter){
  2672. id=sd->status.inventory[i].nameid;
  2673. break;
  2674. }
  2675. }
  2676. }
  2677. push_val(st->stack,C_INT,id);
  2678. return 0;
  2679. }
  2680. /*==========================================
  2681. * repair [Valaris]
  2682. *------------------------------------------
  2683. */
  2684. int buildin_repair(struct script_state *st)
  2685. {
  2686. int i,num;
  2687. int repaircounter=0;
  2688. struct map_session_data *sd;
  2689. sd=script_rid2sd(st);
  2690. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2691. for(i=0; i<MAX_INVENTORY; i++) {
  2692. if(sd->status.inventory[i].attribute==1){
  2693. repaircounter++;
  2694. if(num==repaircounter){
  2695. sd->status.inventory[i].attribute=0;
  2696. clif_equiplist(sd);
  2697. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  2698. clif_misceffect(&sd->bl, 3);
  2699. clif_displaymessage(sd->fd,"Item has been repaired.");
  2700. break;
  2701. }
  2702. }
  2703. }
  2704. return 0;
  2705. }
  2706. /*==========================================
  2707. * 装備チェック
  2708. *------------------------------------------
  2709. */
  2710. int buildin_getequipisequiped(struct script_state *st)
  2711. {
  2712. int i,num;
  2713. struct map_session_data *sd;
  2714. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2715. sd=script_rid2sd(st);
  2716. i=pc_checkequip(sd,equip[num-1]);
  2717. if(i >= 0){
  2718. push_val(st->stack,C_INT,1);
  2719. }else{
  2720. push_val(st->stack,C_INT,0);
  2721. }
  2722. return 0;
  2723. }
  2724. /*==========================================
  2725. * 装備品精錬可能チェック
  2726. *------------------------------------------
  2727. */
  2728. int buildin_getequipisenableref(struct script_state *st)
  2729. {
  2730. int i,num;
  2731. struct map_session_data *sd;
  2732. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2733. sd=script_rid2sd(st);
  2734. i=pc_checkequip(sd,equip[num-1]);
  2735. if(i >= 0 && num<7 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
  2736. // replaced by Celest
  2737. /*(num!=1
  2738. || sd->inventory_data[i]->def > 1
  2739. || (sd->inventory_data[i]->def==1 && sd->inventory_data[i]->equip_script==NULL)
  2740. || (sd->inventory_data[i]->def<=0 && sd->inventory_data[i]->equip_script!=NULL)))*/
  2741. {
  2742. push_val(st->stack,C_INT,1);
  2743. } else {
  2744. push_val(st->stack,C_INT,0);
  2745. }
  2746. return 0;
  2747. }
  2748. /*==========================================
  2749. * 装備品鑑定チェック
  2750. *------------------------------------------
  2751. */
  2752. int buildin_getequipisidentify(struct script_state *st)
  2753. {
  2754. int i,num;
  2755. struct map_session_data *sd;
  2756. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2757. sd=script_rid2sd(st);
  2758. i=pc_checkequip(sd,equip[num-1]);
  2759. if(i >= 0)
  2760. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  2761. else
  2762. push_val(st->stack,C_INT,0);
  2763. return 0;
  2764. }
  2765. /*==========================================
  2766. * 装備品精錬度
  2767. *------------------------------------------
  2768. */
  2769. int buildin_getequiprefinerycnt(struct script_state *st)
  2770. {
  2771. int i,num;
  2772. struct map_session_data *sd;
  2773. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2774. sd=script_rid2sd(st);
  2775. i=pc_checkequip(sd,equip[num-1]);
  2776. if(i >= 0)
  2777. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  2778. else
  2779. push_val(st->stack,C_INT,0);
  2780. return 0;
  2781. }
  2782. /*==========================================
  2783. * 装備品武器LV
  2784. *------------------------------------------
  2785. */
  2786. int buildin_getequipweaponlv(struct script_state *st)
  2787. {
  2788. int i,num;
  2789. struct map_session_data *sd;
  2790. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2791. sd=script_rid2sd(st);
  2792. i=pc_checkequip(sd,equip[num-1]);
  2793. if(i >= 0 && sd->inventory_data[i])
  2794. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  2795. else
  2796. push_val(st->stack,C_INT,0);
  2797. return 0;
  2798. }
  2799. /*==========================================
  2800. * 装備品精錬成功率
  2801. *------------------------------------------
  2802. */
  2803. int buildin_getequippercentrefinery(struct script_state *st)
  2804. {
  2805. int i,num;
  2806. struct map_session_data *sd;
  2807. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2808. sd=script_rid2sd(st);
  2809. i=pc_checkequip(sd,equip[num-1]);
  2810. if(i >= 0)
  2811. push_val(st->stack,C_INT,status_percentrefinery(sd,&sd->status.inventory[i]));
  2812. else
  2813. push_val(st->stack,C_INT,0);
  2814. return 0;
  2815. }
  2816. /*==========================================
  2817. * 精錬成功
  2818. *------------------------------------------
  2819. */
  2820. int buildin_successrefitem(struct script_state *st)
  2821. {
  2822. int i,num,ep;
  2823. struct map_session_data *sd;
  2824. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2825. sd=script_rid2sd(st);
  2826. i=pc_checkequip(sd,equip[num-1]);
  2827. if(i >= 0) {
  2828. ep=sd->status.inventory[i].equip;
  2829. if(log_config.refine > 0)
  2830. log_refine(sd, i, 1);
  2831. sd->status.inventory[i].refine++;
  2832. pc_unequipitem(sd,i,2);
  2833. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  2834. clif_delitem(sd,i,1);
  2835. clif_additem(sd,i,1,0);
  2836. pc_equipitem(sd,i,ep);
  2837. clif_misceffect(&sd->bl,3);
  2838. }
  2839. return 0;
  2840. }
  2841. /*==========================================
  2842. * 精錬失敗
  2843. *------------------------------------------
  2844. */
  2845. int buildin_failedrefitem(struct script_state *st)
  2846. {
  2847. int i,num;
  2848. struct map_session_data *sd;
  2849. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2850. sd=script_rid2sd(st);
  2851. i=pc_checkequip(sd,equip[num-1]);
  2852. if(i >= 0) {
  2853. if(log_config.refine > 0)
  2854. log_refine(sd, i, 0);
  2855. sd->status.inventory[i].refine = 0;
  2856. pc_unequipitem(sd,i,3);
  2857. // 精錬失敗エフェクトのパケット
  2858. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  2859. pc_delitem(sd,i,1,0);
  2860. // 他の人にも失敗を通知
  2861. clif_misceffect(&sd->bl,2);
  2862. }
  2863. return 0;
  2864. }
  2865. /*==========================================
  2866. *
  2867. *------------------------------------------
  2868. */
  2869. int buildin_statusup(struct script_state *st)
  2870. {
  2871. int type;
  2872. struct map_session_data *sd;
  2873. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2874. sd=script_rid2sd(st);
  2875. pc_statusup(sd,type);
  2876. return 0;
  2877. }
  2878. /*==========================================
  2879. *
  2880. *------------------------------------------
  2881. */
  2882. int buildin_statusup2(struct script_state *st)
  2883. {
  2884. int type,val;
  2885. struct map_session_data *sd;
  2886. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2887. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2888. sd=script_rid2sd(st);
  2889. pc_statusup2(sd,type,val);
  2890. return 0;
  2891. }
  2892. /*==========================================
  2893. * 装備品による能力値ボーナス
  2894. *------------------------------------------
  2895. */
  2896. int buildin_bonus(struct script_state *st)
  2897. {
  2898. int type,val;
  2899. struct map_session_data *sd;
  2900. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2901. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2902. sd=script_rid2sd(st);
  2903. pc_bonus(sd,type,val);
  2904. return 0;
  2905. }
  2906. /*==========================================
  2907. * 装備品による能力値ボーナス
  2908. *------------------------------------------
  2909. */
  2910. int buildin_bonus2(struct script_state *st)
  2911. {
  2912. int type,type2,val;
  2913. struct map_session_data *sd;
  2914. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2915. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2916. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2917. sd=script_rid2sd(st);
  2918. pc_bonus2(sd,type,type2,val);
  2919. return 0;
  2920. }
  2921. /*==========================================
  2922. * 装備品による能力値ボーナス
  2923. *------------------------------------------
  2924. */
  2925. int buildin_bonus3(struct script_state *st)
  2926. {
  2927. int type,type2,type3,val;
  2928. struct map_session_data *sd;
  2929. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2930. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2931. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2932. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2933. sd=script_rid2sd(st);
  2934. pc_bonus3(sd,type,type2,type3,val);
  2935. return 0;
  2936. }
  2937. int buildin_bonus4(struct script_state *st)
  2938. {
  2939. int type,type2,type3,type4,val;
  2940. struct map_session_data *sd;
  2941. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2942. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2943. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2944. type4=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2945. val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  2946. sd=script_rid2sd(st);
  2947. pc_bonus4(sd,type,type2,type3,type4,val);
  2948. return 0;
  2949. }
  2950. /*==========================================
  2951. * スキル所得
  2952. *------------------------------------------
  2953. */
  2954. int buildin_skill(struct script_state *st)
  2955. {
  2956. int id,level,flag=1;
  2957. struct map_session_data *sd;
  2958. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2959. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2960. if( st->end>st->start+4 )
  2961. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  2962. sd=script_rid2sd(st);
  2963. pc_skill(sd,id,level,flag);
  2964. return 0;
  2965. }
  2966. // add x levels of skill (stackable) [Valaris]
  2967. int buildin_addtoskill(struct script_state *st)
  2968. {
  2969. int id,level,flag=2;
  2970. struct map_session_data *sd;
  2971. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2972. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2973. if( st->end>st->start+4 )
  2974. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  2975. sd=script_rid2sd(st);
  2976. pc_skill(sd,id,level,flag);
  2977. return 0;
  2978. }
  2979. /*==========================================
  2980. * ギルドスキル取得
  2981. *------------------------------------------
  2982. */
  2983. int buildin_guildskill(struct script_state *st)
  2984. {
  2985. int id,level,flag=0;
  2986. struct map_session_data *sd;
  2987. int i=0;
  2988. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2989. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2990. if( st->end>st->start+4 )
  2991. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  2992. sd=script_rid2sd(st);
  2993. for(i=0;i<level;i++)
  2994. guild_skillup(sd,id,flag);
  2995. return 0;
  2996. }
  2997. /*==========================================
  2998. * スキルレベル所得
  2999. *------------------------------------------
  3000. */
  3001. int buildin_getskilllv(struct script_state *st)
  3002. {
  3003. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3004. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  3005. return 0;
  3006. }
  3007. /*==========================================
  3008. * getgdskilllv(Guild_ID, Skill_ID);
  3009. * skill_id = 10000 : GD_APPROVAL
  3010. * 10001 : GD_KAFRACONTACT
  3011. * 10002 : GD_GUARDIANRESEARCH
  3012. * 10003 : GD_GUARDUP
  3013. * 10004 : GD_EXTENSION
  3014. *------------------------------------------
  3015. */
  3016. int buildin_getgdskilllv(struct script_state *st)
  3017. {
  3018. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3019. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3020. struct guild *g=guild_search(guild_id);
  3021. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  3022. return 0;
  3023. /*
  3024. struct map_session_data *sd=NULL;
  3025. struct guild *g=NULL;
  3026. int skill_id;
  3027. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3028. sd=script_rid2sd(st);
  3029. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  3030. if(sd && g) {
  3031. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  3032. } else {
  3033. push_val(st->stack,C_INT,-1);
  3034. }
  3035. return 0;
  3036. */
  3037. }
  3038. /*==========================================
  3039. *
  3040. *------------------------------------------
  3041. */
  3042. int buildin_basicskillcheck(struct script_state *st)
  3043. {
  3044. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  3045. return 0;
  3046. }
  3047. /*==========================================
  3048. *
  3049. *------------------------------------------
  3050. */
  3051. int buildin_getgmlevel(struct script_state *st)
  3052. {
  3053. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  3054. return 0;
  3055. }
  3056. /*==========================================
  3057. *
  3058. *------------------------------------------
  3059. */
  3060. int buildin_end(struct script_state *st)
  3061. {
  3062. st->state = END;
  3063. return 0;
  3064. }
  3065. /*==========================================
  3066. *
  3067. *------------------------------------------
  3068. */
  3069. int buildin_checkoption(struct script_state *st)
  3070. {
  3071. int type;
  3072. struct map_session_data *sd;
  3073. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3074. sd=script_rid2sd(st);
  3075. if(sd->status.option & type){
  3076. push_val(st->stack,C_INT,1);
  3077. } else {
  3078. push_val(st->stack,C_INT,0);
  3079. }
  3080. return 0;
  3081. }
  3082. /*==========================================
  3083. *
  3084. *------------------------------------------
  3085. */
  3086. int buildin_checkoption1(struct script_state *st)
  3087. {
  3088. int type;
  3089. struct map_session_data *sd;
  3090. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3091. sd=script_rid2sd(st);
  3092. if(sd->opt1 & type){
  3093. push_val(st->stack,C_INT,1);
  3094. } else {
  3095. push_val(st->stack,C_INT,0);
  3096. }
  3097. return 0;
  3098. }
  3099. /*==========================================
  3100. *
  3101. *------------------------------------------
  3102. */
  3103. int buildin_checkoption2(struct script_state *st)
  3104. {
  3105. int type;
  3106. struct map_session_data *sd;
  3107. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3108. sd=script_rid2sd(st);
  3109. if(sd->opt2 & type){
  3110. push_val(st->stack,C_INT,1);
  3111. } else {
  3112. push_val(st->stack,C_INT,0);
  3113. }
  3114. return 0;
  3115. }
  3116. /*==========================================
  3117. *
  3118. *------------------------------------------
  3119. */
  3120. int buildin_setoption(struct script_state *st)
  3121. {
  3122. int type;
  3123. struct map_session_data *sd;
  3124. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3125. sd=script_rid2sd(st);
  3126. pc_setoption(sd,type);
  3127. return 0;
  3128. }
  3129. /*==========================================
  3130. * Checkcart [Valaris]
  3131. *------------------------------------------
  3132. */
  3133. int buildin_checkcart(struct script_state *st)
  3134. {
  3135. struct map_session_data *sd;
  3136. sd=script_rid2sd(st);
  3137. if(pc_iscarton(sd)){
  3138. push_val(st->stack,C_INT,1);
  3139. } else {
  3140. push_val(st->stack,C_INT,0);
  3141. }
  3142. return 0;
  3143. }
  3144. /*==========================================
  3145. * カートを付ける
  3146. *------------------------------------------
  3147. */
  3148. int buildin_setcart(struct script_state *st)
  3149. {
  3150. struct map_session_data *sd;
  3151. sd=script_rid2sd(st);
  3152. pc_setcart(sd,1);
  3153. return 0;
  3154. }
  3155. /*==========================================
  3156. * checkfalcon [Valaris]
  3157. *------------------------------------------
  3158. */
  3159. int buildin_checkfalcon(struct script_state *st)
  3160. {
  3161. struct map_session_data *sd;
  3162. sd=script_rid2sd(st);
  3163. if(pc_isfalcon(sd)){
  3164. push_val(st->stack,C_INT,1);
  3165. } else {
  3166. push_val(st->stack,C_INT,0);
  3167. }
  3168. return 0;
  3169. }
  3170. /*==========================================
  3171. * 鷹を付ける
  3172. *------------------------------------------
  3173. */
  3174. int buildin_setfalcon(struct script_state *st)
  3175. {
  3176. struct map_session_data *sd;
  3177. sd=script_rid2sd(st);
  3178. pc_setfalcon(sd);
  3179. return 0;
  3180. }
  3181. /*==========================================
  3182. * Checkcart [Valaris]
  3183. *------------------------------------------
  3184. */
  3185. int buildin_checkriding(struct script_state *st)
  3186. {
  3187. struct map_session_data *sd;
  3188. sd=script_rid2sd(st);
  3189. if(pc_isriding(sd)){
  3190. push_val(st->stack,C_INT,1);
  3191. } else {
  3192. push_val(st->stack,C_INT,0);
  3193. }
  3194. return 0;
  3195. }
  3196. /*==========================================
  3197. * ペコペコ乗り
  3198. *------------------------------------------
  3199. */
  3200. int buildin_setriding(struct script_state *st)
  3201. {
  3202. struct map_session_data *sd;
  3203. sd=script_rid2sd(st);
  3204. pc_setriding(sd);
  3205. return 0;
  3206. }
  3207. /*==========================================
  3208. * セーブポイントの保存
  3209. *------------------------------------------
  3210. */
  3211. int buildin_savepoint(struct script_state *st)
  3212. {
  3213. int x,y;
  3214. char *str;
  3215. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3216. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3217. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3218. pc_setsavepoint(script_rid2sd(st),str,x,y);
  3219. return 0;
  3220. }
  3221. /*==========================================
  3222. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  3223. *------------------------------------------
  3224. */
  3225. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  3226. {
  3227. int type;
  3228. time_t timer;
  3229. struct tm *t;
  3230. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3231. switch(type){
  3232. case 1:
  3233. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  3234. time(&timer);
  3235. t=localtime(&timer);
  3236. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  3237. break;
  3238. case 0:
  3239. default:
  3240. //type 0:(System Ticks)
  3241. push_val(st->stack,C_INT,gettick());
  3242. break;
  3243. }
  3244. return 0;
  3245. }
  3246. /*==========================================
  3247. * GetTime(Type);
  3248. * 1: Sec 2: Min 3: Hour
  3249. * 4: WeekDay 5: MonthDay 6: Month
  3250. * 7: Year
  3251. *------------------------------------------
  3252. */
  3253. int buildin_gettime(struct script_state *st) /* Asgard Version */
  3254. {
  3255. int type;
  3256. time_t timer;
  3257. struct tm *t;
  3258. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3259. time(&timer);
  3260. t=localtime(&timer);
  3261. switch(type){
  3262. case 1://Sec(0~59)
  3263. push_val(st->stack,C_INT,t->tm_sec);
  3264. break;
  3265. case 2://Min(0~59)
  3266. push_val(st->stack,C_INT,t->tm_min);
  3267. break;
  3268. case 3://Hour(0~23)
  3269. push_val(st->stack,C_INT,t->tm_hour);
  3270. break;
  3271. case 4://WeekDay(0~6)
  3272. push_val(st->stack,C_INT,t->tm_wday);
  3273. break;
  3274. case 5://MonthDay(01~31)
  3275. push_val(st->stack,C_INT,t->tm_mday);
  3276. break;
  3277. case 6://Month(01~12)
  3278. push_val(st->stack,C_INT,t->tm_mon+1);
  3279. break;
  3280. case 7://Year(20xx)
  3281. push_val(st->stack,C_INT,t->tm_year+1900);
  3282. break;
  3283. default://(format error)
  3284. push_val(st->stack,C_INT,-1);
  3285. break;
  3286. }
  3287. return 0;
  3288. }
  3289. /*==========================================
  3290. * GetTimeStr("TimeFMT", Length);
  3291. *------------------------------------------
  3292. */
  3293. int buildin_gettimestr(struct script_state *st)
  3294. {
  3295. char *tmpstr;
  3296. char *fmtstr;
  3297. int maxlen;
  3298. time_t now = time(NULL);
  3299. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3300. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3301. tmpstr=(char *)aCallocA(maxlen+1,sizeof(char));
  3302. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  3303. tmpstr[maxlen]='\0';
  3304. push_str(st->stack,C_STR,tmpstr);
  3305. return 0;
  3306. }
  3307. /*==========================================
  3308. * カプラ倉庫を開く
  3309. *------------------------------------------
  3310. */
  3311. int buildin_openstorage(struct script_state *st)
  3312. {
  3313. storage_storageopen(script_rid2sd(st));
  3314. return 0;
  3315. }
  3316. int buildin_guildopenstorage(struct script_state *st)
  3317. {
  3318. struct map_session_data *sd=script_rid2sd(st);
  3319. int ret;
  3320. ret = storage_guild_storageopen(sd);
  3321. push_val(st->stack,C_INT,ret);
  3322. return 0;
  3323. }
  3324. /*==========================================
  3325. * アイテムによるスキル発動
  3326. *------------------------------------------
  3327. */
  3328. int buildin_itemskill(struct script_state *st)
  3329. {
  3330. int id,lv;
  3331. char *str;
  3332. struct map_session_data *sd=script_rid2sd(st);
  3333. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3334. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3335. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  3336. // 詠唱中にスキルアイテムは使用できない
  3337. if(sd->skilltimer != -1)
  3338. return 0;
  3339. sd->skillitem=id;
  3340. sd->skillitemlv=lv;
  3341. clif_item_skill(sd,id,lv,str);
  3342. return 0;
  3343. }
  3344. /*==========================================
  3345. * アイテム作成
  3346. *------------------------------------------
  3347. */
  3348. int buildin_produce(struct script_state *st)
  3349. {
  3350. int trigger;
  3351. struct map_session_data *sd=script_rid2sd(st);
  3352. if( sd->state.produce_flag == 1) return 0;
  3353. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3354. clif_skill_produce_mix_list(sd,trigger);
  3355. return 0;
  3356. }
  3357. /*==========================================
  3358. * NPCでペット作る
  3359. *------------------------------------------
  3360. */
  3361. int buildin_makepet(struct script_state *st)
  3362. {
  3363. struct map_session_data *sd = script_rid2sd(st);
  3364. struct script_data *data;
  3365. int id,pet_id;
  3366. data=&(st->stack->stack_data[st->start+2]);
  3367. get_val(st,data);
  3368. id=conv_num(st,data);
  3369. pet_id = search_petDB_index(id, PET_CLASS);
  3370. if (pet_id < 0)
  3371. pet_id = search_petDB_index(id, PET_EGG);
  3372. if (pet_id >= 0 && sd) {
  3373. sd->catch_target_class = pet_db[pet_id].class_;
  3374. intif_create_pet(
  3375. sd->status.account_id, sd->status.char_id,
  3376. (short)pet_db[pet_id].class_, (short)mob_db[pet_db[pet_id].class_].lv,
  3377. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  3378. 100, 0, 1, pet_db[pet_id].jname);
  3379. }
  3380. return 0;
  3381. }
  3382. /*==========================================
  3383. * NPCで経験値上げる
  3384. *------------------------------------------
  3385. */
  3386. int buildin_getexp(struct script_state *st)
  3387. {
  3388. struct map_session_data *sd = script_rid2sd(st);
  3389. int base=0,job=0;
  3390. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3391. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  3392. if(base<0 || job<0)
  3393. return 0;
  3394. if(sd)
  3395. pc_gainexp(sd,base,job);
  3396. return 0;
  3397. }
  3398. /*==========================================
  3399. * Gain guild exp [Celest]
  3400. *------------------------------------------
  3401. */
  3402. int buildin_guildgetexp(struct script_state *st)
  3403. {
  3404. struct map_session_data *sd = script_rid2sd(st);
  3405. int exp;
  3406. exp = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3407. if(exp < 0)
  3408. return 0;
  3409. if(sd && sd->status.guild_id > 0)
  3410. guild_getexp (sd, exp);
  3411. return 0;
  3412. }
  3413. /*==========================================
  3414. * モンスター発生
  3415. *------------------------------------------
  3416. */
  3417. int buildin_monster(struct script_state *st)
  3418. {
  3419. int class_,amount,x,y;
  3420. char *str,*map,*event="";
  3421. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  3422. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  3423. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  3424. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  3425. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3426. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  3427. if( st->end>st->start+8 )
  3428. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  3429. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
  3430. return 0;
  3431. }
  3432. /*==========================================
  3433. * モンスター発生
  3434. *------------------------------------------
  3435. */
  3436. int buildin_areamonster(struct script_state *st)
  3437. {
  3438. int class_,amount,x0,y0,x1,y1;
  3439. char *str,*map,*event="";
  3440. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  3441. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  3442. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  3443. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  3444. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  3445. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  3446. class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3447. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3448. if( st->end>st->start+10 )
  3449. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  3450. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
  3451. return 0;
  3452. }
  3453. /*==========================================
  3454. * モンスター削除
  3455. *------------------------------------------
  3456. */
  3457. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  3458. {
  3459. char *event=va_arg(ap,char *);
  3460. int allflag=va_arg(ap,int);
  3461. if(!allflag){
  3462. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  3463. mob_delete((struct mob_data *)bl);
  3464. return 0;
  3465. }else if(allflag){
  3466. if(((struct mob_data *)bl)->spawndelay1==-1 && ((struct mob_data *)bl)->spawndelay2==-1)
  3467. mob_delete((struct mob_data *)bl);
  3468. return 0;
  3469. }
  3470. return 0;
  3471. }
  3472. int buildin_killmonster(struct script_state *st)
  3473. {
  3474. char *mapname,*event;
  3475. int m,allflag=0;
  3476. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3477. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  3478. if(strcmp(event,"All")==0)
  3479. allflag = 1;
  3480. if( (m=map_mapname2mapid(mapname))<0 )
  3481. return 0;
  3482. map_foreachinarea(buildin_killmonster_sub,
  3483. m,0,0,map[m].xs,map[m].ys,BL_MOB, event ,allflag);
  3484. return 0;
  3485. }
  3486. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  3487. {
  3488. mob_delete((struct mob_data *)bl);
  3489. return 0;
  3490. }
  3491. int buildin_killmonsterall(struct script_state *st)
  3492. {
  3493. char *mapname;
  3494. int m;
  3495. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3496. if( (m=map_mapname2mapid(mapname))<0 )
  3497. return 0;
  3498. map_foreachinarea(buildin_killmonsterall_sub,
  3499. m,0,0,map[m].xs,map[m].ys,BL_MOB);
  3500. return 0;
  3501. }
  3502. /*==========================================
  3503. * イベント実行
  3504. *------------------------------------------
  3505. */
  3506. int buildin_doevent(struct script_state *st)
  3507. {
  3508. char *event;
  3509. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3510. npc_event(map_id2sd(st->rid),event,0);
  3511. return 0;
  3512. }
  3513. /*==========================================
  3514. * NPC主体イベント実行
  3515. *------------------------------------------
  3516. */
  3517. int buildin_donpcevent(struct script_state *st)
  3518. {
  3519. char *event;
  3520. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3521. npc_event_do(event);
  3522. return 0;
  3523. }
  3524. /*==========================================
  3525. * イベントタイマー追加
  3526. *------------------------------------------
  3527. */
  3528. int buildin_addtimer(struct script_state *st)
  3529. {
  3530. char *event;
  3531. int tick;
  3532. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3533. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  3534. pc_addeventtimer(script_rid2sd(st),tick,event);
  3535. return 0;
  3536. }
  3537. /*==========================================
  3538. * イベントタイマー削除
  3539. *------------------------------------------
  3540. */
  3541. int buildin_deltimer(struct script_state *st)
  3542. {
  3543. char *event;
  3544. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3545. pc_deleventtimer(script_rid2sd(st),event);
  3546. return 0;
  3547. }
  3548. /*==========================================
  3549. * イベントタイマーのカウント値追加
  3550. *------------------------------------------
  3551. */
  3552. int buildin_addtimercount(struct script_state *st)
  3553. {
  3554. char *event;
  3555. int tick;
  3556. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3557. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3558. pc_addeventtimercount(script_rid2sd(st),event,tick);
  3559. return 0;
  3560. }
  3561. /*==========================================
  3562. * NPCタイマー初期化
  3563. *------------------------------------------
  3564. */
  3565. int buildin_initnpctimer(struct script_state *st)
  3566. {
  3567. struct npc_data *nd;
  3568. if( st->end > st->start+2 )
  3569. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3570. else
  3571. nd=(struct npc_data *)map_id2bl(st->oid);
  3572. npc_settimerevent_tick(nd,0);
  3573. npc_timerevent_start(nd, st->rid);
  3574. return 0;
  3575. }
  3576. /*==========================================
  3577. * NPCタイマー開始
  3578. *------------------------------------------
  3579. */
  3580. int buildin_startnpctimer(struct script_state *st)
  3581. {
  3582. struct npc_data *nd;
  3583. if( st->end > st->start+2 )
  3584. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3585. else
  3586. nd=(struct npc_data *)map_id2bl(st->oid);
  3587. npc_timerevent_start(nd, st->rid);
  3588. return 0;
  3589. }
  3590. /*==========================================
  3591. * NPCタイマー停止
  3592. *------------------------------------------
  3593. */
  3594. int buildin_stopnpctimer(struct script_state *st)
  3595. {
  3596. struct npc_data *nd;
  3597. if( st->end > st->start+2 )
  3598. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3599. else
  3600. nd=(struct npc_data *)map_id2bl(st->oid);
  3601. npc_timerevent_stop(nd);
  3602. return 0;
  3603. }
  3604. /*==========================================
  3605. * NPCタイマー情報所得
  3606. *------------------------------------------
  3607. */
  3608. int buildin_getnpctimer(struct script_state *st)
  3609. {
  3610. struct npc_data *nd;
  3611. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3612. int val=0;
  3613. if( st->end > st->start+3 )
  3614. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  3615. else
  3616. nd=(struct npc_data *)map_id2bl(st->oid);
  3617. switch(type){
  3618. case 0: val=npc_gettimerevent_tick(nd); break;
  3619. case 1: val= (nd->u.scr.nexttimer>=0); break;
  3620. case 2: val= nd->u.scr.timeramount; break;
  3621. }
  3622. push_val(st->stack,C_INT,val);
  3623. return 0;
  3624. }
  3625. /*==========================================
  3626. * NPCタイマー値設定
  3627. *------------------------------------------
  3628. */
  3629. int buildin_setnpctimer(struct script_state *st)
  3630. {
  3631. int tick;
  3632. struct npc_data *nd;
  3633. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3634. if( st->end > st->start+3 )
  3635. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  3636. else
  3637. nd=(struct npc_data *)map_id2bl(st->oid);
  3638. npc_settimerevent_tick(nd,tick);
  3639. return 0;
  3640. }
  3641. /*==========================================
  3642. * attaches the player rid to the timer [Celest]
  3643. *------------------------------------------
  3644. */
  3645. int buildin_attachnpctimer(struct script_state *st)
  3646. {
  3647. struct map_session_data *sd;
  3648. struct npc_data *nd;
  3649. nd=(struct npc_data *)map_id2bl(st->oid);
  3650. if( st->end > st->start+2 ) {
  3651. char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  3652. sd=map_nick2sd(name);
  3653. } else {
  3654. sd = script_rid2sd(st);
  3655. }
  3656. if (sd==NULL)
  3657. return 0;
  3658. nd->u.scr.rid = sd->bl.id;
  3659. return 0;
  3660. }
  3661. /*==========================================
  3662. * detaches a player rid from the timer [Celest]
  3663. *------------------------------------------
  3664. */
  3665. int buildin_detachnpctimer(struct script_state *st)
  3666. {
  3667. struct npc_data *nd;
  3668. if( st->end > st->start+2 )
  3669. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3670. else
  3671. nd=(struct npc_data *)map_id2bl(st->oid);
  3672. nd->u.scr.rid = 0;
  3673. return 0;
  3674. }
  3675. /*==========================================
  3676. * 天の声アナウンス
  3677. *------------------------------------------
  3678. */
  3679. int buildin_announce(struct script_state *st)
  3680. {
  3681. char *str;
  3682. int flag;
  3683. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3684. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3685. if(flag&0x0f){
  3686. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  3687. (struct block_list *)script_rid2sd(st);
  3688. clif_GMmessage(bl,str,strlen(str)+1,flag);
  3689. }else
  3690. intif_GMmessage(str,strlen(str)+1,flag);
  3691. return 0;
  3692. }
  3693. /*==========================================
  3694. * 天の声アナウンス(特定マップ)
  3695. *------------------------------------------
  3696. */
  3697. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  3698. {
  3699. char *str;
  3700. int len,flag;
  3701. str=va_arg(ap,char *);
  3702. len=va_arg(ap,int);
  3703. flag=va_arg(ap,int);
  3704. clif_GMmessage(bl,str,len,flag|3);
  3705. return 0;
  3706. }
  3707. int buildin_mapannounce(struct script_state *st)
  3708. {
  3709. char *mapname,*str;
  3710. int flag,m;
  3711. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3712. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  3713. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3714. if( (m=map_mapname2mapid(mapname))<0 )
  3715. return 0;
  3716. map_foreachinarea(buildin_mapannounce_sub,
  3717. m,0,0,map[m].xs,map[m].ys,BL_PC, str,strlen(str)+1,flag&0x10);
  3718. return 0;
  3719. }
  3720. /*==========================================
  3721. * 天の声アナウンス(特定エリア)
  3722. *------------------------------------------
  3723. */
  3724. int buildin_areaannounce(struct script_state *st)
  3725. {
  3726. char *map,*str;
  3727. int flag,m;
  3728. int x0,y0,x1,y1;
  3729. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3730. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3731. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3732. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3733. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3734. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  3735. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3736. if( (m=map_mapname2mapid(map))<0 )
  3737. return 0;
  3738. map_foreachinarea(buildin_mapannounce_sub,
  3739. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10 );
  3740. return 0;
  3741. }
  3742. /*==========================================
  3743. * ユーザー数所得
  3744. *------------------------------------------
  3745. */
  3746. int buildin_getusers(struct script_state *st)
  3747. {
  3748. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3749. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  3750. int val=0;
  3751. switch(flag&0x07){
  3752. case 0: val=map[bl->m].users; break;
  3753. case 1: val=map_getusers(); break;
  3754. }
  3755. push_val(st->stack,C_INT,val);
  3756. return 0;
  3757. }
  3758. /*==========================================
  3759. * Works like @WHO - displays all online users names in window
  3760. *------------------------------------------
  3761. */
  3762. int buildin_getusersname(struct script_state *st)
  3763. {
  3764. struct map_session_data *pl_sd = NULL;
  3765. int i=0,disp_num=1;
  3766. for (i=0;i<fd_max;i++)
  3767. if(session[i] && (pl_sd=session[i]->session_data) && pl_sd->state.auth){
  3768. if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) ){
  3769. if((disp_num++)%10==0)
  3770. clif_scriptnext(script_rid2sd(st),st->oid);
  3771. clif_scriptmes(script_rid2sd(st),st->oid,pl_sd->status.name);
  3772. }
  3773. }
  3774. return 0;
  3775. }
  3776. /*==========================================
  3777. * マップ指定ユーザー数所得
  3778. *------------------------------------------
  3779. */
  3780. int buildin_getmapusers(struct script_state *st)
  3781. {
  3782. char *str;
  3783. int m;
  3784. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3785. if( (m=map_mapname2mapid(str))< 0){
  3786. push_val(st->stack,C_INT,-1);
  3787. return 0;
  3788. }
  3789. push_val(st->stack,C_INT,map[m].users);
  3790. return 0;
  3791. }
  3792. /*==========================================
  3793. * エリア指定ユーザー数所得
  3794. *------------------------------------------
  3795. */
  3796. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  3797. {
  3798. int *users=va_arg(ap,int *);
  3799. (*users)++;
  3800. return 0;
  3801. }
  3802. int buildin_getareausers(struct script_state *st)
  3803. {
  3804. char *str;
  3805. int m,x0,y0,x1,y1,users=0;
  3806. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3807. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3808. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3809. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3810. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3811. if( (m=map_mapname2mapid(str))< 0){
  3812. push_val(st->stack,C_INT,-1);
  3813. return 0;
  3814. }
  3815. map_foreachinarea(buildin_getareausers_sub,
  3816. m,x0,y0,x1,y1,BL_PC,&users);
  3817. push_val(st->stack,C_INT,users);
  3818. return 0;
  3819. }
  3820. /*==========================================
  3821. * エリア指定ドロップアイテム数所得
  3822. *------------------------------------------
  3823. */
  3824. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  3825. {
  3826. int item=va_arg(ap,int);
  3827. int *amount=va_arg(ap,int *);
  3828. struct flooritem_data *drop=(struct flooritem_data *)bl;
  3829. if(drop->item_data.nameid==item)
  3830. (*amount)+=drop->item_data.amount;
  3831. return 0;
  3832. }
  3833. int buildin_getareadropitem(struct script_state *st)
  3834. {
  3835. char *str;
  3836. int m,x0,y0,x1,y1,item,amount=0;
  3837. struct script_data *data;
  3838. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3839. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3840. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3841. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3842. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3843. data=&(st->stack->stack_data[st->start+7]);
  3844. get_val(st,data);
  3845. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3846. const char *name=conv_str(st,data);
  3847. struct item_data *item_data = itemdb_searchname(name);
  3848. item=512;
  3849. if( item_data )
  3850. item=item_data->nameid;
  3851. }else
  3852. item=conv_num(st,data);
  3853. if( (m=map_mapname2mapid(str))< 0){
  3854. push_val(st->stack,C_INT,-1);
  3855. return 0;
  3856. }
  3857. map_foreachinarea(buildin_getareadropitem_sub,
  3858. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  3859. push_val(st->stack,C_INT,amount);
  3860. return 0;
  3861. }
  3862. /*==========================================
  3863. * NPCの有効化
  3864. *------------------------------------------
  3865. */
  3866. int buildin_enablenpc(struct script_state *st)
  3867. {
  3868. char *str;
  3869. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3870. npc_enable(str,1);
  3871. return 0;
  3872. }
  3873. /*==========================================
  3874. * NPCの無効化
  3875. *------------------------------------------
  3876. */
  3877. int buildin_disablenpc(struct script_state *st)
  3878. {
  3879. char *str;
  3880. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3881. npc_enable(str,0);
  3882. return 0;
  3883. }
  3884. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  3885. {
  3886. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  3887. struct chat_data *cd;
  3888. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  3889. return 0;
  3890. npc_enable(nd->name,1);
  3891. nd->arenaflag=1;
  3892. if(cd->users>=cd->trigger && cd->npc_event[0])
  3893. npc_timer_event(cd->npc_event);
  3894. return 0;
  3895. }
  3896. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  3897. {
  3898. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  3899. nd->arenaflag=0;
  3900. return 0;
  3901. }
  3902. /*==========================================
  3903. * 隠れているNPCの表示
  3904. *------------------------------------------
  3905. */
  3906. int buildin_hideoffnpc(struct script_state *st)
  3907. {
  3908. char *str;
  3909. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3910. npc_enable(str,2);
  3911. return 0;
  3912. }
  3913. /*==========================================
  3914. * NPCをハイディング
  3915. *------------------------------------------
  3916. */
  3917. int buildin_hideonnpc(struct script_state *st)
  3918. {
  3919. char *str;
  3920. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3921. npc_enable(str,4);
  3922. return 0;
  3923. }
  3924. /*==========================================
  3925. * 状態異常にかかる
  3926. *------------------------------------------
  3927. */
  3928. int buildin_sc_start(struct script_state *st)
  3929. {
  3930. struct block_list *bl;
  3931. int type,tick,val1;
  3932. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3933. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3934. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3935. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  3936. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  3937. else
  3938. bl = map_id2bl(st->rid);
  3939. if (bl != 0) {
  3940. if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag)
  3941. bl = map_id2bl(((struct map_session_data *)bl)->skilltarget);
  3942. status_change_start(bl,type,val1,0,0,0,tick,0);
  3943. }
  3944. return 0;
  3945. }
  3946. /*==========================================
  3947. * 状態異常にかかる(確率指定)
  3948. *------------------------------------------
  3949. */
  3950. int buildin_sc_start2(struct script_state *st)
  3951. {
  3952. struct block_list *bl;
  3953. int type,tick,val1,per;
  3954. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3955. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3956. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3957. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3958. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  3959. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  3960. else
  3961. bl = map_id2bl(st->rid);
  3962. if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag)
  3963. bl = map_id2bl(((struct map_session_data *)bl)->skilltarget);
  3964. if(rand()%10000 < per)
  3965. status_change_start(bl,type,val1,0,0,0,tick,0);
  3966. return 0;
  3967. }
  3968. /*==========================================
  3969. * 状態異常が直る
  3970. *------------------------------------------
  3971. */
  3972. int buildin_sc_end(struct script_state *st)
  3973. {
  3974. struct block_list *bl;
  3975. int type;
  3976. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3977. bl = map_id2bl(st->rid);
  3978. if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag)
  3979. bl = map_id2bl(((struct map_session_data *)bl)->skilltarget);
  3980. status_change_end(bl,type,-1);
  3981. // if(battle_config.etc_log)
  3982. // printf("sc_end : %d %d\n",st->rid,type);
  3983. return 0;
  3984. }
  3985. /*==========================================
  3986. * 状態異常耐性を計算した確率を返す
  3987. *------------------------------------------
  3988. */
  3989. int buildin_getscrate(struct script_state *st)
  3990. {
  3991. struct block_list *bl;
  3992. int sc_def,type,rate;
  3993. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3994. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3995. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  3996. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  3997. else
  3998. bl = map_id2bl(st->rid);
  3999. sc_def = status_get_sc_def(bl,type);
  4000. rate = rate * sc_def / 100;
  4001. push_val(st->stack,C_INT,rate);
  4002. return 0;
  4003. }
  4004. /*==========================================
  4005. *
  4006. *------------------------------------------
  4007. */
  4008. int buildin_debugmes(struct script_state *st)
  4009. {
  4010. conv_str(st,& (st->stack->stack_data[st->start+2]));
  4011. printf("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  4012. return 0;
  4013. }
  4014. /*==========================================
  4015. *捕獲アイテム使用
  4016. *------------------------------------------
  4017. */
  4018. int buildin_catchpet(struct script_state *st)
  4019. {
  4020. int pet_id;
  4021. struct map_session_data *sd;
  4022. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  4023. sd=script_rid2sd(st);
  4024. pet_catch_process1(sd,pet_id);
  4025. return 0;
  4026. }
  4027. /*==========================================
  4028. *携帯卵孵化機使用
  4029. *------------------------------------------
  4030. */
  4031. int buildin_birthpet(struct script_state *st)
  4032. {
  4033. struct map_session_data *sd;
  4034. sd=script_rid2sd(st);
  4035. clif_sendegg(sd);
  4036. return 0;
  4037. }
  4038. /*==========================================
  4039. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  4040. *------------------------------------------
  4041. */
  4042. int buildin_resetlvl(struct script_state *st)
  4043. {
  4044. struct map_session_data *sd;
  4045. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4046. sd=script_rid2sd(st);
  4047. pc_resetlvl(sd,type);
  4048. return 0;
  4049. }
  4050. /*==========================================
  4051. * ステータスリセット
  4052. *------------------------------------------
  4053. */
  4054. int buildin_resetstatus(struct script_state *st)
  4055. {
  4056. struct map_session_data *sd;
  4057. sd=script_rid2sd(st);
  4058. pc_resetstate(sd);
  4059. return 0;
  4060. }
  4061. /*==========================================
  4062. * スキルリセット
  4063. *------------------------------------------
  4064. */
  4065. int buildin_resetskill(struct script_state *st)
  4066. {
  4067. struct map_session_data *sd;
  4068. sd=script_rid2sd(st);
  4069. pc_resetskill(sd);
  4070. return 0;
  4071. }
  4072. /*==========================================
  4073. *
  4074. *------------------------------------------
  4075. */
  4076. int buildin_changebase(struct script_state *st)
  4077. {
  4078. struct map_session_data *sd=NULL;
  4079. int vclass;
  4080. if( st->end>st->start+3 )
  4081. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  4082. else
  4083. sd=script_rid2sd(st);
  4084. if(sd == NULL)
  4085. return 0;
  4086. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  4087. if(vclass == 22 && !battle_config.wedding_modifydisplay)
  4088. return 0;
  4089. // if(vclass==22) {
  4090. // pc_unequipitem(sd,sd->equip_index[9],0); // 装備外
  4091. // }
  4092. sd->view_class = vclass;
  4093. return 0;
  4094. }
  4095. /*==========================================
  4096. * 性別変換
  4097. *------------------------------------------
  4098. */
  4099. int buildin_changesex(struct script_state *st) {
  4100. struct map_session_data *sd = NULL;
  4101. sd = script_rid2sd(st);
  4102. if (sd->status.sex == 0) {
  4103. sd->status.sex = 1;
  4104. sd->sex = 1;
  4105. if (sd->status.class_ == 20 || sd->status.class_ == 4021)
  4106. sd->status.class_ -= 1;
  4107. } else if (sd->status.sex == 1) {
  4108. sd->status.sex = 0;
  4109. sd->sex = 0;
  4110. if(sd->status.class_ == 19 || sd->status.class_ == 4020)
  4111. sd->status.class_ += 1;
  4112. }
  4113. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  4114. chrif_save(sd);
  4115. return 0;
  4116. }
  4117. /*==========================================
  4118. * npcチャット作成
  4119. *------------------------------------------
  4120. */
  4121. int buildin_waitingroom(struct script_state *st)
  4122. {
  4123. char *name,*ev="";
  4124. int limit, trigger = 0,pub=1;
  4125. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4126. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  4127. if(limit==0)
  4128. pub=3;
  4129. if( (st->end > st->start+5) ){
  4130. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  4131. get_val(st,data);
  4132. if(data->type==C_INT){
  4133. // 新Athena仕様(旧Athena仕様と互換性あり)
  4134. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  4135. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4136. }else{
  4137. // eathena仕様
  4138. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4139. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  4140. }
  4141. }else{
  4142. // 旧Athena仕様
  4143. if( st->end > st->start+4 )
  4144. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  4145. }
  4146. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  4147. limit,pub,trigger,name,strlen(name)+1,ev);
  4148. return 0;
  4149. }
  4150. /*==========================================
  4151. * Works like 'announce' but outputs in the common chat window
  4152. *------------------------------------------
  4153. */
  4154. int buildin_globalmes(struct script_state *st)
  4155. {
  4156. struct block_list *bl = map_id2bl(st->oid);
  4157. struct npc_data *nd = (struct npc_data *)bl;
  4158. char *name=NULL,*mes;
  4159. mes=conv_str(st,& (st->stack->stack_data[st->start+2])); // メッセージの取得
  4160. if(mes==NULL) return 0;
  4161. if(st->end>st->start+3){ // NPC名の取得(123#456)
  4162. name=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4163. } else {
  4164. name=nd->name;
  4165. }
  4166. npc_globalmessage(name,mes); // グローバルメッセージ送信
  4167. return 0;
  4168. }
  4169. /*==========================================
  4170. * npcチャット削除
  4171. *------------------------------------------
  4172. */
  4173. int buildin_delwaitingroom(struct script_state *st)
  4174. {
  4175. struct npc_data *nd;
  4176. if( st->end > st->start+2 )
  4177. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  4178. else
  4179. nd=(struct npc_data *)map_id2bl(st->oid);
  4180. chat_deletenpcchat(nd);
  4181. return 0;
  4182. }
  4183. /*==========================================
  4184. * npcチャット全員蹴り出す
  4185. *------------------------------------------
  4186. */
  4187. int buildin_waitingroomkickall(struct script_state *st)
  4188. {
  4189. struct npc_data *nd;
  4190. struct chat_data *cd;
  4191. if( st->end > st->start+2 )
  4192. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  4193. else
  4194. nd=(struct npc_data *)map_id2bl(st->oid);
  4195. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  4196. return 0;
  4197. chat_npckickall(cd);
  4198. return 0;
  4199. }
  4200. /*==========================================
  4201. * npcチャットイベント有効化
  4202. *------------------------------------------
  4203. */
  4204. int buildin_enablewaitingroomevent(struct script_state *st)
  4205. {
  4206. struct npc_data *nd;
  4207. struct chat_data *cd;
  4208. if( st->end > st->start+2 )
  4209. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  4210. else
  4211. nd=(struct npc_data *)map_id2bl(st->oid);
  4212. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  4213. return 0;
  4214. chat_enableevent(cd);
  4215. return 0;
  4216. }
  4217. /*==========================================
  4218. * npcチャットイベント無効化
  4219. *------------------------------------------
  4220. */
  4221. int buildin_disablewaitingroomevent(struct script_state *st)
  4222. {
  4223. struct npc_data *nd;
  4224. struct chat_data *cd;
  4225. if( st->end > st->start+2 )
  4226. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  4227. else
  4228. nd=(struct npc_data *)map_id2bl(st->oid);
  4229. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  4230. return 0;
  4231. chat_disableevent(cd);
  4232. return 0;
  4233. }
  4234. /*==========================================
  4235. * npcチャット状態所得
  4236. *------------------------------------------
  4237. */
  4238. int buildin_getwaitingroomstate(struct script_state *st)
  4239. {
  4240. struct npc_data *nd;
  4241. struct chat_data *cd;
  4242. int val=0,type;
  4243. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4244. if( st->end > st->start+3 )
  4245. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  4246. else
  4247. nd=(struct npc_data *)map_id2bl(st->oid);
  4248. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  4249. push_val(st->stack,C_INT,-1);
  4250. return 0;
  4251. }
  4252. switch(type){
  4253. case 0: val=cd->users; break;
  4254. case 1: val=cd->limit; break;
  4255. case 2: val=cd->trigger&0x7f; break;
  4256. case 3: val=((cd->trigger&0x80)>0); break;
  4257. case 32: val=(cd->users >= cd->limit); break;
  4258. case 33: val=(cd->users >= cd->trigger); break;
  4259. case 4:
  4260. push_str(st->stack,C_CONSTSTR,cd->title);
  4261. return 0;
  4262. case 5:
  4263. push_str(st->stack,C_CONSTSTR,cd->pass);
  4264. return 0;
  4265. case 16:
  4266. push_str(st->stack,C_CONSTSTR,cd->npc_event);
  4267. return 0;
  4268. }
  4269. push_val(st->stack,C_INT,val);
  4270. return 0;
  4271. }
  4272. /*==========================================
  4273. * チャットメンバー(規定人数)ワープ
  4274. *------------------------------------------
  4275. */
  4276. int buildin_warpwaitingpc(struct script_state *st)
  4277. {
  4278. int x,y,i,n;
  4279. char *str;
  4280. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  4281. struct chat_data *cd;
  4282. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  4283. return 0;
  4284. n=cd->trigger&0x7f;
  4285. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4286. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4287. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4288. if( st->end > st->start+5 )
  4289. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4290. for(i=0;i<n;i++){
  4291. struct map_session_data *sd=cd->usersd[0]; // リスト先頭のPCを次々に。
  4292. mapreg_setreg(add_str("$@warpwaitingpc")+(i<<24),sd->bl.id);
  4293. if(strcmp(str,"Random")==0)
  4294. pc_randomwarp(sd,3);
  4295. else if(strcmp(str,"SavePoint")==0){
  4296. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  4297. return 0;
  4298. pc_setpos(sd,sd->status.save_point.map,
  4299. sd->status.save_point.x,sd->status.save_point.y,3);
  4300. }else
  4301. pc_setpos(sd,str,x,y,0);
  4302. }
  4303. mapreg_setreg(add_str("$@warpwaitingpcnum"),n);
  4304. return 0;
  4305. }
  4306. /*==========================================
  4307. * RIDのアタッチ
  4308. *------------------------------------------
  4309. */
  4310. int buildin_attachrid(struct script_state *st)
  4311. {
  4312. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4313. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  4314. return 0;
  4315. }
  4316. /*==========================================
  4317. * RIDのデタッチ
  4318. *------------------------------------------
  4319. */
  4320. int buildin_detachrid(struct script_state *st)
  4321. {
  4322. st->rid=0;
  4323. return 0;
  4324. }
  4325. /*==========================================
  4326. * 存在チェック
  4327. *------------------------------------------
  4328. */
  4329. int buildin_isloggedin(struct script_state *st)
  4330. {
  4331. push_val(st->stack,C_INT, map_id2sd(
  4332. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  4333. return 0;
  4334. }
  4335. /*==========================================
  4336. *
  4337. *------------------------------------------
  4338. */
  4339. enum { MF_NOMEMO,MF_NOTELEPORT,MF_NOSAVE,MF_NOBRANCH,MF_NOPENALTY,MF_NOZENYPENALTY,
  4340. MF_PVP,MF_PVP_NOPARTY,MF_PVP_NOGUILD,MF_GVG,MF_GVG_NOPARTY,MF_NOTRADE,MF_NOSKILL,
  4341. MF_NOWARP,MF_NOPVP,MF_NOICEWALL,MF_SNOW,MF_FOG,MF_SAKURA,MF_LEAVES,MF_RAIN,MF_INDOORS,MF_NOGO };
  4342. int buildin_setmapflagnosave(struct script_state *st)
  4343. {
  4344. int m,x,y;
  4345. char *str,*str2;
  4346. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4347. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4348. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4349. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4350. m = map_mapname2mapid(str);
  4351. if(m >= 0) {
  4352. map[m].flag.nosave=1;
  4353. memcpy(map[m].save.map,str2,16);
  4354. map[m].save.x=x;
  4355. map[m].save.y=y;
  4356. }
  4357. return 0;
  4358. }
  4359. int buildin_setmapflag(struct script_state *st)
  4360. {
  4361. int m,i;
  4362. char *str;
  4363. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4364. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4365. m = map_mapname2mapid(str);
  4366. if(m >= 0) {
  4367. switch(i) {
  4368. case MF_NOMEMO:
  4369. map[m].flag.nomemo=1;
  4370. break;
  4371. case MF_NOTELEPORT:
  4372. map[m].flag.noteleport=1;
  4373. break;
  4374. case MF_NOBRANCH:
  4375. map[m].flag.nobranch=1;
  4376. break;
  4377. case MF_NOPENALTY:
  4378. map[m].flag.nopenalty=1;
  4379. break;
  4380. case MF_NOZENYPENALTY:
  4381. map[m].flag.nozenypenalty=1;
  4382. break;
  4383. case MF_PVP:
  4384. map[m].flag.pvp=1;
  4385. break;
  4386. case MF_PVP_NOPARTY:
  4387. map[m].flag.pvp_noparty=1;
  4388. break;
  4389. case MF_PVP_NOGUILD:
  4390. map[m].flag.pvp_noguild=1;
  4391. break;
  4392. case MF_GVG:
  4393. map[m].flag.gvg=1;
  4394. break;
  4395. case MF_GVG_NOPARTY:
  4396. map[m].flag.gvg_noparty=1;
  4397. break;
  4398. case MF_NOTRADE:
  4399. map[m].flag.notrade=1;
  4400. break;
  4401. case MF_NOSKILL:
  4402. map[m].flag.noskill=1;
  4403. break;
  4404. case MF_NOWARP:
  4405. map[m].flag.nowarp=1;
  4406. break;
  4407. case MF_NOPVP:
  4408. map[m].flag.nopvp=1;
  4409. break;
  4410. case MF_NOICEWALL: // [Valaris]
  4411. map[m].flag.noicewall=1;
  4412. break;
  4413. case MF_SNOW: // [Valaris]
  4414. map[m].flag.snow=1;
  4415. break;
  4416. case MF_FOG: // [Valaris]
  4417. map[m].flag.fog=1;
  4418. break;
  4419. case MF_SAKURA: // [Valaris]
  4420. map[m].flag.sakura=1;
  4421. break;
  4422. case MF_LEAVES: // [Valaris]
  4423. map[m].flag.leaves=1;
  4424. break;
  4425. case MF_RAIN: // [Valaris]
  4426. map[m].flag.rain=1;
  4427. break;
  4428. case MF_INDOORS: // celest
  4429. map[m].flag.indoors=1;
  4430. break;
  4431. case MF_NOGO: // celest
  4432. map[m].flag.nogo=1;
  4433. break;
  4434. }
  4435. }
  4436. return 0;
  4437. }
  4438. int buildin_removemapflag(struct script_state *st)
  4439. {
  4440. int m,i;
  4441. char *str;
  4442. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4443. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4444. m = map_mapname2mapid(str);
  4445. if(m >= 0) {
  4446. switch(i) {
  4447. case MF_NOMEMO:
  4448. map[m].flag.nomemo=0;
  4449. break;
  4450. case MF_NOTELEPORT:
  4451. map[m].flag.noteleport=0;
  4452. break;
  4453. case MF_NOSAVE:
  4454. map[m].flag.nosave=0;
  4455. break;
  4456. case MF_NOBRANCH:
  4457. map[m].flag.nobranch=0;
  4458. break;
  4459. case MF_NOPENALTY:
  4460. map[m].flag.nopenalty=0;
  4461. break;
  4462. case MF_PVP:
  4463. map[m].flag.pvp=0;
  4464. break;
  4465. case MF_PVP_NOPARTY:
  4466. map[m].flag.pvp_noparty=0;
  4467. break;
  4468. case MF_PVP_NOGUILD:
  4469. map[m].flag.pvp_noguild=0;
  4470. break;
  4471. case MF_GVG:
  4472. map[m].flag.gvg=0;
  4473. break;
  4474. case MF_GVG_NOPARTY:
  4475. map[m].flag.gvg_noparty=0;
  4476. break;
  4477. case MF_NOZENYPENALTY:
  4478. map[m].flag.nozenypenalty=0;
  4479. break;
  4480. case MF_NOSKILL:
  4481. map[m].flag.noskill=0;
  4482. break;
  4483. case MF_NOWARP:
  4484. map[m].flag.nowarp=0;
  4485. break;
  4486. case MF_NOPVP:
  4487. map[m].flag.nopvp=0;
  4488. break;
  4489. case MF_NOICEWALL: // [Valaris]
  4490. map[m].flag.noicewall=0;
  4491. break;
  4492. case MF_SNOW: // [Valaris]
  4493. map[m].flag.snow=0;
  4494. break;
  4495. case MF_FOG: // [Valaris]
  4496. map[m].flag.fog=0;
  4497. break;
  4498. case MF_SAKURA: // [Valaris]
  4499. map[m].flag.sakura=0;
  4500. break;
  4501. case MF_LEAVES: // [Valaris]
  4502. map[m].flag.leaves=0;
  4503. break;
  4504. case MF_RAIN: // [Valaris]
  4505. map[m].flag.rain=0;
  4506. break;
  4507. case MF_INDOORS: // celest
  4508. map[m].flag.indoors=0;
  4509. break;
  4510. case MF_NOGO: // celest
  4511. map[m].flag.nogo=0;
  4512. break;
  4513. }
  4514. }
  4515. return 0;
  4516. }
  4517. int buildin_pvpon(struct script_state *st)
  4518. {
  4519. int m,i;
  4520. char *str;
  4521. struct map_session_data *pl_sd=NULL;
  4522. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4523. m = map_mapname2mapid(str);
  4524. if(m >= 0 && !map[m].flag.pvp && !map[m].flag.nopvp) {
  4525. map[m].flag.pvp = 1;
  4526. clif_send0199(m,1);
  4527. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  4528. return 0;
  4529. for(i=0;i<fd_max;i++){ //人数分ループ
  4530. if(session[i] && (pl_sd=session[i]->session_data) && pl_sd->state.auth){
  4531. if(m == pl_sd->bl.m && pl_sd->pvp_timer == -1) {
  4532. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  4533. pl_sd->pvp_rank=0;
  4534. pl_sd->pvp_lastusers=0;
  4535. pl_sd->pvp_point=5;
  4536. }
  4537. }
  4538. }
  4539. }
  4540. return 0;
  4541. }
  4542. int buildin_pvpoff(struct script_state *st)
  4543. {
  4544. int m,i;
  4545. char *str;
  4546. struct map_session_data *pl_sd=NULL;
  4547. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4548. m = map_mapname2mapid(str);
  4549. if(m >= 0 && map[m].flag.pvp && map[m].flag.nopvp) {
  4550. map[m].flag.pvp = 0;
  4551. clif_send0199(m,0);
  4552. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  4553. return 0;
  4554. for(i=0;i<fd_max;i++){ //人数分ループ
  4555. if(session[i] && (pl_sd=session[i]->session_data) && pl_sd->state.auth){
  4556. if(m == pl_sd->bl.m) {
  4557. clif_pvpset(pl_sd,0,0,2);
  4558. if(pl_sd->pvp_timer != -1) {
  4559. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  4560. pl_sd->pvp_timer = -1;
  4561. }
  4562. }
  4563. }
  4564. }
  4565. }
  4566. return 0;
  4567. }
  4568. int buildin_gvgon(struct script_state *st)
  4569. {
  4570. int m;
  4571. char *str;
  4572. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4573. m = map_mapname2mapid(str);
  4574. if(m >= 0 && !map[m].flag.gvg) {
  4575. map[m].flag.gvg = 1;
  4576. clif_send0199(m,3);
  4577. }
  4578. return 0;
  4579. }
  4580. int buildin_gvgoff(struct script_state *st)
  4581. {
  4582. int m;
  4583. char *str;
  4584. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4585. m = map_mapname2mapid(str);
  4586. if(m >= 0 && map[m].flag.gvg) {
  4587. map[m].flag.gvg = 0;
  4588. clif_send0199(m,0);
  4589. }
  4590. return 0;
  4591. }
  4592. /*==========================================
  4593. * NPCエモーション
  4594. *------------------------------------------
  4595. */
  4596. int buildin_emotion(struct script_state *st)
  4597. {
  4598. int type;
  4599. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4600. if(type < 0 || type > 100)
  4601. return 0;
  4602. clif_emotion(map_id2bl(st->oid),type);
  4603. return 0;
  4604. }
  4605. int buildin_maprespawnguildid_sub(struct block_list *bl,va_list ap)
  4606. {
  4607. int g_id=va_arg(ap,int);
  4608. int flag=va_arg(ap,int);
  4609. struct map_session_data *sd=NULL;
  4610. struct mob_data *md=NULL;
  4611. if(bl->type == BL_PC)
  4612. sd=(struct map_session_data*)bl;
  4613. if(bl->type == BL_MOB)
  4614. md=(struct mob_data *)bl;
  4615. if(sd){
  4616. if((sd->status.guild_id == g_id) && (flag&1))
  4617. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  4618. else if((sd->status.guild_id != g_id) && (flag&2))
  4619. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  4620. else if (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  4621. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3); // end addition [Valaris]
  4622. }
  4623. if(md && flag&4){
  4624. if(md->class_ < 1285 || md->class_ > 1288)
  4625. mob_delete(md);
  4626. }
  4627. return 0;
  4628. }
  4629. int buildin_maprespawnguildid(struct script_state *st)
  4630. {
  4631. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4632. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4633. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4634. int m=map_mapname2mapid(mapname);
  4635. if(m) map_foreachinarea(buildin_maprespawnguildid_sub,m,0,0,map[m].xs-1,map[m].ys-1,BL_NUL,g_id,flag);
  4636. return 0;
  4637. }
  4638. int buildin_agitstart(struct script_state *st)
  4639. {
  4640. if(agit_flag==1) return 1; // Agit already Start.
  4641. agit_flag=1;
  4642. guild_agit_start();
  4643. return 0;
  4644. }
  4645. int buildin_agitend(struct script_state *st)
  4646. {
  4647. if(agit_flag==0) return 1; // Agit already End.
  4648. agit_flag=0;
  4649. guild_agit_end();
  4650. return 0;
  4651. }
  4652. /*==========================================
  4653. * agitcheck 1; // choice script
  4654. * if(@agit_flag == 1) goto agit;
  4655. * if(agitcheck(0) == 1) goto agit;
  4656. *------------------------------------------
  4657. */
  4658. int buildin_agitcheck(struct script_state *st)
  4659. {
  4660. struct map_session_data *sd;
  4661. int cond;
  4662. cond=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4663. if(cond == 0) {
  4664. if (agit_flag==1) push_val(st->stack,C_INT,1);
  4665. if (agit_flag==0) push_val(st->stack,C_INT,0);
  4666. } else {
  4667. sd=script_rid2sd(st);
  4668. if (agit_flag==1) pc_setreg(sd,add_str("@agit_flag"),1);
  4669. if (agit_flag==0) pc_setreg(sd,add_str("@agit_flag"),0);
  4670. }
  4671. return 0;
  4672. }
  4673. int buildin_flagemblem(struct script_state *st)
  4674. {
  4675. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4676. if(g_id < 0) return 0;
  4677. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  4678. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  4679. return 1;
  4680. }
  4681. int buildin_getcastlename(struct script_state *st)
  4682. {
  4683. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4684. struct guild_castle *gc;
  4685. int i;
  4686. char *buf=NULL;
  4687. for(i=0;i<MAX_GUILDCASTLE;i++){
  4688. if( (gc=guild_castle_search(i)) != NULL ){
  4689. if(strcmp(mapname,gc->map_name)==0){
  4690. buf=(char *)aCallocA(24,sizeof(char));
  4691. strncpy(buf,gc->castle_name,24);
  4692. break;
  4693. }
  4694. }
  4695. }
  4696. if(buf)
  4697. push_str(st->stack,C_STR,buf);
  4698. else
  4699. push_str(st->stack,C_CONSTSTR,"");
  4700. return 0;
  4701. }
  4702. int buildin_getcastledata(struct script_state *st)
  4703. {
  4704. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4705. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4706. char *event=NULL;
  4707. struct guild_castle *gc;
  4708. int i,j;
  4709. if( st->end>st->start+4 && index==0){
  4710. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  4711. if( (gc=guild_castle_search(i)) != NULL &&
  4712. strcmp(mapname,gc->map_name)==0 )
  4713. j=i;
  4714. if(j>=0){
  4715. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  4716. guild_addcastleinfoevent(j,17,event);
  4717. }
  4718. }
  4719. for(i=0;i<MAX_GUILDCASTLE;i++){
  4720. if( (gc=guild_castle_search(i)) != NULL ){
  4721. if(strcmp(mapname,gc->map_name)==0){
  4722. switch(index){
  4723. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  4724. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  4725. case 2: push_val(st->stack,C_INT,gc->economy); break;
  4726. case 3: push_val(st->stack,C_INT,gc->defense); break;
  4727. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  4728. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  4729. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  4730. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  4731. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  4732. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  4733. case 10: push_val(st->stack,C_INT,gc->visibleG0); break;
  4734. case 11: push_val(st->stack,C_INT,gc->visibleG1); break;
  4735. case 12: push_val(st->stack,C_INT,gc->visibleG2); break;
  4736. case 13: push_val(st->stack,C_INT,gc->visibleG3); break;
  4737. case 14: push_val(st->stack,C_INT,gc->visibleG4); break;
  4738. case 15: push_val(st->stack,C_INT,gc->visibleG5); break;
  4739. case 16: push_val(st->stack,C_INT,gc->visibleG6); break;
  4740. case 17: push_val(st->stack,C_INT,gc->visibleG7); break;
  4741. case 18: push_val(st->stack,C_INT,gc->Ghp0); break;
  4742. case 19: push_val(st->stack,C_INT,gc->Ghp1); break;
  4743. case 20: push_val(st->stack,C_INT,gc->Ghp2); break;
  4744. case 21: push_val(st->stack,C_INT,gc->Ghp3); break;
  4745. case 22: push_val(st->stack,C_INT,gc->Ghp4); break;
  4746. case 23: push_val(st->stack,C_INT,gc->Ghp5); break;
  4747. case 24: push_val(st->stack,C_INT,gc->Ghp6); break;
  4748. case 25: push_val(st->stack,C_INT,gc->Ghp7); break;
  4749. default:
  4750. push_val(st->stack,C_INT,0); break;
  4751. }
  4752. return 0;
  4753. }
  4754. }
  4755. }
  4756. push_val(st->stack,C_INT,0);
  4757. return 0;
  4758. }
  4759. int buildin_setcastledata(struct script_state *st)
  4760. {
  4761. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4762. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4763. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4764. struct guild_castle *gc;
  4765. int i;
  4766. for(i=0;i<MAX_GUILDCASTLE;i++){
  4767. if( (gc=guild_castle_search(i)) != NULL ){
  4768. if(strcmp(mapname,gc->map_name)==0){
  4769. // Save Data byself First
  4770. switch(index){
  4771. case 1: gc->guild_id = value; break;
  4772. case 2: gc->economy = value; break;
  4773. case 3: gc->defense = value; break;
  4774. case 4: gc->triggerE = value; break;
  4775. case 5: gc->triggerD = value; break;
  4776. case 6: gc->nextTime = value; break;
  4777. case 7: gc->payTime = value; break;
  4778. case 8: gc->createTime = value; break;
  4779. case 9: gc->visibleC = value; break;
  4780. case 10: gc->visibleG0 = value; break;
  4781. case 11: gc->visibleG1 = value; break;
  4782. case 12: gc->visibleG2 = value; break;
  4783. case 13: gc->visibleG3 = value; break;
  4784. case 14: gc->visibleG4 = value; break;
  4785. case 15: gc->visibleG5 = value; break;
  4786. case 16: gc->visibleG6 = value; break;
  4787. case 17: gc->visibleG7 = value; break;
  4788. case 18: gc->Ghp0 = value; break;
  4789. case 19: gc->Ghp1 = value; break;
  4790. case 20: gc->Ghp2 = value; break;
  4791. case 21: gc->Ghp3 = value; break;
  4792. case 22: gc->Ghp4 = value; break;
  4793. case 23: gc->Ghp5 = value; break;
  4794. case 24: gc->Ghp6 = value; break;
  4795. case 25: gc->Ghp7 = value; break;
  4796. default: return 0;
  4797. }
  4798. guild_castledatasave(gc->castle_id,index,value);
  4799. return 0;
  4800. }
  4801. }
  4802. }
  4803. return 0;
  4804. }
  4805. /* =====================================================================
  4806. * ギルド情報を要求する
  4807. * ---------------------------------------------------------------------
  4808. */
  4809. int buildin_requestguildinfo(struct script_state *st)
  4810. {
  4811. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4812. char *event=NULL;
  4813. if( st->end>st->start+3 )
  4814. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4815. if(guild_id>0)
  4816. guild_npc_request_info(guild_id,event);
  4817. return 0;
  4818. }
  4819. /* =====================================================================
  4820. * カードの数を得る
  4821. * ---------------------------------------------------------------------
  4822. */
  4823. int buildin_getequipcardcnt(struct script_state *st)
  4824. {
  4825. int i,num;
  4826. struct map_session_data *sd;
  4827. int c=4;
  4828. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4829. sd=script_rid2sd(st);
  4830. i=pc_checkequip(sd,equip[num-1]);
  4831. if(sd->status.inventory[i].card[0] == 0x00ff){ // 製造武器はカードなし
  4832. push_val(st->stack,C_INT,0);
  4833. return 0;
  4834. }
  4835. do{
  4836. if( (sd->status.inventory[i].card[c-1] > 4000 &&
  4837. sd->status.inventory[i].card[c-1] < 5000) ||
  4838. itemdb_type(sd->status.inventory[i].card[c-1]) == 6){ // [Celest]
  4839. push_val(st->stack,C_INT,(c));
  4840. return 0;
  4841. }
  4842. }while(c--);
  4843. push_val(st->stack,C_INT,0);
  4844. return 0;
  4845. }
  4846. /* ================================================================
  4847. * カード取り外し成功
  4848. * ----------------------------------------------------------------
  4849. */
  4850. int buildin_successremovecards(struct script_state *st)
  4851. {
  4852. int i,num,cardflag=0,flag;
  4853. struct map_session_data *sd;
  4854. struct item item_tmp;
  4855. int c=4;
  4856. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4857. sd=script_rid2sd(st);
  4858. i=pc_checkequip(sd,equip[num-1]);
  4859. if(sd->status.inventory[i].card[0]==0x00ff){ // 製造武器は処理しない
  4860. return 0;
  4861. }
  4862. do{
  4863. if( (sd->status.inventory[i].card[c-1] > 4000 &&
  4864. sd->status.inventory[i].card[c-1] < 5000) ||
  4865. itemdb_type(sd->status.inventory[i].card[c-1]) == 6){ // [Celest]
  4866. cardflag = 1;
  4867. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  4868. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  4869. item_tmp.attribute=0;
  4870. item_tmp.card[0]=0,item_tmp.card[1]=0,item_tmp.card[2]=0,item_tmp.card[3]=0;
  4871. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  4872. clif_additem(sd,0,0,flag);
  4873. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4874. }
  4875. }
  4876. }while(c--);
  4877. if(cardflag == 1){ // カードを取り除いたアイテム所得
  4878. flag=0;
  4879. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  4880. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  4881. item_tmp.attribute=sd->status.inventory[i].attribute;
  4882. item_tmp.card[0]=0,item_tmp.card[1]=0,item_tmp.card[2]=0,item_tmp.card[3]=0;
  4883. pc_delitem(sd,i,1,0);
  4884. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  4885. clif_additem(sd,0,0,flag);
  4886. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4887. }
  4888. clif_misceffect(&sd->bl,3);
  4889. return 0;
  4890. }
  4891. return 0;
  4892. }
  4893. /* ================================================================
  4894. * カード取り外し失敗 slot,type
  4895. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  4896. * ----------------------------------------------------------------
  4897. */
  4898. int buildin_failedremovecards(struct script_state *st)
  4899. {
  4900. int i,num,cardflag=0,flag,typefail;
  4901. struct map_session_data *sd;
  4902. struct item item_tmp;
  4903. int c=4;
  4904. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4905. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4906. sd=script_rid2sd(st);
  4907. i=pc_checkequip(sd,equip[num-1]);
  4908. if(sd->status.inventory[i].card[0]==0x00ff){ // 製造武器は処理しない
  4909. return 0;
  4910. }
  4911. do{
  4912. if( (sd->status.inventory[i].card[c-1] > 4000 &&
  4913. sd->status.inventory[i].card[c-1] < 5000) ||
  4914. itemdb_type(sd->status.inventory[i].card[c-1]) == 6){ // [Celest]
  4915. cardflag = 1;
  4916. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  4917. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  4918. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  4919. item_tmp.attribute=0;
  4920. item_tmp.card[0]=0,item_tmp.card[1]=0,item_tmp.card[2]=0,item_tmp.card[3]=0;
  4921. if((flag=pc_additem(sd,&item_tmp,1))){
  4922. clif_additem(sd,0,0,flag);
  4923. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4924. }
  4925. }
  4926. }
  4927. }while(c--);
  4928. if(cardflag == 1){
  4929. if(typefail == 0 || typefail == 2){ // 武具損失
  4930. pc_delitem(sd,i,1,0);
  4931. clif_misceffect(&sd->bl,2);
  4932. return 0;
  4933. }
  4934. if(typefail == 1){ // カードのみ損失(武具を返す)
  4935. flag=0;
  4936. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  4937. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  4938. item_tmp.attribute=sd->status.inventory[i].attribute;
  4939. item_tmp.card[0]=0,item_tmp.card[1]=0,item_tmp.card[2]=0,item_tmp.card[3]=0;
  4940. pc_delitem(sd,i,1,0);
  4941. if((flag=pc_additem(sd,&item_tmp,1))){
  4942. clif_additem(sd,0,0,flag);
  4943. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4944. }
  4945. }
  4946. clif_misceffect(&sd->bl,2);
  4947. return 0;
  4948. }
  4949. return 0;
  4950. }
  4951. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  4952. {
  4953. int x,y,m;
  4954. char *str;
  4955. char *mapname;
  4956. int x0,y0,x1,y1;
  4957. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4958. x0=0;
  4959. y0=0;
  4960. x1=map[map_mapname2mapid(mapname)].xs;
  4961. y1=map[map_mapname2mapid(mapname)].ys;
  4962. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4963. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4964. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4965. if( (m=map_mapname2mapid(mapname))< 0)
  4966. return 0;
  4967. map_foreachinarea(buildin_areawarp_sub,
  4968. m,x0,y0,x1,y1,BL_PC, str,x,y );
  4969. return 0;
  4970. }
  4971. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  4972. {
  4973. char *npc,*command;
  4974. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4975. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4976. npc_command(map_id2sd(st->rid),npc,command);
  4977. return 0;
  4978. }
  4979. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  4980. {
  4981. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  4982. // nd->lastaction=nd->timer=gettick();
  4983. npc_do_ontimer(st->oid, map_id2sd(st->rid), 1);
  4984. return 0;
  4985. }
  4986. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  4987. {
  4988. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  4989. // nd->lastaction=nd->timer=-1;
  4990. npc_do_ontimer(st->oid, map_id2sd(st->rid), 0);
  4991. return 0;
  4992. }
  4993. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  4994. {
  4995. char *event=va_arg(ap,char *);
  4996. int *c=va_arg(ap,int *);
  4997. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  4998. (*c)++;
  4999. return 0;
  5000. }
  5001. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  5002. {
  5003. char *mapname,*event;
  5004. int m,c=0;
  5005. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5006. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  5007. if( (m=map_mapname2mapid(mapname))<0 ) {
  5008. push_val(st->stack,C_INT,-1);
  5009. return 0;
  5010. }
  5011. map_foreachinarea(buildin_mobcount_sub,
  5012. m,0,0,map[m].xs,map[m].ys,BL_MOB, event,&c );
  5013. push_val(st->stack,C_INT, (c - 1));
  5014. return 0;
  5015. }
  5016. int buildin_marriage(struct script_state *st)
  5017. {
  5018. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5019. struct map_session_data *sd=script_rid2sd(st);
  5020. struct map_session_data *p_sd=map_nick2sd(partner);
  5021. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  5022. push_val(st->stack,C_INT,0);
  5023. return 0;
  5024. }
  5025. push_val(st->stack,C_INT,1);
  5026. return 0;
  5027. }
  5028. int buildin_wedding_effect(struct script_state *st)
  5029. {
  5030. struct map_session_data *sd=script_rid2sd(st);
  5031. struct block_list *bl;
  5032. if(sd==NULL) {
  5033. bl=map_id2bl(st->oid);
  5034. } else
  5035. bl=&sd->bl;
  5036. clif_wedding_effect(bl);
  5037. return 0;
  5038. }
  5039. int buildin_divorce(struct script_state *st)
  5040. {
  5041. struct map_session_data *sd=script_rid2sd(st);
  5042. if(sd==NULL || pc_divorce(sd) < 0){
  5043. push_val(st->stack,C_INT,0);
  5044. return 0;
  5045. }
  5046. push_val(st->stack,C_INT,1);
  5047. return 0;
  5048. }
  5049. int buildin_ispartneron(struct script_state *st)
  5050. {
  5051. struct map_session_data *sd=script_rid2sd(st);
  5052. struct map_session_data *p_sd=NULL;
  5053. if(sd==NULL || !pc_ismarried(sd) ||
  5054. ((p_sd=map_nick2sd(map_charid2nick(sd->status.partner_id))) == NULL)) {
  5055. push_val(st->stack,C_INT,0);
  5056. return 0;
  5057. }
  5058. push_val(st->stack,C_INT,1);
  5059. return 0;
  5060. }
  5061. int buildin_getpartnerid(struct script_state *st)
  5062. {
  5063. struct map_session_data *sd=script_rid2sd(st);
  5064. if (sd == NULL) {
  5065. push_val(st->stack,C_INT,0);
  5066. return 0;
  5067. }
  5068. push_val(st->stack,C_INT,sd->status.partner_id);
  5069. return 0;
  5070. }
  5071. int buildin_warppartner(struct script_state *st)
  5072. {
  5073. int x,y;
  5074. char *str;
  5075. struct map_session_data *sd=script_rid2sd(st);
  5076. struct map_session_data *p_sd=NULL;
  5077. if(sd==NULL || !pc_ismarried(sd) ||
  5078. ((p_sd=map_nick2sd(map_charid2nick(sd->status.partner_id))) == NULL)) {
  5079. push_val(st->stack,C_INT,0);
  5080. return 0;
  5081. }
  5082. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5083. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5084. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5085. pc_setpos(p_sd,str,x,y,0);
  5086. push_val(st->stack,C_INT,1);
  5087. return 0;
  5088. }
  5089. /*================================================
  5090. * Script for Displaying MOB Information [Valaris]
  5091. *------------------------------------------------
  5092. */
  5093. int buildin_strmobinfo(struct script_state *st)
  5094. {
  5095. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5096. int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5097. if((class_>=0 && class_<=1000) || class_ >2000)
  5098. return 0;
  5099. switch (num) {
  5100. case 1:
  5101. {
  5102. char *buf;
  5103. buf=aCallocA(24, 1);
  5104. // buf=mob_db[class_].name;
  5105. // for string assignments you would need to go for c++ [Shinomori]
  5106. strcpy(buf,mob_db[class_].name);
  5107. push_str(st->stack,C_STR,buf);
  5108. break;
  5109. }
  5110. case 2:
  5111. {
  5112. char *buf;
  5113. buf=aCallocA(24, 1);
  5114. // buf=mob_db[class_].jname;
  5115. // for string assignments you would need to go for c++ [Shinomori]
  5116. strcpy(buf,mob_db[class_].jname);
  5117. push_str(st->stack,C_STR,buf);
  5118. break;
  5119. }
  5120. case 3:
  5121. push_val(st->stack,C_INT,mob_db[class_].lv);
  5122. break;
  5123. case 4:
  5124. push_val(st->stack,C_INT,mob_db[class_].max_hp);
  5125. break;
  5126. case 5:
  5127. push_val(st->stack,C_INT,mob_db[class_].max_sp);
  5128. break;
  5129. case 6:
  5130. push_val(st->stack,C_INT,mob_db[class_].base_exp);
  5131. break;
  5132. case 7:
  5133. push_val(st->stack,C_INT,mob_db[class_].job_exp);
  5134. break;
  5135. }
  5136. return 0;
  5137. }
  5138. /*==========================================
  5139. * Summon guardians [Valaris]
  5140. *------------------------------------------
  5141. */
  5142. int buildin_guardian(struct script_state *st)
  5143. {
  5144. int class_=0,amount=1,x=0,y=0,guardian=0;
  5145. char *str,*map,*event="";
  5146. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  5147. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  5148. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  5149. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  5150. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5151. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5152. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  5153. if( st->end>st->start+9 )
  5154. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5155. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
  5156. return 0;
  5157. }
  5158. /*================================================
  5159. * Script for Displaying Guardian Info [Valaris]
  5160. *------------------------------------------------
  5161. */
  5162. int buildin_guardianinfo(struct script_state *st)
  5163. {
  5164. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5165. struct map_session_data *sd=script_rid2sd(st);
  5166. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  5167. if(guardian==0 && gc->visibleG0 == 1) push_val(st->stack,C_INT,gc->Ghp0);
  5168. if(guardian==1 && gc->visibleG1 == 1) push_val(st->stack,C_INT,gc->Ghp1);
  5169. if(guardian==2 && gc->visibleG2 == 1) push_val(st->stack,C_INT,gc->Ghp2);
  5170. if(guardian==3 && gc->visibleG3 == 1) push_val(st->stack,C_INT,gc->Ghp3);
  5171. if(guardian==4 && gc->visibleG4 == 1) push_val(st->stack,C_INT,gc->Ghp4);
  5172. if(guardian==5 && gc->visibleG5 == 1) push_val(st->stack,C_INT,gc->Ghp5);
  5173. if(guardian==6 && gc->visibleG6 == 1) push_val(st->stack,C_INT,gc->Ghp6);
  5174. if(guardian==7 && gc->visibleG7 == 1) push_val(st->stack,C_INT,gc->Ghp7);
  5175. else push_val(st->stack,C_INT,-1);
  5176. return 0;
  5177. }
  5178. /*==========================================
  5179. * IDからItem名
  5180. *------------------------------------------
  5181. */
  5182. int buildin_getitemname(struct script_state *st)
  5183. {
  5184. int item_id;
  5185. struct item_data *i_data;
  5186. char *item_name;
  5187. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5188. i_data = NULL;
  5189. i_data = itemdb_search(item_id);
  5190. item_name=(char *)aCallocA(24,sizeof(char));
  5191. strncpy(item_name,i_data->jname,23);
  5192. push_str(st->stack,C_STR,item_name);
  5193. return 0;
  5194. }
  5195. /*==========================================
  5196. * petskillbonus [Valaris]
  5197. *------------------------------------------
  5198. */
  5199. int buildin_petskillbonus(struct script_state *st)
  5200. {
  5201. int type,val,duration,timer;
  5202. struct pet_data *pd;
  5203. struct map_session_data *sd=script_rid2sd(st);
  5204. if(sd==NULL || sd->pd==NULL)
  5205. return 0;
  5206. pd=sd->pd;
  5207. if(pd==NULL)
  5208. return 0;
  5209. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5210. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5211. duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5212. timer=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5213. // initialise bonuses
  5214. pd->skillbonustype=type;
  5215. pd->skillbonusval=val;
  5216. pd->skillduration=duration*1000;
  5217. pd->skilltimer=timer*1000;
  5218. if (pd->state.skillbonus == -1)
  5219. pd->state.skillbonus=0; // waiting state
  5220. // wait for timer to start
  5221. pd->skillbonustimer=add_timer(gettick()+pd->skilltimer,pet_skill_bonus_timer,sd->bl.id,0);
  5222. return 0;
  5223. }
  5224. /*==========================================
  5225. * pet looting [Valaris]
  5226. *------------------------------------------
  5227. */
  5228. int buildin_petloot(struct script_state *st)
  5229. {
  5230. int max;
  5231. struct pet_data *pd;
  5232. struct map_session_data *sd=script_rid2sd(st);
  5233. if(sd==NULL || sd->pd==NULL)
  5234. return 0;
  5235. pd=sd->pd;
  5236. if(pd==NULL)
  5237. return 0;
  5238. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5239. if(!max)
  5240. return 0;
  5241. pd->loot=1;
  5242. pd->lootmax=max;
  5243. return 0;
  5244. }
  5245. /*==========================================
  5246. * PCの所持品情報読み取り
  5247. *------------------------------------------
  5248. */
  5249. int buildin_getinventorylist(struct script_state *st)
  5250. {
  5251. struct map_session_data *sd=script_rid2sd(st);
  5252. int i,j=0;
  5253. if(!sd) return 0;
  5254. for(i=0;i<MAX_INVENTORY;i++){
  5255. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  5256. pc_setreg(sd,add_str("@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  5257. pc_setreg(sd,add_str("@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  5258. pc_setreg(sd,add_str("@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  5259. pc_setreg(sd,add_str("@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  5260. pc_setreg(sd,add_str("@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  5261. pc_setreg(sd,add_str("@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  5262. pc_setreg(sd,add_str("@inventorylist_card1")+(j<<24),sd->status.inventory[i].card[0]);
  5263. pc_setreg(sd,add_str("@inventorylist_card2")+(j<<24),sd->status.inventory[i].card[1]);
  5264. pc_setreg(sd,add_str("@inventorylist_card3")+(j<<24),sd->status.inventory[i].card[2]);
  5265. pc_setreg(sd,add_str("@inventorylist_card4")+(j<<24),sd->status.inventory[i].card[3]);
  5266. j++;
  5267. }
  5268. }
  5269. pc_setreg(sd,add_str("@inventorylist_count"),j);
  5270. return 0;
  5271. }
  5272. int buildin_getskilllist(struct script_state *st)
  5273. {
  5274. struct map_session_data *sd=script_rid2sd(st);
  5275. int i,j=0;
  5276. if(!sd) return 0;
  5277. for(i=0;i<MAX_SKILL;i++){
  5278. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  5279. pc_setreg(sd,add_str("@skilllist_id")+(j<<24),sd->status.skill[i].id);
  5280. pc_setreg(sd,add_str("@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  5281. pc_setreg(sd,add_str("@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  5282. j++;
  5283. }
  5284. }
  5285. pc_setreg(sd,add_str("@skilllist_count"),j);
  5286. return 0;
  5287. }
  5288. int buildin_clearitem(struct script_state *st)
  5289. {
  5290. struct map_session_data *sd=script_rid2sd(st);
  5291. int i;
  5292. if(sd==NULL) return 0;
  5293. for (i=0; i<MAX_INVENTORY; i++) {
  5294. if (sd->status.inventory[i].amount)
  5295. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  5296. }
  5297. return 0;
  5298. }
  5299. /*==========================================
  5300. * NPCクラスチェンジ
  5301. * classは変わりたいclass
  5302. * typeは通常0なのかな?
  5303. *------------------------------------------
  5304. */
  5305. int buildin_classchange(struct script_state *st)
  5306. {
  5307. int _class,type;
  5308. struct block_list *bl=map_id2bl(st->oid);
  5309. if(bl==NULL) return 0;
  5310. _class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5311. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5312. clif_class_change(bl,_class,type);
  5313. return 0;
  5314. }
  5315. /*==========================================
  5316. * NPCから発生するエフェクト
  5317. *------------------------------------------
  5318. */
  5319. int buildin_misceffect(struct script_state *st)
  5320. {
  5321. int type;
  5322. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5323. if(st->oid)
  5324. clif_misceffect2(map_id2bl(st->oid),type);
  5325. else{
  5326. struct map_session_data *sd=script_rid2sd(st);
  5327. if(sd)
  5328. clif_misceffect2(&sd->bl,type);
  5329. }
  5330. return 0;
  5331. }
  5332. /*==========================================
  5333. * サウンドエフェクト
  5334. *------------------------------------------
  5335. */
  5336. int buildin_soundeffect(struct script_state *st)
  5337. {
  5338. struct map_session_data *sd=script_rid2sd(st);
  5339. char *name;
  5340. int type=0;
  5341. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5342. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5343. if(sd){
  5344. if(st->oid)
  5345. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  5346. else{
  5347. clif_soundeffect(sd,&sd->bl,name,type);
  5348. }
  5349. }
  5350. return 0;
  5351. }
  5352. int buildin_soundeffectall(struct script_state *st)
  5353. {
  5354. struct map_session_data *sd=script_rid2sd(st);
  5355. char *name;
  5356. int type=0;
  5357. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5358. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5359. if(sd)
  5360. {
  5361. if(st->oid)
  5362. clif_soundeffectall(map_id2bl(st->oid),name,type);
  5363. else
  5364. clif_soundeffectall(&sd->bl,name,type);
  5365. }
  5366. return 0;
  5367. }
  5368. /*==========================================
  5369. * pet status recovery [Valaris]
  5370. *------------------------------------------
  5371. */
  5372. int buildin_petrecovery(struct script_state *st)
  5373. {
  5374. struct pet_data *pd;
  5375. struct map_session_data *sd=script_rid2sd(st);
  5376. if(sd==NULL || sd->pd==NULL)
  5377. return 0;
  5378. pd=sd->pd;
  5379. if(pd==NULL)
  5380. return 0;
  5381. pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5382. pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5383. pd->skillbonustimer=add_timer(gettick()+pd->skilltimer*1000,pet_recovery_timer,sd->bl.id,0);
  5384. return 0;
  5385. }
  5386. /*==========================================
  5387. * pet healing [Valaris]
  5388. *------------------------------------------
  5389. */
  5390. int buildin_petheal(struct script_state *st)
  5391. {
  5392. struct pet_data *pd;
  5393. struct map_session_data *sd=script_rid2sd(st);
  5394. if(sd==NULL || sd->pd==NULL)
  5395. return 0;
  5396. pd=sd->pd;
  5397. if(pd==NULL)
  5398. return 0;
  5399. pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5400. pd->skillval=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5401. pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5402. pd->skillbonustimer=add_timer(gettick()+pd->skilltimer*1000,pet_heal_timer,sd->bl.id,0);
  5403. return 0;
  5404. }
  5405. /*==========================================
  5406. * pet magnificat [Valaris]
  5407. *------------------------------------------
  5408. */
  5409. int buildin_petmag(struct script_state *st)
  5410. {
  5411. struct pet_data *pd;
  5412. struct map_session_data *sd=script_rid2sd(st);
  5413. if(sd==NULL || sd->pd==NULL)
  5414. return 0;
  5415. pd=sd->pd;
  5416. if(pd==NULL)
  5417. return 0;
  5418. pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5419. pd->skillduration=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5420. pd->skillval=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5421. pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5422. pd->skillbonustimer=add_timer(gettick()+pd->skilltimer*1000,pet_mag_timer,sd->bl.id,0);
  5423. return 0;
  5424. }
  5425. /*==========================================
  5426. * pet attack skills [Valaris]
  5427. *------------------------------------------
  5428. */
  5429. int buildin_petskillattack(struct script_state *st)
  5430. {
  5431. struct pet_data *pd;
  5432. struct map_session_data *sd=script_rid2sd(st);
  5433. if(sd==NULL || sd->pd==NULL)
  5434. return 0;
  5435. pd=sd->pd;
  5436. if(pd==NULL)
  5437. return 0;
  5438. pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5439. pd->skillval=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5440. pd->skillduration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5441. pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5442. pd->skillbonustimer=add_timer(gettick()+100,pet_skillattack_timer,sd->bl.id,0);
  5443. return 0;
  5444. }
  5445. /*==========================================
  5446. * Scripted skill effects [Celest]
  5447. *------------------------------------------
  5448. */
  5449. int buildin_skilleffect(struct script_state *st)
  5450. {
  5451. struct map_session_data *sd;
  5452. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5453. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5454. sd=script_rid2sd(st);
  5455. clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
  5456. return 0;
  5457. }
  5458. /*==========================================
  5459. * NPC skill effects [Valaris]
  5460. *------------------------------------------
  5461. */
  5462. int buildin_npcskilleffect(struct script_state *st)
  5463. {
  5464. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5465. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5466. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5467. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5468. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5469. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  5470. return 0;
  5471. }
  5472. /*==========================================
  5473. * Special effects [Valaris]
  5474. *------------------------------------------
  5475. */
  5476. int buildin_specialeffect(struct script_state *st)
  5477. {
  5478. struct block_list *bl=map_id2bl(st->oid);
  5479. if(bl==NULL)
  5480. return 0;
  5481. clif_specialeffect(bl,conv_num(st,& (st->stack->stack_data[st->start+2])), 0);
  5482. return 0;
  5483. }
  5484. int buildin_specialeffect2(struct script_state *st)
  5485. {
  5486. struct map_session_data *sd=script_rid2sd(st);
  5487. if(sd==NULL)
  5488. return 0;
  5489. clif_specialeffect(&sd->bl,conv_num(st,& (st->stack->stack_data[st->start+2])), 0);
  5490. return 0;
  5491. }
  5492. /*==========================================
  5493. * Nude [Valaris]
  5494. *------------------------------------------
  5495. */
  5496. int buildin_nude(struct script_state *st)
  5497. {
  5498. struct map_session_data *sd=script_rid2sd(st);
  5499. int i;
  5500. if(sd==NULL)
  5501. return 0;
  5502. for(i=0;i<11;i++)
  5503. if(sd->equip_index[i] >= 0)
  5504. pc_unequipitem(sd,sd->equip_index[i],2);
  5505. return 0;
  5506. }
  5507. /*==========================================
  5508. * gmcommand [MouseJstr]
  5509. *
  5510. * suggested on the forums...
  5511. *------------------------------------------
  5512. */
  5513. int buildin_gmcommand(struct script_state *st)
  5514. {
  5515. struct map_session_data *sd;
  5516. char *cmd;
  5517. sd = script_rid2sd(st);
  5518. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  5519. is_atcommand(sd->fd, sd, cmd, 99);
  5520. return 0;
  5521. }
  5522. /*==========================================
  5523. * Displays a message for the player only (like system messages like "you got an apple" )
  5524. *------------------------------------------
  5525. */
  5526. int buildin_dispbottom(struct script_state *st)
  5527. {
  5528. struct map_session_data *sd=script_rid2sd(st);
  5529. char *message;
  5530. message=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5531. if(sd)
  5532. clif_disp_onlyself(sd,message,strlen(message));
  5533. return 0;
  5534. }
  5535. /*==========================================
  5536. * All The Players Full Recovery
  5537. (HP/SP full restore and resurrect if need)
  5538. *------------------------------------------
  5539. */
  5540. int buildin_recovery(struct script_state *st)
  5541. {
  5542. int i = 0;
  5543. for (i = 0; i < fd_max; i++) {
  5544. if (session[i]){
  5545. struct map_session_data *sd = session[i]->session_data;
  5546. if (sd && sd->state.auth) {
  5547. sd->status.hp = sd->status.max_hp;
  5548. sd->status.sp = sd->status.max_sp;
  5549. clif_updatestatus(sd, SP_HP);
  5550. clif_updatestatus(sd, SP_SP);
  5551. if(pc_isdead(sd)){
  5552. pc_setstand(sd);
  5553. clif_resurrection(&sd->bl, 1);
  5554. }
  5555. clif_displaymessage(sd->fd,"You have been recovered!");
  5556. }
  5557. }
  5558. }
  5559. return 0;
  5560. }
  5561. /*==========================================
  5562. * Get your pet info: getpetinfo(n)
  5563. * n -> 0:pet_id 1:pet_class 2:pet_name
  5564. 3:friendly 4:hungry
  5565. *------------------------------------------
  5566. */
  5567. int buildin_getpetinfo(struct script_state *st)
  5568. {
  5569. struct map_session_data *sd=script_rid2sd(st);
  5570. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5571. if(sd && sd->status.pet_id){
  5572. switch(type){
  5573. case 0:
  5574. push_val(st->stack,C_INT,sd->status.pet_id);
  5575. break;
  5576. case 1:
  5577. if(sd->pet.class_)
  5578. push_val(st->stack,C_INT,sd->pet.class_);
  5579. else
  5580. push_val(st->stack,C_INT,0);
  5581. break;
  5582. case 2:
  5583. if(sd->pet.name)
  5584. push_str(st->stack,C_STR,sd->pet.name);
  5585. else
  5586. push_val(st->stack,C_INT,0);
  5587. break;
  5588. case 3:
  5589. //if(sd->pet.intimate)
  5590. push_val(st->stack,C_INT,sd->pet.intimate);
  5591. break;
  5592. case 4:
  5593. //if(sd->pet.hungry)
  5594. push_val(st->stack,C_INT,sd->pet.hungry);
  5595. break;
  5596. default:
  5597. push_val(st->stack,C_INT,0);
  5598. break;
  5599. }
  5600. }else{
  5601. push_val(st->stack,C_INT,0);
  5602. }
  5603. return 0;
  5604. }
  5605. /*==========================================
  5606. * Shows wether your inventory(and equips) contain
  5607. selected card or not.
  5608. checkequipedcard(4001);
  5609. *------------------------------------------
  5610. */
  5611. int buildin_checkequipedcard(struct script_state *st)
  5612. {
  5613. struct map_session_data *sd=script_rid2sd(st);
  5614. int n,i,c=0;
  5615. c=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5616. if(sd){
  5617. for(i=0;i<MAX_INVENTORY;i++){
  5618. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount){
  5619. for(n=0;n<4;n++){
  5620. if(sd->status.inventory[i].card[n]==c){
  5621. push_val(st->stack,C_INT,1);
  5622. return 0;
  5623. }
  5624. }
  5625. }
  5626. }
  5627. }
  5628. push_val(st->stack,C_INT,0);
  5629. return 0;
  5630. }
  5631. int buildin_jump_zero(struct script_state *st) {
  5632. int sel;
  5633. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5634. if(!sel) {
  5635. int pos;
  5636. if( st->stack->stack_data[st->start+3].type!=C_POS ){
  5637. printf("script: jump_zero: not label !\n");
  5638. st->state=END;
  5639. return 0;
  5640. }
  5641. pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5642. st->pos=pos;
  5643. st->state=GOTO;
  5644. // printf("script: jump_zero: jumpto : %d\n",pos);
  5645. } else {
  5646. // printf("script: jump_zero: fail\n");
  5647. }
  5648. return 0;
  5649. }
  5650. int buildin_select(struct script_state *st)
  5651. {
  5652. char *buf;
  5653. int len,i;
  5654. struct map_session_data *sd;
  5655. sd=script_rid2sd(st);
  5656. if(sd->state.menu_or_input==0){
  5657. st->state=RERUNLINE;
  5658. sd->state.menu_or_input=1;
  5659. for(i=st->start+2,len=16;i<st->end;i++){
  5660. conv_str(st,& (st->stack->stack_data[i]));
  5661. len+=strlen(st->stack->stack_data[i].u.str)+1;
  5662. }
  5663. buf=(char *)aCalloc(len+1,sizeof(char));
  5664. buf[0]=0;
  5665. for(i=st->start+2,len=0;i<st->end;i++){
  5666. strcat(buf,st->stack->stack_data[i].u.str);
  5667. strcat(buf,":");
  5668. }
  5669. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  5670. aFree(buf);
  5671. } else if(sd->npc_menu==0xff){ // cansel
  5672. sd->state.menu_or_input=0;
  5673. st->state=END;
  5674. } else {
  5675. pc_setreg(sd,add_str("l15"),sd->npc_menu);
  5676. pc_setreg(sd,add_str("@menu"),sd->npc_menu);
  5677. sd->state.menu_or_input=0;
  5678. push_val(st->stack,C_INT,sd->npc_menu);
  5679. }
  5680. return 0;
  5681. }
  5682. /*==========================================
  5683. * GetMapMobs
  5684. returns mob counts on a set map:
  5685. e.g. GetMapMobs("prontera.gat")
  5686. use "this" - for player's map
  5687. *------------------------------------------
  5688. */
  5689. int buildin_getmapmobs(struct script_state *st)
  5690. {
  5691. char *str=NULL;
  5692. int m=-1,bx,by,i;
  5693. int count=0,c;
  5694. struct block_list *bl;
  5695. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5696. if(strcmp(str,"this")==0){
  5697. struct map_session_data *sd=script_rid2sd(st);
  5698. if(sd)
  5699. m=sd->bl.m;
  5700. else{
  5701. push_val(st->stack,C_INT,-1);
  5702. return 0;
  5703. }
  5704. }else
  5705. m=map_mapname2mapid(str);
  5706. if(m < 0){
  5707. push_val(st->stack,C_INT,-1);
  5708. return 0;
  5709. }
  5710. for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++){
  5711. for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++){
  5712. bl = map[m].block_mob[bx+by*map[m].bxs];
  5713. c = map[m].block_mob_count[bx+by*map[m].bxs];
  5714. for(i=0;i<c && bl;i++,bl=bl->next){
  5715. if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
  5716. count++;
  5717. }
  5718. }
  5719. }
  5720. push_val(st->stack,C_INT,count);
  5721. return 0;
  5722. }
  5723. /*==========================================
  5724. * movenpc [MouseJstr]
  5725. *------------------------------------------
  5726. */
  5727. int buildin_movenpc(struct script_state *st)
  5728. {
  5729. struct map_session_data *sd;
  5730. char *map,*npc;
  5731. int x,y;
  5732. sd = script_rid2sd(st);
  5733. map = conv_str(st,& (st->stack->stack_data[st->start+2]));
  5734. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  5735. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  5736. npc = conv_str(st,& (st->stack->stack_data[st->start+5]));
  5737. return 0;
  5738. }
  5739. /*==========================================
  5740. * message [MouseJstr]
  5741. *------------------------------------------
  5742. */
  5743. int buildin_message(struct script_state *st)
  5744. {
  5745. struct map_session_data *sd;
  5746. char *msg,*player;
  5747. struct map_session_data *pl_sd = NULL;
  5748. sd = script_rid2sd(st);
  5749. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  5750. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  5751. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  5752. return 1;
  5753. clif_displaymessage(pl_sd->fd, msg);
  5754. return 0;
  5755. }
  5756. /*==========================================
  5757. * npctalk (sends message to surrounding
  5758. * area) [Valaris]
  5759. *------------------------------------------
  5760. */
  5761. int buildin_npctalk(struct script_state *st)
  5762. {
  5763. char *str;
  5764. char message[255];
  5765. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5766. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5767. if(nd) {
  5768. memcpy(message,nd->name,24);
  5769. strcat(message," : ");
  5770. strcat(message,str);
  5771. clif_message(&(nd->bl), message);
  5772. }
  5773. return 0;
  5774. }
  5775. /*==========================================
  5776. * hasitems (checks to see if player has any
  5777. * items on them, if so will return a 1)
  5778. * [Valaris]
  5779. *------------------------------------------
  5780. */
  5781. int buildin_hasitems(struct script_state *st)
  5782. {
  5783. int i;
  5784. struct map_session_data *sd;
  5785. sd=script_rid2sd(st);
  5786. for(i=0; i<MAX_INVENTORY; i++) {
  5787. if(sd->status.inventory[i].amount) {
  5788. push_val(st->stack,C_INT,1);
  5789. return 0;
  5790. }
  5791. }
  5792. push_val(st->stack,C_INT,0);
  5793. return 0;
  5794. }
  5795. // change npc walkspeed [Valaris]
  5796. int buildin_npcspeed(struct script_state *st)
  5797. {
  5798. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5799. int x=0;
  5800. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5801. if(nd) {
  5802. nd->speed=x;
  5803. }
  5804. return 0;
  5805. }
  5806. // make an npc walk to a position [Valaris]
  5807. int buildin_npcwalkto(struct script_state *st)
  5808. {
  5809. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5810. int x=0,y=0;
  5811. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5812. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5813. if(nd) {
  5814. npc_walktoxy(nd,x,y,0);
  5815. }
  5816. return 0;
  5817. }
  5818. // stop an npc's movement [Valaris]
  5819. int buildin_npcstop(struct script_state *st)
  5820. {
  5821. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5822. if(nd) {
  5823. if(nd->state.state==MS_WALK)
  5824. npc_stop_walking(nd,1);
  5825. }
  5826. return 0;
  5827. }
  5828. /*==========================================
  5829. * getlook char info. getlook(arg)
  5830. *------------------------------------------
  5831. */
  5832. int buildin_getlook(struct script_state *st){
  5833. int type,val;
  5834. struct map_session_data *sd;
  5835. sd=script_rid2sd(st);
  5836. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5837. val=-1;
  5838. switch(type){
  5839. case LOOK_HAIR: //1
  5840. val=sd->status.hair;
  5841. break;
  5842. case LOOK_WEAPON: //2
  5843. val=sd->status.weapon;
  5844. break;
  5845. case LOOK_HEAD_BOTTOM: //3
  5846. val=sd->status.head_bottom;
  5847. break;
  5848. case LOOK_HEAD_TOP: //4
  5849. val=sd->status.head_top;
  5850. break;
  5851. case LOOK_HEAD_MID: //5
  5852. val=sd->status.head_mid;
  5853. break;
  5854. case LOOK_HAIR_COLOR: //6
  5855. val=sd->status.hair_color;
  5856. break;
  5857. case LOOK_CLOTHES_COLOR: //7
  5858. val=sd->status.clothes_color;
  5859. break;
  5860. case LOOK_SHIELD: //8
  5861. val=sd->status.shield;
  5862. break;
  5863. case LOOK_SHOES: //9
  5864. break;
  5865. }
  5866. push_val(st->stack,C_INT,val);
  5867. return 0;
  5868. }
  5869. /*==========================================
  5870. * get char save point. argument: 0- map name, 1- x, 2- y
  5871. *------------------------------------------
  5872. */
  5873. int buildin_getsavepoint(struct script_state *st)
  5874. {
  5875. int x,y,type;
  5876. char *mapname;
  5877. struct map_session_data *sd;
  5878. sd=script_rid2sd(st);
  5879. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5880. mapname=aCallocA(24, 1);
  5881. x=sd->status.save_point.x;
  5882. y=sd->status.save_point.y;
  5883. strncpy(mapname,sd->status.save_point.map,24);
  5884. switch(type){
  5885. case 0:
  5886. push_str(st->stack,C_STR,mapname);
  5887. break;
  5888. case 1:
  5889. push_val(st->stack,C_INT,x);
  5890. break;
  5891. case 2:
  5892. push_val(st->stack,C_INT,y);
  5893. break;
  5894. }
  5895. return 0;
  5896. }
  5897. /*==========================================
  5898. * Get position for char/npc/pet/mob objects. Added by Lorky
  5899. *
  5900. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  5901. * where type:
  5902. * MapName$ - String variable for output map name
  5903. * MapX - Integer variable for output coord X
  5904. * MapY - Integer variable for output coord Y
  5905. * type - type of object
  5906. * 0 - Character coord
  5907. * 1 - NPC coord
  5908. * 2 - Pet coord
  5909. * 3 - Mob coord (not released)
  5910. * CharName$ - Name object. If miss or "this" the current object
  5911. *
  5912. * Return:
  5913. * 0 - success
  5914. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  5915. *------------------------------------------
  5916. */
  5917. int buildin_getmapxy(struct script_state *st){
  5918. struct map_session_data *sd=NULL;
  5919. struct npc_data *nd;
  5920. struct pet_data *pd;
  5921. int num;
  5922. char *name;
  5923. char prefix;
  5924. int x,y,type;
  5925. char *mapname;
  5926. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  5927. printf("script: buildin_getmapxy: not mapname variable\n");
  5928. push_val(st->stack,C_INT,-1);
  5929. return 0;
  5930. }
  5931. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  5932. printf("script: buildin_getmapxy: not mapx variable\n");
  5933. push_val(st->stack,C_INT,-1);
  5934. return 0;
  5935. }
  5936. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  5937. printf("script: buildin_getmapxy: not mapy variable\n");
  5938. push_val(st->stack,C_INT,-1);
  5939. return 0;
  5940. }
  5941. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  5942. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5943. mapname=aCallocA(24, 1);
  5944. switch (type){
  5945. case 0: //Get Character Position
  5946. if( st->end>st->start+6 )
  5947. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  5948. else
  5949. sd=script_rid2sd(st);
  5950. if ( sd==NULL ) { //wrong char name or char offline
  5951. push_val(st->stack,C_INT,-1);
  5952. return 0;
  5953. }
  5954. x=sd->bl.x;
  5955. y=sd->bl.y;
  5956. strncpy(mapname,sd->mapname,24);
  5957. printf(">>>>%s %d %d\n",mapname,x,y);
  5958. break;
  5959. case 1: //Get NPC Position
  5960. if( st->end > st->start+6 )
  5961. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  5962. else
  5963. nd=(struct npc_data *)map_id2bl(st->oid);
  5964. if ( nd==NULL ) { //wrong npc name or char offline
  5965. push_val(st->stack,C_INT,-1);
  5966. return 0;
  5967. }
  5968. x=nd->bl.x;
  5969. y=nd->bl.y;
  5970. strncpy(mapname,map[nd->bl.m].name,24);
  5971. printf(">>>>%s %d %d\n",mapname,x,y);
  5972. break;
  5973. case 2: //Get Pet Position
  5974. if( st->end>st->start+6 )
  5975. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  5976. else
  5977. sd=script_rid2sd(st);
  5978. if ( sd==NULL ) { //wrong char name or char offline
  5979. push_val(st->stack,C_INT,-1);
  5980. return 0;
  5981. }
  5982. pd=sd->pd;
  5983. if(pd==NULL){ //ped data not found
  5984. push_val(st->stack,C_INT,-1);
  5985. return 0;
  5986. }
  5987. x=pd->bl.x;
  5988. y=pd->bl.y;
  5989. strncpy(mapname,map[pd->bl.m].name,24);
  5990. printf(">>>>%s %d %d\n",mapname,x,y);
  5991. break;
  5992. case 3: //Get Mob Position
  5993. push_val(st->stack,C_INT,-1);
  5994. return 0;
  5995. default: //Wrong type parameter
  5996. push_val(st->stack,C_INT,-1);
  5997. return 0;
  5998. }
  5999. //Set MapName$
  6000. num=st->stack->stack_data[st->start+2].u.num;
  6001. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  6002. prefix=*name;
  6003. if( prefix!='$' )
  6004. sd=script_rid2sd(st);
  6005. else
  6006. sd=NULL;
  6007. set_reg(sd,num,name,(void*)mapname);
  6008. //Set MapX
  6009. num=st->stack->stack_data[st->start+3].u.num;
  6010. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  6011. prefix=*name;
  6012. if( prefix!='$' )
  6013. sd=script_rid2sd(st);
  6014. else
  6015. sd=NULL;
  6016. set_reg(sd,num,name,(void*)x);
  6017. //Set MapY
  6018. num=st->stack->stack_data[st->start+4].u.num;
  6019. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  6020. prefix=*name;
  6021. if( prefix!='$' )
  6022. sd=script_rid2sd(st);
  6023. else
  6024. sd=NULL;
  6025. set_reg(sd,num,name,(void*)y);
  6026. //Return Success value
  6027. push_val(st->stack,C_INT,0);
  6028. return 0;
  6029. }
  6030. /*=====================================================
  6031. * Allows players to use a skill - by Qamera
  6032. *-----------------------------------------------------
  6033. */
  6034. int buildin_skilluseid (struct script_state *st)
  6035. {
  6036. int skid,sklv;
  6037. struct map_session_data *sd;
  6038. skid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6039. sklv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6040. sd=script_rid2sd(st);
  6041. skill_use_id(sd,sd->status.account_id,skid,sklv);
  6042. return 0;
  6043. }
  6044. /*=====================================================
  6045. * Allows players to use a skill on a position [Celest]
  6046. *-----------------------------------------------------
  6047. */
  6048. int buildin_skillusepos(struct script_state *st)
  6049. {
  6050. int skid,sklv,x,y;
  6051. struct map_session_data *sd;
  6052. skid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6053. sklv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6054. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6055. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6056. sd=script_rid2sd(st);
  6057. skill_use_pos(sd,x,y,skid,sklv);
  6058. return 0;
  6059. }
  6060. /*==========================================
  6061. * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
  6062. *------------------------------------------
  6063. */
  6064. int buildin_logmes(struct script_state *st)
  6065. {
  6066. if (log_config.npc <= 0 ) return 0;
  6067. conv_str(st,& (st->stack->stack_data[st->start+2]));
  6068. log_npc(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str);
  6069. return 0;
  6070. }
  6071. int buildin_summon(struct script_state *st)
  6072. {
  6073. int _class, id;
  6074. char *str,*event="";
  6075. struct map_session_data *sd;
  6076. struct mob_data *md;
  6077. sd=script_rid2sd(st);
  6078. if (sd) {
  6079. int tick = gettick();
  6080. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6081. _class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6082. if( st->end>st->start+4 )
  6083. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6084. id=mob_once_spawn(sd, "this", 0, 0, str,_class,1,event);
  6085. if((md=(struct mob_data *)map_id2bl(id))){
  6086. md->master_id=sd->bl.id;
  6087. md->state.special_mob_ai=1;
  6088. md->mode=mob_db[md->class_].mode|0x04;
  6089. md->deletetimer=add_timer(tick+60000,mob_timer_delete,id,0);
  6090. clif_misceffect2(&md->bl,344);
  6091. }
  6092. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
  6093. }
  6094. return 0;
  6095. }
  6096. int buildin_isnight(struct script_state *st)
  6097. {
  6098. push_val(st->stack,C_INT, (night_flag == 1));
  6099. return 0;
  6100. }
  6101. int buildin_isday(struct script_state *st)
  6102. {
  6103. push_val(st->stack,C_INT, (night_flag == 0));
  6104. return 0;
  6105. }
  6106. /*================================================
  6107. * Check whether another item/card has been
  6108. * equipped - used for 2/15's cards patch [celest]
  6109. *------------------------------------------------
  6110. */
  6111. int buildin_isequipped(struct script_state *st)
  6112. {
  6113. struct map_session_data *sd;
  6114. int i, j, k, id = 1;
  6115. int ret = -1;
  6116. sd = script_rid2sd(st);
  6117. for (i=0; id!=0; i++) {
  6118. int flag = 0;
  6119. FETCH (i+2, id) else id = 0;
  6120. if (id <= 0)
  6121. continue;
  6122. for (j=0; j<10; j++) {
  6123. int index, type;
  6124. index = sd->equip_index[j];
  6125. if(index < 0) continue;
  6126. if(j == 9 && sd->equip_index[8] == index) continue;
  6127. if(j == 5 && sd->equip_index[4] == index) continue;
  6128. if(j == 6 && (sd->equip_index[5] == index || sd->equip_index[4] == index)) continue;
  6129. type = itemdb_type(id);
  6130. if(sd->inventory_data[index]) {
  6131. if (type == 4 || type == 5) {
  6132. if (sd->inventory_data[index]->nameid == id)
  6133. flag = 1;
  6134. } else if (type == 6) {
  6135. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  6136. if (sd->status.inventory[index].card[0]!=0x00ff &&
  6137. sd->status.inventory[index].card[0]!=0x00fe &&
  6138. sd->status.inventory[index].card[0]!=(short)0xff00 &&
  6139. sd->status.inventory[index].card[k] == id) {
  6140. flag = 1;
  6141. break;
  6142. }
  6143. }
  6144. }
  6145. if (flag) break;
  6146. }
  6147. }
  6148. if (ret == -1)
  6149. ret = flag;
  6150. else
  6151. ret &= flag;
  6152. if (!ret) break;
  6153. }
  6154. push_val(st->stack,C_INT,ret);
  6155. return 0;
  6156. }
  6157. /*================================================
  6158. * Check how many items/cards in the list are
  6159. * equipped - used for 2/15's cards patch [celest]
  6160. *------------------------------------------------
  6161. */
  6162. int buildin_isequippedcnt(struct script_state *st)
  6163. {
  6164. struct map_session_data *sd;
  6165. int i, j, k, id = 1;
  6166. int ret = 0;
  6167. sd = script_rid2sd(st);
  6168. for (i=0; id!=0; i++) {
  6169. FETCH (i+2, id) else id = 0;
  6170. if (id <= 0)
  6171. continue;
  6172. for (j=0; j<10; j++) {
  6173. int index, type;
  6174. index = sd->equip_index[j];
  6175. if(index < 0) continue;
  6176. if(j == 9 && sd->equip_index[8] == index) continue;
  6177. if(j == 5 && sd->equip_index[4] == index) continue;
  6178. if(j == 6 && (sd->equip_index[5] == index || sd->equip_index[4] == index)) continue;
  6179. type = itemdb_type(id);
  6180. if(sd->inventory_data[index]) {
  6181. if (type == 4 || type == 5) {
  6182. if (sd->inventory_data[index]->nameid == id)
  6183. ret++; //[Lupus]
  6184. } else if (type == 6) {
  6185. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  6186. if (sd->status.inventory[index].card[0]!=0x00ff &&
  6187. sd->status.inventory[index].card[0]!=0x00fe &&
  6188. sd->status.inventory[index].card[0]!=(short)0xff00 &&
  6189. sd->status.inventory[index].card[k] == id) {
  6190. ret++; //[Lupus]
  6191. }
  6192. }
  6193. }
  6194. }
  6195. }
  6196. }
  6197. push_val(st->stack,C_INT,ret);
  6198. return 0;
  6199. }
  6200. /*================================================
  6201. * Check how many given inserted cards in the CURRENT
  6202. * weapon - used for 2/15's cards patch [Lupus]
  6203. *------------------------------------------------
  6204. */
  6205. int buildin_cardscnt(struct script_state *st)
  6206. {
  6207. struct map_session_data *sd;
  6208. int i, k, id = 1;
  6209. int ret = 0;
  6210. int index, type;
  6211. sd = script_rid2sd(st);
  6212. for (i=0; id!=0; i++) {
  6213. FETCH (i+2, id) else id = 0;
  6214. if (id <= 0)
  6215. continue;
  6216. index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
  6217. if(index < 0) continue;
  6218. type = itemdb_type(id);
  6219. if(sd->inventory_data[index]) {
  6220. if (type == 4 || type == 5) {
  6221. if (sd->inventory_data[index]->nameid == id)
  6222. ret++;
  6223. } else if (type == 6) {
  6224. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  6225. if (sd->status.inventory[index].card[0]!=0x00ff &&
  6226. sd->status.inventory[index].card[0]!=0x00fe &&
  6227. sd->status.inventory[index].card[0]!=(short)0xff00 &&
  6228. sd->status.inventory[index].card[k] == id) {
  6229. ret++;
  6230. }
  6231. }
  6232. }
  6233. }
  6234. }
  6235. push_val(st->stack,C_INT,ret);
  6236. // push_val(st->stack,C_INT,current_equip_item_index);
  6237. return 0;
  6238. }
  6239. /*=======================================================
  6240. * Returns the refined number of the current item, or an
  6241. * item with inventory index specified
  6242. *-------------------------------------------------------
  6243. */
  6244. int buildin_getrefine(struct script_state *st)
  6245. {
  6246. struct map_session_data *sd;
  6247. if ((sd = script_rid2sd(st))!= NULL)
  6248. push_val(st->stack, C_INT, sd->status.inventory[current_equip_item_index].refine);
  6249. return 0;
  6250. }
  6251. //
  6252. // 実行部main
  6253. //
  6254. /*==========================================
  6255. * コマンドの読み取り
  6256. *------------------------------------------
  6257. */
  6258. static int unget_com_data=-1;
  6259. int get_com(unsigned char *script,int *pos)
  6260. {
  6261. int i,j;
  6262. if(unget_com_data>=0){
  6263. i=unget_com_data;
  6264. unget_com_data=-1;
  6265. return i;
  6266. }
  6267. if(script[*pos]>=0x80){
  6268. return C_INT;
  6269. }
  6270. i=0; j=0;
  6271. while(script[*pos]>=0x40){
  6272. i=script[(*pos)++]<<j;
  6273. j+=6;
  6274. }
  6275. return i+(script[(*pos)++]<<j);
  6276. }
  6277. /*==========================================
  6278. * コマンドのプッシュバック
  6279. *------------------------------------------
  6280. */
  6281. void unget_com(int c)
  6282. {
  6283. if(unget_com_data!=-1){
  6284. if(battle_config.error_log)
  6285. printf("unget_com can back only 1 data\n");
  6286. }
  6287. unget_com_data=c;
  6288. }
  6289. /*==========================================
  6290. * 数値の所得
  6291. *------------------------------------------
  6292. */
  6293. int get_num(unsigned char *script,int *pos)
  6294. {
  6295. int i,j;
  6296. i=0; j=0;
  6297. while(script[*pos]>=0xc0){
  6298. i+=(script[(*pos)++]&0x7f)<<j;
  6299. j+=6;
  6300. }
  6301. return i+((script[(*pos)++]&0x7f)<<j);
  6302. }
  6303. /*==========================================
  6304. * スタックから値を取り出す
  6305. *------------------------------------------
  6306. */
  6307. int pop_val(struct script_state* st)
  6308. {
  6309. if(st->stack->sp<=0)
  6310. return 0;
  6311. st->stack->sp--;
  6312. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  6313. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  6314. return st->stack->stack_data[st->stack->sp].u.num;
  6315. return 0;
  6316. }
  6317. #define isstr(c) ((c).type==C_STR || (c).type==C_CONSTSTR)
  6318. /*==========================================
  6319. * 加算演算子
  6320. *------------------------------------------
  6321. */
  6322. void op_add(struct script_state* st)
  6323. {
  6324. st->stack->sp--;
  6325. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  6326. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  6327. if(isstr(st->stack->stack_data[st->stack->sp]) || isstr(st->stack->stack_data[st->stack->sp-1])){
  6328. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  6329. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  6330. }
  6331. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  6332. st->stack->stack_data[st->stack->sp-1].u.num += st->stack->stack_data[st->stack->sp].u.num;
  6333. } else { // ssの予定
  6334. char *buf;
  6335. buf=(char *)aCallocA(strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  6336. strlen(st->stack->stack_data[st->stack->sp].u.str)+1,sizeof(char));
  6337. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  6338. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  6339. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  6340. aFree(st->stack->stack_data[st->stack->sp-1].u.str);
  6341. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  6342. aFree(st->stack->stack_data[st->stack->sp].u.str);
  6343. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  6344. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  6345. }
  6346. }
  6347. /*==========================================
  6348. * 二項演算子(文字列)
  6349. *------------------------------------------
  6350. */
  6351. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  6352. {
  6353. char *s1=st->stack->stack_data[sp1].u.str,
  6354. *s2=st->stack->stack_data[sp2].u.str;
  6355. int a=0;
  6356. switch(op){
  6357. case C_EQ:
  6358. a= (strcmp(s1,s2)==0);
  6359. break;
  6360. case C_NE:
  6361. a= (strcmp(s1,s2)!=0);
  6362. break;
  6363. case C_GT:
  6364. a= (strcmp(s1,s2)> 0);
  6365. break;
  6366. case C_GE:
  6367. a= (strcmp(s1,s2)>=0);
  6368. break;
  6369. case C_LT:
  6370. a= (strcmp(s1,s2)< 0);
  6371. break;
  6372. case C_LE:
  6373. a= (strcmp(s1,s2)<=0);
  6374. break;
  6375. default:
  6376. printf("illegal string operater\n");
  6377. break;
  6378. }
  6379. push_val(st->stack,C_INT,a);
  6380. if(st->stack->stack_data[sp1].type==C_STR) aFree(s1);
  6381. if(st->stack->stack_data[sp2].type==C_STR) aFree(s2);
  6382. }
  6383. /*==========================================
  6384. * 二項演算子(数値)
  6385. *------------------------------------------
  6386. */
  6387. void op_2num(struct script_state *st,int op,int i1,int i2)
  6388. {
  6389. switch(op){
  6390. case C_SUB:
  6391. i1-=i2;
  6392. break;
  6393. case C_MUL:
  6394. {
  6395. #ifndef _MSC_VER
  6396. long long res = i1 * i2;
  6397. #else
  6398. __int64 res = i1 * i2;
  6399. #endif
  6400. if (res > 2147483647 )
  6401. i1 = 2147483647;
  6402. else
  6403. i1*=i2;
  6404. }
  6405. break;
  6406. case C_DIV:
  6407. i1/=i2;
  6408. break;
  6409. case C_MOD:
  6410. i1%=i2;
  6411. break;
  6412. case C_AND:
  6413. i1&=i2;
  6414. break;
  6415. case C_OR:
  6416. i1|=i2;
  6417. break;
  6418. case C_XOR:
  6419. i1^=i2;
  6420. break;
  6421. case C_LAND:
  6422. i1=i1&&i2;
  6423. break;
  6424. case C_LOR:
  6425. i1=i1||i2;
  6426. break;
  6427. case C_EQ:
  6428. i1=i1==i2;
  6429. break;
  6430. case C_NE:
  6431. i1=i1!=i2;
  6432. break;
  6433. case C_GT:
  6434. i1=i1>i2;
  6435. break;
  6436. case C_GE:
  6437. i1=i1>=i2;
  6438. break;
  6439. case C_LT:
  6440. i1=i1<i2;
  6441. break;
  6442. case C_LE:
  6443. i1=i1<=i2;
  6444. break;
  6445. case C_R_SHIFT:
  6446. i1=i1>>i2;
  6447. break;
  6448. case C_L_SHIFT:
  6449. i1=i1<<i2;
  6450. break;
  6451. }
  6452. push_val(st->stack,C_INT,i1);
  6453. }
  6454. /*==========================================
  6455. * 二項演算子
  6456. *------------------------------------------
  6457. */
  6458. void op_2(struct script_state *st,int op)
  6459. {
  6460. int i1,i2;
  6461. char *s1=NULL,*s2=NULL;
  6462. i2=pop_val(st);
  6463. if( isstr(st->stack->stack_data[st->stack->sp]) )
  6464. s2=st->stack->stack_data[st->stack->sp].u.str;
  6465. i1=pop_val(st);
  6466. if( isstr(st->stack->stack_data[st->stack->sp]) )
  6467. s1=st->stack->stack_data[st->stack->sp].u.str;
  6468. if( s1!=NULL && s2!=NULL ){
  6469. // ss => op_2str
  6470. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  6471. }else if( s1==NULL && s2==NULL ){
  6472. // ii => op_2num
  6473. op_2num(st,op,i1,i2);
  6474. }else{
  6475. // si,is => error
  6476. printf("script: op_2: int&str, str&int not allow.");
  6477. push_val(st->stack,C_INT,0);
  6478. }
  6479. }
  6480. /*==========================================
  6481. * 単項演算子
  6482. *------------------------------------------
  6483. */
  6484. void op_1num(struct script_state *st,int op)
  6485. {
  6486. int i1;
  6487. i1=pop_val(st);
  6488. switch(op){
  6489. case C_NEG:
  6490. i1=-i1;
  6491. break;
  6492. case C_NOT:
  6493. i1=~i1;
  6494. break;
  6495. case C_LNOT:
  6496. i1=!i1;
  6497. break;
  6498. }
  6499. push_val(st->stack,C_INT,i1);
  6500. }
  6501. /*==========================================
  6502. * 関数の実行
  6503. *------------------------------------------
  6504. */
  6505. int run_func(struct script_state *st)
  6506. {
  6507. int i,start_sp,end_sp,func;
  6508. end_sp=st->stack->sp;
  6509. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  6510. if(i==0){
  6511. if(battle_config.error_log)
  6512. printf("function not found\n");
  6513. // st->stack->sp=0;
  6514. st->state=END;
  6515. return 0;
  6516. }
  6517. start_sp=i-1;
  6518. st->start=i-1;
  6519. st->end=end_sp;
  6520. func=st->stack->stack_data[st->start].u.num;
  6521. if( st->stack->stack_data[st->start].type!=C_NAME || str_data[func].type!=C_FUNC ){
  6522. printf("run_func: not function and command! \n");
  6523. // st->stack->sp=0;
  6524. st->state=END;
  6525. return 0;
  6526. }
  6527. #ifdef DEBUG_RUN
  6528. if(battle_config.etc_log) {
  6529. printf("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  6530. printf("stack dump :");
  6531. for(i=0;i<end_sp;i++){
  6532. switch(st->stack->stack_data[i].type){
  6533. case C_INT:
  6534. printf(" int(%d)",st->stack->stack_data[i].u.num);
  6535. break;
  6536. case C_NAME:
  6537. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num].str);
  6538. break;
  6539. case C_ARG:
  6540. printf(" arg");
  6541. break;
  6542. case C_POS:
  6543. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  6544. break;
  6545. default:
  6546. printf(" %d,%d",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  6547. }
  6548. }
  6549. printf("\n");
  6550. }
  6551. #endif
  6552. if(str_data[func].func){
  6553. str_data[func].func(st);
  6554. } else {
  6555. if(battle_config.error_log)
  6556. printf("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  6557. push_val(st->stack,C_INT,0);
  6558. }
  6559. pop_stack(st->stack,start_sp,end_sp);
  6560. if(st->state==RETFUNC){
  6561. // ユーザー定義関数からの復帰
  6562. int olddefsp=st->defsp;
  6563. int i;
  6564. pop_stack(st->stack,st->defsp,start_sp); // 復帰に邪魔なスタック削除
  6565. if(st->defsp<4 || st->stack->stack_data[st->defsp-1].type!=C_RETINFO){
  6566. printf("script:run_func(return) return without callfunc or callsub!\n");
  6567. st->state=END;
  6568. return 0;
  6569. }
  6570. i = conv_num(st,& (st->stack->stack_data[st->defsp-4])); // 引数の数所得
  6571. st->pos=conv_num(st,& (st->stack->stack_data[st->defsp-1])); // スクリプト位置の復元
  6572. st->script=(char*)conv_num(st,& (st->stack->stack_data[st->defsp-2])); // スクリプトを復元
  6573. st->defsp=conv_num(st,& (st->stack->stack_data[st->defsp-3])); // 基準スタックポインタを復元
  6574. pop_stack(st->stack,olddefsp-4-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  6575. st->state=GOTO;
  6576. }
  6577. return 0;
  6578. }
  6579. /*==========================================
  6580. * スクリプトの実行メイン部分
  6581. *------------------------------------------
  6582. */
  6583. int run_script_main(char *script,int pos,int rid,int oid,struct script_state *st,char *rootscript)
  6584. {
  6585. int c,rerun_pos;
  6586. int cmdcount=script_config.check_cmdcount;
  6587. int gotocount=script_config.check_gotocount;
  6588. struct script_stack *stack=st->stack;
  6589. st->defsp=stack->sp;
  6590. st->script=script;
  6591. rerun_pos=st->pos;
  6592. for(st->state=0;st->state==0;){
  6593. switch(c=get_com(script,&st->pos)){
  6594. case C_EOL:
  6595. if(stack->sp!=st->defsp){
  6596. if(battle_config.error_log)
  6597. printf("stack.sp(%d) != default(%d)\n",stack->sp,st->defsp);
  6598. stack->sp=st->defsp;
  6599. }
  6600. rerun_pos=st->pos;
  6601. break;
  6602. case C_INT:
  6603. push_val(stack,C_INT,get_num(script,&st->pos));
  6604. break;
  6605. case C_POS:
  6606. case C_NAME:
  6607. push_val(stack,c,(*(int*)(script+st->pos))&0xffffff);
  6608. st->pos+=3;
  6609. break;
  6610. case C_ARG:
  6611. push_val(stack,c,0);
  6612. break;
  6613. case C_STR:
  6614. push_str(stack,C_CONSTSTR,script+st->pos);
  6615. while(script[st->pos++]);
  6616. break;
  6617. case C_FUNC:
  6618. run_func(st);
  6619. if(st->state==GOTO){
  6620. rerun_pos=st->pos;
  6621. script=st->script;
  6622. st->state=0;
  6623. if( gotocount>0 && (--gotocount)<=0 ){
  6624. printf("run_script: infinity loop !\n");
  6625. st->state=END;
  6626. }
  6627. }
  6628. break;
  6629. case C_ADD:
  6630. op_add(st);
  6631. break;
  6632. case C_SUB:
  6633. case C_MUL:
  6634. case C_DIV:
  6635. case C_MOD:
  6636. case C_EQ:
  6637. case C_NE:
  6638. case C_GT:
  6639. case C_GE:
  6640. case C_LT:
  6641. case C_LE:
  6642. case C_AND:
  6643. case C_OR:
  6644. case C_XOR:
  6645. case C_LAND:
  6646. case C_LOR:
  6647. case C_R_SHIFT:
  6648. case C_L_SHIFT:
  6649. op_2(st,c);
  6650. break;
  6651. case C_NEG:
  6652. case C_NOT:
  6653. case C_LNOT:
  6654. op_1num(st,c);
  6655. break;
  6656. case C_NOP:
  6657. st->state=END;
  6658. break;
  6659. default:
  6660. if(battle_config.error_log)
  6661. printf("unknown command : %d @ %d\n",c,pos);
  6662. st->state=END;
  6663. break;
  6664. }
  6665. if( cmdcount>0 && (--cmdcount)<=0 ){
  6666. printf("run_script: infinity loop !\n");
  6667. st->state=END;
  6668. }
  6669. }
  6670. switch(st->state){
  6671. case STOP:
  6672. break;
  6673. case END:
  6674. {
  6675. struct map_session_data *sd=map_id2sd(st->rid);
  6676. st->pos=-1;
  6677. if(sd && sd->npc_id==st->oid)
  6678. npc_event_dequeue(sd);
  6679. }
  6680. break;
  6681. case RERUNLINE:
  6682. {
  6683. st->pos=rerun_pos;
  6684. }
  6685. break;
  6686. }
  6687. if( st->state!=END){
  6688. // 再開するためにスタック情報を保存
  6689. struct map_session_data *sd=map_id2sd(st->rid);
  6690. if(sd/* && sd->npc_stackbuf==NULL*/){
  6691. if( sd->npc_stackbuf )
  6692. aFree( sd->npc_stackbuf );
  6693. sd->npc_stackbuf = (char *)aCalloc(sizeof(stack->stack_data[0])*stack->sp_max,sizeof(char));
  6694. memcpy(sd->npc_stackbuf, stack->stack_data, sizeof(stack->stack_data[0]) * stack->sp_max);
  6695. sd->npc_stack = stack->sp;
  6696. sd->npc_stackmax = stack->sp_max;
  6697. sd->npc_script=script;
  6698. sd->npc_scriptroot=rootscript;
  6699. }
  6700. }
  6701. return 0;
  6702. }
  6703. /*==========================================
  6704. * スクリプトの実行
  6705. *------------------------------------------
  6706. */
  6707. int run_script(char *script,int pos,int rid,int oid)
  6708. {
  6709. struct script_stack stack;
  6710. struct script_state st;
  6711. struct map_session_data *sd=map_id2sd(rid);
  6712. char *rootscript=script;
  6713. if(script==NULL || pos<0)
  6714. return -1;
  6715. if(sd && sd->npc_stackbuf && sd->npc_scriptroot==rootscript){
  6716. // 前回のスタックを復帰
  6717. script=sd->npc_script;
  6718. stack.sp=sd->npc_stack;
  6719. stack.sp_max=sd->npc_stackmax;
  6720. stack.stack_data=(struct script_data *)aCalloc(stack.sp_max,sizeof(stack.stack_data[0]));
  6721. memcpy(stack.stack_data,sd->npc_stackbuf,sizeof(stack.stack_data[0])*stack.sp_max);
  6722. aFree(sd->npc_stackbuf);
  6723. sd->npc_stackbuf=NULL;
  6724. }else{
  6725. // スタック初期化
  6726. stack.sp=0;
  6727. stack.sp_max=64;
  6728. stack.stack_data=(struct script_data *)aCalloc(stack.sp_max,sizeof(stack.stack_data[0]));
  6729. }
  6730. st.stack=&stack;
  6731. st.pos=pos;
  6732. st.rid=rid;
  6733. st.oid=oid;
  6734. run_script_main(script,pos,rid,oid,&st,rootscript);
  6735. aFree(stack.stack_data);
  6736. stack.stack_data=NULL;
  6737. return st.pos;
  6738. }
  6739. /*==========================================
  6740. * マップ変数の変更
  6741. *------------------------------------------
  6742. */
  6743. int mapreg_setreg(int num,int val)
  6744. {
  6745. if(val!=0)
  6746. numdb_insert(mapreg_db,num,val);
  6747. else
  6748. numdb_erase(mapreg_db,num);
  6749. mapreg_dirty=1;
  6750. return 0;
  6751. }
  6752. /*==========================================
  6753. * 文字列型マップ変数の変更
  6754. *------------------------------------------
  6755. */
  6756. int mapreg_setregstr(int num,const char *str)
  6757. {
  6758. char *p;
  6759. if( (p=numdb_search(mapregstr_db,num))!=NULL )
  6760. aFree(p);
  6761. if( str==NULL || *str==0 ){
  6762. numdb_erase(mapregstr_db,num);
  6763. mapreg_dirty=1;
  6764. return 0;
  6765. }
  6766. p=(char *)aCallocA(strlen(str)+1, sizeof(char));
  6767. strcpy(p,str);
  6768. numdb_insert(mapregstr_db,num,p);
  6769. mapreg_dirty=1;
  6770. return 0;
  6771. }
  6772. /*==========================================
  6773. * 永続的マップ変数の読み込み
  6774. *------------------------------------------
  6775. */
  6776. static int script_load_mapreg()
  6777. {
  6778. FILE *fp;
  6779. char line[1024];
  6780. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  6781. return -1;
  6782. while(fgets(line,sizeof(line),fp)){
  6783. char buf1[256],buf2[1024],*p;
  6784. int n,v,s,i;
  6785. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  6786. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  6787. continue;
  6788. if( buf1[strlen(buf1)-1]=='$' ){
  6789. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  6790. printf("%s: %s broken data !\n",mapreg_txt,buf1);
  6791. continue;
  6792. }
  6793. p=(char *)aCallocA(strlen(buf2) + 1,sizeof(char));
  6794. strcpy(p,buf2);
  6795. s=add_str(buf1);
  6796. numdb_insert(mapregstr_db,(i<<24)|s,p);
  6797. }else{
  6798. if( sscanf(line+n,"%d",&v)!=1 ){
  6799. printf("%s: %s broken data !\n",mapreg_txt,buf1);
  6800. continue;
  6801. }
  6802. s=add_str(buf1);
  6803. numdb_insert(mapreg_db,(i<<24)|s,v);
  6804. }
  6805. }
  6806. fclose(fp);
  6807. mapreg_dirty=0;
  6808. return 0;
  6809. }
  6810. /*==========================================
  6811. * 永続的マップ変数の書き込み
  6812. *------------------------------------------
  6813. */
  6814. static int script_save_mapreg_intsub(void *key,void *data,va_list ap)
  6815. {
  6816. FILE *fp=va_arg(ap,FILE*);
  6817. int num=((int)key)&0x00ffffff, i=((int)key)>>24;
  6818. char *name=str_buf+str_data[num].str;
  6819. if( name[1]!='@' ){
  6820. if(i==0)
  6821. fprintf(fp,"%s\t%d\n", name, (int)data);
  6822. else
  6823. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  6824. }
  6825. return 0;
  6826. }
  6827. static int script_save_mapreg_strsub(void *key,void *data,va_list ap)
  6828. {
  6829. FILE *fp=va_arg(ap,FILE*);
  6830. int num=((int)key)&0x00ffffff, i=((int)key)>>24;
  6831. char *name=str_buf+str_data[num].str;
  6832. if( name[1]!='@' ){
  6833. if(i==0)
  6834. fprintf(fp,"%s\t%s\n", name, (char *)data);
  6835. else
  6836. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  6837. }
  6838. return 0;
  6839. }
  6840. static int script_save_mapreg()
  6841. {
  6842. FILE *fp;
  6843. int lock;
  6844. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL )
  6845. return -1;
  6846. numdb_foreach(mapreg_db,script_save_mapreg_intsub,fp);
  6847. numdb_foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  6848. lock_fclose(fp,mapreg_txt,&lock);
  6849. mapreg_dirty=0;
  6850. return 0;
  6851. }
  6852. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  6853. {
  6854. if(mapreg_dirty)
  6855. script_save_mapreg();
  6856. return 0;
  6857. }
  6858. /*==========================================
  6859. *
  6860. *------------------------------------------
  6861. */
  6862. static int set_posword(char *p)
  6863. {
  6864. char* np,* str[15];
  6865. int i=0;
  6866. for(i=0;i<11;i++) {
  6867. if((np=strchr(p,','))!=NULL) {
  6868. str[i]=p;
  6869. *np=0;
  6870. p=np+1;
  6871. } else {
  6872. str[i]=p;
  6873. p+=strlen(p);
  6874. }
  6875. if(str[i])
  6876. strcpy(pos[i],str[i]);
  6877. }
  6878. return 0;
  6879. }
  6880. int script_config_read(char *cfgName)
  6881. {
  6882. int i;
  6883. char line[1024],w1[1024],w2[1024];
  6884. FILE *fp;
  6885. script_config.warn_func_no_comma=1;
  6886. script_config.warn_cmd_no_comma=1;
  6887. script_config.warn_func_mismatch_paramnum=1;
  6888. script_config.warn_cmd_mismatch_paramnum=1;
  6889. script_config.check_cmdcount=65535;
  6890. script_config.check_gotocount=2048;
  6891. script_config.die_event_name = (char *)aCallocA(24,sizeof(char));
  6892. script_config.kill_event_name = (char *)aCallocA(24,sizeof(char));
  6893. script_config.login_event_name = (char *)aCallocA(24,sizeof(char));
  6894. script_config.logout_event_name = (char *)aCallocA(24,sizeof(char));
  6895. script_config.event_script_type = 0;
  6896. script_config.event_requires_trigger = 1;
  6897. fp=fopen(cfgName,"r");
  6898. if(fp==NULL){
  6899. printf("file not found: %s\n",cfgName);
  6900. return 1;
  6901. }
  6902. while(fgets(line,1020,fp)){
  6903. if(line[0] == '/' && line[1] == '/')
  6904. continue;
  6905. i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  6906. if(i!=2)
  6907. continue;
  6908. if(strcmpi(w1,"refine_posword")==0) {
  6909. set_posword(w2);
  6910. }
  6911. else if(strcmpi(w1,"warn_func_no_comma")==0) {
  6912. script_config.warn_func_no_comma = battle_config_switch(w2);
  6913. }
  6914. else if(strcmpi(w1,"warn_cmd_no_comma")==0) {
  6915. script_config.warn_cmd_no_comma = battle_config_switch(w2);
  6916. }
  6917. else if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
  6918. script_config.warn_func_mismatch_paramnum = battle_config_switch(w2);
  6919. }
  6920. else if(strcmpi(w1,"warn_cmd_mismatch_paramnum")==0) {
  6921. script_config.warn_cmd_mismatch_paramnum = battle_config_switch(w2);
  6922. }
  6923. else if(strcmpi(w1,"check_cmdcount")==0) {
  6924. script_config.check_cmdcount = battle_config_switch(w2);
  6925. }
  6926. else if(strcmpi(w1,"check_gotocount")==0) {
  6927. script_config.check_gotocount = battle_config_switch(w2);
  6928. }
  6929. else if(strcmpi(w1,"event_script_type")==0) {
  6930. script_config.event_script_type = battle_config_switch(w2);
  6931. }
  6932. else if(strcmpi(w1,"die_event_name")==0) {
  6933. strcpy(script_config.die_event_name, w2);
  6934. }
  6935. else if(strcmpi(w1,"kill_event_name")==0) {
  6936. strcpy(script_config.kill_event_name, w2);
  6937. }
  6938. else if(strcmpi(w1,"login_event_name")==0) {
  6939. strcpy(script_config.login_event_name, w2);
  6940. }
  6941. else if(strcmpi(w1,"logout_event_name")==0) {
  6942. strcpy(script_config.logout_event_name, w2);
  6943. }
  6944. else if(strcmpi(w1,"require_set_trigger")==0) {
  6945. script_config.event_requires_trigger = battle_config_switch(w2);
  6946. }
  6947. else if(strcmpi(w1,"import")==0){
  6948. script_config_read(w2);
  6949. }
  6950. }
  6951. fclose(fp);
  6952. return 0;
  6953. }
  6954. /*==========================================
  6955. * 終了
  6956. *------------------------------------------
  6957. */
  6958. static int mapreg_db_final(void *key,void *data,va_list ap)
  6959. {
  6960. return 0;
  6961. }
  6962. static int mapregstr_db_final(void *key,void *data,va_list ap)
  6963. {
  6964. aFree(data);
  6965. return 0;
  6966. }
  6967. static int scriptlabel_db_final(void *key,void *data,va_list ap)
  6968. {
  6969. return 0;
  6970. }
  6971. static int userfunc_db_final(void *key,void *data,va_list ap)
  6972. {
  6973. aFree(key);
  6974. aFree(data);
  6975. return 0;
  6976. }
  6977. int do_final_script()
  6978. {
  6979. if(mapreg_dirty>=0)
  6980. script_save_mapreg();
  6981. if(script_buf)
  6982. aFree(script_buf);
  6983. if(mapreg_db)
  6984. numdb_final(mapreg_db,mapreg_db_final);
  6985. if(mapregstr_db)
  6986. strdb_final(mapregstr_db,mapregstr_db_final);
  6987. if(scriptlabel_db)
  6988. strdb_final(scriptlabel_db,scriptlabel_db_final);
  6989. if(userfunc_db)
  6990. strdb_final(userfunc_db,userfunc_db_final);
  6991. if (str_data)
  6992. aFree(str_data);
  6993. if (str_buf)
  6994. aFree(str_buf);
  6995. if (script_config.die_event_name)
  6996. aFree(script_config.die_event_name);
  6997. if (script_config.kill_event_name)
  6998. aFree(script_config.kill_event_name);
  6999. if (script_config.login_event_name)
  7000. aFree(script_config.login_event_name);
  7001. if (script_config.logout_event_name)
  7002. aFree(script_config.logout_event_name);
  7003. return 0;
  7004. }
  7005. /*==========================================
  7006. * 初期化
  7007. *------------------------------------------
  7008. */
  7009. int do_init_script()
  7010. {
  7011. mapreg_db=numdb_init();
  7012. mapregstr_db=numdb_init();
  7013. script_load_mapreg();
  7014. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  7015. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  7016. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  7017. scriptlabel_db=strdb_init(50);
  7018. return 0;
  7019. }