script.c 334 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. //#define DEBUG_FUNCIN
  4. //#define DEBUG_DISP
  5. //#define DEBUG_RUN
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <math.h>
  11. #include <limits.h>
  12. #ifndef _WIN32
  13. #include <sys/time.h>
  14. #endif
  15. #include <time.h>
  16. #include <setjmp.h>
  17. #include "../common/socket.h"
  18. #include "../common/timer.h"
  19. #include "../common/malloc.h"
  20. #include "../common/lock.h"
  21. #include "../common/nullpo.h"
  22. #include "../common/showmsg.h"
  23. #include "../common/strlib.h"
  24. #include "map.h"
  25. #include "clif.h"
  26. #include "chrif.h"
  27. #include "itemdb.h"
  28. #include "pc.h"
  29. #include "status.h"
  30. #include "script.h"
  31. #include "storage.h"
  32. #include "mob.h"
  33. #include "npc.h"
  34. #include "pet.h"
  35. #include "mercenary.h" //[orn]
  36. #include "intif.h"
  37. #include "skill.h"
  38. #include "chat.h"
  39. #include "battle.h"
  40. #include "party.h"
  41. #include "guild.h"
  42. #include "atcommand.h"
  43. #include "charcommand.h"
  44. #include "log.h"
  45. #include "unit.h"
  46. #include "irc.h"
  47. #include "pet.h"
  48. #define FETCH(n, t) \
  49. if(st->end>st->start+(n)) \
  50. (t)=conv_num(st,&(st->stack->stack_data[st->start+(n)]));
  51. #define SCRIPT_BLOCK_SIZE 512
  52. enum { LABEL_NEXTLINE=1,LABEL_START };
  53. static unsigned char * script_buf = NULL;
  54. static int script_pos,script_size;
  55. static char *str_buf;
  56. static int str_pos,str_size;
  57. static struct str_data_struct {
  58. int type;
  59. int str;
  60. int backpatch;
  61. int label;
  62. int (*func)(struct script_state *st);
  63. int val;
  64. int next;
  65. } *str_data = NULL;
  66. int str_num=LABEL_START,str_data_size;
  67. int str_hash[16];
  68. static struct dbt *mapreg_db=NULL;
  69. static struct dbt *mapregstr_db=NULL;
  70. static int mapreg_dirty=-1;
  71. char mapreg_txt[256]="save/mapreg.txt";
  72. #define MAPREG_AUTOSAVE_INTERVAL (300*1000)
  73. static struct dbt *scriptlabel_db=NULL;
  74. static struct dbt *userfunc_db=NULL;
  75. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  76. struct dbt* script_get_userfunc_db(){ return userfunc_db; }
  77. static char pos[11][100] = {"頭","体","左手","右手","ローブ","靴","アクセサリー1","アクセサリー2","頭2","頭3","装着していない"};
  78. struct Script_Config script_config;
  79. static int parse_cmd;
  80. static jmp_buf error_jump;
  81. static char* error_msg;
  82. static char* error_pos;
  83. // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
  84. // [Eoe / jA 1080, 1081, 1094, 1164]
  85. enum { TYPE_NULL = 0 , TYPE_IF , TYPE_SWITCH , TYPE_WHILE , TYPE_FOR , TYPE_DO , TYPE_USERFUNC};
  86. static struct {
  87. struct {
  88. int type;
  89. int index;
  90. int count;
  91. int flag;
  92. } curly[256]; // 右カッコの情報
  93. int curly_count; // 右カッコの数
  94. int index; // スクリプト内で使用した構文の数
  95. } syntax;
  96. unsigned char* parse_curly_close(unsigned char *p);
  97. unsigned char* parse_syntax_close(unsigned char *p);
  98. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag);
  99. unsigned char* parse_syntax(unsigned char *p);
  100. static int parse_syntax_for_flag = 0;
  101. extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
  102. int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
  103. int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
  104. int potion_target=0;
  105. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  106. // [zBuffer] SQL Mapreg Saving/Loading Database Declaration
  107. char mapregsql_db[32] = "mapreg";
  108. char mapregsql_db_varname[32] = "varname";
  109. char mapregsql_db_index[32] = "index";
  110. char mapregsql_db_value[32] = "value";
  111. char tmp_sql[65535];
  112. // --------------------------------------------------------
  113. #endif
  114. int get_com(unsigned char *script,int *pos);
  115. int get_num(unsigned char *script,int *pos);
  116. extern struct script_function {
  117. int (*func)(struct script_state *st);
  118. char *name;
  119. char *arg;
  120. } buildin_func[];
  121. static struct linkdb_node *sleep_db;
  122. #define not_server_variable(prefix) (prefix != '$' && prefix != '.')
  123. /*==========================================
  124. * ローカルプロトタイプ宣言 (必要な物のみ)
  125. *------------------------------------------
  126. */
  127. unsigned char* parse_subexpr(unsigned char *,int);
  128. void push_val(struct script_stack *stack,int type,int val);
  129. int run_func(struct script_state *st);
  130. int mapreg_setreg(int num,int val);
  131. int mapreg_setregstr(int num,const char *str);
  132. enum {
  133. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  134. C_NAME,C_EOL, C_RETINFO,
  135. C_USERFUNC, C_USERFUNC_POS, // user defined functions
  136. C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  137. 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
  138. };
  139. enum {
  140. MF_NOMEMO,
  141. MF_NOTELEPORT,
  142. MF_NOSAVE,
  143. MF_NOBRANCH,
  144. MF_NOPENALTY,
  145. MF_NOZENYPENALTY,
  146. MF_PVP,
  147. MF_PVP_NOPARTY,
  148. MF_PVP_NOGUILD,
  149. MF_GVG,
  150. MF_GVG_NOPARTY,
  151. MF_NOTRADE,
  152. MF_NOSKILL,
  153. MF_NOWARP,
  154. MF_FREE,
  155. MF_NOICEWALL,
  156. MF_SNOW,
  157. MF_FOG,
  158. MF_SAKURA,
  159. MF_LEAVES,
  160. MF_RAIN,
  161. MF_INDOORS,
  162. MF_NOGO,
  163. MF_CLOUDS,
  164. MF_CLOUDS2,
  165. MF_FIREWORKS,
  166. MF_GVG_CASTLE,
  167. MF_GVG_DUNGEON,
  168. MF_NIGHTENABLED,
  169. MF_NOBASEEXP,
  170. MF_NOJOBEXP,
  171. MF_NOMOBLOOT,
  172. MF_NOMVPLOOT,
  173. MF_NORETURN,
  174. MF_NOWARPTO,
  175. MF_NIGHTMAREDROP,
  176. MF_RESTRICTED,
  177. MF_NOCOMMAND,
  178. MF_NODROP,
  179. MF_JEXP,
  180. MF_BEXP,
  181. MF_NOVENDING,
  182. MF_LOADEVENT,
  183. MF_NOCHAT
  184. };
  185. //Reports on the console the src of an script error.
  186. static void report_src(struct script_state *st) {
  187. struct block_list *bl;
  188. if (!st->oid) return; //Can't report source.
  189. bl = map_id2bl(st->oid);
  190. if (!bl) return;
  191. switch (bl->type) {
  192. case BL_NPC:
  193. if (bl->m >=0)
  194. ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
  195. else
  196. ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
  197. break;
  198. default:
  199. if (bl->m >=0)
  200. ShowDebug("Source (Non-NPC): type %d at %s (%d,%d)\n", bl->type, map[bl->m].name, bl->x, bl->y);
  201. else
  202. ShowDebug("Source (Non-NPC): type %d (invisible/not on a map)\n", bl->type);
  203. break;
  204. }
  205. }
  206. static void check_event(struct script_state *st, unsigned char *event){
  207. if(event != NULL && event[0] != '\0' && !strstr(event,"::")){
  208. ShowError("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n",event);
  209. report_src(st);
  210. }
  211. return;
  212. }
  213. /*==========================================
  214. * 文字列のハッシュを計算
  215. *------------------------------------------
  216. */
  217. static int calc_hash(const unsigned char *p)
  218. {
  219. int h=0;
  220. while(*p){
  221. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  222. h+=*p++;
  223. }
  224. return h&15;
  225. }
  226. /*==========================================
  227. * str_dataの中に名前があるか検索する
  228. *------------------------------------------
  229. */
  230. // 既存のであれば番号、無ければ-1
  231. static int search_str(const unsigned char *p)
  232. {
  233. int i;
  234. i=str_hash[calc_hash(p)];
  235. while(i){
  236. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  237. return i;
  238. }
  239. i=str_data[i].next;
  240. }
  241. return -1;
  242. }
  243. /*==========================================
  244. * str_dataに名前を登録
  245. *------------------------------------------
  246. */
  247. // 既存のであれば番号、無ければ登録して新規番号
  248. int add_str(const unsigned char *p)
  249. {
  250. int i;
  251. char *lowcase;
  252. lowcase=aStrdup((char *) p);
  253. for(i=0;lowcase[i];i++)
  254. lowcase[i]=tolower(lowcase[i]);
  255. if((i=search_str((unsigned char *) lowcase))>=0){
  256. aFree(lowcase);
  257. return i;
  258. }
  259. aFree(lowcase);
  260. i=calc_hash(p);
  261. if(str_hash[i]==0){
  262. str_hash[i]=str_num;
  263. } else {
  264. i=str_hash[i];
  265. for(;;){
  266. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  267. return i;
  268. }
  269. if(str_data[i].next==0)
  270. break;
  271. i=str_data[i].next;
  272. }
  273. str_data[i].next=str_num;
  274. }
  275. if(str_num>=str_data_size){
  276. str_data_size+=128;
  277. str_data=aRealloc(str_data,sizeof(str_data[0])*str_data_size);
  278. memset(str_data + (str_data_size - 128), '\0', 128);
  279. }
  280. while(str_pos+(int)strlen((char *) p)+1>=str_size){
  281. str_size+=256;
  282. str_buf=(char *)aRealloc(str_buf,str_size);
  283. memset(str_buf + (str_size - 256), '\0', 256);
  284. }
  285. strcpy(str_buf+str_pos, (char *) p);
  286. str_data[str_num].type=C_NOP;
  287. str_data[str_num].str=str_pos;
  288. str_data[str_num].next=0;
  289. str_data[str_num].func=NULL;
  290. str_data[str_num].backpatch=-1;
  291. str_data[str_num].label=-1;
  292. str_pos+=(int)strlen( (char *) p)+1;
  293. return str_num++;
  294. }
  295. /*==========================================
  296. * スクリプトバッファサイズの確認と拡張
  297. *------------------------------------------
  298. */
  299. static void check_script_buf(int size)
  300. {
  301. if(script_pos+size>=script_size){
  302. script_size+=SCRIPT_BLOCK_SIZE;
  303. script_buf=(unsigned char *)aRealloc(script_buf,script_size);
  304. memset(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  305. SCRIPT_BLOCK_SIZE);
  306. }
  307. }
  308. /*==========================================
  309. * スクリプトバッファに1バイト書き込む
  310. *------------------------------------------
  311. */
  312. #define add_scriptb(a) if( script_pos+1>=script_size ) check_script_buf(1); script_buf[script_pos++]=(a);
  313. #if 0
  314. static void add_scriptb(int a)
  315. {
  316. check_script_buf(1);
  317. script_buf[script_pos++]=a;
  318. }
  319. #endif
  320. /*==========================================
  321. * スクリプトバッファにデータタイプを書き込む
  322. *------------------------------------------
  323. */
  324. static void add_scriptc(int a)
  325. {
  326. while(a>=0x40){
  327. add_scriptb((a&0x3f)|0x40);
  328. a=(a-0x40)>>6;
  329. }
  330. add_scriptb(a&0x3f);
  331. }
  332. /*==========================================
  333. * スクリプトバッファに整数を書き込む
  334. *------------------------------------------
  335. */
  336. static void add_scripti(int a)
  337. {
  338. while(a>=0x40){
  339. add_scriptb(a|0xc0);
  340. a=(a-0x40)>>6;
  341. }
  342. add_scriptb(a|0x80);
  343. }
  344. /*==========================================
  345. * スクリプトバッファにラベル/変数/関数を書き込む
  346. *------------------------------------------
  347. */
  348. // 最大16Mまで
  349. static void add_scriptl(int l)
  350. {
  351. int backpatch = str_data[l].backpatch;
  352. switch(str_data[l].type){
  353. case C_POS:
  354. case C_USERFUNC_POS:
  355. add_scriptc(C_POS);
  356. add_scriptb(str_data[l].label);
  357. add_scriptb(str_data[l].label>>8);
  358. add_scriptb(str_data[l].label>>16);
  359. break;
  360. case C_NOP:
  361. case C_USERFUNC:
  362. // ラベルの可能性があるのでbackpatch用データ埋め込み
  363. add_scriptc(C_NAME);
  364. str_data[l].backpatch=script_pos;
  365. add_scriptb(backpatch);
  366. add_scriptb(backpatch>>8);
  367. add_scriptb(backpatch>>16);
  368. break;
  369. case C_INT:
  370. add_scripti(str_data[l].val);
  371. break;
  372. default:
  373. // もう他の用途と確定してるので数字をそのまま
  374. add_scriptc(C_NAME);
  375. add_scriptb(l);
  376. add_scriptb(l>>8);
  377. add_scriptb(l>>16);
  378. break;
  379. }
  380. }
  381. /*==========================================
  382. * ラベルを解決する
  383. *------------------------------------------
  384. */
  385. void set_label(int l,int pos)
  386. {
  387. int i,next;
  388. str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  389. str_data[l].label=pos;
  390. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  391. next=(*(int*)(script_buf+i)) & 0x00ffffff;
  392. script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  393. script_buf[i]=pos;
  394. script_buf[i+1]=pos>>8;
  395. script_buf[i+2]=pos>>16;
  396. i=next;
  397. }
  398. }
  399. /*==========================================
  400. * スペース/コメント読み飛ばし
  401. *------------------------------------------
  402. */
  403. static unsigned char *skip_space(unsigned char *p)
  404. {
  405. while(1){
  406. while(isspace(*p))
  407. p++;
  408. if(p[0]=='/' && p[1]=='/'){
  409. while(*p && *p!='\n')
  410. p++;
  411. } else if(p[0]=='/' && p[1]=='*'){
  412. p++;
  413. while(*p && (p[-1]!='*' || p[0]!='/'))
  414. p++;
  415. if(*p) p++;
  416. } else
  417. break;
  418. }
  419. return p;
  420. }
  421. /*==========================================
  422. * 1単語スキップ
  423. *------------------------------------------
  424. */
  425. static unsigned char *skip_word(unsigned char *p)
  426. {
  427. // prefix
  428. if(*p=='.') p++;
  429. if(*p=='$') p++; // MAP鯖内共有変数用
  430. if(*p=='@') p++; // 一時的変数用(like weiss)
  431. if(*p=='#') p++; // account変数用
  432. if(*p=='#') p++; // ワールドaccount変数用
  433. while(isalnum(*p)||*p=='_'|| *p>=0x81) {
  434. if(*p>=0x81 && p[1]){
  435. p+=2;
  436. } else
  437. p++;
  438. }
  439. // postfix
  440. if(*p=='$') p++; // 文字列変数
  441. return p;
  442. }
  443. /*==========================================
  444. * エラーメッセージ出力
  445. *------------------------------------------
  446. */
  447. static void disp_error_message(const char *mes,unsigned char *pos)
  448. {
  449. error_msg = aStrdup(mes);
  450. error_pos = pos;
  451. longjmp( error_jump, 1 );
  452. }
  453. /*==========================================
  454. * 項の解析
  455. *------------------------------------------
  456. */
  457. unsigned char* parse_simpleexpr(unsigned char *p)
  458. {
  459. int i;
  460. p=skip_space(p);
  461. #ifdef DEBUG_FUNCIN
  462. if(battle_config.etc_log)
  463. ShowDebug("parse_simpleexpr %s\n",p);
  464. #endif
  465. if(*p==';' || *p==','){
  466. disp_error_message("unexpected expr end",p);
  467. exit(1);
  468. }
  469. if(*p=='('){
  470. p=parse_subexpr(p+1,-1);
  471. p=skip_space(p);
  472. if((*p++)!=')'){
  473. disp_error_message("unmatch ')'",p);
  474. exit(1);
  475. }
  476. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  477. char *np;
  478. i=strtoul((char *) p,&np,0);
  479. add_scripti(i);
  480. p=(unsigned char *) np;
  481. } else if(*p=='"'){
  482. add_scriptc(C_STR);
  483. p++;
  484. while(*p && *p!='"'){
  485. if(p[-1]<=0x7e && *p=='\\')
  486. p++;
  487. else if(*p=='\n'){
  488. disp_error_message("unexpected newline @ string",p);
  489. exit(1);
  490. }
  491. add_scriptb(*p++);
  492. }
  493. if(!*p){
  494. disp_error_message("unexpected eof @ string",p);
  495. exit(1);
  496. }
  497. add_scriptb(0);
  498. p++; //'"'
  499. } else {
  500. int c,l;
  501. char *p2;
  502. // label , register , function etc
  503. //From what I read, jA figured a better way to handle empty parenthesis '()'
  504. if(skip_word(p)==p/* && !(*p==')' && p[-1]=='(')*/){
  505. disp_error_message("unexpected character",p);
  506. exit(1);
  507. }
  508. p2=(char *) skip_word(p);
  509. c=*p2; *p2=0; // 名前をadd_strする
  510. l=add_str(p);
  511. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  512. *p2=c;
  513. p=(unsigned char *) p2;
  514. if(str_data[l].type!=C_FUNC && c=='['){
  515. // array(name[i] => getelementofarray(name,i) )
  516. add_scriptl(search_str((unsigned char *) "getelementofarray"));
  517. add_scriptc(C_ARG);
  518. add_scriptl(l);
  519. p=parse_subexpr(p+1,-1);
  520. p=skip_space(p);
  521. if((*p++)!=']'){
  522. disp_error_message("unmatch ']'",p);
  523. exit(1);
  524. }
  525. add_scriptc(C_FUNC);
  526. } else if(str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS) {
  527. add_scriptl(search_str((unsigned char*)"callsub"));
  528. add_scriptc(C_ARG);
  529. add_scriptl(l);
  530. }else
  531. add_scriptl(l);
  532. }
  533. #ifdef DEBUG_FUNCIN
  534. if(battle_config.etc_log)
  535. ShowDebug("parse_simpleexpr end %s\n",p);
  536. #endif
  537. return p;
  538. }
  539. /*==========================================
  540. * 式の解析
  541. *------------------------------------------
  542. */
  543. unsigned char* parse_subexpr(unsigned char *p,int limit)
  544. {
  545. int op,opl,len;
  546. char *tmpp;
  547. #ifdef DEBUG_FUNCIN
  548. if(battle_config.etc_log)
  549. ShowDebug("parse_subexpr %s\n",p);
  550. #endif
  551. p=skip_space(p);
  552. if(*p=='-'){
  553. tmpp=(char *) skip_space((unsigned char *) (p+1));
  554. if(*tmpp==';' || *tmpp==','){
  555. add_scriptl(LABEL_NEXTLINE);
  556. p++;
  557. return p;
  558. }
  559. }
  560. tmpp=(char *) p;
  561. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  562. p=parse_subexpr(p+1,8);
  563. add_scriptc(op);
  564. } else
  565. p=parse_simpleexpr(p);
  566. p=skip_space(p);
  567. while((
  568. (op=C_ADD,opl=6,len=1,*p=='+') ||
  569. (op=C_SUB,opl=6,len=1,*p=='-') ||
  570. (op=C_MUL,opl=7,len=1,*p=='*') ||
  571. (op=C_DIV,opl=7,len=1,*p=='/') ||
  572. (op=C_MOD,opl=7,len=1,*p=='%') ||
  573. (op=C_FUNC,opl=9,len=1,*p=='(') ||
  574. (op=C_LAND,opl=1,len=2,*p=='&' && p[1]=='&') ||
  575. (op=C_AND,opl=5,len=1,*p=='&') ||
  576. (op=C_LOR,opl=0,len=2,*p=='|' && p[1]=='|') ||
  577. (op=C_OR,opl=4,len=1,*p=='|') ||
  578. (op=C_XOR,opl=3,len=1,*p=='^') ||
  579. (op=C_EQ,opl=2,len=2,*p=='=' && p[1]=='=') ||
  580. (op=C_NE,opl=2,len=2,*p=='!' && p[1]=='=') ||
  581. (op=C_R_SHIFT,opl=5,len=2,*p=='>' && p[1]=='>') ||
  582. (op=C_GE,opl=2,len=2,*p=='>' && p[1]=='=') ||
  583. (op=C_GT,opl=2,len=1,*p=='>') ||
  584. (op=C_L_SHIFT,opl=5,len=2,*p=='<' && p[1]=='<') ||
  585. (op=C_LE,opl=2,len=2,*p=='<' && p[1]=='=') ||
  586. (op=C_LT,opl=2,len=1,*p=='<')) && opl>limit){
  587. p+=len;
  588. if(op==C_FUNC){
  589. int i=0,func=parse_cmd;
  590. const char *plist[128];
  591. if(str_data[parse_cmd].type == C_FUNC){
  592. // 通常の関数
  593. add_scriptc(C_ARG);
  594. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  595. // ユーザー定義関数呼び出し
  596. parse_cmd = search_str((unsigned char*)"callsub");
  597. i++;
  598. } else {
  599. disp_error_message(
  600. "expect command, missing function name or calling undeclared function",(unsigned char *) tmpp
  601. );
  602. exit(0);
  603. }
  604. func=parse_cmd;
  605. while(*p && *p!=')' && i<128) {
  606. plist[i]=(char *) p;
  607. p=parse_subexpr(p,-1);
  608. p=skip_space(p);
  609. if(*p==',') p++;
  610. else if(*p!=')' && script_config.warn_func_no_comma){
  611. disp_error_message("expect ',' or ')' at func params",p);
  612. }
  613. p=skip_space(p);
  614. i++;
  615. };
  616. plist[i]=(char *) p;
  617. if(*(p++)!=')'){
  618. disp_error_message("func request '(' ')'",p);
  619. exit(1);
  620. }
  621. if( str_data[func].type==C_FUNC && script_config.warn_func_mismatch_paramnum){
  622. const char *arg = buildin_func[str_data[func].val].arg;
  623. int j = 0;
  624. for (; arg[j]; j++) if (arg[j] == '*') break;
  625. if (!(i <= 1 && j == 0) && ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j))) {
  626. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  627. }
  628. }
  629. } else {
  630. p=parse_subexpr(p,opl);
  631. }
  632. add_scriptc(op);
  633. p=skip_space(p);
  634. }
  635. #ifdef DEBUG_FUNCIN
  636. if(battle_config.etc_log)
  637. ShowDebug("parse_subexpr end %s\n",p);
  638. #endif
  639. return p; /* return first untreated operator */
  640. }
  641. /*==========================================
  642. * 式の評価
  643. *------------------------------------------
  644. */
  645. unsigned char* parse_expr(unsigned char *p)
  646. {
  647. #ifdef DEBUG_FUNCIN
  648. if(battle_config.etc_log)
  649. ShowDebug("parse_expr %s\n",p);
  650. #endif
  651. switch(*p){
  652. case ')': case ';': case ':': case '[': case ']':
  653. case '}':
  654. disp_error_message("unexpected char",p);
  655. exit(1);
  656. }
  657. if(*p == '(') {
  658. unsigned char *p2 = skip_space(p + 1);
  659. if(*p2 == ')') {
  660. return p2 + 1;
  661. }
  662. }
  663. p=parse_subexpr(p,-1);
  664. #ifdef DEBUG_FUNCIN
  665. if(battle_config.etc_log)
  666. ShowDebug("parse_expr end %s\n",p);
  667. #endif
  668. return p;
  669. }
  670. /*==========================================
  671. * 行の解析
  672. *------------------------------------------
  673. */
  674. unsigned char* parse_line(unsigned char *p)
  675. {
  676. int i=0,cmd;
  677. const char *plist[128];
  678. unsigned char *p2;
  679. char end;
  680. p=skip_space(p);
  681. if(*p==';') {
  682. // if(); for(); while(); のために閉じ判定
  683. p = parse_syntax_close(p);
  684. return p+1;
  685. }
  686. if(*p==')' && parse_syntax_for_flag)
  687. return p+1;
  688. p = skip_space(p);
  689. if(p[0] == '{') {
  690. syntax.curly[syntax.curly_count].type = TYPE_NULL;
  691. syntax.curly[syntax.curly_count].count = -1;
  692. syntax.curly[syntax.curly_count].index = -1;
  693. syntax.curly_count++;
  694. return p + 1;
  695. } else if(p[0] == '}') {
  696. return parse_curly_close(p);
  697. }
  698. // 構文関連の処理
  699. p2 = parse_syntax(p);
  700. if(p2 != NULL) { return p2; }
  701. // 最初は関数名
  702. p2=(char *) p;
  703. p=parse_simpleexpr(p);
  704. p=skip_space(p);
  705. if(str_data[parse_cmd].type == C_FUNC){
  706. // 通常の関数
  707. add_scriptc(C_ARG);
  708. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  709. // ユーザー定義関数呼び出し
  710. parse_cmd = search_str((unsigned char*)"callsub");
  711. i++;
  712. } else {
  713. disp_error_message(
  714. "expect command, missing function name or calling undeclared function", (unsigned char *)p2
  715. );
  716. // exit(0);
  717. }
  718. cmd=parse_cmd;
  719. if(parse_syntax_for_flag) {
  720. end = ')';
  721. } else {
  722. end = ';';
  723. }
  724. while(p && *p && *p != end && i<128){
  725. plist[i]=(char *) p;
  726. p=parse_expr(p);
  727. p=skip_space(p);
  728. // 引数区切りの,処理
  729. if(*p==',') p++;
  730. else if(*p!=end && script_config.warn_cmd_no_comma && 0 <= i ){
  731. if(parse_syntax_for_flag) {
  732. disp_error_message("expect ',' or ')' at cmd params",p);
  733. } else {
  734. disp_error_message("expect ',' or ';' at cmd params",p);
  735. }
  736. }
  737. p=skip_space(p);
  738. i++;
  739. }
  740. plist[i]=(char *) p;
  741. if(!p || *(p++)!=end){
  742. if(parse_syntax_for_flag) {
  743. disp_error_message("need ')'",p);
  744. } else {
  745. disp_error_message("need ';'",p);
  746. }
  747. exit(1);
  748. }
  749. add_scriptc(C_FUNC);
  750. // if, for , while の閉じ判定
  751. p = parse_syntax_close(p);
  752. if( str_data[cmd].type==C_FUNC && script_config.warn_cmd_mismatch_paramnum){
  753. const char *arg=buildin_func[str_data[cmd].val].arg;
  754. int j=0;
  755. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  756. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  757. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  758. }
  759. }
  760. return p;
  761. }
  762. // { ... } の閉じ処理
  763. unsigned char* parse_curly_close(unsigned char *p) {
  764. if(syntax.curly_count <= 0) {
  765. disp_error_message("unexpected string",p);
  766. return p + 1;
  767. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
  768. syntax.curly_count--;
  769. // if, for , while の閉じ判定
  770. p = parse_syntax_close(p + 1);
  771. return p;
  772. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
  773. // switch() 閉じ判定
  774. int pos = syntax.curly_count-1;
  775. unsigned char label[256];
  776. int l;
  777. // 一時変数を消す
  778. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  779. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  780. parse_line(label);
  781. syntax.curly_count--;
  782. // 無条件で終了ポインタに移動
  783. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  784. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  785. parse_line(label);
  786. syntax.curly_count--;
  787. // 現在地のラベルを付ける
  788. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  789. l=add_str(label);
  790. if(str_data[l].label!=-1){
  791. disp_error_message("dup label ",p);
  792. exit(1);
  793. }
  794. set_label(l,script_pos);
  795. if(syntax.curly[pos].flag) {
  796. // default が存在する
  797. sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
  798. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  799. parse_line(label);
  800. syntax.curly_count--;
  801. }
  802. // 終了ラベルを付ける
  803. sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
  804. l=add_str(label);
  805. if(str_data[l].label!=-1){
  806. disp_error_message("dup label ",p);
  807. exit(1);
  808. }
  809. set_label(l,script_pos);
  810. syntax.curly_count--;
  811. return p+1;
  812. } else {
  813. disp_error_message("unexpected string",p);
  814. return p + 1;
  815. }
  816. }
  817. // 構文関連の処理
  818. // break, case, continue, default, do, for, function,
  819. // if, switch, while をこの内部で処理します。
  820. unsigned char* parse_syntax(unsigned char *p) {
  821. switch(p[0]) {
  822. case 'b':
  823. if(!strncmp(p,"break",5) && !isalpha(*(p + 5))) {
  824. // break の処理
  825. char label[256];
  826. int pos = syntax.curly_count - 1;
  827. while(pos >= 0) {
  828. if(syntax.curly[pos].type == TYPE_DO) {
  829. sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
  830. break;
  831. } else if(syntax.curly[pos].type == TYPE_FOR) {
  832. sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
  833. break;
  834. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  835. sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
  836. break;
  837. } else if(syntax.curly[pos].type == TYPE_SWITCH) {
  838. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  839. break;
  840. }
  841. pos--;
  842. }
  843. if(pos < 0) {
  844. disp_error_message("unexpected 'break'",p);
  845. } else {
  846. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  847. parse_line(label);
  848. syntax.curly_count--;
  849. }
  850. p = skip_word(p);
  851. p++;
  852. // if, for , while の閉じ判定
  853. p = parse_syntax_close(p + 1);
  854. return p;
  855. }
  856. break;
  857. case 'c':
  858. if(!strncmp(p,"case",4) && !isalpha(*(p + 4))) {
  859. // case の処理
  860. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  861. disp_error_message("unexpected 'case' ",p);
  862. return p+1;
  863. } else {
  864. char *p2;
  865. char label[256];
  866. int l;
  867. int pos = syntax.curly_count-1;
  868. if(syntax.curly[pos].count != 1) {
  869. // FALLTHRU 用のジャンプ
  870. sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
  871. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  872. parse_line(label);
  873. syntax.curly_count--;
  874. // 現在地のラベルを付ける
  875. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  876. l=add_str(label);
  877. if(str_data[l].label!=-1){
  878. disp_error_message("dup label ",p);
  879. exit(1);
  880. }
  881. set_label(l,script_pos);
  882. }
  883. // switch 判定文
  884. p = skip_word(p);
  885. p = skip_space(p);
  886. p2 = p;
  887. p = skip_word(p);
  888. p = skip_space(p);
  889. if(*p != ':') {
  890. disp_error_message("expect ':'",p);
  891. exit(1);
  892. }
  893. *p = 0;
  894. sprintf(label,"if(%s != $@__SW%x_VAL) goto __SW%x_%x;",
  895. p2,syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
  896. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  897. *p = ':';
  898. // 2回parse しないとダメ
  899. p2 = parse_line(label);
  900. parse_line(p2);
  901. syntax.curly_count--;
  902. if(syntax.curly[pos].count != 1) {
  903. // FALLTHRU 終了後のラベル
  904. sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
  905. l=add_str(label);
  906. if(str_data[l].label!=-1){
  907. disp_error_message("dup label ",p);
  908. exit(1);
  909. }
  910. set_label(l,script_pos);
  911. }
  912. // 一時変数を消す
  913. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  914. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  915. parse_line(label);
  916. syntax.curly_count--;
  917. syntax.curly[pos].count++;
  918. }
  919. return p + 1;
  920. } else if(!strncmp(p,"continue",8) && !isalpha(*(p + 8))) {
  921. // continue の処理
  922. char label[256];
  923. int pos = syntax.curly_count - 1;
  924. while(pos >= 0) {
  925. if(syntax.curly[pos].type == TYPE_DO) {
  926. sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
  927. syntax.curly[pos].flag = 1; // continue 用のリンク張るフラグ
  928. break;
  929. } else if(syntax.curly[pos].type == TYPE_FOR) {
  930. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  931. break;
  932. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  933. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  934. break;
  935. }
  936. pos--;
  937. }
  938. if(pos < 0) {
  939. disp_error_message("unexpected 'continue'",p);
  940. } else {
  941. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  942. parse_line(label);
  943. syntax.curly_count--;
  944. }
  945. p = skip_word(p);
  946. p++;
  947. // if, for , while の閉じ判定
  948. p = parse_syntax_close(p + 1);
  949. return p;
  950. }
  951. break;
  952. case 'd':
  953. if(!strncmp(p,"default",7) && !isalpha(*(p + 7))) {
  954. // switch - default の処理
  955. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  956. disp_error_message("unexpected 'default'",p);
  957. return p+1;
  958. } else if(syntax.curly[syntax.curly_count - 1].flag) {
  959. disp_error_message("dup 'default'",p);
  960. return p+1;
  961. } else {
  962. char label[256];
  963. int l;
  964. int pos = syntax.curly_count-1;
  965. // 現在地のラベルを付ける
  966. p = skip_word(p);
  967. p = skip_space(p);
  968. if(*p != ':') {
  969. disp_error_message("need ':'",p);
  970. }
  971. p++;
  972. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  973. l=add_str(label);
  974. if(str_data[l].label!=-1){
  975. disp_error_message("dup label ",p);
  976. exit(1);
  977. }
  978. set_label(l,script_pos);
  979. // 無条件で次のリンクに飛ばす
  980. sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
  981. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  982. parse_line(label);
  983. syntax.curly_count--;
  984. // default のラベルを付ける
  985. sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
  986. l=add_str(label);
  987. if(str_data[l].label!=-1){
  988. disp_error_message("dup label ",p);
  989. exit(1);
  990. }
  991. set_label(l,script_pos);
  992. syntax.curly[syntax.curly_count - 1].flag = 1;
  993. syntax.curly[pos].count++;
  994. p = skip_word(p);
  995. return p + 1;
  996. }
  997. } else if(!strncmp(p,"do",2) && !isalpha(*(p + 2))) {
  998. int l;
  999. char label[256];
  1000. p=skip_word(p);
  1001. p=skip_space(p);
  1002. syntax.curly[syntax.curly_count].type = TYPE_DO;
  1003. syntax.curly[syntax.curly_count].count = 1;
  1004. syntax.curly[syntax.curly_count].index = syntax.index++;
  1005. syntax.curly[syntax.curly_count].flag = 0;
  1006. // 現在地のラベル形成する
  1007. sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
  1008. l=add_str(label);
  1009. if(str_data[l].label!=-1){
  1010. disp_error_message("dup label ",p);
  1011. exit(1);
  1012. }
  1013. set_label(l,script_pos);
  1014. syntax.curly_count++;
  1015. return p;
  1016. }
  1017. break;
  1018. case 'f':
  1019. if(!strncmp(p,"for",3) && !isalpha(*(p + 3))) {
  1020. int l;
  1021. unsigned char label[256];
  1022. int pos = syntax.curly_count;
  1023. syntax.curly[syntax.curly_count].type = TYPE_FOR;
  1024. syntax.curly[syntax.curly_count].count = 1;
  1025. syntax.curly[syntax.curly_count].index = syntax.index++;
  1026. syntax.curly[syntax.curly_count].flag = 0;
  1027. syntax.curly_count++;
  1028. p=skip_word(p);
  1029. p=skip_space(p);
  1030. if(*p != '(') {
  1031. disp_error_message("need '('",p);
  1032. return p+1;
  1033. }
  1034. p++;
  1035. // 初期化文を実行する
  1036. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1037. p=parse_line(p);
  1038. syntax.curly_count--;
  1039. // 条件判断開始のラベル形成する
  1040. sprintf(label,"__FR%x_J",syntax.curly[pos].index);
  1041. l=add_str(label);
  1042. if(str_data[l].label!=-1){
  1043. disp_error_message("dup label ",p);
  1044. exit(1);
  1045. }
  1046. set_label(l,script_pos);
  1047. p=skip_space(p);
  1048. if(*p == ';') {
  1049. // for(;;) のパターンなので必ず真
  1050. ;
  1051. } else {
  1052. // 条件が偽なら終了地点に飛ばす
  1053. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1054. add_scriptl(add_str("jump_zero"));
  1055. add_scriptc(C_ARG);
  1056. p=parse_expr(p);
  1057. p=skip_space(p);
  1058. add_scriptl(add_str(label));
  1059. add_scriptc(C_FUNC);
  1060. }
  1061. if(*p != ';') {
  1062. disp_error_message("need ';'",p);
  1063. return p+1;
  1064. }
  1065. p++;
  1066. // ループ開始に飛ばす
  1067. sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
  1068. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1069. parse_line(label);
  1070. syntax.curly_count--;
  1071. // 次のループへのラベル形成する
  1072. sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
  1073. l=add_str(label);
  1074. if(str_data[l].label!=-1){
  1075. disp_error_message("dup label ",p);
  1076. exit(1);
  1077. }
  1078. set_label(l,script_pos);
  1079. // 次のループに入る時の処理
  1080. // for 最後の ')' を ';' として扱うフラグ
  1081. parse_syntax_for_flag = 1;
  1082. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1083. p=parse_line(p);
  1084. syntax.curly_count--;
  1085. parse_syntax_for_flag = 0;
  1086. // 条件判定処理に飛ばす
  1087. sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
  1088. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1089. parse_line(label);
  1090. syntax.curly_count--;
  1091. // ループ開始のラベル付け
  1092. sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
  1093. l=add_str(label);
  1094. if(str_data[l].label!=-1){
  1095. disp_error_message("dup label ",p);
  1096. exit(1);
  1097. }
  1098. set_label(l,script_pos);
  1099. return p;
  1100. } else if(!strncmp(p,"function",8) && !isalpha(*(p + 8))) {
  1101. unsigned char *func_name;
  1102. // function
  1103. p=skip_word(p);
  1104. p=skip_space(p);
  1105. // function - name
  1106. func_name = p;
  1107. p=skip_word(p);
  1108. if(*skip_space(p) == ';') {
  1109. // 関数の宣言 - 名前を登録して終わり
  1110. unsigned char c = *p;
  1111. int l;
  1112. *p = 0;
  1113. l=add_str(func_name);
  1114. *p = c;
  1115. if(str_data[l].type == C_NOP) {
  1116. str_data[l].type = C_USERFUNC;
  1117. }
  1118. return skip_space(p) + 1;
  1119. } else {
  1120. // 関数の中身
  1121. char label[256];
  1122. unsigned char c = *p;
  1123. int l;
  1124. syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
  1125. syntax.curly[syntax.curly_count].count = 1;
  1126. syntax.curly[syntax.curly_count].index = syntax.index++;
  1127. syntax.curly[syntax.curly_count].flag = 0;
  1128. syntax.curly_count++;
  1129. // 関数終了まで飛ばす
  1130. sprintf(label,"goto __FN%x_FIN;",syntax.curly[syntax.curly_count-1].index);
  1131. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1132. parse_line(label);
  1133. syntax.curly_count--;
  1134. // 関数名のラベルを付ける
  1135. *p = 0;
  1136. l=add_str(func_name);
  1137. if(str_data[l].type == C_NOP) {
  1138. str_data[l].type = C_USERFUNC;
  1139. }
  1140. if(str_data[l].label!=-1){
  1141. *p=c;
  1142. disp_error_message("dup label ",p);
  1143. exit(1);
  1144. }
  1145. set_label(l,script_pos);
  1146. strdb_put(scriptlabel_db,func_name,(void*)script_pos); // 外部用label db登録
  1147. *p = c;
  1148. return skip_space(p);
  1149. }
  1150. }
  1151. break;
  1152. case 'i':
  1153. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1154. // if() の処理
  1155. char label[256];
  1156. p=skip_word(p);
  1157. p=skip_space(p);
  1158. syntax.curly[syntax.curly_count].type = TYPE_IF;
  1159. syntax.curly[syntax.curly_count].count = 1;
  1160. syntax.curly[syntax.curly_count].index = syntax.index++;
  1161. syntax.curly[syntax.curly_count].flag = 0;
  1162. sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
  1163. syntax.curly_count++;
  1164. add_scriptl(add_str("jump_zero"));
  1165. add_scriptc(C_ARG);
  1166. p=parse_expr(p);
  1167. p=skip_space(p);
  1168. add_scriptl(add_str(label));
  1169. add_scriptc(C_FUNC);
  1170. return p;
  1171. }
  1172. break;
  1173. case 's':
  1174. if(!strncmp(p,"switch",6) && !isalpha(*(p + 6))) {
  1175. // switch() の処理
  1176. char label[256];
  1177. syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
  1178. syntax.curly[syntax.curly_count].count = 1;
  1179. syntax.curly[syntax.curly_count].index = syntax.index++;
  1180. syntax.curly[syntax.curly_count].flag = 0;
  1181. sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
  1182. syntax.curly_count++;
  1183. add_scriptl(add_str((unsigned char*)"set"));
  1184. add_scriptc(C_ARG);
  1185. add_scriptl(add_str(label));
  1186. p=skip_word(p);
  1187. p=skip_space(p);
  1188. p=parse_expr(p);
  1189. p=skip_space(p);
  1190. if(*p != '{') {
  1191. disp_error_message("need '{'",p);
  1192. }
  1193. add_scriptc(C_FUNC);
  1194. return p + 1;
  1195. }
  1196. break;
  1197. case 'w':
  1198. if(!strncmp(p,"while",5) && !isalpha(*(p + 5))) {
  1199. int l;
  1200. char label[256];
  1201. p=skip_word(p);
  1202. p=skip_space(p);
  1203. syntax.curly[syntax.curly_count].type = TYPE_WHILE;
  1204. syntax.curly[syntax.curly_count].count = 1;
  1205. syntax.curly[syntax.curly_count].index = syntax.index++;
  1206. syntax.curly[syntax.curly_count].flag = 0;
  1207. // 条件判断開始のラベル形成する
  1208. sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
  1209. l=add_str(label);
  1210. if(str_data[l].label!=-1){
  1211. disp_error_message("dup label ",p);
  1212. exit(1);
  1213. }
  1214. set_label(l,script_pos);
  1215. // 条件が偽なら終了地点に飛ばす
  1216. sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
  1217. add_scriptl(add_str("jump_zero"));
  1218. add_scriptc(C_ARG);
  1219. p=parse_expr(p);
  1220. p=skip_space(p);
  1221. add_scriptl(add_str(label));
  1222. add_scriptc(C_FUNC);
  1223. syntax.curly_count++;
  1224. return p;
  1225. }
  1226. break;
  1227. }
  1228. return NULL;
  1229. }
  1230. unsigned char* parse_syntax_close(unsigned char *p) {
  1231. // if(...) for(...) hoge(); のように、1度閉じられたら再度閉じられるか確認する
  1232. int flag;
  1233. do {
  1234. p = parse_syntax_close_sub(p,&flag);
  1235. } while(flag);
  1236. return p;
  1237. }
  1238. // if, for , while , do の閉じ判定
  1239. // flag == 1 : 閉じられた
  1240. // flag == 0 : 閉じられない
  1241. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
  1242. unsigned char label[256];
  1243. int pos = syntax.curly_count - 1;
  1244. int l;
  1245. *flag = 1;
  1246. if(syntax.curly_count <= 0) {
  1247. *flag = 0;
  1248. return p;
  1249. } else if(syntax.curly[pos].type == TYPE_IF) {
  1250. char *p2 = p;
  1251. // if 最終場所へ飛ばす
  1252. sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
  1253. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1254. parse_line(label);
  1255. syntax.curly_count--;
  1256. // 現在地のラベルを付ける
  1257. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1258. l=add_str(label);
  1259. if(str_data[l].label!=-1){
  1260. disp_error_message("dup label ",p);
  1261. exit(1);
  1262. }
  1263. set_label(l,script_pos);
  1264. syntax.curly[pos].count++;
  1265. p = skip_space(p);
  1266. if(!syntax.curly[pos].flag && !strncmp(p,"else",4) && !isalpha(*(p + 4))) {
  1267. // else or else - if
  1268. p = skip_word(p);
  1269. p = skip_space(p);
  1270. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1271. // else - if
  1272. p=skip_word(p);
  1273. p=skip_space(p);
  1274. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1275. add_scriptl(add_str("jump_zero"));
  1276. add_scriptc(C_ARG);
  1277. p=parse_expr(p);
  1278. p=skip_space(p);
  1279. add_scriptl(add_str(label));
  1280. add_scriptc(C_FUNC);
  1281. *flag = 0;
  1282. return p;
  1283. } else {
  1284. // else
  1285. if(!syntax.curly[pos].flag) {
  1286. syntax.curly[pos].flag = 1;
  1287. *flag = 0;
  1288. return p;
  1289. }
  1290. }
  1291. }
  1292. // if 閉じ
  1293. syntax.curly_count--;
  1294. // 最終地のラベルを付ける
  1295. sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
  1296. l=add_str(label);
  1297. if(str_data[l].label!=-1){
  1298. disp_error_message("dup label ",p);
  1299. exit(1);
  1300. }
  1301. set_label(l,script_pos);
  1302. if(syntax.curly[pos].flag == 1) {
  1303. // このifに対するelseじゃないのでポインタの位置は同じ
  1304. return p2;
  1305. }
  1306. return p;
  1307. } else if(syntax.curly[pos].type == TYPE_DO) {
  1308. int l;
  1309. char label[256];
  1310. unsigned char *p2;
  1311. if(syntax.curly[pos].flag) {
  1312. // 現在地のラベル形成する(continue でここに来る)
  1313. sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
  1314. l=add_str(label);
  1315. if(str_data[l].label!=-1){
  1316. disp_error_message("dup label ",p);
  1317. exit(1);
  1318. }
  1319. set_label(l,script_pos);
  1320. }
  1321. // 条件が偽なら終了地点に飛ばす
  1322. p = skip_space(p);
  1323. p2 = skip_word(p);
  1324. if(p2 - p != 5 || strncmp("while",p,5)) {
  1325. disp_error_message("need 'while'",p);
  1326. }
  1327. p = p2;
  1328. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1329. add_scriptl(add_str("jump_zero"));
  1330. add_scriptc(C_ARG);
  1331. p=parse_expr(p);
  1332. p=skip_space(p);
  1333. add_scriptl(add_str(label));
  1334. add_scriptc(C_FUNC);
  1335. // 開始地点に飛ばす
  1336. sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
  1337. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1338. parse_line(label);
  1339. syntax.curly_count--;
  1340. // 条件終了地点のラベル形成する
  1341. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1342. l=add_str(label);
  1343. if(str_data[l].label!=-1){
  1344. disp_error_message("dup label ",p);
  1345. exit(1);
  1346. }
  1347. set_label(l,script_pos);
  1348. p = skip_space(p);
  1349. if(*p != ';') {
  1350. disp_error_message("need ';'",p);
  1351. return p+1;
  1352. }
  1353. p++;
  1354. syntax.curly_count--;
  1355. return p;
  1356. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1357. // 次のループに飛ばす
  1358. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1359. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1360. parse_line(label);
  1361. syntax.curly_count--;
  1362. // for 終了のラベル付け
  1363. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1364. l=add_str(label);
  1365. if(str_data[l].label!=-1){
  1366. disp_error_message("dup label ",p);
  1367. exit(1);
  1368. }
  1369. set_label(l,script_pos);
  1370. syntax.curly_count--;
  1371. return p;
  1372. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1373. // while 条件判断へ飛ばす
  1374. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1375. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1376. parse_line(label);
  1377. syntax.curly_count--;
  1378. // while 終了のラベル付け
  1379. sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
  1380. l=add_str(label);
  1381. if(str_data[l].label!=-1){
  1382. disp_error_message("dup label ",p);
  1383. exit(1);
  1384. }
  1385. set_label(l,script_pos);
  1386. syntax.curly_count--;
  1387. return p;
  1388. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
  1389. int pos = syntax.curly_count-1;
  1390. char label[256];
  1391. int l;
  1392. // 戻す
  1393. sprintf(label,"return;");
  1394. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1395. parse_line(label);
  1396. syntax.curly_count--;
  1397. // 現在地のラベルを付ける
  1398. sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
  1399. l=add_str(label);
  1400. if(str_data[l].label!=-1){
  1401. disp_error_message("dup label ",p);
  1402. exit(1);
  1403. }
  1404. set_label(l,script_pos);
  1405. syntax.curly_count--;
  1406. return p + 1;
  1407. } else {
  1408. *flag = 0;
  1409. return p;
  1410. }
  1411. }
  1412. /*==========================================
  1413. * 組み込み関数の追加
  1414. *------------------------------------------
  1415. */
  1416. static void add_buildin_func(void)
  1417. {
  1418. int i,n;
  1419. for(i=0;buildin_func[i].func;i++){
  1420. n=add_str((unsigned char *) buildin_func[i].name);
  1421. str_data[n].type=C_FUNC;
  1422. str_data[n].val=i;
  1423. str_data[n].func=buildin_func[i].func;
  1424. }
  1425. }
  1426. /*==========================================
  1427. * 定数データベースの読み込み
  1428. *------------------------------------------
  1429. */
  1430. static void read_constdb(void)
  1431. {
  1432. FILE *fp;
  1433. char line[1024],name[1024];
  1434. int val,n,i,type;
  1435. sprintf(line, "%s/const.txt", db_path);
  1436. fp=fopen(line, "r");
  1437. if(fp==NULL){
  1438. ShowError("can't read %s\n", line);
  1439. return ;
  1440. }
  1441. while(fgets(line,1020,fp)){
  1442. if(line[0]=='/' && line[1]=='/')
  1443. continue;
  1444. type=0;
  1445. if(sscanf(line,"%[A-Za-z0-9_],%d,%d",name,&val,&type)>=2 ||
  1446. sscanf(line,"%[A-Za-z0-9_] %d %d",name,&val,&type)>=2){
  1447. for(i=0;name[i];i++)
  1448. name[i]=tolower(name[i]);
  1449. n=add_str((const unsigned char *) name);
  1450. if(type==0)
  1451. str_data[n].type=C_INT;
  1452. else
  1453. str_data[n].type=C_PARAM;
  1454. str_data[n].val=val;
  1455. }
  1456. }
  1457. fclose(fp);
  1458. }
  1459. /*==========================================
  1460. * エラー表示
  1461. *------------------------------------------
  1462. */
  1463. const char* script_print_line( const char *p, const char *mark, int line );
  1464. void script_error(char *src,const char *file,int start_line, const char *error_msg, const char *error_pos) {
  1465. // エラーが発生した行を求める
  1466. int j;
  1467. int line = start_line;
  1468. const char *p;
  1469. const char *linestart[5] = { NULL, NULL, NULL, NULL, NULL };
  1470. for(p=src;p && *p;line++){
  1471. char *lineend=strchr(p,'\n');
  1472. if(lineend==NULL || error_pos<lineend){
  1473. break;
  1474. }
  1475. for( j = 0; j < 4; j++ ) {
  1476. linestart[j] = linestart[j+1];
  1477. }
  1478. linestart[4] = p;
  1479. p=lineend+1;
  1480. }
  1481. printf("\a\n");
  1482. printf("script error on %s line %d\n", file, line);
  1483. printf(" %s\n", error_msg);
  1484. for(j = 0; j < 5; j++ ) {
  1485. script_print_line( linestart[j], NULL, line + j - 5);
  1486. }
  1487. p = script_print_line( p, error_pos, -line);
  1488. for(j = 0; j < 5; j++) {
  1489. p = script_print_line( p, NULL, line + j + 1 );
  1490. }
  1491. }
  1492. const char* script_print_line( const char *p, const char *mark, int line ) {
  1493. int i;
  1494. if( p == NULL || !p[0] ) return NULL;
  1495. if( line < 0 )
  1496. printf("*% 5d : ", -line);
  1497. else
  1498. printf(" % 5d : ", line);
  1499. for(i=0;p[i] && p[i] != '\n';i++){
  1500. if(p + i != mark)
  1501. printf("%c",p[i]);
  1502. else
  1503. printf("\'%c\'",p[i]);
  1504. }
  1505. printf("\n");
  1506. return p+i+(p[i] == '\n' ? 1 : 0);
  1507. }
  1508. /*==========================================
  1509. * スクリプトの解析
  1510. *------------------------------------------
  1511. */
  1512. struct script_code* parse_script(unsigned char *src,const char *file,int line)
  1513. {
  1514. unsigned char *p,*tmpp;
  1515. int i;
  1516. struct script_code *code;
  1517. static int first=1;
  1518. memset(&syntax,0,sizeof(syntax));
  1519. if(first){
  1520. add_buildin_func();
  1521. read_constdb();
  1522. }
  1523. first=0;
  1524. script_buf=(unsigned char *)aCalloc(SCRIPT_BLOCK_SIZE,sizeof(unsigned char));
  1525. script_pos=0;
  1526. script_size=SCRIPT_BLOCK_SIZE;
  1527. str_data[LABEL_NEXTLINE].type=C_NOP;
  1528. str_data[LABEL_NEXTLINE].backpatch=-1;
  1529. str_data[LABEL_NEXTLINE].label=-1;
  1530. for(i=LABEL_START;i<str_num;i++){
  1531. if(
  1532. str_data[i].type==C_POS || str_data[i].type==C_NAME ||
  1533. str_data[i].type==C_USERFUNC || str_data[i].type == C_USERFUNC_POS
  1534. ){
  1535. str_data[i].type=C_NOP;
  1536. str_data[i].backpatch=-1;
  1537. str_data[i].label=-1;
  1538. }
  1539. }
  1540. //Labels must be reparsed for the script....
  1541. scriptlabel_db->clear(scriptlabel_db, NULL);
  1542. if( setjmp( error_jump ) != 0 ) {
  1543. //Restore program state when script has problems. [from jA]
  1544. script_error(src,file,line,error_msg,error_pos);
  1545. aFree( error_msg );
  1546. aFree( script_buf );
  1547. script_pos = 0;
  1548. script_size = 0;
  1549. script_buf = NULL;
  1550. for(i=LABEL_START;i<str_num;i++){
  1551. if(str_data[i].type == C_NOP) str_data[i].type = C_NAME;
  1552. }
  1553. return NULL;
  1554. }
  1555. p=src;
  1556. p=skip_space(p);
  1557. if(*p!='{'){
  1558. disp_error_message("not found '{'",p);
  1559. exit(1);
  1560. }
  1561. p++;
  1562. p = skip_space(p);
  1563. if (p && *p == '}') {
  1564. // an empty function, just return
  1565. aFree( script_buf );
  1566. script_pos = 0;
  1567. script_size = 0;
  1568. script_buf = NULL;
  1569. return NULL;
  1570. }
  1571. while (p && *p && (*p!='}' || syntax.curly_count != 0)) {
  1572. p=skip_space(p);
  1573. // labelだけ特殊処理
  1574. tmpp=skip_space(skip_word(p));
  1575. if(*tmpp==':' && !(!strncmp(p,"default:",8) && p + 7 == tmpp)){
  1576. int l,c;
  1577. c=*skip_word(p);
  1578. *skip_word(p)=0;
  1579. if(*p == 0) {
  1580. *skip_word(p)=c;
  1581. disp_error_message("label length 0 ",p);
  1582. exit(1);
  1583. }
  1584. l=add_str(p);
  1585. if(str_data[l].label!=-1){
  1586. *skip_word(p)=c;
  1587. disp_error_message("dup label ",p);
  1588. exit(1);
  1589. }
  1590. set_label(l,script_pos);
  1591. strdb_put(scriptlabel_db, p, (void*)script_pos); // 外部用label db登録
  1592. *skip_word(p)=c;
  1593. p=tmpp+1;
  1594. continue;
  1595. }
  1596. // 他は全部一緒くた
  1597. p=parse_line(p);
  1598. p=skip_space(p);
  1599. add_scriptc(C_EOL);
  1600. set_label(LABEL_NEXTLINE,script_pos);
  1601. str_data[LABEL_NEXTLINE].type=C_NOP;
  1602. str_data[LABEL_NEXTLINE].backpatch=-1;
  1603. str_data[LABEL_NEXTLINE].label=-1;
  1604. }
  1605. add_scriptc(C_NOP);
  1606. script_size = script_pos;
  1607. script_buf=(unsigned char *)aRealloc(script_buf,script_pos);
  1608. // 未解決のラベルを解決
  1609. for(i=LABEL_START;i<str_num;i++){
  1610. if(str_data[i].type==C_NOP){
  1611. int j,next;
  1612. str_data[i].type=C_NAME;
  1613. str_data[i].label=i;
  1614. for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
  1615. next=(*(int*)(script_buf+j)) & 0x00ffffff;
  1616. script_buf[j]=i;
  1617. script_buf[j+1]=i>>8;
  1618. script_buf[j+2]=i>>16;
  1619. j=next;
  1620. }
  1621. }
  1622. }
  1623. #ifdef DEBUG_DISP
  1624. for(i=0;i<script_pos;i++){
  1625. if((i&15)==0) printf("%04x : ",i);
  1626. printf("%02x ",script_buf[i]);
  1627. if((i&15)==15) printf("\n");
  1628. }
  1629. printf("\n");
  1630. #endif
  1631. code = aCalloc(1, sizeof(struct script_code));
  1632. code->script_buf = script_buf;
  1633. code->script_size = script_size;
  1634. code->script_vars = NULL;
  1635. return code;
  1636. }
  1637. //
  1638. // 実行系
  1639. //
  1640. enum {RUN = 0,STOP,END,RERUNLINE,GOTO,RETFUNC};
  1641. /*==========================================
  1642. * ridからsdへの解決
  1643. *------------------------------------------
  1644. */
  1645. struct map_session_data *script_rid2sd(struct script_state *st)
  1646. {
  1647. struct map_session_data *sd=map_id2sd(st->rid);
  1648. if(!sd){
  1649. ShowError("script_rid2sd: fatal error ! player not attached!\n");
  1650. report_src(st);
  1651. }
  1652. return sd;
  1653. }
  1654. /*==========================================
  1655. * 変数の読み取り
  1656. *------------------------------------------
  1657. */
  1658. int get_val(struct script_state*st,struct script_data* data)
  1659. {
  1660. struct map_session_data *sd=NULL;
  1661. if(data->type==C_NAME){
  1662. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  1663. char prefix=*name;
  1664. char postfix=name[strlen(name)-1];
  1665. if(not_server_variable(prefix)){
  1666. if((sd=script_rid2sd(st))==NULL)
  1667. ShowError("get_val error name?:%s\n",name);
  1668. }
  1669. if(postfix=='$'){
  1670. data->type=C_CONSTSTR;
  1671. if( prefix=='@'){
  1672. if(sd)
  1673. data->u.str = pc_readregstr(sd,data->u.num);
  1674. }else if(prefix=='$'){
  1675. data->u.str = (char *)idb_get(mapregstr_db,data->u.num);
  1676. }else if(prefix=='#'){
  1677. if( name[1]=='#'){
  1678. if(sd)
  1679. data->u.str = pc_readaccountreg2str(sd,name);
  1680. }else{
  1681. if(sd)
  1682. data->u.str = pc_readaccountregstr(sd,name);
  1683. }
  1684. }else if(prefix=='.') {
  1685. struct linkdb_node **n;
  1686. if( data->ref ) {
  1687. n = data->ref;
  1688. } else if( name[1] == '@' ) {
  1689. n = st->stack->var_function;
  1690. } else {
  1691. n = &st->script->script_vars;
  1692. }
  1693. data->u.str = linkdb_search(n, (void*)data->u.num );
  1694. }else{
  1695. if(sd)
  1696. data->u.str = pc_readglobalreg_str(sd,name);
  1697. } // [zBuffer]
  1698. /*else{
  1699. ShowWarning("script: get_val: illegal scope string variable.\n");
  1700. data->u.str = "!!ERROR!!";
  1701. }*/
  1702. if( data->u.str == NULL )
  1703. data->u.str ="";
  1704. }else{
  1705. data->type=C_INT;
  1706. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  1707. data->u.num = str_data[data->u.num&0x00ffffff].val;
  1708. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  1709. if(sd)
  1710. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  1711. }else if(prefix=='@'){
  1712. if(sd)
  1713. data->u.num = pc_readreg(sd,data->u.num);
  1714. }else if(prefix=='$'){
  1715. data->u.num = (int)idb_get(mapreg_db,data->u.num);
  1716. }else if(prefix=='#'){
  1717. if( name[1]=='#'){
  1718. if(sd)
  1719. data->u.num = pc_readaccountreg2(sd,name);
  1720. }else{
  1721. if(sd)
  1722. data->u.num = pc_readaccountreg(sd,name);
  1723. }
  1724. }else if(prefix=='.'){
  1725. struct linkdb_node **n;
  1726. if( data->ref ) {
  1727. n = data->ref;
  1728. } else if( name[1] == '@' ) {
  1729. n = st->stack->var_function;
  1730. } else {
  1731. n = &st->script->script_vars;
  1732. }
  1733. data->u.num = (int)linkdb_search(n, (void*)data->u.num);
  1734. }else{
  1735. if(sd)
  1736. data->u.num = pc_readglobalreg(sd,name);
  1737. }
  1738. }
  1739. }
  1740. return 0;
  1741. }
  1742. /*==========================================
  1743. * 変数の読み取り2
  1744. *------------------------------------------
  1745. */
  1746. void* get_val2(struct script_state*st,int num,struct linkdb_node **ref)
  1747. {
  1748. struct script_data dat;
  1749. dat.type=C_NAME;
  1750. dat.u.num=num;
  1751. dat.ref=ref;
  1752. get_val(st,&dat);
  1753. if( dat.type==C_INT ) return (void*)dat.u.num;
  1754. else return (void*)dat.u.str;
  1755. }
  1756. /*==========================================
  1757. * 変数設定用
  1758. *------------------------------------------
  1759. */
  1760. static int set_reg(struct script_state*st,struct map_session_data *sd,int num,char *name,void *v,struct linkdb_node** ref)
  1761. {
  1762. char prefix=*name;
  1763. char postfix=name[strlen(name)-1];
  1764. if( postfix=='$' ){
  1765. char *str=(char*)v;
  1766. if( prefix=='@'){
  1767. pc_setregstr(sd,num,str);
  1768. }else if(prefix=='$') {
  1769. mapreg_setregstr(num,str);
  1770. }else if(prefix=='#') {
  1771. if( name[1]=='#' )
  1772. pc_setaccountreg2str(sd,name,str);
  1773. else
  1774. pc_setaccountregstr(sd,name,str);
  1775. }else if(prefix=='.') {
  1776. char *p;
  1777. struct linkdb_node **n;
  1778. if( ref ) {
  1779. n = ref;
  1780. } else if( name[1] == '@' ) {
  1781. n = st->stack->var_function;
  1782. } else {
  1783. n = &st->script->script_vars;
  1784. }
  1785. p = linkdb_search(n, (void*)num);
  1786. if(p) {
  1787. linkdb_erase(n, (void*)num);
  1788. aFree(p);
  1789. }
  1790. if( ((char*)v)[0] )
  1791. linkdb_insert(n, (void*)num, aStrdup(v));
  1792. }else{
  1793. pc_setglobalreg_str(sd,name,str);
  1794. } // [zBuffer]
  1795. }else{
  1796. // 数値
  1797. int val = (int)v;
  1798. if(str_data[num&0x00ffffff].type==C_PARAM){
  1799. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  1800. }else if(prefix=='@') {
  1801. pc_setreg(sd,num,val);
  1802. }else if(prefix=='$') {
  1803. mapreg_setreg(num,val);
  1804. }else if(prefix=='#') {
  1805. if( name[1]=='#' )
  1806. pc_setaccountreg2(sd,name,val);
  1807. else
  1808. pc_setaccountreg(sd,name,val);
  1809. }else if(prefix == '.') {
  1810. struct linkdb_node **n;
  1811. if( ref ) {
  1812. n = ref;
  1813. } else if( name[1] == '@' ) {
  1814. n = st->stack->var_function;
  1815. } else {
  1816. n = &st->script->script_vars;
  1817. }
  1818. if( val == 0 ) {
  1819. linkdb_erase(n, (void*)num);
  1820. } else {
  1821. linkdb_replace(n, (void*)num, (void*)val);
  1822. }
  1823. }else{
  1824. pc_setglobalreg(sd,name,val);
  1825. }
  1826. }
  1827. return 0;
  1828. }
  1829. int set_var(struct map_session_data *sd, char *name, void *val)
  1830. {
  1831. return set_reg(NULL, sd, add_str((unsigned char *) name), name, val, NULL);
  1832. }
  1833. /*==========================================
  1834. * 文字列への変換
  1835. *------------------------------------------
  1836. */
  1837. char* conv_str(struct script_state *st,struct script_data *data)
  1838. {
  1839. get_val(st,data);
  1840. if(data->type==C_INT){
  1841. char *buf;
  1842. buf=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  1843. snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
  1844. data->type=C_STR;
  1845. data->u.str=buf;
  1846. #if 1
  1847. } else if(data->type==C_NAME){
  1848. // テンポラリ。本来無いはず
  1849. data->type=C_CONSTSTR;
  1850. data->u.str=str_buf+str_data[data->u.num].str;
  1851. #endif
  1852. }
  1853. return data->u.str;
  1854. }
  1855. /*==========================================
  1856. * 数値へ変換
  1857. *------------------------------------------
  1858. */
  1859. int conv_num(struct script_state *st,struct script_data *data)
  1860. {
  1861. char *p;
  1862. get_val(st,data);
  1863. if(data->type==C_STR || data->type==C_CONSTSTR){
  1864. p=data->u.str;
  1865. data->u.num = atoi(p);
  1866. if(data->type==C_STR)
  1867. aFree(p);
  1868. data->type=C_INT;
  1869. }
  1870. return data->u.num;
  1871. }
  1872. /*==========================================
  1873. * スタックへ数値をプッシュ
  1874. *------------------------------------------
  1875. */
  1876. void push_val(struct script_stack *stack,int type,int val)
  1877. {
  1878. if(stack->sp >= stack->sp_max){
  1879. stack->sp_max += 64;
  1880. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1881. sizeof(stack->stack_data[0]) * stack->sp_max);
  1882. memset(stack->stack_data + (stack->sp_max - 64), 0,
  1883. 64 * sizeof(*(stack->stack_data)));
  1884. }
  1885. // if(battle_config.etc_log)
  1886. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  1887. stack->stack_data[stack->sp].type=type;
  1888. stack->stack_data[stack->sp].u.num=val;
  1889. stack->stack_data[stack->sp].ref = NULL;
  1890. stack->sp++;
  1891. }
  1892. /*==========================================
  1893. * スタックへ数値+リファレンスをプッシュ
  1894. *------------------------------------------
  1895. */
  1896. void push_val2(struct script_stack *stack,int type,int val,struct linkdb_node** ref) {
  1897. push_val(stack,type,val);
  1898. stack->stack_data[stack->sp-1].ref = ref;
  1899. }
  1900. /*==========================================
  1901. * スタックへ文字列をプッシュ
  1902. *------------------------------------------
  1903. */
  1904. void push_str(struct script_stack *stack,int type,unsigned char *str)
  1905. {
  1906. if(stack->sp>=stack->sp_max){
  1907. stack->sp_max += 64;
  1908. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1909. sizeof(stack->stack_data[0]) * stack->sp_max);
  1910. memset(stack->stack_data + (stack->sp_max - 64), '\0',
  1911. 64 * sizeof(*(stack->stack_data)));
  1912. }
  1913. // if(battle_config.etc_log)
  1914. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  1915. stack->stack_data[stack->sp].type=type;
  1916. stack->stack_data[stack->sp].u.str=(char *) str;
  1917. stack->stack_data[stack->sp].ref = NULL;
  1918. stack->sp++;
  1919. }
  1920. /*==========================================
  1921. * スタックへ複製をプッシュ
  1922. *------------------------------------------
  1923. */
  1924. void push_copy(struct script_stack *stack,int pos)
  1925. {
  1926. switch(stack->stack_data[pos].type){
  1927. case C_CONSTSTR:
  1928. push_str(stack,C_CONSTSTR,(unsigned char *) stack->stack_data[pos].u.str);
  1929. break;
  1930. case C_STR:
  1931. push_str(stack,C_STR,(unsigned char *) aStrdup(stack->stack_data[pos].u.str));
  1932. break;
  1933. default:
  1934. push_val2(
  1935. stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num,
  1936. stack->stack_data[pos].ref
  1937. );
  1938. break;
  1939. }
  1940. }
  1941. /*==========================================
  1942. * スタックからポップ
  1943. *------------------------------------------
  1944. */
  1945. void pop_stack(struct script_stack* stack,int start,int end)
  1946. {
  1947. int i;
  1948. for(i=start;i<end;i++){
  1949. if(stack->stack_data[i].type==C_STR){
  1950. aFree(stack->stack_data[i].u.str);
  1951. stack->stack_data[i].type=C_INT; //Might not be correct, but it's done in case to prevent pointer errors later on. [Skotlex]
  1952. }
  1953. }
  1954. if(stack->sp>end){
  1955. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  1956. }
  1957. stack->sp-=end-start;
  1958. }
  1959. /*==========================================
  1960. * スクリプト依存変数、関数依存変数の解放
  1961. *------------------------------------------
  1962. */
  1963. void script_free_vars(struct linkdb_node **node) {
  1964. struct linkdb_node *n = *node;
  1965. while(n) {
  1966. char *name = str_buf + str_data[(int)(n->key)&0x00ffffff].str;
  1967. char postfix = name[strlen(name)-1];
  1968. if( postfix == '$' ) {
  1969. // 文字型変数なので、データ削除
  1970. aFree(n->data);
  1971. }
  1972. n = n->next;
  1973. }
  1974. linkdb_final( node );
  1975. }
  1976. /*==========================================
  1977. * Free's the whole stack. Invoked when clearing a character. [Skotlex]
  1978. *------------------------------------------
  1979. */
  1980. void script_free_stack(struct script_stack *stack) {
  1981. int i;
  1982. for(i = 0; i < stack->sp; i++) {
  1983. if( stack->stack_data[i].type == C_STR ) {
  1984. aFree(stack->stack_data[i].u.str);
  1985. stack->stack_data[i].type = C_INT;
  1986. } else if( i > 0 && stack->stack_data[i].type == C_RETINFO ) {
  1987. struct linkdb_node** n = (struct linkdb_node**)stack->stack_data[i-1].u.num;
  1988. script_free_vars( n );
  1989. aFree( n );
  1990. }
  1991. }
  1992. script_free_vars( stack->var_function );
  1993. aFree(stack->var_function);
  1994. aFree(stack->stack_data);
  1995. aFree(stack);
  1996. }
  1997. void script_free_code(struct script_code* code) {
  1998. script_free_vars( &code->script_vars );
  1999. aFree( code->script_buf );
  2000. aFree( code );
  2001. }
  2002. //
  2003. // 実行部main
  2004. //
  2005. /*==========================================
  2006. * コマンドの読み取り
  2007. *------------------------------------------
  2008. */
  2009. static int unget_com_data=-1;
  2010. int get_com(unsigned char *script,int *pos)
  2011. {
  2012. int i,j;
  2013. if(unget_com_data>=0){
  2014. i=unget_com_data;
  2015. unget_com_data=-1;
  2016. return i;
  2017. }
  2018. if(script[*pos]>=0x80){
  2019. return C_INT;
  2020. }
  2021. i=0; j=0;
  2022. while(script[*pos]>=0x40){
  2023. i=script[(*pos)++]<<j;
  2024. j+=6;
  2025. }
  2026. return i+(script[(*pos)++]<<j);
  2027. }
  2028. /*==========================================
  2029. * コマンドのプッシュバック
  2030. *------------------------------------------
  2031. */
  2032. void unget_com(int c)
  2033. {
  2034. if(unget_com_data!=-1){
  2035. if(battle_config.error_log)
  2036. ShowError("unget_com can back only 1 data\n");
  2037. }
  2038. unget_com_data=c;
  2039. }
  2040. /*==========================================
  2041. * 数値の所得
  2042. *------------------------------------------
  2043. */
  2044. int get_num(unsigned char *script,int *pos)
  2045. {
  2046. int i,j;
  2047. i=0; j=0;
  2048. while(script[*pos]>=0xc0){
  2049. i+=(script[(*pos)++]&0x7f)<<j;
  2050. j+=6;
  2051. }
  2052. return i+((script[(*pos)++]&0x7f)<<j);
  2053. }
  2054. /*==========================================
  2055. * スタックから値を取り出す
  2056. *------------------------------------------
  2057. */
  2058. int pop_val(struct script_state* st)
  2059. {
  2060. if(st->stack->sp<=0)
  2061. return 0;
  2062. st->stack->sp--;
  2063. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  2064. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  2065. return st->stack->stack_data[st->stack->sp].u.num;
  2066. return 0;
  2067. }
  2068. int isstr(struct script_data *c) {
  2069. if( c->type == C_STR || c->type == C_CONSTSTR )
  2070. return 1;
  2071. else if( c->type == C_NAME ) {
  2072. char *p = str_buf + str_data[c->u.num & 0xffffff].str;
  2073. char postfix = p[strlen(p)-1];
  2074. return (postfix == '$');
  2075. }
  2076. return 0;
  2077. }
  2078. /*==========================================
  2079. * 加算演算子
  2080. *------------------------------------------
  2081. */
  2082. void op_add(struct script_state* st)
  2083. {
  2084. st->stack->sp--;
  2085. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  2086. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  2087. if(isstr(&st->stack->stack_data[st->stack->sp]) || isstr(&st->stack->stack_data[st->stack->sp-1])){
  2088. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  2089. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  2090. }
  2091. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  2092. int *i1 = &st->stack->stack_data[st->stack->sp-1].u.num;
  2093. int *i2 = &st->stack->stack_data[st->stack->sp].u.num;
  2094. int ret = *i1 + *i2;
  2095. double ret_double = (double)*i1 + (double)*i2;
  2096. if(ret_double > INT_MAX|| ret_double < INT_MIN) {
  2097. ShowWarning("script::op_add overflow detected op:%d\n",C_ADD);
  2098. report_src(st);
  2099. ret = cap_value(ret, INT_MIN, INT_MAX);
  2100. }
  2101. *i1 = ret;
  2102. } else { // ssの予定
  2103. char *buf;
  2104. buf=(char *)aMallocA((strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  2105. strlen(st->stack->stack_data[st->stack->sp].u.str)+1)*sizeof(char));
  2106. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  2107. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  2108. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  2109. {
  2110. aFree(st->stack->stack_data[st->stack->sp-1].u.str);
  2111. st->stack->stack_data[st->stack->sp-1].type=C_INT;
  2112. }
  2113. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  2114. {
  2115. aFree(st->stack->stack_data[st->stack->sp].u.str);
  2116. st->stack->stack_data[st->stack->sp].type=C_INT;
  2117. }
  2118. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  2119. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  2120. }
  2121. st->stack->stack_data[st->stack->sp-1].ref = NULL;
  2122. }
  2123. /*==========================================
  2124. * 二項演算子(文字列)
  2125. *------------------------------------------
  2126. */
  2127. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  2128. {
  2129. char *s1=st->stack->stack_data[sp1].u.str,
  2130. *s2=st->stack->stack_data[sp2].u.str;
  2131. int a=0;
  2132. switch(op){
  2133. case C_EQ:
  2134. a= (strcmp(s1,s2)==0);
  2135. break;
  2136. case C_NE:
  2137. a= (strcmp(s1,s2)!=0);
  2138. break;
  2139. case C_GT:
  2140. a= (strcmp(s1,s2)> 0);
  2141. break;
  2142. case C_GE:
  2143. a= (strcmp(s1,s2)>=0);
  2144. break;
  2145. case C_LT:
  2146. a= (strcmp(s1,s2)< 0);
  2147. break;
  2148. case C_LE:
  2149. a= (strcmp(s1,s2)<=0);
  2150. break;
  2151. default:
  2152. ShowWarning("script: illegal string operator\n");
  2153. break;
  2154. }
  2155. // Because push_val() overwrite stack_data[sp1], C_STR on stack_data[sp1] won't be freed.
  2156. // So, call push_val() after freeing strings. [jA1783]
  2157. // push_val(st->stack,C_INT,a);
  2158. if(st->stack->stack_data[sp1].type==C_STR)
  2159. {
  2160. aFree(s1);
  2161. st->stack->stack_data[sp1].type=C_INT;
  2162. }
  2163. if(st->stack->stack_data[sp2].type==C_STR)
  2164. {
  2165. aFree(s2);
  2166. st->stack->stack_data[sp2].type=C_INT;
  2167. }
  2168. push_val(st->stack,C_INT,a);
  2169. }
  2170. /*==========================================
  2171. * 二項演算子(数値)
  2172. *------------------------------------------
  2173. */
  2174. void op_2num(struct script_state *st,int op,int i1,int i2)
  2175. {
  2176. int ret = 0;
  2177. double ret_double = 0;
  2178. switch(op){
  2179. case C_MOD: ret = i1 % i2; break;
  2180. case C_AND: ret = i1 & i2; break;
  2181. case C_OR: ret = i1 | i2; break;
  2182. case C_XOR: ret = i1 ^ i2; break;
  2183. case C_LAND: ret = (i1 && i2); break;
  2184. case C_LOR: ret = (i1 || i2); break;
  2185. case C_EQ: ret = (i1 == i2); break;
  2186. case C_NE: ret = (i1 != i2); break;
  2187. case C_GT: ret = (i1 > i2); break;
  2188. case C_GE: ret = (i1 >= i2); break;
  2189. case C_LT: ret = (i1 < i2); break;
  2190. case C_LE: ret = (i1 <= i2); break;
  2191. case C_R_SHIFT: ret = i1>>i2; break;
  2192. case C_L_SHIFT: ret = i1<<i2; break;
  2193. default:
  2194. switch(op) {
  2195. case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
  2196. case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
  2197. case C_DIV:
  2198. if(i2 == 0) {
  2199. printf("script::op_2num division by zero.\n");
  2200. ret = INT_MAX;
  2201. ret_double = 0; // doubleの精度が怪しいのでオーバーフロー対策を飛ばす
  2202. } else {
  2203. ret = i1 / i2; ret_double = (double)i1 / (double)i2;
  2204. }
  2205. break;
  2206. }
  2207. if(ret_double > INT_MAX || ret_double < INT_MIN) {
  2208. printf("script::op_2num overflow detected op:%d\n",op);
  2209. report_src(st);
  2210. ret = cap_value(ret_double,INT_MAX,INT_MIN);
  2211. }
  2212. }
  2213. push_val(st->stack,C_INT,ret);
  2214. }
  2215. /*==========================================
  2216. * 二項演算子
  2217. *------------------------------------------
  2218. */
  2219. void op_2(struct script_state *st,int op)
  2220. {
  2221. int i1,i2;
  2222. char *s1=NULL,*s2=NULL;
  2223. i2=pop_val(st);
  2224. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2225. s2=st->stack->stack_data[st->stack->sp].u.str;
  2226. i1=pop_val(st);
  2227. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2228. s1=st->stack->stack_data[st->stack->sp].u.str;
  2229. if( s1!=NULL && s2!=NULL ){
  2230. // ss => op_2str
  2231. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  2232. }else if( s1==NULL && s2==NULL ){
  2233. // ii => op_2num
  2234. op_2num(st,op,i1,i2);
  2235. }else{
  2236. // si,is => error
  2237. ShowWarning("script: op_2: int&str, str&int not allow.\n");
  2238. report_src(st);
  2239. if(s1 && st->stack->stack_data[st->stack->sp].type == C_STR)
  2240. {
  2241. aFree(s1);
  2242. st->stack->stack_data[st->stack->sp].type = C_INT;
  2243. }
  2244. if(s2 && st->stack->stack_data[st->stack->sp+1].type == C_STR)
  2245. {
  2246. aFree(s2);
  2247. st->stack->stack_data[st->stack->sp+1].type = C_INT;
  2248. }
  2249. push_val(st->stack,C_INT,0);
  2250. }
  2251. }
  2252. /*==========================================
  2253. * 単項演算子
  2254. *------------------------------------------
  2255. */
  2256. void op_1num(struct script_state *st,int op)
  2257. {
  2258. int i1;
  2259. i1=pop_val(st);
  2260. switch(op){
  2261. case C_NEG:
  2262. i1=-i1;
  2263. break;
  2264. case C_NOT:
  2265. i1=~i1;
  2266. break;
  2267. case C_LNOT:
  2268. i1=!i1;
  2269. break;
  2270. }
  2271. push_val(st->stack,C_INT,i1);
  2272. }
  2273. /*==========================================
  2274. * 関数の実行
  2275. *------------------------------------------
  2276. */
  2277. int run_func(struct script_state *st)
  2278. {
  2279. int i,start_sp,end_sp,func;
  2280. end_sp=st->stack->sp;
  2281. #ifdef DEBUG_RUN
  2282. if(battle_config.etc_log) {
  2283. ShowDebug("run_func : %s? (%d(%d)) sp=%d (%d...%d)\n",str_buf+str_data[func].str, func, str_data[func].type, st->stack->sp, st->start, st->end);
  2284. ShowDebug("stack dump :");
  2285. for(i=0;i<end_sp;i++){
  2286. switch(st->stack->stack_data[i].type){
  2287. case C_INT:
  2288. printf(" int(%d)",st->stack->stack_data[i].u.num);
  2289. break;
  2290. case C_NAME:
  2291. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num & 0xffffff].str);
  2292. break;
  2293. case C_ARG:
  2294. printf(" arg");
  2295. break;
  2296. case C_POS:
  2297. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  2298. break;
  2299. case C_STR:
  2300. printf(" str(%s)",st->stack->stack_data[i].u.str);
  2301. break;
  2302. case C_CONSTSTR:
  2303. printf(" cstr(%s)",st->stack->stack_data[i].u.str);
  2304. break;
  2305. default:
  2306. printf(" etc(%d,%d)",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  2307. }
  2308. }
  2309. printf("\n");
  2310. }
  2311. #endif
  2312. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  2313. if(i==0){
  2314. if(battle_config.error_log)
  2315. ShowError("function not found\n");
  2316. // st->stack->sp=0;
  2317. st->state=END;
  2318. report_src(st);
  2319. return 1;
  2320. }
  2321. start_sp=i-1;
  2322. st->start=i-1;
  2323. st->end=end_sp;
  2324. func=st->stack->stack_data[st->start].u.num;
  2325. if(str_data[func].type!=C_FUNC ){
  2326. ShowMessage ("run_func: '"CL_WHITE"%s"CL_RESET"' (type %d) is not function and command!\n");
  2327. // st->stack->sp=0;
  2328. st->state=END;
  2329. report_src(st);
  2330. return 1;
  2331. }
  2332. #ifdef DEBUG_RUN
  2333. ShowDebug("run_func : %s (func_no : %d , func_type : %d pos : 0x%x)\n",
  2334. str_buf+str_data[func].str,func,str_data[func].type,st->pos
  2335. );
  2336. #endif
  2337. if(str_data[func].func){
  2338. if (str_data[func].func(st)) //Report error
  2339. report_src(st);
  2340. } else {
  2341. if(battle_config.error_log)
  2342. ShowError("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  2343. push_val(st->stack,C_INT,0);
  2344. report_src(st);
  2345. }
  2346. // Stack's datum are used when re-run functions [Eoe]
  2347. if(st->state != RERUNLINE) {
  2348. pop_stack(st->stack,start_sp,end_sp);
  2349. }
  2350. if(st->state==RETFUNC){
  2351. // ユーザー定義関数からの復帰
  2352. int olddefsp=st->stack->defsp;
  2353. int i;
  2354. pop_stack(st->stack,st->stack->defsp,start_sp); // 復帰に邪魔なスタック削除
  2355. if(st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO){
  2356. ShowWarning("script:run_func(return) return without callfunc or callsub!\n");
  2357. st->state=END;
  2358. report_src(st);
  2359. return 1;
  2360. }
  2361. script_free_vars( st->stack->var_function );
  2362. aFree(st->stack->var_function);
  2363. i = conv_num(st,& (st->stack->stack_data[st->stack->defsp-5])); // 引数の数所得
  2364. st->pos=conv_num(st,& (st->stack->stack_data[st->stack->defsp-1])); // スクリプト位置の復元
  2365. st->script=(struct script_code*)conv_num(st,& (st->stack->stack_data[st->stack->defsp-3])); // スクリプトを復元
  2366. st->stack->var_function = (struct linkdb_node**)st->stack->stack_data[st->stack->defsp-2].u.num; // 関数依存変数
  2367. st->stack->defsp=conv_num(st,& (st->stack->stack_data[st->stack->defsp-4])); // 基準スタックポインタを復元
  2368. pop_stack(st->stack,olddefsp-5-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  2369. st->state=GOTO;
  2370. }
  2371. return 0;
  2372. }
  2373. /*==========================================
  2374. * スクリプトの実行
  2375. *------------------------------------------
  2376. */
  2377. void run_script_main(struct script_state *st);
  2378. void run_script(struct script_code *rootscript,int pos,int rid,int oid)
  2379. {
  2380. struct script_state *st;
  2381. struct map_session_data *sd=NULL;
  2382. if(rootscript==NULL || pos<0)
  2383. return;
  2384. if (rid) sd = map_id2sd(rid);
  2385. if (sd && sd->st && sd->st->scriptroot == rootscript && sd->st->pos == pos){
  2386. //Resume script.
  2387. st = sd->st;
  2388. } else {
  2389. st = aCalloc(sizeof(struct script_state), 1);
  2390. // the script is different, make new script_state and stack
  2391. st->stack = aMalloc (sizeof(struct script_stack));
  2392. st->stack->sp=0;
  2393. st->stack->sp_max=64;
  2394. st->stack->stack_data = (struct script_data *)aCalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]));
  2395. st->stack->defsp = st->stack->sp;
  2396. st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
  2397. st->state = RUN;
  2398. st->script = rootscript;
  2399. }
  2400. st->pos = pos;
  2401. st->rid = rid;
  2402. st->oid = oid;
  2403. st->sleep.timer = -1;
  2404. run_script_main(st);
  2405. }
  2406. /*==========================================
  2407. * 指定ノードをsleep_dbから削除
  2408. *------------------------------------------
  2409. */
  2410. struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n)
  2411. {
  2412. struct linkdb_node *retnode;
  2413. if( n == NULL)
  2414. return NULL;
  2415. if( n->prev == NULL )
  2416. sleep_db = n->next;
  2417. else
  2418. n->prev->next = n->next;
  2419. if( n->next )
  2420. n->next->prev = n->prev;
  2421. retnode = n->next;
  2422. aFree( n );
  2423. return retnode; // 次のノードを返す
  2424. }
  2425. /*==========================================
  2426. * sleep用タイマー関数
  2427. *------------------------------------------
  2428. */
  2429. int run_script_timer(int tid, unsigned int tick, int id, int data)
  2430. {
  2431. struct script_state *st = (struct script_state *)data;
  2432. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  2433. struct map_session_data *sd = map_id2sd(st->rid);
  2434. if((sd && sd->char_id != id) || (st->rid && !sd))
  2435. { //Character mismatch. Cancel execution.
  2436. st->rid = 0;
  2437. st->state = END;
  2438. }
  2439. while( node && st->sleep.timer != -1 ) {
  2440. if( (int)node->key == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
  2441. script_erase_sleepdb(node);
  2442. st->sleep.timer = -1;
  2443. break;
  2444. }
  2445. node = node->next;
  2446. }
  2447. run_script_main(st);
  2448. return 0;
  2449. }
  2450. /*==========================================
  2451. * スクリプトの実行メイン部分
  2452. *------------------------------------------
  2453. */
  2454. void run_script_main(struct script_state *st)
  2455. {
  2456. int c;
  2457. int cmdcount=script_config.check_cmdcount;
  2458. int gotocount=script_config.check_gotocount;
  2459. struct map_session_data *sd;
  2460. //For backing up purposes
  2461. struct script_state *bk_st = NULL;
  2462. int bk_npcid = 0;
  2463. struct script_stack *stack=st->stack;
  2464. sd = st->rid?map_id2sd(st->rid):NULL;
  2465. if(sd){
  2466. if(sd->st != st){
  2467. bk_st = sd->st;
  2468. bk_npcid = sd->npc_id;
  2469. }
  2470. sd->st = st;
  2471. sd->npc_id = st->oid;
  2472. }
  2473. if(st->state == RERUNLINE) {
  2474. st->state = RUN;
  2475. run_func(st);
  2476. if(st->state == GOTO)
  2477. st->state = RUN;
  2478. } else if(st->state != END)
  2479. st->state = RUN;
  2480. while(st->state == RUN){
  2481. c= get_com((unsigned char *) st->script->script_buf,&st->pos);
  2482. switch(c){
  2483. case C_EOL:
  2484. if(stack->sp!=stack->defsp){
  2485. if(stack->sp > stack->defsp)
  2486. { //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex]
  2487. //Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded.
  2488. if (battle_config.etc_log)
  2489. ShowWarning("Clearing unused stack stack.sp(%d) -> default(%d)\n",stack->sp,stack->defsp);
  2490. pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section.
  2491. } else if(battle_config.error_log)
  2492. ShowError("stack.sp(%d) != default(%d)\n",stack->sp,stack->defsp);
  2493. stack->sp=stack->defsp;
  2494. }
  2495. break;
  2496. case C_INT:
  2497. push_val(stack,C_INT,get_num((unsigned char *) st->script->script_buf,&st->pos));
  2498. break;
  2499. case C_POS:
  2500. case C_NAME:
  2501. push_val(stack,c,(*(int*)(st->script->script_buf+st->pos))&0xffffff);
  2502. st->pos+=3;
  2503. break;
  2504. case C_ARG:
  2505. push_val(stack,c,0);
  2506. break;
  2507. case C_STR:
  2508. push_str(stack,C_CONSTSTR,(unsigned char *) (st->script->script_buf+st->pos));
  2509. while(st->script->script_buf[st->pos++]);
  2510. break;
  2511. case C_FUNC:
  2512. run_func(st);
  2513. if(st->state==GOTO){
  2514. st->state = RUN;
  2515. if( gotocount>0 && (--gotocount)<=0 ){
  2516. ShowError("run_script: infinity loop !\n");
  2517. st->state=END;
  2518. }
  2519. }
  2520. break;
  2521. case C_ADD:
  2522. op_add(st);
  2523. break;
  2524. case C_SUB:
  2525. case C_MUL:
  2526. case C_DIV:
  2527. case C_MOD:
  2528. case C_EQ:
  2529. case C_NE:
  2530. case C_GT:
  2531. case C_GE:
  2532. case C_LT:
  2533. case C_LE:
  2534. case C_AND:
  2535. case C_OR:
  2536. case C_XOR:
  2537. case C_LAND:
  2538. case C_LOR:
  2539. case C_R_SHIFT:
  2540. case C_L_SHIFT:
  2541. op_2(st,c);
  2542. break;
  2543. case C_NEG:
  2544. case C_NOT:
  2545. case C_LNOT:
  2546. op_1num(st,c);
  2547. break;
  2548. case C_NOP:
  2549. st->state=END;
  2550. break;
  2551. default:
  2552. if(battle_config.error_log)
  2553. ShowError("unknown command : %d @ %d\n",c,pos);
  2554. st->state=END;
  2555. break;
  2556. }
  2557. if( cmdcount>0 && (--cmdcount)<=0 ){
  2558. ShowError("run_script: infinity loop !\n");
  2559. st->state=END;
  2560. }
  2561. }
  2562. if(st->sleep.tick > 0) {
  2563. //Delay execution
  2564. st->sleep.charid = sd?sd->char_id:0;
  2565. st->sleep.timer = add_timer(gettick()+st->sleep.tick,
  2566. run_script_timer, st->sleep.charid, (int)st);
  2567. linkdb_insert(&sleep_db, (void*)st->oid, st);
  2568. //Restore previous script
  2569. sd->st = bk_st;
  2570. sd->npc_id = bk_npcid;
  2571. bk_st = NULL; //Remove tag for removal.
  2572. }
  2573. else if(st->state != END && sd){
  2574. //Resume later (st is already attached to player).
  2575. if(bk_st && sd->st != bk_st)
  2576. ShowWarning("Unable to restore stack! Double continuation!\n");
  2577. } else {
  2578. //Dispose of script.
  2579. if (sd)
  2580. { //Restore previous stack and save char.
  2581. if(sd->state.using_fake_npc){
  2582. clif_clearchar_id(sd->npc_id, 0, sd->fd);
  2583. sd->state.using_fake_npc = 0;
  2584. }
  2585. //Restore previous script if any.
  2586. sd->st = bk_st;
  2587. sd->npc_id = bk_npcid;
  2588. if (!bk_st)
  2589. npc_event_dequeue(sd);
  2590. else
  2591. bk_st = NULL; //Remove tag for removal.
  2592. if (sd->state.reg_dirty&2)
  2593. intif_saveregistry(sd,2);
  2594. if (sd->state.reg_dirty&1)
  2595. intif_saveregistry(sd,1);
  2596. }
  2597. st->pos = -1;
  2598. script_free_stack (st->stack);
  2599. aFree(st);
  2600. }
  2601. if (bk_st)
  2602. { //Remove previous script
  2603. bk_st->pos = -1;
  2604. script_free_stack(bk_st->stack);
  2605. aFree(bk_st);
  2606. bk_st = NULL;
  2607. }
  2608. }
  2609. /*==========================================
  2610. * マップ変数の変更
  2611. *------------------------------------------
  2612. */
  2613. int mapreg_setreg(int num,int val)
  2614. {
  2615. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2616. int i=num>>24;
  2617. char *name=str_buf+str_data[num&0x00ffffff].str;
  2618. char tmp_str[64];
  2619. #endif
  2620. if(val!=0) {
  2621. if(idb_put(mapreg_db,num,(void*)val))
  2622. ;
  2623. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2624. else if(name[1] != '@') {
  2625. sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%d')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,val);
  2626. if(mysql_query(&mmysql_handle,tmp_sql)){
  2627. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2628. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2629. }
  2630. }
  2631. #endif
  2632. // else
  2633. } else { // [zBuffer]
  2634. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2635. if(name[1] != '@') { // Remove from database because it is unused.
  2636. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2637. if(mysql_query(&mmysql_handle,tmp_sql)){
  2638. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2639. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2640. }
  2641. }
  2642. #endif
  2643. idb_remove(mapreg_db,num);
  2644. }
  2645. mapreg_dirty=1;
  2646. return 0;
  2647. }
  2648. /*==========================================
  2649. * 文字列型マップ変数の変更
  2650. *------------------------------------------
  2651. */
  2652. int mapreg_setregstr(int num,const char *str)
  2653. {
  2654. char *p;
  2655. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2656. char tmp_str[64];
  2657. char tmp_str2[512];
  2658. int i=num>>24; // [zBuffer]
  2659. char *name=str_buf+str_data[num&0x00ffffff].str;
  2660. #endif
  2661. if( str==NULL || *str==0 ){
  2662. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2663. if(name[1] != '@') {
  2664. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2665. if(mysql_query(&mmysql_handle,tmp_sql)){
  2666. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2667. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2668. }
  2669. }
  2670. #endif
  2671. idb_remove(mapregstr_db,num);
  2672. mapreg_dirty=1;
  2673. return 0;
  2674. }
  2675. p=(char *)aMallocA((strlen(str)+1)*sizeof(char));
  2676. strcpy(p,str);
  2677. if (idb_put(mapregstr_db,num,p))
  2678. ;
  2679. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2680. else if(name[1] != '@'){ //put returned null, so we must insert.
  2681. // Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
  2682. sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%s')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,jstrescapecpy(tmp_str2,p));
  2683. if(mysql_query(&mmysql_handle,tmp_sql)){
  2684. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2685. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2686. }
  2687. }
  2688. #endif
  2689. mapreg_dirty=1;
  2690. return 0;
  2691. }
  2692. /*==========================================
  2693. * 永続的マップ変数の読み込み
  2694. *------------------------------------------
  2695. */
  2696. static int script_load_mapreg(void)
  2697. {
  2698. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2699. FILE *fp;
  2700. char line[1024];
  2701. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  2702. return -1;
  2703. while(fgets(line,sizeof(line),fp)){
  2704. char buf1[256],buf2[1024],*p;
  2705. int n,v,s,i;
  2706. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  2707. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  2708. continue;
  2709. if( buf1[strlen(buf1)-1]=='$' ){
  2710. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  2711. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2712. continue;
  2713. }
  2714. p=(char *)aMallocA((strlen(buf2) + 1)*sizeof(char));
  2715. strcpy(p,buf2);
  2716. s= add_str((unsigned char *) buf1);
  2717. idb_put(mapregstr_db,(i<<24)|s,p);
  2718. }else{
  2719. if( sscanf(line+n,"%d",&v)!=1 ){
  2720. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2721. continue;
  2722. }
  2723. s= add_str((unsigned char *) buf1);
  2724. idb_put(mapreg_db,(i<<24)|s,(void*)v);
  2725. }
  2726. }
  2727. fclose(fp);
  2728. mapreg_dirty=0;
  2729. return 0;
  2730. #else
  2731. // SQL mapreg code start [zBuffer]
  2732. /*
  2733. 0 1 2
  2734. +-------------------------+
  2735. | varname | index | value |
  2736. +-------------------------+
  2737. */
  2738. unsigned int perfomance = (unsigned int)time(NULL);
  2739. sprintf(tmp_sql,"SELECT * FROM `%s`",mapregsql_db);
  2740. ShowInfo("Querying script_load_mapreg ...\n");
  2741. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2742. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2743. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2744. return -1;
  2745. }
  2746. ShowInfo("Success! Returning results ...\n");
  2747. sql_res = mysql_store_result(&mmysql_handle);
  2748. if (sql_res) {
  2749. while ((sql_row = mysql_fetch_row(sql_res))) {
  2750. char buf1[33], *p = NULL;
  2751. int i,v,s;
  2752. strcpy(buf1,sql_row[0]);
  2753. if( buf1[strlen(buf1)-1]=='$' ){
  2754. i = atoi(sql_row[1]);
  2755. p=(char *)aMallocA((strlen(sql_row[2]) + 1)*sizeof(char));
  2756. strcpy(p,sql_row[2]);
  2757. s= add_str((unsigned char *) buf1);
  2758. idb_put(mapregstr_db,(i<<24)|s,p);
  2759. }else{
  2760. s= add_str((unsigned char *) buf1);
  2761. v= atoi(sql_row[2]);
  2762. i = atoi(sql_row[1]);
  2763. idb_put(mapreg_db,(i<<24)|s,(void *)v);
  2764. }
  2765. }
  2766. }
  2767. ShowInfo("Freeing results...\n");
  2768. mysql_free_result(sql_res);
  2769. mapreg_dirty=0;
  2770. perfomance = ((unsigned int)time(NULL) - perfomance);
  2771. ShowInfo("SQL Mapreg Loading Completed Under %d Seconds.\n",perfomance);
  2772. return 0;
  2773. #endif /* TXT_ONLY */
  2774. }
  2775. /*==========================================
  2776. * 永続的マップ変数の書き込み
  2777. *------------------------------------------
  2778. */
  2779. static int script_save_mapreg_intsub(DBKey key,void *data,va_list ap)
  2780. {
  2781. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2782. FILE *fp=va_arg(ap,FILE*);
  2783. int num=key.i&0x00ffffff, i=key.i>>24;
  2784. char *name=str_buf+str_data[num].str;
  2785. if( name[1]!='@' ){
  2786. if(i==0)
  2787. fprintf(fp,"%s\t%d\n", name, (int)data);
  2788. else
  2789. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  2790. }
  2791. return 0;
  2792. #else
  2793. int num=key.i&0x00ffffff, i=key.i>>24; // [zBuffer]
  2794. char *name=str_buf+str_data[num].str;
  2795. if ( name[1] != '@') {
  2796. sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%d' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,(int)data,mapregsql_db_varname,name,mapregsql_db_index,i);
  2797. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2798. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2799. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2800. }
  2801. }
  2802. return 0;
  2803. #endif
  2804. }
  2805. static int script_save_mapreg_strsub(DBKey key,void *data,va_list ap)
  2806. {
  2807. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2808. FILE *fp=va_arg(ap,FILE*);
  2809. int num=key.i&0x00ffffff, i=key.i>>24;
  2810. char *name=str_buf+str_data[num].str;
  2811. if( name[1]!='@' ){
  2812. if(i==0)
  2813. fprintf(fp,"%s\t%s\n", name, (char *)data);
  2814. else
  2815. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  2816. }
  2817. return 0;
  2818. #else
  2819. char tmp_str2[512];
  2820. int num=key.i&0x00ffffff, i=key.i>>24;
  2821. char *name=str_buf+str_data[num].str;
  2822. if ( name[1] != '@') {
  2823. sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%s' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,jstrescapecpy(tmp_str2,(char *)data),mapregsql_db_varname,name,mapregsql_db_index,i);
  2824. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2825. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2826. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2827. }
  2828. }
  2829. return 0;
  2830. #endif
  2831. }
  2832. static int script_save_mapreg(void)
  2833. {
  2834. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2835. FILE *fp;
  2836. int lock;
  2837. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL ) {
  2838. ShowError("script_save_mapreg: Unable to lock-open file [%s]\n",mapreg_txt);
  2839. return -1;
  2840. }
  2841. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub,fp);
  2842. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  2843. lock_fclose(fp,mapreg_txt,&lock);
  2844. #else
  2845. unsigned int perfomance = (unsigned int)time(NULL);
  2846. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub); // [zBuffer]
  2847. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub);
  2848. perfomance = ((unsigned int)time(NULL) - perfomance);
  2849. if(perfomance > 2)
  2850. ShowWarning("Slow Query: MapregSQL Saving @ %d second(s).\n", perfomance);
  2851. #endif
  2852. mapreg_dirty=0;
  2853. return 0;
  2854. }
  2855. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  2856. {
  2857. if(mapreg_dirty)
  2858. if (script_save_mapreg() == -1)
  2859. ShowError("Failed to save the mapreg data!\n");
  2860. return 0;
  2861. }
  2862. /*==========================================
  2863. *
  2864. *------------------------------------------
  2865. */
  2866. static int set_posword(char *p)
  2867. {
  2868. char* np,* str[15];
  2869. int i=0;
  2870. for(i=0;i<11;i++) {
  2871. if((np=strchr(p,','))!=NULL) {
  2872. str[i]=p;
  2873. *np=0;
  2874. p=np+1;
  2875. } else {
  2876. str[i]=p;
  2877. p+=strlen(p);
  2878. }
  2879. if(str[i])
  2880. strcpy(pos[i],str[i]);
  2881. }
  2882. return 0;
  2883. }
  2884. int script_config_read_sub(char *cfgName)
  2885. {
  2886. int i;
  2887. char line[1024],w1[1024],w2[1024];
  2888. FILE *fp;
  2889. fp=fopen(cfgName,"r");
  2890. if(fp==NULL){
  2891. ShowError("file not found: [%s]\n", cfgName);
  2892. return 1;
  2893. }
  2894. while(fgets(line,sizeof(line)-1,fp)){
  2895. if(line[0] == '/' && line[1] == '/')
  2896. continue;
  2897. i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  2898. if(i!=2)
  2899. continue;
  2900. if(strcmpi(w1,"refine_posword")==0) {
  2901. set_posword(w2);
  2902. }
  2903. else if(strcmpi(w1,"verbose_mode")==0) {
  2904. script_config.verbose_mode = battle_config_switch(w2);
  2905. }
  2906. else if(strcmpi(w1,"warn_func_no_comma")==0) {
  2907. script_config.warn_func_no_comma = battle_config_switch(w2);
  2908. }
  2909. else if(strcmpi(w1,"warn_cmd_no_comma")==0) {
  2910. script_config.warn_cmd_no_comma = battle_config_switch(w2);
  2911. }
  2912. else if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
  2913. script_config.warn_func_mismatch_paramnum = battle_config_switch(w2);
  2914. }
  2915. else if(strcmpi(w1,"warn_cmd_mismatch_paramnum")==0) {
  2916. script_config.warn_cmd_mismatch_paramnum = battle_config_switch(w2);
  2917. }
  2918. else if(strcmpi(w1,"check_cmdcount")==0) {
  2919. script_config.check_cmdcount = battle_config_switch(w2);
  2920. }
  2921. else if(strcmpi(w1,"check_gotocount")==0) {
  2922. script_config.check_gotocount = battle_config_switch(w2);
  2923. }
  2924. else if(strcmpi(w1,"event_script_type")==0) {
  2925. script_config.event_script_type = battle_config_switch(w2);
  2926. }
  2927. else if(strcmpi(w1,"event_requires_trigger")==0) {
  2928. script_config.event_requires_trigger = battle_config_switch(w2);
  2929. }
  2930. else if(strcmpi(w1,"die_event_name")==0) {
  2931. strncpy(script_config.die_event_name, w2, NAME_LENGTH-1);
  2932. if (strlen(script_config.die_event_name) != strlen(w2))
  2933. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.die_event_name);
  2934. }
  2935. else if(strcmpi(w1,"kill_pc_event_name")==0) {
  2936. strncpy(script_config.kill_pc_event_name, w2, NAME_LENGTH-1);
  2937. if (strlen(script_config.kill_pc_event_name) != strlen(w2))
  2938. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_pc_event_name);
  2939. }
  2940. else if(strcmpi(w1,"kill_mob_event_name")==0) {
  2941. strncpy(script_config.kill_mob_event_name, w2, NAME_LENGTH-1);
  2942. if (strlen(script_config.kill_mob_event_name) != strlen(w2))
  2943. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_mob_event_name);
  2944. }
  2945. else if(strcmpi(w1,"login_event_name")==0) {
  2946. strncpy(script_config.login_event_name, w2, NAME_LENGTH-1);
  2947. if (strlen(script_config.login_event_name) != strlen(w2))
  2948. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.login_event_name);
  2949. }
  2950. else if(strcmpi(w1,"logout_event_name")==0) {
  2951. strncpy(script_config.logout_event_name, w2, NAME_LENGTH-1);
  2952. if (strlen(script_config.logout_event_name) != strlen(w2))
  2953. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.logout_event_name);
  2954. }
  2955. else if(strcmpi(w1,"loadmap_event_name")==0) {
  2956. strncpy(script_config.loadmap_event_name, w2, NAME_LENGTH-1);
  2957. if (strlen(script_config.loadmap_event_name) != strlen(w2))
  2958. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.loadmap_event_name);
  2959. }
  2960. else if(strcmpi(w1,"baselvup_event_name")==0) {
  2961. strncpy(script_config.baselvup_event_name, w2, NAME_LENGTH-1);
  2962. if (strlen(script_config.baselvup_event_name) != strlen(w2))
  2963. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.baselvup_event_name);
  2964. }
  2965. else if(strcmpi(w1,"joblvup_event_name")==0) {
  2966. strncpy(script_config.joblvup_event_name, w2, NAME_LENGTH-1);
  2967. if (strlen(script_config.joblvup_event_name) != strlen(w2))
  2968. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.joblvup_event_name);
  2969. }
  2970. else if(strcmpi(w1,"import")==0){
  2971. script_config_read_sub(w2);
  2972. }
  2973. }
  2974. fclose(fp);
  2975. return 0;
  2976. }
  2977. int script_config_read(char *cfgName)
  2978. { //Script related variables should be initialized once! [Skotlex]
  2979. memset (&script_config, 0, sizeof(script_config));
  2980. script_config.verbose_mode = 0;
  2981. script_config.warn_func_no_comma = 1;
  2982. script_config.warn_cmd_no_comma = 1;
  2983. script_config.warn_func_mismatch_paramnum = 1;
  2984. script_config.warn_cmd_mismatch_paramnum = 1;
  2985. script_config.check_cmdcount = 65535;
  2986. script_config.check_gotocount = 2048;
  2987. script_config.event_script_type = 0;
  2988. script_config.event_requires_trigger = 1;
  2989. return script_config_read_sub(cfgName);
  2990. }
  2991. static int do_final_userfunc_sub (DBKey key,void *data,va_list ap){
  2992. struct script_code *code = (struct script_code *)data;
  2993. if(code){
  2994. script_free_vars( &code->script_vars );
  2995. aFree( code->script_buf );
  2996. }
  2997. return 0;
  2998. }
  2999. /*==========================================
  3000. * 終了
  3001. *------------------------------------------
  3002. */
  3003. int do_final_script()
  3004. {
  3005. if(mapreg_dirty>=0)
  3006. script_save_mapreg();
  3007. mapreg_db->destroy(mapreg_db,NULL);
  3008. mapregstr_db->destroy(mapregstr_db,NULL);
  3009. scriptlabel_db->destroy(scriptlabel_db,NULL);
  3010. userfunc_db->destroy(userfunc_db,do_final_userfunc_sub);
  3011. if(sleep_db) {
  3012. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  3013. while(n) {
  3014. struct script_state *st = (struct script_state *)n->data;
  3015. script_free_stack(st->stack);
  3016. free(st);
  3017. n = n->next;
  3018. }
  3019. linkdb_final(&sleep_db);
  3020. }
  3021. if (str_data)
  3022. aFree(str_data);
  3023. if (str_buf)
  3024. aFree(str_buf);
  3025. return 0;
  3026. }
  3027. /*==========================================
  3028. * 初期化
  3029. *------------------------------------------
  3030. */
  3031. int do_init_script()
  3032. {
  3033. mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
  3034. mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
  3035. userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_RELEASE_BOTH,50);
  3036. scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_ALLOW_NULL_DATA,50);
  3037. script_load_mapreg();
  3038. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  3039. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  3040. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  3041. return 0;
  3042. }
  3043. int script_reload()
  3044. {
  3045. if(mapreg_dirty>=0)
  3046. script_save_mapreg();
  3047. mapreg_db->clear(mapreg_db, NULL);
  3048. mapregstr_db->clear(mapregstr_db, NULL);
  3049. userfunc_db->clear(userfunc_db,do_final_userfunc_sub);
  3050. scriptlabel_db->clear(scriptlabel_db, NULL);
  3051. if(sleep_db) {
  3052. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  3053. while(n) {
  3054. struct script_state *st = (struct script_state *)n->data;
  3055. script_free_stack(st->stack);
  3056. free(st);
  3057. n = n->next;
  3058. }
  3059. linkdb_final(&sleep_db);
  3060. }
  3061. script_load_mapreg();
  3062. return 0;
  3063. }
  3064. int buildin_mes(struct script_state *st);
  3065. int buildin_goto(struct script_state *st);
  3066. int buildin_callsub(struct script_state *st);
  3067. int buildin_callfunc(struct script_state *st);
  3068. int buildin_return(struct script_state *st);
  3069. int buildin_getarg(struct script_state *st);
  3070. int buildin_next(struct script_state *st);
  3071. int buildin_close(struct script_state *st);
  3072. int buildin_close2(struct script_state *st);
  3073. int buildin_menu(struct script_state *st);
  3074. int buildin_rand(struct script_state *st);
  3075. int buildin_warp(struct script_state *st);
  3076. int buildin_areawarp(struct script_state *st);
  3077. int buildin_warpchar(struct script_state *st); // [LuzZza]
  3078. int buildin_warpparty(struct script_state *st); //[Fredzilla]
  3079. int buildin_warpguild(struct script_state *st); //[Fredzilla]
  3080. int buildin_heal(struct script_state *st);
  3081. int buildin_itemheal(struct script_state *st);
  3082. int buildin_percentheal(struct script_state *st);
  3083. int buildin_jobchange(struct script_state *st);
  3084. int buildin_input(struct script_state *st);
  3085. int buildin_setlook(struct script_state *st);
  3086. int buildin_set(struct script_state *st);
  3087. int buildin_setarray(struct script_state *st);
  3088. int buildin_cleararray(struct script_state *st);
  3089. int buildin_copyarray(struct script_state *st);
  3090. int buildin_getarraysize(struct script_state *st);
  3091. int buildin_deletearray(struct script_state *st);
  3092. int buildin_getelementofarray(struct script_state *st);
  3093. int buildin_getitem(struct script_state *st);
  3094. int buildin_getitem2(struct script_state *st);
  3095. int buildin_getnameditem(struct script_state *st);
  3096. int buildin_grouprandomitem(struct script_state *st);
  3097. int buildin_makeitem(struct script_state *st);
  3098. int buildin_delitem(struct script_state *st);
  3099. int buildin_delitem2(struct script_state *st);
  3100. int buildin_enableitemuse(struct script_state *st);
  3101. int buildin_disableitemuse(struct script_state *st);
  3102. int buildin_viewpoint(struct script_state *st);
  3103. int buildin_countitem(struct script_state *st);
  3104. int buildin_countitem2(struct script_state *st);
  3105. int buildin_checkweight(struct script_state *st);
  3106. int buildin_readparam(struct script_state *st);
  3107. int buildin_getcharid(struct script_state *st);
  3108. int buildin_getpartyname(struct script_state *st);
  3109. int buildin_getpartymember(struct script_state *st);
  3110. int buildin_getguildname(struct script_state *st);
  3111. int buildin_getguildmaster(struct script_state *st);
  3112. int buildin_getguildmasterid(struct script_state *st);
  3113. int buildin_strcharinfo(struct script_state *st);
  3114. int buildin_getequipid(struct script_state *st);
  3115. int buildin_getequipname(struct script_state *st);
  3116. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  3117. int buildin_repair(struct script_state *st); // [Valaris]
  3118. int buildin_getequipisequiped(struct script_state *st);
  3119. int buildin_getequipisenableref(struct script_state *st);
  3120. int buildin_getequipisidentify(struct script_state *st);
  3121. int buildin_getequiprefinerycnt(struct script_state *st);
  3122. int buildin_getequipweaponlv(struct script_state *st);
  3123. int buildin_getequippercentrefinery(struct script_state *st);
  3124. int buildin_successrefitem(struct script_state *st);
  3125. int buildin_failedrefitem(struct script_state *st);
  3126. int buildin_cutin(struct script_state *st);
  3127. int buildin_cutincard(struct script_state *st);
  3128. int buildin_statusup(struct script_state *st);
  3129. int buildin_statusup2(struct script_state *st);
  3130. int buildin_bonus(struct script_state *st);
  3131. int buildin_bonus2(struct script_state *st);
  3132. int buildin_bonus3(struct script_state *st);
  3133. int buildin_bonus4(struct script_state *st);
  3134. int buildin_skill(struct script_state *st);
  3135. int buildin_addtoskill(struct script_state *st); // [Valaris]
  3136. int buildin_guildskill(struct script_state *st);
  3137. int buildin_getskilllv(struct script_state *st);
  3138. int buildin_getgdskilllv(struct script_state *st);
  3139. int buildin_basicskillcheck(struct script_state *st);
  3140. int buildin_getgmlevel(struct script_state *st);
  3141. int buildin_end(struct script_state *st);
  3142. int buildin_checkoption(struct script_state *st);
  3143. int buildin_setoption(struct script_state *st);
  3144. int buildin_setcart(struct script_state *st);
  3145. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  3146. int buildin_setfalcon(struct script_state *st);
  3147. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  3148. int buildin_setriding(struct script_state *st);
  3149. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  3150. int buildin_savepoint(struct script_state *st);
  3151. int buildin_gettimetick(struct script_state *st);
  3152. int buildin_gettime(struct script_state *st);
  3153. int buildin_gettimestr(struct script_state *st);
  3154. int buildin_openstorage(struct script_state *st);
  3155. int buildin_guildopenstorage(struct script_state *st);
  3156. int buildin_itemskill(struct script_state *st);
  3157. int buildin_produce(struct script_state *st);
  3158. int buildin_monster(struct script_state *st);
  3159. int buildin_areamonster(struct script_state *st);
  3160. int buildin_killmonster(struct script_state *st);
  3161. int buildin_killmonsterall(struct script_state *st);
  3162. int buildin_clone(struct script_state *st);
  3163. int buildin_doevent(struct script_state *st);
  3164. int buildin_donpcevent(struct script_state *st);
  3165. int buildin_addtimer(struct script_state *st);
  3166. int buildin_deltimer(struct script_state *st);
  3167. int buildin_addtimercount(struct script_state *st);
  3168. int buildin_initnpctimer(struct script_state *st);
  3169. int buildin_stopnpctimer(struct script_state *st);
  3170. int buildin_startnpctimer(struct script_state *st);
  3171. int buildin_setnpctimer(struct script_state *st);
  3172. int buildin_getnpctimer(struct script_state *st);
  3173. int buildin_attachnpctimer(struct script_state *st); // [celest]
  3174. int buildin_detachnpctimer(struct script_state *st); // [celest]
  3175. int buildin_playerattached(struct script_state *st); // [Skotlex]
  3176. int buildin_announce(struct script_state *st);
  3177. int buildin_mapannounce(struct script_state *st);
  3178. int buildin_areaannounce(struct script_state *st);
  3179. int buildin_getusers(struct script_state *st);
  3180. int buildin_getmapusers(struct script_state *st);
  3181. int buildin_getareausers(struct script_state *st);
  3182. int buildin_getareadropitem(struct script_state *st);
  3183. int buildin_enablenpc(struct script_state *st);
  3184. int buildin_disablenpc(struct script_state *st);
  3185. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  3186. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  3187. int buildin_hideoffnpc(struct script_state *st);
  3188. int buildin_hideonnpc(struct script_state *st);
  3189. int buildin_sc_start(struct script_state *st);
  3190. int buildin_sc_start2(struct script_state *st);
  3191. int buildin_sc_start4(struct script_state *st);
  3192. int buildin_sc_end(struct script_state *st);
  3193. int buildin_getscrate(struct script_state *st);
  3194. int buildin_debugmes(struct script_state *st);
  3195. int buildin_catchpet(struct script_state *st);
  3196. int buildin_birthpet(struct script_state *st);
  3197. int buildin_resetlvl(struct script_state *st);
  3198. int buildin_resetstatus(struct script_state *st);
  3199. int buildin_resetskill(struct script_state *st);
  3200. int buildin_skillpointcount(struct script_state *st);
  3201. int buildin_changebase(struct script_state *st);
  3202. int buildin_changesex(struct script_state *st);
  3203. int buildin_waitingroom(struct script_state *st);
  3204. int buildin_delwaitingroom(struct script_state *st);
  3205. int buildin_enablewaitingroomevent(struct script_state *st);
  3206. int buildin_disablewaitingroomevent(struct script_state *st);
  3207. int buildin_getwaitingroomstate(struct script_state *st);
  3208. int buildin_warpwaitingpc(struct script_state *st);
  3209. int buildin_attachrid(struct script_state *st);
  3210. int buildin_detachrid(struct script_state *st);
  3211. int buildin_isloggedin(struct script_state *st);
  3212. int buildin_setmapflagnosave(struct script_state *st);
  3213. int buildin_setmapflag(struct script_state *st);
  3214. int buildin_removemapflag(struct script_state *st);
  3215. int buildin_pvpon(struct script_state *st);
  3216. int buildin_pvpoff(struct script_state *st);
  3217. int buildin_gvgon(struct script_state *st);
  3218. int buildin_gvgoff(struct script_state *st);
  3219. int buildin_emotion(struct script_state *st);
  3220. int buildin_maprespawnguildid(struct script_state *st);
  3221. int buildin_agitstart(struct script_state *st); // <Agit>
  3222. int buildin_agitend(struct script_state *st);
  3223. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  3224. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  3225. int buildin_getcastlename(struct script_state *st);
  3226. int buildin_getcastledata(struct script_state *st);
  3227. int buildin_setcastledata(struct script_state *st);
  3228. int buildin_requestguildinfo(struct script_state *st);
  3229. int buildin_getequipcardcnt(struct script_state *st);
  3230. int buildin_successremovecards(struct script_state *st);
  3231. int buildin_failedremovecards(struct script_state *st);
  3232. int buildin_marriage(struct script_state *st);
  3233. int buildin_wedding_effect(struct script_state *st);
  3234. int buildin_divorce(struct script_state *st);
  3235. int buildin_ispartneron(struct script_state *st); // MouseJstr
  3236. int buildin_getpartnerid(struct script_state *st); // MouseJstr
  3237. int buildin_getchildid(struct script_state *st); // Skotlex
  3238. int buildin_getmotherid(struct script_state *st); // Lupus
  3239. int buildin_getfatherid(struct script_state *st); // Lupus
  3240. int buildin_warppartner(struct script_state *st); // MouseJstr
  3241. int buildin_getitemname(struct script_state *st);
  3242. int buildin_getitemslots(struct script_state *st);
  3243. int buildin_makepet(struct script_state *st);
  3244. int buildin_getexp(struct script_state *st);
  3245. int buildin_getinventorylist(struct script_state *st);
  3246. int buildin_getskilllist(struct script_state *st);
  3247. int buildin_clearitem(struct script_state *st);
  3248. int buildin_classchange(struct script_state *st);
  3249. int buildin_misceffect(struct script_state *st);
  3250. int buildin_soundeffect(struct script_state *st);
  3251. int buildin_soundeffectall(struct script_state *st);
  3252. int buildin_setcastledata(struct script_state *st);
  3253. int buildin_mapwarp(struct script_state *st);
  3254. int buildin_inittimer(struct script_state *st);
  3255. int buildin_stoptimer(struct script_state *st);
  3256. int buildin_cmdothernpc(struct script_state *st);
  3257. int buildin_mobcount(struct script_state *st);
  3258. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3259. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  3260. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3261. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  3262. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  3263. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  3264. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  3265. //int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  3266. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Skotlex]
  3267. int buildin_petskillattack2(struct script_state *st); // pet skill attacks [Skotlex]
  3268. int buildin_petskillsupport(struct script_state *st); // pet support skill [Valaris]
  3269. int buildin_skilleffect(struct script_state *st); // skill effects [Celest]
  3270. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  3271. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  3272. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  3273. int buildin_nude(struct script_state *st); // nude [Valaris]
  3274. int buildin_atcommand(struct script_state *st); // [MouseJstr]
  3275. int buildin_charcommand(struct script_state *st); // [MouseJstr]
  3276. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  3277. int buildin_message(struct script_state *st); // [MouseJstr]
  3278. int buildin_npctalk(struct script_state *st); // [Valaris]
  3279. int buildin_hasitems(struct script_state *st); // [Valaris]
  3280. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  3281. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  3282. int buildin_npcspeed(struct script_state *st); // [Valaris]
  3283. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  3284. int buildin_npcstop(struct script_state *st); // [Valaris]
  3285. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  3286. int buildin_checkoption1(struct script_state *st); // [celest]
  3287. int buildin_checkoption2(struct script_state *st); // [celest]
  3288. int buildin_guildgetexp(struct script_state *st); // [celest]
  3289. int buildin_guildchangegm(struct script_state *st); // [Skotlex]
  3290. int buildin_logmes(struct script_state *st); // [Lupus]
  3291. int buildin_summon(struct script_state *st); // [celest]
  3292. int buildin_isnight(struct script_state *st); // [celest]
  3293. int buildin_isday(struct script_state *st); // [celest]
  3294. int buildin_isequipped(struct script_state *st); // [celest]
  3295. int buildin_isequippedcnt(struct script_state *st); // [celest]
  3296. int buildin_cardscnt(struct script_state *st); // [Lupus]
  3297. int buildin_getrefine(struct script_state *st); // [celest]
  3298. int buildin_adopt(struct script_state *st);
  3299. int buildin_night(struct script_state *st);
  3300. int buildin_day(struct script_state *st);
  3301. int buildin_getusersname(struct script_state *st); //jA commands added [Lupus]
  3302. int buildin_dispbottom(struct script_state *st);
  3303. int buildin_recovery(struct script_state *st);
  3304. int buildin_getpetinfo(struct script_state *st);
  3305. int buildin_checkequipedcard(struct script_state *st);
  3306. int buildin_globalmes(struct script_state *st);
  3307. int buildin_jump_zero(struct script_state *st);
  3308. int buildin_select(struct script_state *st);
  3309. int buildin_getmapmobs(struct script_state *st); //jA addition end
  3310. int buildin_unequip(struct script_state *st); // unequip [Spectre]
  3311. int buildin_getstrlen(struct script_state *st); //strlen [valaris]
  3312. int buildin_charisalpha(struct script_state *st);//isalpha [valaris]
  3313. int buildin_fakenpcname(struct script_state *st); // [Lance]
  3314. int buildin_compare(struct script_state *st); // Lordalfa, to bring strstr to Scripting Engine
  3315. int buildin_getiteminfo(struct script_state *st); //[Lupus] returns Items Buy / sell Price, etc info
  3316. int buildin_getequipcardid(struct script_state *st); //[Lupus] returns card id from quipped item card slot N
  3317. // [zBuffer] List of mathematics commands --->
  3318. int buildin_sqrt(struct script_state *st);
  3319. int buildin_pow(struct script_state *st);
  3320. int buildin_distance(struct script_state *st);
  3321. int buildin_checkcell(struct script_state *st);
  3322. // <--- [zBuffer] List of mathematics commands
  3323. // [zBuffer] List of dynamic var commands --->
  3324. int buildin_getd(struct script_state *st);
  3325. int buildin_setd(struct script_state *st);
  3326. // <--- [zBuffer] List of dynamic var commands
  3327. int buildin_petstat(struct script_state *st); // [Lance] Pet Stat Rq: Dubby
  3328. int buildin_callshop(struct script_state *st); // [Skotlex]
  3329. int buildin_npcshopitem(struct script_state *st); // [Lance]
  3330. int buildin_npcshopadditem(struct script_state *st);
  3331. int buildin_npcshopdelitem(struct script_state *st);
  3332. int buildin_equip(struct script_state *st);
  3333. int buildin_autoequip(struct script_state *st);
  3334. int buildin_setbattleflag(struct script_state *st);
  3335. int buildin_getbattleflag(struct script_state *st);
  3336. #ifndef TXT_ONLY
  3337. int buildin_query_sql(struct script_state *st);
  3338. int buildin_escape_sql(struct script_state *st);
  3339. #endif
  3340. int buildin_atoi(struct script_state *st);
  3341. int buildin_axtoi(struct script_state *st);
  3342. // [zBuffer] List of player cont commands --->
  3343. int buildin_rid2name(struct script_state *st);
  3344. int buildin_pcfollow(struct script_state *st);
  3345. int buildin_pcstopfollow(struct script_state *st);
  3346. int buildin_pcblockmove(struct script_state *st);
  3347. // <--- [zBuffer] List of player cont commands
  3348. // [zBuffer] List of mob control commands --->
  3349. int buildin_mobspawn(struct script_state *st);
  3350. int buildin_mobremove(struct script_state *st);
  3351. int buildin_getmobdata(struct script_state *st);
  3352. int buildin_setmobdata(struct script_state *st);
  3353. int buildin_mobassist(struct script_state *st);
  3354. int buildin_mobattach(struct script_state *st);
  3355. int buildin_unitwalk(struct script_state *st);
  3356. int buildin_unitkill(struct script_state *st);
  3357. int buildin_unitwarp(struct script_state *st);
  3358. int buildin_unitattack(struct script_state *st);
  3359. int buildin_unitstop(struct script_state *st);
  3360. int buildin_unittalk(struct script_state *st);
  3361. int buildin_unitemote(struct script_state *st);
  3362. int buildin_unitdeadsit(struct script_state *st);
  3363. int buildin_unitskilluseid(struct script_state *st); // originally by Qamera [celest]
  3364. int buildin_unitskillusepos(struct script_state *st); // originally by Qamera [celest]
  3365. // <--- [zBuffer] List of mob control commands
  3366. int buildin_sleep(struct script_state *st);
  3367. int buildin_sleep2(struct script_state *st);
  3368. int buildin_awake(struct script_state *st);
  3369. int buildin_getvariableofnpc(struct script_state *st);
  3370. // [blackhole89] -->
  3371. int buildin_warpportal(struct script_state *st);
  3372. // <-- [blackhole89]
  3373. int buildin_homunculus_evolution(struct script_state *st) ; //[orn]
  3374. int buildin_setitemscript(struct script_state *st);
  3375. int buildin_disguise(struct script_state *st);
  3376. int buildin_undisguise(struct script_state *st);
  3377. int buildin_getmonsterinfo(struct script_state *st); // [Lupus]
  3378. #ifdef PCRE_SUPPORT
  3379. int buildin_defpattern(struct script_state *st); // MouseJstr
  3380. int buildin_activatepset(struct script_state *st); // MouseJstr
  3381. int buildin_deactivatepset(struct script_state *st); // MouseJstr
  3382. int buildin_deletepset(struct script_state *st); // MouseJstr
  3383. #endif
  3384. struct script_function buildin_func[] = {
  3385. {buildin_mes,"mes","s"},
  3386. {buildin_next,"next",""},
  3387. {buildin_close,"close",""},
  3388. {buildin_close2,"close2",""},
  3389. {buildin_menu,"menu","*"},
  3390. {buildin_goto,"goto","l"},
  3391. {buildin_callsub,"callsub","i*"},
  3392. {buildin_callfunc,"callfunc","s*"},
  3393. {buildin_return,"return","*"},
  3394. {buildin_getarg,"getarg","i"},
  3395. {buildin_jobchange,"jobchange","i*"},
  3396. {buildin_input,"input","*"},
  3397. {buildin_warp,"warp","sii"},
  3398. {buildin_areawarp,"areawarp","siiiisii"},
  3399. {buildin_warpchar,"warpchar","siii"}, // [LuzZza]
  3400. {buildin_warpparty,"warpparty","siii"}, // [Fredzilla]
  3401. {buildin_warpguild,"warpguild","siii"}, // [Fredzilla]
  3402. {buildin_setlook,"setlook","ii"},
  3403. {buildin_set,"set","ii"},
  3404. {buildin_setarray,"setarray","ii*"},
  3405. {buildin_cleararray,"cleararray","iii"},
  3406. {buildin_copyarray,"copyarray","iii"},
  3407. {buildin_getarraysize,"getarraysize","i"},
  3408. {buildin_deletearray,"deletearray","ii"},
  3409. {buildin_getelementofarray,"getelementofarray","ii"},
  3410. {buildin_getitem,"getitem","ii**"},
  3411. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  3412. {buildin_getnameditem,"getnameditem","is"},
  3413. {buildin_grouprandomitem,"groupranditem","i"},
  3414. {buildin_makeitem,"makeitem","iisii"},
  3415. {buildin_delitem,"delitem","ii"},
  3416. {buildin_delitem2,"delitem2","iiiiiiiii"},
  3417. {buildin_enableitemuse,"enable_items",""},
  3418. {buildin_disableitemuse,"disable_items",""},
  3419. {buildin_cutin,"cutin","si"},
  3420. {buildin_cutincard,"cutincard","i"},
  3421. {buildin_viewpoint,"viewpoint","iiiii"},
  3422. {buildin_heal,"heal","ii"},
  3423. {buildin_itemheal,"itemheal","ii"},
  3424. {buildin_percentheal,"percentheal","ii"},
  3425. {buildin_rand,"rand","i*"},
  3426. {buildin_countitem,"countitem","i"},
  3427. {buildin_countitem2,"countitem2","iiiiiiii"},
  3428. {buildin_checkweight,"checkweight","ii"},
  3429. {buildin_readparam,"readparam","i*"},
  3430. {buildin_getcharid,"getcharid","i*"},
  3431. {buildin_getpartyname,"getpartyname","i"},
  3432. {buildin_getpartymember,"getpartymember","i*"},
  3433. {buildin_getguildname,"getguildname","i"},
  3434. {buildin_getguildmaster,"getguildmaster","i"},
  3435. {buildin_getguildmasterid,"getguildmasterid","i"},
  3436. {buildin_strcharinfo,"strcharinfo","i"},
  3437. {buildin_getequipid,"getequipid","i"},
  3438. {buildin_getequipname,"getequipname","i"},
  3439. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  3440. {buildin_repair,"repair","i"}, // [Valaris]
  3441. {buildin_getequipisequiped,"getequipisequiped","i"},
  3442. {buildin_getequipisenableref,"getequipisenableref","i"},
  3443. {buildin_getequipisidentify,"getequipisidentify","i"},
  3444. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  3445. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  3446. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  3447. {buildin_successrefitem,"successrefitem","i"},
  3448. {buildin_failedrefitem,"failedrefitem","i"},
  3449. {buildin_statusup,"statusup","i"},
  3450. {buildin_statusup2,"statusup2","ii"},
  3451. {buildin_bonus,"bonus","ii"},
  3452. {buildin_bonus2,"bonus2","iii"},
  3453. {buildin_bonus3,"bonus3","iiii"},
  3454. {buildin_bonus4,"bonus4","iiiii"},
  3455. {buildin_skill,"skill","ii*"},
  3456. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  3457. {buildin_guildskill,"guildskill","ii"},
  3458. {buildin_getskilllv,"getskilllv","i"},
  3459. {buildin_getgdskilllv,"getgdskilllv","ii"},
  3460. {buildin_basicskillcheck,"basicskillcheck","*"},
  3461. {buildin_getgmlevel,"getgmlevel","*"},
  3462. {buildin_end,"end",""},
  3463. // {buildin_end,"break",""}, this might confuse advanced scripting support [Eoe]
  3464. {buildin_checkoption,"checkoption","i"},
  3465. {buildin_setoption,"setoption","i*"},
  3466. {buildin_setcart,"setcart",""},
  3467. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  3468. {buildin_setfalcon,"setfalcon",""},
  3469. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3470. {buildin_setriding,"setriding",""},
  3471. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3472. {buildin_savepoint,"save","sii"},
  3473. {buildin_savepoint,"savepoint","sii"},
  3474. {buildin_gettimetick,"gettimetick","i"},
  3475. {buildin_gettime,"gettime","i"},
  3476. {buildin_gettimestr,"gettimestr","si"},
  3477. {buildin_openstorage,"openstorage",""},
  3478. {buildin_guildopenstorage,"guildopenstorage","*"},
  3479. {buildin_itemskill,"itemskill","iis"},
  3480. {buildin_produce,"produce","i"},
  3481. {buildin_monster,"monster","siisii*"},
  3482. {buildin_areamonster,"areamonster","siiiisii*"},
  3483. {buildin_killmonster,"killmonster","ss"},
  3484. {buildin_killmonsterall,"killmonsterall","s"},
  3485. {buildin_clone,"clone","siisi*"},
  3486. {buildin_doevent,"doevent","s"},
  3487. {buildin_donpcevent,"donpcevent","s"},
  3488. {buildin_addtimer,"addtimer","is"},
  3489. {buildin_deltimer,"deltimer","s"},
  3490. {buildin_addtimercount,"addtimercount","si"},
  3491. {buildin_initnpctimer,"initnpctimer","*"},
  3492. {buildin_stopnpctimer,"stopnpctimer","*"},
  3493. {buildin_startnpctimer,"startnpctimer","*"},
  3494. {buildin_setnpctimer,"setnpctimer","*"},
  3495. {buildin_getnpctimer,"getnpctimer","i*"},
  3496. {buildin_attachnpctimer,"attachnpctimer","*"}, // attached the player id to the npc timer [Celest]
  3497. {buildin_detachnpctimer,"detachnpctimer","*"}, // detached the player id from the npc timer [Celest]
  3498. {buildin_playerattached,"playerattached",""}, // returns id of the current attached player. [Skotlex]
  3499. {buildin_announce,"announce","si*"},
  3500. {buildin_mapannounce,"mapannounce","ssi*"},
  3501. {buildin_areaannounce,"areaannounce","siiiisi*"},
  3502. {buildin_getusers,"getusers","i"},
  3503. {buildin_getmapusers,"getmapusers","s"},
  3504. {buildin_getareausers,"getareausers","siiii"},
  3505. {buildin_getareadropitem,"getareadropitem","siiiii"},
  3506. {buildin_enablenpc,"enablenpc","s"},
  3507. {buildin_disablenpc,"disablenpc","s"},
  3508. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  3509. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  3510. {buildin_hideoffnpc,"hideoffnpc","s"},
  3511. {buildin_hideonnpc,"hideonnpc","s"},
  3512. {buildin_sc_start,"sc_start","iii*"},
  3513. {buildin_sc_start2,"sc_start2","iiii*"},
  3514. {buildin_sc_start4,"sc_start4","iiiiii*"},
  3515. {buildin_sc_end,"sc_end","i"},
  3516. {buildin_getscrate,"getscrate","ii*"},
  3517. {buildin_debugmes,"debugmes","s"},
  3518. {buildin_catchpet,"pet","i"},
  3519. {buildin_birthpet,"bpet",""},
  3520. {buildin_resetlvl,"resetlvl","i"},
  3521. {buildin_resetstatus,"resetstatus",""},
  3522. {buildin_resetskill,"resetskill",""},
  3523. {buildin_skillpointcount,"skillpointcount",""},
  3524. {buildin_changebase,"changebase","i"},
  3525. {buildin_changesex,"changesex",""},
  3526. {buildin_waitingroom,"waitingroom","si*"},
  3527. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  3528. {buildin_delwaitingroom,"delwaitingroom","*"},
  3529. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  3530. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  3531. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  3532. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  3533. {buildin_attachrid,"attachrid","i"},
  3534. {buildin_detachrid,"detachrid",""},
  3535. {buildin_isloggedin,"isloggedin","i"},
  3536. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  3537. {buildin_setmapflag,"setmapflag","si*"},
  3538. {buildin_removemapflag,"removemapflag","si"},
  3539. {buildin_pvpon,"pvpon","s"},
  3540. {buildin_pvpoff,"pvpoff","s"},
  3541. {buildin_gvgon,"gvgon","s"},
  3542. {buildin_gvgoff,"gvgoff","s"},
  3543. {buildin_emotion,"emotion","i*"},
  3544. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  3545. {buildin_agitstart,"agitstart",""}, // <Agit>
  3546. {buildin_agitend,"agitend",""},
  3547. {buildin_agitcheck,"agitcheck","i"}, // <Agitcheck>
  3548. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  3549. {buildin_getcastlename,"getcastlename","s"},
  3550. {buildin_getcastledata,"getcastledata","si*"},
  3551. {buildin_setcastledata,"setcastledata","sii"},
  3552. {buildin_requestguildinfo,"requestguildinfo","i*"},
  3553. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  3554. {buildin_successremovecards,"successremovecards","i"},
  3555. {buildin_failedremovecards,"failedremovecards","ii"},
  3556. {buildin_marriage,"marriage","s"},
  3557. {buildin_wedding_effect,"wedding",""},
  3558. {buildin_divorce,"divorce",""},
  3559. {buildin_ispartneron,"ispartneron",""},
  3560. {buildin_getpartnerid,"getpartnerid",""},
  3561. {buildin_getchildid,"getchildid",""},
  3562. {buildin_getmotherid,"getmotherid",""},
  3563. {buildin_getfatherid,"getfatherid",""},
  3564. {buildin_warppartner,"warppartner","sii"},
  3565. {buildin_getitemname,"getitemname","i"},
  3566. {buildin_getitemslots,"getitemslots","i"},
  3567. {buildin_makepet,"makepet","i"},
  3568. {buildin_getexp,"getexp","ii"},
  3569. {buildin_getinventorylist,"getinventorylist",""},
  3570. {buildin_getskilllist,"getskilllist",""},
  3571. {buildin_clearitem,"clearitem",""},
  3572. {buildin_classchange,"classchange","ii"},
  3573. {buildin_misceffect,"misceffect","i"},
  3574. {buildin_soundeffect,"soundeffect","si"},
  3575. {buildin_soundeffectall,"soundeffectall","si*"}, // SoundEffectAll [Codemaster]
  3576. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  3577. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  3578. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  3579. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  3580. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  3581. {buildin_petloot,"petloot","i"}, // [Valaris]
  3582. {buildin_petheal,"petheal","iiii"}, // [Valaris]
  3583. // {buildin_petmag,"petmag","iiii"}, // [Valaris]
  3584. {buildin_petskillattack,"petskillattack","iiii"}, // [Skotlex]
  3585. {buildin_petskillattack2,"petskillattack2","iiiii"}, // [Valaris]
  3586. {buildin_petskillsupport,"petskillsupport","iiiii"}, // [Skotlex]
  3587. {buildin_skilleffect,"skilleffect","ii"}, // skill effect [Celest]
  3588. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  3589. {buildin_specialeffect,"specialeffect","i*"}, // npc skill effect [Valaris]
  3590. {buildin_specialeffect2,"specialeffect2","i*"}, // skill effect on players[Valaris]
  3591. {buildin_nude,"nude",""}, // nude command [Valaris]
  3592. {buildin_mapwarp,"mapwarp","ssii"}, // Added by RoVeRT
  3593. {buildin_inittimer,"inittimer",""},
  3594. {buildin_stoptimer,"stoptimer",""},
  3595. {buildin_cmdothernpc,"cmdothernpc","ss"},
  3596. {buildin_atcommand,"atcommand","*"}, // [MouseJstr]
  3597. {buildin_charcommand,"charcommand","*"}, // [MouseJstr]
  3598. {buildin_movenpc,"movenpc","sii"}, // [MouseJstr]
  3599. {buildin_message,"message","s*"}, // [MouseJstr]
  3600. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  3601. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  3602. {buildin_mobcount,"mobcount","ss"},
  3603. {buildin_getlook,"getlook","i"},
  3604. {buildin_getsavepoint,"getsavepoint","i"},
  3605. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  3606. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  3607. {buildin_npcstop,"npcstop",""}, // [Valaris]
  3608. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  3609. {buildin_checkoption1,"checkoption1","i"},
  3610. {buildin_checkoption2,"checkoption2","i"},
  3611. {buildin_guildgetexp,"guildgetexp","i"},
  3612. {buildin_guildchangegm,"guildchangegm","is"},
  3613. {buildin_logmes,"logmes","s"}, //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
  3614. {buildin_summon,"summon","si*"}, // summons a slave monster [Celest]
  3615. {buildin_isnight,"isnight",""}, // check whether it is night time [Celest]
  3616. {buildin_isday,"isday",""}, // check whether it is day time [Celest]
  3617. {buildin_isequipped,"isequipped","i*"}, // check whether another item/card has been equipped [Celest]
  3618. {buildin_isequippedcnt,"isequippedcnt","i*"}, // check how many items/cards are being equipped [Celest]
  3619. {buildin_cardscnt,"cardscnt","i*"}, // check how many items/cards are being equipped in the same arm [Lupus]
  3620. {buildin_getrefine,"getrefine","*"}, // returns the refined number of the current item, or an item with index specified [celest]
  3621. {buildin_adopt,"adopt","sss"}, // allows 2 parents to adopt a child
  3622. {buildin_night,"night",""}, // sets the server to night time
  3623. {buildin_day,"day",""}, // sets the server to day time
  3624. #ifdef PCRE_SUPPORT
  3625. {buildin_defpattern, "defpattern", "iss"}, // Define pattern to listen for [MouseJstr]
  3626. {buildin_activatepset, "activatepset", "i"}, // Activate a pattern set [MouseJstr]
  3627. {buildin_deactivatepset, "deactivatepset", "i"}, // Deactive a pattern set [MouseJstr]
  3628. {buildin_deletepset, "deletepset", "i"}, // Delete a pattern set [MouseJstr]
  3629. #endif
  3630. {buildin_dispbottom,"dispbottom","s"}, //added from jA [Lupus]
  3631. {buildin_getusersname,"getusersname","*"},
  3632. {buildin_recovery,"recovery",""},
  3633. {buildin_getpetinfo,"getpetinfo","i"},
  3634. {buildin_checkequipedcard,"checkequipedcard","i"},
  3635. {buildin_jump_zero,"jump_zero","ii"}, //for future jA script compatibility
  3636. {buildin_select,"select","*"}, //for future jA script compatibility
  3637. {buildin_globalmes,"globalmes","s*"},
  3638. {buildin_getmapmobs,"getmapmobs","s"}, //end jA addition
  3639. {buildin_unequip,"unequip","i"}, // unequip command [Spectre]
  3640. {buildin_getstrlen,"getstrlen","s"}, //strlen [Valaris]
  3641. {buildin_charisalpha,"charisalpha","si"}, //isalpha [Valaris]
  3642. {buildin_fakenpcname,"fakenpcname","ssi"}, // [Lance]
  3643. {buildin_compare,"compare","ss"}, // Lordalfa - To bring strstr to scripting Engine.
  3644. {buildin_getiteminfo,"getiteminfo","ii"}, //[Lupus] returns Items Buy / sell Price, etc info
  3645. {buildin_getequipcardid,"getequipcardid","ii"}, //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
  3646. // [zBuffer] List of mathematics commands --->
  3647. {buildin_sqrt,"sqrt","i"},
  3648. {buildin_pow,"pow","ii"},
  3649. {buildin_distance,"distance","iiii"},
  3650. {buildin_checkcell,"checkcell","siii"},
  3651. // <--- [zBuffer] List of mathematics commands
  3652. // [zBuffer] List of dynamic var commands --->
  3653. {buildin_getd,"getd","*"},
  3654. {buildin_setd,"setd","*"},
  3655. // <--- [zBuffer] List of dynamic var commands
  3656. {buildin_petstat,"petstat","i"},
  3657. {buildin_callshop,"callshop","si"}, // [Skotlex]
  3658. {buildin_npcshopitem,"npcshopitem","sii*"}, // [Lance]
  3659. {buildin_npcshopadditem,"npcshopadditem","sii*"},
  3660. {buildin_npcshopdelitem,"npcshopdelitem","si*"},
  3661. {buildin_equip,"equip","i"},
  3662. {buildin_autoequip,"autoequip","ii"},
  3663. {buildin_setbattleflag,"setbattleflag","ss"},
  3664. {buildin_getbattleflag,"getbattleflag","s"},
  3665. {buildin_setitemscript,"setitemscript","is"}, //Set NEW item bonus script. Lupus
  3666. {buildin_disguise,"disguise","i"}, //disguise player. Lupus
  3667. {buildin_undisguise,"undisguise","i"}, //undisguise player. Lupus
  3668. {buildin_getmonsterinfo,"getmonsterinfo","ii"}, //Lupus
  3669. {buildin_axtoi,"axtoi","s"},
  3670. #ifndef TXT_ONLY
  3671. {buildin_query_sql, "query_sql", "s*"},
  3672. {buildin_escape_sql, "escape_sql", "s"},
  3673. #endif
  3674. {buildin_atoi,"atoi","s"},
  3675. // [zBuffer] List of player cont commands --->
  3676. {buildin_rid2name,"rid2name","i"},
  3677. {buildin_pcfollow,"pcfollow","ii"},
  3678. {buildin_pcstopfollow,"pcstopfollow","i"},
  3679. {buildin_pcblockmove,"pcblockmove","ii"},
  3680. // <--- [zBuffer] List of player cont commands
  3681. // [zBuffer] List of mob control commands --->
  3682. {buildin_mobspawn,"mobspawn","*"},
  3683. {buildin_mobremove,"mobremove","i"},
  3684. {buildin_getmobdata,"getmobdata","i*"},
  3685. {buildin_setmobdata,"setmobdata","iii"},
  3686. {buildin_mobassist,"mobassist","i*"},
  3687. {buildin_mobattach,"mobattach","i*"},
  3688. {buildin_unitwalk,"unitwalk","i*"},
  3689. {buildin_unitkill,"unitkill","i"},
  3690. {buildin_unitwarp,"unitwarp","isii"},
  3691. {buildin_unitattack,"unitattack","i*"},
  3692. {buildin_unitstop,"unitstop","i"},
  3693. {buildin_unittalk,"unittalk","is"},
  3694. {buildin_unitemote,"unitemote","ii"},
  3695. {buildin_unitdeadsit,"unitdeadsit","ii"},
  3696. {buildin_unitskilluseid,"unitskilluseid","iii*"}, // originally by Qamera [Celest]
  3697. {buildin_unitskillusepos,"unitskillusepos","iiiii"}, // [Celest]
  3698. // <--- [zBuffer] List of mob control commands
  3699. {buildin_sleep,"sleep","i"},
  3700. {buildin_sleep2,"sleep2","i"},
  3701. {buildin_awake,"awake","s"},
  3702. {buildin_getvariableofnpc,"getvariableofnpc","is"},
  3703. // [blackhole89] -->
  3704. {buildin_warpportal,"warpportal","iisii"},
  3705. // <--- [blackhole89]
  3706. {buildin_homunculus_evolution,"homevolution",""}, //[orn]
  3707. {NULL,NULL,NULL},
  3708. };
  3709. /*==========================================
  3710. *
  3711. *------------------------------------------
  3712. */
  3713. int buildin_mes(struct script_state *st)
  3714. {
  3715. conv_str(st,& (st->stack->stack_data[st->start+2]));
  3716. clif_scriptmes(script_rid2sd(st),st->oid,st->stack->stack_data[st->start+2].u.str);
  3717. return 0;
  3718. }
  3719. /*==========================================
  3720. *
  3721. *------------------------------------------
  3722. */
  3723. int buildin_goto(struct script_state *st)
  3724. {
  3725. int pos;
  3726. if( st->stack->stack_data[st->start+2].type!=C_POS){
  3727. ShowMessage("script: goto: not label!\n");
  3728. st->state=END;
  3729. return 1;
  3730. }
  3731. pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3732. st->pos=pos;
  3733. st->state=GOTO;
  3734. return 0;
  3735. }
  3736. /*==========================================
  3737. * ユーザー定義関数の呼び出し
  3738. *------------------------------------------
  3739. */
  3740. int buildin_callfunc(struct script_state *st)
  3741. {
  3742. struct script_code *scr, *oldscr;
  3743. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3744. if( (scr=strdb_get(userfunc_db,(unsigned char*)str)) ){
  3745. int i,j;
  3746. struct linkdb_node **oldval = st->stack->var_function;
  3747. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3748. push_copy(st->stack,i);
  3749. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3750. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3751. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3752. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3753. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3754. oldscr = st->script;
  3755. st->pos=0;
  3756. st->script=scr;
  3757. st->stack->defsp=st->start+5+j;
  3758. st->state=GOTO;
  3759. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3760. // ' 変数の引き継ぎ
  3761. for(i = 0; i < j; i++) {
  3762. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3763. if( s->type == C_NAME && !s->ref ) {
  3764. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3765. // '@ 変数の引き継ぎ
  3766. if( name[0] == '.' && name[1] == '@' ) {
  3767. s->ref = oldval;
  3768. } else if( name[0] == '.' ) {
  3769. s->ref = &oldscr->script_vars;
  3770. }
  3771. }
  3772. }
  3773. }else{
  3774. ShowWarning("script:callfunc: function not found! [%s]\n",str);
  3775. st->state=END;
  3776. return 1;
  3777. }
  3778. return 0;
  3779. }
  3780. /*==========================================
  3781. * サブルーティンの呼び出し
  3782. *------------------------------------------
  3783. */
  3784. int buildin_callsub(struct script_state *st)
  3785. {
  3786. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3787. int i,j;
  3788. if(st->stack->stack_data[st->start+2].type != C_POS && st->stack->stack_data[st->start+2].type != C_USERFUNC_POS) {
  3789. ShowError("script: callsub: not label !\n");
  3790. st->state=END;
  3791. return 1;
  3792. } else {
  3793. struct linkdb_node **oldval = st->stack->var_function;
  3794. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3795. push_copy(st->stack,i);
  3796. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3797. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3798. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3799. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3800. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3801. st->pos=pos;
  3802. st->stack->defsp=st->start+5+j;
  3803. st->state=GOTO;
  3804. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3805. // ' 変数の引き継ぎ
  3806. for(i = 0; i < j; i++) {
  3807. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3808. if( s->type == C_NAME && !s->ref ) {
  3809. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3810. // '@ 変数の引き継ぎ
  3811. if( name[0] == '.' && name[1] == '@' ) {
  3812. s->ref = oldval;
  3813. }
  3814. }
  3815. }
  3816. }
  3817. return 0;
  3818. }
  3819. /*==========================================
  3820. * 引数の所得
  3821. *------------------------------------------
  3822. */
  3823. int buildin_getarg(struct script_state *st)
  3824. {
  3825. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3826. int max,stsp;
  3827. if( st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO ){
  3828. ShowWarning("script:getarg without callfunc or callsub!\n");
  3829. st->state=END;
  3830. return 1;
  3831. }
  3832. max=conv_num(st,& (st->stack->stack_data[st->stack->defsp-5]));
  3833. stsp=st->stack->defsp - max -5;
  3834. if( num >= max ){
  3835. ShowWarning("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  3836. st->state=END;
  3837. return 1;
  3838. }
  3839. push_copy(st->stack,stsp+num);
  3840. return 0;
  3841. }
  3842. /*==========================================
  3843. * サブルーチン/ユーザー定義関数の終了
  3844. *------------------------------------------
  3845. */
  3846. int buildin_return(struct script_state *st)
  3847. {
  3848. if(st->end>st->start+2){ // 戻り値有り
  3849. struct script_data *sd;
  3850. push_copy(st->stack,st->start+2);
  3851. sd = &st->stack->stack_data[st->stack->sp-1];
  3852. if(sd->type == C_NAME) {
  3853. char *name = str_buf + str_data[sd->u.num&0x00ffffff].str;
  3854. if( name[0] == '.' && name[1] == '@') {
  3855. // '@ 変数を参照渡しにすると危険なので値渡しにする
  3856. get_val(st,sd);
  3857. } else if( name[0] == '.' && !sd->ref) {
  3858. // ' 変数は参照渡しでも良いが、参照元が設定されていないと
  3859. // 元のスクリプトの値を差してしまうので補正する。
  3860. sd->ref = &st->script->script_vars;
  3861. }
  3862. }
  3863. }
  3864. st->state=RETFUNC;
  3865. return 0;
  3866. }
  3867. /*==========================================
  3868. *
  3869. *------------------------------------------
  3870. */
  3871. int buildin_next(struct script_state *st)
  3872. {
  3873. st->state=STOP;
  3874. clif_scriptnext(script_rid2sd(st),st->oid);
  3875. return 0;
  3876. }
  3877. /*==========================================
  3878. *
  3879. *------------------------------------------
  3880. */
  3881. int buildin_close(struct script_state *st)
  3882. {
  3883. st->state=END;
  3884. clif_scriptclose(script_rid2sd(st),st->oid);
  3885. return 0;
  3886. }
  3887. int buildin_close2(struct script_state *st)
  3888. {
  3889. st->state=STOP;
  3890. clif_scriptclose(script_rid2sd(st),st->oid);
  3891. return 0;
  3892. }
  3893. /*==========================================
  3894. *
  3895. *------------------------------------------
  3896. */
  3897. int buildin_menu(struct script_state *st)
  3898. {
  3899. char *buf;
  3900. int len,i;
  3901. struct map_session_data *sd = script_rid2sd(st);
  3902. nullpo_retr(0, sd);
  3903. if(sd->state.menu_or_input==0){
  3904. st->state=RERUNLINE;
  3905. sd->state.menu_or_input=1;
  3906. if( (st->end - st->start - 2) % 2 == 1 ) {
  3907. // 引数の数が奇数なのでエラー扱い
  3908. ShowError("buildin_menu: illigal argument count(%d).\n", st->end - st->start - 2);
  3909. sd->state.menu_or_input=0;
  3910. st->state=END;
  3911. return 1;
  3912. }
  3913. for(i=st->start+2,len=0;i<st->end;i+=2){
  3914. conv_str(st,& (st->stack->stack_data[i]));
  3915. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  3916. }
  3917. buf=(char *)aMallocA((len+1)*sizeof(char));
  3918. buf[0]=0;
  3919. for(i=st->start+2,len=0;i<st->end;i+=2){
  3920. if( st->stack->stack_data[i].u.str[0] ) {
  3921. strcat(buf,st->stack->stack_data[i].u.str);
  3922. strcat(buf,":");
  3923. }
  3924. }
  3925. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  3926. aFree(buf);
  3927. } else if(sd->npc_menu==0xff){ // cansel
  3928. sd->state.menu_or_input=0;
  3929. st->state=END;
  3930. } else { // goto動作
  3931. sd->state.menu_or_input=0;
  3932. if(sd->npc_menu>0){
  3933. //Skip empty menu entries which weren't displayed on the client (blackhole89)
  3934. for(i=st->start+2;i<=(st->start+sd->npc_menu*2) && sd->npc_menu<(st->end-st->start)/2;i+=2) {
  3935. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  3936. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  3937. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  3938. }
  3939. if(sd->npc_menu >= (st->end-st->start)/2) {
  3940. //Invalid selection.
  3941. st->state=END;
  3942. return 0;
  3943. }
  3944. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  3945. ShowError("script: menu: not label !\n");
  3946. st->state=END;
  3947. return 1;
  3948. }
  3949. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  3950. st->pos=conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  3951. st->state=GOTO;
  3952. }
  3953. }
  3954. return 0;
  3955. }
  3956. /*==========================================
  3957. *
  3958. *------------------------------------------
  3959. */
  3960. int buildin_rand(struct script_state *st)
  3961. {
  3962. int range,min,max;
  3963. if (st->end > st->start+3){
  3964. min = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3965. max = conv_num(st,& (st->stack->stack_data[st->start+3]));
  3966. if (max == min){ //Why would someone do this?
  3967. push_val(st->stack,C_INT,min);
  3968. return 0;
  3969. }
  3970. if(max<min){
  3971. int tmp = min;
  3972. min = max;
  3973. max = tmp;
  3974. }
  3975. range = max - min + 1;
  3976. if (range == 0) range = 1;
  3977. push_val(st->stack,C_INT,rand()%range+min);
  3978. } else {
  3979. range = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3980. if (range == 0) range = 1;
  3981. push_val(st->stack,C_INT,rand()%range);
  3982. }
  3983. return 0;
  3984. }
  3985. /*==========================================
  3986. *
  3987. *------------------------------------------
  3988. */
  3989. int buildin_warp(struct script_state *st)
  3990. {
  3991. int x,y;
  3992. char *str;
  3993. struct map_session_data *sd=script_rid2sd(st);
  3994. nullpo_retr(0, sd);
  3995. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3996. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3997. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3998. if(strcmp(str,"Random")==0)
  3999. pc_randomwarp(sd,3);
  4000. else if(strcmp(str,"SavePoint")==0){
  4001. pc_setpos(sd,sd->status.save_point.map,
  4002. sd->status.save_point.x,sd->status.save_point.y,3);
  4003. }else if(strcmp(str,"Save")==0){
  4004. pc_setpos(sd,sd->status.save_point.map,
  4005. sd->status.save_point.x,sd->status.save_point.y,3);
  4006. }else
  4007. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  4008. return 0;
  4009. }
  4010. /*==========================================
  4011. * エリア指定ワープ
  4012. *------------------------------------------
  4013. */
  4014. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  4015. {
  4016. int x,y;
  4017. unsigned int map;
  4018. map=va_arg(ap, unsigned int);
  4019. x=va_arg(ap,int);
  4020. y=va_arg(ap,int);
  4021. if(map == 0)
  4022. pc_randomwarp((struct map_session_data *)bl,3);
  4023. else
  4024. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  4025. return 0;
  4026. }
  4027. int buildin_areawarp(struct script_state *st)
  4028. {
  4029. int x,y,m;
  4030. unsigned int index;
  4031. char *str;
  4032. char *mapname;
  4033. int x0,y0,x1,y1;
  4034. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4035. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4036. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4037. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4038. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4039. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  4040. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4041. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4042. if( (m=map_mapname2mapid(mapname))< 0)
  4043. return 0;
  4044. if(strcmp(str,"Random")==0)
  4045. index = 0;
  4046. else if(!(index=mapindex_name2id(str)))
  4047. return 0;
  4048. map_foreachinarea(buildin_areawarp_sub,
  4049. m,x0,y0,x1,y1,BL_PC, index,x,y );
  4050. return 0;
  4051. }
  4052. /*==========================================
  4053. * warpchar [LuzZza]
  4054. * Useful for warp one player from
  4055. * another player npc-session.
  4056. * Using: warpchar "mapname.gat",x,y,Char_ID;
  4057. *------------------------------------------
  4058. */
  4059. int buildin_warpchar(struct script_state *st)
  4060. {
  4061. int x,y,a,i;
  4062. char *str;
  4063. struct map_session_data *sd, **pl_allsd;
  4064. int users;
  4065. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4066. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4067. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4068. a=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4069. pl_allsd = map_getallusers(&users);
  4070. for(i=0; i<users; i++) {
  4071. sd = pl_allsd[i];
  4072. if(sd->status.char_id == a) {
  4073. if(strcmp(str, "Random") == 0)
  4074. pc_randomwarp(sd, 3);
  4075. else if(strcmp(str, "SavePoint") == 0)
  4076. pc_setpos(sd, sd->status.save_point.map,
  4077. sd->status.save_point.x, sd->status.save_point.y, 3);
  4078. else
  4079. pc_setpos(sd, mapindex_name2id(str), x, y, 3);
  4080. }
  4081. }
  4082. return 0;
  4083. }
  4084. /*==========================================
  4085. * Warpparty - [Fredzilla]
  4086. * Syntax: warpparty "mapname.gat",x,y,Party_ID;
  4087. *------------------------------------------
  4088. */
  4089. int buildin_warpparty(struct script_state *st)
  4090. {
  4091. int x,y;
  4092. char *str;
  4093. int p_id;
  4094. int i;
  4095. unsigned short mapindex;
  4096. struct map_session_data *pl_sd;
  4097. struct party_data *p=NULL;
  4098. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4099. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4100. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4101. p_id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4102. if(p_id < 1)
  4103. return 0;
  4104. p = party_search(p_id);
  4105. if (!p)
  4106. return 0;
  4107. if(strcmp(str,"Random")==0)
  4108. {
  4109. for (i = 0; i < MAX_PARTY; i++)
  4110. {
  4111. if ((pl_sd = p->data[i].sd))
  4112. {
  4113. if(map[pl_sd->bl.m].flag.nowarp)
  4114. continue;
  4115. pc_randomwarp(pl_sd,3);
  4116. }
  4117. }
  4118. }
  4119. else if(strcmp(str,"SavePointAll")==0)
  4120. {
  4121. for (i = 0; i < MAX_PARTY; i++)
  4122. {
  4123. if ((pl_sd = p->data[i].sd))
  4124. {
  4125. if(map[pl_sd->bl.m].flag.noreturn)
  4126. continue;
  4127. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4128. }
  4129. }
  4130. }
  4131. else if(strcmp(str,"SavePoint")==0)
  4132. {
  4133. pl_sd=script_rid2sd(st);
  4134. if (!pl_sd) return 0;
  4135. mapindex=pl_sd->status.save_point.map;
  4136. x=pl_sd->status.save_point.x;
  4137. y=pl_sd->status.save_point.y;
  4138. for (i = 0; i < MAX_PARTY; i++)
  4139. {
  4140. if ((pl_sd = p->data[i].sd))
  4141. {
  4142. if(map[pl_sd->bl.m].flag.noreturn)
  4143. continue;
  4144. pc_setpos(pl_sd,mapindex,x,y,3);
  4145. }
  4146. }
  4147. }
  4148. else
  4149. {
  4150. mapindex = mapindex_name2id(str);
  4151. if (!mapindex) //Show source of npc error.
  4152. return 1;
  4153. for (i = 0; i < MAX_PARTY; i++)
  4154. {
  4155. if ((pl_sd = p->data[i].sd))
  4156. {
  4157. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4158. continue;
  4159. pc_setpos(pl_sd,mapindex,x,y,3);
  4160. }
  4161. }
  4162. }
  4163. return 0;
  4164. }
  4165. /*==========================================
  4166. * Warpguild - [Fredzilla]
  4167. * Syntax: warpguild "mapname.gat",x,y,Guild_ID;
  4168. *------------------------------------------
  4169. */
  4170. int buildin_warpguild(struct script_state *st)
  4171. {
  4172. int x,y;
  4173. unsigned short mapindex;
  4174. char *str;
  4175. int g;
  4176. int i;
  4177. struct map_session_data *pl_sd, **pl_allsd;
  4178. int users;
  4179. struct map_session_data *sd;
  4180. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4181. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4182. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4183. g=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4184. sd=script_rid2sd(st);
  4185. if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
  4186. return 0;
  4187. if(g < 1)
  4188. return 0;
  4189. pl_allsd = map_getallusers(&users);
  4190. if(strcmp(str,"Random")==0)
  4191. {
  4192. for (i = 0; i < users; i++)
  4193. {
  4194. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4195. {
  4196. if(map[pl_sd->bl.m].flag.nowarp)
  4197. continue;
  4198. pc_randomwarp(pl_sd,3);
  4199. }
  4200. }
  4201. }
  4202. else if(strcmp(str,"SavePointAll")==0)
  4203. {
  4204. if(map[sd->bl.m].flag.noreturn)
  4205. return 0;
  4206. for (i = 0; i < users; i++)
  4207. {
  4208. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4209. {
  4210. if(map[pl_sd->bl.m].flag.noreturn)
  4211. continue;
  4212. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4213. }
  4214. }
  4215. }
  4216. else if(strcmp(str,"SavePoint")==0)
  4217. {
  4218. if(map[sd->bl.m].flag.noreturn)
  4219. return 0;
  4220. mapindex=sd->status.save_point.map;
  4221. x=sd->status.save_point.x;
  4222. y=sd->status.save_point.y;
  4223. for (i = 0; i < users; i++)
  4224. {
  4225. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4226. {
  4227. if(map[pl_sd->bl.m].flag.noreturn)
  4228. continue;
  4229. pc_setpos(pl_sd,mapindex,x,y,3);
  4230. }
  4231. }
  4232. }
  4233. else
  4234. {
  4235. mapindex = mapindex_name2id(str);
  4236. for (i = 0; i < users; i++)
  4237. {
  4238. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4239. {
  4240. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4241. continue;
  4242. pc_setpos(pl_sd,mapindex,x,y,3);
  4243. }
  4244. }
  4245. }
  4246. return 0;
  4247. }
  4248. /*==========================================
  4249. *
  4250. *------------------------------------------
  4251. */
  4252. int buildin_heal(struct script_state *st)
  4253. {
  4254. struct map_session_data *sd;
  4255. int hp,sp;
  4256. sd = script_rid2sd(st);
  4257. if (!sd) return 0;
  4258. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4259. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4260. status_heal(&sd->bl, hp, sp, 1);
  4261. return 0;
  4262. }
  4263. /*==========================================
  4264. *
  4265. *------------------------------------------
  4266. */
  4267. int buildin_itemheal(struct script_state *st)
  4268. {
  4269. struct map_session_data *sd;
  4270. int hp,sp;
  4271. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4272. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4273. if(potion_flag==1) {
  4274. potion_hp = hp;
  4275. potion_sp = sp;
  4276. return 0;
  4277. }
  4278. sd = script_rid2sd(st);
  4279. if (!sd) return 0;
  4280. pc_itemheal(sd,sd->itemid,hp,sp);
  4281. return 0;
  4282. }
  4283. /*==========================================
  4284. *
  4285. *------------------------------------------
  4286. */
  4287. int buildin_percentheal(struct script_state *st)
  4288. {
  4289. int hp,sp;
  4290. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4291. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4292. if(potion_flag==1) {
  4293. potion_per_hp = hp;
  4294. potion_per_sp = sp;
  4295. return 0;
  4296. }
  4297. pc_percentheal(script_rid2sd(st),hp,sp);
  4298. return 0;
  4299. }
  4300. /*==========================================
  4301. *
  4302. *------------------------------------------
  4303. */
  4304. int buildin_jobchange(struct script_state *st)
  4305. {
  4306. int job, upper=-1;
  4307. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4308. if( st->end>st->start+3 )
  4309. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4310. if ((job >= 0 && job < MAX_PC_CLASS)){
  4311. pc_jobchange(script_rid2sd(st),job, upper);
  4312. if(use_irc && irc_announce_jobchange_flag)
  4313. irc_announce_jobchange(script_rid2sd(st));
  4314. }
  4315. return 0;
  4316. }
  4317. /*==========================================
  4318. *
  4319. *------------------------------------------
  4320. */
  4321. int buildin_input(struct script_state *st)
  4322. {
  4323. struct map_session_data *sd = script_rid2sd(st);
  4324. int num = (st->end>st->start+2)? st->stack->stack_data[st->start+2].u.num: 0;
  4325. char *name = (st->end>st->start+2)? str_buf+str_data[num&0x00ffffff].str: "";
  4326. char postfix=name[strlen(name)-1];
  4327. nullpo_retr(0, sd);
  4328. if(sd->state.menu_or_input){
  4329. sd->state.menu_or_input=0;
  4330. if( postfix=='$' ){
  4331. // 文字列
  4332. if(st->end>st->start+2){ // 引数1個
  4333. set_reg(st,sd,num,name,(void*)sd->npc_str,st->stack->stack_data[st->start+2].ref);
  4334. }else{
  4335. ShowError("buildin_input: string discarded !!\n");
  4336. return 1;
  4337. }
  4338. return 0;
  4339. }
  4340. // commented by Lupus (check Value Number Input fix in clif.c)
  4341. // readded by Yor: set ammount to 0 instead of cancel trade.
  4342. // ** Fix by fritz :X keeps people from abusing old input bugs
  4343. if (sd->npc_amount < 0) { //** If input amount is less then 0
  4344. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  4345. // buildin_close(st); // ** close
  4346. sd->npc_amount = 0;
  4347. } else if ((unsigned int)sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  4348. sd->npc_amount = battle_config.vending_max_value;
  4349. // 数値
  4350. if(st->end>st->start+2){ // 引数1個
  4351. set_reg(st,sd,num,name,(void*)sd->npc_amount,st->stack->stack_data[st->start+2].ref);
  4352. } else {
  4353. // ragemu互換のため
  4354. //pc_setreg(sd,add_str((unsigned char *) "l14"),sd->npc_amount);
  4355. }
  4356. return 0;
  4357. }
  4358. //state.menu_or_input = 0
  4359. st->state=RERUNLINE;
  4360. if(postfix=='$')
  4361. clif_scriptinputstr(sd,st->oid);
  4362. else
  4363. clif_scriptinput(sd,st->oid);
  4364. sd->state.menu_or_input=1;
  4365. return 0;
  4366. }
  4367. /*==========================================
  4368. * 変数設定
  4369. *------------------------------------------
  4370. */
  4371. int buildin_set(struct script_state *st)
  4372. {
  4373. struct map_session_data *sd=NULL;
  4374. int num=st->stack->stack_data[st->start+2].u.num;
  4375. char *name=str_buf+str_data[num&0x00ffffff].str;
  4376. char prefix=*name;
  4377. char postfix=name[strlen(name)-1];
  4378. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  4379. ShowError("script: buildin_set: not name\n");
  4380. return 1;
  4381. }
  4382. if(not_server_variable(prefix))
  4383. sd=script_rid2sd(st);
  4384. if( postfix=='$' ){
  4385. // 文字列
  4386. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  4387. set_reg(st,sd,num,name,(void*)str,st->stack->stack_data[st->start+2].ref);
  4388. }else{
  4389. // 数値
  4390. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  4391. set_reg(st,sd,num,name,(void*)val,st->stack->stack_data[st->start+2].ref);
  4392. }
  4393. return 0;
  4394. }
  4395. /*==========================================
  4396. * 配列変数設定
  4397. *------------------------------------------
  4398. */
  4399. int buildin_setarray(struct script_state *st)
  4400. {
  4401. struct map_session_data *sd=NULL;
  4402. int num=st->stack->stack_data[st->start+2].u.num;
  4403. char *name=str_buf+str_data[num&0x00ffffff].str;
  4404. char prefix=*name;
  4405. char postfix=name[strlen(name)-1];
  4406. int i,j;
  4407. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4408. ShowWarning("buildin_setarray: illegal scope !\n");
  4409. return 1;
  4410. }
  4411. if(not_server_variable(prefix))
  4412. sd=script_rid2sd(st);
  4413. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  4414. void *v;
  4415. if( postfix=='$' )
  4416. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  4417. else
  4418. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  4419. set_reg(st, sd, num+(j<<24), name, v, st->stack->stack_data[st->start+2].ref);
  4420. }
  4421. return 0;
  4422. }
  4423. /*==========================================
  4424. * 配列変数クリア
  4425. *------------------------------------------
  4426. */
  4427. int buildin_cleararray(struct script_state *st)
  4428. {
  4429. struct map_session_data *sd=NULL;
  4430. int num=st->stack->stack_data[st->start+2].u.num;
  4431. char *name=str_buf+str_data[num&0x00ffffff].str;
  4432. char prefix=*name;
  4433. char postfix=name[strlen(name)-1];
  4434. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4435. int i;
  4436. void *v;
  4437. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4438. ShowWarning("buildin_cleararray: illegal scope !\n");
  4439. return 1;
  4440. }
  4441. if( not_server_variable(prefix) )
  4442. sd=script_rid2sd(st);
  4443. if( postfix=='$' )
  4444. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  4445. else
  4446. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  4447. for(i=0;i<sz;i++)
  4448. set_reg(st,sd,num+(i<<24),name,v,st->stack->stack_data[st->start+2].ref);
  4449. return 0;
  4450. }
  4451. /*==========================================
  4452. * 配列変数コピー
  4453. *------------------------------------------
  4454. */
  4455. int buildin_copyarray(struct script_state *st)
  4456. {
  4457. struct map_session_data *sd=NULL;
  4458. int num=st->stack->stack_data[st->start+2].u.num;
  4459. char *name=str_buf+str_data[num&0x00ffffff].str;
  4460. char prefix=*name;
  4461. char postfix=name[strlen(name)-1];
  4462. int num2=st->stack->stack_data[st->start+3].u.num;
  4463. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  4464. char prefix2=*name2;
  4465. char postfix2=name2[strlen(name2)-1];
  4466. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4467. int i;
  4468. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4469. printf("buildin_copyarray: illeagal scope !\n");
  4470. return 0;
  4471. }
  4472. if( prefix2!='$' && prefix2!='@' && prefix2!='.' ) {
  4473. printf("buildin_copyarray: illeagal scope !\n");
  4474. return 0;
  4475. }
  4476. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  4477. printf("buildin_copyarray: type mismatch !\n");
  4478. return 0;
  4479. }
  4480. if( not_server_variable(prefix) || not_server_variable(prefix2) )
  4481. sd=script_rid2sd(st);
  4482. if((num & 0x00FFFFFF) == (num2 & 0x00FFFFFF) && (num & 0xFF000000) > (num2 & 0xFF000000)) {
  4483. // 同じ配列で、num > num2 の場合大きい方からコピーしないといけない
  4484. for(i=sz-1;i>=0;i--)
  4485. set_reg(
  4486. st,sd,num+(i<<24),name,
  4487. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4488. st->stack->stack_data[st->start+2].ref
  4489. );
  4490. } else {
  4491. for(i=0;i<sz;i++)
  4492. set_reg(
  4493. st,sd,num+(i<<24),name,
  4494. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4495. st->stack->stack_data[st->start+2].ref
  4496. );
  4497. }
  4498. return 0;
  4499. }
  4500. /*==========================================
  4501. * 配列変数のサイズ所得
  4502. *------------------------------------------
  4503. */
  4504. static int getarraysize(struct script_state *st,int num,int postfix,struct linkdb_node** ref)
  4505. {
  4506. int i=(num>>24),c=(i==0? -1:i); // Moded to -1 because even if the first element is 0, it will still report as 1 [Lance]
  4507. if(postfix == '$'){
  4508. for(;i<128;i++){
  4509. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4510. if(*((char*)v)) c=i;
  4511. }
  4512. }else{
  4513. for(;i<128;i++){
  4514. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4515. if((int)v) c=i;
  4516. }
  4517. }
  4518. return c+1;
  4519. }
  4520. int buildin_getarraysize(struct script_state *st)
  4521. {
  4522. int num=st->stack->stack_data[st->start+2].u.num;
  4523. char *name=str_buf+str_data[num&0x00ffffff].str;
  4524. char prefix=*name;
  4525. char postfix=name[strlen(name)-1];
  4526. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4527. ShowWarning("buildin_copyarray: illegal scope !\n");
  4528. return 1;
  4529. }
  4530. push_val(st->stack,C_INT,getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref));
  4531. return 0;
  4532. }
  4533. /*==========================================
  4534. * 配列変数から要素削除
  4535. *------------------------------------------
  4536. */
  4537. int buildin_deletearray(struct script_state *st)
  4538. {
  4539. struct map_session_data *sd=NULL;
  4540. int num=st->stack->stack_data[st->start+2].u.num;
  4541. char *name=str_buf+str_data[num&0x00ffffff].str;
  4542. char prefix=*name;
  4543. char postfix=name[strlen(name)-1];
  4544. int count=1;
  4545. int i,sz=getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref)-(num>>24)-count+1;
  4546. if( (st->end > st->start+3) )
  4547. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4548. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4549. ShowWarning("buildin_deletearray: illegal scope !\n");
  4550. return 1;
  4551. }
  4552. if( not_server_variable(prefix) )
  4553. sd=script_rid2sd(st);
  4554. for(i=0;i<sz;i++){
  4555. set_reg(
  4556. st,sd,num+(i<<24),name,
  4557. get_val2(st,num+((i+count)<<24),st->stack->stack_data[st->start+2].ref),
  4558. st->stack->stack_data[st->start+2].ref
  4559. );
  4560. }
  4561. if(postfix != '$'){
  4562. for(;i<(128-(num>>24));i++)
  4563. set_reg(st,sd,num+(i<<24),name, 0,st->stack->stack_data[st->start+2].ref);
  4564. } else {
  4565. for(;i<(128-(num>>24));i++)
  4566. set_reg(st,sd,num+(i<<24),name, (void *) "",st->stack->stack_data[st->start+2].ref);
  4567. }
  4568. return 0;
  4569. }
  4570. /*==========================================
  4571. * 指定要素を表す値(キー)を所得する
  4572. *------------------------------------------
  4573. */
  4574. int buildin_getelementofarray(struct script_state *st)
  4575. {
  4576. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  4577. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4578. if(i>127 || i<0){
  4579. ShowWarning("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  4580. push_val(st->stack,C_INT,0);
  4581. return 1;
  4582. }else{
  4583. push_val2(st->stack,C_NAME,
  4584. (i<<24) | st->stack->stack_data[st->start+2].u.num, st->stack->stack_data[st->start+2].ref );
  4585. }
  4586. }else{
  4587. ShowError("script: getelementofarray (operator[]): param1 not name !\n");
  4588. push_val(st->stack,C_INT,0);
  4589. }
  4590. return 0;
  4591. }
  4592. /*==========================================
  4593. *
  4594. *------------------------------------------
  4595. */
  4596. int buildin_setlook(struct script_state *st)
  4597. {
  4598. int type,val;
  4599. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4600. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4601. pc_changelook(script_rid2sd(st),type,val);
  4602. return 0;
  4603. }
  4604. /*==========================================
  4605. *
  4606. *------------------------------------------
  4607. */
  4608. int buildin_cutin(struct script_state *st)
  4609. {
  4610. int type;
  4611. conv_str(st,& (st->stack->stack_data[st->start+2]));
  4612. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4613. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  4614. return 0;
  4615. }
  4616. /*==========================================
  4617. * カードのイラストを表示する
  4618. *------------------------------------------
  4619. */
  4620. int buildin_cutincard(struct script_state *st)
  4621. {
  4622. int itemid;
  4623. struct item_data *i_data;
  4624. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4625. i_data = itemdb_exists(itemid);
  4626. if (i_data)
  4627. clif_cutin(script_rid2sd(st),i_data->cardillustname,4);
  4628. return 0;
  4629. }
  4630. /*==========================================
  4631. *
  4632. *------------------------------------------
  4633. */
  4634. int buildin_viewpoint(struct script_state *st)
  4635. {
  4636. int type,x,y,id,color;
  4637. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4638. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4639. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4640. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4641. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4642. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  4643. return 0;
  4644. }
  4645. /*==========================================
  4646. *
  4647. *------------------------------------------
  4648. */
  4649. int buildin_countitem(struct script_state *st)
  4650. {
  4651. int nameid=0,count=0,i;
  4652. struct map_session_data *sd;
  4653. struct script_data *data;
  4654. sd = script_rid2sd(st);
  4655. data=&(st->stack->stack_data[st->start+2]);
  4656. get_val(st,data);
  4657. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4658. const char *name=conv_str(st,data);
  4659. struct item_data *item_data;
  4660. if( (item_data = itemdb_searchname(name)) != NULL)
  4661. nameid=item_data->nameid;
  4662. }else
  4663. nameid=conv_num(st,data);
  4664. if (nameid>=500) //if no such ID then skip this iteration
  4665. for(i=0;i<MAX_INVENTORY;i++){
  4666. if(sd->status.inventory[i].nameid==nameid)
  4667. count+=sd->status.inventory[i].amount;
  4668. }
  4669. else{
  4670. if(battle_config.error_log)
  4671. ShowError("wrong item ID : countitem(%i)\n",nameid);
  4672. push_val(st->stack,C_INT,0);
  4673. return 1;
  4674. }
  4675. push_val(st->stack,C_INT,count);
  4676. return 0;
  4677. }
  4678. /*==========================================
  4679. * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
  4680. * returns number of items that met the conditions
  4681. *------------------------------------------
  4682. */
  4683. int buildin_countitem2(struct script_state *st)
  4684. {
  4685. int nameid=0,count=0,i;
  4686. int iden,ref,attr,c1,c2,c3,c4;
  4687. struct map_session_data *sd;
  4688. struct script_data *data;
  4689. sd = script_rid2sd(st);
  4690. data=&(st->stack->stack_data[st->start+2]);
  4691. get_val(st,data);
  4692. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4693. const char *name=conv_str(st,data);
  4694. struct item_data *item_data;
  4695. if( (item_data = itemdb_searchname(name)) != NULL)
  4696. nameid=item_data->nameid;
  4697. }else
  4698. nameid=conv_num(st,data);
  4699. iden=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4700. ref=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4701. attr=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4702. c1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4703. c2=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4704. c3=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4705. c4=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4706. if (nameid>=500) //if no such ID then skip this iteration
  4707. for(i=0;i<MAX_INVENTORY;i++){
  4708. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  4709. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  4710. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  4711. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  4712. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  4713. sd->status.inventory[i].card[3]!=c4)
  4714. continue;
  4715. count+=sd->status.inventory[i].amount;
  4716. }
  4717. else{
  4718. if(battle_config.error_log)
  4719. ShowError("wrong item ID : countitem2(%i)\n",nameid);
  4720. push_val(st->stack,C_INT,0);
  4721. return 1;
  4722. }
  4723. push_val(st->stack,C_INT,count);
  4724. return 0;
  4725. }
  4726. /*==========================================
  4727. * 重量チェック
  4728. *------------------------------------------
  4729. */
  4730. int buildin_checkweight(struct script_state *st)
  4731. {
  4732. int nameid=0,amount,i;
  4733. unsigned long weight;
  4734. struct map_session_data *sd;
  4735. struct script_data *data;
  4736. sd = script_rid2sd(st);
  4737. data=&(st->stack->stack_data[st->start+2]);
  4738. get_val(st,data);
  4739. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4740. const char *name=conv_str(st,data);
  4741. struct item_data *item_data = itemdb_searchname(name);
  4742. if( item_data )
  4743. nameid=item_data->nameid;
  4744. }else
  4745. nameid=conv_num(st,data);
  4746. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4747. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  4748. push_val(st->stack,C_INT,0);
  4749. ShowError("buildin_checkweight: Wrong item ID or amount.\n");
  4750. return 1;
  4751. }
  4752. weight = itemdb_weight(nameid)*amount;
  4753. if(amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight){
  4754. push_val(st->stack,C_INT,0);
  4755. } else {
  4756. //Check if the inventory ain't full.
  4757. //TODO: Currently does not checks if you can just stack it on top of another item you already have....
  4758. i = pc_search_inventory(sd,0);
  4759. if (i >= 0) //Empty slot available.
  4760. push_val(st->stack,C_INT,1);
  4761. else //Inventory full
  4762. push_val(st->stack,C_INT,0);
  4763. }
  4764. return 0;
  4765. }
  4766. /*==========================================
  4767. *
  4768. *------------------------------------------
  4769. */
  4770. int buildin_getitem(struct script_state *st)
  4771. {
  4772. int nameid,amount,flag = 0;
  4773. struct item item_tmp;
  4774. struct map_session_data *sd;
  4775. struct script_data *data;
  4776. sd = script_rid2sd(st);
  4777. data=&(st->stack->stack_data[st->start+2]);
  4778. get_val(st,data);
  4779. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4780. const char *name=conv_str(st,data);
  4781. struct item_data *item_data = itemdb_searchname(name);
  4782. if( item_data == NULL) {
  4783. ShowWarning("buildin_getitem: Nonexistant item %s requested.\n", name);
  4784. return 1; //No item created.
  4785. }
  4786. nameid=item_data->nameid;
  4787. }else
  4788. nameid=conv_num(st,data);
  4789. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0)
  4790. return 0; //return if amount <=0, skip the useles iteration
  4791. //Violet Box, Blue Box, etc - random item pick
  4792. if(nameid <0) {
  4793. nameid=itemdb_searchrandomid(-nameid);
  4794. flag = 1;
  4795. }
  4796. if(nameid <= 0 || !itemdb_exists(nameid)) {
  4797. ShowWarning("buildin_getitem: Nonexistant item %d requested.\n", nameid);
  4798. return 1; //No item created.
  4799. }
  4800. memset(&item_tmp,0,sizeof(item_tmp));
  4801. item_tmp.nameid=nameid;
  4802. if(!flag)
  4803. item_tmp.identify=1;
  4804. else
  4805. item_tmp.identify=itemdb_isidentified(nameid);
  4806. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  4807. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  4808. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4809. return 0;
  4810. if(pet_create_egg(sd, nameid))
  4811. amount = 1; //This is a pet!
  4812. else
  4813. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4814. clif_additem(sd,0,0,flag);
  4815. if (pc_candrop(sd, &item_tmp))
  4816. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4817. }
  4818. //Logs items, got from (N)PC scripts [Lupus]
  4819. if(log_config.pick > 0 ) {
  4820. log_pick(sd, "N", 0, nameid, amount, NULL);
  4821. }
  4822. //Logs
  4823. return 0;
  4824. }
  4825. /*==========================================
  4826. *
  4827. *------------------------------------------
  4828. */
  4829. int buildin_getitem2(struct script_state *st)
  4830. {
  4831. int nameid,amount,flag = 0;
  4832. int iden,ref,attr,c1,c2,c3,c4;
  4833. struct item_data *item_data;
  4834. struct item item_tmp;
  4835. struct map_session_data *sd;
  4836. struct script_data *data;
  4837. sd = script_rid2sd(st);
  4838. data=&(st->stack->stack_data[st->start+2]);
  4839. get_val(st,data);
  4840. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4841. const char *name=conv_str(st,data);
  4842. struct item_data *item_data = itemdb_searchname(name);
  4843. nameid=UNKNOWN_ITEM_ID;
  4844. if( item_data )
  4845. nameid=item_data->nameid;
  4846. }else
  4847. nameid=conv_num(st,data);
  4848. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4849. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4850. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4851. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4852. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4853. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4854. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4855. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  4856. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  4857. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  4858. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4859. return 0;
  4860. if(nameid<0) { // ランダム
  4861. nameid=itemdb_searchrandomid(-nameid);
  4862. flag = 1;
  4863. }
  4864. if(nameid > 0) {
  4865. memset(&item_tmp,0,sizeof(item_tmp));
  4866. item_data=itemdb_exists(nameid);
  4867. if (item_data == NULL)
  4868. return -1;
  4869. if(item_data->type==4 || item_data->type==5){
  4870. if(ref > 10) ref = 10;
  4871. }
  4872. else if(item_data->type==7) {
  4873. iden = 1;
  4874. ref = 0;
  4875. }
  4876. else {
  4877. iden = 1;
  4878. ref = attr = 0;
  4879. }
  4880. item_tmp.nameid=nameid;
  4881. if(!flag)
  4882. item_tmp.identify=iden;
  4883. else if(item_data->type==4 || item_data->type==5)
  4884. item_tmp.identify=0;
  4885. item_tmp.refine=ref;
  4886. item_tmp.attribute=attr;
  4887. item_tmp.card[0]=c1;
  4888. item_tmp.card[1]=c2;
  4889. item_tmp.card[2]=c3;
  4890. item_tmp.card[3]=c4;
  4891. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4892. clif_additem(sd,0,0,flag);
  4893. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4894. }
  4895. //Logs items, got from (N)PC scripts [Lupus]
  4896. if(log_config.pick > 0 ) {
  4897. log_pick(sd, "N", 0, nameid, amount, &item_tmp);
  4898. }
  4899. //Logs
  4900. }
  4901. return 0;
  4902. }
  4903. /*==========================================
  4904. * gets an item with someone's name inscribed [Skotlex]
  4905. * getinscribeditem item_num, character_name
  4906. * Returned Qty is always 1, only works on equip-able
  4907. * equipment
  4908. *------------------------------------------
  4909. */
  4910. int buildin_getnameditem(struct script_state *st)
  4911. {
  4912. int nameid;
  4913. struct item item_tmp;
  4914. struct map_session_data *sd, *tsd;
  4915. struct script_data *data;
  4916. sd = script_rid2sd(st);
  4917. if (sd == NULL)
  4918. { //Player not attached!
  4919. push_val(st->stack,C_INT,0);
  4920. return 0;
  4921. }
  4922. data=&(st->stack->stack_data[st->start+2]);
  4923. get_val(st,data);
  4924. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4925. const char *name=conv_str(st,data);
  4926. struct item_data *item_data = itemdb_searchname(name);
  4927. if( item_data == NULL)
  4928. { //Failed
  4929. push_val(st->stack,C_INT,0);
  4930. return 0;
  4931. }
  4932. nameid = item_data->nameid;
  4933. }else
  4934. nameid = conv_num(st,data);
  4935. if(!itemdb_exists(nameid) || itemdb_isstackable(nameid))
  4936. { //We don't allow non-equipable/stackable items to be named
  4937. //to avoid any qty exploits that could happen because of it.
  4938. push_val(st->stack,C_INT,0);
  4939. return 0;
  4940. }
  4941. data=&(st->stack->stack_data[st->start+3]);
  4942. get_val(st,data);
  4943. if( data->type==C_STR || data->type==C_CONSTSTR ) //Char Name
  4944. tsd=map_nick2sd(conv_str(st,data));
  4945. else //Char Id was given
  4946. tsd=map_charid2sd(conv_num(st,data));
  4947. if( tsd == NULL )
  4948. { //Failed
  4949. push_val(st->stack,C_INT,0);
  4950. return 0;
  4951. }
  4952. memset(&item_tmp,0,sizeof(item_tmp));
  4953. item_tmp.nameid=nameid;
  4954. item_tmp.amount=1;
  4955. item_tmp.identify=1;
  4956. item_tmp.card[0]=254; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
  4957. item_tmp.card[2]=tsd->status.char_id;
  4958. item_tmp.card[3]=tsd->status.char_id >> 16;
  4959. if(pc_additem(sd,&item_tmp,1)) {
  4960. push_val(st->stack,C_INT,0);
  4961. return 0; //Failed to add item, we will not drop if they don't fit
  4962. }
  4963. //Logs items, got from (N)PC scripts [Lupus]
  4964. if(log_config.pick > 0 ) {
  4965. log_pick(sd, "N", 0, item_tmp.nameid, item_tmp.amount, &item_tmp);
  4966. }
  4967. //Logs
  4968. push_val(st->stack,C_INT,1);
  4969. return 0;
  4970. }
  4971. /*==========================================
  4972. * gets a random item ID from an item group [Skotlex]
  4973. * groupranditem group_num
  4974. *------------------------------------------
  4975. */
  4976. int buildin_grouprandomitem(struct script_state *st)
  4977. {
  4978. int group;
  4979. group = conv_num(st,& (st->stack->stack_data[st->start+2]));
  4980. push_val(st->stack, C_INT, itemdb_searchrandomid(group));
  4981. return 0;
  4982. }
  4983. /*==========================================
  4984. *
  4985. *------------------------------------------
  4986. */
  4987. int buildin_makeitem(struct script_state *st)
  4988. {
  4989. int nameid,amount,flag = 0;
  4990. int x,y,m;
  4991. char *mapname;
  4992. struct item item_tmp;
  4993. struct script_data *data;
  4994. data=&(st->stack->stack_data[st->start+2]);
  4995. get_val(st,data);
  4996. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4997. const char *name=conv_str(st,data);
  4998. struct item_data *item_data = itemdb_searchname(name);
  4999. nameid=UNKNOWN_ITEM_ID;
  5000. if( item_data )
  5001. nameid=item_data->nameid;
  5002. }else
  5003. nameid=conv_num(st,data);
  5004. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5005. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  5006. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  5007. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  5008. if(strcmp(mapname,"this")==0)
  5009. {
  5010. struct map_session_data *sd;
  5011. sd = script_rid2sd(st);
  5012. if (!sd) return 0; //Failed...
  5013. m=sd->bl.m;
  5014. } else
  5015. m=map_mapname2mapid(mapname);
  5016. if(nameid<0) { // ランダム
  5017. nameid=itemdb_searchrandomid(-nameid);
  5018. flag = 1;
  5019. }
  5020. if(nameid > 0) {
  5021. memset(&item_tmp,0,sizeof(item_tmp));
  5022. item_tmp.nameid=nameid;
  5023. if(!flag)
  5024. item_tmp.identify=1;
  5025. else
  5026. item_tmp.identify=itemdb_isidentified(nameid);
  5027. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  5028. }
  5029. return 0;
  5030. }
  5031. /*==========================================
  5032. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  5033. *------------------------------------------
  5034. */
  5035. int buildin_delitem(struct script_state *st)
  5036. {
  5037. int nameid=0,amount,i,important_item=0;
  5038. struct map_session_data *sd;
  5039. struct script_data *data;
  5040. sd = script_rid2sd(st);
  5041. data=&(st->stack->stack_data[st->start+2]);
  5042. get_val(st,data);
  5043. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5044. const char *name=conv_str(st,data);
  5045. struct item_data *item_data = itemdb_searchname(name);
  5046. //nameid=UNKNOWN_ITEM_ID;
  5047. if( item_data )
  5048. nameid=item_data->nameid;
  5049. }else
  5050. nameid=conv_num(st,data);
  5051. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5052. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5053. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5054. return 0;
  5055. }
  5056. //1st pass
  5057. //here we won't delete items with CARDS, named items but we count them
  5058. for(i=0;i<MAX_INVENTORY;i++){
  5059. //we don't delete wrong item or equipped item
  5060. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5061. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid)
  5062. continue;
  5063. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5064. if(sd->inventory_data[i]->type==IT_PETEGG &&
  5065. sd->status.inventory[i].card[0] == CARD0_PET)
  5066. {
  5067. if (intif_delete_petdata(MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5068. continue; //pet couldn't be sent for deletion.
  5069. }
  5070. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  5071. if(itemdb_isspecial(sd->status.inventory[i].card[0]) ||
  5072. sd->status.inventory[i].card[1] ||
  5073. sd->status.inventory[i].card[2] ||
  5074. sd->status.inventory[i].card[3] ||
  5075. sd->status.inventory[i].refine) {
  5076. //this is important item, count it (except for pet eggs)
  5077. if(sd->status.inventory[i].card[0] != CARD0_PET)
  5078. important_item++;
  5079. continue;
  5080. }
  5081. if(sd->status.inventory[i].amount>=amount){
  5082. //Logs items, got from (N)PC scripts [Lupus]
  5083. if(log_config.pick > 0 ) {
  5084. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5085. }
  5086. //Logs
  5087. pc_delitem(sd,i,amount,0);
  5088. return 0; //we deleted exact amount of items. now exit
  5089. } else {
  5090. amount-=sd->status.inventory[i].amount;
  5091. //Logs items, got from (N)PC scripts [Lupus]
  5092. if(log_config.pick > 0 ) {
  5093. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5094. }
  5095. //Logs
  5096. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5097. }
  5098. }
  5099. //2nd pass
  5100. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  5101. if (important_item>0 && amount>0)
  5102. for(i=0;i<MAX_INVENTORY;i++){
  5103. //we don't delete wrong item
  5104. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5105. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  5106. continue;
  5107. if(sd->status.inventory[i].amount>=amount){
  5108. //Logs items, got from (N)PC scripts [Lupus]
  5109. if(log_config.pick > 0 ) {
  5110. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5111. }
  5112. //Logs
  5113. pc_delitem(sd,i,amount,0);
  5114. return 0; //we deleted exact amount of items. now exit
  5115. } else {
  5116. amount-=sd->status.inventory[i].amount;
  5117. //Logs items, got from (N)PC scripts [Lupus]
  5118. if(log_config.pick > 0 ) {
  5119. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5120. }
  5121. //Logs
  5122. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5123. }
  5124. }
  5125. return 0;
  5126. }
  5127. /*==========================================
  5128. * advanced version of delitem [modified by Mihilion]
  5129. *------------------------------------------
  5130. */
  5131. int buildin_delitem2(struct script_state *st)
  5132. {
  5133. int nameid=0,amount,i=0;
  5134. int iden,ref,attr,c1,c2,c3,c4;
  5135. struct map_session_data *sd;
  5136. struct script_data *data;
  5137. sd = script_rid2sd(st);
  5138. data=&(st->stack->stack_data[st->start+2]);
  5139. get_val(st,data);
  5140. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5141. const char *name=conv_str(st,data);
  5142. struct item_data *item_data = itemdb_searchname(name);
  5143. //nameid=UNKNOWN_ITEM_ID;
  5144. if( item_data )
  5145. nameid=item_data->nameid;
  5146. }else
  5147. nameid=conv_num(st,data);
  5148. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5149. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5150. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5151. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5152. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5153. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5154. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5155. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  5156. if (!itemdb_exists(nameid) || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5157. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5158. return 0;
  5159. }
  5160. for(i=0;i<MAX_INVENTORY;i++){
  5161. //we don't delete wrong item or equipped item
  5162. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5163. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  5164. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  5165. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  5166. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  5167. sd->status.inventory[i].card[3]!=c4)
  5168. continue;
  5169. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5170. if(sd->inventory_data[i]->type==IT_PETEGG && sd->status.inventory[i].card[0] == CARD0_PET)
  5171. {
  5172. if (!intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5173. continue; //Failed to send delete the pet.
  5174. }
  5175. if(sd->status.inventory[i].amount>=amount){
  5176. //Logs items, got from (N)PC scripts [Lupus]
  5177. if(log_config.pick > 0 ) {
  5178. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5179. }
  5180. //Logs
  5181. pc_delitem(sd,i,amount,0);
  5182. return 0; //we deleted exact amount of items. now exit
  5183. } else {
  5184. amount-=sd->status.inventory[i].amount;
  5185. //Logs items, got from (N)PC scripts [Lupus]
  5186. if(log_config.pick > 0 ) {
  5187. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5188. }
  5189. //Logs
  5190. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5191. }
  5192. }
  5193. return 0;
  5194. }
  5195. /*==========================================
  5196. * Enables/Disables use of items while in an NPC [Skotlex]
  5197. *------------------------------------------
  5198. */
  5199. int buildin_enableitemuse(struct script_state *st) {
  5200. struct map_session_data *sd;
  5201. sd=script_rid2sd(st);
  5202. if (sd)
  5203. sd->npc_item_flag = st->oid;
  5204. return 0;
  5205. }
  5206. int buildin_disableitemuse(struct script_state *st) {
  5207. struct map_session_data *sd;
  5208. sd=script_rid2sd(st);
  5209. if (sd)
  5210. sd->npc_item_flag = 0;
  5211. return 0;
  5212. }
  5213. /*==========================================
  5214. *キャラ関係のパラメータ取得
  5215. *------------------------------------------
  5216. */
  5217. int buildin_readparam(struct script_state *st)
  5218. {
  5219. int type;
  5220. struct map_session_data *sd;
  5221. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5222. if( st->end>st->start+3 )
  5223. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5224. else
  5225. sd=script_rid2sd(st);
  5226. if(sd==NULL){
  5227. push_val(st->stack,C_INT,-1);
  5228. return 0;
  5229. }
  5230. push_val(st->stack,C_INT,pc_readparam(sd,type));
  5231. return 0;
  5232. }
  5233. /*==========================================
  5234. *キャラ関係のID取得
  5235. *------------------------------------------
  5236. */
  5237. int buildin_getcharid(struct script_state *st)
  5238. {
  5239. int num;
  5240. struct map_session_data *sd;
  5241. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5242. if( st->end>st->start+3 )
  5243. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5244. else
  5245. sd=script_rid2sd(st);
  5246. if(sd==NULL){
  5247. push_val(st->stack,C_INT,-1);
  5248. return 0;
  5249. }
  5250. if(num==0)
  5251. push_val(st->stack,C_INT,sd->status.char_id);
  5252. if(num==1)
  5253. push_val(st->stack,C_INT,sd->status.party_id);
  5254. if(num==2)
  5255. push_val(st->stack,C_INT,sd->status.guild_id);
  5256. if(num==3)
  5257. push_val(st->stack,C_INT,sd->status.account_id);
  5258. return 0;
  5259. }
  5260. /*==========================================
  5261. *指定IDのPT名取得
  5262. *------------------------------------------
  5263. */
  5264. char *buildin_getpartyname_sub(int party_id)
  5265. {
  5266. struct party_data *p;
  5267. p=party_search(party_id);
  5268. if(p!=NULL){
  5269. char *buf;
  5270. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5271. memcpy(buf, p->party.name, NAME_LENGTH-1);
  5272. buf[NAME_LENGTH-1] = '\0';
  5273. return buf;
  5274. }
  5275. return 0;
  5276. }
  5277. int buildin_getpartyname(struct script_state *st)
  5278. {
  5279. char *name;
  5280. int party_id;
  5281. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5282. name=buildin_getpartyname_sub(party_id);
  5283. if(name != NULL)
  5284. push_str(st->stack,C_STR,(unsigned char *)name);
  5285. else
  5286. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  5287. return 0;
  5288. }
  5289. /*==========================================
  5290. *指定IDのPT人数とメンバーID取得
  5291. *------------------------------------------
  5292. */
  5293. int buildin_getpartymember(struct script_state *st)
  5294. {
  5295. struct party_data *p;
  5296. int i,j=0,type=0;
  5297. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  5298. if( st->end>st->start+3 )
  5299. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5300. if(p!=NULL){
  5301. for(i=0;i<MAX_PARTY;i++){
  5302. if(p->party.member[i].account_id){
  5303. switch (type) {
  5304. case 2:
  5305. mapreg_setreg(add_str((unsigned char *) "$@partymemberaid")+(j<<24),p->party.member[i].account_id);
  5306. break;
  5307. case 1:
  5308. mapreg_setreg(add_str((unsigned char *) "$@partymembercid")+(j<<24),p->party.member[i].char_id);
  5309. break;
  5310. default:
  5311. mapreg_setregstr(add_str((unsigned char *) "$@partymembername$")+(j<<24),p->party.member[i].name);
  5312. }
  5313. j++;
  5314. }
  5315. }
  5316. }
  5317. mapreg_setreg(add_str((unsigned char *) "$@partymembercount"),j);
  5318. return 0;
  5319. }
  5320. /*==========================================
  5321. *指定IDのギルド名取得
  5322. *------------------------------------------
  5323. */
  5324. char *buildin_getguildname_sub(int guild_id)
  5325. {
  5326. struct guild *g=NULL;
  5327. g=guild_search(guild_id);
  5328. if(g!=NULL){
  5329. char *buf;
  5330. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5331. memcpy(buf, g->name, NAME_LENGTH-1);
  5332. buf[NAME_LENGTH-1] = '\0';
  5333. return buf;
  5334. }
  5335. return NULL;
  5336. }
  5337. int buildin_getguildname(struct script_state *st)
  5338. {
  5339. char *name;
  5340. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5341. name=buildin_getguildname_sub(guild_id);
  5342. if(name != NULL)
  5343. push_str(st->stack,C_STR,(unsigned char *) name);
  5344. else
  5345. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  5346. return 0;
  5347. }
  5348. /*==========================================
  5349. *指定IDのGuildMaster名取得
  5350. *------------------------------------------
  5351. */
  5352. char *buildin_getguildmaster_sub(int guild_id)
  5353. {
  5354. struct guild *g=NULL;
  5355. g=guild_search(guild_id);
  5356. if(g!=NULL){
  5357. char *buf;
  5358. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5359. memcpy(buf, g->master, NAME_LENGTH-1);
  5360. buf[NAME_LENGTH-1] = '\0';
  5361. return buf;
  5362. }
  5363. return 0;
  5364. }
  5365. int buildin_getguildmaster(struct script_state *st)
  5366. {
  5367. char *master;
  5368. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5369. master=buildin_getguildmaster_sub(guild_id);
  5370. if(master!=0)
  5371. push_str(st->stack,C_STR,(unsigned char *) master);
  5372. else
  5373. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  5374. return 0;
  5375. }
  5376. int buildin_getguildmasterid(struct script_state *st)
  5377. {
  5378. char *master;
  5379. struct map_session_data *sd=NULL;
  5380. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5381. master=buildin_getguildmaster_sub(guild_id);
  5382. if(master!=0){
  5383. if((sd=map_nick2sd(master)) == NULL){
  5384. push_val(st->stack,C_INT,0);
  5385. return 0;
  5386. }
  5387. push_val(st->stack,C_INT,sd->status.char_id);
  5388. }else{
  5389. push_val(st->stack,C_INT,0);
  5390. }
  5391. return 0;
  5392. }
  5393. /*==========================================
  5394. * キャラクタの名前
  5395. *------------------------------------------
  5396. */
  5397. int buildin_strcharinfo(struct script_state *st)
  5398. {
  5399. struct map_session_data *sd;
  5400. int num;
  5401. char *buf;
  5402. sd=script_rid2sd(st);
  5403. if (!sd) { //Avoid crashing....
  5404. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5405. return 0;
  5406. }
  5407. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5408. switch(num){
  5409. case 0:
  5410. push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->status.name);
  5411. break;
  5412. case 1:
  5413. buf=buildin_getpartyname_sub(sd->status.party_id);
  5414. if(buf!=0)
  5415. push_str(st->stack,C_STR,(unsigned char *) buf);
  5416. else
  5417. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5418. break;
  5419. case 2:
  5420. buf=buildin_getguildname_sub(sd->status.guild_id);
  5421. if(buf != NULL)
  5422. push_str(st->stack,C_STR,(unsigned char *) buf);
  5423. else
  5424. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5425. break;
  5426. default:
  5427. ShowWarning("buildin_strcharinfo: unknown parameter.");
  5428. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5429. break;
  5430. }
  5431. return 0;
  5432. }
  5433. unsigned int equip[10]={EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW};
  5434. /*==========================================
  5435. * GetEquipID(Pos); Pos: 1-10
  5436. *------------------------------------------
  5437. */
  5438. int buildin_getequipid(struct script_state *st)
  5439. {
  5440. int i,num;
  5441. struct map_session_data *sd;
  5442. struct item_data* item;
  5443. sd=script_rid2sd(st);
  5444. if(sd == NULL)
  5445. {
  5446. ShowError("getequipid: sd == NULL\n");
  5447. return 0;
  5448. }
  5449. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5450. i=pc_checkequip(sd,equip[num-1]);
  5451. if(i >= 0){
  5452. item=sd->inventory_data[i];
  5453. if(item)
  5454. push_val(st->stack,C_INT,item->nameid);
  5455. else
  5456. push_val(st->stack,C_INT,0);
  5457. }else{
  5458. push_val(st->stack,C_INT,-1);
  5459. }
  5460. return 0;
  5461. }
  5462. /*==========================================
  5463. * 装備名文字列(精錬メニュー用)
  5464. *------------------------------------------
  5465. */
  5466. int buildin_getequipname(struct script_state *st)
  5467. {
  5468. int i,num;
  5469. struct map_session_data *sd;
  5470. struct item_data* item;
  5471. char *buf;
  5472. buf=(char *)aMallocA(64*sizeof(char));
  5473. sd=script_rid2sd(st);
  5474. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5475. i=pc_checkequip(sd,equip[num-1]);
  5476. if(i >= 0){
  5477. item=sd->inventory_data[i];
  5478. if(item)
  5479. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  5480. else
  5481. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5482. }else{
  5483. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5484. }
  5485. push_str(st->stack,C_STR,(unsigned char *) buf);
  5486. return 0;
  5487. }
  5488. /*==========================================
  5489. * getbrokenid [Valaris]
  5490. *------------------------------------------
  5491. */
  5492. int buildin_getbrokenid(struct script_state *st)
  5493. {
  5494. int i,num,id=0,brokencounter=0;
  5495. struct map_session_data *sd;
  5496. sd=script_rid2sd(st);
  5497. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5498. for(i=0; i<MAX_INVENTORY; i++) {
  5499. if(sd->status.inventory[i].attribute==1){
  5500. brokencounter++;
  5501. if(num==brokencounter){
  5502. id=sd->status.inventory[i].nameid;
  5503. break;
  5504. }
  5505. }
  5506. }
  5507. push_val(st->stack,C_INT,id);
  5508. return 0;
  5509. }
  5510. /*==========================================
  5511. * repair [Valaris]
  5512. *------------------------------------------
  5513. */
  5514. int buildin_repair(struct script_state *st)
  5515. {
  5516. int i,num;
  5517. int repaircounter=0;
  5518. struct map_session_data *sd;
  5519. sd=script_rid2sd(st);
  5520. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5521. for(i=0; i<MAX_INVENTORY; i++) {
  5522. if(sd->status.inventory[i].attribute==1){
  5523. repaircounter++;
  5524. if(num==repaircounter){
  5525. sd->status.inventory[i].attribute=0;
  5526. clif_equiplist(sd);
  5527. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  5528. clif_misceffect(&sd->bl, 3);
  5529. clif_displaymessage(sd->fd,"Item has been repaired.");
  5530. break;
  5531. }
  5532. }
  5533. }
  5534. return 0;
  5535. }
  5536. /*==========================================
  5537. * 装備チェック
  5538. *------------------------------------------
  5539. */
  5540. int buildin_getequipisequiped(struct script_state *st)
  5541. {
  5542. int i,num;
  5543. struct map_session_data *sd;
  5544. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5545. sd=script_rid2sd(st);
  5546. if ((num - 1) >= (sizeof(equip) / sizeof(equip[0])))
  5547. i = -1;
  5548. else
  5549. i=pc_checkequip(sd,equip[num-1]);
  5550. if(i >= 0)
  5551. push_val(st->stack,C_INT,1);
  5552. else
  5553. push_val(st->stack,C_INT,0);
  5554. return 0;
  5555. }
  5556. /*==========================================
  5557. * 装備品精錬可能チェック
  5558. *------------------------------------------
  5559. */
  5560. int buildin_getequipisenableref(struct script_state *st)
  5561. {
  5562. int i,num;
  5563. struct map_session_data *sd;
  5564. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5565. sd=script_rid2sd(st);
  5566. i=pc_checkequip(sd,equip[num-1]);
  5567. if(i >= 0 && num<7 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
  5568. {
  5569. push_val(st->stack,C_INT,1);
  5570. } else {
  5571. push_val(st->stack,C_INT,0);
  5572. }
  5573. return 0;
  5574. }
  5575. /*==========================================
  5576. * 装備品鑑定チェック
  5577. *------------------------------------------
  5578. */
  5579. int buildin_getequipisidentify(struct script_state *st)
  5580. {
  5581. int i,num;
  5582. struct map_session_data *sd;
  5583. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5584. sd=script_rid2sd(st);
  5585. i=pc_checkequip(sd,equip[num-1]);
  5586. if(i >= 0)
  5587. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  5588. else
  5589. push_val(st->stack,C_INT,0);
  5590. return 0;
  5591. }
  5592. /*==========================================
  5593. * 装備品精錬度
  5594. *------------------------------------------
  5595. */
  5596. int buildin_getequiprefinerycnt(struct script_state *st)
  5597. {
  5598. int i,num;
  5599. struct map_session_data *sd;
  5600. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5601. sd=script_rid2sd(st);
  5602. i=pc_checkequip(sd,equip[num-1]);
  5603. if(i >= 0)
  5604. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  5605. else
  5606. push_val(st->stack,C_INT,0);
  5607. return 0;
  5608. }
  5609. /*==========================================
  5610. * 装備品武器LV
  5611. *------------------------------------------
  5612. */
  5613. int buildin_getequipweaponlv(struct script_state *st)
  5614. {
  5615. int i,num;
  5616. struct map_session_data *sd;
  5617. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5618. sd=script_rid2sd(st);
  5619. i=pc_checkequip(sd,equip[num-1]);
  5620. if(i >= 0 && sd->inventory_data[i])
  5621. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  5622. else
  5623. push_val(st->stack,C_INT,0);
  5624. return 0;
  5625. }
  5626. /*==========================================
  5627. * 装備品精錬成功率
  5628. *------------------------------------------
  5629. */
  5630. int buildin_getequippercentrefinery(struct script_state *st)
  5631. {
  5632. int i,num;
  5633. struct map_session_data *sd;
  5634. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5635. sd=script_rid2sd(st);
  5636. i=pc_checkequip(sd,equip[num-1]);
  5637. if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
  5638. push_val(st->stack,C_INT,percentrefinery[itemdb_wlv(sd->status.inventory[i].nameid)][(int)sd->status.inventory[i].refine]);
  5639. else
  5640. push_val(st->stack,C_INT,0);
  5641. return 0;
  5642. }
  5643. /*==========================================
  5644. * 精錬成功
  5645. *------------------------------------------
  5646. */
  5647. int buildin_successrefitem(struct script_state *st)
  5648. {
  5649. int i,num,ep;
  5650. struct map_session_data *sd;
  5651. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5652. sd=script_rid2sd(st);
  5653. i=pc_checkequip(sd,equip[num-1]);
  5654. if(i >= 0) {
  5655. ep=sd->status.inventory[i].equip;
  5656. //Logs items, got from (N)PC scripts [Lupus]
  5657. if(log_config.pick > 0 ) {
  5658. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5659. }
  5660. //Logs
  5661. sd->status.inventory[i].refine++;
  5662. pc_unequipitem(sd,i,2);
  5663. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  5664. clif_delitem(sd,i,1);
  5665. //Logs items, got from (N)PC scripts [Lupus]
  5666. if(log_config.pick > 0 ) {
  5667. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]);
  5668. }
  5669. //Logs
  5670. clif_additem(sd,i,1,0);
  5671. pc_equipitem(sd,i,ep);
  5672. clif_misceffect(&sd->bl,3);
  5673. if(sd->status.inventory[i].refine == MAX_REFINE &&
  5674. sd->status.inventory[i].card[0] == CARD0_FORGE &&
  5675. sd->char_id == MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])
  5676. ){ // Fame point system [DracoRPG]
  5677. switch (sd->inventory_data[i]->wlv){
  5678. case 1:
  5679. pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
  5680. break;
  5681. case 2:
  5682. pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
  5683. break;
  5684. case 3:
  5685. pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
  5686. break;
  5687. }
  5688. }
  5689. }
  5690. return 0;
  5691. }
  5692. /*==========================================
  5693. * 精錬失敗
  5694. *------------------------------------------
  5695. */
  5696. int buildin_failedrefitem(struct script_state *st)
  5697. {
  5698. int i,num;
  5699. struct map_session_data *sd;
  5700. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5701. sd=script_rid2sd(st);
  5702. i=pc_checkequip(sd,equip[num-1]);
  5703. if(i >= 0) {
  5704. //Logs items, got from (N)PC scripts [Lupus]
  5705. if(log_config.pick > 0 ) {
  5706. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5707. }
  5708. //Logs
  5709. sd->status.inventory[i].refine = 0;
  5710. pc_unequipitem(sd,i,3);
  5711. // 精錬失敗エフェクトのパケット
  5712. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  5713. pc_delitem(sd,i,1,0);
  5714. // 他の人にも失敗を通知
  5715. clif_misceffect(&sd->bl,2);
  5716. }
  5717. return 0;
  5718. }
  5719. /*==========================================
  5720. *
  5721. *------------------------------------------
  5722. */
  5723. int buildin_statusup(struct script_state *st)
  5724. {
  5725. int type;
  5726. struct map_session_data *sd;
  5727. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5728. sd=script_rid2sd(st);
  5729. pc_statusup(sd,type);
  5730. return 0;
  5731. }
  5732. /*==========================================
  5733. *
  5734. *------------------------------------------
  5735. */
  5736. int buildin_statusup2(struct script_state *st)
  5737. {
  5738. int type,val;
  5739. struct map_session_data *sd;
  5740. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5741. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5742. sd=script_rid2sd(st);
  5743. pc_statusup2(sd,type,val);
  5744. return 0;
  5745. }
  5746. /*==========================================
  5747. * 装備品による能力値ボーナス
  5748. *------------------------------------------
  5749. */
  5750. int buildin_bonus(struct script_state *st)
  5751. {
  5752. int type,val;
  5753. struct map_session_data *sd;
  5754. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5755. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5756. sd=script_rid2sd(st);
  5757. pc_bonus(sd,type,val);
  5758. return 0;
  5759. }
  5760. /*==========================================
  5761. * 装備品による能力値ボーナス
  5762. *------------------------------------------
  5763. */
  5764. int buildin_bonus2(struct script_state *st)
  5765. {
  5766. int type,type2,val;
  5767. struct map_session_data *sd;
  5768. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5769. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5770. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5771. sd=script_rid2sd(st);
  5772. pc_bonus2(sd,type,type2,val);
  5773. return 0;
  5774. }
  5775. /*==========================================
  5776. * 装備品による能力値ボーナス
  5777. *------------------------------------------
  5778. */
  5779. int buildin_bonus3(struct script_state *st)
  5780. {
  5781. int type,type2,type3,val;
  5782. struct map_session_data *sd;
  5783. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5784. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5785. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5786. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5787. sd=script_rid2sd(st);
  5788. pc_bonus3(sd,type,type2,type3,val);
  5789. return 0;
  5790. }
  5791. int buildin_bonus4(struct script_state *st)
  5792. {
  5793. int type,type2,type3,type4,val;
  5794. struct map_session_data *sd;
  5795. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5796. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5797. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5798. type4=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5799. val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5800. sd=script_rid2sd(st);
  5801. pc_bonus4(sd,type,type2,type3,type4,val);
  5802. return 0;
  5803. }
  5804. /*==========================================
  5805. * スキル所得
  5806. *------------------------------------------
  5807. */
  5808. int buildin_skill(struct script_state *st)
  5809. {
  5810. int id,level,flag=1;
  5811. struct map_session_data *sd;
  5812. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5813. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5814. if( st->end>st->start+4 )
  5815. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5816. sd=script_rid2sd(st);
  5817. pc_skill(sd,id,level,flag);
  5818. return 0;
  5819. }
  5820. // add x levels of skill (stackable) [Valaris]
  5821. int buildin_addtoskill(struct script_state *st)
  5822. {
  5823. int id,level,flag=2;
  5824. struct map_session_data *sd;
  5825. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5826. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5827. if( st->end>st->start+4 )
  5828. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5829. sd=script_rid2sd(st);
  5830. pc_skill(sd,id,level,flag);
  5831. return 0;
  5832. }
  5833. /*==========================================
  5834. * ギルドスキル取得
  5835. *------------------------------------------
  5836. */
  5837. int buildin_guildskill(struct script_state *st)
  5838. {
  5839. int id,level,flag=0;
  5840. struct map_session_data *sd;
  5841. int i=0;
  5842. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5843. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5844. if( st->end>st->start+4 )
  5845. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5846. sd=script_rid2sd(st);
  5847. for(i=0;i<level;i++)
  5848. guild_skillup(sd,id,flag);
  5849. return 0;
  5850. }
  5851. /*==========================================
  5852. * スキルレベル所得
  5853. *------------------------------------------
  5854. */
  5855. int buildin_getskilllv(struct script_state *st)
  5856. {
  5857. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5858. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  5859. return 0;
  5860. }
  5861. /*==========================================
  5862. * getgdskilllv(Guild_ID, Skill_ID);
  5863. * skill_id = 10000 : GD_APPROVAL
  5864. * 10001 : GD_KAFRACONTRACT
  5865. * 10002 : GD_GUARDIANRESEARCH
  5866. * 10003 : GD_GUARDUP
  5867. * 10004 : GD_EXTENSION
  5868. *------------------------------------------
  5869. */
  5870. int buildin_getgdskilllv(struct script_state *st)
  5871. {
  5872. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5873. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5874. struct guild *g=guild_search(guild_id);
  5875. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  5876. return 0;
  5877. /*
  5878. struct map_session_data *sd=NULL;
  5879. struct guild *g=NULL;
  5880. int skill_id;
  5881. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5882. sd=script_rid2sd(st);
  5883. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  5884. if(sd && g) {
  5885. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  5886. } else {
  5887. push_val(st->stack,C_INT,-1);
  5888. }
  5889. return 0;
  5890. */
  5891. }
  5892. /*==========================================
  5893. *
  5894. *------------------------------------------
  5895. */
  5896. int buildin_basicskillcheck(struct script_state *st)
  5897. {
  5898. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  5899. return 0;
  5900. }
  5901. /*==========================================
  5902. *
  5903. *------------------------------------------
  5904. */
  5905. int buildin_getgmlevel(struct script_state *st)
  5906. {
  5907. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  5908. return 0;
  5909. }
  5910. /*==========================================
  5911. *
  5912. *------------------------------------------
  5913. */
  5914. int buildin_end(struct script_state *st)
  5915. {
  5916. st->state = END;
  5917. return 0;
  5918. }
  5919. /*==========================================
  5920. *
  5921. *------------------------------------------
  5922. */
  5923. int buildin_checkoption(struct script_state *st)
  5924. {
  5925. int type;
  5926. struct map_session_data *sd;
  5927. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5928. sd=script_rid2sd(st);
  5929. if(sd->sc.option & type){
  5930. push_val(st->stack,C_INT,1);
  5931. } else {
  5932. push_val(st->stack,C_INT,0);
  5933. }
  5934. return 0;
  5935. }
  5936. /*==========================================
  5937. *
  5938. *------------------------------------------
  5939. */
  5940. int buildin_checkoption1(struct script_state *st)
  5941. {
  5942. int type;
  5943. struct map_session_data *sd;
  5944. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5945. sd=script_rid2sd(st);
  5946. if(sd->sc.opt1 & type){
  5947. push_val(st->stack,C_INT,1);
  5948. } else {
  5949. push_val(st->stack,C_INT,0);
  5950. }
  5951. return 0;
  5952. }
  5953. /*==========================================
  5954. *
  5955. *------------------------------------------
  5956. */
  5957. int buildin_checkoption2(struct script_state *st)
  5958. {
  5959. int type;
  5960. struct map_session_data *sd;
  5961. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5962. sd=script_rid2sd(st);
  5963. if(sd->sc.opt2 & type){
  5964. push_val(st->stack,C_INT,1);
  5965. } else {
  5966. push_val(st->stack,C_INT,0);
  5967. }
  5968. return 0;
  5969. }
  5970. /*==========================================
  5971. *
  5972. *------------------------------------------
  5973. */
  5974. int buildin_setoption(struct script_state *st)
  5975. {
  5976. int type;
  5977. struct map_session_data *sd;
  5978. int flag=1;
  5979. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5980. if(st->end>st->start+3 )
  5981. flag=conv_num(st,&(st->stack->stack_data[st->start+3]) );
  5982. else if (!type) { //Request to remove everything.
  5983. flag = 0;
  5984. type = OPTION_CART|OPTION_FALCON|OPTION_RIDING;
  5985. }
  5986. sd=script_rid2sd(st);
  5987. if (!sd) return 0;
  5988. if (flag) {//Add option
  5989. if (type&OPTION_WEDDING && !battle_config.wedding_modifydisplay)
  5990. type&=~OPTION_WEDDING; //Do not show the wedding sprites
  5991. pc_setoption(sd,sd->sc.option|type);
  5992. } else//Remove option
  5993. pc_setoption(sd,sd->sc.option&~type);
  5994. return 0;
  5995. }
  5996. /*==========================================
  5997. * Checkcart [Valaris]
  5998. *------------------------------------------
  5999. */
  6000. int buildin_checkcart(struct script_state *st)
  6001. {
  6002. struct map_session_data *sd;
  6003. sd=script_rid2sd(st);
  6004. if(pc_iscarton(sd)){
  6005. push_val(st->stack,C_INT,1);
  6006. } else {
  6007. push_val(st->stack,C_INT,0);
  6008. }
  6009. return 0;
  6010. }
  6011. /*==========================================
  6012. * カートを付ける
  6013. *------------------------------------------
  6014. */
  6015. int buildin_setcart(struct script_state *st)
  6016. {
  6017. struct map_session_data *sd;
  6018. sd=script_rid2sd(st);
  6019. pc_setcart(sd,1);
  6020. return 0;
  6021. }
  6022. /*==========================================
  6023. * checkfalcon [Valaris]
  6024. *------------------------------------------
  6025. */
  6026. int buildin_checkfalcon(struct script_state *st)
  6027. {
  6028. struct map_session_data *sd;
  6029. sd=script_rid2sd(st);
  6030. if(pc_isfalcon(sd)){
  6031. push_val(st->stack,C_INT,1);
  6032. } else {
  6033. push_val(st->stack,C_INT,0);
  6034. }
  6035. return 0;
  6036. }
  6037. /*==========================================
  6038. * 鷹を付ける
  6039. *------------------------------------------
  6040. */
  6041. int buildin_setfalcon(struct script_state *st)
  6042. {
  6043. struct map_session_data *sd;
  6044. sd=script_rid2sd(st);
  6045. pc_setfalcon(sd);
  6046. return 0;
  6047. }
  6048. /*==========================================
  6049. * Checkcart [Valaris]
  6050. *------------------------------------------
  6051. */
  6052. int buildin_checkriding(struct script_state *st)
  6053. {
  6054. struct map_session_data *sd;
  6055. sd=script_rid2sd(st);
  6056. if(pc_isriding(sd)){
  6057. push_val(st->stack,C_INT,1);
  6058. } else {
  6059. push_val(st->stack,C_INT,0);
  6060. }
  6061. return 0;
  6062. }
  6063. /*==========================================
  6064. * ペコペコ乗り
  6065. *------------------------------------------
  6066. */
  6067. int buildin_setriding(struct script_state *st)
  6068. {
  6069. struct map_session_data *sd;
  6070. sd=script_rid2sd(st);
  6071. pc_setriding(sd);
  6072. return 0;
  6073. }
  6074. /*==========================================
  6075. * セーブポイントの保存
  6076. *------------------------------------------
  6077. */
  6078. int buildin_savepoint(struct script_state *st)
  6079. {
  6080. int x,y;
  6081. short map;
  6082. char *str;
  6083. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6084. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6085. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6086. map = mapindex_name2id(str);
  6087. if (map)
  6088. pc_setsavepoint(script_rid2sd(st),map,x,y);
  6089. return 0;
  6090. }
  6091. /*==========================================
  6092. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  6093. *------------------------------------------
  6094. */
  6095. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  6096. {
  6097. int type;
  6098. time_t timer;
  6099. struct tm *t;
  6100. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6101. switch(type){
  6102. case 2:
  6103. //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
  6104. // from the system clock.)
  6105. push_val(st->stack,C_INT,(int)time(NULL));
  6106. break;
  6107. case 1:
  6108. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  6109. time(&timer);
  6110. t=localtime(&timer);
  6111. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  6112. break;
  6113. case 0:
  6114. default:
  6115. //type 0:(System Ticks)
  6116. push_val(st->stack,C_INT,gettick());
  6117. break;
  6118. }
  6119. return 0;
  6120. }
  6121. /*==========================================
  6122. * GetTime(Type);
  6123. * 1: Sec 2: Min 3: Hour
  6124. * 4: WeekDay 5: MonthDay 6: Month
  6125. * 7: Year
  6126. *------------------------------------------
  6127. */
  6128. int buildin_gettime(struct script_state *st) /* Asgard Version */
  6129. {
  6130. int type;
  6131. time_t timer;
  6132. struct tm *t;
  6133. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6134. time(&timer);
  6135. t=localtime(&timer);
  6136. switch(type){
  6137. case 1://Sec(0~59)
  6138. push_val(st->stack,C_INT,t->tm_sec);
  6139. break;
  6140. case 2://Min(0~59)
  6141. push_val(st->stack,C_INT,t->tm_min);
  6142. break;
  6143. case 3://Hour(0~23)
  6144. push_val(st->stack,C_INT,t->tm_hour);
  6145. break;
  6146. case 4://WeekDay(0~6)
  6147. push_val(st->stack,C_INT,t->tm_wday);
  6148. break;
  6149. case 5://MonthDay(01~31)
  6150. push_val(st->stack,C_INT,t->tm_mday);
  6151. break;
  6152. case 6://Month(01~12)
  6153. push_val(st->stack,C_INT,t->tm_mon+1);
  6154. break;
  6155. case 7://Year(20xx)
  6156. push_val(st->stack,C_INT,t->tm_year+1900);
  6157. break;
  6158. case 8://Year Day(01~366)
  6159. push_val(st->stack,C_INT,t->tm_yday+1);
  6160. break;
  6161. default://(format error)
  6162. push_val(st->stack,C_INT,-1);
  6163. break;
  6164. }
  6165. return 0;
  6166. }
  6167. /*==========================================
  6168. * GetTimeStr("TimeFMT", Length);
  6169. *------------------------------------------
  6170. */
  6171. int buildin_gettimestr(struct script_state *st)
  6172. {
  6173. char *tmpstr;
  6174. char *fmtstr;
  6175. int maxlen;
  6176. time_t now = time(NULL);
  6177. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6178. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6179. tmpstr=(char *)aMallocA((maxlen+1)*sizeof(char));
  6180. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  6181. tmpstr[maxlen]='\0';
  6182. push_str(st->stack,C_STR,(unsigned char *) tmpstr);
  6183. return 0;
  6184. }
  6185. /*==========================================
  6186. * カプラ倉庫を開く
  6187. *------------------------------------------
  6188. */
  6189. int buildin_openstorage(struct script_state *st)
  6190. {
  6191. storage_storageopen(script_rid2sd(st));
  6192. return 0;
  6193. }
  6194. int buildin_guildopenstorage(struct script_state *st)
  6195. {
  6196. struct map_session_data *sd=script_rid2sd(st);
  6197. int ret;
  6198. ret = storage_guild_storageopen(sd);
  6199. push_val(st->stack,C_INT,ret);
  6200. return 0;
  6201. }
  6202. /*==========================================
  6203. * アイテムによるスキル発動
  6204. *------------------------------------------
  6205. */
  6206. int buildin_itemskill(struct script_state *st)
  6207. {
  6208. int id,lv;
  6209. char *str;
  6210. struct map_session_data *sd=script_rid2sd(st);
  6211. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6212. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6213. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6214. // 詠唱中にスキルアイテムは使用できない
  6215. if(sd->ud.skilltimer != -1)
  6216. return 0;
  6217. sd->skillitem=id;
  6218. sd->skillitemlv=lv;
  6219. clif_item_skill(sd,id,lv,str);
  6220. return 0;
  6221. }
  6222. /*==========================================
  6223. * アイテム作成
  6224. *------------------------------------------
  6225. */
  6226. int buildin_produce(struct script_state *st)
  6227. {
  6228. int trigger;
  6229. struct map_session_data *sd=script_rid2sd(st);
  6230. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6231. clif_skill_produce_mix_list(sd, trigger);
  6232. return 0;
  6233. }
  6234. /*==========================================
  6235. * NPCでペット作る
  6236. *------------------------------------------
  6237. */
  6238. int buildin_makepet(struct script_state *st)
  6239. {
  6240. struct map_session_data *sd = script_rid2sd(st);
  6241. struct script_data *data;
  6242. int id,pet_id;
  6243. data=&(st->stack->stack_data[st->start+2]);
  6244. get_val(st,data);
  6245. id=conv_num(st,data);
  6246. pet_id = search_petDB_index(id, PET_CLASS);
  6247. if (pet_id < 0)
  6248. pet_id = search_petDB_index(id, PET_EGG);
  6249. if (pet_id >= 0 && sd) {
  6250. sd->catch_target_class = pet_db[pet_id].class_;
  6251. intif_create_pet(
  6252. sd->status.account_id, sd->status.char_id,
  6253. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  6254. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  6255. 100, 0, 1, pet_db[pet_id].jname);
  6256. }
  6257. return 0;
  6258. }
  6259. /*==========================================
  6260. * NPCで経験値上げる
  6261. *------------------------------------------
  6262. */
  6263. int buildin_getexp(struct script_state *st)
  6264. {
  6265. struct map_session_data *sd = script_rid2sd(st);
  6266. int base=0,job=0;
  6267. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6268. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6269. if(base<0 || job<0)
  6270. return 0;
  6271. if(sd)
  6272. pc_gainexp(sd,NULL,base,job);
  6273. return 0;
  6274. }
  6275. /*==========================================
  6276. * Gain guild exp [Celest]
  6277. *------------------------------------------
  6278. */
  6279. int buildin_guildgetexp(struct script_state *st)
  6280. {
  6281. struct map_session_data *sd = script_rid2sd(st);
  6282. int exp;
  6283. exp = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6284. if(exp < 0)
  6285. return 0;
  6286. if(sd && sd->status.guild_id > 0)
  6287. guild_getexp (sd, exp);
  6288. return 0;
  6289. }
  6290. /*==========================================
  6291. * Changes the guild master of a guild [Skotlex]
  6292. *------------------------------------------
  6293. */
  6294. int buildin_guildchangegm(struct script_state *st)
  6295. {
  6296. struct map_session_data *sd;
  6297. int guild_id;
  6298. char *name;
  6299. guild_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6300. name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  6301. sd=map_nick2sd(name);
  6302. if (!sd)
  6303. push_val(st->stack,C_INT,0);
  6304. else
  6305. push_val(st->stack,C_INT,guild_gm_change(guild_id, sd));
  6306. return 0;
  6307. }
  6308. /*==========================================
  6309. * モンスター発生
  6310. *------------------------------------------
  6311. */
  6312. int buildin_monster(struct script_state *st)
  6313. {
  6314. int class_,amount,x,y;
  6315. char *str,*map,*event="";
  6316. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6317. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6318. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6319. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  6320. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6321. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6322. if( st->end>st->start+8 ){
  6323. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  6324. check_event(st, event);
  6325. }
  6326. if (class_ >= 0 && !mobdb_checkid(class_)) {
  6327. ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
  6328. return 1;
  6329. }
  6330. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
  6331. return 0;
  6332. }
  6333. /*==========================================
  6334. * モンスター発生
  6335. *------------------------------------------
  6336. */
  6337. int buildin_areamonster(struct script_state *st)
  6338. {
  6339. int class_,amount,x0,y0,x1,y1;
  6340. char *str,*map,*event="";
  6341. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6342. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6343. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6344. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  6345. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  6346. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  6347. class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6348. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6349. if( st->end>st->start+10 ){
  6350. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  6351. check_event(st, event);
  6352. }
  6353. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
  6354. return 0;
  6355. }
  6356. /*==========================================
  6357. * モンスター削除
  6358. *------------------------------------------
  6359. */
  6360. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  6361. {
  6362. TBL_MOB* md = (TBL_MOB*)bl;
  6363. char *event=va_arg(ap,char *);
  6364. int allflag=va_arg(ap,int);
  6365. if(!allflag){
  6366. if(strcmp(event,md->npc_event)==0)
  6367. status_kill(bl);
  6368. return 0;
  6369. }else{
  6370. if(!md->spawn)
  6371. status_kill(bl);
  6372. return 0;
  6373. }
  6374. return 0;
  6375. }
  6376. int buildin_killmonster(struct script_state *st)
  6377. {
  6378. char *mapname,*event;
  6379. int m,allflag=0;
  6380. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6381. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6382. if(strcmp(event,"All")==0)
  6383. allflag = 1;
  6384. else
  6385. check_event(st, event);
  6386. if( (m=map_mapname2mapid(mapname))<0 )
  6387. return 0;
  6388. map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
  6389. return 0;
  6390. }
  6391. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  6392. {
  6393. status_kill(bl);
  6394. return 0;
  6395. }
  6396. int buildin_killmonsterall(struct script_state *st)
  6397. {
  6398. char *mapname;
  6399. int m;
  6400. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6401. if( (m=map_mapname2mapid(mapname))<0 )
  6402. return 0;
  6403. map_foreachinmap(buildin_killmonsterall_sub,
  6404. m,BL_MOB);
  6405. return 0;
  6406. }
  6407. /*==========================================
  6408. * Creates a clone of a player.
  6409. * clone map, x, y, event, char_id, master_id, mode, flag, duration
  6410. *------------------------------------------
  6411. */
  6412. int buildin_clone(struct script_state *st) {
  6413. struct map_session_data *sd, *msd=NULL;
  6414. int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
  6415. unsigned int duration = 0;
  6416. char *map,*event="";
  6417. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6418. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6419. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6420. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6421. char_id=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6422. if( st->end>st->start+7 )
  6423. master_id=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6424. if( st->end>st->start+8 )
  6425. mode=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6426. if( st->end>st->start+9 )
  6427. flag=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6428. if( st->end>st->start+10 )
  6429. duration=conv_num(st,& (st->stack->stack_data[st->start+10]));
  6430. check_event(st, event);
  6431. m = map_mapname2mapid(map);
  6432. if (m < 0) return 0;
  6433. sd = map_charid2sd(char_id);
  6434. if (master_id) {
  6435. msd = map_charid2sd(master_id);
  6436. if (msd)
  6437. master_id = msd->bl.id;
  6438. else
  6439. master_id = 0;
  6440. }
  6441. if (sd) //Return ID of newly crafted clone.
  6442. push_val(st->stack,C_INT,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
  6443. else //Failed to create clone.
  6444. push_val(st->stack,C_INT,0);
  6445. return 0;
  6446. }
  6447. /*==========================================
  6448. * イベント実行
  6449. *------------------------------------------
  6450. */
  6451. int buildin_doevent(struct script_state *st)
  6452. {
  6453. char *event;
  6454. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6455. check_event(st, event);
  6456. npc_event(map_id2sd(st->rid),event,0);
  6457. return 0;
  6458. }
  6459. /*==========================================
  6460. * NPC主体イベント実行
  6461. *------------------------------------------
  6462. */
  6463. int buildin_donpcevent(struct script_state *st)
  6464. {
  6465. char *event;
  6466. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6467. check_event(st, event);
  6468. npc_event_do(event);
  6469. return 0;
  6470. }
  6471. /*==========================================
  6472. * イベントタイマー追加
  6473. *------------------------------------------
  6474. */
  6475. int buildin_addtimer(struct script_state *st)
  6476. {
  6477. char *event;
  6478. int tick;
  6479. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6480. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6481. check_event(st, event);
  6482. pc_addeventtimer(script_rid2sd(st),tick,event);
  6483. return 0;
  6484. }
  6485. /*==========================================
  6486. * イベントタイマー削除
  6487. *------------------------------------------
  6488. */
  6489. int buildin_deltimer(struct script_state *st)
  6490. {
  6491. char *event;
  6492. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6493. check_event(st, event);
  6494. pc_deleventtimer(script_rid2sd(st),event);
  6495. return 0;
  6496. }
  6497. /*==========================================
  6498. * イベントタイマーのカウント値追加
  6499. *------------------------------------------
  6500. */
  6501. int buildin_addtimercount(struct script_state *st)
  6502. {
  6503. char *event;
  6504. int tick;
  6505. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6506. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6507. check_event(st, event);
  6508. pc_addeventtimercount(script_rid2sd(st),event,tick);
  6509. return 0;
  6510. }
  6511. /*==========================================
  6512. * NPCタイマー初期化
  6513. *------------------------------------------
  6514. */
  6515. int buildin_initnpctimer(struct script_state *st)
  6516. {
  6517. struct npc_data *nd;
  6518. if( st->end > st->start+2 )
  6519. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6520. else
  6521. nd=(struct npc_data *)map_id2bl(st->oid);
  6522. //nd->u.scr.rid = st->rid; //NO, use npcattachtimer if you want a player-attached timer! [Skotlex]
  6523. npc_settimerevent_tick(nd,0);
  6524. npc_timerevent_start(nd, st->rid);
  6525. return 0;
  6526. }
  6527. /*==========================================
  6528. * NPCタイマー開始
  6529. *------------------------------------------
  6530. */
  6531. int buildin_startnpctimer(struct script_state *st)
  6532. {
  6533. struct npc_data *nd;
  6534. if( st->end > st->start+2 )
  6535. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6536. else
  6537. nd=(struct npc_data *)map_id2bl(st->oid);
  6538. npc_timerevent_start(nd, st->rid);
  6539. return 0;
  6540. }
  6541. /*==========================================
  6542. * NPCタイマー停止
  6543. *------------------------------------------
  6544. */
  6545. int buildin_stopnpctimer(struct script_state *st)
  6546. {
  6547. struct npc_data *nd;
  6548. if( st->end > st->start+2 )
  6549. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6550. else
  6551. nd=(struct npc_data *)map_id2bl(st->oid);
  6552. npc_timerevent_stop(nd);
  6553. return 0;
  6554. }
  6555. /*==========================================
  6556. * NPCタイマー情報所得
  6557. *------------------------------------------
  6558. */
  6559. int buildin_getnpctimer(struct script_state *st)
  6560. {
  6561. struct npc_data *nd;
  6562. struct map_session_data *sd;
  6563. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6564. int val=0;
  6565. if( st->end > st->start+3 )
  6566. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6567. else
  6568. nd=(struct npc_data *)map_id2bl(st->oid);
  6569. switch(type){
  6570. case 0: val=npc_gettimerevent_tick(nd); break;
  6571. case 1:
  6572. if (nd->u.scr.rid) {
  6573. sd = map_id2sd(nd->u.scr.rid);
  6574. if (!sd) {
  6575. if(battle_config.error_log)
  6576. ShowError("buildin_getnpctimer: Attached player not found!\n");
  6577. break;
  6578. }
  6579. val = (sd->npc_timer_id != -1);
  6580. } else
  6581. val= (nd->u.scr.timerid !=-1);
  6582. break;
  6583. case 2: val= nd->u.scr.timeramount; break;
  6584. }
  6585. push_val(st->stack,C_INT,val);
  6586. return 0;
  6587. }
  6588. /*==========================================
  6589. * NPCタイマー値設定
  6590. *------------------------------------------
  6591. */
  6592. int buildin_setnpctimer(struct script_state *st)
  6593. {
  6594. int tick;
  6595. struct npc_data *nd;
  6596. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6597. if( st->end > st->start+3 )
  6598. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6599. else
  6600. nd=(struct npc_data *)map_id2bl(st->oid);
  6601. npc_settimerevent_tick(nd,tick);
  6602. return 0;
  6603. }
  6604. /*==========================================
  6605. * attaches the player rid to the timer [Celest]
  6606. *------------------------------------------
  6607. */
  6608. int buildin_attachnpctimer(struct script_state *st)
  6609. {
  6610. struct map_session_data *sd;
  6611. struct npc_data *nd;
  6612. nd=(struct npc_data *)map_id2bl(st->oid);
  6613. if( st->end > st->start+2 ) {
  6614. char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  6615. sd=map_nick2sd(name);
  6616. } else {
  6617. sd = script_rid2sd(st);
  6618. }
  6619. if (sd==NULL)
  6620. return 0;
  6621. nd->u.scr.rid = sd->bl.id;
  6622. return 0;
  6623. }
  6624. /*==========================================
  6625. * detaches a player rid from the timer [Celest]
  6626. *------------------------------------------
  6627. */
  6628. int buildin_detachnpctimer(struct script_state *st)
  6629. {
  6630. struct npc_data *nd;
  6631. if( st->end > st->start+2 )
  6632. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6633. else
  6634. nd=(struct npc_data *)map_id2bl(st->oid);
  6635. nd->u.scr.rid = 0;
  6636. return 0;
  6637. }
  6638. /*==========================================
  6639. * To avoid "player not attached" script errors, this function is provided,
  6640. * it checks if there is a player attached to the current script. [Skotlex]
  6641. * If no, returns 0, if yes, returns the char_id of the attached player.
  6642. *------------------------------------------
  6643. */
  6644. int buildin_playerattached(struct script_state *st)
  6645. {
  6646. struct map_session_data *sd;
  6647. if (st->rid == 0 || (sd = map_id2sd(st->rid)) == NULL)
  6648. push_val(st->stack,C_INT,0);
  6649. else
  6650. push_val(st->stack,C_INT,st->rid);
  6651. return 0;
  6652. }
  6653. /*==========================================
  6654. * 天の声アナウンス
  6655. *------------------------------------------
  6656. */
  6657. int buildin_announce(struct script_state *st)
  6658. {
  6659. char *str, *color=NULL;
  6660. int flag;
  6661. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6662. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6663. if (st->end>st->start+4)
  6664. color=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6665. if(flag&0x0f){
  6666. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  6667. (struct block_list *)script_rid2sd(st);
  6668. if (color)
  6669. clif_announce(bl,str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0),flag);
  6670. else
  6671. clif_GMmessage(bl,str,(int)strlen(str)+1,flag);
  6672. }else {
  6673. if (color)
  6674. intif_announce(str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0), flag);
  6675. else
  6676. intif_GMmessage(str,(int)strlen(str)+1,flag);
  6677. }
  6678. return 0;
  6679. }
  6680. /*==========================================
  6681. * 天の声アナウンス(特定マップ)
  6682. *------------------------------------------
  6683. */
  6684. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  6685. {
  6686. char *str, *color;
  6687. int len,flag;
  6688. str=va_arg(ap,char *);
  6689. len=va_arg(ap,int);
  6690. flag=va_arg(ap,int);
  6691. color=va_arg(ap,char *);
  6692. if (color)
  6693. clif_announce(bl,str,len, strtol(color, (char **)NULL, 0), flag|3);
  6694. else
  6695. clif_GMmessage(bl,str,len,flag|3);
  6696. return 0;
  6697. }
  6698. int buildin_mapannounce(struct script_state *st)
  6699. {
  6700. char *mapname,*str, *color=NULL;
  6701. int flag,m;
  6702. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6703. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6704. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6705. if (st->end>st->start+5)
  6706. color=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6707. if( (m=map_mapname2mapid(mapname))<0 )
  6708. return 0;
  6709. map_foreachinmap(buildin_mapannounce_sub,
  6710. m, BL_PC, str,strlen(str)+1,flag&0x10, color);
  6711. return 0;
  6712. }
  6713. /*==========================================
  6714. * 天の声アナウンス(特定エリア)
  6715. *------------------------------------------
  6716. */
  6717. int buildin_areaannounce(struct script_state *st)
  6718. {
  6719. char *map,*str,*color=NULL;
  6720. int flag,m;
  6721. int x0,y0,x1,y1;
  6722. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6723. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6724. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6725. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6726. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6727. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  6728. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6729. if (st->end>st->start+9)
  6730. color=conv_str(st,& (st->stack->stack_data[st->start+9]));
  6731. if( (m=map_mapname2mapid(map))<0 )
  6732. return 0;
  6733. map_foreachinarea(buildin_mapannounce_sub,
  6734. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10, color);
  6735. return 0;
  6736. }
  6737. /*==========================================
  6738. * ユーザー数所得
  6739. *------------------------------------------
  6740. */
  6741. int buildin_getusers(struct script_state *st)
  6742. {
  6743. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6744. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  6745. int val=0;
  6746. switch(flag&0x07){
  6747. case 0: val=map[bl->m].users; break;
  6748. case 1: val=map_getusers(); break;
  6749. }
  6750. push_val(st->stack,C_INT,val);
  6751. return 0;
  6752. }
  6753. /*==========================================
  6754. * Works like @WHO - displays all online users names in window
  6755. *------------------------------------------
  6756. */
  6757. int buildin_getusersname(struct script_state *st)
  6758. {
  6759. struct map_session_data *pl_sd = NULL, **pl_allsd;
  6760. int i=0,disp_num=1, users;
  6761. pl_allsd = map_getallusers(&users);
  6762. for (i=0;i<users;i++)
  6763. {
  6764. pl_sd = pl_allsd[i];
  6765. if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) )
  6766. {
  6767. if((disp_num++)%10==0)
  6768. clif_scriptnext(script_rid2sd(st),st->oid);
  6769. clif_scriptmes(script_rid2sd(st),st->oid,pl_sd->status.name);
  6770. }
  6771. }
  6772. return 0;
  6773. }
  6774. /*==========================================
  6775. * マップ指定ユーザー数所得
  6776. *------------------------------------------
  6777. */
  6778. int buildin_getmapusers(struct script_state *st)
  6779. {
  6780. char *str;
  6781. int m;
  6782. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6783. if( (m=map_mapname2mapid(str))< 0){
  6784. push_val(st->stack,C_INT,-1);
  6785. return 0;
  6786. }
  6787. push_val(st->stack,C_INT,map[m].users);
  6788. return 0;
  6789. }
  6790. /*==========================================
  6791. * エリア指定ユーザー数所得
  6792. *------------------------------------------
  6793. */
  6794. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  6795. {
  6796. int *users=va_arg(ap,int *);
  6797. (*users)++;
  6798. return 0;
  6799. }
  6800. int buildin_getareausers(struct script_state *st)
  6801. {
  6802. char *str;
  6803. int m,x0,y0,x1,y1,users=0;
  6804. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6805. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6806. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6807. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6808. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6809. if( (m=map_mapname2mapid(str))< 0){
  6810. push_val(st->stack,C_INT,-1);
  6811. return 0;
  6812. }
  6813. map_foreachinarea(buildin_getareausers_sub,
  6814. m,x0,y0,x1,y1,BL_PC,&users);
  6815. push_val(st->stack,C_INT,users);
  6816. return 0;
  6817. }
  6818. /*==========================================
  6819. * エリア指定ドロップアイテム数所得
  6820. *------------------------------------------
  6821. */
  6822. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  6823. {
  6824. int item=va_arg(ap,int);
  6825. int *amount=va_arg(ap,int *);
  6826. struct flooritem_data *drop=(struct flooritem_data *)bl;
  6827. if(drop->item_data.nameid==item)
  6828. (*amount)+=drop->item_data.amount;
  6829. return 0;
  6830. }
  6831. int buildin_getareadropitem(struct script_state *st)
  6832. {
  6833. char *str;
  6834. int m,x0,y0,x1,y1,item,amount=0;
  6835. struct script_data *data;
  6836. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6837. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6838. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6839. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6840. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6841. data=&(st->stack->stack_data[st->start+7]);
  6842. get_val(st,data);
  6843. if( data->type==C_STR || data->type==C_CONSTSTR ){
  6844. const char *name=conv_str(st,data);
  6845. struct item_data *item_data = itemdb_searchname(name);
  6846. item=UNKNOWN_ITEM_ID;
  6847. if( item_data )
  6848. item=item_data->nameid;
  6849. }else
  6850. item=conv_num(st,data);
  6851. if( (m=map_mapname2mapid(str))< 0){
  6852. push_val(st->stack,C_INT,-1);
  6853. return 0;
  6854. }
  6855. map_foreachinarea(buildin_getareadropitem_sub,
  6856. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  6857. push_val(st->stack,C_INT,amount);
  6858. return 0;
  6859. }
  6860. /*==========================================
  6861. * NPCの有効化
  6862. *------------------------------------------
  6863. */
  6864. int buildin_enablenpc(struct script_state *st)
  6865. {
  6866. char *str;
  6867. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6868. npc_enable(str,1);
  6869. return 0;
  6870. }
  6871. /*==========================================
  6872. * NPCの無効化
  6873. *------------------------------------------
  6874. */
  6875. int buildin_disablenpc(struct script_state *st)
  6876. {
  6877. char *str;
  6878. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6879. npc_enable(str,0);
  6880. return 0;
  6881. }
  6882. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  6883. {
  6884. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6885. struct chat_data *cd;
  6886. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  6887. return 0;
  6888. npc_enable(nd->name,1);
  6889. nd->arenaflag=1;
  6890. if(cd->users>=cd->trigger && cd->npc_event[0])
  6891. npc_timer_event(cd->npc_event);
  6892. return 0;
  6893. }
  6894. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  6895. {
  6896. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6897. nd->arenaflag=0;
  6898. return 0;
  6899. }
  6900. /*==========================================
  6901. * 隠れているNPCの表示
  6902. *------------------------------------------
  6903. */
  6904. int buildin_hideoffnpc(struct script_state *st)
  6905. {
  6906. char *str;
  6907. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6908. npc_enable(str,2);
  6909. return 0;
  6910. }
  6911. /*==========================================
  6912. * NPCをハイディング
  6913. *------------------------------------------
  6914. */
  6915. int buildin_hideonnpc(struct script_state *st)
  6916. {
  6917. char *str;
  6918. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6919. npc_enable(str,4);
  6920. return 0;
  6921. }
  6922. /*==========================================
  6923. * 状態異常にかかる
  6924. *------------------------------------------
  6925. */
  6926. int buildin_sc_start(struct script_state *st)
  6927. {
  6928. struct block_list *bl;
  6929. int type,tick,val1,val4=0;
  6930. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6931. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6932. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6933. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  6934. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  6935. else
  6936. bl = map_id2bl(st->rid);
  6937. if (potion_flag==1 && potion_target) {
  6938. bl = map_id2bl(potion_target);
  6939. tick/=2; //Thrown potions only last half.
  6940. val4 = 1; //Mark that this was a thrown sc_effect
  6941. }
  6942. if (bl)
  6943. status_change_start(bl,type,10000,val1,0,0,val4,tick,11);
  6944. return 0;
  6945. }
  6946. /*==========================================
  6947. * 状態異常にかかる(確率指定)
  6948. *------------------------------------------
  6949. */
  6950. int buildin_sc_start2(struct script_state *st)
  6951. {
  6952. struct block_list *bl;
  6953. int type,tick,val1,val4=0,per;
  6954. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6955. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6956. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6957. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6958. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  6959. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  6960. else
  6961. bl = map_id2bl(st->rid);
  6962. if (potion_flag==1 && potion_target) {
  6963. bl = map_id2bl(potion_target);
  6964. tick/=2;
  6965. val4 = 1;
  6966. }
  6967. if(bl)
  6968. status_change_start(bl,type,per,val1,0,0,val4,tick,11);
  6969. return 0;
  6970. }
  6971. /*==========================================
  6972. * Starts a SC_ change with the four values passed. [Skotlex]
  6973. * Final optional argument is the ID of player to affect.
  6974. * sc_start4 type, duration, val1, val2, val3, val4, <id>;
  6975. *------------------------------------------
  6976. */
  6977. int buildin_sc_start4(struct script_state *st)
  6978. {
  6979. struct block_list *bl;
  6980. int type,tick,val1,val2,val3,val4;
  6981. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6982. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6983. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6984. val2=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6985. val3=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6986. val4=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6987. if( st->end>st->start+8 )
  6988. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+8])));
  6989. else
  6990. bl = map_id2bl(st->rid);
  6991. if (potion_flag==1 && potion_target) {
  6992. bl = map_id2bl(potion_target);
  6993. tick/=2;
  6994. }
  6995. if (bl)
  6996. status_change_start(bl,type,10000,val1,val2,val3,val4,tick,11);
  6997. return 0;
  6998. }
  6999. /*==========================================
  7000. * 状態異常が直る
  7001. *------------------------------------------
  7002. */
  7003. int buildin_sc_end(struct script_state *st)
  7004. {
  7005. struct block_list *bl;
  7006. int type;
  7007. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7008. bl = map_id2bl(st->rid);
  7009. if (potion_flag==1 && potion_target)
  7010. bl = map_id2bl(potion_target);
  7011. if (!bl) return 0;
  7012. if (type >= 0)
  7013. status_change_end(bl,type,-1);
  7014. else
  7015. status_change_clear(bl, 2);
  7016. return 0;
  7017. }
  7018. /*==========================================
  7019. * 状態異常耐性を計算した確率を返す
  7020. *------------------------------------------
  7021. */
  7022. int buildin_getscrate(struct script_state *st)
  7023. {
  7024. struct block_list *bl;
  7025. int sc_def=0,type,rate;
  7026. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7027. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7028. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  7029. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  7030. else
  7031. bl = map_id2bl(st->rid);
  7032. if (bl)
  7033. sc_def = status_get_sc_def(bl,type);
  7034. rate = rate*(10000-sc_def)/10000;
  7035. push_val(st->stack,C_INT,rate<0?0:rate);
  7036. return 0;
  7037. }
  7038. /*==========================================
  7039. *
  7040. *------------------------------------------
  7041. */
  7042. int buildin_debugmes(struct script_state *st)
  7043. {
  7044. conv_str(st,& (st->stack->stack_data[st->start+2]));
  7045. ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  7046. return 0;
  7047. }
  7048. /*==========================================
  7049. *捕獲アイテム使用
  7050. *------------------------------------------
  7051. */
  7052. int buildin_catchpet(struct script_state *st)
  7053. {
  7054. int pet_id;
  7055. struct map_session_data *sd;
  7056. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  7057. sd=script_rid2sd(st);
  7058. pet_catch_process1(sd,pet_id);
  7059. return 0;
  7060. }
  7061. /*==========================================
  7062. * [orn]
  7063. *------------------------------------------
  7064. */
  7065. int buildin_homunculus_evolution(struct script_state *st)
  7066. {
  7067. struct map_session_data *sd;
  7068. sd=script_rid2sd(st);
  7069. if ( sd->hd && sd->hd->homunculusDB->evo_class && sd->homunculus.intimacy > 91000 ) {
  7070. return merc_hom_evolution(sd->hd) ;
  7071. }
  7072. clif_emotion(&sd->hd->bl, 4) ; //swt
  7073. return 0;
  7074. }
  7075. /*==========================================
  7076. *携帯卵孵化機使用
  7077. *------------------------------------------
  7078. */
  7079. int buildin_birthpet(struct script_state *st)
  7080. {
  7081. struct map_session_data *sd;
  7082. sd=script_rid2sd(st);
  7083. clif_sendegg(sd);
  7084. return 0;
  7085. }
  7086. /*==========================================
  7087. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  7088. *------------------------------------------
  7089. */
  7090. int buildin_resetlvl(struct script_state *st)
  7091. {
  7092. struct map_session_data *sd;
  7093. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7094. sd=script_rid2sd(st);
  7095. pc_resetlvl(sd,type);
  7096. return 0;
  7097. }
  7098. /*==========================================
  7099. * ステータスリセット
  7100. *------------------------------------------
  7101. */
  7102. int buildin_resetstatus(struct script_state *st)
  7103. {
  7104. struct map_session_data *sd;
  7105. sd=script_rid2sd(st);
  7106. pc_resetstate(sd);
  7107. return 0;
  7108. }
  7109. /*==========================================
  7110. * script command resetskill
  7111. *------------------------------------------
  7112. */
  7113. int buildin_resetskill(struct script_state *st)
  7114. {
  7115. struct map_session_data *sd;
  7116. sd=script_rid2sd(st);
  7117. pc_resetskill(sd,1);
  7118. return 0;
  7119. }
  7120. /*==========================================
  7121. * Counts total amount of skill points.
  7122. *------------------------------------------
  7123. */
  7124. int buildin_skillpointcount(struct script_state *st)
  7125. {
  7126. struct map_session_data *sd;
  7127. sd=script_rid2sd(st);
  7128. push_val(st->stack,C_INT,sd->status.skill_point + pc_resetskill(sd,2));
  7129. return 0;
  7130. }
  7131. /*==========================================
  7132. *
  7133. *------------------------------------------
  7134. */
  7135. int buildin_changebase(struct script_state *st)
  7136. {
  7137. struct map_session_data *sd=NULL;
  7138. int vclass;
  7139. if( st->end>st->start+3 )
  7140. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  7141. else
  7142. sd=script_rid2sd(st);
  7143. if(sd == NULL)
  7144. return 0;
  7145. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7146. if(vclass == JOB_WEDDING)
  7147. {
  7148. if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
  7149. sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore.
  7150. )
  7151. return 0;
  7152. }
  7153. if(!sd->disguise && vclass != sd->vd.class_) {
  7154. status_set_viewdata(&sd->bl, vclass);
  7155. //Updated client view. Base, Weapon and Cloth Colors.
  7156. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_);
  7157. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7158. if (sd->vd.cloth_color)
  7159. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7160. }
  7161. return 0;
  7162. }
  7163. /*==========================================
  7164. * 性別変換
  7165. *------------------------------------------
  7166. */
  7167. int buildin_changesex(struct script_state *st) {
  7168. struct map_session_data *sd = NULL;
  7169. sd = script_rid2sd(st);
  7170. if (sd->status.sex == 0) {
  7171. sd->status.sex = 1;
  7172. sd->sex = 1;
  7173. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7174. sd->status.class_ -= 1;
  7175. } else if (sd->status.sex == 1) {
  7176. sd->status.sex = 0;
  7177. sd->sex = 0;
  7178. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7179. sd->status.class_ += 1;
  7180. }
  7181. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  7182. chrif_save(sd,0);
  7183. return 0;
  7184. }
  7185. /*==========================================
  7186. * npcチャット作成
  7187. *------------------------------------------
  7188. */
  7189. int buildin_waitingroom(struct script_state *st)
  7190. {
  7191. char *name,*ev="";
  7192. int limit, trigger = 0,pub=1;
  7193. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7194. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  7195. if(limit==0)
  7196. pub=3;
  7197. if( (st->end > st->start+5) ){
  7198. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  7199. get_val(st,data);
  7200. if(data->type==C_INT){
  7201. // 新Athena仕様(旧Athena仕様と互換性あり)
  7202. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7203. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7204. }else{
  7205. // eathena仕様
  7206. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7207. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  7208. }
  7209. }else{
  7210. // 旧Athena仕様
  7211. if( st->end > st->start+4 )
  7212. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7213. }
  7214. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  7215. limit,pub,trigger,name,(int)strlen(name)+1,ev);
  7216. return 0;
  7217. }
  7218. /*==========================================
  7219. * Works like 'announce' but outputs in the common chat window
  7220. *------------------------------------------
  7221. */
  7222. int buildin_globalmes(struct script_state *st)
  7223. {
  7224. struct block_list *bl = map_id2bl(st->oid);
  7225. struct npc_data *nd = (struct npc_data *)bl;
  7226. char *name=NULL,*mes;
  7227. mes=conv_str(st,& (st->stack->stack_data[st->start+2])); // メッセージの取得
  7228. if(mes==NULL) return 0;
  7229. if(st->end>st->start+3){ // NPC名の取得(123#456)
  7230. name=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7231. } else {
  7232. name=nd->name;
  7233. }
  7234. npc_globalmessage(name,mes); // グローバルメッセージ送信
  7235. return 0;
  7236. }
  7237. /*==========================================
  7238. * npcチャット削除
  7239. *------------------------------------------
  7240. */
  7241. int buildin_delwaitingroom(struct script_state *st)
  7242. {
  7243. struct npc_data *nd;
  7244. if( st->end > st->start+2 )
  7245. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7246. else
  7247. nd=(struct npc_data *)map_id2bl(st->oid);
  7248. chat_deletenpcchat(nd);
  7249. return 0;
  7250. }
  7251. /*==========================================
  7252. * npcチャット全員蹴り出す
  7253. *------------------------------------------
  7254. */
  7255. int buildin_waitingroomkickall(struct script_state *st)
  7256. {
  7257. struct npc_data *nd;
  7258. struct chat_data *cd;
  7259. if( st->end > st->start+2 )
  7260. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7261. else
  7262. nd=(struct npc_data *)map_id2bl(st->oid);
  7263. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7264. return 0;
  7265. chat_npckickall(cd);
  7266. return 0;
  7267. }
  7268. /*==========================================
  7269. * npcチャットイベント有効化
  7270. *------------------------------------------
  7271. */
  7272. int buildin_enablewaitingroomevent(struct script_state *st)
  7273. {
  7274. struct npc_data *nd;
  7275. struct chat_data *cd;
  7276. if( st->end > st->start+2 )
  7277. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7278. else
  7279. nd=(struct npc_data *)map_id2bl(st->oid);
  7280. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7281. return 0;
  7282. chat_enableevent(cd);
  7283. return 0;
  7284. }
  7285. /*==========================================
  7286. * npcチャットイベント無効化
  7287. *------------------------------------------
  7288. */
  7289. int buildin_disablewaitingroomevent(struct script_state *st)
  7290. {
  7291. struct npc_data *nd;
  7292. struct chat_data *cd;
  7293. if( st->end > st->start+2 )
  7294. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7295. else
  7296. nd=(struct npc_data *)map_id2bl(st->oid);
  7297. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7298. return 0;
  7299. chat_disableevent(cd);
  7300. return 0;
  7301. }
  7302. /*==========================================
  7303. * npcチャット状態所得
  7304. *------------------------------------------
  7305. */
  7306. int buildin_getwaitingroomstate(struct script_state *st)
  7307. {
  7308. struct npc_data *nd;
  7309. struct chat_data *cd;
  7310. int val=0,type;
  7311. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7312. if( st->end > st->start+3 )
  7313. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  7314. else
  7315. nd=(struct npc_data *)map_id2bl(st->oid);
  7316. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  7317. push_val(st->stack,C_INT,-1);
  7318. return 0;
  7319. }
  7320. switch(type){
  7321. case 0: val=cd->users; break;
  7322. case 1: val=cd->limit; break;
  7323. case 2: val=cd->trigger&0x7f; break;
  7324. case 3: val=((cd->trigger&0x80)>0); break;
  7325. case 32: val=(cd->users >= cd->limit); break;
  7326. case 33: val=(cd->users >= cd->trigger); break;
  7327. case 4:
  7328. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->title);
  7329. return 0;
  7330. case 5:
  7331. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->pass);
  7332. return 0;
  7333. case 16:
  7334. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->npc_event);
  7335. return 0;
  7336. }
  7337. push_val(st->stack,C_INT,val);
  7338. return 0;
  7339. }
  7340. /*==========================================
  7341. * チャットメンバー(規定人数)ワープ
  7342. *------------------------------------------
  7343. */
  7344. int buildin_warpwaitingpc(struct script_state *st)
  7345. {
  7346. int x,y,i,n;
  7347. char *str;
  7348. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7349. struct chat_data *cd;
  7350. struct map_session_data *sd;
  7351. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7352. return 0;
  7353. n=cd->trigger&0x7f;
  7354. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7355. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7356. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7357. if( st->end > st->start+5 )
  7358. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7359. for(i=0;i<n;i++){
  7360. sd=cd->usersd[0];
  7361. if (!sd) continue; //Broken npc chat room?
  7362. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpc")+(i<<24),sd->bl.id);
  7363. if(strcmp(str,"Random")==0)
  7364. pc_randomwarp(sd,3);
  7365. else if(strcmp(str,"SavePoint")==0){
  7366. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  7367. return 0;
  7368. pc_setpos(sd,sd->status.save_point.map,
  7369. sd->status.save_point.x,sd->status.save_point.y,3);
  7370. }else
  7371. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  7372. }
  7373. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpcnum"),n);
  7374. return 0;
  7375. }
  7376. /*==========================================
  7377. * RIDのアタッチ
  7378. *------------------------------------------
  7379. */
  7380. int buildin_attachrid(struct script_state *st)
  7381. {
  7382. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7383. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  7384. return 0;
  7385. }
  7386. /*==========================================
  7387. * RIDのデタッチ
  7388. *------------------------------------------
  7389. */
  7390. int buildin_detachrid(struct script_state *st)
  7391. {
  7392. st->rid=0;
  7393. return 0;
  7394. }
  7395. /*==========================================
  7396. * 存在チェック
  7397. *------------------------------------------
  7398. */
  7399. int buildin_isloggedin(struct script_state *st)
  7400. {
  7401. push_val(st->stack,C_INT, map_id2sd(
  7402. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  7403. return 0;
  7404. }
  7405. /*==========================================
  7406. *
  7407. *------------------------------------------
  7408. */
  7409. int buildin_setmapflagnosave(struct script_state *st)
  7410. {
  7411. int m,x,y;
  7412. unsigned short mapindex;
  7413. char *str,*str2;
  7414. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7415. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7416. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7417. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7418. m = map_mapname2mapid(str);
  7419. mapindex = mapindex_name2id(str2);
  7420. if(m >= 0 && mapindex) {
  7421. map[m].flag.nosave=1;
  7422. map[m].save.map=mapindex;
  7423. map[m].save.x=x;
  7424. map[m].save.y=y;
  7425. }
  7426. return 0;
  7427. }
  7428. int buildin_setmapflag(struct script_state *st)
  7429. {
  7430. int m,i;
  7431. char *str;
  7432. char *val=NULL;
  7433. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7434. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7435. if(st->end>st->start+4){
  7436. val=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7437. }
  7438. m = map_mapname2mapid(str);
  7439. if(m >= 0) {
  7440. switch(i) {
  7441. case MF_NOMEMO:
  7442. map[m].flag.nomemo=1;
  7443. break;
  7444. case MF_NOTELEPORT:
  7445. map[m].flag.noteleport=1;
  7446. break;
  7447. case MF_NOBRANCH:
  7448. map[m].flag.nobranch=1;
  7449. break;
  7450. case MF_NOPENALTY:
  7451. map[m].flag.nopenalty=1;
  7452. break;
  7453. case MF_NOZENYPENALTY:
  7454. map[m].flag.nozenypenalty=1;
  7455. break;
  7456. case MF_PVP:
  7457. map[m].flag.pvp=1;
  7458. break;
  7459. case MF_PVP_NOPARTY:
  7460. map[m].flag.pvp_noparty=1;
  7461. break;
  7462. case MF_PVP_NOGUILD:
  7463. map[m].flag.pvp_noguild=1;
  7464. break;
  7465. case MF_GVG:
  7466. map[m].flag.gvg=1;
  7467. break;
  7468. case MF_GVG_NOPARTY:
  7469. map[m].flag.gvg_noparty=1;
  7470. break;
  7471. case MF_GVG_DUNGEON:
  7472. map[m].flag.gvg_dungeon=1;
  7473. break;
  7474. case MF_GVG_CASTLE:
  7475. map[m].flag.gvg_castle=1;
  7476. break;
  7477. case MF_NOTRADE:
  7478. map[m].flag.notrade=1;
  7479. break;
  7480. case MF_NODROP:
  7481. map[m].flag.nodrop=1;
  7482. break;
  7483. case MF_NOSKILL:
  7484. map[m].flag.noskill=1;
  7485. break;
  7486. case MF_NOWARP:
  7487. map[m].flag.nowarp=1;
  7488. break;
  7489. case MF_NOICEWALL: // [Valaris]
  7490. map[m].flag.noicewall=1;
  7491. break;
  7492. case MF_SNOW: // [Valaris]
  7493. map[m].flag.snow=1;
  7494. break;
  7495. case MF_CLOUDS:
  7496. map[m].flag.clouds=1;
  7497. break;
  7498. case MF_CLOUDS2: // [Valaris]
  7499. map[m].flag.clouds2=1;
  7500. break;
  7501. case MF_FOG: // [Valaris]
  7502. map[m].flag.fog=1;
  7503. break;
  7504. case MF_FIREWORKS:
  7505. map[m].flag.fireworks=1;
  7506. break;
  7507. case MF_SAKURA: // [Valaris]
  7508. map[m].flag.sakura=1;
  7509. break;
  7510. case MF_LEAVES: // [Valaris]
  7511. map[m].flag.leaves=1;
  7512. break;
  7513. case MF_RAIN: // [Valaris]
  7514. map[m].flag.rain=1;
  7515. break;
  7516. case MF_INDOORS: // celest
  7517. map[m].flag.indoors=1;
  7518. break;
  7519. case MF_NIGHTENABLED:
  7520. map[m].flag.nightenabled=1;
  7521. break;
  7522. case MF_NOGO: // celest
  7523. map[m].flag.nogo=1;
  7524. break;
  7525. case MF_NOBASEEXP:
  7526. map[m].flag.nobaseexp=1;
  7527. break;
  7528. case MF_NOJOBEXP:
  7529. map[m].flag.nojobexp=1;
  7530. break;
  7531. case MF_NOMOBLOOT:
  7532. map[m].flag.nomobloot=1;
  7533. break;
  7534. case MF_NOMVPLOOT:
  7535. map[m].flag.nomvploot=1;
  7536. break;
  7537. case MF_NORETURN:
  7538. map[m].flag.noreturn=1;
  7539. break;
  7540. case MF_NOWARPTO:
  7541. map[m].flag.nowarpto=1;
  7542. break;
  7543. case MF_NIGHTMAREDROP:
  7544. map[m].flag.pvp_nightmaredrop=1;
  7545. break;
  7546. case MF_RESTRICTED:
  7547. map[m].flag.restricted=1;
  7548. break;
  7549. case MF_NOCOMMAND:
  7550. map[m].flag.nocommand=1;
  7551. break;
  7552. case MF_JEXP:
  7553. map[m].jexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7554. break;
  7555. case MF_BEXP:
  7556. map[m].bexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7557. break;
  7558. case MF_NOVENDING:
  7559. map[m].flag.novending=1;
  7560. break;
  7561. case MF_LOADEVENT:
  7562. map[m].flag.loadevent=1;
  7563. break;
  7564. case MF_NOCHAT:
  7565. map[m].flag.nochat=1;
  7566. }
  7567. }
  7568. return 0;
  7569. }
  7570. int buildin_removemapflag(struct script_state *st)
  7571. {
  7572. int m,i;
  7573. char *str;
  7574. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7575. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7576. m = map_mapname2mapid(str);
  7577. if(m >= 0) {
  7578. switch(i) {
  7579. case MF_NOMEMO:
  7580. map[m].flag.nomemo=0;
  7581. break;
  7582. case MF_NOTELEPORT:
  7583. map[m].flag.noteleport=0;
  7584. break;
  7585. case MF_NOSAVE:
  7586. map[m].flag.nosave=0;
  7587. break;
  7588. case MF_NOBRANCH:
  7589. map[m].flag.nobranch=0;
  7590. break;
  7591. case MF_NOPENALTY:
  7592. map[m].flag.nopenalty=0;
  7593. break;
  7594. case MF_PVP:
  7595. map[m].flag.pvp=0;
  7596. break;
  7597. case MF_PVP_NOPARTY:
  7598. map[m].flag.pvp_noparty=0;
  7599. break;
  7600. case MF_PVP_NOGUILD:
  7601. map[m].flag.pvp_noguild=0;
  7602. break;
  7603. case MF_GVG:
  7604. map[m].flag.gvg=0;
  7605. break;
  7606. case MF_GVG_NOPARTY:
  7607. map[m].flag.gvg_noparty=0;
  7608. break;
  7609. case MF_GVG_DUNGEON:
  7610. map[m].flag.gvg_dungeon=0;
  7611. break;
  7612. case MF_GVG_CASTLE:
  7613. map[m].flag.gvg_castle=0;
  7614. break;
  7615. case MF_NOZENYPENALTY:
  7616. map[m].flag.nozenypenalty=0;
  7617. break;
  7618. case MF_NOTRADE:
  7619. map[m].flag.notrade=0;
  7620. break;
  7621. case MF_NODROP:
  7622. map[m].flag.nodrop=0;
  7623. break;
  7624. case MF_NOSKILL:
  7625. map[m].flag.noskill=0;
  7626. break;
  7627. case MF_NOWARP:
  7628. map[m].flag.nowarp=0;
  7629. break;
  7630. case MF_NOICEWALL: // [Valaris]
  7631. map[m].flag.noicewall=0;
  7632. break;
  7633. case MF_SNOW: // [Valaris]
  7634. map[m].flag.snow=0;
  7635. break;
  7636. case MF_CLOUDS:
  7637. map[m].flag.clouds=0;
  7638. break;
  7639. case MF_CLOUDS2: // [Valaris]
  7640. map[m].flag.clouds2=0;
  7641. break;
  7642. case MF_FOG: // [Valaris]
  7643. map[m].flag.fog=0;
  7644. break;
  7645. case MF_FIREWORKS:
  7646. map[m].flag.fireworks=0;
  7647. break;
  7648. case MF_SAKURA: // [Valaris]
  7649. map[m].flag.sakura=0;
  7650. break;
  7651. case MF_LEAVES: // [Valaris]
  7652. map[m].flag.leaves=0;
  7653. break;
  7654. case MF_RAIN: // [Valaris]
  7655. map[m].flag.rain=0;
  7656. break;
  7657. case MF_INDOORS: // celest
  7658. map[m].flag.indoors=0;
  7659. break;
  7660. case MF_NIGHTENABLED:
  7661. map[m].flag.nightenabled=0;
  7662. break;
  7663. case MF_NOGO: // celest
  7664. map[m].flag.nogo=0;
  7665. break;
  7666. case MF_NOBASEEXP:
  7667. map[m].flag.nobaseexp=0;
  7668. break;
  7669. case MF_NOJOBEXP:
  7670. map[m].flag.nojobexp=0;
  7671. break;
  7672. case MF_NOMOBLOOT:
  7673. map[m].flag.nomobloot=0;
  7674. break;
  7675. case MF_NOMVPLOOT:
  7676. map[m].flag.nomvploot=0;
  7677. break;
  7678. case MF_NORETURN:
  7679. map[m].flag.noreturn=0;
  7680. break;
  7681. case MF_NOWARPTO:
  7682. map[m].flag.nowarpto=0;
  7683. break;
  7684. case MF_NIGHTMAREDROP:
  7685. map[m].flag.pvp_nightmaredrop=0;
  7686. break;
  7687. case MF_RESTRICTED:
  7688. map[m].flag.restricted=0;
  7689. break;
  7690. case MF_NOCOMMAND:
  7691. map[m].flag.nocommand=0;
  7692. break;
  7693. case MF_JEXP:
  7694. map[m].jexp=100;
  7695. break;
  7696. case MF_BEXP:
  7697. map[m].bexp=100;
  7698. break;
  7699. case MF_NOVENDING:
  7700. map[m].flag.novending=0;
  7701. break;
  7702. case MF_LOADEVENT:
  7703. map[m].flag.loadevent=0;
  7704. break;
  7705. case MF_NOCHAT:
  7706. map[m].flag.nochat=0;
  7707. }
  7708. }
  7709. return 0;
  7710. }
  7711. int buildin_pvpon(struct script_state *st)
  7712. {
  7713. int m,i,users;
  7714. char *str;
  7715. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7716. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7717. m = map_mapname2mapid(str);
  7718. if(m >= 0 && !map[m].flag.pvp) {
  7719. map[m].flag.pvp = 1;
  7720. clif_send0199(m,1);
  7721. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  7722. return 0;
  7723. pl_allsd = map_getallusers(&users);
  7724. for(i=0;i<users;i++)
  7725. {
  7726. if ((pl_sd = pl_allsd[i]) && m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
  7727. {
  7728. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  7729. pl_sd->pvp_rank=0;
  7730. pl_sd->pvp_lastusers=0;
  7731. pl_sd->pvp_point=5;
  7732. pl_sd->pvp_won = 0;
  7733. pl_sd->pvp_lost = 0;
  7734. }
  7735. }
  7736. }
  7737. return 0;
  7738. }
  7739. int buildin_pvpoff(struct script_state *st)
  7740. {
  7741. int m,i,users;
  7742. char *str;
  7743. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7744. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7745. m = map_mapname2mapid(str);
  7746. if(m >= 0 && map[m].flag.pvp) { //fixed Lupus
  7747. map[m].flag.pvp = 0;
  7748. clif_send0199(m,0);
  7749. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  7750. return 0;
  7751. pl_allsd = map_getallusers(&users);
  7752. for(i=0;i<users;i++)
  7753. {
  7754. if((pl_sd=pl_allsd[i]) && m == pl_sd->bl.m)
  7755. {
  7756. clif_pvpset(pl_sd,0,0,2);
  7757. if(pl_sd->pvp_timer != -1) {
  7758. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  7759. pl_sd->pvp_timer = -1;
  7760. }
  7761. }
  7762. }
  7763. }
  7764. return 0;
  7765. }
  7766. int buildin_gvgon(struct script_state *st)
  7767. {
  7768. int m;
  7769. char *str;
  7770. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7771. m = map_mapname2mapid(str);
  7772. if(m >= 0 && !map[m].flag.gvg) {
  7773. map[m].flag.gvg = 1;
  7774. clif_send0199(m,3);
  7775. }
  7776. return 0;
  7777. }
  7778. int buildin_gvgoff(struct script_state *st)
  7779. {
  7780. int m;
  7781. char *str;
  7782. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7783. m = map_mapname2mapid(str);
  7784. if(m >= 0 && map[m].flag.gvg) {
  7785. map[m].flag.gvg = 0;
  7786. clif_send0199(m,0);
  7787. }
  7788. return 0;
  7789. }
  7790. /*==========================================
  7791. * Shows an emoticon on top of the player/npc
  7792. * emotion emotion#, <target: 0 - NPC, 1 - PC>
  7793. *------------------------------------------
  7794. */
  7795. //Optional second parameter added by [Skotlex]
  7796. int buildin_emotion(struct script_state *st)
  7797. {
  7798. int type;
  7799. int player=0;
  7800. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7801. if(type < 0 || type > 100)
  7802. return 0;
  7803. if( st->end>st->start+3 )
  7804. player=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7805. if (player) {
  7806. struct map_session_data *sd = script_rid2sd(st);
  7807. if (sd)
  7808. clif_emotion(&sd->bl,type);
  7809. } else
  7810. clif_emotion(map_id2bl(st->oid),type);
  7811. return 0;
  7812. }
  7813. int buildin_maprespawnguildid_sub(struct block_list *bl,va_list ap)
  7814. {
  7815. int g_id=va_arg(ap,int);
  7816. int flag=va_arg(ap,int);
  7817. struct map_session_data *sd=NULL;
  7818. struct mob_data *md=NULL;
  7819. if(bl->type == BL_PC)
  7820. sd=(struct map_session_data*)bl;
  7821. if(bl->type == BL_MOB)
  7822. md=(struct mob_data *)bl;
  7823. if(sd){
  7824. if((sd->status.guild_id == g_id) && (flag&1))
  7825. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  7826. else if((sd->status.guild_id != g_id) && (flag&2))
  7827. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  7828. else if (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  7829. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3); // end addition [Valaris]
  7830. }
  7831. if(md && flag&4){
  7832. if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
  7833. unit_remove_map(bl,1);
  7834. }
  7835. return 0;
  7836. }
  7837. int buildin_maprespawnguildid(struct script_state *st)
  7838. {
  7839. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7840. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7841. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7842. int m=map_mapname2mapid(mapname);
  7843. if(m) map_foreachinmap(buildin_maprespawnguildid_sub,m,BL_CHAR,g_id,flag);
  7844. return 0;
  7845. }
  7846. int buildin_agitstart(struct script_state *st)
  7847. {
  7848. if(agit_flag==1) return 0; // Agit already Start.
  7849. agit_flag=1;
  7850. guild_agit_start();
  7851. return 0;
  7852. }
  7853. int buildin_agitend(struct script_state *st)
  7854. {
  7855. if(agit_flag==0) return 0; // Agit already End.
  7856. agit_flag=0;
  7857. guild_agit_end();
  7858. return 0;
  7859. }
  7860. /*==========================================
  7861. * agitcheck 1; // choice script
  7862. * if(@agit_flag == 1) goto agit;
  7863. * if(agitcheck(0) == 1) goto agit;
  7864. *------------------------------------------
  7865. */
  7866. int buildin_agitcheck(struct script_state *st)
  7867. {
  7868. struct map_session_data *sd;
  7869. int cond;
  7870. cond=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7871. if(cond == 0) {
  7872. if (agit_flag==1) push_val(st->stack,C_INT,1);
  7873. if (agit_flag==0) push_val(st->stack,C_INT,0);
  7874. } else {
  7875. sd=script_rid2sd(st);
  7876. if (agit_flag==1) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),1);
  7877. if (agit_flag==0) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),0);
  7878. }
  7879. return 0;
  7880. }
  7881. int buildin_flagemblem(struct script_state *st)
  7882. {
  7883. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7884. if(g_id < 0) return 0;
  7885. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  7886. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  7887. return 0;
  7888. }
  7889. int buildin_getcastlename(struct script_state *st)
  7890. {
  7891. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7892. struct guild_castle *gc;
  7893. int i;
  7894. for(i=0;i<MAX_GUILDCASTLE;i++){
  7895. if( (gc=guild_castle_search(i)) != NULL ){
  7896. if(strcmp(mapname,gc->map_name)==0){
  7897. break;
  7898. }
  7899. }
  7900. }
  7901. if(gc)
  7902. push_str(st->stack,C_CONSTSTR,(unsigned char *) gc->castle_name);
  7903. else
  7904. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  7905. return 0;
  7906. }
  7907. int buildin_getcastledata(struct script_state *st)
  7908. {
  7909. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7910. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7911. char *event=NULL;
  7912. struct guild_castle *gc;
  7913. int i,j;
  7914. if( st->end>st->start+4 && index==0){
  7915. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  7916. if( (gc=guild_castle_search(i)) != NULL &&
  7917. strcmp(mapname,gc->map_name)==0 )
  7918. j=i;
  7919. if(j>=0){
  7920. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7921. check_event(st, event);
  7922. guild_addcastleinfoevent(j,17,event);
  7923. }
  7924. }
  7925. for(i=0;i<MAX_GUILDCASTLE;i++){
  7926. if( (gc=guild_castle_search(i)) != NULL ){
  7927. if(strcmp(mapname,gc->map_name)==0){
  7928. switch(index){
  7929. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  7930. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  7931. case 2: push_val(st->stack,C_INT,gc->economy); break;
  7932. case 3: push_val(st->stack,C_INT,gc->defense); break;
  7933. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  7934. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  7935. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  7936. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  7937. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  7938. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  7939. case 10:
  7940. case 11:
  7941. case 12:
  7942. case 13:
  7943. case 14:
  7944. case 15:
  7945. case 16:
  7946. case 17:
  7947. push_val(st->stack,C_INT,gc->guardian[index-10].visible); break;
  7948. case 18:
  7949. case 19:
  7950. case 20:
  7951. case 21:
  7952. case 22:
  7953. case 23:
  7954. case 24:
  7955. case 25:
  7956. push_val(st->stack,C_INT,gc->guardian[index-18].hp); break;
  7957. default:
  7958. push_val(st->stack,C_INT,0); break;
  7959. }
  7960. return 0;
  7961. }
  7962. }
  7963. }
  7964. push_val(st->stack,C_INT,0);
  7965. return 0;
  7966. }
  7967. int buildin_setcastledata(struct script_state *st)
  7968. {
  7969. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7970. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7971. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7972. struct guild_castle *gc;
  7973. int i;
  7974. for(i=0;i<MAX_GUILDCASTLE;i++){
  7975. if( (gc=guild_castle_search(i)) != NULL ){
  7976. if(strcmp(mapname,gc->map_name)==0){
  7977. // Save Data byself First
  7978. switch(index){
  7979. case 1: gc->guild_id = value; break;
  7980. case 2: gc->economy = value; break;
  7981. case 3: gc->defense = value; break;
  7982. case 4: gc->triggerE = value; break;
  7983. case 5: gc->triggerD = value; break;
  7984. case 6: gc->nextTime = value; break;
  7985. case 7: gc->payTime = value; break;
  7986. case 8: gc->createTime = value; break;
  7987. case 9: gc->visibleC = value; break;
  7988. case 10:
  7989. case 11:
  7990. case 12:
  7991. case 13:
  7992. case 14:
  7993. case 15:
  7994. case 16:
  7995. case 17:
  7996. gc->guardian[index-10].visible = value; break;
  7997. case 18:
  7998. case 19:
  7999. case 20:
  8000. case 21:
  8001. case 22:
  8002. case 23:
  8003. case 24:
  8004. case 25:
  8005. gc->guardian[index-18].hp = value;
  8006. if (gc->guardian[index-18].id)
  8007. { //Update this mob's HP.
  8008. struct block_list *bl = map_id2bl(gc->guardian[index-18].id);
  8009. if (!bl)
  8010. { //Wrong target?
  8011. gc->guardian[index-18].id = 0;
  8012. break;
  8013. }
  8014. if (value < 1) {
  8015. status_kill(bl);
  8016. break;
  8017. }
  8018. status_set_hp(bl, value, 0);
  8019. }
  8020. break;
  8021. default: return 0;
  8022. }
  8023. guild_castledatasave(gc->castle_id,index,value);
  8024. return 0;
  8025. }
  8026. }
  8027. }
  8028. return 0;
  8029. }
  8030. /* =====================================================================
  8031. * ギルド情報を要求する
  8032. * ---------------------------------------------------------------------
  8033. */
  8034. int buildin_requestguildinfo(struct script_state *st)
  8035. {
  8036. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8037. char *event=NULL;
  8038. if( st->end>st->start+3 ){
  8039. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8040. check_event(st, event);
  8041. }
  8042. if(guild_id>0)
  8043. guild_npc_request_info(guild_id,event);
  8044. return 0;
  8045. }
  8046. /* =====================================================================
  8047. * カードの数を得る
  8048. * ---------------------------------------------------------------------
  8049. */
  8050. int buildin_getequipcardcnt(struct script_state *st)
  8051. {
  8052. int i,num;
  8053. struct map_session_data *sd;
  8054. int c=MAX_SLOTS;
  8055. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8056. sd=script_rid2sd(st);
  8057. i=pc_checkequip(sd,equip[num-1]);
  8058. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8059. {
  8060. push_val(st->stack,C_INT,0);
  8061. return 0;
  8062. }
  8063. do{
  8064. if(sd->status.inventory[i].card[c-1] &&
  8065. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8066. push_val(st->stack,C_INT,(c));
  8067. return 0;
  8068. }
  8069. }while(c--);
  8070. push_val(st->stack,C_INT,0);
  8071. return 0;
  8072. }
  8073. /* ================================================================
  8074. * カード取り外し成功
  8075. * ----------------------------------------------------------------
  8076. */
  8077. int buildin_successremovecards(struct script_state *st)
  8078. {
  8079. int i,j,num,cardflag=0,flag;
  8080. struct map_session_data *sd;
  8081. struct item item_tmp;
  8082. int c=MAX_SLOTS;
  8083. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8084. sd=script_rid2sd(st);
  8085. i=pc_checkequip(sd,equip[num-1]);
  8086. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8087. return 0;
  8088. do{
  8089. if(sd->status.inventory[i].card[c-1] &&
  8090. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8091. cardflag = 1;
  8092. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8093. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8094. item_tmp.attribute=0;
  8095. for (j = 0; j < MAX_SLOTS; j++)
  8096. item_tmp.card[j]=0;
  8097. //Logs items, got from (N)PC scripts [Lupus]
  8098. if(log_config.pick > 0 ) {
  8099. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  8100. }
  8101. //Logs
  8102. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  8103. clif_additem(sd,0,0,flag);
  8104. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8105. }
  8106. }
  8107. }while(c--);
  8108. if(cardflag == 1){ // カードを取り除いたアイテム所得
  8109. flag=0;
  8110. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8111. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8112. item_tmp.attribute=sd->status.inventory[i].attribute;
  8113. //Logs items, got from (N)PC scripts [Lupus]
  8114. if(log_config.pick > 0 ) {
  8115. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8116. }
  8117. //Logs
  8118. for (j = 0; j < MAX_SLOTS; j++)
  8119. item_tmp.card[j]=0;
  8120. pc_delitem(sd,i,1,0);
  8121. //Logs items, got from (N)PC scripts [Lupus]
  8122. if(log_config.pick > 0 ) {
  8123. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  8124. }
  8125. //Logs
  8126. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  8127. clif_additem(sd,0,0,flag);
  8128. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8129. }
  8130. clif_misceffect(&sd->bl,3);
  8131. return 0;
  8132. }
  8133. return 0;
  8134. }
  8135. /* ================================================================
  8136. * カード取り外し失敗 slot,type
  8137. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  8138. * ----------------------------------------------------------------
  8139. */
  8140. int buildin_failedremovecards(struct script_state *st)
  8141. {
  8142. int i,j,num,cardflag=0,flag,typefail;
  8143. struct map_session_data *sd;
  8144. struct item item_tmp;
  8145. int c=MAX_SLOTS;
  8146. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8147. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8148. sd=script_rid2sd(st);
  8149. i=pc_checkequip(sd,equip[num-1]);
  8150. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8151. return 0;
  8152. do{
  8153. if(sd->status.inventory[i].card[c-1] &&
  8154. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8155. cardflag = 1;
  8156. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  8157. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8158. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8159. item_tmp.attribute=0;
  8160. for (j = 0; j < MAX_SLOTS; j++)
  8161. item_tmp.card[j]=0;
  8162. //Logs items, got from (N)PC scripts [Lupus]
  8163. if(log_config.pick > 0 ) {
  8164. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  8165. }
  8166. //Logs
  8167. if((flag=pc_additem(sd,&item_tmp,1))){
  8168. clif_additem(sd,0,0,flag);
  8169. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8170. }
  8171. }
  8172. }
  8173. }while(c--);
  8174. if(cardflag == 1){
  8175. if(typefail == 0 || typefail == 2){ // 武具損失
  8176. //Logs items, got from (N)PC scripts [Lupus]
  8177. if(log_config.pick > 0 ) {
  8178. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8179. }
  8180. //Logs
  8181. pc_delitem(sd,i,1,0);
  8182. clif_misceffect(&sd->bl,2);
  8183. return 0;
  8184. }
  8185. if(typefail == 1){ // カードのみ損失(武具を返す)
  8186. flag=0;
  8187. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8188. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8189. item_tmp.attribute=sd->status.inventory[i].attribute;
  8190. //Logs items, got from (N)PC scripts [Lupus]
  8191. if(log_config.pick > 0 ) {
  8192. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8193. }
  8194. //Logs
  8195. for (j = 0; j < MAX_SLOTS; j++)
  8196. item_tmp.card[j]=0;
  8197. pc_delitem(sd,i,1,0);
  8198. //Logs items, got from (N)PC scripts [Lupus]
  8199. if(log_config.pick > 0 ) {
  8200. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  8201. }
  8202. //Logs
  8203. if((flag=pc_additem(sd,&item_tmp,1))){
  8204. clif_additem(sd,0,0,flag);
  8205. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8206. }
  8207. }
  8208. clif_misceffect(&sd->bl,2);
  8209. return 0;
  8210. }
  8211. return 0;
  8212. }
  8213. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  8214. {
  8215. int x,y,m;
  8216. char *str;
  8217. char *mapname;
  8218. unsigned int index;
  8219. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8220. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8221. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8222. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8223. if( (m=map_mapname2mapid(mapname))< 0)
  8224. return 0;
  8225. if(!(index=mapindex_name2id(str)))
  8226. return 0;
  8227. map_foreachinmap(buildin_areawarp_sub,
  8228. m,BL_PC,index,x,y);
  8229. return 0;
  8230. }
  8231. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  8232. {
  8233. char *npc,*command;
  8234. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8235. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8236. npc_command(map_id2sd(st->rid),npc,command);
  8237. return 0;
  8238. }
  8239. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  8240. {
  8241. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8242. // nd->lastaction=nd->timer=gettick();
  8243. npc_do_ontimer(st->oid, 1);
  8244. return 0;
  8245. }
  8246. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  8247. {
  8248. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8249. // nd->lastaction=nd->timer=-1;
  8250. npc_do_ontimer(st->oid, 0);
  8251. return 0;
  8252. }
  8253. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  8254. {
  8255. char *event=va_arg(ap,char *);
  8256. int *c=va_arg(ap,int *);
  8257. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  8258. (*c)++;
  8259. return 0;
  8260. }
  8261. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  8262. {
  8263. char *mapname,*event;
  8264. int m,c=0;
  8265. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8266. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8267. check_event(st, event);
  8268. if( (m=map_mapname2mapid(mapname))<0 ) {
  8269. push_val(st->stack,C_INT,-1);
  8270. return 0;
  8271. }
  8272. map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event,&c );
  8273. push_val(st->stack,C_INT, (c));
  8274. return 0;
  8275. }
  8276. int buildin_marriage(struct script_state *st)
  8277. {
  8278. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8279. struct map_session_data *sd=script_rid2sd(st);
  8280. struct map_session_data *p_sd=map_nick2sd(partner);
  8281. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  8282. push_val(st->stack,C_INT,0);
  8283. return 0;
  8284. }
  8285. push_val(st->stack,C_INT,1);
  8286. return 0;
  8287. }
  8288. int buildin_wedding_effect(struct script_state *st)
  8289. {
  8290. struct map_session_data *sd=script_rid2sd(st);
  8291. struct block_list *bl;
  8292. if(sd==NULL) {
  8293. bl=map_id2bl(st->oid);
  8294. } else
  8295. bl=&sd->bl;
  8296. clif_wedding_effect(bl);
  8297. return 0;
  8298. }
  8299. int buildin_divorce(struct script_state *st)
  8300. {
  8301. struct map_session_data *sd=script_rid2sd(st);
  8302. if(sd==NULL || pc_divorce(sd) < 0){
  8303. push_val(st->stack,C_INT,0);
  8304. return 0;
  8305. }
  8306. push_val(st->stack,C_INT,1);
  8307. return 0;
  8308. }
  8309. int buildin_ispartneron(struct script_state *st)
  8310. {
  8311. struct map_session_data *sd=script_rid2sd(st);
  8312. struct map_session_data *p_sd=NULL;
  8313. if(sd==NULL || !pc_ismarried(sd) ||
  8314. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8315. push_val(st->stack,C_INT,0);
  8316. return 0;
  8317. }
  8318. push_val(st->stack,C_INT,1);
  8319. return 0;
  8320. }
  8321. int buildin_getpartnerid(struct script_state *st)
  8322. {
  8323. struct map_session_data *sd=script_rid2sd(st);
  8324. if (sd == NULL) {
  8325. push_val(st->stack,C_INT,0);
  8326. return 0;
  8327. }
  8328. push_val(st->stack,C_INT,sd->status.partner_id);
  8329. return 0;
  8330. }
  8331. int buildin_getchildid(struct script_state *st)
  8332. {
  8333. struct map_session_data *sd=script_rid2sd(st);
  8334. if (sd == NULL) {
  8335. push_val(st->stack,C_INT,0);
  8336. return 0;
  8337. }
  8338. push_val(st->stack,C_INT,sd->status.child);
  8339. return 0;
  8340. }
  8341. int buildin_getmotherid(struct script_state *st)
  8342. {
  8343. struct map_session_data *sd=script_rid2sd(st);
  8344. if (sd == NULL) {
  8345. push_val(st->stack,C_INT,0);
  8346. return 0;
  8347. }
  8348. push_val(st->stack,C_INT,sd->status.mother);
  8349. return 0;
  8350. }
  8351. int buildin_getfatherid(struct script_state *st)
  8352. {
  8353. struct map_session_data *sd=script_rid2sd(st);
  8354. if (sd == NULL) {
  8355. push_val(st->stack,C_INT,0);
  8356. return 0;
  8357. }
  8358. push_val(st->stack,C_INT,sd->status.father);
  8359. return 0;
  8360. }
  8361. int buildin_warppartner(struct script_state *st)
  8362. {
  8363. int x,y;
  8364. unsigned short mapindex;
  8365. char *str;
  8366. struct map_session_data *sd=script_rid2sd(st);
  8367. struct map_session_data *p_sd=NULL;
  8368. if(sd==NULL || !pc_ismarried(sd) ||
  8369. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8370. push_val(st->stack,C_INT,0);
  8371. return 0;
  8372. }
  8373. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8374. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8375. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8376. mapindex = mapindex_name2id(str);
  8377. if (mapindex) {
  8378. pc_setpos(p_sd,mapindex,x,y,0);
  8379. push_val(st->stack,C_INT,1);
  8380. } else
  8381. push_val(st->stack,C_INT,0);
  8382. return 0;
  8383. }
  8384. /*================================================
  8385. * Script for Displaying MOB Information [Valaris]
  8386. *------------------------------------------------
  8387. */
  8388. int buildin_strmobinfo(struct script_state *st)
  8389. {
  8390. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8391. int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8392. if((class_>=0 && class_<=1000) || class_ >2000)
  8393. return 0;
  8394. switch (num) {
  8395. case 1:
  8396. push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->name);
  8397. break;
  8398. case 2:
  8399. push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->jname);
  8400. break;
  8401. case 3:
  8402. push_val(st->stack,C_INT,mob_db(class_)->lv);
  8403. break;
  8404. case 4:
  8405. push_val(st->stack,C_INT,mob_db(class_)->status.max_hp);
  8406. break;
  8407. case 5:
  8408. push_val(st->stack,C_INT,mob_db(class_)->status.max_sp);
  8409. break;
  8410. case 6:
  8411. push_val(st->stack,C_INT,mob_db(class_)->base_exp);
  8412. break;
  8413. case 7:
  8414. push_val(st->stack,C_INT,mob_db(class_)->job_exp);
  8415. break;
  8416. }
  8417. return 0;
  8418. }
  8419. /*==========================================
  8420. * Summon guardians [Valaris]
  8421. *------------------------------------------
  8422. */
  8423. int buildin_guardian(struct script_state *st)
  8424. {
  8425. int class_=0,amount=1,x=0,y=0,guardian=0;
  8426. char *str,*map,*event="";
  8427. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  8428. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  8429. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  8430. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  8431. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8432. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  8433. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  8434. if( st->end>st->start+9 )
  8435. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  8436. check_event(st, event);
  8437. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
  8438. return 0;
  8439. }
  8440. /*================================================
  8441. * Script for Displaying Guardian Info [Valaris]
  8442. *------------------------------------------------
  8443. */
  8444. int buildin_guardianinfo(struct script_state *st)
  8445. {
  8446. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8447. struct map_session_data *sd=script_rid2sd(st);
  8448. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  8449. if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
  8450. {
  8451. push_val(st->stack,C_INT,-1);
  8452. return 0;
  8453. }
  8454. if(gc->guardian[guardian].visible)
  8455. push_val(st->stack,C_INT,gc->guardian[guardian].hp);
  8456. else push_val(st->stack,C_INT,-1);
  8457. return 0;
  8458. }
  8459. /*==========================================
  8460. * IDからItem名
  8461. *------------------------------------------
  8462. */
  8463. int buildin_getitemname(struct script_state *st)
  8464. {
  8465. int item_id=0;
  8466. struct item_data *i_data;
  8467. char *item_name;
  8468. struct script_data *data;
  8469. data=&(st->stack->stack_data[st->start+2]);
  8470. get_val(st,data);
  8471. if( data->type==C_STR || data->type==C_CONSTSTR ){
  8472. const char *name=conv_str(st,data);
  8473. struct item_data *item_data = itemdb_searchname(name);
  8474. if( item_data )
  8475. item_id=item_data->nameid;
  8476. }else
  8477. item_id=conv_num(st,data);
  8478. i_data = itemdb_exists(item_id);
  8479. if (i_data == NULL)
  8480. {
  8481. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  8482. return 0;
  8483. }
  8484. item_name=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  8485. memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
  8486. push_str(st->stack,C_STR,(unsigned char *) item_name);
  8487. return 0;
  8488. }
  8489. /*==========================================
  8490. * Returns number of slots an item has. [Skotlex]
  8491. *------------------------------------------
  8492. */
  8493. int buildin_getitemslots(struct script_state *st)
  8494. {
  8495. int item_id;
  8496. struct item_data *i_data;
  8497. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8498. i_data = itemdb_exists(item_id);
  8499. if (i_data)
  8500. push_val(st->stack,C_INT,i_data->slot);
  8501. else
  8502. push_val(st->stack,C_INT,-1);
  8503. return 0;
  8504. }
  8505. /*==========================================
  8506. * Returns some values of an item [Lupus]
  8507. * Price, Weight, etc...
  8508. getiteminfo(itemID,n), where n
  8509. 0 value_buy;
  8510. 1 value_sell;
  8511. 2 type;
  8512. 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
  8513. if = 0, then monsters don't drop it at all (rare or a quest item)
  8514. if = 10000, then this item is sold in NPC shops only
  8515. 4 sex;
  8516. 5 equip;
  8517. 6 weight;
  8518. 7 atk;
  8519. 8 def;
  8520. 9 range;
  8521. 10 slot;
  8522. 11 look;
  8523. 12 elv;
  8524. 13 wlv;
  8525. *------------------------------------------
  8526. */
  8527. int buildin_getiteminfo(struct script_state *st)
  8528. {
  8529. int item_id,n;
  8530. int *item_arr;
  8531. struct item_data *i_data;
  8532. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8533. n = conv_num(st,& (st->stack->stack_data[st->start+3]));
  8534. i_data = itemdb_exists(item_id);
  8535. if (i_data && n>=0 && n<14) {
  8536. item_arr = (int*)&i_data->value_buy;
  8537. push_val(st->stack,C_INT,item_arr[n]);
  8538. } else
  8539. push_val(st->stack,C_INT,-1);
  8540. return 0;
  8541. }
  8542. /*==========================================
  8543. * Returns value from equipped item slot n [Lupus]
  8544. getequipcardid(num,slot)
  8545. where
  8546. num = eqip position slot
  8547. slot = 0,1,2,3 (Card Slot N)
  8548. This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
  8549. it's useful when you want to check item cards or if it's signed
  8550. Useful for such quests as "Sign this refined item with players name" etc
  8551. Hat[0] +4 -> Player's Hat[0] +4
  8552. *------------------------------------------
  8553. */
  8554. int buildin_getequipcardid(struct script_state *st)
  8555. {
  8556. int i,num,slot;
  8557. struct map_session_data *sd;
  8558. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8559. slot=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8560. sd=script_rid2sd(st);
  8561. i=pc_checkequip(sd,equip[num-1]);
  8562. if(i >= 0 && slot>=0 && slot<4)
  8563. push_val(st->stack,C_INT,sd->status.inventory[i].card[slot]);
  8564. else
  8565. push_val(st->stack,C_INT,0);
  8566. return 0;
  8567. }
  8568. /*==========================================
  8569. * petskillbonus [Valaris] //Rewritten by [Skotlex]
  8570. *------------------------------------------
  8571. */
  8572. int buildin_petskillbonus(struct script_state *st)
  8573. {
  8574. struct pet_data *pd;
  8575. struct map_session_data *sd=script_rid2sd(st);
  8576. if(sd==NULL || sd->pd==NULL)
  8577. return 0;
  8578. pd=sd->pd;
  8579. if (pd->bonus)
  8580. { //Clear previous bonus
  8581. if (pd->bonus->timer != -1)
  8582. delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
  8583. } else //init
  8584. pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
  8585. pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8586. pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8587. pd->bonus->duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8588. pd->bonus->delay=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8589. if (pd->state.skillbonus == 1)
  8590. pd->state.skillbonus=0; // waiting state
  8591. // wait for timer to start
  8592. if (battle_config.pet_equip_required && pd->equip == 0)
  8593. pd->bonus->timer=-1;
  8594. else
  8595. pd->bonus->timer=add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
  8596. return 0;
  8597. }
  8598. /*==========================================
  8599. * pet looting [Valaris] //Rewritten by [Skotlex]
  8600. *------------------------------------------
  8601. */
  8602. int buildin_petloot(struct script_state *st)
  8603. {
  8604. int max;
  8605. struct pet_data *pd;
  8606. struct map_session_data *sd=script_rid2sd(st);
  8607. if(sd==NULL || sd->pd==NULL)
  8608. return 0;
  8609. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8610. if(max < 1)
  8611. max = 1; //Let'em loot at least 1 item.
  8612. else if (max > MAX_PETLOOT_SIZE)
  8613. max = MAX_PETLOOT_SIZE;
  8614. pd = sd->pd;
  8615. if (pd->loot != NULL)
  8616. { //Release whatever was there already and reallocate memory
  8617. pet_lootitem_drop(pd, pd->msd);
  8618. aFree(pd->loot->item);
  8619. }
  8620. else
  8621. pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
  8622. pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
  8623. pd->loot->max=max;
  8624. pd->loot->count = 0;
  8625. pd->loot->weight = 0;
  8626. return 0;
  8627. }
  8628. /*==========================================
  8629. * PCの所持品情報読み取り
  8630. *------------------------------------------
  8631. */
  8632. int buildin_getinventorylist(struct script_state *st)
  8633. {
  8634. struct map_session_data *sd=script_rid2sd(st);
  8635. unsigned char card_var[NAME_LENGTH];
  8636. int i,j=0,k;
  8637. if(!sd) return 0;
  8638. for(i=0;i<MAX_INVENTORY;i++){
  8639. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  8640. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  8641. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  8642. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  8643. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  8644. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  8645. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  8646. for (k = 0; k < MAX_SLOTS; k++)
  8647. {
  8648. sprintf(card_var, "@inventorylist_card%d",k+1);
  8649. pc_setreg(sd,add_str(card_var)+(j<<24),sd->status.inventory[i].card[k]);
  8650. }
  8651. j++;
  8652. }
  8653. }
  8654. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_count"),j);
  8655. return 0;
  8656. }
  8657. int buildin_getskilllist(struct script_state *st)
  8658. {
  8659. struct map_session_data *sd=script_rid2sd(st);
  8660. int i,j=0;
  8661. if(!sd) return 0;
  8662. for(i=0;i<MAX_SKILL;i++){
  8663. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  8664. pc_setreg(sd,add_str((unsigned char *) "@skilllist_id")+(j<<24),sd->status.skill[i].id);
  8665. pc_setreg(sd,add_str((unsigned char *)"@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  8666. pc_setreg(sd,add_str((unsigned char *)"@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  8667. j++;
  8668. }
  8669. }
  8670. pc_setreg(sd,add_str((unsigned char *) "@skilllist_count"),j);
  8671. return 0;
  8672. }
  8673. int buildin_clearitem(struct script_state *st)
  8674. {
  8675. struct map_session_data *sd=script_rid2sd(st);
  8676. int i;
  8677. if(sd==NULL) return 0;
  8678. for (i=0; i<MAX_INVENTORY; i++) {
  8679. if (sd->status.inventory[i].amount) {
  8680. //Logs items, got from (N)PC scripts [Lupus]
  8681. if(log_config.pick > 0 ) {
  8682. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  8683. }
  8684. //Logs
  8685. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  8686. }
  8687. }
  8688. return 0;
  8689. }
  8690. /*==========================================
  8691. Disguise Player (returns Mob/NPC ID if success, 0 on fail) [Lupus]
  8692. *------------------------------------------
  8693. */
  8694. int buildin_disguise(struct script_state *st)
  8695. {
  8696. struct map_session_data *sd=script_rid2sd(st);
  8697. int id;
  8698. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8699. if (!mobdb_checkid(id) && !npcdb_checkid(id)) {
  8700. push_val(st->stack,C_INT,0);
  8701. return 0;
  8702. }
  8703. pc_disguise(sd, id);
  8704. push_val(st->stack,C_INT,id);
  8705. return 0;
  8706. }
  8707. /*==========================================
  8708. Undisguise Player (returns 1 if success, 0 on fail) [Lupus]
  8709. *------------------------------------------
  8710. */
  8711. int buildin_undisguise(struct script_state *st)
  8712. {
  8713. struct map_session_data *sd=script_rid2sd(st);
  8714. if (sd->disguise) {
  8715. pc_disguise(sd, 0);
  8716. push_val(st->stack,C_INT,0);
  8717. } else {
  8718. push_val(st->stack,C_INT,1);
  8719. }
  8720. return 0;
  8721. }
  8722. /*==========================================
  8723. * NPCクラスチェンジ
  8724. * classは変わりたいclass
  8725. * typeは通常0なのかな?
  8726. *------------------------------------------
  8727. */
  8728. int buildin_classchange(struct script_state *st)
  8729. {
  8730. int _class,type;
  8731. struct block_list *bl=map_id2bl(st->oid);
  8732. if(bl==NULL) return 0;
  8733. _class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8734. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8735. clif_class_change(bl,_class,type);
  8736. return 0;
  8737. }
  8738. /*==========================================
  8739. * NPCから発生するエフェクト
  8740. *------------------------------------------
  8741. */
  8742. int buildin_misceffect(struct script_state *st)
  8743. {
  8744. int type;
  8745. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8746. if(st->oid) {
  8747. struct block_list *bl = map_id2bl(st->oid);
  8748. if (bl)
  8749. clif_misceffect2(bl,type);
  8750. } else{
  8751. struct map_session_data *sd=script_rid2sd(st);
  8752. if(sd)
  8753. clif_misceffect2(&sd->bl,type);
  8754. }
  8755. return 0;
  8756. }
  8757. /*==========================================
  8758. * サウンドエフェクト
  8759. *------------------------------------------
  8760. */
  8761. int buildin_soundeffect(struct script_state *st)
  8762. {
  8763. // Redundn
  8764. struct map_session_data *sd=script_rid2sd(st);
  8765. char *name;
  8766. int type=0;
  8767. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8768. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8769. if(sd){
  8770. if(!st->rid)
  8771. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  8772. else{
  8773. clif_soundeffect(sd,&sd->bl,name,type);
  8774. }
  8775. }
  8776. return 0;
  8777. }
  8778. int soundeffect_sub(struct block_list* bl,va_list ap)
  8779. {
  8780. char *name;
  8781. int type;
  8782. nullpo_retr(0, bl);
  8783. nullpo_retr(0, ap);
  8784. name = va_arg(ap,char *);
  8785. type = va_arg(ap,int);
  8786. clif_soundeffect((struct map_session_data *)bl, bl, name, type);
  8787. return 0;
  8788. }
  8789. int buildin_soundeffectall(struct script_state *st)
  8790. {
  8791. // [Lance] - Improved.
  8792. char *name, *map = NULL;
  8793. struct block_list *bl;
  8794. int type, coverage, x0, y0, x1, y1;
  8795. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8796. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8797. coverage=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8798. if(!st->rid)
  8799. bl = map_id2bl(st->oid);
  8800. else
  8801. bl = &(script_rid2sd(st)->bl);
  8802. if(bl){
  8803. if(coverage < 23){
  8804. clif_soundeffectall(bl,name,type,coverage);
  8805. }else {
  8806. if(st->end > st->start+9){
  8807. map=conv_str(st,& (st->stack->stack_data[st->start+5]));
  8808. x0 = conv_num(st,& (st->stack->stack_data[st->start+6]));
  8809. y0 = conv_num(st,& (st->stack->stack_data[st->start+7]));
  8810. x1 = conv_num(st,& (st->stack->stack_data[st->start+8]));
  8811. y1 = conv_num(st,& (st->stack->stack_data[st->start+9]));
  8812. map_foreachinarea(soundeffect_sub,map_mapname2mapid(map),x0,y0,x1,y1,BL_PC,name,type);
  8813. } else {
  8814. ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
  8815. }
  8816. }
  8817. }
  8818. return 0;
  8819. }
  8820. /*==========================================
  8821. * pet status recovery [Valaris] / Rewritten by [Skotlex]
  8822. *------------------------------------------
  8823. */
  8824. int buildin_petrecovery(struct script_state *st)
  8825. {
  8826. struct pet_data *pd;
  8827. struct map_session_data *sd=script_rid2sd(st);
  8828. if(sd==NULL || sd->pd==NULL)
  8829. return 0;
  8830. pd=sd->pd;
  8831. if (pd->recovery)
  8832. { //Halt previous bonus
  8833. if (pd->recovery->timer != -1)
  8834. delete_timer(pd->recovery->timer, pet_recovery_timer);
  8835. } else //Init
  8836. pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
  8837. pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8838. pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8839. pd->recovery->timer=-1;
  8840. return 0;
  8841. }
  8842. /*==========================================
  8843. * pet healing [Valaris] //Rewritten by [Skotlex]
  8844. *------------------------------------------
  8845. */
  8846. int buildin_petheal(struct script_state *st)
  8847. {
  8848. struct pet_data *pd;
  8849. struct map_session_data *sd=script_rid2sd(st);
  8850. if(sd==NULL || sd->pd==NULL)
  8851. return 0;
  8852. pd=sd->pd;
  8853. if (pd->s_skill)
  8854. { //Clear previous skill
  8855. if (pd->s_skill->timer != -1)
  8856. {
  8857. if (pd->s_skill->id)
  8858. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  8859. else
  8860. delete_timer(pd->s_skill->timer, pet_heal_timer);
  8861. }
  8862. } else //init memory
  8863. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  8864. pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
  8865. //Use the lv as the amount to heal
  8866. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8867. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8868. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8869. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8870. //Use delay as initial offset to avoid skill/heal exploits
  8871. if (battle_config.pet_equip_required && pd->equip == 0)
  8872. pd->s_skill->timer=-1;
  8873. else
  8874. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
  8875. return 0;
  8876. }
  8877. /*==========================================
  8878. * pet attack skills [Valaris] //Rewritten by [Skotlex]
  8879. *------------------------------------------
  8880. */
  8881. int buildin_petskillattack(struct script_state *st)
  8882. {
  8883. struct pet_data *pd;
  8884. struct map_session_data *sd=script_rid2sd(st);
  8885. if(sd==NULL || sd->pd==NULL)
  8886. return 0;
  8887. pd=sd->pd;
  8888. if (pd->a_skill == NULL)
  8889. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  8890. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8891. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8892. pd->a_skill->div_ = 0;
  8893. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8894. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8895. return 0;
  8896. }
  8897. /*==========================================
  8898. * pet attack skills [Valaris]
  8899. *------------------------------------------
  8900. */
  8901. int buildin_petskillattack2(struct script_state *st)
  8902. {
  8903. struct pet_data *pd;
  8904. struct map_session_data *sd=script_rid2sd(st);
  8905. if(sd==NULL || sd->pd==NULL)
  8906. return 0;
  8907. pd=sd->pd;
  8908. if (pd->a_skill == NULL)
  8909. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  8910. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8911. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8912. pd->a_skill->div_ = conv_num(st,& (st->stack->stack_data[st->start+4]));
  8913. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8914. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8915. return 0;
  8916. }
  8917. /*==========================================
  8918. * pet support skills [Skotlex]
  8919. *------------------------------------------
  8920. */
  8921. int buildin_petskillsupport(struct script_state *st)
  8922. {
  8923. struct pet_data *pd;
  8924. struct map_session_data *sd=script_rid2sd(st);
  8925. if(sd==NULL || sd->pd==NULL)
  8926. return 0;
  8927. pd=sd->pd;
  8928. if (pd->s_skill)
  8929. { //Clear previous skill
  8930. if (pd->s_skill->timer != -1)
  8931. {
  8932. if (pd->s_skill->id)
  8933. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  8934. else
  8935. delete_timer(pd->s_skill->timer, pet_heal_timer);
  8936. }
  8937. } else //init memory
  8938. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  8939. pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8940. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8941. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8942. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8943. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8944. //Use delay as initial offset to avoid skill/heal exploits
  8945. if (battle_config.pet_equip_required && pd->equip == 0)
  8946. pd->s_skill->timer=-1;
  8947. else
  8948. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
  8949. return 0;
  8950. }
  8951. /*==========================================
  8952. * Scripted skill effects [Celest]
  8953. *------------------------------------------
  8954. */
  8955. int buildin_skilleffect(struct script_state *st)
  8956. {
  8957. struct map_session_data *sd;
  8958. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8959. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8960. sd=script_rid2sd(st);
  8961. clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
  8962. return 0;
  8963. }
  8964. /*==========================================
  8965. * NPC skill effects [Valaris]
  8966. *------------------------------------------
  8967. */
  8968. int buildin_npcskilleffect(struct script_state *st)
  8969. {
  8970. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  8971. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8972. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8973. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8974. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8975. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  8976. return 0;
  8977. }
  8978. /*==========================================
  8979. * Special effects [Valaris]
  8980. *------------------------------------------
  8981. */
  8982. int buildin_specialeffect(struct script_state *st)
  8983. {
  8984. struct block_list *bl=map_id2bl(st->oid);
  8985. if(bl==NULL)
  8986. return 0;
  8987. clif_specialeffect(bl,conv_num(st,& (st->stack->stack_data[st->start+2])), ((st->end > st->start+3)?conv_num(st,& (st->stack->stack_data[st->start+3])):AREA));
  8988. return 0;
  8989. }
  8990. int buildin_specialeffect2(struct script_state *st)
  8991. {
  8992. struct map_session_data *sd=script_rid2sd(st);
  8993. if(sd==NULL)
  8994. return 0;
  8995. clif_specialeffect(&sd->bl,conv_num(st,& (st->stack->stack_data[st->start+2])), ((st->end > st->start+3)?conv_num(st,& (st->stack->stack_data[st->start+3])):AREA));
  8996. return 0;
  8997. }
  8998. /*==========================================
  8999. * Nude [Valaris]
  9000. *------------------------------------------
  9001. */
  9002. int buildin_nude(struct script_state *st)
  9003. {
  9004. struct map_session_data *sd=script_rid2sd(st);
  9005. int i,calcflag=0;
  9006. if(sd==NULL)
  9007. return 0;
  9008. for(i=0;i<11;i++)
  9009. if(sd->equip_index[i] >= 0) {
  9010. if(!calcflag)
  9011. calcflag=1;
  9012. pc_unequipitem(sd,sd->equip_index[i],2);
  9013. }
  9014. if(calcflag)
  9015. status_calc_pc(sd,0);
  9016. return 0;
  9017. }
  9018. /*==========================================
  9019. * gmcommand [MouseJstr]
  9020. *
  9021. * suggested on the forums...
  9022. * splitted into atcommand & charcommand by [Skotlex]
  9023. *------------------------------------------
  9024. */
  9025. int buildin_atcommand(struct script_state *st)
  9026. {
  9027. struct map_session_data *sd=NULL;
  9028. char *cmd;
  9029. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9030. if (st->rid)
  9031. sd = script_rid2sd(st);
  9032. if (sd) is_atcommand(sd->fd, sd, cmd, 99);
  9033. else { //Use a dummy character.
  9034. struct map_session_data dummy_sd;
  9035. struct block_list *bl = NULL;
  9036. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  9037. if (st->oid) bl = map_id2bl(st->oid);
  9038. if (bl) {
  9039. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9040. if (bl->type == BL_NPC)
  9041. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9042. }
  9043. is_atcommand(0, &dummy_sd, cmd, 99);
  9044. }
  9045. return 0;
  9046. }
  9047. int buildin_charcommand(struct script_state *st)
  9048. {
  9049. struct map_session_data *sd=NULL;
  9050. char *cmd;
  9051. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9052. if (st->rid)
  9053. sd = script_rid2sd(st);
  9054. if (sd) is_charcommand(sd->fd, sd, cmd, 99);
  9055. else { //Use a dummy character.
  9056. struct map_session_data dummy_sd;
  9057. struct block_list *bl = NULL;
  9058. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  9059. if (st->oid) bl = map_id2bl(st->oid);
  9060. if (bl) {
  9061. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9062. if (bl->type == BL_NPC)
  9063. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9064. }
  9065. is_charcommand(0, &dummy_sd, cmd, 99);
  9066. }
  9067. return 0;
  9068. }
  9069. /*==========================================
  9070. * Displays a message for the player only (like system messages like "you got an apple" )
  9071. *------------------------------------------
  9072. */
  9073. int buildin_dispbottom(struct script_state *st)
  9074. {
  9075. struct map_session_data *sd=script_rid2sd(st);
  9076. char *message;
  9077. message=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9078. if(sd)
  9079. clif_disp_onlyself(sd,message,(int)strlen(message));
  9080. return 0;
  9081. }
  9082. /*==========================================
  9083. * All The Players Full Recovery
  9084. (HP/SP full restore and resurrect if need)
  9085. *------------------------------------------
  9086. */
  9087. int buildin_recovery(struct script_state *st)
  9088. {
  9089. struct map_session_data *sd, **all_sd;
  9090. int i = 0, users;
  9091. all_sd = map_getallusers(&users);
  9092. for (i = 0; i < users; i++)
  9093. {
  9094. sd = all_sd[i];
  9095. if(pc_isdead(sd))
  9096. status_revive(&sd->bl, 100, 100);
  9097. else
  9098. status_percent_heal(&sd->bl, 100, 100);
  9099. clif_displaymessage(sd->fd,"You have been recovered!");
  9100. }
  9101. return 0;
  9102. }
  9103. /*==========================================
  9104. * Get your pet info: getpetinfo(n)
  9105. * n -> 0:pet_id 1:pet_class 2:pet_name
  9106. 3:friendly 4:hungry
  9107. *------------------------------------------
  9108. */
  9109. int buildin_getpetinfo(struct script_state *st)
  9110. {
  9111. struct map_session_data *sd=script_rid2sd(st);
  9112. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9113. if(sd && sd->status.pet_id){
  9114. switch(type){
  9115. case 0:
  9116. push_val(st->stack,C_INT,sd->status.pet_id);
  9117. break;
  9118. case 1:
  9119. push_val(st->stack,C_INT,sd->pet.class_);
  9120. break;
  9121. case 2:
  9122. if(sd->pet.name)
  9123. {
  9124. push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->pet.name);
  9125. }
  9126. else
  9127. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  9128. break;
  9129. case 3:
  9130. //if(sd->pet.intimate)
  9131. push_val(st->stack,C_INT,sd->pet.intimate);
  9132. break;
  9133. case 4:
  9134. //if(sd->pet.hungry)
  9135. push_val(st->stack,C_INT,sd->pet.hungry);
  9136. break;
  9137. default:
  9138. push_val(st->stack,C_INT,0);
  9139. break;
  9140. }
  9141. }else{
  9142. push_val(st->stack,C_INT,0);
  9143. }
  9144. return 0;
  9145. }
  9146. /*==========================================
  9147. * Shows wether your inventory(and equips) contain
  9148. selected card or not.
  9149. checkequipedcard(4001);
  9150. *------------------------------------------
  9151. */
  9152. int buildin_checkequipedcard(struct script_state *st)
  9153. {
  9154. struct map_session_data *sd=script_rid2sd(st);
  9155. int n,i,c=0;
  9156. c=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9157. if(sd){
  9158. for(i=0;i<MAX_INVENTORY;i++){
  9159. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount){
  9160. for(n=0;n<MAX_SLOTS;n++){
  9161. if(sd->status.inventory[i].card[n]==c){
  9162. push_val(st->stack,C_INT,1);
  9163. return 0;
  9164. }
  9165. }
  9166. }
  9167. }
  9168. }
  9169. push_val(st->stack,C_INT,0);
  9170. return 0;
  9171. }
  9172. int buildin_jump_zero(struct script_state *st) {
  9173. int sel;
  9174. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9175. if(!sel) {
  9176. int pos;
  9177. if( st->stack->stack_data[st->start+3].type!=C_POS ){
  9178. ShowError("script: jump_zero: not label !\n");
  9179. st->state=END;
  9180. return 0;
  9181. }
  9182. pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9183. st->pos=pos;
  9184. st->state=GOTO;
  9185. // printf("script: jump_zero: jumpto : %d\n",pos);
  9186. } else {
  9187. // printf("script: jump_zero: fail\n");
  9188. }
  9189. return 0;
  9190. }
  9191. int buildin_select(struct script_state *st)
  9192. {
  9193. char *buf;
  9194. int len,i;
  9195. struct map_session_data *sd;
  9196. sd=script_rid2sd(st);
  9197. if(sd->state.menu_or_input==0){
  9198. st->state=RERUNLINE;
  9199. sd->state.menu_or_input=1;
  9200. for(i=st->start+2,len=16;i<st->end;i++){
  9201. conv_str(st,& (st->stack->stack_data[i]));
  9202. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  9203. }
  9204. buf=(char *)aMalloc((len+1)*sizeof(char));
  9205. buf[0]=0;
  9206. for(i=st->start+2,len=0;i<st->end;i++){
  9207. strcat(buf,st->stack->stack_data[i].u.str);
  9208. strcat(buf,":");
  9209. }
  9210. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  9211. aFree(buf);
  9212. } else if(sd->npc_menu==0xff){ // cansel
  9213. sd->state.menu_or_input=0;
  9214. st->state=END;
  9215. } else {
  9216. // pc_setreg(sd,add_str((unsigned char *) "l15"),sd->npc_menu);
  9217. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  9218. sd->state.menu_or_input=0;
  9219. push_val(st->stack,C_INT,sd->npc_menu);
  9220. }
  9221. return 0;
  9222. }
  9223. /*==========================================
  9224. * GetMapMobs
  9225. returns mob counts on a set map:
  9226. e.g. GetMapMobs("prontera.gat")
  9227. use "this" - for player's map
  9228. *------------------------------------------
  9229. */
  9230. int buildin_getmapmobs(struct script_state *st)
  9231. {
  9232. char *str=NULL;
  9233. int m=-1,bx,by,i;
  9234. int count=0,c;
  9235. struct block_list *bl;
  9236. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9237. if(strcmp(str,"this")==0){
  9238. struct map_session_data *sd=script_rid2sd(st);
  9239. if(sd)
  9240. m=sd->bl.m;
  9241. else{
  9242. push_val(st->stack,C_INT,-1);
  9243. return 0;
  9244. }
  9245. }else
  9246. m=map_mapname2mapid(str);
  9247. if(m < 0){
  9248. push_val(st->stack,C_INT,-1);
  9249. return 0;
  9250. }
  9251. for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++){
  9252. for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++){
  9253. bl = map[m].block_mob[bx+by*map[m].bxs];
  9254. c = map[m].block_mob_count[bx+by*map[m].bxs];
  9255. for(i=0;i<c && bl;i++,bl=bl->next){
  9256. if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
  9257. count++;
  9258. }
  9259. }
  9260. }
  9261. push_val(st->stack,C_INT,count);
  9262. return 0;
  9263. }
  9264. /*==========================================
  9265. * movenpc [MouseJstr]
  9266. *------------------------------------------
  9267. */
  9268. int buildin_movenpc(struct script_state *st)
  9269. {
  9270. TBL_NPC *nd = NULL;
  9271. char *npc;
  9272. int x,y;
  9273. short m;
  9274. npc = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9275. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  9276. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9277. if ((nd = npc_name2id(npc)) == NULL)
  9278. return -1;
  9279. if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  9280. return -1; //Not on a map.
  9281. if (x < 0) x = 0;
  9282. else if (x >= map[m].xs) x = map[m].xs-1;
  9283. if (y < 0) y = 0;
  9284. else if (y >= map[m].ys) y = map[m].ys-1;
  9285. map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9286. map_moveblock(&nd->bl, x, y, gettick());
  9287. map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9288. return 0;
  9289. }
  9290. /*==========================================
  9291. * message [MouseJstr]
  9292. *------------------------------------------
  9293. */
  9294. int buildin_message(struct script_state *st)
  9295. {
  9296. struct map_session_data *sd;
  9297. char *msg,*player;
  9298. struct map_session_data *pl_sd = NULL;
  9299. sd = script_rid2sd(st);
  9300. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9301. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9302. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  9303. return 0;
  9304. clif_displaymessage(pl_sd->fd, msg);
  9305. return 0;
  9306. }
  9307. /*==========================================
  9308. * npctalk (sends message to surrounding
  9309. * area) [Valaris]
  9310. *------------------------------------------
  9311. */
  9312. int buildin_npctalk(struct script_state *st)
  9313. {
  9314. char *str;
  9315. char message[255];
  9316. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9317. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9318. if(nd) {
  9319. memcpy(message, nd->name, NAME_LENGTH);
  9320. strcat(message," : ");
  9321. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  9322. clif_message(&(nd->bl), message);
  9323. }
  9324. return 0;
  9325. }
  9326. /*==========================================
  9327. * hasitems (checks to see if player has any
  9328. * items on them, if so will return a 1)
  9329. * [Valaris]
  9330. *------------------------------------------
  9331. */
  9332. int buildin_hasitems(struct script_state *st)
  9333. {
  9334. int i;
  9335. struct map_session_data *sd;
  9336. sd=script_rid2sd(st);
  9337. for(i=0; i<MAX_INVENTORY; i++) {
  9338. if(sd->status.inventory[i].amount && sd->status.inventory[i].nameid!=2364 && sd->status.inventory[i].nameid!=2365) {
  9339. push_val(st->stack,C_INT,1);
  9340. return 0;
  9341. }
  9342. }
  9343. push_val(st->stack,C_INT,0);
  9344. return 0;
  9345. }
  9346. // change npc walkspeed [Valaris]
  9347. int buildin_npcspeed(struct script_state *st)
  9348. {
  9349. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9350. int x=0;
  9351. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9352. if(nd) {
  9353. nd->speed=x;
  9354. }
  9355. return 0;
  9356. }
  9357. // make an npc walk to a position [Valaris]
  9358. int buildin_npcwalkto(struct script_state *st)
  9359. {
  9360. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9361. int x=0,y=0;
  9362. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9363. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9364. if(nd) {
  9365. unit_walktoxy(&nd->bl,x,y,0);
  9366. }
  9367. return 0;
  9368. }
  9369. // stop an npc's movement [Valaris]
  9370. int buildin_npcstop(struct script_state *st)
  9371. {
  9372. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9373. if(nd) {
  9374. unit_stop_walking(&nd->bl,1);
  9375. }
  9376. return 0;
  9377. }
  9378. /*==========================================
  9379. * getlook char info. getlook(arg)
  9380. *------------------------------------------
  9381. */
  9382. int buildin_getlook(struct script_state *st){
  9383. int type,val;
  9384. struct map_session_data *sd;
  9385. sd=script_rid2sd(st);
  9386. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9387. val=-1;
  9388. switch(type){
  9389. case LOOK_HAIR: //1
  9390. val=sd->status.hair;
  9391. break;
  9392. case LOOK_WEAPON: //2
  9393. val=sd->status.weapon;
  9394. break;
  9395. case LOOK_HEAD_BOTTOM: //3
  9396. val=sd->status.head_bottom;
  9397. break;
  9398. case LOOK_HEAD_TOP: //4
  9399. val=sd->status.head_top;
  9400. break;
  9401. case LOOK_HEAD_MID: //5
  9402. val=sd->status.head_mid;
  9403. break;
  9404. case LOOK_HAIR_COLOR: //6
  9405. val=sd->status.hair_color;
  9406. break;
  9407. case LOOK_CLOTHES_COLOR: //7
  9408. val=sd->status.clothes_color;
  9409. break;
  9410. case LOOK_SHIELD: //8
  9411. val=sd->status.shield;
  9412. break;
  9413. case LOOK_SHOES: //9
  9414. break;
  9415. }
  9416. push_val(st->stack,C_INT,val);
  9417. return 0;
  9418. }
  9419. /*==========================================
  9420. * get char save point. argument: 0- map name, 1- x, 2- y
  9421. *------------------------------------------
  9422. */
  9423. int buildin_getsavepoint(struct script_state *st)
  9424. {
  9425. int x,y,type;
  9426. char *mapname;
  9427. struct map_session_data *sd;
  9428. sd=script_rid2sd(st);
  9429. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9430. x=sd->status.save_point.x;
  9431. y=sd->status.save_point.y;
  9432. switch(type){
  9433. case 0:
  9434. mapname=(char *) aMallocA((MAP_NAME_LENGTH+1)*sizeof(char));
  9435. memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
  9436. mapname[MAP_NAME_LENGTH]='\0';
  9437. push_str(st->stack,C_STR,(unsigned char *) mapname);
  9438. break;
  9439. case 1:
  9440. push_val(st->stack,C_INT,x);
  9441. break;
  9442. case 2:
  9443. push_val(st->stack,C_INT,y);
  9444. break;
  9445. }
  9446. return 0;
  9447. }
  9448. /*==========================================
  9449. * Get position for char/npc/pet/mob objects. Added by Lorky
  9450. *
  9451. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  9452. * where type:
  9453. * MapName$ - String variable for output map name
  9454. * MapX - Integer variable for output coord X
  9455. * MapY - Integer variable for output coord Y
  9456. * type - type of object
  9457. * 0 - Character coord
  9458. * 1 - NPC coord
  9459. * 2 - Pet coord
  9460. * 3 - Mob coord (not released)
  9461. * CharName$ - Name object. If miss or "this" the current object
  9462. *
  9463. * Return:
  9464. * 0 - success
  9465. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  9466. *------------------------------------------
  9467. */
  9468. int buildin_getmapxy(struct script_state *st){
  9469. struct map_session_data *sd=NULL;
  9470. struct npc_data *nd;
  9471. struct pet_data *pd;
  9472. int num;
  9473. char *name;
  9474. char prefix;
  9475. int x,y,type;
  9476. char mapname[MAP_NAME_LENGTH+1];
  9477. memset(mapname, 0, sizeof(mapname));
  9478. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  9479. ShowWarning("script: buildin_getmapxy: not mapname variable\n");
  9480. push_val(st->stack,C_INT,-1);
  9481. return 0;
  9482. }
  9483. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  9484. ShowWarning("script: buildin_getmapxy: not mapx variable\n");
  9485. push_val(st->stack,C_INT,-1);
  9486. return 0;
  9487. }
  9488. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  9489. ShowWarning("script: buildin_getmapxy: not mapy variable\n");
  9490. push_val(st->stack,C_INT,-1);
  9491. return 0;
  9492. }
  9493. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  9494. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9495. switch (type){
  9496. case 0: //Get Character Position
  9497. if( st->end>st->start+6 )
  9498. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9499. else
  9500. sd=script_rid2sd(st);
  9501. if ( sd==NULL ) { //wrong char name or char offline
  9502. push_val(st->stack,C_INT,-1);
  9503. return 0;
  9504. }
  9505. x=sd->bl.x;
  9506. y=sd->bl.y;
  9507. memcpy(mapname,mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  9508. break;
  9509. case 1: //Get NPC Position
  9510. if( st->end > st->start+6 )
  9511. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9512. else
  9513. nd=(struct npc_data *)map_id2bl(st->oid);
  9514. if ( nd==NULL ) { //wrong npc name or char offline
  9515. push_val(st->stack,C_INT,-1);
  9516. return 0;
  9517. }
  9518. x=nd->bl.x;
  9519. y=nd->bl.y;
  9520. memcpy(mapname, map[nd->bl.m].name, MAP_NAME_LENGTH);
  9521. break;
  9522. case 2: //Get Pet Position
  9523. if( st->end>st->start+6 )
  9524. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9525. else
  9526. sd=script_rid2sd(st);
  9527. if ( sd==NULL ) { //wrong char name or char offline
  9528. push_val(st->stack,C_INT,-1);
  9529. return 0;
  9530. }
  9531. pd=sd->pd;
  9532. if(pd==NULL){ //pet data not found
  9533. push_val(st->stack,C_INT,-1);
  9534. return 0;
  9535. }
  9536. x=pd->bl.x;
  9537. y=pd->bl.y;
  9538. memcpy(mapname, map[pd->bl.m].name, MAP_NAME_LENGTH);
  9539. break;
  9540. case 3: //Get Mob Position
  9541. push_val(st->stack,C_INT,-1);
  9542. return 0;
  9543. default: //Wrong type parameter
  9544. push_val(st->stack,C_INT,-1);
  9545. return 0;
  9546. }
  9547. //Set MapName$
  9548. num=st->stack->stack_data[st->start+2].u.num;
  9549. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9550. prefix=*name;
  9551. if(not_server_variable(prefix))
  9552. sd=script_rid2sd(st);
  9553. else
  9554. sd=NULL;
  9555. set_reg(st,sd,num,name,(void*)mapname,st->stack->stack_data[st->start+2].ref);
  9556. //Set MapX
  9557. num=st->stack->stack_data[st->start+3].u.num;
  9558. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9559. prefix=*name;
  9560. if(not_server_variable(prefix))
  9561. sd=script_rid2sd(st);
  9562. else
  9563. sd=NULL;
  9564. set_reg(st,sd,num,name,(void*)x,st->stack->stack_data[st->start+3].ref);
  9565. //Set MapY
  9566. num=st->stack->stack_data[st->start+4].u.num;
  9567. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9568. prefix=*name;
  9569. if(not_server_variable(prefix))
  9570. sd=script_rid2sd(st);
  9571. else
  9572. sd=NULL;
  9573. set_reg(st,sd,num,name,(void*)y,st->stack->stack_data[st->start+4].ref);
  9574. //Return Success value
  9575. push_val(st->stack,C_INT,0);
  9576. return 0;
  9577. }
  9578. /*==========================================
  9579. * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
  9580. *------------------------------------------
  9581. */
  9582. int buildin_logmes(struct script_state *st)
  9583. {
  9584. if (log_config.npc <= 0 ) return 0;
  9585. conv_str(st,& (st->stack->stack_data[st->start+2]));
  9586. log_npc(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str);
  9587. return 0;
  9588. }
  9589. int buildin_summon(struct script_state *st)
  9590. {
  9591. int _class, id, timeout=0;
  9592. char *str,*event="";
  9593. struct map_session_data *sd;
  9594. struct mob_data *md;
  9595. int tick = gettick();
  9596. sd=script_rid2sd(st);
  9597. if (!sd) return 0;
  9598. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  9599. _class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9600. if( st->end>st->start+4 )
  9601. timeout=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9602. if( st->end>st->start+5 ){
  9603. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  9604. check_event(st, event);
  9605. }
  9606. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
  9607. id=mob_once_spawn(sd, "this", 0, 0, str,_class,1,event);
  9608. md=(struct mob_data *)map_id2bl(id);
  9609. if (!md) return 0;
  9610. md->master_id=sd->bl.id;
  9611. md->special_state.ai=1;
  9612. md->deletetimer=add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,id,0);
  9613. clif_misceffect2(&md->bl,344);
  9614. sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  9615. return 0;
  9616. }
  9617. /*==========================================
  9618. * Checks whether it is daytime/nighttime
  9619. *------------------------------------------
  9620. */
  9621. int buildin_isnight(struct script_state *st)
  9622. {
  9623. push_val(st->stack,C_INT, (night_flag == 1));
  9624. return 0;
  9625. }
  9626. int buildin_isday(struct script_state *st)
  9627. {
  9628. push_val(st->stack,C_INT, (night_flag == 0));
  9629. return 0;
  9630. }
  9631. /*================================================
  9632. * Check whether another item/card has been
  9633. * equipped - used for 2/15's cards patch [celest]
  9634. *------------------------------------------------
  9635. */
  9636. // leave this here, just in case
  9637. #if 0
  9638. int buildin_isequipped(struct script_state *st)
  9639. {
  9640. struct map_session_data *sd;
  9641. int i, j, k, id = 1;
  9642. int ret = -1;
  9643. sd = script_rid2sd(st);
  9644. for (i=0; id!=0; i++) {
  9645. int flag = 0;
  9646. FETCH (i+2, id) else id = 0;
  9647. if (id <= 0)
  9648. continue;
  9649. for (j=0; j<EQI_MAX; j++) {
  9650. int index;
  9651. index = sd->equip_index[j];
  9652. if(index < 0) continue;
  9653. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9654. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9655. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9656. if(!sd->inventory_data[index])
  9657. continue;
  9658. if(itemdb_type(id) != IT_CARD) { //Non card
  9659. if (sd->inventory_data[index]->nameid != id)
  9660. continue;
  9661. flag = 1;
  9662. break;
  9663. } else { //Card
  9664. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9665. continue;
  9666. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9667. if (sd->status.inventory[index].card[k] == id)
  9668. {
  9669. flag = 1;
  9670. break;
  9671. }
  9672. }
  9673. }
  9674. if (flag) break;
  9675. }
  9676. if (ret == -1)
  9677. ret = flag;
  9678. else
  9679. ret &= flag;
  9680. if (!ret) break;
  9681. }
  9682. push_val(st->stack,C_INT,ret);
  9683. return 0;
  9684. }
  9685. #endif
  9686. /*================================================
  9687. * Check how many items/cards in the list are
  9688. * equipped - used for 2/15's cards patch [celest]
  9689. *------------------------------------------------
  9690. */
  9691. int buildin_isequippedcnt(struct script_state *st)
  9692. {
  9693. struct map_session_data *sd;
  9694. int i, j, k, id = 1;
  9695. int ret = 0;
  9696. sd = script_rid2sd(st);
  9697. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9698. push_val(st->stack,C_INT,0);
  9699. return 0;
  9700. }
  9701. for (i=0; id!=0; i++) {
  9702. FETCH (i+2, id) else id = 0;
  9703. if (id <= 0)
  9704. continue;
  9705. for (j=0; j<EQI_MAX; j++) {
  9706. int index;
  9707. index = sd->equip_index[j];
  9708. if(index < 0) continue;
  9709. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9710. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9711. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9712. if(!sd->inventory_data[index])
  9713. continue;
  9714. if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
  9715. if (sd->inventory_data[index]->nameid == id)
  9716. ret+= sd->status.inventory[index].amount;
  9717. } else { //Count cards.
  9718. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9719. continue; //No cards
  9720. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9721. if (sd->status.inventory[index].card[k] == id)
  9722. ret++; //[Lupus]
  9723. }
  9724. }
  9725. }
  9726. }
  9727. push_val(st->stack,C_INT,ret);
  9728. return 0;
  9729. }
  9730. /*================================================
  9731. * Check whether another card has been
  9732. * equipped - used for 2/15's cards patch [celest]
  9733. * -- Items checked cannot be reused in another
  9734. * card set to prevent exploits
  9735. *------------------------------------------------
  9736. */
  9737. int buildin_isequipped(struct script_state *st)
  9738. {
  9739. struct map_session_data *sd;
  9740. int i, j, k, id = 1;
  9741. int index, flag;
  9742. int ret = -1;
  9743. sd = script_rid2sd(st);
  9744. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9745. push_val(st->stack,C_INT,0);
  9746. return 0;
  9747. }
  9748. for (i=0; id!=0; i++)
  9749. {
  9750. FETCH (i+2, id) else id = 0;
  9751. if (id <= 0)
  9752. continue;
  9753. flag = 0;
  9754. for (j=0; j<EQI_MAX; j++)
  9755. {
  9756. index = sd->equip_index[j];
  9757. if(index < 0) continue;
  9758. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9759. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9760. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9761. if(!sd->inventory_data[index])
  9762. continue;
  9763. if (itemdb_type(id) != IT_CARD) {
  9764. if (sd->inventory_data[index]->nameid != id)
  9765. continue;
  9766. flag = 1;
  9767. break;
  9768. } else { //Cards
  9769. if (sd->inventory_data[index]->slot == 0 ||
  9770. itemdb_isspecial(sd->status.inventory[index].card[0]))
  9771. continue;
  9772. for (k = 0; k < sd->inventory_data[index]->slot; k++)
  9773. { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
  9774. unsigned int hash = 0;
  9775. if (sd->status.inventory[index].card[k] != id)
  9776. continue;
  9777. hash = 1<<((j<5?j:j-5)*4 + k);
  9778. // check if card is already used by another set
  9779. if ((j<5?sd->setitem_hash:sd->setitem_hash2) & hash)
  9780. continue;
  9781. // We have found a match
  9782. flag = 1;
  9783. // Set hash so this card cannot be used by another
  9784. if (j<5)
  9785. sd->setitem_hash |= hash;
  9786. else
  9787. sd->setitem_hash2 |= hash;
  9788. break;
  9789. }
  9790. }
  9791. if (flag) break; //Card found
  9792. }
  9793. if (ret == -1)
  9794. ret = flag;
  9795. else
  9796. ret &= flag;
  9797. if (!ret) break;
  9798. }
  9799. push_val(st->stack,C_INT,ret);
  9800. return 0;
  9801. }
  9802. /*================================================
  9803. * Check how many given inserted cards in the CURRENT
  9804. * weapon - used for 2/15's cards patch [Lupus]
  9805. *------------------------------------------------
  9806. */
  9807. int buildin_cardscnt(struct script_state *st)
  9808. {
  9809. struct map_session_data *sd;
  9810. int i, k, id = 1;
  9811. int ret = 0;
  9812. int index;
  9813. sd = script_rid2sd(st);
  9814. for (i=0; id!=0; i++) {
  9815. FETCH (i+2, id) else id = 0;
  9816. if (id <= 0)
  9817. continue;
  9818. index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
  9819. if(index < 0) continue;
  9820. if(!sd->inventory_data[index])
  9821. continue;
  9822. if(itemdb_type(id) != IT_CARD) {
  9823. if (sd->inventory_data[index]->nameid == id)
  9824. ret+= sd->status.inventory[index].amount;
  9825. } else {
  9826. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9827. continue;
  9828. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9829. if (sd->status.inventory[index].card[k] == id)
  9830. ret++;
  9831. }
  9832. }
  9833. }
  9834. push_val(st->stack,C_INT,ret);
  9835. // push_val(st->stack,C_INT,current_equip_item_index);
  9836. return 0;
  9837. }
  9838. /*=======================================================
  9839. * Returns the refined number of the current item, or an
  9840. * item with inventory index specified
  9841. *-------------------------------------------------------
  9842. */
  9843. int buildin_getrefine(struct script_state *st)
  9844. {
  9845. struct map_session_data *sd;
  9846. if ((sd = script_rid2sd(st))!= NULL)
  9847. push_val(st->stack, C_INT, sd->status.inventory[current_equip_item_index].refine);
  9848. return 0;
  9849. }
  9850. /*=======================================================
  9851. * Allows 2 Parents to adopt a character as a Baby
  9852. *-------------------------------------------------------
  9853. */
  9854. int buildin_adopt(struct script_state *st)
  9855. {
  9856. int ret;
  9857. char *parent1 = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9858. char *parent2 = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9859. char *child = conv_str(st,& (st->stack->stack_data[st->start+4]));
  9860. struct map_session_data *p1_sd = map_nick2sd(parent1);
  9861. struct map_session_data *p2_sd = map_nick2sd(parent2);
  9862. struct map_session_data *c_sd = map_nick2sd(child);
  9863. if (!p1_sd || !p2_sd || !c_sd ||
  9864. p1_sd->status.base_level < 70 ||
  9865. p2_sd->status.base_level < 70)
  9866. return 0;
  9867. ret = pc_adoption(p1_sd, p2_sd, c_sd);
  9868. push_val(st->stack, C_INT, ret);
  9869. return 0;
  9870. }
  9871. /*=======================================================
  9872. * Day/Night controls
  9873. *-------------------------------------------------------
  9874. */
  9875. int buildin_night(struct script_state *st)
  9876. {
  9877. if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
  9878. return 0;
  9879. }
  9880. int buildin_day(struct script_state *st)
  9881. {
  9882. if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
  9883. return 0;
  9884. }
  9885. //=======================================================
  9886. // Unequip [Spectre]
  9887. //-------------------------------------------------------
  9888. int buildin_unequip(struct script_state *st)
  9889. {
  9890. int i;
  9891. size_t num;
  9892. struct map_session_data *sd;
  9893. num = conv_num(st,& (st->stack->stack_data[st->start+2])) - 1;
  9894. sd=script_rid2sd(st);
  9895. if(sd!=NULL && num<10)
  9896. {
  9897. i=pc_checkequip(sd,equip[num]);
  9898. pc_unequipitem(sd,i,2);
  9899. return 0;
  9900. }
  9901. return 0;
  9902. }
  9903. int buildin_equip(struct script_state *st)
  9904. {
  9905. int nameid=0,i;
  9906. struct map_session_data *sd;
  9907. struct item_data *item_data;
  9908. sd = script_rid2sd(st);
  9909. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9910. if((item_data = itemdb_exists(nameid)) == NULL)
  9911. {
  9912. if(battle_config.error_log)
  9913. ShowError("wrong item ID : equipitem(%i)\n",nameid);
  9914. return 1;
  9915. }
  9916. for(i=0;i<MAX_INVENTORY && sd->status.inventory[i].nameid!=nameid;i++);
  9917. if(i==MAX_INVENTORY) return 0;
  9918. pc_equipitem(sd,i,item_data->equip);
  9919. return 0;
  9920. }
  9921. int buildin_autoequip(struct script_state *st){
  9922. int nameid, flag;
  9923. struct item_data *item_data;
  9924. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9925. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9926. if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
  9927. item_data->flag.autoequip = flag>0?1:0;
  9928. }
  9929. return 0;
  9930. }
  9931. int buildin_setbattleflag(struct script_state *st){
  9932. char *flag, *value;
  9933. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9934. value = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9935. if (battle_set_value(flag, value) == 0)
  9936. ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'",flag);
  9937. else
  9938. ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.",flag,value);
  9939. return 0;
  9940. }
  9941. int buildin_getbattleflag(struct script_state *st){
  9942. char *flag;
  9943. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9944. push_val(st->stack,C_INT,battle_get_value(flag));
  9945. return 0;
  9946. }
  9947. //=======================================================
  9948. // strlen [Valaris]
  9949. //-------------------------------------------------------
  9950. int buildin_getstrlen(struct script_state *st) {
  9951. char *str = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9952. int len = (str) ? (int)strlen(str) : 0;
  9953. push_val(st->stack,C_INT,len);
  9954. return 0;
  9955. }
  9956. //=======================================================
  9957. // isalpha [Valaris]
  9958. //-------------------------------------------------------
  9959. int buildin_charisalpha(struct script_state *st) {
  9960. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9961. int pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9962. int val = ( str && pos>0 && (unsigned int)pos<strlen(str) ) ? isalpha( str[pos] ) : 0;
  9963. push_val(st->stack,C_INT,val);
  9964. return 0;
  9965. }
  9966. // [Lance]
  9967. int buildin_fakenpcname(struct script_state *st)
  9968. {
  9969. char *name;
  9970. char *newname;
  9971. int look;
  9972. name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9973. newname = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9974. look = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9975. if(look > 32767 || look < -32768) {
  9976. ShowError("buildin_fakenpcname: Invalid look value %d\n",look);
  9977. return 1; // Safety measure to prevent runtime errors
  9978. }
  9979. npc_changename(name,newname,(short)look);
  9980. return 0;
  9981. }
  9982. int buildin_atoi(struct script_state *st) {
  9983. char *value;
  9984. value = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9985. push_val(st->stack, C_INT, atoi(value));
  9986. return 0;
  9987. }
  9988. //-----------------------------------------------------------------------//
  9989. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA START //
  9990. //-----------------------------------------------------------------------//
  9991. int buildin_compare(struct script_state *st) {
  9992. char *message;
  9993. char *cmpstring;
  9994. int j;
  9995. message = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9996. cmpstring = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9997. for (j = 0; message[j]; j++)
  9998. message[j] = tolower(message[j]);
  9999. for (j = 0; cmpstring[j]; j++)
  10000. cmpstring[j] = tolower(cmpstring[j]);
  10001. push_val(st->stack,C_INT,(strstr(message,cmpstring) != NULL));
  10002. return 0;
  10003. }
  10004. //-----------------------------------------------------------------------//
  10005. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA END //
  10006. //-----------------------------------------------------------------------//
  10007. // [zBuffer] List of mathematics commands --->
  10008. int buildin_sqrt(struct script_state *st){
  10009. double i, a;
  10010. i = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10011. a = sqrt(i);
  10012. push_val(st->stack, C_INT, (int)a);
  10013. return 0;
  10014. }
  10015. int buildin_pow(struct script_state *st){
  10016. double i, a, b;
  10017. a = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10018. b = conv_num(st, &(st->stack->stack_data[st->start+3]));
  10019. i = pow(a,b);
  10020. push_val(st->stack, C_INT, (int)i);
  10021. return 0;
  10022. }
  10023. int buildin_distance(struct script_state *st){
  10024. int x0, y0, x1, y1;
  10025. x0 = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10026. y0 = conv_num(st, &(st->stack->stack_data[st->start+3]));
  10027. x1 = conv_num(st, &(st->stack->stack_data[st->start+4]));
  10028. y1 = conv_num(st, &(st->stack->stack_data[st->start+5]));
  10029. push_val(st->stack, C_INT, distance(x0-x1, y0-y1));
  10030. return 0;
  10031. }
  10032. int buildin_checkcell(struct script_state *st){
  10033. int m;
  10034. char *map = conv_str(st, &(st->stack->stack_data[st->start+2]));
  10035. m = mapindex_name2id(map);
  10036. if(m){
  10037. push_val(st->stack, C_INT, map_getcell(m, conv_num(st, &(st->stack->stack_data[st->start+3])), conv_num(st, &(st->stack->stack_data[st->start+4])),conv_num(st, &(st->stack->stack_data[st->start+5]))));
  10038. } else {
  10039. push_val(st->stack, C_INT, 0);
  10040. }
  10041. return 0;
  10042. }
  10043. // <--- [zBuffer] List of mathematics commands
  10044. // [zBuffer] List of dynamic var commands --->
  10045. void setd_sub(struct script_state *st, struct map_session_data *sd, char *varname, int elem, void *value, struct linkdb_node **ref)
  10046. {
  10047. set_reg(st, sd, add_str((unsigned char *) varname)+(elem<<24), varname, value, ref);
  10048. return;
  10049. }
  10050. int buildin_setd(struct script_state *st)
  10051. {
  10052. struct map_session_data *sd=NULL;
  10053. char varname[100], *buffer;
  10054. char *value;
  10055. int elem;
  10056. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10057. value = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10058. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10059. elem = 0;
  10060. if(st->rid)
  10061. sd = script_rid2sd(st);
  10062. if(varname[strlen(varname)-1] != '$') {
  10063. setd_sub(st,sd, varname, elem, (void *)atoi(value),NULL);
  10064. } else {
  10065. setd_sub(st,sd, varname, elem, (void *)value,NULL);
  10066. }
  10067. return 0;
  10068. }
  10069. #ifndef TXT_ONLY
  10070. int buildin_query_sql(struct script_state *st) {
  10071. char *name, *query;
  10072. int num, i = 0;
  10073. struct map_session_data *sd = (st->rid)? script_rid2sd(st) : NULL;
  10074. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10075. strcpy(tmp_sql, query);
  10076. if(mysql_query(&mmysql_handle,tmp_sql)){
  10077. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10078. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10079. return 1;
  10080. }
  10081. if(st->end > st->start+3) {
  10082. if(st->stack->stack_data[st->start+3].type != C_NAME){
  10083. ShowWarning("buildin_query_sql: 2nd parameter is not a variable!\n");
  10084. } else {
  10085. num=st->stack->stack_data[st->start+3].u.num;
  10086. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10087. if((sql_res = mysql_store_result(&mmysql_handle))){
  10088. if(name[strlen(name)-1] != '$') {
  10089. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  10090. setd_sub(st,sd, name, i, (void *)atoi(sql_row[0]),st->stack->stack_data[st->start+3].ref);
  10091. i++;
  10092. }
  10093. } else {
  10094. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  10095. setd_sub(st,sd, name, i, (void *)sql_row[0],st->stack->stack_data[st->start+3].ref);
  10096. i++;
  10097. }
  10098. }
  10099. mysql_free_result(sql_res);
  10100. }
  10101. }
  10102. }
  10103. return 0;
  10104. }
  10105. //Allows escaping of a given string.
  10106. int buildin_escape_sql(struct script_state *st) {
  10107. char *t_query, *query;
  10108. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10109. t_query = aMallocA((strlen(query)*2+1)*sizeof(char));
  10110. jstrescapecpy(t_query,query);
  10111. push_str(st->stack,C_STR,(unsigned char *)t_query);
  10112. return 0;
  10113. }
  10114. #endif
  10115. int buildin_getd (struct script_state *st)
  10116. {
  10117. char varname[100], *buffer;
  10118. //struct script_data dat;
  10119. int elem;
  10120. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10121. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10122. elem = 0;
  10123. /*dat.type=C_NAME;
  10124. dat.u.num=add_str((unsigned char *) varname)+(elem<<24);
  10125. get_val(st,&dat);
  10126. if(dat.type == C_INT)
  10127. push_val(st->stack, C_INT, dat.u.num);
  10128. else if(dat.type == C_CONSTSTR){
  10129. buffer = aStrdup((char *)dat.u.str);
  10130. // dat.u.str holds the actual pointer to the data, must be duplicated.
  10131. // It will be freed later. Tested.
  10132. push_str(st->stack, C_STR, buffer);
  10133. }*/
  10134. // Push the 'pointer' so it's more flexible [Lance]
  10135. push_val(st->stack,C_NAME,
  10136. (elem<<24) | add_str((unsigned char *) varname));
  10137. return 0;
  10138. }
  10139. // <--- [zBuffer] List of dynamic var commands
  10140. // Pet stat [Lance]
  10141. int buildin_petstat(struct script_state *st){
  10142. struct map_session_data *sd = NULL;
  10143. char *tmp;
  10144. int flag = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10145. sd = script_rid2sd(st);
  10146. if(!sd || !sd->pet.pet_id){
  10147. if(flag == 2)
  10148. push_str(st->stack, C_CONSTSTR, "");
  10149. else
  10150. push_val(st->stack, C_INT, 0);
  10151. }
  10152. else {
  10153. switch(flag){
  10154. case 1:
  10155. push_val(st->stack, C_INT, (int)sd->pet.class_);
  10156. break;
  10157. case 2:
  10158. tmp = aStrdup(sd->pet.name);
  10159. push_str(st->stack, C_STR, tmp);
  10160. break;
  10161. case 3:
  10162. push_val(st->stack, C_INT, (int)sd->pet.level);
  10163. break;
  10164. case 4:
  10165. push_val(st->stack, C_INT, (int)sd->pet.hungry);
  10166. break;
  10167. case 5:
  10168. push_val(st->stack, C_INT, (int)sd->pet.intimate);
  10169. break;
  10170. default:
  10171. push_val(st->stack, C_INT, 0);
  10172. break;
  10173. }
  10174. }
  10175. return 0;
  10176. }
  10177. int buildin_callshop(struct script_state *st)
  10178. {
  10179. struct map_session_data *sd = NULL;
  10180. struct npc_data *nd;
  10181. char *shopname;
  10182. int flag = 0;
  10183. sd = script_rid2sd(st);
  10184. if (!sd) {
  10185. push_val(st->stack,C_INT,0);
  10186. return 0;
  10187. }
  10188. shopname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10189. if( st->end>st->start+3 )
  10190. flag = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10191. nd = npc_name2id(shopname);
  10192. if (!nd || nd->bl.type!=BL_NPC || nd->bl.subtype!=SHOP) {
  10193. ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)", shopname);
  10194. push_val(st->stack,C_INT,0);
  10195. return 1;
  10196. }
  10197. switch (flag) {
  10198. case 1: //Buy window
  10199. npc_buysellsel(sd,nd->bl.id,0);
  10200. break;
  10201. case 2: //Sell window
  10202. npc_buysellsel(sd,nd->bl.id,1);
  10203. break;
  10204. default: //Show menu
  10205. clif_npcbuysell(sd,nd->bl.id);
  10206. break;
  10207. }
  10208. sd->npc_shopid = nd->bl.id;
  10209. push_val(st->stack,C_INT,1);
  10210. return 0;
  10211. }
  10212. #ifndef MAX_SHOPITEM
  10213. #define MAX_SHOPITEM 100
  10214. #endif
  10215. int buildin_npcshopitem(struct script_state *st)
  10216. {
  10217. struct npc_data *nd= NULL;
  10218. int n = 0;
  10219. int i = 3;
  10220. int amount;
  10221. char* npcname = conv_str(st, & (st->stack->stack_data[st->start + 2]));
  10222. nd = npc_name2id(npcname);
  10223. if(nd && nd->bl.subtype==SHOP){
  10224. amount = ((st->end-2)/2)+1;
  10225. // st->end - 2 = nameid + value # ... / 2 = number of items ... + 1 to end it
  10226. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10227. sizeof(nd->u.shop_item[0]) * amount);
  10228. // Reset sell list.
  10229. memset(nd->u.shop_item, 0, sizeof(nd->u.shop_item[0]) * amount);
  10230. n = 0;
  10231. while (st->end > st->start + i) {
  10232. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10233. i++;
  10234. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10235. i++;
  10236. n++;
  10237. }
  10238. map_addiddb(&nd->bl);
  10239. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10240. } else {
  10241. ShowError("buildin_npcshopitem: shop not found.\n");
  10242. }
  10243. return 0;
  10244. }
  10245. int buildin_npcshopadditem(struct script_state *st) {
  10246. struct npc_data *nd=NULL;
  10247. int n = 0;
  10248. int i = 3;
  10249. int amount;
  10250. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10251. nd = npc_name2id(npcname);
  10252. if (nd && nd->bl.subtype==SHOP){
  10253. amount = ((st->end-2)/2)+1;
  10254. while (nd->u.shop_item[n].nameid && n < MAX_SHOPITEM)
  10255. n++;
  10256. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10257. sizeof(nd->u.shop_item[0]) * (amount+n));
  10258. while(st->end > st->start + i){
  10259. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10260. i++;
  10261. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10262. i++;
  10263. n++;
  10264. }
  10265. // Marks the last of our stuff..
  10266. nd->u.shop_item[n].value = 0;
  10267. nd->u.shop_item[n].nameid = 0;
  10268. map_addiddb(&nd->bl);
  10269. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10270. } else {
  10271. ShowError("buildin_npcshopadditem: shop not found.\n");
  10272. }
  10273. return 0;
  10274. }
  10275. int buildin_npcshopdelitem(struct script_state *st)
  10276. {
  10277. struct npc_data *nd=NULL;
  10278. int n=0;
  10279. int i=3;
  10280. int size = 0;
  10281. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10282. nd = npc_name2id(npcname);
  10283. if (nd && nd->bl.subtype==SHOP) {
  10284. while (nd->u.shop_item[size].nameid)
  10285. size++;
  10286. while (st->end > st->start+i) {
  10287. for(n=0;nd->u.shop_item[n].nameid && n < MAX_SHOPITEM;n++) {
  10288. if (nd->u.shop_item[n].nameid == conv_num(st, & (st->stack->stack_data[st->start+i]))) {
  10289. // We're moving 1 extra empty block. Junk data is eliminated later.
  10290. memmove(&nd->u.shop_item[n], &nd->u.shop_item[n+1], sizeof(nd->u.shop_item[0])*(size-n));
  10291. }
  10292. }
  10293. i++;
  10294. }
  10295. size = 0;
  10296. while (nd->u.shop_item[size].nameid)
  10297. size++;
  10298. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10299. sizeof(nd->u.shop_item[0]) * (size+1));
  10300. map_addiddb(&nd->bl);
  10301. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10302. } else {
  10303. ShowError("buildin_npcshopdelitem: shop not found.\n");
  10304. }
  10305. return 0;
  10306. }
  10307. /*==========================================
  10308. * Returns some values of an item [Lupus]
  10309. * Price, Weight, etc...
  10310. setiteminfo(itemID,"{new item bonus script}");
  10311. *------------------------------------------
  10312. */
  10313. int buildin_setitemscript(struct script_state *st)
  10314. {
  10315. int item_id;
  10316. char *script;
  10317. struct item_data *i_data;
  10318. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10319. script = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10320. i_data = itemdb_exists(item_id);
  10321. if (i_data && script!=NULL && script[0]=='{') {
  10322. if(i_data->script!=NULL)
  10323. script_free_code(i_data->script);
  10324. i_data->script = parse_script((unsigned char *) script, "script_setitemscript", 0);
  10325. push_val(st->stack,C_INT,1);
  10326. } else
  10327. push_val(st->stack,C_INT,0);
  10328. return 0;
  10329. }
  10330. /* Work In Progress [Lupus]
  10331. int buildin_addmonsterdrop(struct script_state *st)
  10332. {
  10333. int class_,item_id,chance;
  10334. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10335. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10336. chance=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10337. if(class_>1000 && item_id>500 && chance>0) {
  10338. push_val(st->stack,C_INT,1);
  10339. } else {
  10340. push_val(st->stack,C_INT,0);
  10341. }
  10342. }
  10343. int buildin_delmonsterdrop(struct script_state *st)
  10344. {
  10345. int class_,item_id;
  10346. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10347. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10348. if(class_>1000 && item_id>500) {
  10349. push_val(st->stack,C_INT,1);
  10350. } else {
  10351. push_val(st->stack,C_INT,0);
  10352. }
  10353. }
  10354. */
  10355. /*==========================================
  10356. * Returns some values of a monster [Lupus]
  10357. * Name, Level, race, size, etc...
  10358. getmonsterinfo(monsterID,queryIndex);
  10359. *------------------------------------------
  10360. */
  10361. int buildin_getmonsterinfo(struct script_state *st)
  10362. {
  10363. struct mob_db *mob;
  10364. int mob_id;
  10365. mob_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10366. if (!mobdb_checkid(mob_id)) {
  10367. ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i", mob_id);
  10368. push_val(st->stack, C_INT, -1);
  10369. return -1;
  10370. }
  10371. mob = mob_db(mob_id);
  10372. switch ( conv_num(st,& (st->stack->stack_data[st->start+3])) ) {
  10373. case 0: //Name
  10374. push_str(st->stack,C_CONSTSTR, (unsigned char *) mob->jname);
  10375. break;
  10376. case 1: //Lvl
  10377. push_val(st->stack,C_INT, mob->lv);
  10378. break;
  10379. case 2: //MaxHP
  10380. push_val(st->stack,C_INT, mob->status.max_hp);
  10381. break;
  10382. case 3: //Base EXP
  10383. push_val(st->stack,C_INT, mob->base_exp);
  10384. break;
  10385. case 4: //Job EXP
  10386. push_val(st->stack,C_INT, mob->job_exp);
  10387. break;
  10388. case 5: //Atk1
  10389. push_val(st->stack,C_INT, mob->status.rhw.atk);
  10390. break;
  10391. case 6: //Atk2
  10392. push_val(st->stack,C_INT, mob->status.rhw.atk2);
  10393. break;
  10394. case 7: //Def
  10395. push_val(st->stack,C_INT, mob->status.def);
  10396. break;
  10397. case 8: //Mdef
  10398. push_val(st->stack,C_INT, mob->status.mdef);
  10399. break;
  10400. case 9: //Str
  10401. push_val(st->stack,C_INT, mob->status.str);
  10402. break;
  10403. case 10: //Agi
  10404. push_val(st->stack,C_INT, mob->status.agi);
  10405. break;
  10406. case 11: //Vit
  10407. push_val(st->stack,C_INT, mob->status.vit);
  10408. break;
  10409. case 12: //Int
  10410. push_val(st->stack,C_INT, mob->status.int_);
  10411. break;
  10412. case 13: //Dex
  10413. push_val(st->stack,C_INT, mob->status.dex);
  10414. break;
  10415. case 14: //Luk
  10416. push_val(st->stack,C_INT, mob->status.luk);
  10417. break;
  10418. case 15: //Range
  10419. push_val(st->stack,C_INT, mob->status.rhw.range);
  10420. break;
  10421. case 16: //Range2
  10422. push_val(st->stack,C_INT, mob->range2);
  10423. break;
  10424. case 17: //Range3
  10425. push_val(st->stack,C_INT, mob->range3);
  10426. break;
  10427. case 18: //Size
  10428. push_val(st->stack,C_INT, mob->status.size);
  10429. break;
  10430. case 19: //Race
  10431. push_val(st->stack,C_INT, mob->status.race);
  10432. break;
  10433. case 20: //Element
  10434. push_val(st->stack,C_INT, mob->status.def_ele);
  10435. break;
  10436. case 21: //Mode
  10437. push_val(st->stack,C_INT, mob->status.mode);
  10438. break;
  10439. default: //wrong Index
  10440. push_val(st->stack,C_INT,-1);
  10441. }
  10442. return 0;
  10443. }
  10444. int axtoi(char *hexStg) {
  10445. int n = 0; // position in string
  10446. int m = 0; // position in digit[] to shift
  10447. int count; // loop index
  10448. int intValue = 0; // integer value of hex string
  10449. int digit[11]; // hold values to convert
  10450. while (n < 10) {
  10451. if (hexStg[n]=='\0')
  10452. break;
  10453. if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
  10454. digit[n] = hexStg[n] & 0x0f; //convert to int
  10455. else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
  10456. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10457. else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
  10458. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10459. else break;
  10460. n++;
  10461. }
  10462. count = n;
  10463. m = n - 1;
  10464. n = 0;
  10465. while(n < count) {
  10466. // digit[n] is value of hex digit at position n
  10467. // (m << 2) is the number of positions to shift
  10468. // OR the bits into return value
  10469. intValue = intValue | (digit[n] << (m << 2));
  10470. m--; // adjust the position to set
  10471. n++; // next digit to process
  10472. }
  10473. return (intValue);
  10474. }
  10475. // [Lance] Hex string to integer converter
  10476. int buildin_axtoi(struct script_state *st)
  10477. {
  10478. char *hex = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10479. push_val(st->stack, C_INT, axtoi(hex));
  10480. return 0;
  10481. }
  10482. // [zBuffer] List of player cont commands --->
  10483. int buildin_rid2name(struct script_state *st){
  10484. struct block_list *bl = NULL;
  10485. int rid = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10486. if((bl = map_id2bl(rid))){
  10487. switch(bl->type){
  10488. case BL_MOB:
  10489. push_str(st->stack,C_CONSTSTR,((struct mob_data *)bl)->name);
  10490. break;
  10491. case BL_PC:
  10492. push_str(st->stack,C_CONSTSTR,((struct map_session_data *)bl)->status.name);
  10493. break;
  10494. case BL_NPC:
  10495. push_str(st->stack,C_CONSTSTR,((struct npc_data *)bl)->exname);
  10496. break;
  10497. case BL_PET:
  10498. push_str(st->stack,C_CONSTSTR,((struct pet_data *)bl)->name);
  10499. break;
  10500. case BL_HOMUNCULUS:
  10501. push_str(st->stack,C_CONSTSTR,((struct homun_data *)bl)->master->homunculus.name);
  10502. break;
  10503. default:
  10504. ShowError("buildin_rid2name: BL type unknown.\n");
  10505. push_str(st->stack,C_CONSTSTR,"");
  10506. break;
  10507. }
  10508. }
  10509. return 0;
  10510. }
  10511. int buildin_pcblockmove(struct script_state *st){
  10512. int id, flag;
  10513. struct map_session_data *sd = NULL;
  10514. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10515. flag = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10516. if(id)
  10517. sd = map_id2sd(id);
  10518. else
  10519. sd = script_rid2sd(st);
  10520. if(sd)
  10521. sd->state.blockedmove = flag > 0;
  10522. return 0;
  10523. }
  10524. int buildin_pcfollow(struct script_state *st) {
  10525. int id, targetid;
  10526. struct map_session_data *sd = NULL;
  10527. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10528. targetid = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10529. if(id)
  10530. sd = map_id2sd(id);
  10531. else
  10532. sd = script_rid2sd(st);
  10533. if(sd)
  10534. pc_follow(sd, targetid);
  10535. return 0;
  10536. }
  10537. int buildin_pcstopfollow(struct script_state *st) {
  10538. int id;
  10539. struct map_session_data *sd = NULL;
  10540. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10541. if(id)
  10542. sd = map_id2sd(id);
  10543. else
  10544. sd = script_rid2sd(st);
  10545. if(sd)
  10546. pc_stop_following(sd);
  10547. return 0;
  10548. }
  10549. // <--- [zBuffer] List of player cont commands
  10550. // [zBuffer] List of mob control commands --->
  10551. int buildin_mobspawn(struct script_state *st){
  10552. int class_,x,y,id;
  10553. char *str,*map;
  10554. // Who?
  10555. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  10556. // What?
  10557. class_ =conv_num(st,& (st->stack->stack_data[st->start+3]));
  10558. // Where?
  10559. map =conv_str(st,& (st->stack->stack_data[st->start+4]));
  10560. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  10561. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  10562. id = mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,1,NULL);
  10563. push_val(st->stack,C_INT,id);
  10564. return 0;
  10565. }
  10566. int buildin_mobremove(struct script_state *st) {
  10567. int id;
  10568. struct block_list *bl = NULL;
  10569. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10570. bl = map_id2bl(id);
  10571. if (bl && bl->type == BL_MOB)
  10572. unit_free(bl);
  10573. return 0;
  10574. }
  10575. int buildin_getmobdata(struct script_state *st) {
  10576. int num, id;
  10577. char *name;
  10578. struct mob_data *md = NULL;
  10579. struct map_session_data *sd = st->rid?map_id2sd(st->rid):NULL;
  10580. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10581. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB || st->stack->stack_data[st->start+3].type!=C_NAME ){
  10582. ShowWarning("buildin_getmobdata: Error in argument!\n");
  10583. return -1;
  10584. }
  10585. num=st->stack->stack_data[st->start+3].u.num;
  10586. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10587. setd_sub(st,sd,name,0,(void *)(int)md->class_,st->stack->stack_data[st->start+3].ref);
  10588. setd_sub(st,sd,name,1,(void *)(int)md->level,st->stack->stack_data[st->start+3].ref);
  10589. setd_sub(st,sd,name,2,(void *)(int)md->status.hp,st->stack->stack_data[st->start+3].ref);
  10590. setd_sub(st,sd,name,3,(void *)(int)md->status.max_hp,st->stack->stack_data[st->start+3].ref);
  10591. setd_sub(st,sd,name,4,(void *)(int)md->master_id,st->stack->stack_data[st->start+3].ref);
  10592. setd_sub(st,sd,name,5,(void *)(int)md->bl.m,st->stack->stack_data[st->start+3].ref);
  10593. setd_sub(st,sd,name,6,(void *)(int)md->bl.x,st->stack->stack_data[st->start+3].ref);
  10594. setd_sub(st,sd,name,7,(void *)(int)md->bl.y,st->stack->stack_data[st->start+3].ref);
  10595. setd_sub(st,sd,name,8,(void *)(int)md->status.speed,st->stack->stack_data[st->start+3].ref);
  10596. setd_sub(st,sd,name,9,(void *)(int)md->status.mode,st->stack->stack_data[st->start+3].ref);
  10597. setd_sub(st,sd,name,10,(void *)(int)md->special_state.ai,st->stack->stack_data[st->start+3].ref);
  10598. setd_sub(st,sd,name,11,(void *)(int)md->sc.option,st->stack->stack_data[st->start+3].ref);
  10599. setd_sub(st,sd,name,12,(void *)(int)md->vd->sex,st->stack->stack_data[st->start+3].ref);
  10600. setd_sub(st,sd,name,13,(void *)(int)md->vd->class_,st->stack->stack_data[st->start+3].ref);
  10601. setd_sub(st,sd,name,14,(void *)(int)md->vd->hair_style,st->stack->stack_data[st->start+3].ref);
  10602. setd_sub(st,sd,name,15,(void *)(int)md->vd->hair_color,st->stack->stack_data[st->start+3].ref);
  10603. setd_sub(st,sd,name,16,(void *)(int)md->vd->head_bottom,st->stack->stack_data[st->start+3].ref);
  10604. setd_sub(st,sd,name,17,(void *)(int)md->vd->head_mid,st->stack->stack_data[st->start+3].ref);
  10605. setd_sub(st,sd,name,18,(void *)(int)md->vd->head_top,st->stack->stack_data[st->start+3].ref);
  10606. setd_sub(st,sd,name,19,(void *)(int)md->vd->cloth_color,st->stack->stack_data[st->start+3].ref);
  10607. setd_sub(st,sd,name,20,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10608. setd_sub(st,sd,name,21,(void *)(int)md->vd->weapon,st->stack->stack_data[st->start+3].ref);
  10609. setd_sub(st,sd,name,22,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10610. setd_sub(st,sd,name,23,(void *)(int)md->ud.dir,st->stack->stack_data[st->start+3].ref);
  10611. setd_sub(st,sd,name,24,(void *)(int)md->state.killer,st->stack->stack_data[st->start+3].ref);
  10612. setd_sub(st,sd,name,25,(void *)(int)md->callback_flag,st->stack->stack_data[st->start+3].ref);
  10613. setd_sub(st,sd,name,26,(void *)(int)md->state.no_random_walk, st->stack->stack_data[st->start+3].ref);
  10614. return 0;
  10615. }
  10616. int buildin_setmobdata(struct script_state *st){
  10617. int id, value, value2;
  10618. struct mob_data *md = NULL;
  10619. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10620. value = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10621. value2 = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10622. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB){
  10623. ShowWarning("buildin_setmobdata: Error in argument!\n");
  10624. return -1;
  10625. }
  10626. switch(value){
  10627. case 0:
  10628. md->class_ = (short)value2;
  10629. break;
  10630. case 1:
  10631. md->level = (unsigned short)value2;
  10632. break;
  10633. case 2:
  10634. md->status.hp = value2;
  10635. break;
  10636. case 3:
  10637. md->status.max_hp = value2;
  10638. break;
  10639. case 4:
  10640. md->master_id = value2;
  10641. break;
  10642. case 5:
  10643. md->bl.m = (short)value2;
  10644. break;
  10645. case 6:
  10646. md->bl.x = (short)value2;
  10647. break;
  10648. case 7:
  10649. md->bl.y = (short)value2;
  10650. break;
  10651. case 8:
  10652. md->status.speed = (short)value2;
  10653. break;
  10654. case 9:
  10655. md->status.mode = (short)value2;
  10656. break;
  10657. case 10:
  10658. md->special_state.ai = (unsigned int)value2;
  10659. break;
  10660. case 11:
  10661. md->sc.option = (short)value2;
  10662. break;
  10663. case 12:
  10664. md->vd->sex = value2;
  10665. break;
  10666. case 13:
  10667. md->vd->class_ = value2;
  10668. break;
  10669. case 14:
  10670. md->vd->hair_style = (short)value2;
  10671. break;
  10672. case 15:
  10673. md->vd->hair_color = (short)value2;
  10674. break;
  10675. case 16:
  10676. md->vd->head_bottom = (short)value2;
  10677. break;
  10678. case 17:
  10679. md->vd->head_mid = (short)value2;
  10680. break;
  10681. case 18:
  10682. md->vd->head_top = (short)value2;
  10683. break;
  10684. case 19:
  10685. md->vd->cloth_color = (short)value2;
  10686. break;
  10687. case 20:
  10688. md->vd->shield = value2;
  10689. break;
  10690. case 21:
  10691. md->vd->weapon = (short)value2;
  10692. break;
  10693. case 22:
  10694. md->vd->shield = (short)value2;
  10695. break;
  10696. case 23:
  10697. md->ud.dir = (unsigned char)value2;
  10698. break;
  10699. case 24:
  10700. md->state.killer = value2>0?1:0;
  10701. break;
  10702. case 25:
  10703. md->callback_flag = (short)value2;
  10704. break;
  10705. case 26:
  10706. md->state.no_random_walk = value2>0?1:0;
  10707. break;
  10708. default:
  10709. ShowError("buildin_setmobdata: argument id is not identified.");
  10710. return -1;
  10711. }
  10712. return 0;
  10713. }
  10714. int buildin_mobassist(struct script_state *st) {
  10715. int id;
  10716. char *target;
  10717. struct mob_data *md = NULL;
  10718. struct block_list *bl = NULL;
  10719. struct unit_data *ud;
  10720. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10721. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10722. if((bl =&(map_nick2sd(target)->bl)) || (bl = map_id2bl(atoi(target)))) {
  10723. md = (struct mob_data *)map_id2bl(id);
  10724. if(md && md->bl.type == BL_MOB) {
  10725. ud = unit_bl2ud(bl);
  10726. md->master_id = bl->id;
  10727. md->state.killer = 1;
  10728. mob_convertslave(md);
  10729. if (ud) {
  10730. if (ud->target)
  10731. md->target_id = ud->target;
  10732. else if (ud->skilltarget)
  10733. md->target_id = ud->skilltarget;
  10734. if(md->target_id)
  10735. unit_walktobl(&md->bl, map_id2bl(md->target_id), 65025, 2);
  10736. }
  10737. }
  10738. }
  10739. return 0;
  10740. }
  10741. int buildin_mobattach(struct script_state *st){
  10742. int id;
  10743. struct mob_data *md = NULL;
  10744. struct npc_data *nd = NULL;
  10745. char *npcname = NULL;
  10746. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10747. if(st->end > st->start + 3){
  10748. npcname = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10749. }
  10750. if(npcname)
  10751. nd = npc_name2id(npcname);
  10752. else
  10753. nd = (struct npc_data *)map_id2bl(st->oid);
  10754. if(nd)
  10755. if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB)
  10756. md->nd = nd;
  10757. return 0;
  10758. }
  10759. int buildin_unitwalk(struct script_state *st){
  10760. int id,x,y = 0;
  10761. struct block_list *bl = NULL;
  10762. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10763. x = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10764. if(st->end > st->start+4)
  10765. y = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10766. bl = map_id2bl(id);
  10767. if(bl){
  10768. if(y)
  10769. push_val(st->stack,C_INT,unit_walktoxy(bl,x,y,0)); // We'll use harder calculations.
  10770. else
  10771. push_val(st->stack,C_INT,unit_walktobl(bl,map_id2bl(x),65025,1));
  10772. } else {
  10773. push_val(st->stack,C_INT,0);
  10774. }
  10775. return 0;
  10776. }
  10777. int buildin_unitkill(struct script_state *st){
  10778. struct block_list *bl = map_id2bl(conv_num(st, & (st->stack->stack_data[st->start+2])));
  10779. if(bl)
  10780. status_kill(bl);
  10781. return 0;
  10782. }
  10783. int buildin_unitwarp(struct script_state *st){
  10784. int id,x,y,m = 0;
  10785. char *map;
  10786. struct block_list *bl = NULL;
  10787. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10788. map = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10789. x = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10790. y = conv_num(st, & (st->stack->stack_data[st->start+5]));
  10791. bl = map_id2bl(id);
  10792. m = map_mapname2mapid(map);
  10793. if(m && bl){
  10794. push_val(st->stack,C_INT,unit_warp(bl, m, (short)x, (short)y, 0));
  10795. } else {
  10796. push_val(st->stack,C_INT,0);
  10797. }
  10798. return 0;
  10799. }
  10800. int buildin_unitattack(struct script_state *st) {
  10801. int id = 0, actiontype = 0;
  10802. char *target = NULL;
  10803. struct map_session_data *sd = NULL;
  10804. struct block_list *bl = NULL, *tbl = NULL;
  10805. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10806. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10807. if(st->end > st->start + 4)
  10808. actiontype = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10809. sd = map_nick2sd(target);
  10810. if(!sd)
  10811. tbl = map_id2bl(atoi(target));
  10812. else
  10813. tbl = &sd->bl;
  10814. if((bl = map_id2bl(id))){
  10815. if (bl->type == BL_MOB) {
  10816. ((TBL_MOB *)bl)->state.killer = 1;
  10817. ((TBL_MOB *)bl)->target_id = tbl->id;
  10818. } else if(bl->type == BL_PC){
  10819. clif_parse_ActionRequest_sub(((TBL_PC *)bl), actiontype > 0?0x07:0x00, tbl->id, gettick());
  10820. push_val(st->stack,C_INT,1);
  10821. return 0;
  10822. }
  10823. push_val(st->stack,C_INT,unit_walktobl(bl, tbl, 65025, 2));
  10824. } else {
  10825. push_val(st->stack,C_INT,0);
  10826. }
  10827. return 0;
  10828. }
  10829. int buildin_unitstop(struct script_state *st) {
  10830. int id;
  10831. struct block_list *bl = NULL;
  10832. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10833. bl = map_id2bl(id);
  10834. if(bl){
  10835. unit_stop_attack(bl);
  10836. unit_stop_walking(bl,0);
  10837. if(bl->type == BL_MOB)
  10838. ((TBL_MOB *)bl)->target_id = 0;
  10839. }
  10840. return 0;
  10841. }
  10842. int buildin_unittalk(struct script_state *st)
  10843. {
  10844. char *str;
  10845. int id;
  10846. char message[255];
  10847. struct block_list *bl = NULL;
  10848. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10849. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  10850. bl = map_id2bl(id);
  10851. if(bl) {
  10852. switch(bl->type){
  10853. case BL_MOB:
  10854. memcpy(message, ((TBL_MOB *)bl)->name, NAME_LENGTH);
  10855. break;
  10856. case BL_PC:
  10857. if(strlen(((TBL_PC *)bl)->fakename)>0)
  10858. memcpy(message, ((TBL_PC *)bl)->fakename, NAME_LENGTH);
  10859. else
  10860. memcpy(message, ((TBL_PC *)bl)->status.name, NAME_LENGTH);
  10861. break;
  10862. case BL_NPC:
  10863. memcpy(message, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  10864. break;
  10865. case BL_HOMUNCULUS:
  10866. memcpy(message, ((TBL_HOMUNCULUS *)bl)->master->homunculus.name, NAME_LENGTH);
  10867. break;
  10868. case BL_PET:
  10869. memcpy(message, ((TBL_PET *)bl)->name, NAME_LENGTH);
  10870. break;
  10871. default:
  10872. strcpy(message, "Unknown");
  10873. }
  10874. strcat(message," : ");
  10875. strncat(message,str, 228); //Prevent overflow possibility. [Skotlex]
  10876. clif_message(bl, message);
  10877. if(bl->type == BL_PC)
  10878. clif_displaymessage(((TBL_PC*)bl)->fd, message);
  10879. }
  10880. return 0;
  10881. }
  10882. int buildin_unitemote(struct script_state *st) {
  10883. int id, emo;
  10884. struct block_list *bl= NULL;
  10885. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10886. emo = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10887. if((bl = map_id2bl(id)))
  10888. clif_emotion(bl,emo);
  10889. return 0;
  10890. }
  10891. int buildin_unitdeadsit(struct script_state *st){
  10892. int id, action;
  10893. struct block_list *bl = NULL;
  10894. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10895. action = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10896. if((bl = map_id2bl(id))){
  10897. if(action > -1 && action < 4){
  10898. unsigned char buf[61] = "";
  10899. switch(bl->type){
  10900. case BL_MOB:
  10901. ((TBL_MOB *)bl)->vd->dead_sit = action;
  10902. break;
  10903. case BL_PC:
  10904. ((TBL_PC *)bl)->vd.dead_sit = action;
  10905. break;
  10906. case BL_NPC:
  10907. ((TBL_NPC *)bl)->vd->dead_sit = action;
  10908. break;
  10909. case BL_HOMUNCULUS:
  10910. ((TBL_HOMUNCULUS *)bl)->vd->dead_sit = action;
  10911. break;
  10912. case BL_PET:
  10913. ((TBL_PET *)bl)->vd.dead_sit = action;
  10914. break;
  10915. WBUFW(buf, 0) = 0x8a;
  10916. WBUFL(buf, 2) = bl->id;
  10917. WBUFB(buf,26) = (unsigned char)action;
  10918. clif_send(buf, 61, bl, AREA);
  10919. }
  10920. }else {
  10921. ShowError("buildin_unitdeadsit: Invalid action.\n");
  10922. report_src(st);
  10923. }
  10924. }else{
  10925. ShowError("buildin_unitdeadsit: Target is not found.\n");
  10926. report_src(st);
  10927. }
  10928. return 0;
  10929. }
  10930. int buildin_unitskilluseid (struct script_state *st)
  10931. {
  10932. int id,skid,sklv;
  10933. struct block_list *bl = NULL;
  10934. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10935. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10936. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10937. if ((bl = map_id2bl(id)))
  10938. unit_skilluse_id(bl,(st->end>st->start+5)?conv_num(st,& (st->stack->stack_data[st->start+5])):bl->id,skid,sklv);
  10939. return 0;
  10940. }
  10941. int buildin_unitskillusepos(struct script_state *st)
  10942. {
  10943. int skid,sklv,x,y,id;
  10944. struct block_list *bl = NULL;
  10945. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10946. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10947. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10948. x=conv_num(st,& (st->stack->stack_data[st->start+5]));
  10949. y=conv_num(st,& (st->stack->stack_data[st->start+6]));
  10950. if ((bl=map_id2bl(id)))
  10951. unit_skilluse_pos(bl,x,y,skid,sklv);
  10952. return 0;
  10953. }
  10954. // <--- [zBuffer] List of mob control commands
  10955. // sleep <mili sec>
  10956. int buildin_sleep(struct script_state *st) {
  10957. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10958. struct map_session_data *sd = map_id2sd(st->rid);
  10959. if(sd && sd->npc_id == st->oid) {
  10960. sd->npc_id = 0;
  10961. }
  10962. st->rid = 0;
  10963. if(tick <= 0) {
  10964. // 何もしない
  10965. } else if( !st->sleep.tick ) {
  10966. // 初回実行
  10967. st->state = RERUNLINE;
  10968. st->sleep.tick = tick;
  10969. } else {
  10970. // 続行
  10971. st->sleep.tick = 0;
  10972. }
  10973. return 0;
  10974. }
  10975. // sleep2 <mili sec>
  10976. int buildin_sleep2(struct script_state *st) {
  10977. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10978. if( tick <= 0 ) {
  10979. // 0ms の待機時間を指定された
  10980. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  10981. } else if( !st->sleep.tick ) {
  10982. // 初回実行時
  10983. st->state = RERUNLINE;
  10984. st->sleep.tick = tick;
  10985. } else {
  10986. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  10987. st->sleep.tick = 0;
  10988. }
  10989. return 0;
  10990. }
  10991. /*==========================================
  10992. * 指定NPCの全てのsleepを再開する
  10993. *------------------------------------------
  10994. */
  10995. int buildin_awake(struct script_state *st)
  10996. {
  10997. struct npc_data *nd;
  10998. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  10999. nd = npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  11000. if(nd == NULL)
  11001. return 0;
  11002. while( node ) {
  11003. if( (int)node->key == nd->bl.id) {
  11004. struct script_state *tst = node->data;
  11005. struct map_session_data *sd = map_id2sd(tst->rid);
  11006. if( tst->sleep.timer == -1 ) {
  11007. node = node->next;
  11008. continue;
  11009. }
  11010. if((sd && sd->char_id != tst->sleep.charid) || (tst->rid && !sd))
  11011. { //Cancel Execution
  11012. tst->state=END;
  11013. tst->rid = 0;
  11014. }
  11015. delete_timer(tst->sleep.timer, run_script_timer);
  11016. node = script_erase_sleepdb(node);
  11017. tst->sleep.timer = -1;
  11018. run_script_main(tst);
  11019. } else {
  11020. node = node->next;
  11021. }
  11022. }
  11023. return 0;
  11024. }
  11025. // getvariableofnpc(<param>, <npc name>);
  11026. int buildin_getvariableofnpc(struct script_state *st)
  11027. {
  11028. if( st->stack->stack_data[st->start+2].type != C_NAME ) {
  11029. // 第一引数が変数名じゃない
  11030. printf("getvariableofnpc: param not name\n");
  11031. push_val(st->stack,C_INT,0);
  11032. } else {
  11033. int num = st->stack->stack_data[st->start+2].u.num;
  11034. char *var_name = str_buf+str_data[num&0x00ffffff].str;
  11035. char *npc_name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  11036. struct npc_data *nd = npc_name2id(npc_name);
  11037. if( var_name[0] != '.' || var_name[1] == '@' ) {
  11038. // ' 変数以外はダメ
  11039. printf("getvariableofnpc: invalid scope %s\n", var_name);
  11040. push_val(st->stack,C_INT,0);
  11041. } else if( nd == NULL || nd->bl.subtype != SCRIPT || !nd->u.scr.script) {
  11042. // NPC が見つからない or SCRIPT以外のNPC
  11043. printf("getvariableofnpc: can't find npc %s\n", npc_name);
  11044. push_val(st->stack,C_INT,0);
  11045. } else {
  11046. push_val2(st->stack,C_NAME,num, &nd->u.scr.script->script_vars );
  11047. }
  11048. }
  11049. return 0;
  11050. }
  11051. // [blackhole89] --->
  11052. // Set a warp portal.
  11053. int buildin_warpportal(struct script_state *st){
  11054. struct skill_unit_group *group;
  11055. unsigned short mapindex;
  11056. long spx,spy,tpx,tpy;
  11057. struct block_list *bl=map_id2bl(st->oid);
  11058. nullpo_retr(0,bl);
  11059. spx=conv_num(st, & (st->stack->stack_data[st->start+2]));
  11060. spy=conv_num(st, & (st->stack->stack_data[st->start+3]));
  11061. mapindex = mapindex_name2id((char*)conv_str(st,& (st->stack->stack_data[st->start+4])));
  11062. printf("mapindex: %d\n",mapindex);
  11063. tpx=conv_num(st, & (st->stack->stack_data[st->start+5]));
  11064. tpy=conv_num(st, & (st->stack->stack_data[st->start+6]));
  11065. if(!mapindex) return 0;
  11066. if((group=skill_unitsetting(bl,AL_WARP,4,spx,spy,1))==NULL) {
  11067. return 0;
  11068. }
  11069. group->val2=(tpx<<16)|tpy;
  11070. group->val3 = mapindex;
  11071. return 0;
  11072. }
  11073. // <-- [blackhole89]