script.c 180 KB

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