script.c 337 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. //#define DEBUG_FUNCIN
  4. //#define DEBUG_DISP
  5. //#define DEBUG_RUN
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <math.h>
  11. #include <limits.h>
  12. #ifndef _WIN32
  13. #include <sys/time.h>
  14. #endif
  15. #include <time.h>
  16. #include <setjmp.h>
  17. #include "../common/socket.h"
  18. #include "../common/timer.h"
  19. #include "../common/malloc.h"
  20. #include "../common/lock.h"
  21. #include "../common/nullpo.h"
  22. #include "../common/showmsg.h"
  23. #include "../common/strlib.h"
  24. #include "map.h"
  25. #include "clif.h"
  26. #include "chrif.h"
  27. #include "itemdb.h"
  28. #include "pc.h"
  29. #include "status.h"
  30. #include "script.h"
  31. #include "storage.h"
  32. #include "mob.h"
  33. #include "npc.h"
  34. #include "pet.h"
  35. #include "mercenary.h" //[orn]
  36. #include "intif.h"
  37. #include "skill.h"
  38. #include "chat.h"
  39. #include "battle.h"
  40. #include "party.h"
  41. #include "guild.h"
  42. #include "atcommand.h"
  43. #include "charcommand.h"
  44. #include "log.h"
  45. #include "unit.h"
  46. #include "irc.h"
  47. #include "pet.h"
  48. #define FETCH(n, t) \
  49. if(st->end>st->start+(n)) \
  50. (t)=conv_num(st,&(st->stack->stack_data[st->start+(n)]));
  51. #define SCRIPT_BLOCK_SIZE 512
  52. enum { LABEL_NEXTLINE=1,LABEL_START };
  53. static unsigned char * script_buf = NULL;
  54. static int script_pos,script_size;
  55. static char *str_buf;
  56. static int str_pos,str_size;
  57. static struct str_data_struct {
  58. int type;
  59. int str;
  60. int backpatch;
  61. int label;
  62. int (*func)(struct script_state *st);
  63. int val;
  64. int next;
  65. } *str_data = NULL;
  66. int str_num=LABEL_START,str_data_size;
  67. int str_hash[16];
  68. static struct dbt *mapreg_db=NULL;
  69. static struct dbt *mapregstr_db=NULL;
  70. static int mapreg_dirty=-1;
  71. char mapreg_txt[256]="save/mapreg.txt";
  72. #define MAPREG_AUTOSAVE_INTERVAL (300*1000)
  73. static struct dbt *scriptlabel_db=NULL;
  74. static struct dbt *userfunc_db=NULL;
  75. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  76. struct dbt* script_get_userfunc_db(){ return userfunc_db; }
  77. static char pos[11][100] = {"頭","体","左手","右手","ローブ","靴","アクセサリー1","アクセサリー2","頭2","頭3","装着していない"};
  78. struct Script_Config script_config;
  79. static int parse_cmd;
  80. static jmp_buf error_jump;
  81. static char* error_msg;
  82. static char* error_pos;
  83. // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
  84. // [Eoe / jA 1080, 1081, 1094, 1164]
  85. enum { TYPE_NULL = 0 , TYPE_IF , TYPE_SWITCH , TYPE_WHILE , TYPE_FOR , TYPE_DO , TYPE_USERFUNC};
  86. static struct {
  87. struct {
  88. int type;
  89. int index;
  90. int count;
  91. int flag;
  92. } curly[256]; // 右カッコの情報
  93. int curly_count; // 右カッコの数
  94. int index; // スクリプト内で使用した構文の数
  95. } syntax;
  96. unsigned char* parse_curly_close(unsigned char *p);
  97. unsigned char* parse_syntax_close(unsigned char *p);
  98. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag);
  99. unsigned char* parse_syntax(unsigned char *p);
  100. static int parse_syntax_for_flag = 0;
  101. extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
  102. int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
  103. int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
  104. int potion_target=0;
  105. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  106. // [zBuffer] SQL Mapreg Saving/Loading Database Declaration
  107. char mapregsql_db[32] = "mapreg";
  108. char mapregsql_db_varname[32] = "varname";
  109. char mapregsql_db_index[32] = "index";
  110. char mapregsql_db_value[32] = "value";
  111. char tmp_sql[65535];
  112. // --------------------------------------------------------
  113. #endif
  114. int get_com(unsigned char *script,int *pos);
  115. int get_num(unsigned char *script,int *pos);
  116. extern struct script_function {
  117. int (*func)(struct script_state *st);
  118. char *name;
  119. char *arg;
  120. } buildin_func[];
  121. static struct linkdb_node *sleep_db;
  122. #define not_server_variable(prefix) (prefix != '$' && prefix != '.')
  123. /*==========================================
  124. * ローカルプロトタイプ宣言 (必要な物のみ)
  125. *------------------------------------------
  126. */
  127. unsigned char* parse_subexpr(unsigned char *,int);
  128. void push_val(struct script_stack *stack,int type,int val);
  129. int run_func(struct script_state *st);
  130. int mapreg_setreg(int num,int val);
  131. int mapreg_setregstr(int num,const char *str);
  132. static void disp_error_message(const char *mes,unsigned char *pos);
  133. enum {
  134. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  135. C_NAME,C_EOL, C_RETINFO,
  136. C_USERFUNC, C_USERFUNC_POS, // user defined functions
  137. C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  138. C_XOR,C_OR,C_AND,C_ADD,C_SUB,C_MUL,C_DIV,C_MOD,C_NEG,C_LNOT,C_NOT,C_R_SHIFT,C_L_SHIFT
  139. };
  140. enum {
  141. MF_NOMEMO, //0
  142. MF_NOTELEPORT,
  143. MF_NOSAVE,
  144. MF_NOBRANCH,
  145. MF_NOPENALTY,
  146. MF_NOZENYPENALTY,
  147. MF_PVP,
  148. MF_PVP_NOPARTY,
  149. MF_PVP_NOGUILD,
  150. MF_GVG,
  151. MF_GVG_NOPARTY, //10
  152. MF_NOTRADE,
  153. MF_NOSKILL,
  154. MF_NOWARP,
  155. MF_FREE,
  156. MF_NOICEWALL,
  157. MF_SNOW,
  158. MF_FOG,
  159. MF_SAKURA,
  160. MF_LEAVES,
  161. MF_RAIN, //20
  162. MF_INDOORS,
  163. MF_NOGO,
  164. MF_CLOUDS,
  165. MF_CLOUDS2,
  166. MF_FIREWORKS,
  167. MF_GVG_CASTLE,
  168. MF_GVG_DUNGEON,
  169. MF_NIGHTENABLED,
  170. MF_NOBASEEXP,
  171. MF_NOJOBEXP, //30
  172. MF_NOMOBLOOT,
  173. MF_NOMVPLOOT,
  174. MF_NORETURN,
  175. MF_NOWARPTO,
  176. MF_NIGHTMAREDROP,
  177. MF_RESTRICTED,
  178. MF_NOCOMMAND,
  179. MF_NODROP,
  180. MF_JEXP,
  181. MF_BEXP, //40
  182. MF_NOVENDING,
  183. MF_LOADEVENT,
  184. MF_NOCHAT
  185. };
  186. //Reports on the console the src of an script error.
  187. static void report_src(struct script_state *st) {
  188. struct block_list *bl;
  189. if (!st->oid) return; //Can't report source.
  190. bl = map_id2bl(st->oid);
  191. if (!bl) return;
  192. switch (bl->type) {
  193. case BL_NPC:
  194. if (bl->m >=0)
  195. ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
  196. else
  197. ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
  198. break;
  199. default:
  200. if (bl->m >=0)
  201. ShowDebug("Source (Non-NPC): type %d at %s (%d,%d)\n", bl->type, map[bl->m].name, bl->x, bl->y);
  202. else
  203. ShowDebug("Source (Non-NPC): type %d (invisible/not on a map)\n", bl->type);
  204. break;
  205. }
  206. }
  207. static void check_event(struct script_state *st, unsigned char *event){
  208. if(event != NULL && event[0] != '\0' && !strstr(event,"::")){
  209. ShowError("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n",event);
  210. report_src(st);
  211. }
  212. return;
  213. }
  214. /*==========================================
  215. * 文字列のハッシュを計算
  216. *------------------------------------------
  217. */
  218. static int calc_hash(const unsigned char *p)
  219. {
  220. int h=0;
  221. while(*p){
  222. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  223. h+=*p++;
  224. }
  225. return h&15;
  226. }
  227. /*==========================================
  228. * str_dataの中に名前があるか検索する
  229. *------------------------------------------
  230. */
  231. // 既存のであれば番号、無ければ-1
  232. static int search_str(const unsigned char *p)
  233. {
  234. int i;
  235. i=str_hash[calc_hash(p)];
  236. while(i){
  237. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  238. return i;
  239. }
  240. i=str_data[i].next;
  241. }
  242. return -1;
  243. }
  244. /*==========================================
  245. * str_dataに名前を登録
  246. *------------------------------------------
  247. */
  248. // 既存のであれば番号、無ければ登録して新規番号
  249. int add_str(const unsigned char *p)
  250. {
  251. int i;
  252. char *lowcase;
  253. lowcase=aStrdup((char *) p);
  254. for(i=0;lowcase[i];i++)
  255. lowcase[i]=tolower(lowcase[i]);
  256. if((i=search_str((unsigned char *) lowcase))>=0){
  257. aFree(lowcase);
  258. return i;
  259. }
  260. aFree(lowcase);
  261. i=calc_hash(p);
  262. if(str_hash[i]==0){
  263. str_hash[i]=str_num;
  264. } else {
  265. i=str_hash[i];
  266. for(;;){
  267. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  268. return i;
  269. }
  270. if(str_data[i].next==0)
  271. break;
  272. i=str_data[i].next;
  273. }
  274. str_data[i].next=str_num;
  275. }
  276. if(str_num>=str_data_size){
  277. str_data_size+=128;
  278. str_data=aRealloc(str_data,sizeof(str_data[0])*str_data_size);
  279. memset(str_data + (str_data_size - 128), '\0', 128);
  280. }
  281. while(str_pos+(int)strlen((char *) p)+1>=str_size){
  282. str_size+=256;
  283. str_buf=(char *)aRealloc(str_buf,str_size);
  284. memset(str_buf + (str_size - 256), '\0', 256);
  285. }
  286. strcpy(str_buf+str_pos, (char *) p);
  287. str_data[str_num].type=C_NOP;
  288. str_data[str_num].str=str_pos;
  289. str_data[str_num].next=0;
  290. str_data[str_num].func=NULL;
  291. str_data[str_num].backpatch=-1;
  292. str_data[str_num].label=-1;
  293. str_pos+=(int)strlen( (char *) p)+1;
  294. return str_num++;
  295. }
  296. /*==========================================
  297. * スクリプトバッファサイズの確認と拡張
  298. *------------------------------------------
  299. */
  300. static void check_script_buf(int size)
  301. {
  302. if(script_pos+size>=script_size){
  303. script_size+=SCRIPT_BLOCK_SIZE;
  304. script_buf=(unsigned char *)aRealloc(script_buf,script_size);
  305. memset(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  306. SCRIPT_BLOCK_SIZE);
  307. }
  308. }
  309. /*==========================================
  310. * スクリプトバッファに1バイト書き込む
  311. *------------------------------------------
  312. */
  313. #define add_scriptb(a) if( script_pos+1>=script_size ) check_script_buf(1); script_buf[script_pos++]=(a);
  314. #if 0
  315. static void add_scriptb(int a)
  316. {
  317. check_script_buf(1);
  318. script_buf[script_pos++]=a;
  319. }
  320. #endif
  321. /*==========================================
  322. * スクリプトバッファにデータタイプを書き込む
  323. *------------------------------------------
  324. */
  325. static void add_scriptc(int a)
  326. {
  327. while(a>=0x40){
  328. add_scriptb((a&0x3f)|0x40);
  329. a=(a-0x40)>>6;
  330. }
  331. add_scriptb(a&0x3f);
  332. }
  333. /*==========================================
  334. * スクリプトバッファに整数を書き込む
  335. *------------------------------------------
  336. */
  337. static void add_scripti(int a)
  338. {
  339. while(a>=0x40){
  340. add_scriptb(a|0xc0);
  341. a=(a-0x40)>>6;
  342. }
  343. add_scriptb(a|0x80);
  344. }
  345. /*==========================================
  346. * スクリプトバッファにラベル/変数/関数を書き込む
  347. *------------------------------------------
  348. */
  349. // 最大16Mまで
  350. static void add_scriptl(int l)
  351. {
  352. int backpatch = str_data[l].backpatch;
  353. switch(str_data[l].type){
  354. case C_POS:
  355. case C_USERFUNC_POS:
  356. add_scriptc(C_POS);
  357. add_scriptb(str_data[l].label);
  358. add_scriptb(str_data[l].label>>8);
  359. add_scriptb(str_data[l].label>>16);
  360. break;
  361. case C_NOP:
  362. case C_USERFUNC:
  363. // ラベルの可能性があるのでbackpatch用データ埋め込み
  364. add_scriptc(C_NAME);
  365. str_data[l].backpatch=script_pos;
  366. add_scriptb(backpatch);
  367. add_scriptb(backpatch>>8);
  368. add_scriptb(backpatch>>16);
  369. break;
  370. case C_INT:
  371. add_scripti(str_data[l].val);
  372. break;
  373. default:
  374. // もう他の用途と確定してるので数字をそのまま
  375. add_scriptc(C_NAME);
  376. add_scriptb(l);
  377. add_scriptb(l>>8);
  378. add_scriptb(l>>16);
  379. break;
  380. }
  381. }
  382. /*==========================================
  383. * ラベルを解決する
  384. *------------------------------------------
  385. */
  386. void set_label(int l,int pos, unsigned char *script_pos)
  387. {
  388. int i,next;
  389. if(str_data[l].type==C_INT || str_data[l].type==C_PARAM)
  390. { //Prevent overwriting constants values and parameters [Skotlex]
  391. disp_error_message("invalid label name",script_pos);
  392. return;
  393. }
  394. if(str_data[l].label!=-1){
  395. disp_error_message("dup label ",script_pos);
  396. return;
  397. }
  398. str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  399. str_data[l].label=pos;
  400. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  401. next=(*(int*)(script_buf+i)) & 0x00ffffff;
  402. script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  403. script_buf[i]=pos;
  404. script_buf[i+1]=pos>>8;
  405. script_buf[i+2]=pos>>16;
  406. i=next;
  407. }
  408. }
  409. /*==========================================
  410. * スペース/コメント読み飛ばし
  411. *------------------------------------------
  412. */
  413. static unsigned char *skip_space(unsigned char *p)
  414. {
  415. while(1){
  416. while(isspace(*p))
  417. p++;
  418. if(p[0]=='/' && p[1]=='/'){
  419. while(*p && *p!='\n')
  420. p++;
  421. } else if(p[0]=='/' && p[1]=='*'){
  422. p++;
  423. while(*p && (p[-1]!='*' || p[0]!='/'))
  424. p++;
  425. if(*p) p++;
  426. } else
  427. break;
  428. }
  429. return p;
  430. }
  431. /*==========================================
  432. * 1単語スキップ
  433. *------------------------------------------
  434. */
  435. static unsigned char *skip_word(unsigned char *p)
  436. {
  437. // prefix
  438. if(*p=='.') p++;
  439. if(*p=='$') p++; // MAP鯖内共有変数用
  440. if(*p=='@') p++; // 一時的変数用(like weiss)
  441. if(*p=='#') p++; // account変数用
  442. if(*p=='#') p++; // ワールドaccount変数用
  443. while(isalnum(*p)||*p=='_'|| *p>=0x81) {
  444. if(*p>=0x81 && p[1]){
  445. p+=2;
  446. } else
  447. p++;
  448. }
  449. // postfix
  450. if(*p=='$') p++; // 文字列変数
  451. return p;
  452. }
  453. /*==========================================
  454. * エラーメッセージ出力
  455. *------------------------------------------
  456. */
  457. static void disp_error_message(const char *mes,unsigned char *pos)
  458. {
  459. error_msg = aStrdup(mes);
  460. error_pos = pos;
  461. longjmp( error_jump, 1 );
  462. }
  463. /*==========================================
  464. * 項の解析
  465. *------------------------------------------
  466. */
  467. unsigned char* parse_simpleexpr(unsigned char *p)
  468. {
  469. int i;
  470. p=skip_space(p);
  471. #ifdef DEBUG_FUNCIN
  472. if(battle_config.etc_log)
  473. ShowDebug("parse_simpleexpr %s\n",p);
  474. #endif
  475. if(*p==';' || *p==','){
  476. disp_error_message("unexpected expr end",p);
  477. exit(1);
  478. }
  479. if(*p=='('){
  480. p=parse_subexpr(p+1,-1);
  481. p=skip_space(p);
  482. if((*p++)!=')'){
  483. disp_error_message("unmatch ')'",p);
  484. exit(1);
  485. }
  486. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  487. char *np;
  488. i=strtoul((char *) p,&np,0);
  489. add_scripti(i);
  490. p=(unsigned char *) np;
  491. } else if(*p=='"'){
  492. add_scriptc(C_STR);
  493. p++;
  494. while(*p && *p!='"'){
  495. if(p[-1]<=0x7e && *p=='\\')
  496. p++;
  497. else if(*p=='\n'){
  498. disp_error_message("unexpected newline @ string",p);
  499. exit(1);
  500. }
  501. add_scriptb(*p++);
  502. }
  503. if(!*p){
  504. disp_error_message("unexpected eof @ string",p);
  505. exit(1);
  506. }
  507. add_scriptb(0);
  508. p++; //'"'
  509. } else {
  510. int c,l;
  511. char *p2;
  512. // label , register , function etc
  513. //From what I read, jA figured a better way to handle empty parenthesis '()'
  514. if(skip_word(p)==p/* && !(*p==')' && p[-1]=='(')*/){
  515. disp_error_message("unexpected character",p);
  516. exit(1);
  517. }
  518. p2=(char *) skip_word(p);
  519. c=*p2; *p2=0; // 名前をadd_strする
  520. l=add_str(p);
  521. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  522. *p2=c;
  523. p=(unsigned char *) p2;
  524. if(str_data[l].type!=C_FUNC && c=='['){
  525. // array(name[i] => getelementofarray(name,i) )
  526. add_scriptl(search_str((unsigned char *) "getelementofarray"));
  527. add_scriptc(C_ARG);
  528. add_scriptl(l);
  529. p=parse_subexpr(p+1,-1);
  530. p=skip_space(p);
  531. if((*p++)!=']'){
  532. disp_error_message("unmatch ']'",p);
  533. exit(1);
  534. }
  535. add_scriptc(C_FUNC);
  536. } else if(str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS) {
  537. add_scriptl(search_str((unsigned char*)"callsub"));
  538. add_scriptc(C_ARG);
  539. add_scriptl(l);
  540. }else
  541. add_scriptl(l);
  542. }
  543. #ifdef DEBUG_FUNCIN
  544. if(battle_config.etc_log)
  545. ShowDebug("parse_simpleexpr end %s\n",p);
  546. #endif
  547. return p;
  548. }
  549. /*==========================================
  550. * 式の解析
  551. *------------------------------------------
  552. */
  553. unsigned char* parse_subexpr(unsigned char *p,int limit)
  554. {
  555. int op,opl,len;
  556. char *tmpp;
  557. #ifdef DEBUG_FUNCIN
  558. if(battle_config.etc_log)
  559. ShowDebug("parse_subexpr %s\n",p);
  560. #endif
  561. p=skip_space(p);
  562. if(*p=='-'){
  563. tmpp=(char *) skip_space((unsigned char *) (p+1));
  564. if(*tmpp==';' || *tmpp==','){
  565. add_scriptl(LABEL_NEXTLINE);
  566. p++;
  567. return p;
  568. }
  569. }
  570. tmpp=(char *) p;
  571. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  572. p=parse_subexpr(p+1,8);
  573. add_scriptc(op);
  574. } else
  575. p=parse_simpleexpr(p);
  576. p=skip_space(p);
  577. while((
  578. (op=C_ADD,opl=6,len=1,*p=='+') ||
  579. (op=C_SUB,opl=6,len=1,*p=='-') ||
  580. (op=C_MUL,opl=7,len=1,*p=='*') ||
  581. (op=C_DIV,opl=7,len=1,*p=='/') ||
  582. (op=C_MOD,opl=7,len=1,*p=='%') ||
  583. (op=C_FUNC,opl=9,len=1,*p=='(') ||
  584. (op=C_LAND,opl=1,len=2,*p=='&' && p[1]=='&') ||
  585. (op=C_AND,opl=5,len=1,*p=='&') ||
  586. (op=C_LOR,opl=0,len=2,*p=='|' && p[1]=='|') ||
  587. (op=C_OR,opl=4,len=1,*p=='|') ||
  588. (op=C_XOR,opl=3,len=1,*p=='^') ||
  589. (op=C_EQ,opl=2,len=2,*p=='=' && p[1]=='=') ||
  590. (op=C_NE,opl=2,len=2,*p=='!' && p[1]=='=') ||
  591. (op=C_R_SHIFT,opl=5,len=2,*p=='>' && p[1]=='>') ||
  592. (op=C_GE,opl=2,len=2,*p=='>' && p[1]=='=') ||
  593. (op=C_GT,opl=2,len=1,*p=='>') ||
  594. (op=C_L_SHIFT,opl=5,len=2,*p=='<' && p[1]=='<') ||
  595. (op=C_LE,opl=2,len=2,*p=='<' && p[1]=='=') ||
  596. (op=C_LT,opl=2,len=1,*p=='<')) && opl>limit){
  597. p+=len;
  598. if(op==C_FUNC){
  599. int i=0,func=parse_cmd;
  600. const char *plist[128];
  601. if(str_data[parse_cmd].type == C_FUNC){
  602. // 通常の関数
  603. add_scriptc(C_ARG);
  604. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  605. // ユーザー定義関数呼び出し
  606. parse_cmd = search_str((unsigned char*)"callsub");
  607. i++;
  608. } else {
  609. disp_error_message(
  610. "expect command, missing function name or calling undeclared function",(unsigned char *) tmpp
  611. );
  612. exit(0);
  613. }
  614. func=parse_cmd;
  615. while(*p && *p!=')' && i<128) {
  616. plist[i]=(char *) p;
  617. p=parse_subexpr(p,-1);
  618. p=skip_space(p);
  619. if(*p==',') p++;
  620. else if(*p!=')' && script_config.warn_func_no_comma){
  621. disp_error_message("expect ',' or ')' at func params",p);
  622. }
  623. p=skip_space(p);
  624. i++;
  625. };
  626. plist[i]=(char *) p;
  627. if(*(p++)!=')'){
  628. disp_error_message("func request '(' ')'",p);
  629. exit(1);
  630. }
  631. if( str_data[func].type==C_FUNC && script_config.warn_func_mismatch_paramnum){
  632. const char *arg = buildin_func[str_data[func].val].arg;
  633. int j = 0;
  634. for (; arg[j]; j++) if (arg[j] == '*') break;
  635. if (!(i <= 1 && j == 0) && ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j))) {
  636. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  637. }
  638. }
  639. } else {
  640. p=parse_subexpr(p,opl);
  641. }
  642. add_scriptc(op);
  643. p=skip_space(p);
  644. }
  645. #ifdef DEBUG_FUNCIN
  646. if(battle_config.etc_log)
  647. ShowDebug("parse_subexpr end %s\n",p);
  648. #endif
  649. return p; /* return first untreated operator */
  650. }
  651. /*==========================================
  652. * 式の評価
  653. *------------------------------------------
  654. */
  655. unsigned char* parse_expr(unsigned char *p)
  656. {
  657. #ifdef DEBUG_FUNCIN
  658. if(battle_config.etc_log)
  659. ShowDebug("parse_expr %s\n",p);
  660. #endif
  661. switch(*p){
  662. case ')': case ';': case ':': case '[': case ']':
  663. case '}':
  664. disp_error_message("unexpected char",p);
  665. exit(1);
  666. }
  667. if(*p == '(') {
  668. unsigned char *p2 = skip_space(p + 1);
  669. if(*p2 == ')') {
  670. return p2 + 1;
  671. }
  672. }
  673. p=parse_subexpr(p,-1);
  674. #ifdef DEBUG_FUNCIN
  675. if(battle_config.etc_log)
  676. ShowDebug("parse_expr end %s\n",p);
  677. #endif
  678. return p;
  679. }
  680. /*==========================================
  681. * 行の解析
  682. *------------------------------------------
  683. */
  684. unsigned char* parse_line(unsigned char *p)
  685. {
  686. int i=0,cmd;
  687. const char *plist[128];
  688. unsigned char *p2;
  689. char end;
  690. p=skip_space(p);
  691. if(*p==';') {
  692. // if(); for(); while(); のために閉じ判定
  693. p = parse_syntax_close(p);
  694. return p+1;
  695. }
  696. if(*p==')' && parse_syntax_for_flag)
  697. return p+1;
  698. p = skip_space(p);
  699. if(p[0] == '{') {
  700. syntax.curly[syntax.curly_count].type = TYPE_NULL;
  701. syntax.curly[syntax.curly_count].count = -1;
  702. syntax.curly[syntax.curly_count].index = -1;
  703. syntax.curly_count++;
  704. return p + 1;
  705. } else if(p[0] == '}') {
  706. return parse_curly_close(p);
  707. }
  708. // 構文関連の処理
  709. p2 = parse_syntax(p);
  710. if(p2 != NULL) { return p2; }
  711. // 最初は関数名
  712. p2=(char *) p;
  713. p=parse_simpleexpr(p);
  714. p=skip_space(p);
  715. if(str_data[parse_cmd].type == C_FUNC){
  716. // 通常の関数
  717. add_scriptc(C_ARG);
  718. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  719. // ユーザー定義関数呼び出し
  720. parse_cmd = search_str((unsigned char*)"callsub");
  721. i++;
  722. } else {
  723. disp_error_message(
  724. "expect command, missing function name or calling undeclared function", (unsigned char *)p2
  725. );
  726. // exit(0);
  727. }
  728. cmd=parse_cmd;
  729. if(parse_syntax_for_flag) {
  730. end = ')';
  731. } else {
  732. end = ';';
  733. }
  734. while(p && *p && *p != end && i<128){
  735. plist[i]=(char *) p;
  736. p=parse_expr(p);
  737. p=skip_space(p);
  738. // 引数区切りの,処理
  739. if(*p==',') p++;
  740. else if(*p!=end && script_config.warn_cmd_no_comma && 0 <= i ){
  741. if(parse_syntax_for_flag) {
  742. disp_error_message("expect ',' or ')' at cmd params",p);
  743. } else {
  744. disp_error_message("expect ',' or ';' at cmd params",p);
  745. }
  746. }
  747. p=skip_space(p);
  748. i++;
  749. }
  750. plist[i]=(char *) p;
  751. if(!p || *(p++)!=end){
  752. if(parse_syntax_for_flag) {
  753. disp_error_message("need ')'",p);
  754. } else {
  755. disp_error_message("need ';'",p);
  756. }
  757. exit(1);
  758. }
  759. add_scriptc(C_FUNC);
  760. // if, for , while の閉じ判定
  761. p = parse_syntax_close(p);
  762. if( str_data[cmd].type==C_FUNC && script_config.warn_cmd_mismatch_paramnum){
  763. const char *arg=buildin_func[str_data[cmd].val].arg;
  764. int j=0;
  765. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  766. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  767. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  768. }
  769. }
  770. return p;
  771. }
  772. // { ... } の閉じ処理
  773. unsigned char* parse_curly_close(unsigned char *p) {
  774. if(syntax.curly_count <= 0) {
  775. disp_error_message("unexpected string",p);
  776. return p + 1;
  777. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
  778. syntax.curly_count--;
  779. // if, for , while の閉じ判定
  780. p = parse_syntax_close(p + 1);
  781. return p;
  782. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
  783. // switch() 閉じ判定
  784. int pos = syntax.curly_count-1;
  785. unsigned char label[256];
  786. int l;
  787. // 一時変数を消す
  788. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  789. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  790. parse_line(label);
  791. syntax.curly_count--;
  792. // 無条件で終了ポインタに移動
  793. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  794. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  795. parse_line(label);
  796. syntax.curly_count--;
  797. // 現在地のラベルを付ける
  798. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  799. l=add_str(label);
  800. set_label(l,script_pos, p);
  801. if(syntax.curly[pos].flag) {
  802. // default が存在する
  803. sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
  804. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  805. parse_line(label);
  806. syntax.curly_count--;
  807. }
  808. // 終了ラベルを付ける
  809. sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
  810. l=add_str(label);
  811. set_label(l,script_pos, p);
  812. syntax.curly_count--;
  813. return p+1;
  814. } else {
  815. disp_error_message("unexpected string",p);
  816. return p + 1;
  817. }
  818. }
  819. // 構文関連の処理
  820. // break, case, continue, default, do, for, function,
  821. // if, switch, while をこの内部で処理します。
  822. unsigned char* parse_syntax(unsigned char *p) {
  823. switch(p[0]) {
  824. case 'b':
  825. if(!strncmp(p,"break",5) && !isalpha(*(p + 5))) {
  826. // break の処理
  827. char label[256];
  828. int pos = syntax.curly_count - 1;
  829. while(pos >= 0) {
  830. if(syntax.curly[pos].type == TYPE_DO) {
  831. sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
  832. break;
  833. } else if(syntax.curly[pos].type == TYPE_FOR) {
  834. sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
  835. break;
  836. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  837. sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
  838. break;
  839. } else if(syntax.curly[pos].type == TYPE_SWITCH) {
  840. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  841. break;
  842. }
  843. pos--;
  844. }
  845. if(pos < 0) {
  846. disp_error_message("unexpected 'break'",p);
  847. } else {
  848. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  849. parse_line(label);
  850. syntax.curly_count--;
  851. }
  852. p = skip_word(p);
  853. p++;
  854. // if, for , while の閉じ判定
  855. p = parse_syntax_close(p + 1);
  856. return p;
  857. }
  858. break;
  859. case 'c':
  860. if(!strncmp(p,"case",4) && !isalpha(*(p + 4))) {
  861. // case の処理
  862. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  863. disp_error_message("unexpected 'case' ",p);
  864. return p+1;
  865. } else {
  866. char *p2;
  867. char label[256];
  868. int l;
  869. int pos = syntax.curly_count-1;
  870. if(syntax.curly[pos].count != 1) {
  871. // FALLTHRU 用のジャンプ
  872. sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
  873. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  874. parse_line(label);
  875. syntax.curly_count--;
  876. // 現在地のラベルを付ける
  877. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  878. l=add_str(label);
  879. set_label(l,script_pos, p);
  880. }
  881. // switch 判定文
  882. p = skip_word(p);
  883. p = skip_space(p);
  884. p2 = p;
  885. p = skip_word(p);
  886. p = skip_space(p);
  887. if(*p != ':') {
  888. disp_error_message("expect ':'",p);
  889. exit(1);
  890. }
  891. *p = 0;
  892. sprintf(label,"if(%s != $@__SW%x_VAL) goto __SW%x_%x;",
  893. p2,syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
  894. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  895. *p = ':';
  896. // 2回parse しないとダメ
  897. p2 = parse_line(label);
  898. parse_line(p2);
  899. syntax.curly_count--;
  900. if(syntax.curly[pos].count != 1) {
  901. // FALLTHRU 終了後のラベル
  902. sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
  903. l=add_str(label);
  904. set_label(l,script_pos,p);
  905. }
  906. // 一時変数を消す
  907. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  908. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  909. parse_line(label);
  910. syntax.curly_count--;
  911. syntax.curly[pos].count++;
  912. }
  913. return p + 1;
  914. } else if(!strncmp(p,"continue",8) && !isalpha(*(p + 8))) {
  915. // continue の処理
  916. char label[256];
  917. int pos = syntax.curly_count - 1;
  918. while(pos >= 0) {
  919. if(syntax.curly[pos].type == TYPE_DO) {
  920. sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
  921. syntax.curly[pos].flag = 1; // continue 用のリンク張るフラグ
  922. break;
  923. } else if(syntax.curly[pos].type == TYPE_FOR) {
  924. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  925. break;
  926. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  927. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  928. break;
  929. }
  930. pos--;
  931. }
  932. if(pos < 0) {
  933. disp_error_message("unexpected 'continue'",p);
  934. } else {
  935. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  936. parse_line(label);
  937. syntax.curly_count--;
  938. }
  939. p = skip_word(p);
  940. p++;
  941. // if, for , while の閉じ判定
  942. p = parse_syntax_close(p + 1);
  943. return p;
  944. }
  945. break;
  946. case 'd':
  947. if(!strncmp(p,"default",7) && !isalpha(*(p + 7))) {
  948. // switch - default の処理
  949. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  950. disp_error_message("unexpected 'default'",p);
  951. return p+1;
  952. } else if(syntax.curly[syntax.curly_count - 1].flag) {
  953. disp_error_message("dup 'default'",p);
  954. return p+1;
  955. } else {
  956. char label[256];
  957. int l;
  958. int pos = syntax.curly_count-1;
  959. // 現在地のラベルを付ける
  960. p = skip_word(p);
  961. p = skip_space(p);
  962. if(*p != ':') {
  963. disp_error_message("need ':'",p);
  964. }
  965. p++;
  966. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  967. l=add_str(label);
  968. set_label(l,script_pos,p);
  969. // 無条件で次のリンクに飛ばす
  970. sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
  971. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  972. parse_line(label);
  973. syntax.curly_count--;
  974. // default のラベルを付ける
  975. sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
  976. l=add_str(label);
  977. set_label(l,script_pos,p);
  978. syntax.curly[syntax.curly_count - 1].flag = 1;
  979. syntax.curly[pos].count++;
  980. p = skip_word(p);
  981. return p + 1;
  982. }
  983. } else if(!strncmp(p,"do",2) && !isalpha(*(p + 2))) {
  984. int l;
  985. char label[256];
  986. p=skip_word(p);
  987. p=skip_space(p);
  988. syntax.curly[syntax.curly_count].type = TYPE_DO;
  989. syntax.curly[syntax.curly_count].count = 1;
  990. syntax.curly[syntax.curly_count].index = syntax.index++;
  991. syntax.curly[syntax.curly_count].flag = 0;
  992. // 現在地のラベル形成する
  993. sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
  994. l=add_str(label);
  995. set_label(l,script_pos,p);
  996. syntax.curly_count++;
  997. return p;
  998. }
  999. break;
  1000. case 'f':
  1001. if(!strncmp(p,"for",3) && !isalpha(*(p + 3))) {
  1002. int l;
  1003. unsigned char label[256];
  1004. int pos = syntax.curly_count;
  1005. syntax.curly[syntax.curly_count].type = TYPE_FOR;
  1006. syntax.curly[syntax.curly_count].count = 1;
  1007. syntax.curly[syntax.curly_count].index = syntax.index++;
  1008. syntax.curly[syntax.curly_count].flag = 0;
  1009. syntax.curly_count++;
  1010. p=skip_word(p);
  1011. p=skip_space(p);
  1012. if(*p != '(') {
  1013. disp_error_message("need '('",p);
  1014. return p+1;
  1015. }
  1016. p++;
  1017. // 初期化文を実行する
  1018. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1019. p=parse_line(p);
  1020. syntax.curly_count--;
  1021. // 条件判断開始のラベル形成する
  1022. sprintf(label,"__FR%x_J",syntax.curly[pos].index);
  1023. l=add_str(label);
  1024. set_label(l,script_pos,p);
  1025. p=skip_space(p);
  1026. if(*p == ';') {
  1027. // for(;;) のパターンなので必ず真
  1028. ;
  1029. } else {
  1030. // 条件が偽なら終了地点に飛ばす
  1031. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1032. add_scriptl(add_str("jump_zero"));
  1033. add_scriptc(C_ARG);
  1034. p=parse_expr(p);
  1035. p=skip_space(p);
  1036. add_scriptl(add_str(label));
  1037. add_scriptc(C_FUNC);
  1038. }
  1039. if(*p != ';') {
  1040. disp_error_message("need ';'",p);
  1041. return p+1;
  1042. }
  1043. p++;
  1044. // ループ開始に飛ばす
  1045. sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
  1046. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1047. parse_line(label);
  1048. syntax.curly_count--;
  1049. // 次のループへのラベル形成する
  1050. sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
  1051. l=add_str(label);
  1052. set_label(l,script_pos,p);
  1053. // 次のループに入る時の処理
  1054. // for 最後の ')' を ';' として扱うフラグ
  1055. parse_syntax_for_flag = 1;
  1056. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1057. p=parse_line(p);
  1058. syntax.curly_count--;
  1059. parse_syntax_for_flag = 0;
  1060. // 条件判定処理に飛ばす
  1061. sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
  1062. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1063. parse_line(label);
  1064. syntax.curly_count--;
  1065. // ループ開始のラベル付け
  1066. sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
  1067. l=add_str(label);
  1068. set_label(l,script_pos,p);
  1069. return p;
  1070. } else if(!strncmp(p,"function",8) && !isalpha(*(p + 8))) {
  1071. unsigned char *func_name;
  1072. // function
  1073. p=skip_word(p);
  1074. p=skip_space(p);
  1075. // function - name
  1076. func_name = p;
  1077. p=skip_word(p);
  1078. if(*skip_space(p) == ';') {
  1079. // 関数の宣言 - 名前を登録して終わり
  1080. unsigned char c = *p;
  1081. int l;
  1082. *p = 0;
  1083. l=add_str(func_name);
  1084. *p = c;
  1085. if(str_data[l].type == C_NOP) {
  1086. str_data[l].type = C_USERFUNC;
  1087. }
  1088. return skip_space(p) + 1;
  1089. } else {
  1090. // 関数の中身
  1091. char label[256];
  1092. unsigned char c = *p;
  1093. int l;
  1094. syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
  1095. syntax.curly[syntax.curly_count].count = 1;
  1096. syntax.curly[syntax.curly_count].index = syntax.index++;
  1097. syntax.curly[syntax.curly_count].flag = 0;
  1098. syntax.curly_count++;
  1099. // 関数終了まで飛ばす
  1100. sprintf(label,"goto __FN%x_FIN;",syntax.curly[syntax.curly_count-1].index);
  1101. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1102. parse_line(label);
  1103. syntax.curly_count--;
  1104. // 関数名のラベルを付ける
  1105. *p = 0;
  1106. l=add_str(func_name);
  1107. if(str_data[l].type == C_NOP)
  1108. str_data[l].type = C_USERFUNC;
  1109. *p = c;
  1110. set_label(l,script_pos,p);
  1111. strdb_put(scriptlabel_db,func_name,(void*)script_pos);
  1112. return skip_space(p);
  1113. }
  1114. }
  1115. break;
  1116. case 'i':
  1117. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1118. // if() の処理
  1119. char label[256];
  1120. p=skip_word(p);
  1121. p=skip_space(p);
  1122. syntax.curly[syntax.curly_count].type = TYPE_IF;
  1123. syntax.curly[syntax.curly_count].count = 1;
  1124. syntax.curly[syntax.curly_count].index = syntax.index++;
  1125. syntax.curly[syntax.curly_count].flag = 0;
  1126. sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
  1127. syntax.curly_count++;
  1128. add_scriptl(add_str("jump_zero"));
  1129. add_scriptc(C_ARG);
  1130. p=parse_expr(p);
  1131. p=skip_space(p);
  1132. add_scriptl(add_str(label));
  1133. add_scriptc(C_FUNC);
  1134. return p;
  1135. }
  1136. break;
  1137. case 's':
  1138. if(!strncmp(p,"switch",6) && !isalpha(*(p + 6))) {
  1139. // switch() の処理
  1140. char label[256];
  1141. syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
  1142. syntax.curly[syntax.curly_count].count = 1;
  1143. syntax.curly[syntax.curly_count].index = syntax.index++;
  1144. syntax.curly[syntax.curly_count].flag = 0;
  1145. sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
  1146. syntax.curly_count++;
  1147. add_scriptl(add_str((unsigned char*)"set"));
  1148. add_scriptc(C_ARG);
  1149. add_scriptl(add_str(label));
  1150. p=skip_word(p);
  1151. p=skip_space(p);
  1152. p=parse_expr(p);
  1153. p=skip_space(p);
  1154. if(*p != '{') {
  1155. disp_error_message("need '{'",p);
  1156. }
  1157. add_scriptc(C_FUNC);
  1158. return p + 1;
  1159. }
  1160. break;
  1161. case 'w':
  1162. if(!strncmp(p,"while",5) && !isalpha(*(p + 5))) {
  1163. int l;
  1164. char label[256];
  1165. p=skip_word(p);
  1166. p=skip_space(p);
  1167. syntax.curly[syntax.curly_count].type = TYPE_WHILE;
  1168. syntax.curly[syntax.curly_count].count = 1;
  1169. syntax.curly[syntax.curly_count].index = syntax.index++;
  1170. syntax.curly[syntax.curly_count].flag = 0;
  1171. // 条件判断開始のラベル形成する
  1172. sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
  1173. l=add_str(label);
  1174. set_label(l,script_pos,p);
  1175. // 条件が偽なら終了地点に飛ばす
  1176. sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
  1177. add_scriptl(add_str("jump_zero"));
  1178. add_scriptc(C_ARG);
  1179. p=parse_expr(p);
  1180. p=skip_space(p);
  1181. add_scriptl(add_str(label));
  1182. add_scriptc(C_FUNC);
  1183. syntax.curly_count++;
  1184. return p;
  1185. }
  1186. break;
  1187. }
  1188. return NULL;
  1189. }
  1190. unsigned char* parse_syntax_close(unsigned char *p) {
  1191. // if(...) for(...) hoge(); のように、1度閉じられたら再度閉じられるか確認する
  1192. int flag;
  1193. do {
  1194. p = parse_syntax_close_sub(p,&flag);
  1195. } while(flag);
  1196. return p;
  1197. }
  1198. // if, for , while , do の閉じ判定
  1199. // flag == 1 : 閉じられた
  1200. // flag == 0 : 閉じられない
  1201. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
  1202. unsigned char label[256];
  1203. int pos = syntax.curly_count - 1;
  1204. int l;
  1205. *flag = 1;
  1206. if(syntax.curly_count <= 0) {
  1207. *flag = 0;
  1208. return p;
  1209. } else if(syntax.curly[pos].type == TYPE_IF) {
  1210. char *p2 = p;
  1211. // if 最終場所へ飛ばす
  1212. sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
  1213. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1214. parse_line(label);
  1215. syntax.curly_count--;
  1216. // 現在地のラベルを付ける
  1217. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1218. l=add_str(label);
  1219. set_label(l,script_pos,p);
  1220. syntax.curly[pos].count++;
  1221. p = skip_space(p);
  1222. if(!syntax.curly[pos].flag && !strncmp(p,"else",4) && !isalpha(*(p + 4))) {
  1223. // else or else - if
  1224. p = skip_word(p);
  1225. p = skip_space(p);
  1226. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1227. // else - if
  1228. p=skip_word(p);
  1229. p=skip_space(p);
  1230. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1231. add_scriptl(add_str("jump_zero"));
  1232. add_scriptc(C_ARG);
  1233. p=parse_expr(p);
  1234. p=skip_space(p);
  1235. add_scriptl(add_str(label));
  1236. add_scriptc(C_FUNC);
  1237. *flag = 0;
  1238. return p;
  1239. } else {
  1240. // else
  1241. if(!syntax.curly[pos].flag) {
  1242. syntax.curly[pos].flag = 1;
  1243. *flag = 0;
  1244. return p;
  1245. }
  1246. }
  1247. }
  1248. // if 閉じ
  1249. syntax.curly_count--;
  1250. // 最終地のラベルを付ける
  1251. sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
  1252. l=add_str(label);
  1253. set_label(l,script_pos,p);
  1254. if(syntax.curly[pos].flag == 1) {
  1255. // このifに対するelseじゃないのでポインタの位置は同じ
  1256. return p2;
  1257. }
  1258. return p;
  1259. } else if(syntax.curly[pos].type == TYPE_DO) {
  1260. int l;
  1261. char label[256];
  1262. unsigned char *p2;
  1263. if(syntax.curly[pos].flag) {
  1264. // 現在地のラベル形成する(continue でここに来る)
  1265. sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
  1266. l=add_str(label);
  1267. set_label(l,script_pos,p);
  1268. }
  1269. // 条件が偽なら終了地点に飛ばす
  1270. p = skip_space(p);
  1271. p2 = skip_word(p);
  1272. if(p2 - p != 5 || strncmp("while",p,5)) {
  1273. disp_error_message("need 'while'",p);
  1274. }
  1275. p = p2;
  1276. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1277. add_scriptl(add_str("jump_zero"));
  1278. add_scriptc(C_ARG);
  1279. p=parse_expr(p);
  1280. p=skip_space(p);
  1281. add_scriptl(add_str(label));
  1282. add_scriptc(C_FUNC);
  1283. // 開始地点に飛ばす
  1284. sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
  1285. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1286. parse_line(label);
  1287. syntax.curly_count--;
  1288. // 条件終了地点のラベル形成する
  1289. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1290. l=add_str(label);
  1291. set_label(l,script_pos,p);
  1292. p = skip_space(p);
  1293. if(*p != ';') {
  1294. disp_error_message("need ';'",p);
  1295. return p+1;
  1296. }
  1297. p++;
  1298. syntax.curly_count--;
  1299. return p;
  1300. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1301. // 次のループに飛ばす
  1302. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1303. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1304. parse_line(label);
  1305. syntax.curly_count--;
  1306. // for 終了のラベル付け
  1307. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1308. l=add_str(label);
  1309. set_label(l,script_pos,p);
  1310. syntax.curly_count--;
  1311. return p;
  1312. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1313. // while 条件判断へ飛ばす
  1314. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1315. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1316. parse_line(label);
  1317. syntax.curly_count--;
  1318. // while 終了のラベル付け
  1319. sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
  1320. l=add_str(label);
  1321. set_label(l,script_pos,p);
  1322. syntax.curly_count--;
  1323. return p;
  1324. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
  1325. int pos = syntax.curly_count-1;
  1326. char label[256];
  1327. int l;
  1328. // 戻す
  1329. sprintf(label,"return;");
  1330. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1331. parse_line(label);
  1332. syntax.curly_count--;
  1333. // 現在地のラベルを付ける
  1334. sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
  1335. l=add_str(label);
  1336. set_label(l,script_pos,p);
  1337. syntax.curly_count--;
  1338. return p + 1;
  1339. } else {
  1340. *flag = 0;
  1341. return p;
  1342. }
  1343. }
  1344. /*==========================================
  1345. * 組み込み関数の追加
  1346. *------------------------------------------
  1347. */
  1348. static void add_buildin_func(void)
  1349. {
  1350. int i,n;
  1351. for(i=0;buildin_func[i].func;i++){
  1352. n=add_str((unsigned char *) buildin_func[i].name);
  1353. str_data[n].type=C_FUNC;
  1354. str_data[n].val=i;
  1355. str_data[n].func=buildin_func[i].func;
  1356. }
  1357. }
  1358. /*==========================================
  1359. * 定数データベースの読み込み
  1360. *------------------------------------------
  1361. */
  1362. static void read_constdb(void)
  1363. {
  1364. FILE *fp;
  1365. char line[1024],name[1024],val[1024];
  1366. int n,i,type;
  1367. sprintf(line, "%s/const.txt", db_path);
  1368. fp=fopen(line, "r");
  1369. if(fp==NULL){
  1370. ShowError("can't read %s\n", line);
  1371. return ;
  1372. }
  1373. while(fgets(line,1020,fp)){
  1374. if(line[0]=='/' && line[1]=='/')
  1375. continue;
  1376. type=0;
  1377. if(sscanf(line,"%[A-Za-z0-9_],%[0-9xXA-Fa-f],%d",name,val,&type)>=2 ||
  1378. sscanf(line,"%[A-Za-z0-9_] %[0-9xXA-Fa-f] %d",name,val,&type)>=2){
  1379. for(i=0;name[i];i++)
  1380. name[i]=tolower(name[i]);
  1381. n=add_str((const unsigned char *) name);
  1382. if(type==0)
  1383. str_data[n].type=C_INT;
  1384. else
  1385. str_data[n].type=C_PARAM;
  1386. str_data[n].val= (int)strtol(val,NULL,0);
  1387. }
  1388. }
  1389. fclose(fp);
  1390. }
  1391. /*==========================================
  1392. * エラー表示
  1393. *------------------------------------------
  1394. */
  1395. const char* script_print_line( const char *p, const char *mark, int line );
  1396. void script_error(char *src,const char *file,int start_line, const char *error_msg, const char *error_pos) {
  1397. // エラーが発生した行を求める
  1398. int j;
  1399. int line = start_line;
  1400. const char *p;
  1401. const char *linestart[5] = { NULL, NULL, NULL, NULL, NULL };
  1402. for(p=src;p && *p;line++){
  1403. char *lineend=strchr(p,'\n');
  1404. if(lineend==NULL || error_pos<lineend){
  1405. break;
  1406. }
  1407. for( j = 0; j < 4; j++ ) {
  1408. linestart[j] = linestart[j+1];
  1409. }
  1410. linestart[4] = p;
  1411. p=lineend+1;
  1412. }
  1413. printf("\a\n");
  1414. printf("script error on %s line %d\n", file, line);
  1415. printf(" %s\n", error_msg);
  1416. for(j = 0; j < 5; j++ ) {
  1417. script_print_line( linestart[j], NULL, line + j - 5);
  1418. }
  1419. p = script_print_line( p, error_pos, -line);
  1420. for(j = 0; j < 5; j++) {
  1421. p = script_print_line( p, NULL, line + j + 1 );
  1422. }
  1423. }
  1424. const char* script_print_line( const char *p, const char *mark, int line ) {
  1425. int i;
  1426. if( p == NULL || !p[0] ) return NULL;
  1427. if( line < 0 )
  1428. printf("*% 5d : ", -line);
  1429. else
  1430. printf(" % 5d : ", line);
  1431. for(i=0;p[i] && p[i] != '\n';i++){
  1432. if(p + i != mark)
  1433. printf("%c",p[i]);
  1434. else
  1435. printf("\'%c\'",p[i]);
  1436. }
  1437. printf("\n");
  1438. return p+i+(p[i] == '\n' ? 1 : 0);
  1439. }
  1440. /*==========================================
  1441. * スクリプトの解析
  1442. *------------------------------------------
  1443. */
  1444. struct script_code* parse_script(unsigned char *src,const char *file,int line)
  1445. {
  1446. unsigned char *p,*tmpp;
  1447. int i;
  1448. struct script_code *code;
  1449. static int first=1;
  1450. memset(&syntax,0,sizeof(syntax));
  1451. if(first){
  1452. add_buildin_func();
  1453. read_constdb();
  1454. }
  1455. first=0;
  1456. script_buf=(unsigned char *)aCalloc(SCRIPT_BLOCK_SIZE,sizeof(unsigned char));
  1457. script_pos=0;
  1458. script_size=SCRIPT_BLOCK_SIZE;
  1459. str_data[LABEL_NEXTLINE].type=C_NOP;
  1460. str_data[LABEL_NEXTLINE].backpatch=-1;
  1461. str_data[LABEL_NEXTLINE].label=-1;
  1462. for(i=LABEL_START;i<str_num;i++){
  1463. if(
  1464. str_data[i].type==C_POS || str_data[i].type==C_NAME ||
  1465. str_data[i].type==C_USERFUNC || str_data[i].type == C_USERFUNC_POS
  1466. ){
  1467. str_data[i].type=C_NOP;
  1468. str_data[i].backpatch=-1;
  1469. str_data[i].label=-1;
  1470. }
  1471. }
  1472. //Labels must be reparsed for the script....
  1473. scriptlabel_db->clear(scriptlabel_db, NULL);
  1474. if( setjmp( error_jump ) != 0 ) {
  1475. //Restore program state when script has problems. [from jA]
  1476. script_error(src,file,line,error_msg,error_pos);
  1477. aFree( error_msg );
  1478. aFree( script_buf );
  1479. script_pos = 0;
  1480. script_size = 0;
  1481. script_buf = NULL;
  1482. for(i=LABEL_START;i<str_num;i++){
  1483. if(str_data[i].type == C_NOP) str_data[i].type = C_NAME;
  1484. }
  1485. return NULL;
  1486. }
  1487. p=src;
  1488. p=skip_space(p);
  1489. if(*p!='{'){
  1490. disp_error_message("not found '{'",p);
  1491. exit(1);
  1492. }
  1493. p++;
  1494. p = skip_space(p);
  1495. if (p && *p == '}') {
  1496. // an empty function, just return
  1497. aFree( script_buf );
  1498. script_pos = 0;
  1499. script_size = 0;
  1500. script_buf = NULL;
  1501. return NULL;
  1502. }
  1503. while (p && *p && (*p!='}' || syntax.curly_count != 0)) {
  1504. p=skip_space(p);
  1505. // labelだけ特殊処理
  1506. tmpp=skip_space(skip_word(p));
  1507. if(*tmpp==':' && !(!strncmp(p,"default:",8) && p + 7 == tmpp)){
  1508. int l,c;
  1509. c=*skip_word(p);
  1510. *skip_word(p)=0;
  1511. if(*p == 0) {
  1512. *skip_word(p)=c;
  1513. disp_error_message("label length 0 ",p);
  1514. exit(1);
  1515. }
  1516. l=add_str(p);
  1517. /* FIXME: How much does it breaks to not restore skipword(p)=c when an error occurs here?
  1518. if(str_data[l].label!=-1){
  1519. *skip_word(p)=c;
  1520. disp_error_message("dup label ",p);
  1521. exit(1);
  1522. }
  1523. */
  1524. set_label(l,script_pos,p);
  1525. strdb_put(scriptlabel_db, p, (void*)script_pos);
  1526. *skip_word(p)=c;
  1527. p=tmpp+1;
  1528. continue;
  1529. }
  1530. // 他は全部一緒くた
  1531. p=parse_line(p);
  1532. p=skip_space(p);
  1533. add_scriptc(C_EOL);
  1534. set_label(LABEL_NEXTLINE,script_pos,p);
  1535. str_data[LABEL_NEXTLINE].type=C_NOP;
  1536. str_data[LABEL_NEXTLINE].backpatch=-1;
  1537. str_data[LABEL_NEXTLINE].label=-1;
  1538. }
  1539. add_scriptc(C_NOP);
  1540. script_size = script_pos;
  1541. script_buf=(unsigned char *)aRealloc(script_buf,script_pos);
  1542. // 未解決のラベルを解決
  1543. for(i=LABEL_START;i<str_num;i++){
  1544. if(str_data[i].type==C_NOP){
  1545. int j,next;
  1546. str_data[i].type=C_NAME;
  1547. str_data[i].label=i;
  1548. for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
  1549. next=(*(int*)(script_buf+j)) & 0x00ffffff;
  1550. script_buf[j]=i;
  1551. script_buf[j+1]=i>>8;
  1552. script_buf[j+2]=i>>16;
  1553. j=next;
  1554. }
  1555. }
  1556. }
  1557. #ifdef DEBUG_DISP
  1558. for(i=0;i<script_pos;i++){
  1559. if((i&15)==0) printf("%04x : ",i);
  1560. printf("%02x ",script_buf[i]);
  1561. if((i&15)==15) printf("\n");
  1562. }
  1563. printf("\n");
  1564. #endif
  1565. code = aCalloc(1, sizeof(struct script_code));
  1566. code->script_buf = script_buf;
  1567. code->script_size = script_size;
  1568. code->script_vars = NULL;
  1569. return code;
  1570. }
  1571. //
  1572. // 実行系
  1573. //
  1574. enum {RUN = 0,STOP,END,RERUNLINE,GOTO,RETFUNC};
  1575. /*==========================================
  1576. * ridからsdへの解決
  1577. *------------------------------------------
  1578. */
  1579. struct map_session_data *script_rid2sd(struct script_state *st)
  1580. {
  1581. struct map_session_data *sd=map_id2sd(st->rid);
  1582. if(!sd){
  1583. ShowError("script_rid2sd: fatal error ! player not attached!\n");
  1584. report_src(st);
  1585. }
  1586. return sd;
  1587. }
  1588. /*==========================================
  1589. * 変数の読み取り
  1590. *------------------------------------------
  1591. */
  1592. int get_val(struct script_state*st,struct script_data* data)
  1593. {
  1594. struct map_session_data *sd=NULL;
  1595. if(data->type==C_NAME){
  1596. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  1597. char prefix=*name;
  1598. char postfix=name[strlen(name)-1];
  1599. if(not_server_variable(prefix)){
  1600. if((sd=script_rid2sd(st))==NULL)
  1601. ShowError("get_val error name?:%s\n",name);
  1602. }
  1603. if(postfix=='$'){
  1604. data->type=C_CONSTSTR;
  1605. if( prefix=='@'){
  1606. if(sd)
  1607. data->u.str = pc_readregstr(sd,data->u.num);
  1608. }else if(prefix=='$'){
  1609. data->u.str = (char *)idb_get(mapregstr_db,data->u.num);
  1610. }else if(prefix=='#'){
  1611. if( name[1]=='#'){
  1612. if(sd)
  1613. data->u.str = pc_readaccountreg2str(sd,name);
  1614. }else{
  1615. if(sd)
  1616. data->u.str = pc_readaccountregstr(sd,name);
  1617. }
  1618. }else if(prefix=='.') {
  1619. struct linkdb_node **n;
  1620. if( data->ref ) {
  1621. n = data->ref;
  1622. } else if( name[1] == '@' ) {
  1623. n = st->stack->var_function;
  1624. } else {
  1625. n = &st->script->script_vars;
  1626. }
  1627. data->u.str = linkdb_search(n, (void*)data->u.num );
  1628. }else{
  1629. if(sd)
  1630. data->u.str = pc_readglobalreg_str(sd,name);
  1631. } // [zBuffer]
  1632. /*else{
  1633. ShowWarning("script: get_val: illegal scope string variable.\n");
  1634. data->u.str = "!!ERROR!!";
  1635. }*/
  1636. if( data->u.str == NULL )
  1637. data->u.str ="";
  1638. }else{
  1639. data->type=C_INT;
  1640. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  1641. data->u.num = str_data[data->u.num&0x00ffffff].val;
  1642. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  1643. if(sd)
  1644. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  1645. }else if(prefix=='@'){
  1646. if(sd)
  1647. data->u.num = pc_readreg(sd,data->u.num);
  1648. }else if(prefix=='$'){
  1649. data->u.num = (int)idb_get(mapreg_db,data->u.num);
  1650. }else if(prefix=='#'){
  1651. if( name[1]=='#'){
  1652. if(sd)
  1653. data->u.num = pc_readaccountreg2(sd,name);
  1654. }else{
  1655. if(sd)
  1656. data->u.num = pc_readaccountreg(sd,name);
  1657. }
  1658. }else if(prefix=='.'){
  1659. struct linkdb_node **n;
  1660. if( data->ref ) {
  1661. n = data->ref;
  1662. } else if( name[1] == '@' ) {
  1663. n = st->stack->var_function;
  1664. } else {
  1665. n = &st->script->script_vars;
  1666. }
  1667. data->u.num = (int)linkdb_search(n, (void*)data->u.num);
  1668. }else{
  1669. if(sd)
  1670. data->u.num = pc_readglobalreg(sd,name);
  1671. }
  1672. }
  1673. }
  1674. return 0;
  1675. }
  1676. /*==========================================
  1677. * 変数の読み取り2
  1678. *------------------------------------------
  1679. */
  1680. void* get_val2(struct script_state*st,int num,struct linkdb_node **ref)
  1681. {
  1682. struct script_data dat;
  1683. dat.type=C_NAME;
  1684. dat.u.num=num;
  1685. dat.ref=ref;
  1686. get_val(st,&dat);
  1687. if( dat.type==C_INT ) return (void*)dat.u.num;
  1688. else return (void*)dat.u.str;
  1689. }
  1690. /*==========================================
  1691. * 変数設定用
  1692. *------------------------------------------
  1693. */
  1694. static int set_reg(struct script_state*st,struct map_session_data *sd,int num,char *name,void *v,struct linkdb_node** ref)
  1695. {
  1696. char prefix=*name;
  1697. char postfix=name[strlen(name)-1];
  1698. if( postfix=='$' ){
  1699. char *str=(char*)v;
  1700. if( prefix=='@'){
  1701. pc_setregstr(sd,num,str);
  1702. }else if(prefix=='$') {
  1703. mapreg_setregstr(num,str);
  1704. }else if(prefix=='#') {
  1705. if( name[1]=='#' )
  1706. pc_setaccountreg2str(sd,name,str);
  1707. else
  1708. pc_setaccountregstr(sd,name,str);
  1709. }else if(prefix=='.') {
  1710. char *p;
  1711. struct linkdb_node **n;
  1712. if( ref ) {
  1713. n = ref;
  1714. } else if( name[1] == '@' ) {
  1715. n = st->stack->var_function;
  1716. } else {
  1717. n = &st->script->script_vars;
  1718. }
  1719. p = linkdb_search(n, (void*)num);
  1720. if(p) {
  1721. linkdb_erase(n, (void*)num);
  1722. aFree(p);
  1723. }
  1724. if( ((char*)v)[0] )
  1725. linkdb_insert(n, (void*)num, aStrdup(v));
  1726. }else{
  1727. pc_setglobalreg_str(sd,name,str);
  1728. } // [zBuffer]
  1729. }else{
  1730. // 数値
  1731. int val = (int)v;
  1732. if(str_data[num&0x00ffffff].type==C_PARAM){
  1733. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  1734. }else if(prefix=='@') {
  1735. pc_setreg(sd,num,val);
  1736. }else if(prefix=='$') {
  1737. mapreg_setreg(num,val);
  1738. }else if(prefix=='#') {
  1739. if( name[1]=='#' )
  1740. pc_setaccountreg2(sd,name,val);
  1741. else
  1742. pc_setaccountreg(sd,name,val);
  1743. }else if(prefix == '.') {
  1744. struct linkdb_node **n;
  1745. if( ref ) {
  1746. n = ref;
  1747. } else if( name[1] == '@' ) {
  1748. n = st->stack->var_function;
  1749. } else {
  1750. n = &st->script->script_vars;
  1751. }
  1752. if( val == 0 ) {
  1753. linkdb_erase(n, (void*)num);
  1754. } else {
  1755. linkdb_replace(n, (void*)num, (void*)val);
  1756. }
  1757. }else{
  1758. pc_setglobalreg(sd,name,val);
  1759. }
  1760. }
  1761. return 0;
  1762. }
  1763. int set_var(struct map_session_data *sd, char *name, void *val)
  1764. {
  1765. return set_reg(NULL, sd, add_str((unsigned char *) name), name, val, NULL);
  1766. }
  1767. /*==========================================
  1768. * 文字列への変換
  1769. *------------------------------------------
  1770. */
  1771. char* conv_str(struct script_state *st,struct script_data *data)
  1772. {
  1773. get_val(st,data);
  1774. if(data->type==C_INT){
  1775. char *buf;
  1776. buf=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  1777. snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
  1778. data->type=C_STR;
  1779. data->u.str=buf;
  1780. #if 1
  1781. } else if(data->type==C_NAME){
  1782. // テンポラリ。本来無いはず
  1783. data->type=C_CONSTSTR;
  1784. data->u.str=str_buf+str_data[data->u.num].str;
  1785. #endif
  1786. }
  1787. return data->u.str;
  1788. }
  1789. /*==========================================
  1790. * 数値へ変換
  1791. *------------------------------------------
  1792. */
  1793. int conv_num(struct script_state *st,struct script_data *data)
  1794. {
  1795. char *p;
  1796. get_val(st,data);
  1797. if(data->type==C_STR || data->type==C_CONSTSTR){
  1798. p=data->u.str;
  1799. data->u.num = atoi(p);
  1800. if(data->type==C_STR)
  1801. aFree(p);
  1802. data->type=C_INT;
  1803. }
  1804. return data->u.num;
  1805. }
  1806. /*==========================================
  1807. * スタックへ数値をプッシュ
  1808. *------------------------------------------
  1809. */
  1810. void push_val(struct script_stack *stack,int type,int val)
  1811. {
  1812. if(stack->sp >= stack->sp_max){
  1813. stack->sp_max += 64;
  1814. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1815. sizeof(stack->stack_data[0]) * stack->sp_max);
  1816. memset(stack->stack_data + (stack->sp_max - 64), 0,
  1817. 64 * sizeof(*(stack->stack_data)));
  1818. }
  1819. // if(battle_config.etc_log)
  1820. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  1821. stack->stack_data[stack->sp].type=type;
  1822. stack->stack_data[stack->sp].u.num=val;
  1823. stack->stack_data[stack->sp].ref = NULL;
  1824. stack->sp++;
  1825. }
  1826. /*==========================================
  1827. * スタックへ数値+リファレンスをプッシュ
  1828. *------------------------------------------
  1829. */
  1830. void push_val2(struct script_stack *stack,int type,int val,struct linkdb_node** ref) {
  1831. push_val(stack,type,val);
  1832. stack->stack_data[stack->sp-1].ref = ref;
  1833. }
  1834. /*==========================================
  1835. * スタックへ文字列をプッシュ
  1836. *------------------------------------------
  1837. */
  1838. void push_str(struct script_stack *stack,int type,unsigned char *str)
  1839. {
  1840. if(stack->sp>=stack->sp_max){
  1841. stack->sp_max += 64;
  1842. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1843. sizeof(stack->stack_data[0]) * stack->sp_max);
  1844. memset(stack->stack_data + (stack->sp_max - 64), '\0',
  1845. 64 * sizeof(*(stack->stack_data)));
  1846. }
  1847. // if(battle_config.etc_log)
  1848. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  1849. stack->stack_data[stack->sp].type=type;
  1850. stack->stack_data[stack->sp].u.str=(char *) str;
  1851. stack->stack_data[stack->sp].ref = NULL;
  1852. stack->sp++;
  1853. }
  1854. /*==========================================
  1855. * スタックへ複製をプッシュ
  1856. *------------------------------------------
  1857. */
  1858. void push_copy(struct script_stack *stack,int pos)
  1859. {
  1860. switch(stack->stack_data[pos].type){
  1861. case C_CONSTSTR:
  1862. push_str(stack,C_CONSTSTR,(unsigned char *) stack->stack_data[pos].u.str);
  1863. break;
  1864. case C_STR:
  1865. push_str(stack,C_STR,(unsigned char *) aStrdup(stack->stack_data[pos].u.str));
  1866. break;
  1867. default:
  1868. push_val2(
  1869. stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num,
  1870. stack->stack_data[pos].ref
  1871. );
  1872. break;
  1873. }
  1874. }
  1875. /*==========================================
  1876. * スタックからポップ
  1877. *------------------------------------------
  1878. */
  1879. void pop_stack(struct script_stack* stack,int start,int end)
  1880. {
  1881. int i;
  1882. for(i=start;i<end;i++){
  1883. if(stack->stack_data[i].type==C_STR){
  1884. aFree(stack->stack_data[i].u.str);
  1885. stack->stack_data[i].type=C_INT; //Might not be correct, but it's done in case to prevent pointer errors later on. [Skotlex]
  1886. }
  1887. }
  1888. if(stack->sp>end){
  1889. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  1890. }
  1891. stack->sp-=end-start;
  1892. }
  1893. /*==========================================
  1894. * スクリプト依存変数、関数依存変数の解放
  1895. *------------------------------------------
  1896. */
  1897. void script_free_vars(struct linkdb_node **node) {
  1898. struct linkdb_node *n = *node;
  1899. while(n) {
  1900. char *name = str_buf + str_data[(int)(n->key)&0x00ffffff].str;
  1901. char postfix = name[strlen(name)-1];
  1902. if( postfix == '$' ) {
  1903. // 文字型変数なので、データ削除
  1904. aFree(n->data);
  1905. }
  1906. n = n->next;
  1907. }
  1908. linkdb_final( node );
  1909. }
  1910. /*==========================================
  1911. * Free's the whole stack. Invoked when clearing a character. [Skotlex]
  1912. *------------------------------------------
  1913. */
  1914. void script_free_stack(struct script_stack *stack) {
  1915. int i;
  1916. for(i = 0; i < stack->sp; i++) {
  1917. if( stack->stack_data[i].type == C_STR ) {
  1918. aFree(stack->stack_data[i].u.str);
  1919. stack->stack_data[i].type = C_INT;
  1920. } else if( i > 0 && stack->stack_data[i].type == C_RETINFO ) {
  1921. struct linkdb_node** n = (struct linkdb_node**)stack->stack_data[i-1].u.num;
  1922. script_free_vars( n );
  1923. aFree( n );
  1924. }
  1925. }
  1926. script_free_vars( stack->var_function );
  1927. aFree(stack->var_function);
  1928. aFree(stack->stack_data);
  1929. aFree(stack);
  1930. }
  1931. void script_free_code(struct script_code* code) {
  1932. script_free_vars( &code->script_vars );
  1933. aFree( code->script_buf );
  1934. aFree( code );
  1935. }
  1936. //
  1937. // 実行部main
  1938. //
  1939. /*==========================================
  1940. * コマンドの読み取り
  1941. *------------------------------------------
  1942. */
  1943. static int unget_com_data=-1;
  1944. int get_com(unsigned char *script,int *pos)
  1945. {
  1946. int i,j;
  1947. if(unget_com_data>=0){
  1948. i=unget_com_data;
  1949. unget_com_data=-1;
  1950. return i;
  1951. }
  1952. if(script[*pos]>=0x80){
  1953. return C_INT;
  1954. }
  1955. i=0; j=0;
  1956. while(script[*pos]>=0x40){
  1957. i=script[(*pos)++]<<j;
  1958. j+=6;
  1959. }
  1960. return i+(script[(*pos)++]<<j);
  1961. }
  1962. /*==========================================
  1963. * コマンドのプッシュバック
  1964. *------------------------------------------
  1965. */
  1966. void unget_com(int c)
  1967. {
  1968. if(unget_com_data!=-1){
  1969. if(battle_config.error_log)
  1970. ShowError("unget_com can back only 1 data\n");
  1971. }
  1972. unget_com_data=c;
  1973. }
  1974. /*==========================================
  1975. * 数値の所得
  1976. *------------------------------------------
  1977. */
  1978. int get_num(unsigned char *script,int *pos)
  1979. {
  1980. int i,j;
  1981. i=0; j=0;
  1982. while(script[*pos]>=0xc0){
  1983. i+=(script[(*pos)++]&0x7f)<<j;
  1984. j+=6;
  1985. }
  1986. return i+((script[(*pos)++]&0x7f)<<j);
  1987. }
  1988. /*==========================================
  1989. * スタックから値を取り出す
  1990. *------------------------------------------
  1991. */
  1992. int pop_val(struct script_state* st)
  1993. {
  1994. if(st->stack->sp<=0)
  1995. return 0;
  1996. st->stack->sp--;
  1997. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  1998. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  1999. return st->stack->stack_data[st->stack->sp].u.num;
  2000. return 0;
  2001. }
  2002. int isstr(struct script_data *c) {
  2003. if( c->type == C_STR || c->type == C_CONSTSTR )
  2004. return 1;
  2005. else if( c->type == C_NAME ) {
  2006. char *p = str_buf + str_data[c->u.num & 0xffffff].str;
  2007. char postfix = p[strlen(p)-1];
  2008. return (postfix == '$');
  2009. }
  2010. return 0;
  2011. }
  2012. /*==========================================
  2013. * 加算演算子
  2014. *------------------------------------------
  2015. */
  2016. void op_add(struct script_state* st)
  2017. {
  2018. st->stack->sp--;
  2019. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  2020. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  2021. if(isstr(&st->stack->stack_data[st->stack->sp]) || isstr(&st->stack->stack_data[st->stack->sp-1])){
  2022. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  2023. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  2024. }
  2025. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  2026. int *i1 = &st->stack->stack_data[st->stack->sp-1].u.num;
  2027. int *i2 = &st->stack->stack_data[st->stack->sp].u.num;
  2028. int ret = *i1 + *i2;
  2029. double ret_double = (double)*i1 + (double)*i2;
  2030. if(ret_double > INT_MAX|| ret_double < INT_MIN) {
  2031. ShowWarning("script::op_add overflow detected op:%d\n",C_ADD);
  2032. report_src(st);
  2033. ret = cap_value(ret, INT_MIN, INT_MAX);
  2034. }
  2035. *i1 = ret;
  2036. } else { // ssの予定
  2037. char *buf;
  2038. buf=(char *)aMallocA((strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  2039. strlen(st->stack->stack_data[st->stack->sp].u.str)+1)*sizeof(char));
  2040. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  2041. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  2042. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  2043. {
  2044. aFree(st->stack->stack_data[st->stack->sp-1].u.str);
  2045. st->stack->stack_data[st->stack->sp-1].type=C_INT;
  2046. }
  2047. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  2048. {
  2049. aFree(st->stack->stack_data[st->stack->sp].u.str);
  2050. st->stack->stack_data[st->stack->sp].type=C_INT;
  2051. }
  2052. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  2053. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  2054. }
  2055. st->stack->stack_data[st->stack->sp-1].ref = NULL;
  2056. }
  2057. /*==========================================
  2058. * 二項演算子(文字列)
  2059. *------------------------------------------
  2060. */
  2061. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  2062. {
  2063. char *s1=st->stack->stack_data[sp1].u.str,
  2064. *s2=st->stack->stack_data[sp2].u.str;
  2065. int a=0;
  2066. switch(op){
  2067. case C_EQ:
  2068. a= (strcmp(s1,s2)==0);
  2069. break;
  2070. case C_NE:
  2071. a= (strcmp(s1,s2)!=0);
  2072. break;
  2073. case C_GT:
  2074. a= (strcmp(s1,s2)> 0);
  2075. break;
  2076. case C_GE:
  2077. a= (strcmp(s1,s2)>=0);
  2078. break;
  2079. case C_LT:
  2080. a= (strcmp(s1,s2)< 0);
  2081. break;
  2082. case C_LE:
  2083. a= (strcmp(s1,s2)<=0);
  2084. break;
  2085. default:
  2086. ShowWarning("script: illegal string operator\n");
  2087. break;
  2088. }
  2089. // Because push_val() overwrite stack_data[sp1], C_STR on stack_data[sp1] won't be freed.
  2090. // So, call push_val() after freeing strings. [jA1783]
  2091. // push_val(st->stack,C_INT,a);
  2092. if(st->stack->stack_data[sp1].type==C_STR)
  2093. {
  2094. aFree(s1);
  2095. st->stack->stack_data[sp1].type=C_INT;
  2096. }
  2097. if(st->stack->stack_data[sp2].type==C_STR)
  2098. {
  2099. aFree(s2);
  2100. st->stack->stack_data[sp2].type=C_INT;
  2101. }
  2102. push_val(st->stack,C_INT,a);
  2103. }
  2104. /*==========================================
  2105. * 二項演算子(数値)
  2106. *------------------------------------------
  2107. */
  2108. void op_2num(struct script_state *st,int op,int i1,int i2)
  2109. {
  2110. int ret = 0;
  2111. double ret_double = 0;
  2112. switch(op){
  2113. case C_MOD: ret = i1 % i2; break;
  2114. case C_AND: ret = i1 & i2; break;
  2115. case C_OR: ret = i1 | i2; break;
  2116. case C_XOR: ret = i1 ^ i2; break;
  2117. case C_LAND: ret = (i1 && i2); break;
  2118. case C_LOR: ret = (i1 || i2); break;
  2119. case C_EQ: ret = (i1 == i2); break;
  2120. case C_NE: ret = (i1 != i2); break;
  2121. case C_GT: ret = (i1 > i2); break;
  2122. case C_GE: ret = (i1 >= i2); break;
  2123. case C_LT: ret = (i1 < i2); break;
  2124. case C_LE: ret = (i1 <= i2); break;
  2125. case C_R_SHIFT: ret = i1>>i2; break;
  2126. case C_L_SHIFT: ret = i1<<i2; break;
  2127. default:
  2128. switch(op) {
  2129. case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
  2130. case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
  2131. case C_DIV:
  2132. if(i2 == 0) {
  2133. printf("script::op_2num division by zero.\n");
  2134. ret = INT_MAX;
  2135. ret_double = 0; // doubleの精度が怪しいのでオーバーフロー対策を飛ばす
  2136. } else {
  2137. ret = i1 / i2; ret_double = (double)i1 / (double)i2;
  2138. }
  2139. break;
  2140. }
  2141. if(ret_double > INT_MAX || ret_double < INT_MIN) {
  2142. printf("script::op_2num overflow detected op:%d\n",op);
  2143. report_src(st);
  2144. ret = (int)cap_value(ret_double,INT_MAX,INT_MIN);
  2145. }
  2146. }
  2147. push_val(st->stack,C_INT,ret);
  2148. }
  2149. /*==========================================
  2150. * 二項演算子
  2151. *------------------------------------------
  2152. */
  2153. void op_2(struct script_state *st,int op)
  2154. {
  2155. int i1,i2;
  2156. char *s1=NULL,*s2=NULL;
  2157. i2=pop_val(st);
  2158. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2159. s2=st->stack->stack_data[st->stack->sp].u.str;
  2160. i1=pop_val(st);
  2161. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2162. s1=st->stack->stack_data[st->stack->sp].u.str;
  2163. if( s1!=NULL && s2!=NULL ){
  2164. // ss => op_2str
  2165. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  2166. }else if( s1==NULL && s2==NULL ){
  2167. // ii => op_2num
  2168. op_2num(st,op,i1,i2);
  2169. }else{
  2170. // si,is => error
  2171. ShowWarning("script: op_2: int&str, str&int not allow.\n");
  2172. report_src(st);
  2173. if(s1 && st->stack->stack_data[st->stack->sp].type == C_STR)
  2174. {
  2175. aFree(s1);
  2176. st->stack->stack_data[st->stack->sp].type = C_INT;
  2177. }
  2178. if(s2 && st->stack->stack_data[st->stack->sp+1].type == C_STR)
  2179. {
  2180. aFree(s2);
  2181. st->stack->stack_data[st->stack->sp+1].type = C_INT;
  2182. }
  2183. push_val(st->stack,C_INT,0);
  2184. }
  2185. }
  2186. /*==========================================
  2187. * 単項演算子
  2188. *------------------------------------------
  2189. */
  2190. void op_1num(struct script_state *st,int op)
  2191. {
  2192. int i1;
  2193. i1=pop_val(st);
  2194. switch(op){
  2195. case C_NEG:
  2196. i1=-i1;
  2197. break;
  2198. case C_NOT:
  2199. i1=~i1;
  2200. break;
  2201. case C_LNOT:
  2202. i1=!i1;
  2203. break;
  2204. }
  2205. push_val(st->stack,C_INT,i1);
  2206. }
  2207. /*==========================================
  2208. * 関数の実行
  2209. *------------------------------------------
  2210. */
  2211. int run_func(struct script_state *st)
  2212. {
  2213. int i,start_sp,end_sp,func;
  2214. end_sp=st->stack->sp;
  2215. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  2216. if(i==0){
  2217. if(battle_config.error_log)
  2218. ShowError("function not found\n");
  2219. // st->stack->sp=0;
  2220. st->state=END;
  2221. report_src(st);
  2222. return 1;
  2223. }
  2224. start_sp=i-1;
  2225. st->start=i-1;
  2226. st->end=end_sp;
  2227. func=st->stack->stack_data[st->start].u.num;
  2228. #ifdef DEBUG_RUN
  2229. if(battle_config.etc_log) {
  2230. ShowDebug("run_func : %s? (%d(%d)) sp=%d (%d...%d)\n",str_buf+str_data[func].str, func, str_data[func].type, st->stack->sp, st->start, st->end);
  2231. ShowDebug("stack dump :");
  2232. for(i=0;i<end_sp;i++){
  2233. switch(st->stack->stack_data[i].type){
  2234. case C_INT:
  2235. printf(" int(%d)",st->stack->stack_data[i].u.num);
  2236. break;
  2237. case C_NAME:
  2238. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num & 0xffffff].str);
  2239. break;
  2240. case C_ARG:
  2241. printf(" arg");
  2242. break;
  2243. case C_POS:
  2244. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  2245. break;
  2246. case C_STR:
  2247. printf(" str(%s)",st->stack->stack_data[i].u.str);
  2248. break;
  2249. case C_CONSTSTR:
  2250. printf(" cstr(%s)",st->stack->stack_data[i].u.str);
  2251. break;
  2252. default:
  2253. printf(" etc(%d,%d)",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  2254. }
  2255. }
  2256. printf("\n");
  2257. }
  2258. #endif
  2259. if(str_data[func].type!=C_FUNC ){
  2260. ShowMessage ("run_func: '"CL_WHITE"%s"CL_RESET"' (type %d) is not function and command!\n", str_buf+str_data[func].str, str_data[func].type);
  2261. // st->stack->sp=0;
  2262. st->state=END;
  2263. report_src(st);
  2264. return 1;
  2265. }
  2266. #ifdef DEBUG_RUN
  2267. ShowDebug("run_func : %s (func_no : %d , func_type : %d pos : 0x%x)\n",
  2268. str_buf+str_data[func].str,func,str_data[func].type,st->pos
  2269. );
  2270. #endif
  2271. if(str_data[func].func){
  2272. if (str_data[func].func(st)) //Report error
  2273. report_src(st);
  2274. } else {
  2275. if(battle_config.error_log)
  2276. ShowError("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  2277. push_val(st->stack,C_INT,0);
  2278. report_src(st);
  2279. }
  2280. // Stack's datum are used when re-run functions [Eoe]
  2281. if(st->state != RERUNLINE) {
  2282. pop_stack(st->stack,start_sp,end_sp);
  2283. }
  2284. if(st->state==RETFUNC){
  2285. // ユーザー定義関数からの復帰
  2286. int olddefsp=st->stack->defsp;
  2287. int i;
  2288. pop_stack(st->stack,st->stack->defsp,start_sp); // 復帰に邪魔なスタック削除
  2289. if(st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO){
  2290. ShowWarning("script:run_func(return) return without callfunc or callsub!\n");
  2291. st->state=END;
  2292. report_src(st);
  2293. return 1;
  2294. }
  2295. script_free_vars( st->stack->var_function );
  2296. aFree(st->stack->var_function);
  2297. i = conv_num(st,& (st->stack->stack_data[st->stack->defsp-5])); // 引数の数所得
  2298. st->pos=conv_num(st,& (st->stack->stack_data[st->stack->defsp-1])); // スクリプト位置の復元
  2299. st->script=(struct script_code*)conv_num(st,& (st->stack->stack_data[st->stack->defsp-3])); // スクリプトを復元
  2300. st->stack->var_function = (struct linkdb_node**)st->stack->stack_data[st->stack->defsp-2].u.num; // 関数依存変数
  2301. st->stack->defsp=conv_num(st,& (st->stack->stack_data[st->stack->defsp-4])); // 基準スタックポインタを復元
  2302. pop_stack(st->stack,olddefsp-5-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  2303. st->state=GOTO;
  2304. }
  2305. return 0;
  2306. }
  2307. /*==========================================
  2308. * スクリプトの実行
  2309. *------------------------------------------
  2310. */
  2311. void run_script_main(struct script_state *st);
  2312. //FIXME: Temporary replacement to locate the leak source.
  2313. //void run_script(struct script_code *rootscript,int pos,int rid,int oid)
  2314. void run_script_sub(struct script_code *rootscript,int pos,int rid,int oid, char* file, int lineno)
  2315. {
  2316. struct script_state *st;
  2317. struct map_session_data *sd=NULL;
  2318. if(rootscript==NULL || pos<0)
  2319. return;
  2320. if (rid) sd = map_id2sd(rid);
  2321. if (sd && sd->st && sd->st->scriptroot == rootscript && sd->st->pos == pos){
  2322. //Resume script.
  2323. st = sd->st;
  2324. } else {
  2325. // st = aCalloc(sizeof(struct script_state), 1);
  2326. st = _mcalloc(sizeof(struct script_state), 1, file, lineno, __func__);
  2327. // the script is different, make new script_state and stack
  2328. // st->stack = aMalloc (sizeof(struct script_stack));
  2329. st->stack = _mmalloc(sizeof(struct script_stack), file, lineno, __func__);
  2330. st->stack->sp=0;
  2331. st->stack->sp_max=64;
  2332. // st->stack->stack_data = (struct script_data *)aCalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]));
  2333. st->stack->stack_data = (struct script_data *)_mcalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]), file, lineno, __func__);
  2334. st->stack->defsp = st->stack->sp;
  2335. // st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
  2336. st->stack->var_function = _mcalloc(1, sizeof(struct linkdb_node*), file, lineno, __func__);
  2337. st->state = RUN;
  2338. st->script = rootscript;
  2339. }
  2340. st->pos = pos;
  2341. st->rid = rid;
  2342. st->oid = oid;
  2343. st->sleep.timer = -1;
  2344. run_script_main(st);
  2345. }
  2346. /*==========================================
  2347. * 指定ノードをsleep_dbから削除
  2348. *------------------------------------------
  2349. */
  2350. struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n)
  2351. {
  2352. struct linkdb_node *retnode;
  2353. if( n == NULL)
  2354. return NULL;
  2355. if( n->prev == NULL )
  2356. sleep_db = n->next;
  2357. else
  2358. n->prev->next = n->next;
  2359. if( n->next )
  2360. n->next->prev = n->prev;
  2361. retnode = n->next;
  2362. aFree( n );
  2363. return retnode; // 次のノードを返す
  2364. }
  2365. /*==========================================
  2366. * sleep用タイマー関数
  2367. *------------------------------------------
  2368. */
  2369. int run_script_timer(int tid, unsigned int tick, int id, int data)
  2370. {
  2371. struct script_state *st = (struct script_state *)data;
  2372. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  2373. struct map_session_data *sd = map_id2sd(st->rid);
  2374. if((sd && sd->char_id != id) || (st->rid && !sd))
  2375. { //Character mismatch. Cancel execution.
  2376. st->rid = 0;
  2377. st->state = END;
  2378. }
  2379. while( node && st->sleep.timer != -1 ) {
  2380. if( (int)node->key == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
  2381. script_erase_sleepdb(node);
  2382. st->sleep.timer = -1;
  2383. break;
  2384. }
  2385. node = node->next;
  2386. }
  2387. //Cancel tick value or run_script_main can get into an infinite loop by always delaying execution. [Skotlex]
  2388. st->sleep.tick = 0;
  2389. run_script_main(st);
  2390. return 0;
  2391. }
  2392. /*==========================================
  2393. * スクリプトの実行メイン部分
  2394. *------------------------------------------
  2395. */
  2396. void run_script_main(struct script_state *st)
  2397. {
  2398. int c;
  2399. int cmdcount=script_config.check_cmdcount;
  2400. int gotocount=script_config.check_gotocount;
  2401. struct map_session_data *sd;
  2402. //For backing up purposes
  2403. struct script_state *bk_st = NULL;
  2404. int bk_npcid = 0;
  2405. struct script_stack *stack=st->stack;
  2406. sd = st->rid?map_id2sd(st->rid):NULL;
  2407. if(sd){
  2408. if(sd->st != st){
  2409. bk_st = sd->st;
  2410. bk_npcid = sd->npc_id;
  2411. }
  2412. sd->st = st;
  2413. sd->npc_id = st->oid;
  2414. }
  2415. if(st->state == RERUNLINE) {
  2416. st->state = RUN;
  2417. run_func(st);
  2418. if(st->state == GOTO)
  2419. st->state = RUN;
  2420. } else if(st->state != END)
  2421. st->state = RUN;
  2422. while(st->state == RUN){
  2423. c= get_com((unsigned char *) st->script->script_buf,&st->pos);
  2424. switch(c){
  2425. case C_EOL:
  2426. if(stack->sp!=stack->defsp){
  2427. if(stack->sp > stack->defsp)
  2428. { //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex]
  2429. //Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded.
  2430. if (battle_config.etc_log)
  2431. ShowWarning("Clearing unused stack stack.sp(%d) -> default(%d)\n",stack->sp,stack->defsp);
  2432. pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section.
  2433. } else if(battle_config.error_log)
  2434. ShowError("stack.sp(%d) != default(%d)\n",stack->sp,stack->defsp);
  2435. stack->sp=stack->defsp;
  2436. }
  2437. break;
  2438. case C_INT:
  2439. push_val(stack,C_INT,get_num((unsigned char *) st->script->script_buf,&st->pos));
  2440. break;
  2441. case C_POS:
  2442. case C_NAME:
  2443. push_val(stack,c,(*(int*)(st->script->script_buf+st->pos))&0xffffff);
  2444. st->pos+=3;
  2445. break;
  2446. case C_ARG:
  2447. push_val(stack,c,0);
  2448. break;
  2449. case C_STR:
  2450. push_str(stack,C_CONSTSTR,(unsigned char *) (st->script->script_buf+st->pos));
  2451. while(st->script->script_buf[st->pos++]);
  2452. break;
  2453. case C_FUNC:
  2454. run_func(st);
  2455. if(st->state==GOTO){
  2456. st->state = RUN;
  2457. if( gotocount>0 && (--gotocount)<=0 ){
  2458. ShowError("run_script: infinity loop !\n");
  2459. st->state=END;
  2460. }
  2461. }
  2462. break;
  2463. case C_ADD:
  2464. op_add(st);
  2465. break;
  2466. case C_SUB:
  2467. case C_MUL:
  2468. case C_DIV:
  2469. case C_MOD:
  2470. case C_EQ:
  2471. case C_NE:
  2472. case C_GT:
  2473. case C_GE:
  2474. case C_LT:
  2475. case C_LE:
  2476. case C_AND:
  2477. case C_OR:
  2478. case C_XOR:
  2479. case C_LAND:
  2480. case C_LOR:
  2481. case C_R_SHIFT:
  2482. case C_L_SHIFT:
  2483. op_2(st,c);
  2484. break;
  2485. case C_NEG:
  2486. case C_NOT:
  2487. case C_LNOT:
  2488. op_1num(st,c);
  2489. break;
  2490. case C_NOP:
  2491. st->state=END;
  2492. break;
  2493. default:
  2494. if(battle_config.error_log)
  2495. ShowError("unknown command : %d @ %d\n",c,pos);
  2496. st->state=END;
  2497. break;
  2498. }
  2499. if( cmdcount>0 && (--cmdcount)<=0 ){
  2500. ShowError("run_script: infinity loop !\n");
  2501. st->state=END;
  2502. }
  2503. }
  2504. if(st->sleep.tick > 0) {
  2505. //Delay execution
  2506. st->sleep.charid = sd?sd->char_id:0;
  2507. st->sleep.timer = add_timer(gettick()+st->sleep.tick,
  2508. run_script_timer, st->sleep.charid, (int)st);
  2509. linkdb_insert(&sleep_db, (void*)st->oid, st);
  2510. //Restore previous script
  2511. if (sd) {
  2512. sd->st = bk_st;
  2513. sd->npc_id = bk_npcid;
  2514. bk_st = NULL; //Remove tag for removal.
  2515. }
  2516. }
  2517. else if(st->state != END && sd){
  2518. //Resume later (st is already attached to player).
  2519. if(bk_st)
  2520. ShowWarning("Unable to restore stack! Double continuation!\n");
  2521. } else {
  2522. //Dispose of script.
  2523. if (sd)
  2524. { //Restore previous stack and save char.
  2525. if(sd->state.using_fake_npc){
  2526. clif_clearchar_id(sd->npc_id, 0, sd->fd);
  2527. sd->state.using_fake_npc = 0;
  2528. }
  2529. //Restore previous script if any.
  2530. sd->st = bk_st;
  2531. sd->npc_id = bk_npcid;
  2532. if (!bk_st)
  2533. npc_event_dequeue(sd);
  2534. else
  2535. bk_st = NULL; //Remove tag for removal.
  2536. if (sd->state.reg_dirty&2)
  2537. intif_saveregistry(sd,2);
  2538. if (sd->state.reg_dirty&1)
  2539. intif_saveregistry(sd,1);
  2540. }
  2541. st->pos = -1;
  2542. script_free_stack (st->stack);
  2543. aFree(st);
  2544. }
  2545. if (bk_st)
  2546. { //Remove previous script
  2547. bk_st->pos = -1;
  2548. script_free_stack(bk_st->stack);
  2549. aFree(bk_st);
  2550. bk_st = NULL;
  2551. }
  2552. }
  2553. /*==========================================
  2554. * マップ変数の変更
  2555. *------------------------------------------
  2556. */
  2557. int mapreg_setreg(int num,int val)
  2558. {
  2559. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2560. int i=num>>24;
  2561. char *name=str_buf+str_data[num&0x00ffffff].str;
  2562. char tmp_str[64];
  2563. #endif
  2564. if(val!=0) {
  2565. if(idb_put(mapreg_db,num,(void*)val))
  2566. ;
  2567. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2568. else if(name[1] != '@') {
  2569. sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%d')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,val);
  2570. if(mysql_query(&mmysql_handle,tmp_sql)){
  2571. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2572. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2573. }
  2574. }
  2575. #endif
  2576. // else
  2577. } else { // [zBuffer]
  2578. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2579. if(name[1] != '@') { // Remove from database because it is unused.
  2580. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2581. if(mysql_query(&mmysql_handle,tmp_sql)){
  2582. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2583. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2584. }
  2585. }
  2586. #endif
  2587. idb_remove(mapreg_db,num);
  2588. }
  2589. mapreg_dirty=1;
  2590. return 0;
  2591. }
  2592. /*==========================================
  2593. * 文字列型マップ変数の変更
  2594. *------------------------------------------
  2595. */
  2596. int mapreg_setregstr(int num,const char *str)
  2597. {
  2598. char *p;
  2599. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2600. char tmp_str[64];
  2601. char tmp_str2[512];
  2602. int i=num>>24; // [zBuffer]
  2603. char *name=str_buf+str_data[num&0x00ffffff].str;
  2604. #endif
  2605. if( str==NULL || *str==0 ){
  2606. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2607. if(name[1] != '@') {
  2608. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2609. if(mysql_query(&mmysql_handle,tmp_sql)){
  2610. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2611. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2612. }
  2613. }
  2614. #endif
  2615. idb_remove(mapregstr_db,num);
  2616. mapreg_dirty=1;
  2617. return 0;
  2618. }
  2619. p=(char *)aMallocA((strlen(str)+1)*sizeof(char));
  2620. strcpy(p,str);
  2621. if (idb_put(mapregstr_db,num,p))
  2622. ;
  2623. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2624. else if(name[1] != '@'){ //put returned null, so we must insert.
  2625. // Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
  2626. sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%s')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,jstrescapecpy(tmp_str2,p));
  2627. if(mysql_query(&mmysql_handle,tmp_sql)){
  2628. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2629. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2630. }
  2631. }
  2632. #endif
  2633. mapreg_dirty=1;
  2634. return 0;
  2635. }
  2636. /*==========================================
  2637. * 永続的マップ変数の読み込み
  2638. *------------------------------------------
  2639. */
  2640. static int script_load_mapreg(void)
  2641. {
  2642. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2643. FILE *fp;
  2644. char line[1024];
  2645. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  2646. return -1;
  2647. while(fgets(line,sizeof(line),fp)){
  2648. char buf1[256],buf2[1024],*p;
  2649. int n,v,s,i;
  2650. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  2651. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  2652. continue;
  2653. if( buf1[strlen(buf1)-1]=='$' ){
  2654. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  2655. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2656. continue;
  2657. }
  2658. p=(char *)aMallocA((strlen(buf2) + 1)*sizeof(char));
  2659. strcpy(p,buf2);
  2660. s= add_str((unsigned char *) buf1);
  2661. idb_put(mapregstr_db,(i<<24)|s,p);
  2662. }else{
  2663. if( sscanf(line+n,"%d",&v)!=1 ){
  2664. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2665. continue;
  2666. }
  2667. s= add_str((unsigned char *) buf1);
  2668. idb_put(mapreg_db,(i<<24)|s,(void*)v);
  2669. }
  2670. }
  2671. fclose(fp);
  2672. mapreg_dirty=0;
  2673. return 0;
  2674. #else
  2675. // SQL mapreg code start [zBuffer]
  2676. /*
  2677. 0 1 2
  2678. +-------------------------+
  2679. | varname | index | value |
  2680. +-------------------------+
  2681. */
  2682. unsigned int perfomance = (unsigned int)time(NULL);
  2683. sprintf(tmp_sql,"SELECT * FROM `%s`",mapregsql_db);
  2684. ShowInfo("Querying script_load_mapreg ...\n");
  2685. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2686. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2687. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2688. return -1;
  2689. }
  2690. ShowInfo("Success! Returning results ...\n");
  2691. sql_res = mysql_store_result(&mmysql_handle);
  2692. if (sql_res) {
  2693. while ((sql_row = mysql_fetch_row(sql_res))) {
  2694. char buf1[33], *p = NULL;
  2695. int i,v,s;
  2696. strcpy(buf1,sql_row[0]);
  2697. if( buf1[strlen(buf1)-1]=='$' ){
  2698. i = atoi(sql_row[1]);
  2699. p=(char *)aMallocA((strlen(sql_row[2]) + 1)*sizeof(char));
  2700. strcpy(p,sql_row[2]);
  2701. s= add_str((unsigned char *) buf1);
  2702. idb_put(mapregstr_db,(i<<24)|s,p);
  2703. }else{
  2704. s= add_str((unsigned char *) buf1);
  2705. v= atoi(sql_row[2]);
  2706. i = atoi(sql_row[1]);
  2707. idb_put(mapreg_db,(i<<24)|s,(void *)v);
  2708. }
  2709. }
  2710. }
  2711. ShowInfo("Freeing results...\n");
  2712. mysql_free_result(sql_res);
  2713. mapreg_dirty=0;
  2714. perfomance = ((unsigned int)time(NULL) - perfomance);
  2715. ShowInfo("SQL Mapreg Loading Completed Under %d Seconds.\n",perfomance);
  2716. return 0;
  2717. #endif /* TXT_ONLY */
  2718. }
  2719. /*==========================================
  2720. * 永続的マップ変数の書き込み
  2721. *------------------------------------------
  2722. */
  2723. static int script_save_mapreg_intsub(DBKey key,void *data,va_list ap)
  2724. {
  2725. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2726. FILE *fp=va_arg(ap,FILE*);
  2727. int num=key.i&0x00ffffff, i=key.i>>24;
  2728. char *name=str_buf+str_data[num].str;
  2729. if( name[1]!='@' ){
  2730. if(i==0)
  2731. fprintf(fp,"%s\t%d\n", name, (int)data);
  2732. else
  2733. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  2734. }
  2735. return 0;
  2736. #else
  2737. int num=key.i&0x00ffffff, i=key.i>>24; // [zBuffer]
  2738. char *name=str_buf+str_data[num].str;
  2739. if ( name[1] != '@') {
  2740. sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%d' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,(int)data,mapregsql_db_varname,name,mapregsql_db_index,i);
  2741. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2742. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2743. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2744. }
  2745. }
  2746. return 0;
  2747. #endif
  2748. }
  2749. static int script_save_mapreg_strsub(DBKey key,void *data,va_list ap)
  2750. {
  2751. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2752. FILE *fp=va_arg(ap,FILE*);
  2753. int num=key.i&0x00ffffff, i=key.i>>24;
  2754. char *name=str_buf+str_data[num].str;
  2755. if( name[1]!='@' ){
  2756. if(i==0)
  2757. fprintf(fp,"%s\t%s\n", name, (char *)data);
  2758. else
  2759. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  2760. }
  2761. return 0;
  2762. #else
  2763. char tmp_str2[512];
  2764. int num=key.i&0x00ffffff, i=key.i>>24;
  2765. char *name=str_buf+str_data[num].str;
  2766. if ( name[1] != '@') {
  2767. sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%s' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,jstrescapecpy(tmp_str2,(char *)data),mapregsql_db_varname,name,mapregsql_db_index,i);
  2768. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2769. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2770. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2771. }
  2772. }
  2773. return 0;
  2774. #endif
  2775. }
  2776. static int script_save_mapreg(void)
  2777. {
  2778. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2779. FILE *fp;
  2780. int lock;
  2781. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL ) {
  2782. ShowError("script_save_mapreg: Unable to lock-open file [%s]\n",mapreg_txt);
  2783. return -1;
  2784. }
  2785. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub,fp);
  2786. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  2787. lock_fclose(fp,mapreg_txt,&lock);
  2788. #else
  2789. unsigned int perfomance = (unsigned int)time(NULL);
  2790. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub); // [zBuffer]
  2791. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub);
  2792. perfomance = ((unsigned int)time(NULL) - perfomance);
  2793. if(perfomance > 2)
  2794. ShowWarning("Slow Query: MapregSQL Saving @ %d second(s).\n", perfomance);
  2795. #endif
  2796. mapreg_dirty=0;
  2797. return 0;
  2798. }
  2799. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  2800. {
  2801. if(mapreg_dirty)
  2802. if (script_save_mapreg() == -1)
  2803. ShowError("Failed to save the mapreg data!\n");
  2804. return 0;
  2805. }
  2806. /*==========================================
  2807. *
  2808. *------------------------------------------
  2809. */
  2810. static int set_posword(char *p)
  2811. {
  2812. char* np,* str[15];
  2813. int i=0;
  2814. for(i=0;i<11;i++) {
  2815. if((np=strchr(p,','))!=NULL) {
  2816. str[i]=p;
  2817. *np=0;
  2818. p=np+1;
  2819. } else {
  2820. str[i]=p;
  2821. p+=strlen(p);
  2822. }
  2823. if(str[i])
  2824. strcpy(pos[i],str[i]);
  2825. }
  2826. return 0;
  2827. }
  2828. int script_config_read_sub(char *cfgName)
  2829. {
  2830. int i;
  2831. char line[1024],w1[1024],w2[1024];
  2832. FILE *fp;
  2833. fp=fopen(cfgName,"r");
  2834. if(fp==NULL){
  2835. ShowError("file not found: [%s]\n", cfgName);
  2836. return 1;
  2837. }
  2838. while(fgets(line,sizeof(line)-1,fp)){
  2839. if(line[0] == '/' && line[1] == '/')
  2840. continue;
  2841. i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  2842. if(i!=2)
  2843. continue;
  2844. if(strcmpi(w1,"refine_posword")==0) {
  2845. set_posword(w2);
  2846. }
  2847. else if(strcmpi(w1,"verbose_mode")==0) {
  2848. script_config.verbose_mode = battle_config_switch(w2);
  2849. }
  2850. else if(strcmpi(w1,"warn_func_no_comma")==0) {
  2851. script_config.warn_func_no_comma = battle_config_switch(w2);
  2852. }
  2853. else if(strcmpi(w1,"warn_cmd_no_comma")==0) {
  2854. script_config.warn_cmd_no_comma = battle_config_switch(w2);
  2855. }
  2856. else if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
  2857. script_config.warn_func_mismatch_paramnum = battle_config_switch(w2);
  2858. }
  2859. else if(strcmpi(w1,"warn_cmd_mismatch_paramnum")==0) {
  2860. script_config.warn_cmd_mismatch_paramnum = battle_config_switch(w2);
  2861. }
  2862. else if(strcmpi(w1,"check_cmdcount")==0) {
  2863. script_config.check_cmdcount = battle_config_switch(w2);
  2864. }
  2865. else if(strcmpi(w1,"check_gotocount")==0) {
  2866. script_config.check_gotocount = battle_config_switch(w2);
  2867. }
  2868. else if(strcmpi(w1,"event_script_type")==0) {
  2869. script_config.event_script_type = battle_config_switch(w2);
  2870. }
  2871. else if(strcmpi(w1,"event_requires_trigger")==0) {
  2872. script_config.event_requires_trigger = battle_config_switch(w2);
  2873. }
  2874. else if(strcmpi(w1,"die_event_name")==0) {
  2875. strncpy(script_config.die_event_name, w2, NAME_LENGTH-1);
  2876. if (strlen(script_config.die_event_name) != strlen(w2))
  2877. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.die_event_name);
  2878. }
  2879. else if(strcmpi(w1,"kill_pc_event_name")==0) {
  2880. strncpy(script_config.kill_pc_event_name, w2, NAME_LENGTH-1);
  2881. if (strlen(script_config.kill_pc_event_name) != strlen(w2))
  2882. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_pc_event_name);
  2883. }
  2884. else if(strcmpi(w1,"kill_mob_event_name")==0) {
  2885. strncpy(script_config.kill_mob_event_name, w2, NAME_LENGTH-1);
  2886. if (strlen(script_config.kill_mob_event_name) != strlen(w2))
  2887. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_mob_event_name);
  2888. }
  2889. else if(strcmpi(w1,"login_event_name")==0) {
  2890. strncpy(script_config.login_event_name, w2, NAME_LENGTH-1);
  2891. if (strlen(script_config.login_event_name) != strlen(w2))
  2892. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.login_event_name);
  2893. }
  2894. else if(strcmpi(w1,"logout_event_name")==0) {
  2895. strncpy(script_config.logout_event_name, w2, NAME_LENGTH-1);
  2896. if (strlen(script_config.logout_event_name) != strlen(w2))
  2897. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.logout_event_name);
  2898. }
  2899. else if(strcmpi(w1,"loadmap_event_name")==0) {
  2900. strncpy(script_config.loadmap_event_name, w2, NAME_LENGTH-1);
  2901. if (strlen(script_config.loadmap_event_name) != strlen(w2))
  2902. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.loadmap_event_name);
  2903. }
  2904. else if(strcmpi(w1,"baselvup_event_name")==0) {
  2905. strncpy(script_config.baselvup_event_name, w2, NAME_LENGTH-1);
  2906. if (strlen(script_config.baselvup_event_name) != strlen(w2))
  2907. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.baselvup_event_name);
  2908. }
  2909. else if(strcmpi(w1,"joblvup_event_name")==0) {
  2910. strncpy(script_config.joblvup_event_name, w2, NAME_LENGTH-1);
  2911. if (strlen(script_config.joblvup_event_name) != strlen(w2))
  2912. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.joblvup_event_name);
  2913. }
  2914. else if(strcmpi(w1,"import")==0){
  2915. script_config_read_sub(w2);
  2916. }
  2917. }
  2918. fclose(fp);
  2919. return 0;
  2920. }
  2921. int script_config_read(char *cfgName)
  2922. { //Script related variables should be initialized once! [Skotlex]
  2923. memset (&script_config, 0, sizeof(script_config));
  2924. script_config.verbose_mode = 0;
  2925. script_config.warn_func_no_comma = 1;
  2926. script_config.warn_cmd_no_comma = 1;
  2927. script_config.warn_func_mismatch_paramnum = 1;
  2928. script_config.warn_cmd_mismatch_paramnum = 1;
  2929. script_config.check_cmdcount = 65535;
  2930. script_config.check_gotocount = 2048;
  2931. script_config.event_script_type = 0;
  2932. script_config.event_requires_trigger = 1;
  2933. return script_config_read_sub(cfgName);
  2934. }
  2935. static int do_final_userfunc_sub (DBKey key,void *data,va_list ap){
  2936. struct script_code *code = (struct script_code *)data;
  2937. if(code){
  2938. script_free_vars( &code->script_vars );
  2939. aFree( code->script_buf );
  2940. }
  2941. return 0;
  2942. }
  2943. /*==========================================
  2944. * 終了
  2945. *------------------------------------------
  2946. */
  2947. int do_final_script()
  2948. {
  2949. if(mapreg_dirty>=0)
  2950. script_save_mapreg();
  2951. mapreg_db->destroy(mapreg_db,NULL);
  2952. mapregstr_db->destroy(mapregstr_db,NULL);
  2953. scriptlabel_db->destroy(scriptlabel_db,NULL);
  2954. userfunc_db->destroy(userfunc_db,do_final_userfunc_sub);
  2955. if(sleep_db) {
  2956. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  2957. while(n) {
  2958. struct script_state *st = (struct script_state *)n->data;
  2959. script_free_stack(st->stack);
  2960. aFree(st);
  2961. n = n->next;
  2962. }
  2963. linkdb_final(&sleep_db);
  2964. }
  2965. if (str_data)
  2966. aFree(str_data);
  2967. if (str_buf)
  2968. aFree(str_buf);
  2969. return 0;
  2970. }
  2971. /*==========================================
  2972. * 初期化
  2973. *------------------------------------------
  2974. */
  2975. int do_init_script()
  2976. {
  2977. mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
  2978. mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
  2979. userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_RELEASE_BOTH,50);
  2980. scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_ALLOW_NULL_DATA,50);
  2981. script_load_mapreg();
  2982. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  2983. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  2984. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  2985. return 0;
  2986. }
  2987. int script_reload()
  2988. {
  2989. if(mapreg_dirty>=0)
  2990. script_save_mapreg();
  2991. mapreg_db->clear(mapreg_db, NULL);
  2992. mapregstr_db->clear(mapregstr_db, NULL);
  2993. userfunc_db->clear(userfunc_db,do_final_userfunc_sub);
  2994. scriptlabel_db->clear(scriptlabel_db, NULL);
  2995. if(sleep_db) {
  2996. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  2997. while(n) {
  2998. struct script_state *st = (struct script_state *)n->data;
  2999. script_free_stack(st->stack);
  3000. aFree(st);
  3001. n = n->next;
  3002. }
  3003. linkdb_final(&sleep_db);
  3004. }
  3005. script_load_mapreg();
  3006. return 0;
  3007. }
  3008. int buildin_mes(struct script_state *st);
  3009. int buildin_goto(struct script_state *st);
  3010. int buildin_callsub(struct script_state *st);
  3011. int buildin_callfunc(struct script_state *st);
  3012. int buildin_return(struct script_state *st);
  3013. int buildin_getarg(struct script_state *st);
  3014. int buildin_next(struct script_state *st);
  3015. int buildin_close(struct script_state *st);
  3016. int buildin_close2(struct script_state *st);
  3017. int buildin_menu(struct script_state *st);
  3018. int buildin_rand(struct script_state *st);
  3019. int buildin_warp(struct script_state *st);
  3020. int buildin_areawarp(struct script_state *st);
  3021. int buildin_warpchar(struct script_state *st); // [LuzZza]
  3022. int buildin_warpparty(struct script_state *st); //[Fredzilla]
  3023. int buildin_warpguild(struct script_state *st); //[Fredzilla]
  3024. int buildin_heal(struct script_state *st);
  3025. int buildin_itemheal(struct script_state *st);
  3026. int buildin_percentheal(struct script_state *st);
  3027. int buildin_jobchange(struct script_state *st);
  3028. int buildin_jobname(struct script_state *st);
  3029. int buildin_input(struct script_state *st);
  3030. int buildin_setlook(struct script_state *st);
  3031. int buildin_set(struct script_state *st);
  3032. int buildin_setarray(struct script_state *st);
  3033. int buildin_cleararray(struct script_state *st);
  3034. int buildin_copyarray(struct script_state *st);
  3035. int buildin_getarraysize(struct script_state *st);
  3036. int buildin_deletearray(struct script_state *st);
  3037. int buildin_getelementofarray(struct script_state *st);
  3038. int buildin_getitem(struct script_state *st);
  3039. int buildin_getitem2(struct script_state *st);
  3040. int buildin_getnameditem(struct script_state *st);
  3041. int buildin_grouprandomitem(struct script_state *st);
  3042. int buildin_makeitem(struct script_state *st);
  3043. int buildin_delitem(struct script_state *st);
  3044. int buildin_delitem2(struct script_state *st);
  3045. int buildin_enableitemuse(struct script_state *st);
  3046. int buildin_disableitemuse(struct script_state *st);
  3047. int buildin_viewpoint(struct script_state *st);
  3048. int buildin_countitem(struct script_state *st);
  3049. int buildin_countitem2(struct script_state *st);
  3050. int buildin_checkweight(struct script_state *st);
  3051. int buildin_readparam(struct script_state *st);
  3052. int buildin_getcharid(struct script_state *st);
  3053. int buildin_getpartyname(struct script_state *st);
  3054. int buildin_getpartymember(struct script_state *st);
  3055. int buildin_getpartyleader(struct script_state *st);
  3056. int buildin_getguildname(struct script_state *st);
  3057. int buildin_getguildmaster(struct script_state *st);
  3058. int buildin_getguildmasterid(struct script_state *st);
  3059. int buildin_strcharinfo(struct script_state *st);
  3060. int buildin_getequipid(struct script_state *st);
  3061. int buildin_getequipname(struct script_state *st);
  3062. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  3063. int buildin_repair(struct script_state *st); // [Valaris]
  3064. int buildin_getequipisequiped(struct script_state *st);
  3065. int buildin_getequipisenableref(struct script_state *st);
  3066. int buildin_getequipisidentify(struct script_state *st);
  3067. int buildin_getequiprefinerycnt(struct script_state *st);
  3068. int buildin_getequipweaponlv(struct script_state *st);
  3069. int buildin_getequippercentrefinery(struct script_state *st);
  3070. int buildin_successrefitem(struct script_state *st);
  3071. int buildin_failedrefitem(struct script_state *st);
  3072. int buildin_cutin(struct script_state *st);
  3073. int buildin_cutincard(struct script_state *st);
  3074. int buildin_statusup(struct script_state *st);
  3075. int buildin_statusup2(struct script_state *st);
  3076. int buildin_bonus(struct script_state *st);
  3077. int buildin_bonus2(struct script_state *st);
  3078. int buildin_bonus3(struct script_state *st);
  3079. int buildin_bonus4(struct script_state *st);
  3080. int buildin_skill(struct script_state *st);
  3081. int buildin_addtoskill(struct script_state *st); // [Valaris]
  3082. int buildin_guildskill(struct script_state *st);
  3083. int buildin_getskilllv(struct script_state *st);
  3084. int buildin_getgdskilllv(struct script_state *st);
  3085. int buildin_basicskillcheck(struct script_state *st);
  3086. int buildin_getgmlevel(struct script_state *st);
  3087. int buildin_end(struct script_state *st);
  3088. int buildin_checkoption(struct script_state *st);
  3089. int buildin_setoption(struct script_state *st);
  3090. int buildin_setcart(struct script_state *st);
  3091. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  3092. int buildin_setfalcon(struct script_state *st);
  3093. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  3094. int buildin_setriding(struct script_state *st);
  3095. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  3096. int buildin_savepoint(struct script_state *st);
  3097. int buildin_gettimetick(struct script_state *st);
  3098. int buildin_gettime(struct script_state *st);
  3099. int buildin_gettimestr(struct script_state *st);
  3100. int buildin_openstorage(struct script_state *st);
  3101. int buildin_guildopenstorage(struct script_state *st);
  3102. int buildin_itemskill(struct script_state *st);
  3103. int buildin_produce(struct script_state *st);
  3104. int buildin_monster(struct script_state *st);
  3105. int buildin_areamonster(struct script_state *st);
  3106. int buildin_killmonster(struct script_state *st);
  3107. int buildin_killmonsterall(struct script_state *st);
  3108. int buildin_clone(struct script_state *st);
  3109. int buildin_doevent(struct script_state *st);
  3110. int buildin_donpcevent(struct script_state *st);
  3111. int buildin_addtimer(struct script_state *st);
  3112. int buildin_deltimer(struct script_state *st);
  3113. int buildin_addtimercount(struct script_state *st);
  3114. int buildin_initnpctimer(struct script_state *st);
  3115. int buildin_stopnpctimer(struct script_state *st);
  3116. int buildin_startnpctimer(struct script_state *st);
  3117. int buildin_setnpctimer(struct script_state *st);
  3118. int buildin_getnpctimer(struct script_state *st);
  3119. int buildin_attachnpctimer(struct script_state *st); // [celest]
  3120. int buildin_detachnpctimer(struct script_state *st); // [celest]
  3121. int buildin_playerattached(struct script_state *st); // [Skotlex]
  3122. int buildin_announce(struct script_state *st);
  3123. int buildin_mapannounce(struct script_state *st);
  3124. int buildin_areaannounce(struct script_state *st);
  3125. int buildin_getusers(struct script_state *st);
  3126. int buildin_getmapusers(struct script_state *st);
  3127. int buildin_getareausers(struct script_state *st);
  3128. int buildin_getareadropitem(struct script_state *st);
  3129. int buildin_enablenpc(struct script_state *st);
  3130. int buildin_disablenpc(struct script_state *st);
  3131. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  3132. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  3133. int buildin_hideoffnpc(struct script_state *st);
  3134. int buildin_hideonnpc(struct script_state *st);
  3135. int buildin_sc_start(struct script_state *st);
  3136. int buildin_sc_start2(struct script_state *st);
  3137. int buildin_sc_start4(struct script_state *st);
  3138. int buildin_sc_end(struct script_state *st);
  3139. int buildin_getscrate(struct script_state *st);
  3140. int buildin_debugmes(struct script_state *st);
  3141. int buildin_catchpet(struct script_state *st);
  3142. int buildin_birthpet(struct script_state *st);
  3143. int buildin_resetlvl(struct script_state *st);
  3144. int buildin_resetstatus(struct script_state *st);
  3145. int buildin_resetskill(struct script_state *st);
  3146. int buildin_skillpointcount(struct script_state *st);
  3147. int buildin_changebase(struct script_state *st);
  3148. int buildin_changesex(struct script_state *st);
  3149. int buildin_waitingroom(struct script_state *st);
  3150. int buildin_delwaitingroom(struct script_state *st);
  3151. int buildin_waitingroomkickall(struct script_state *st);
  3152. int buildin_enablewaitingroomevent(struct script_state *st);
  3153. int buildin_disablewaitingroomevent(struct script_state *st);
  3154. int buildin_getwaitingroomstate(struct script_state *st);
  3155. int buildin_warpwaitingpc(struct script_state *st);
  3156. int buildin_attachrid(struct script_state *st);
  3157. int buildin_detachrid(struct script_state *st);
  3158. int buildin_isloggedin(struct script_state *st);
  3159. int buildin_setmapflagnosave(struct script_state *st);
  3160. int buildin_setmapflag(struct script_state *st);
  3161. int buildin_removemapflag(struct script_state *st);
  3162. int buildin_pvpon(struct script_state *st);
  3163. int buildin_pvpoff(struct script_state *st);
  3164. int buildin_gvgon(struct script_state *st);
  3165. int buildin_gvgoff(struct script_state *st);
  3166. int buildin_emotion(struct script_state *st);
  3167. int buildin_maprespawnguildid(struct script_state *st);
  3168. int buildin_agitstart(struct script_state *st); // <Agit>
  3169. int buildin_agitend(struct script_state *st);
  3170. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  3171. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  3172. int buildin_getcastlename(struct script_state *st);
  3173. int buildin_getcastledata(struct script_state *st);
  3174. int buildin_setcastledata(struct script_state *st);
  3175. int buildin_requestguildinfo(struct script_state *st);
  3176. int buildin_getequipcardcnt(struct script_state *st);
  3177. int buildin_successremovecards(struct script_state *st);
  3178. int buildin_failedremovecards(struct script_state *st);
  3179. int buildin_marriage(struct script_state *st);
  3180. int buildin_wedding_effect(struct script_state *st);
  3181. int buildin_divorce(struct script_state *st);
  3182. int buildin_ispartneron(struct script_state *st); // MouseJstr
  3183. int buildin_getpartnerid(struct script_state *st); // MouseJstr
  3184. int buildin_getchildid(struct script_state *st); // Skotlex
  3185. int buildin_getmotherid(struct script_state *st); // Lupus
  3186. int buildin_getfatherid(struct script_state *st); // Lupus
  3187. int buildin_warppartner(struct script_state *st); // MouseJstr
  3188. int buildin_getitemname(struct script_state *st);
  3189. int buildin_getitemslots(struct script_state *st);
  3190. int buildin_makepet(struct script_state *st);
  3191. int buildin_getexp(struct script_state *st);
  3192. int buildin_getinventorylist(struct script_state *st);
  3193. int buildin_getskilllist(struct script_state *st);
  3194. int buildin_clearitem(struct script_state *st);
  3195. int buildin_classchange(struct script_state *st);
  3196. int buildin_misceffect(struct script_state *st);
  3197. int buildin_soundeffect(struct script_state *st);
  3198. int buildin_soundeffectall(struct script_state *st);
  3199. int buildin_setcastledata(struct script_state *st);
  3200. int buildin_mapwarp(struct script_state *st);
  3201. int buildin_inittimer(struct script_state *st);
  3202. int buildin_stoptimer(struct script_state *st);
  3203. int buildin_cmdothernpc(struct script_state *st);
  3204. int buildin_mobcount(struct script_state *st);
  3205. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3206. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  3207. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3208. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  3209. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  3210. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  3211. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  3212. //int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  3213. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Skotlex]
  3214. int buildin_petskillattack2(struct script_state *st); // pet skill attacks [Skotlex]
  3215. int buildin_petskillsupport(struct script_state *st); // pet support skill [Valaris]
  3216. int buildin_skilleffect(struct script_state *st); // skill effects [Celest]
  3217. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  3218. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  3219. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  3220. int buildin_nude(struct script_state *st); // nude [Valaris]
  3221. int buildin_atcommand(struct script_state *st); // [MouseJstr]
  3222. int buildin_charcommand(struct script_state *st); // [MouseJstr]
  3223. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  3224. int buildin_message(struct script_state *st); // [MouseJstr]
  3225. int buildin_npctalk(struct script_state *st); // [Valaris]
  3226. int buildin_hasitems(struct script_state *st); // [Valaris]
  3227. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  3228. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  3229. int buildin_npcspeed(struct script_state *st); // [Valaris]
  3230. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  3231. int buildin_npcstop(struct script_state *st); // [Valaris]
  3232. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  3233. int buildin_checkoption1(struct script_state *st); // [celest]
  3234. int buildin_checkoption2(struct script_state *st); // [celest]
  3235. int buildin_guildgetexp(struct script_state *st); // [celest]
  3236. int buildin_guildchangegm(struct script_state *st); // [Skotlex]
  3237. int buildin_logmes(struct script_state *st); // [Lupus]
  3238. int buildin_summon(struct script_state *st); // [celest]
  3239. int buildin_isnight(struct script_state *st); // [celest]
  3240. int buildin_isday(struct script_state *st); // [celest]
  3241. int buildin_isequipped(struct script_state *st); // [celest]
  3242. int buildin_isequippedcnt(struct script_state *st); // [celest]
  3243. int buildin_cardscnt(struct script_state *st); // [Lupus]
  3244. int buildin_getrefine(struct script_state *st); // [celest]
  3245. int buildin_adopt(struct script_state *st);
  3246. int buildin_night(struct script_state *st);
  3247. int buildin_day(struct script_state *st);
  3248. int buildin_getusersname(struct script_state *st); //jA commands added [Lupus]
  3249. int buildin_dispbottom(struct script_state *st);
  3250. int buildin_recovery(struct script_state *st);
  3251. int buildin_getpetinfo(struct script_state *st);
  3252. int buildin_checkequipedcard(struct script_state *st);
  3253. int buildin_globalmes(struct script_state *st);
  3254. int buildin_jump_zero(struct script_state *st);
  3255. int buildin_select(struct script_state *st);
  3256. int buildin_getmapmobs(struct script_state *st); //jA addition end
  3257. int buildin_unequip(struct script_state *st); // unequip [Spectre]
  3258. int buildin_getstrlen(struct script_state *st); //strlen [valaris]
  3259. int buildin_charisalpha(struct script_state *st);//isalpha [valaris]
  3260. int buildin_fakenpcname(struct script_state *st); // [Lance]
  3261. int buildin_compare(struct script_state *st); // Lordalfa, to bring strstr to Scripting Engine
  3262. int buildin_getiteminfo(struct script_state *st); //[Lupus] returns Items Buy / sell Price, etc info
  3263. int buildin_getequipcardid(struct script_state *st); //[Lupus] returns card id from quipped item card slot N
  3264. // [zBuffer] List of mathematics commands --->
  3265. int buildin_sqrt(struct script_state *st);
  3266. int buildin_pow(struct script_state *st);
  3267. int buildin_distance(struct script_state *st);
  3268. int buildin_checkcell(struct script_state *st);
  3269. // <--- [zBuffer] List of mathematics commands
  3270. // [zBuffer] List of dynamic var commands --->
  3271. int buildin_getd(struct script_state *st);
  3272. int buildin_setd(struct script_state *st);
  3273. // <--- [zBuffer] List of dynamic var commands
  3274. int buildin_petstat(struct script_state *st); // [Lance] Pet Stat Rq: Dubby
  3275. int buildin_callshop(struct script_state *st); // [Skotlex]
  3276. int buildin_npcshopitem(struct script_state *st); // [Lance]
  3277. int buildin_npcshopadditem(struct script_state *st);
  3278. int buildin_npcshopdelitem(struct script_state *st);
  3279. int buildin_equip(struct script_state *st);
  3280. int buildin_autoequip(struct script_state *st);
  3281. int buildin_setbattleflag(struct script_state *st);
  3282. int buildin_getbattleflag(struct script_state *st);
  3283. #ifndef TXT_ONLY
  3284. int buildin_query_sql(struct script_state *st);
  3285. int buildin_escape_sql(struct script_state *st);
  3286. #endif
  3287. int buildin_atoi(struct script_state *st);
  3288. int buildin_axtoi(struct script_state *st);
  3289. // [zBuffer] List of player cont commands --->
  3290. int buildin_rid2name(struct script_state *st);
  3291. int buildin_pcfollow(struct script_state *st);
  3292. int buildin_pcstopfollow(struct script_state *st);
  3293. int buildin_pcblockmove(struct script_state *st);
  3294. // <--- [zBuffer] List of player cont commands
  3295. // [zBuffer] List of mob control commands --->
  3296. int buildin_mobspawn(struct script_state *st);
  3297. int buildin_mobremove(struct script_state *st);
  3298. int buildin_getmobdata(struct script_state *st);
  3299. int buildin_setmobdata(struct script_state *st);
  3300. int buildin_mobassist(struct script_state *st);
  3301. int buildin_mobattach(struct script_state *st);
  3302. int buildin_unitwalk(struct script_state *st);
  3303. int buildin_unitkill(struct script_state *st);
  3304. int buildin_unitwarp(struct script_state *st);
  3305. int buildin_unitattack(struct script_state *st);
  3306. int buildin_unitstop(struct script_state *st);
  3307. int buildin_unittalk(struct script_state *st);
  3308. int buildin_unitemote(struct script_state *st);
  3309. int buildin_unitdeadsit(struct script_state *st);
  3310. int buildin_unitskilluseid(struct script_state *st); // originally by Qamera [celest]
  3311. int buildin_unitskillusepos(struct script_state *st); // originally by Qamera [celest]
  3312. // <--- [zBuffer] List of mob control commands
  3313. int buildin_sleep(struct script_state *st);
  3314. int buildin_sleep2(struct script_state *st);
  3315. int buildin_awake(struct script_state *st);
  3316. int buildin_getvariableofnpc(struct script_state *st);
  3317. // [blackhole89] -->
  3318. int buildin_warpportal(struct script_state *st);
  3319. // <-- [blackhole89]
  3320. int buildin_homunculus_evolution(struct script_state *st) ; //[orn]
  3321. int buildin_setitemscript(struct script_state *st);
  3322. int buildin_disguise(struct script_state *st);
  3323. int buildin_undisguise(struct script_state *st);
  3324. int buildin_getmonsterinfo(struct script_state *st); // [Lupus]
  3325. #ifdef PCRE_SUPPORT
  3326. int buildin_defpattern(struct script_state *st); // MouseJstr
  3327. int buildin_activatepset(struct script_state *st); // MouseJstr
  3328. int buildin_deactivatepset(struct script_state *st); // MouseJstr
  3329. int buildin_deletepset(struct script_state *st); // MouseJstr
  3330. #endif
  3331. struct script_function buildin_func[] = {
  3332. {buildin_mes,"mes","s"},
  3333. {buildin_next,"next",""},
  3334. {buildin_close,"close",""},
  3335. {buildin_close2,"close2",""},
  3336. {buildin_menu,"menu","*"},
  3337. {buildin_goto,"goto","l"},
  3338. {buildin_callsub,"callsub","i*"},
  3339. {buildin_callfunc,"callfunc","s*"},
  3340. {buildin_return,"return","*"},
  3341. {buildin_getarg,"getarg","i"},
  3342. {buildin_jobchange,"jobchange","i*"},
  3343. {buildin_jobname,"jobname","i"},
  3344. {buildin_input,"input","*"},
  3345. {buildin_warp,"warp","sii"},
  3346. {buildin_areawarp,"areawarp","siiiisii"},
  3347. {buildin_warpchar,"warpchar","siii"}, // [LuzZza]
  3348. {buildin_warpparty,"warpparty","siii"}, // [Fredzilla]
  3349. {buildin_warpguild,"warpguild","siii"}, // [Fredzilla]
  3350. {buildin_setlook,"setlook","ii"},
  3351. {buildin_set,"set","ii"},
  3352. {buildin_setarray,"setarray","ii*"},
  3353. {buildin_cleararray,"cleararray","iii"},
  3354. {buildin_copyarray,"copyarray","iii"},
  3355. {buildin_getarraysize,"getarraysize","i"},
  3356. {buildin_deletearray,"deletearray","ii"},
  3357. {buildin_getelementofarray,"getelementofarray","ii"},
  3358. {buildin_getitem,"getitem","ii**"},
  3359. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  3360. {buildin_getnameditem,"getnameditem","is"},
  3361. {buildin_grouprandomitem,"groupranditem","i"},
  3362. {buildin_makeitem,"makeitem","iisii"},
  3363. {buildin_delitem,"delitem","ii"},
  3364. {buildin_delitem2,"delitem2","iiiiiiiii"},
  3365. {buildin_enableitemuse,"enable_items",""},
  3366. {buildin_disableitemuse,"disable_items",""},
  3367. {buildin_cutin,"cutin","si"},
  3368. {buildin_cutincard,"cutincard","i"},
  3369. {buildin_viewpoint,"viewpoint","iiiii"},
  3370. {buildin_heal,"heal","ii"},
  3371. {buildin_itemheal,"itemheal","ii"},
  3372. {buildin_percentheal,"percentheal","ii"},
  3373. {buildin_rand,"rand","i*"},
  3374. {buildin_countitem,"countitem","i"},
  3375. {buildin_countitem2,"countitem2","iiiiiiii"},
  3376. {buildin_checkweight,"checkweight","ii"},
  3377. {buildin_readparam,"readparam","i*"},
  3378. {buildin_getcharid,"getcharid","i*"},
  3379. {buildin_getpartyname,"getpartyname","i"},
  3380. {buildin_getpartymember,"getpartymember","i*"},
  3381. {buildin_getpartyleader,"getpartyleader","i*"},
  3382. {buildin_getguildname,"getguildname","i"},
  3383. {buildin_getguildmaster,"getguildmaster","i"},
  3384. {buildin_getguildmasterid,"getguildmasterid","i"},
  3385. {buildin_strcharinfo,"strcharinfo","i"},
  3386. {buildin_getequipid,"getequipid","i"},
  3387. {buildin_getequipname,"getequipname","i"},
  3388. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  3389. {buildin_repair,"repair","i"}, // [Valaris]
  3390. {buildin_getequipisequiped,"getequipisequiped","i"},
  3391. {buildin_getequipisenableref,"getequipisenableref","i"},
  3392. {buildin_getequipisidentify,"getequipisidentify","i"},
  3393. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  3394. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  3395. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  3396. {buildin_successrefitem,"successrefitem","i"},
  3397. {buildin_failedrefitem,"failedrefitem","i"},
  3398. {buildin_statusup,"statusup","i"},
  3399. {buildin_statusup2,"statusup2","ii"},
  3400. {buildin_bonus,"bonus","ii"},
  3401. {buildin_bonus2,"bonus2","iii"},
  3402. {buildin_bonus3,"bonus3","iiii"},
  3403. {buildin_bonus4,"bonus4","iiiii"},
  3404. {buildin_skill,"skill","ii*"},
  3405. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  3406. {buildin_guildskill,"guildskill","ii"},
  3407. {buildin_getskilllv,"getskilllv","i"},
  3408. {buildin_getgdskilllv,"getgdskilllv","ii"},
  3409. {buildin_basicskillcheck,"basicskillcheck","*"},
  3410. {buildin_getgmlevel,"getgmlevel","*"},
  3411. {buildin_end,"end",""},
  3412. // {buildin_end,"break",""}, this might confuse advanced scripting support [Eoe]
  3413. {buildin_checkoption,"checkoption","i"},
  3414. {buildin_setoption,"setoption","i*"},
  3415. {buildin_setcart,"setcart",""},
  3416. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  3417. {buildin_setfalcon,"setfalcon",""},
  3418. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3419. {buildin_setriding,"setriding",""},
  3420. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3421. {buildin_savepoint,"save","sii"},
  3422. {buildin_savepoint,"savepoint","sii"},
  3423. {buildin_gettimetick,"gettimetick","i"},
  3424. {buildin_gettime,"gettime","i"},
  3425. {buildin_gettimestr,"gettimestr","si"},
  3426. {buildin_openstorage,"openstorage",""},
  3427. {buildin_guildopenstorage,"guildopenstorage","*"},
  3428. {buildin_itemskill,"itemskill","iis"},
  3429. {buildin_produce,"produce","i"},
  3430. {buildin_monster,"monster","siisii*"},
  3431. {buildin_areamonster,"areamonster","siiiisii*"},
  3432. {buildin_killmonster,"killmonster","ss"},
  3433. {buildin_killmonsterall,"killmonsterall","s"},
  3434. {buildin_clone,"clone","siisi*"},
  3435. {buildin_doevent,"doevent","s"},
  3436. {buildin_donpcevent,"donpcevent","s"},
  3437. {buildin_addtimer,"addtimer","is"},
  3438. {buildin_deltimer,"deltimer","s"},
  3439. {buildin_addtimercount,"addtimercount","si"},
  3440. {buildin_initnpctimer,"initnpctimer","*"},
  3441. {buildin_stopnpctimer,"stopnpctimer","*"},
  3442. {buildin_startnpctimer,"startnpctimer","*"},
  3443. {buildin_setnpctimer,"setnpctimer","*"},
  3444. {buildin_getnpctimer,"getnpctimer","i*"},
  3445. {buildin_attachnpctimer,"attachnpctimer","*"}, // attached the player id to the npc timer [Celest]
  3446. {buildin_detachnpctimer,"detachnpctimer","*"}, // detached the player id from the npc timer [Celest]
  3447. {buildin_playerattached,"playerattached",""}, // returns id of the current attached player. [Skotlex]
  3448. {buildin_announce,"announce","si*"},
  3449. {buildin_mapannounce,"mapannounce","ssi*"},
  3450. {buildin_areaannounce,"areaannounce","siiiisi*"},
  3451. {buildin_getusers,"getusers","i"},
  3452. {buildin_getmapusers,"getmapusers","s"},
  3453. {buildin_getareausers,"getareausers","siiii"},
  3454. {buildin_getareadropitem,"getareadropitem","siiiii"},
  3455. {buildin_enablenpc,"enablenpc","s"},
  3456. {buildin_disablenpc,"disablenpc","s"},
  3457. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  3458. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  3459. {buildin_hideoffnpc,"hideoffnpc","s"},
  3460. {buildin_hideonnpc,"hideonnpc","s"},
  3461. {buildin_sc_start,"sc_start","iii*"},
  3462. {buildin_sc_start2,"sc_start2","iiii*"},
  3463. {buildin_sc_start4,"sc_start4","iiiiii*"},
  3464. {buildin_sc_end,"sc_end","i"},
  3465. {buildin_getscrate,"getscrate","ii*"},
  3466. {buildin_debugmes,"debugmes","s"},
  3467. {buildin_catchpet,"pet","i"},
  3468. {buildin_birthpet,"bpet",""},
  3469. {buildin_resetlvl,"resetlvl","i"},
  3470. {buildin_resetstatus,"resetstatus",""},
  3471. {buildin_resetskill,"resetskill",""},
  3472. {buildin_skillpointcount,"skillpointcount",""},
  3473. {buildin_changebase,"changebase","i"},
  3474. {buildin_changesex,"changesex",""},
  3475. {buildin_waitingroom,"waitingroom","si*"},
  3476. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  3477. {buildin_delwaitingroom,"delwaitingroom","*"},
  3478. {buildin_waitingroomkickall,"kickwaitingroomall","*"},
  3479. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  3480. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  3481. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  3482. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  3483. {buildin_attachrid,"attachrid","i"},
  3484. {buildin_detachrid,"detachrid",""},
  3485. {buildin_isloggedin,"isloggedin","i"},
  3486. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  3487. {buildin_setmapflag,"setmapflag","si*"},
  3488. {buildin_removemapflag,"removemapflag","si"},
  3489. {buildin_pvpon,"pvpon","s"},
  3490. {buildin_pvpoff,"pvpoff","s"},
  3491. {buildin_gvgon,"gvgon","s"},
  3492. {buildin_gvgoff,"gvgoff","s"},
  3493. {buildin_emotion,"emotion","i*"},
  3494. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  3495. {buildin_agitstart,"agitstart",""}, // <Agit>
  3496. {buildin_agitend,"agitend",""},
  3497. {buildin_agitcheck,"agitcheck","i"}, // <Agitcheck>
  3498. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  3499. {buildin_getcastlename,"getcastlename","s"},
  3500. {buildin_getcastledata,"getcastledata","si*"},
  3501. {buildin_setcastledata,"setcastledata","sii"},
  3502. {buildin_requestguildinfo,"requestguildinfo","i*"},
  3503. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  3504. {buildin_successremovecards,"successremovecards","i"},
  3505. {buildin_failedremovecards,"failedremovecards","ii"},
  3506. {buildin_marriage,"marriage","s"},
  3507. {buildin_wedding_effect,"wedding",""},
  3508. {buildin_divorce,"divorce",""},
  3509. {buildin_ispartneron,"ispartneron",""},
  3510. {buildin_getpartnerid,"getpartnerid",""},
  3511. {buildin_getchildid,"getchildid",""},
  3512. {buildin_getmotherid,"getmotherid",""},
  3513. {buildin_getfatherid,"getfatherid",""},
  3514. {buildin_warppartner,"warppartner","sii"},
  3515. {buildin_getitemname,"getitemname","i"},
  3516. {buildin_getitemslots,"getitemslots","i"},
  3517. {buildin_makepet,"makepet","i"},
  3518. {buildin_getexp,"getexp","ii"},
  3519. {buildin_getinventorylist,"getinventorylist",""},
  3520. {buildin_getskilllist,"getskilllist",""},
  3521. {buildin_clearitem,"clearitem",""},
  3522. {buildin_classchange,"classchange","ii"},
  3523. {buildin_misceffect,"misceffect","i"},
  3524. {buildin_soundeffect,"soundeffect","si"},
  3525. {buildin_soundeffectall,"soundeffectall","si*"}, // SoundEffectAll [Codemaster]
  3526. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  3527. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  3528. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  3529. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  3530. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  3531. {buildin_petloot,"petloot","i"}, // [Valaris]
  3532. {buildin_petheal,"petheal","iiii"}, // [Valaris]
  3533. // {buildin_petmag,"petmag","iiii"}, // [Valaris]
  3534. {buildin_petskillattack,"petskillattack","iiii"}, // [Skotlex]
  3535. {buildin_petskillattack2,"petskillattack2","iiiii"}, // [Valaris]
  3536. {buildin_petskillsupport,"petskillsupport","iiiii"}, // [Skotlex]
  3537. {buildin_skilleffect,"skilleffect","ii"}, // skill effect [Celest]
  3538. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  3539. {buildin_specialeffect,"specialeffect","i*"}, // npc skill effect [Valaris]
  3540. {buildin_specialeffect2,"specialeffect2","i*"}, // skill effect on players[Valaris]
  3541. {buildin_nude,"nude",""}, // nude command [Valaris]
  3542. {buildin_mapwarp,"mapwarp","ssii"}, // Added by RoVeRT
  3543. {buildin_inittimer,"inittimer",""},
  3544. {buildin_stoptimer,"stoptimer",""},
  3545. {buildin_cmdothernpc,"cmdothernpc","ss"},
  3546. {buildin_atcommand,"atcommand","*"}, // [MouseJstr]
  3547. {buildin_charcommand,"charcommand","*"}, // [MouseJstr]
  3548. {buildin_movenpc,"movenpc","sii"}, // [MouseJstr]
  3549. {buildin_message,"message","s*"}, // [MouseJstr]
  3550. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  3551. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  3552. {buildin_mobcount,"mobcount","ss"},
  3553. {buildin_getlook,"getlook","i"},
  3554. {buildin_getsavepoint,"getsavepoint","i"},
  3555. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  3556. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  3557. {buildin_npcstop,"npcstop",""}, // [Valaris]
  3558. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  3559. {buildin_checkoption1,"checkoption1","i"},
  3560. {buildin_checkoption2,"checkoption2","i"},
  3561. {buildin_guildgetexp,"guildgetexp","i"},
  3562. {buildin_guildchangegm,"guildchangegm","is"},
  3563. {buildin_logmes,"logmes","s"}, //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
  3564. {buildin_summon,"summon","si*"}, // summons a slave monster [Celest]
  3565. {buildin_isnight,"isnight",""}, // check whether it is night time [Celest]
  3566. {buildin_isday,"isday",""}, // check whether it is day time [Celest]
  3567. {buildin_isequipped,"isequipped","i*"}, // check whether another item/card has been equipped [Celest]
  3568. {buildin_isequippedcnt,"isequippedcnt","i*"}, // check how many items/cards are being equipped [Celest]
  3569. {buildin_cardscnt,"cardscnt","i*"}, // check how many items/cards are being equipped in the same arm [Lupus]
  3570. {buildin_getrefine,"getrefine","*"}, // returns the refined number of the current item, or an item with index specified [celest]
  3571. {buildin_adopt,"adopt","sss"}, // allows 2 parents to adopt a child
  3572. {buildin_night,"night",""}, // sets the server to night time
  3573. {buildin_day,"day",""}, // sets the server to day time
  3574. #ifdef PCRE_SUPPORT
  3575. {buildin_defpattern, "defpattern", "iss"}, // Define pattern to listen for [MouseJstr]
  3576. {buildin_activatepset, "activatepset", "i"}, // Activate a pattern set [MouseJstr]
  3577. {buildin_deactivatepset, "deactivatepset", "i"}, // Deactive a pattern set [MouseJstr]
  3578. {buildin_deletepset, "deletepset", "i"}, // Delete a pattern set [MouseJstr]
  3579. #endif
  3580. {buildin_dispbottom,"dispbottom","s"}, //added from jA [Lupus]
  3581. {buildin_getusersname,"getusersname","*"},
  3582. {buildin_recovery,"recovery",""},
  3583. {buildin_getpetinfo,"getpetinfo","i"},
  3584. {buildin_checkequipedcard,"checkequipedcard","i"},
  3585. {buildin_jump_zero,"jump_zero","ii"}, //for future jA script compatibility
  3586. {buildin_select,"select","*"}, //for future jA script compatibility
  3587. {buildin_globalmes,"globalmes","s*"},
  3588. {buildin_getmapmobs,"getmapmobs","s"}, //end jA addition
  3589. {buildin_unequip,"unequip","i"}, // unequip command [Spectre]
  3590. {buildin_getstrlen,"getstrlen","s"}, //strlen [Valaris]
  3591. {buildin_charisalpha,"charisalpha","si"}, //isalpha [Valaris]
  3592. {buildin_fakenpcname,"fakenpcname","ssi"}, // [Lance]
  3593. {buildin_compare,"compare","ss"}, // Lordalfa - To bring strstr to scripting Engine.
  3594. {buildin_getiteminfo,"getiteminfo","ii"}, //[Lupus] returns Items Buy / sell Price, etc info
  3595. {buildin_getequipcardid,"getequipcardid","ii"}, //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
  3596. // [zBuffer] List of mathematics commands --->
  3597. {buildin_sqrt,"sqrt","i"},
  3598. {buildin_pow,"pow","ii"},
  3599. {buildin_distance,"distance","iiii"},
  3600. {buildin_checkcell,"checkcell","siii"},
  3601. // <--- [zBuffer] List of mathematics commands
  3602. // [zBuffer] List of dynamic var commands --->
  3603. {buildin_getd,"getd","*"},
  3604. {buildin_setd,"setd","*"},
  3605. // <--- [zBuffer] List of dynamic var commands
  3606. {buildin_petstat,"petstat","i"},
  3607. {buildin_callshop,"callshop","si"}, // [Skotlex]
  3608. {buildin_npcshopitem,"npcshopitem","sii*"}, // [Lance]
  3609. {buildin_npcshopadditem,"npcshopadditem","sii*"},
  3610. {buildin_npcshopdelitem,"npcshopdelitem","si*"},
  3611. {buildin_equip,"equip","i"},
  3612. {buildin_autoequip,"autoequip","ii"},
  3613. {buildin_setbattleflag,"setbattleflag","ss"},
  3614. {buildin_getbattleflag,"getbattleflag","s"},
  3615. {buildin_setitemscript,"setitemscript","is"}, //Set NEW item bonus script. Lupus
  3616. {buildin_disguise,"disguise","i"}, //disguise player. Lupus
  3617. {buildin_undisguise,"undisguise","i"}, //undisguise player. Lupus
  3618. {buildin_getmonsterinfo,"getmonsterinfo","ii"}, //Lupus
  3619. {buildin_axtoi,"axtoi","s"},
  3620. #ifndef TXT_ONLY
  3621. {buildin_query_sql, "query_sql", "s*"},
  3622. {buildin_escape_sql, "escape_sql", "s"},
  3623. #endif
  3624. {buildin_atoi,"atoi","s"},
  3625. // [zBuffer] List of player cont commands --->
  3626. {buildin_rid2name,"rid2name","i"},
  3627. {buildin_pcfollow,"pcfollow","ii"},
  3628. {buildin_pcstopfollow,"pcstopfollow","i"},
  3629. {buildin_pcblockmove,"pcblockmove","ii"},
  3630. // <--- [zBuffer] List of player cont commands
  3631. // [zBuffer] List of mob control commands --->
  3632. {buildin_mobspawn,"mobspawn","*"},
  3633. {buildin_mobremove,"mobremove","i"},
  3634. {buildin_getmobdata,"getmobdata","i*"},
  3635. {buildin_setmobdata,"setmobdata","iii"},
  3636. {buildin_mobassist,"mobassist","i*"},
  3637. {buildin_mobattach,"mobattach","i*"},
  3638. {buildin_unitwalk,"unitwalk","i*"},
  3639. {buildin_unitkill,"unitkill","i"},
  3640. {buildin_unitwarp,"unitwarp","isii"},
  3641. {buildin_unitattack,"unitattack","i*"},
  3642. {buildin_unitstop,"unitstop","i"},
  3643. {buildin_unittalk,"unittalk","is"},
  3644. {buildin_unitemote,"unitemote","ii"},
  3645. {buildin_unitdeadsit,"unitdeadsit","ii"},
  3646. {buildin_unitskilluseid,"unitskilluseid","iii*"}, // originally by Qamera [Celest]
  3647. {buildin_unitskillusepos,"unitskillusepos","iiiii"}, // [Celest]
  3648. // <--- [zBuffer] List of mob control commands
  3649. {buildin_sleep,"sleep","i"},
  3650. {buildin_sleep2,"sleep2","i"},
  3651. {buildin_awake,"awake","s"},
  3652. {buildin_getvariableofnpc,"getvariableofnpc","is"},
  3653. // [blackhole89] -->
  3654. {buildin_warpportal,"warpportal","iisii"},
  3655. // <--- [blackhole89]
  3656. {buildin_homunculus_evolution,"homevolution",""}, //[orn]
  3657. {NULL,NULL,NULL},
  3658. };
  3659. /*==========================================
  3660. *
  3661. *------------------------------------------
  3662. */
  3663. int buildin_mes(struct script_state *st)
  3664. {
  3665. conv_str(st,& (st->stack->stack_data[st->start+2]));
  3666. clif_scriptmes(script_rid2sd(st),st->oid,st->stack->stack_data[st->start+2].u.str);
  3667. return 0;
  3668. }
  3669. /*==========================================
  3670. *
  3671. *------------------------------------------
  3672. */
  3673. int buildin_goto(struct script_state *st)
  3674. {
  3675. int pos;
  3676. if( st->stack->stack_data[st->start+2].type!=C_POS){
  3677. ShowMessage("script: goto: not label!\n");
  3678. st->state=END;
  3679. return 1;
  3680. }
  3681. pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3682. st->pos=pos;
  3683. st->state=GOTO;
  3684. return 0;
  3685. }
  3686. /*==========================================
  3687. * ユーザー定義関数の呼び出し
  3688. *------------------------------------------
  3689. */
  3690. int buildin_callfunc(struct script_state *st)
  3691. {
  3692. struct script_code *scr, *oldscr;
  3693. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3694. if( (scr=strdb_get(userfunc_db,(unsigned char*)str)) ){
  3695. int i,j;
  3696. struct linkdb_node **oldval = st->stack->var_function;
  3697. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3698. push_copy(st->stack,i);
  3699. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3700. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3701. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3702. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3703. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3704. oldscr = st->script;
  3705. st->pos=0;
  3706. st->script=scr;
  3707. st->stack->defsp=st->start+5+j;
  3708. st->state=GOTO;
  3709. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3710. // ' 変数の引き継ぎ
  3711. for(i = 0; i < j; i++) {
  3712. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3713. if( s->type == C_NAME && !s->ref ) {
  3714. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3715. // '@ 変数の引き継ぎ
  3716. if( name[0] == '.' && name[1] == '@' ) {
  3717. s->ref = oldval;
  3718. } else if( name[0] == '.' ) {
  3719. s->ref = &oldscr->script_vars;
  3720. }
  3721. }
  3722. }
  3723. }else{
  3724. ShowWarning("script:callfunc: function not found! [%s]\n",str);
  3725. st->state=END;
  3726. return 1;
  3727. }
  3728. return 0;
  3729. }
  3730. /*==========================================
  3731. * サブルーティンの呼び出し
  3732. *------------------------------------------
  3733. */
  3734. int buildin_callsub(struct script_state *st)
  3735. {
  3736. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3737. int i,j;
  3738. if(st->stack->stack_data[st->start+2].type != C_POS && st->stack->stack_data[st->start+2].type != C_USERFUNC_POS) {
  3739. ShowError("script: callsub: not label !\n");
  3740. st->state=END;
  3741. return 1;
  3742. } else {
  3743. struct linkdb_node **oldval = st->stack->var_function;
  3744. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3745. push_copy(st->stack,i);
  3746. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3747. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3748. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3749. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3750. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3751. st->pos=pos;
  3752. st->stack->defsp=st->start+5+j;
  3753. st->state=GOTO;
  3754. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3755. // ' 変数の引き継ぎ
  3756. for(i = 0; i < j; i++) {
  3757. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3758. if( s->type == C_NAME && !s->ref ) {
  3759. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3760. // '@ 変数の引き継ぎ
  3761. if( name[0] == '.' && name[1] == '@' ) {
  3762. s->ref = oldval;
  3763. }
  3764. }
  3765. }
  3766. }
  3767. return 0;
  3768. }
  3769. /*==========================================
  3770. * 引数の所得
  3771. *------------------------------------------
  3772. */
  3773. int buildin_getarg(struct script_state *st)
  3774. {
  3775. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3776. int max,stsp;
  3777. if( st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO ){
  3778. ShowWarning("script:getarg without callfunc or callsub!\n");
  3779. st->state=END;
  3780. return 1;
  3781. }
  3782. max=conv_num(st,& (st->stack->stack_data[st->stack->defsp-5]));
  3783. stsp=st->stack->defsp - max -5;
  3784. if( num >= max ){
  3785. ShowWarning("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  3786. st->state=END;
  3787. return 1;
  3788. }
  3789. push_copy(st->stack,stsp+num);
  3790. return 0;
  3791. }
  3792. /*==========================================
  3793. * サブルーチン/ユーザー定義関数の終了
  3794. *------------------------------------------
  3795. */
  3796. int buildin_return(struct script_state *st)
  3797. {
  3798. if(st->end>st->start+2){ // 戻り値有り
  3799. struct script_data *sd;
  3800. push_copy(st->stack,st->start+2);
  3801. sd = &st->stack->stack_data[st->stack->sp-1];
  3802. if(sd->type == C_NAME) {
  3803. char *name = str_buf + str_data[sd->u.num&0x00ffffff].str;
  3804. if( name[0] == '.' && name[1] == '@') {
  3805. // '@ 変数を参照渡しにすると危険なので値渡しにする
  3806. get_val(st,sd);
  3807. } else if( name[0] == '.' && !sd->ref) {
  3808. // ' 変数は参照渡しでも良いが、参照元が設定されていないと
  3809. // 元のスクリプトの値を差してしまうので補正する。
  3810. sd->ref = &st->script->script_vars;
  3811. }
  3812. }
  3813. }
  3814. st->state=RETFUNC;
  3815. return 0;
  3816. }
  3817. /*==========================================
  3818. *
  3819. *------------------------------------------
  3820. */
  3821. int buildin_next(struct script_state *st)
  3822. {
  3823. st->state=STOP;
  3824. clif_scriptnext(script_rid2sd(st),st->oid);
  3825. return 0;
  3826. }
  3827. /*==========================================
  3828. *
  3829. *------------------------------------------
  3830. */
  3831. int buildin_close(struct script_state *st)
  3832. {
  3833. st->state=END;
  3834. clif_scriptclose(script_rid2sd(st),st->oid);
  3835. return 0;
  3836. }
  3837. int buildin_close2(struct script_state *st)
  3838. {
  3839. st->state=STOP;
  3840. clif_scriptclose(script_rid2sd(st),st->oid);
  3841. return 0;
  3842. }
  3843. /*==========================================
  3844. *
  3845. *------------------------------------------
  3846. */
  3847. int buildin_menu(struct script_state *st)
  3848. {
  3849. char *buf;
  3850. int len,i;
  3851. struct map_session_data *sd = script_rid2sd(st);
  3852. nullpo_retr(0, sd);
  3853. if(sd->state.menu_or_input==0){
  3854. st->state=RERUNLINE;
  3855. sd->state.menu_or_input=1;
  3856. if( (st->end - st->start - 2) % 2 == 1 ) {
  3857. // 引数の数が奇数なのでエラー扱い
  3858. ShowError("buildin_menu: illigal argument count(%d).\n", st->end - st->start - 2);
  3859. sd->state.menu_or_input=0;
  3860. st->state=END;
  3861. return 1;
  3862. }
  3863. for(i=st->start+2,len=0;i<st->end;i+=2){
  3864. conv_str(st,& (st->stack->stack_data[i]));
  3865. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  3866. }
  3867. buf=(char *)aMallocA((len+1)*sizeof(char));
  3868. buf[0]=0;
  3869. for(i=st->start+2,len=0;i<st->end;i+=2){
  3870. if( st->stack->stack_data[i].u.str[0] ) {
  3871. strcat(buf,st->stack->stack_data[i].u.str);
  3872. strcat(buf,":");
  3873. }
  3874. }
  3875. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  3876. aFree(buf);
  3877. } else if(sd->npc_menu==0xff){ // cansel
  3878. sd->state.menu_or_input=0;
  3879. st->state=END;
  3880. } else { // goto動作
  3881. sd->state.menu_or_input=0;
  3882. if(sd->npc_menu>0){
  3883. //Skip empty menu entries which weren't displayed on the client (blackhole89)
  3884. for(i=st->start+2;i<=(st->start+sd->npc_menu*2) && sd->npc_menu<(st->end-st->start)/2;i+=2) {
  3885. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  3886. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  3887. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  3888. }
  3889. if(sd->npc_menu >= (st->end-st->start)/2) {
  3890. //Invalid selection.
  3891. st->state=END;
  3892. return 0;
  3893. }
  3894. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  3895. ShowError("script: menu: not label !\n");
  3896. st->state=END;
  3897. return 1;
  3898. }
  3899. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  3900. st->pos=conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  3901. st->state=GOTO;
  3902. }
  3903. }
  3904. return 0;
  3905. }
  3906. /*==========================================
  3907. *
  3908. *------------------------------------------
  3909. */
  3910. int buildin_rand(struct script_state *st)
  3911. {
  3912. int range,min,max;
  3913. if (st->end > st->start+3){
  3914. min = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3915. max = conv_num(st,& (st->stack->stack_data[st->start+3]));
  3916. if (max == min){ //Why would someone do this?
  3917. push_val(st->stack,C_INT,min);
  3918. return 0;
  3919. }
  3920. if(max<min){
  3921. int tmp = min;
  3922. min = max;
  3923. max = tmp;
  3924. }
  3925. range = max - min + 1;
  3926. if (range == 0) range = 1;
  3927. push_val(st->stack,C_INT,rand()%range+min);
  3928. } else {
  3929. range = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3930. if (range == 0) range = 1;
  3931. push_val(st->stack,C_INT,rand()%range);
  3932. }
  3933. return 0;
  3934. }
  3935. /*==========================================
  3936. *
  3937. *------------------------------------------
  3938. */
  3939. int buildin_warp(struct script_state *st)
  3940. {
  3941. int x,y;
  3942. char *str;
  3943. struct map_session_data *sd=script_rid2sd(st);
  3944. nullpo_retr(0, sd);
  3945. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3946. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3947. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3948. if(strcmp(str,"Random")==0)
  3949. pc_randomwarp(sd,3);
  3950. else if(strcmp(str,"SavePoint")==0){
  3951. pc_setpos(sd,sd->status.save_point.map,
  3952. sd->status.save_point.x,sd->status.save_point.y,3);
  3953. }else if(strcmp(str,"Save")==0){
  3954. pc_setpos(sd,sd->status.save_point.map,
  3955. sd->status.save_point.x,sd->status.save_point.y,3);
  3956. }else
  3957. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  3958. return 0;
  3959. }
  3960. /*==========================================
  3961. * エリア指定ワープ
  3962. *------------------------------------------
  3963. */
  3964. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  3965. {
  3966. int x,y;
  3967. unsigned int map;
  3968. map=va_arg(ap, unsigned int);
  3969. x=va_arg(ap,int);
  3970. y=va_arg(ap,int);
  3971. if(map == 0)
  3972. pc_randomwarp((struct map_session_data *)bl,3);
  3973. else
  3974. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  3975. return 0;
  3976. }
  3977. int buildin_areawarp(struct script_state *st)
  3978. {
  3979. int x,y,m;
  3980. unsigned int index;
  3981. char *str;
  3982. char *mapname;
  3983. int x0,y0,x1,y1;
  3984. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3985. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3986. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3987. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3988. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3989. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  3990. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3991. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3992. if( (m=map_mapname2mapid(mapname))< 0)
  3993. return 0;
  3994. if(strcmp(str,"Random")==0)
  3995. index = 0;
  3996. else if(!(index=mapindex_name2id(str)))
  3997. return 0;
  3998. map_foreachinarea(buildin_areawarp_sub,
  3999. m,x0,y0,x1,y1,BL_PC, index,x,y );
  4000. return 0;
  4001. }
  4002. /*==========================================
  4003. * warpchar [LuzZza]
  4004. * Useful for warp one player from
  4005. * another player npc-session.
  4006. * Using: warpchar "mapname.gat",x,y,Char_ID;
  4007. *------------------------------------------
  4008. */
  4009. int buildin_warpchar(struct script_state *st)
  4010. {
  4011. int x,y,a,i;
  4012. char *str;
  4013. struct map_session_data *sd, **pl_allsd;
  4014. int users;
  4015. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4016. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4017. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4018. a=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4019. pl_allsd = map_getallusers(&users);
  4020. for(i=0; i<users; i++) {
  4021. sd = pl_allsd[i];
  4022. if(sd->status.char_id == a) {
  4023. if(strcmp(str, "Random") == 0)
  4024. pc_randomwarp(sd, 3);
  4025. else if(strcmp(str, "SavePoint") == 0)
  4026. pc_setpos(sd, sd->status.save_point.map,
  4027. sd->status.save_point.x, sd->status.save_point.y, 3);
  4028. else
  4029. pc_setpos(sd, mapindex_name2id(str), x, y, 3);
  4030. }
  4031. }
  4032. return 0;
  4033. }
  4034. /*==========================================
  4035. * Warpparty - [Fredzilla]
  4036. * Syntax: warpparty "mapname.gat",x,y,Party_ID;
  4037. *------------------------------------------
  4038. */
  4039. int buildin_warpparty(struct script_state *st)
  4040. {
  4041. int x,y;
  4042. char *str;
  4043. int p_id;
  4044. int i;
  4045. unsigned short mapindex;
  4046. struct map_session_data *pl_sd;
  4047. struct party_data *p=NULL;
  4048. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4049. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4050. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4051. p_id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4052. if(p_id < 1)
  4053. return 0;
  4054. p = party_search(p_id);
  4055. if (!p)
  4056. return 0;
  4057. if(strcmp(str,"Random")==0)
  4058. {
  4059. for (i = 0; i < MAX_PARTY; i++)
  4060. {
  4061. if ((pl_sd = p->data[i].sd))
  4062. {
  4063. if(map[pl_sd->bl.m].flag.nowarp)
  4064. continue;
  4065. pc_randomwarp(pl_sd,3);
  4066. }
  4067. }
  4068. }
  4069. else if(strcmp(str,"SavePointAll")==0)
  4070. {
  4071. for (i = 0; i < MAX_PARTY; i++)
  4072. {
  4073. if ((pl_sd = p->data[i].sd))
  4074. {
  4075. if(map[pl_sd->bl.m].flag.noreturn)
  4076. continue;
  4077. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4078. }
  4079. }
  4080. }
  4081. else if(strcmp(str,"SavePoint")==0)
  4082. {
  4083. pl_sd=script_rid2sd(st);
  4084. if (!pl_sd) return 0;
  4085. mapindex=pl_sd->status.save_point.map;
  4086. x=pl_sd->status.save_point.x;
  4087. y=pl_sd->status.save_point.y;
  4088. for (i = 0; i < MAX_PARTY; i++)
  4089. {
  4090. if ((pl_sd = p->data[i].sd))
  4091. {
  4092. if(map[pl_sd->bl.m].flag.noreturn)
  4093. continue;
  4094. pc_setpos(pl_sd,mapindex,x,y,3);
  4095. }
  4096. }
  4097. }
  4098. else
  4099. {
  4100. mapindex = mapindex_name2id(str);
  4101. if (!mapindex) //Show source of npc error.
  4102. return 1;
  4103. for (i = 0; i < MAX_PARTY; i++)
  4104. {
  4105. if ((pl_sd = p->data[i].sd))
  4106. {
  4107. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4108. continue;
  4109. pc_setpos(pl_sd,mapindex,x,y,3);
  4110. }
  4111. }
  4112. }
  4113. return 0;
  4114. }
  4115. /*==========================================
  4116. * Warpguild - [Fredzilla]
  4117. * Syntax: warpguild "mapname.gat",x,y,Guild_ID;
  4118. *------------------------------------------
  4119. */
  4120. int buildin_warpguild(struct script_state *st)
  4121. {
  4122. int x,y;
  4123. unsigned short mapindex;
  4124. char *str;
  4125. int g;
  4126. int i;
  4127. struct map_session_data *pl_sd, **pl_allsd;
  4128. int users;
  4129. struct map_session_data *sd;
  4130. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4131. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4132. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4133. g=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4134. sd=script_rid2sd(st);
  4135. if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
  4136. return 0;
  4137. if(g < 1)
  4138. return 0;
  4139. pl_allsd = map_getallusers(&users);
  4140. if(strcmp(str,"Random")==0)
  4141. {
  4142. for (i = 0; i < users; i++)
  4143. {
  4144. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4145. {
  4146. if(map[pl_sd->bl.m].flag.nowarp)
  4147. continue;
  4148. pc_randomwarp(pl_sd,3);
  4149. }
  4150. }
  4151. }
  4152. else if(strcmp(str,"SavePointAll")==0)
  4153. {
  4154. if(map[sd->bl.m].flag.noreturn)
  4155. return 0;
  4156. for (i = 0; i < users; i++)
  4157. {
  4158. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4159. {
  4160. if(map[pl_sd->bl.m].flag.noreturn)
  4161. continue;
  4162. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4163. }
  4164. }
  4165. }
  4166. else if(strcmp(str,"SavePoint")==0)
  4167. {
  4168. if(map[sd->bl.m].flag.noreturn)
  4169. return 0;
  4170. mapindex=sd->status.save_point.map;
  4171. x=sd->status.save_point.x;
  4172. y=sd->status.save_point.y;
  4173. for (i = 0; i < users; i++)
  4174. {
  4175. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4176. {
  4177. if(map[pl_sd->bl.m].flag.noreturn)
  4178. continue;
  4179. pc_setpos(pl_sd,mapindex,x,y,3);
  4180. }
  4181. }
  4182. }
  4183. else
  4184. {
  4185. mapindex = mapindex_name2id(str);
  4186. for (i = 0; i < users; i++)
  4187. {
  4188. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4189. {
  4190. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4191. continue;
  4192. pc_setpos(pl_sd,mapindex,x,y,3);
  4193. }
  4194. }
  4195. }
  4196. return 0;
  4197. }
  4198. /*==========================================
  4199. *
  4200. *------------------------------------------
  4201. */
  4202. int buildin_heal(struct script_state *st)
  4203. {
  4204. struct map_session_data *sd;
  4205. int hp,sp;
  4206. sd = script_rid2sd(st);
  4207. if (!sd) return 0;
  4208. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4209. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4210. status_heal(&sd->bl, hp, sp, 1);
  4211. return 0;
  4212. }
  4213. /*==========================================
  4214. *
  4215. *------------------------------------------
  4216. */
  4217. int buildin_itemheal(struct script_state *st)
  4218. {
  4219. struct map_session_data *sd;
  4220. int hp,sp;
  4221. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4222. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4223. if(potion_flag==1) {
  4224. potion_hp = hp;
  4225. potion_sp = sp;
  4226. return 0;
  4227. }
  4228. sd = script_rid2sd(st);
  4229. if (!sd) return 0;
  4230. pc_itemheal(sd,sd->itemid,hp,sp);
  4231. return 0;
  4232. }
  4233. /*==========================================
  4234. *
  4235. *------------------------------------------
  4236. */
  4237. int buildin_percentheal(struct script_state *st)
  4238. {
  4239. int hp,sp;
  4240. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4241. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4242. if(potion_flag==1) {
  4243. potion_per_hp = hp;
  4244. potion_per_sp = sp;
  4245. return 0;
  4246. }
  4247. pc_percentheal(script_rid2sd(st),hp,sp);
  4248. return 0;
  4249. }
  4250. /*==========================================
  4251. *
  4252. *------------------------------------------
  4253. */
  4254. int buildin_jobchange(struct script_state *st)
  4255. {
  4256. int job, upper=-1;
  4257. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4258. if( st->end>st->start+3 )
  4259. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4260. if ((job >= 0 && job < MAX_PC_CLASS)){
  4261. pc_jobchange(script_rid2sd(st),job, upper);
  4262. if(use_irc && irc_announce_jobchange_flag)
  4263. irc_announce_jobchange(script_rid2sd(st));
  4264. }
  4265. return 0;
  4266. }
  4267. /*==========================================
  4268. *
  4269. *------------------------------------------
  4270. */
  4271. int buildin_jobname(struct script_state *st)
  4272. {
  4273. int class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4274. push_str(st->stack,C_CONSTSTR,job_name(class_));
  4275. return 0;
  4276. }
  4277. /*==========================================
  4278. *
  4279. *------------------------------------------
  4280. */
  4281. int buildin_input(struct script_state *st)
  4282. {
  4283. struct map_session_data *sd = script_rid2sd(st);
  4284. int num = (st->end>st->start+2)? st->stack->stack_data[st->start+2].u.num: 0;
  4285. char *name = (st->end>st->start+2)? str_buf+str_data[num&0x00ffffff].str: "";
  4286. char postfix=name[strlen(name)-1];
  4287. nullpo_retr(0, sd);
  4288. if(sd->state.menu_or_input){
  4289. sd->state.menu_or_input=0;
  4290. if( postfix=='$' ){
  4291. // 文字列
  4292. if(st->end>st->start+2){ // 引数1個
  4293. set_reg(st,sd,num,name,(void*)sd->npc_str,st->stack->stack_data[st->start+2].ref);
  4294. }else{
  4295. ShowError("buildin_input: string discarded !!\n");
  4296. return 1;
  4297. }
  4298. return 0;
  4299. }
  4300. // commented by Lupus (check Value Number Input fix in clif.c)
  4301. // readded by Yor: set ammount to 0 instead of cancel trade.
  4302. // ** Fix by fritz :X keeps people from abusing old input bugs
  4303. if (sd->npc_amount < 0) { //** If input amount is less then 0
  4304. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  4305. // buildin_close(st); // ** close
  4306. sd->npc_amount = 0;
  4307. } else if ((unsigned int)sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  4308. sd->npc_amount = battle_config.vending_max_value;
  4309. // 数値
  4310. if(st->end>st->start+2){ // 引数1個
  4311. set_reg(st,sd,num,name,(void*)sd->npc_amount,st->stack->stack_data[st->start+2].ref);
  4312. } else {
  4313. // ragemu互換のため
  4314. //pc_setreg(sd,add_str((unsigned char *) "l14"),sd->npc_amount);
  4315. }
  4316. return 0;
  4317. }
  4318. //state.menu_or_input = 0
  4319. st->state=RERUNLINE;
  4320. if(postfix=='$')
  4321. clif_scriptinputstr(sd,st->oid);
  4322. else
  4323. clif_scriptinput(sd,st->oid);
  4324. sd->state.menu_or_input=1;
  4325. return 0;
  4326. }
  4327. /*==========================================
  4328. * 変数設定
  4329. *------------------------------------------
  4330. */
  4331. int buildin_set(struct script_state *st)
  4332. {
  4333. struct map_session_data *sd=NULL;
  4334. int num=st->stack->stack_data[st->start+2].u.num;
  4335. char *name=str_buf+str_data[num&0x00ffffff].str;
  4336. char prefix=*name;
  4337. char postfix=name[strlen(name)-1];
  4338. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  4339. ShowError("script: buildin_set: not name\n");
  4340. return 1;
  4341. }
  4342. if(not_server_variable(prefix))
  4343. sd=script_rid2sd(st);
  4344. if( postfix=='$' ){
  4345. // 文字列
  4346. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  4347. set_reg(st,sd,num,name,(void*)str,st->stack->stack_data[st->start+2].ref);
  4348. }else{
  4349. // 数値
  4350. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  4351. set_reg(st,sd,num,name,(void*)val,st->stack->stack_data[st->start+2].ref);
  4352. }
  4353. return 0;
  4354. }
  4355. /*==========================================
  4356. * 配列変数設定
  4357. *------------------------------------------
  4358. */
  4359. int buildin_setarray(struct script_state *st)
  4360. {
  4361. struct map_session_data *sd=NULL;
  4362. int num=st->stack->stack_data[st->start+2].u.num;
  4363. char *name=str_buf+str_data[num&0x00ffffff].str;
  4364. char prefix=*name;
  4365. char postfix=name[strlen(name)-1];
  4366. int i,j;
  4367. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4368. ShowWarning("buildin_setarray: illegal scope !\n");
  4369. return 1;
  4370. }
  4371. if(not_server_variable(prefix))
  4372. sd=script_rid2sd(st);
  4373. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  4374. void *v;
  4375. if( postfix=='$' )
  4376. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  4377. else
  4378. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  4379. set_reg(st, sd, num+(j<<24), name, v, st->stack->stack_data[st->start+2].ref);
  4380. }
  4381. return 0;
  4382. }
  4383. /*==========================================
  4384. * 配列変数クリア
  4385. *------------------------------------------
  4386. */
  4387. int buildin_cleararray(struct script_state *st)
  4388. {
  4389. struct map_session_data *sd=NULL;
  4390. int num=st->stack->stack_data[st->start+2].u.num;
  4391. char *name=str_buf+str_data[num&0x00ffffff].str;
  4392. char prefix=*name;
  4393. char postfix=name[strlen(name)-1];
  4394. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4395. int i;
  4396. void *v;
  4397. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4398. ShowWarning("buildin_cleararray: illegal scope !\n");
  4399. return 1;
  4400. }
  4401. if( not_server_variable(prefix) )
  4402. sd=script_rid2sd(st);
  4403. if( postfix=='$' )
  4404. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  4405. else
  4406. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  4407. for(i=0;i<sz;i++)
  4408. set_reg(st,sd,num+(i<<24),name,v,st->stack->stack_data[st->start+2].ref);
  4409. return 0;
  4410. }
  4411. /*==========================================
  4412. * 配列変数コピー
  4413. *------------------------------------------
  4414. */
  4415. int buildin_copyarray(struct script_state *st)
  4416. {
  4417. struct map_session_data *sd=NULL;
  4418. int num=st->stack->stack_data[st->start+2].u.num;
  4419. char *name=str_buf+str_data[num&0x00ffffff].str;
  4420. char prefix=*name;
  4421. char postfix=name[strlen(name)-1];
  4422. int num2=st->stack->stack_data[st->start+3].u.num;
  4423. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  4424. char prefix2=*name2;
  4425. char postfix2=name2[strlen(name2)-1];
  4426. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4427. int i;
  4428. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4429. printf("buildin_copyarray: illeagal scope !\n");
  4430. return 0;
  4431. }
  4432. if( prefix2!='$' && prefix2!='@' && prefix2!='.' ) {
  4433. printf("buildin_copyarray: illeagal scope !\n");
  4434. return 0;
  4435. }
  4436. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  4437. printf("buildin_copyarray: type mismatch !\n");
  4438. return 0;
  4439. }
  4440. if( not_server_variable(prefix) || not_server_variable(prefix2) )
  4441. sd=script_rid2sd(st);
  4442. if((num & 0x00FFFFFF) == (num2 & 0x00FFFFFF) && (num & 0xFF000000) > (num2 & 0xFF000000)) {
  4443. // 同じ配列で、num > num2 の場合大きい方からコピーしないといけない
  4444. for(i=sz-1;i>=0;i--)
  4445. set_reg(
  4446. st,sd,num+(i<<24),name,
  4447. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4448. st->stack->stack_data[st->start+2].ref
  4449. );
  4450. } else {
  4451. for(i=0;i<sz;i++)
  4452. set_reg(
  4453. st,sd,num+(i<<24),name,
  4454. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4455. st->stack->stack_data[st->start+2].ref
  4456. );
  4457. }
  4458. return 0;
  4459. }
  4460. /*==========================================
  4461. * 配列変数のサイズ所得
  4462. *------------------------------------------
  4463. */
  4464. static int getarraysize(struct script_state *st,int num,int postfix,struct linkdb_node** ref)
  4465. {
  4466. 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]
  4467. if(postfix == '$'){
  4468. for(;i<128;i++){
  4469. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4470. if(*((char*)v)) c=i;
  4471. }
  4472. }else{
  4473. for(;i<128;i++){
  4474. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4475. if((int)v) c=i;
  4476. }
  4477. }
  4478. return c+1;
  4479. }
  4480. int buildin_getarraysize(struct script_state *st)
  4481. {
  4482. int num=st->stack->stack_data[st->start+2].u.num;
  4483. char *name=str_buf+str_data[num&0x00ffffff].str;
  4484. char prefix=*name;
  4485. char postfix=name[strlen(name)-1];
  4486. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4487. ShowWarning("buildin_copyarray: illegal scope !\n");
  4488. return 1;
  4489. }
  4490. push_val(st->stack,C_INT,getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref));
  4491. return 0;
  4492. }
  4493. /*==========================================
  4494. * 配列変数から要素削除
  4495. *------------------------------------------
  4496. */
  4497. int buildin_deletearray(struct script_state *st)
  4498. {
  4499. struct map_session_data *sd=NULL;
  4500. int num=st->stack->stack_data[st->start+2].u.num;
  4501. char *name=str_buf+str_data[num&0x00ffffff].str;
  4502. char prefix=*name;
  4503. char postfix=name[strlen(name)-1];
  4504. int count=1;
  4505. int i,sz=getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref)-(num>>24)-count+1;
  4506. if( (st->end > st->start+3) )
  4507. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4508. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4509. ShowWarning("buildin_deletearray: illegal scope !\n");
  4510. return 1;
  4511. }
  4512. if( not_server_variable(prefix) )
  4513. sd=script_rid2sd(st);
  4514. for(i=0;i<sz;i++){
  4515. set_reg(
  4516. st,sd,num+(i<<24),name,
  4517. get_val2(st,num+((i+count)<<24),st->stack->stack_data[st->start+2].ref),
  4518. st->stack->stack_data[st->start+2].ref
  4519. );
  4520. }
  4521. if(postfix != '$'){
  4522. for(;i<(128-(num>>24));i++)
  4523. set_reg(st,sd,num+(i<<24),name, 0,st->stack->stack_data[st->start+2].ref);
  4524. } else {
  4525. for(;i<(128-(num>>24));i++)
  4526. set_reg(st,sd,num+(i<<24),name, (void *) "",st->stack->stack_data[st->start+2].ref);
  4527. }
  4528. return 0;
  4529. }
  4530. /*==========================================
  4531. * 指定要素を表す値(キー)を所得する
  4532. *------------------------------------------
  4533. */
  4534. int buildin_getelementofarray(struct script_state *st)
  4535. {
  4536. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  4537. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4538. if(i>127 || i<0){
  4539. ShowWarning("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  4540. push_val(st->stack,C_INT,0);
  4541. return 1;
  4542. }else{
  4543. push_val2(st->stack,C_NAME,
  4544. (i<<24) | st->stack->stack_data[st->start+2].u.num, st->stack->stack_data[st->start+2].ref );
  4545. }
  4546. }else{
  4547. ShowError("script: getelementofarray (operator[]): param1 not name !\n");
  4548. push_val(st->stack,C_INT,0);
  4549. }
  4550. return 0;
  4551. }
  4552. /*==========================================
  4553. *
  4554. *------------------------------------------
  4555. */
  4556. int buildin_setlook(struct script_state *st)
  4557. {
  4558. int type,val;
  4559. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4560. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4561. pc_changelook(script_rid2sd(st),type,val);
  4562. return 0;
  4563. }
  4564. /*==========================================
  4565. *
  4566. *------------------------------------------
  4567. */
  4568. int buildin_cutin(struct script_state *st)
  4569. {
  4570. int type;
  4571. conv_str(st,& (st->stack->stack_data[st->start+2]));
  4572. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4573. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  4574. return 0;
  4575. }
  4576. /*==========================================
  4577. * カードのイラストを表示する
  4578. *------------------------------------------
  4579. */
  4580. int buildin_cutincard(struct script_state *st)
  4581. {
  4582. int itemid;
  4583. struct item_data *i_data;
  4584. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4585. i_data = itemdb_exists(itemid);
  4586. if (i_data)
  4587. clif_cutin(script_rid2sd(st),i_data->cardillustname,4);
  4588. return 0;
  4589. }
  4590. /*==========================================
  4591. *
  4592. *------------------------------------------
  4593. */
  4594. int buildin_viewpoint(struct script_state *st)
  4595. {
  4596. int type,x,y,id,color;
  4597. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4598. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4599. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4600. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4601. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4602. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  4603. return 0;
  4604. }
  4605. /*==========================================
  4606. *
  4607. *------------------------------------------
  4608. */
  4609. int buildin_countitem(struct script_state *st)
  4610. {
  4611. int nameid=0,count=0,i;
  4612. struct map_session_data *sd;
  4613. struct script_data *data;
  4614. sd = script_rid2sd(st);
  4615. data=&(st->stack->stack_data[st->start+2]);
  4616. get_val(st,data);
  4617. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4618. const char *name=conv_str(st,data);
  4619. struct item_data *item_data;
  4620. if( (item_data = itemdb_searchname(name)) != NULL)
  4621. nameid=item_data->nameid;
  4622. }else
  4623. nameid=conv_num(st,data);
  4624. if (nameid>=500) //if no such ID then skip this iteration
  4625. for(i=0;i<MAX_INVENTORY;i++){
  4626. if(sd->status.inventory[i].nameid==nameid)
  4627. count+=sd->status.inventory[i].amount;
  4628. }
  4629. else{
  4630. if(battle_config.error_log)
  4631. ShowError("wrong item ID : countitem(%i)\n",nameid);
  4632. push_val(st->stack,C_INT,0);
  4633. return 1;
  4634. }
  4635. push_val(st->stack,C_INT,count);
  4636. return 0;
  4637. }
  4638. /*==========================================
  4639. * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
  4640. * returns number of items that met the conditions
  4641. *------------------------------------------
  4642. */
  4643. int buildin_countitem2(struct script_state *st)
  4644. {
  4645. int nameid=0,count=0,i;
  4646. int iden,ref,attr,c1,c2,c3,c4;
  4647. struct map_session_data *sd;
  4648. struct script_data *data;
  4649. sd = script_rid2sd(st);
  4650. data=&(st->stack->stack_data[st->start+2]);
  4651. get_val(st,data);
  4652. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4653. const char *name=conv_str(st,data);
  4654. struct item_data *item_data;
  4655. if( (item_data = itemdb_searchname(name)) != NULL)
  4656. nameid=item_data->nameid;
  4657. }else
  4658. nameid=conv_num(st,data);
  4659. iden=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4660. ref=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4661. attr=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4662. c1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4663. c2=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4664. c3=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4665. c4=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4666. if (nameid>=500) //if no such ID then skip this iteration
  4667. for(i=0;i<MAX_INVENTORY;i++){
  4668. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  4669. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  4670. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  4671. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  4672. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  4673. sd->status.inventory[i].card[3]!=c4)
  4674. continue;
  4675. count+=sd->status.inventory[i].amount;
  4676. }
  4677. else{
  4678. if(battle_config.error_log)
  4679. ShowError("wrong item ID : countitem2(%i)\n",nameid);
  4680. push_val(st->stack,C_INT,0);
  4681. return 1;
  4682. }
  4683. push_val(st->stack,C_INT,count);
  4684. return 0;
  4685. }
  4686. /*==========================================
  4687. * 重量チェック
  4688. *------------------------------------------
  4689. */
  4690. int buildin_checkweight(struct script_state *st)
  4691. {
  4692. int nameid=0,amount,i;
  4693. unsigned long weight;
  4694. struct map_session_data *sd;
  4695. struct script_data *data;
  4696. sd = script_rid2sd(st);
  4697. data=&(st->stack->stack_data[st->start+2]);
  4698. get_val(st,data);
  4699. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4700. const char *name=conv_str(st,data);
  4701. struct item_data *item_data = itemdb_searchname(name);
  4702. if( item_data )
  4703. nameid=item_data->nameid;
  4704. }else
  4705. nameid=conv_num(st,data);
  4706. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4707. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  4708. push_val(st->stack,C_INT,0);
  4709. ShowError("buildin_checkweight: Wrong item ID or amount.\n");
  4710. return 1;
  4711. }
  4712. weight = itemdb_weight(nameid)*amount;
  4713. if(amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight){
  4714. push_val(st->stack,C_INT,0);
  4715. } else {
  4716. //Check if the inventory ain't full.
  4717. //TODO: Currently does not checks if you can just stack it on top of another item you already have....
  4718. i = pc_search_inventory(sd,0);
  4719. if (i >= 0) //Empty slot available.
  4720. push_val(st->stack,C_INT,1);
  4721. else //Inventory full
  4722. push_val(st->stack,C_INT,0);
  4723. }
  4724. return 0;
  4725. }
  4726. /*==========================================
  4727. *
  4728. *------------------------------------------
  4729. */
  4730. int buildin_getitem(struct script_state *st)
  4731. {
  4732. int nameid,amount,flag = 0;
  4733. struct item item_tmp;
  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 == NULL) {
  4743. ShowWarning("buildin_getitem: Nonexistant item %s requested.\n", name);
  4744. return 1; //No item created.
  4745. }
  4746. nameid=item_data->nameid;
  4747. }else
  4748. nameid=conv_num(st,data);
  4749. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0)
  4750. return 0; //return if amount <=0, skip the useles iteration
  4751. //Violet Box, Blue Box, etc - random item pick
  4752. if(nameid <0) {
  4753. nameid=itemdb_searchrandomid(-nameid);
  4754. flag = 1;
  4755. }
  4756. if(nameid <= 0 || !itemdb_exists(nameid)) {
  4757. ShowWarning("buildin_getitem: Nonexistant item %d requested.\n", nameid);
  4758. return 1; //No item created.
  4759. }
  4760. memset(&item_tmp,0,sizeof(item_tmp));
  4761. item_tmp.nameid=nameid;
  4762. if(!flag)
  4763. item_tmp.identify=1;
  4764. else
  4765. item_tmp.identify=itemdb_isidentified(nameid);
  4766. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  4767. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  4768. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4769. return 0;
  4770. if(pet_create_egg(sd, nameid))
  4771. amount = 1; //This is a pet!
  4772. else
  4773. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4774. clif_additem(sd,0,0,flag);
  4775. if (pc_candrop(sd, &item_tmp))
  4776. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4777. }
  4778. //Logs items, got from (N)PC scripts [Lupus]
  4779. if(log_config.enable_logs&0x40)
  4780. log_pick(sd, "N", 0, nameid, amount, NULL);
  4781. return 0;
  4782. }
  4783. /*==========================================
  4784. *
  4785. *------------------------------------------
  4786. */
  4787. int buildin_getitem2(struct script_state *st)
  4788. {
  4789. int nameid,amount,flag = 0;
  4790. int iden,ref,attr,c1,c2,c3,c4;
  4791. struct item_data *item_data;
  4792. struct item item_tmp;
  4793. struct map_session_data *sd;
  4794. struct script_data *data;
  4795. sd = script_rid2sd(st);
  4796. data=&(st->stack->stack_data[st->start+2]);
  4797. get_val(st,data);
  4798. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4799. const char *name=conv_str(st,data);
  4800. struct item_data *item_data = itemdb_searchname(name);
  4801. nameid=UNKNOWN_ITEM_ID;
  4802. if( item_data )
  4803. nameid=item_data->nameid;
  4804. }else
  4805. nameid=conv_num(st,data);
  4806. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4807. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4808. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4809. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4810. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4811. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4812. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4813. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  4814. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  4815. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  4816. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4817. return 0;
  4818. if(nameid<0) { // ランダム
  4819. nameid=itemdb_searchrandomid(-nameid);
  4820. flag = 1;
  4821. }
  4822. if(nameid > 0) {
  4823. memset(&item_tmp,0,sizeof(item_tmp));
  4824. item_data=itemdb_exists(nameid);
  4825. if (item_data == NULL)
  4826. return -1;
  4827. if(item_data->type==4 || item_data->type==5){
  4828. if(ref > 10) ref = 10;
  4829. }
  4830. else if(item_data->type==7) {
  4831. iden = 1;
  4832. ref = 0;
  4833. }
  4834. else {
  4835. iden = 1;
  4836. ref = attr = 0;
  4837. }
  4838. item_tmp.nameid=nameid;
  4839. if(!flag)
  4840. item_tmp.identify=iden;
  4841. else if(item_data->type==4 || item_data->type==5)
  4842. item_tmp.identify=0;
  4843. item_tmp.refine=ref;
  4844. item_tmp.attribute=attr;
  4845. item_tmp.card[0]=c1;
  4846. item_tmp.card[1]=c2;
  4847. item_tmp.card[2]=c3;
  4848. item_tmp.card[3]=c4;
  4849. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4850. clif_additem(sd,0,0,flag);
  4851. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4852. }
  4853. //Logs items, got from (N)PC scripts [Lupus]
  4854. if(log_config.enable_logs&0x40)
  4855. log_pick(sd, "N", 0, nameid, amount, &item_tmp);
  4856. }
  4857. return 0;
  4858. }
  4859. /*==========================================
  4860. * gets an item with someone's name inscribed [Skotlex]
  4861. * getinscribeditem item_num, character_name
  4862. * Returned Qty is always 1, only works on equip-able
  4863. * equipment
  4864. *------------------------------------------
  4865. */
  4866. int buildin_getnameditem(struct script_state *st)
  4867. {
  4868. int nameid;
  4869. struct item item_tmp;
  4870. struct map_session_data *sd, *tsd;
  4871. struct script_data *data;
  4872. sd = script_rid2sd(st);
  4873. if (sd == NULL)
  4874. { //Player not attached!
  4875. push_val(st->stack,C_INT,0);
  4876. return 0;
  4877. }
  4878. data=&(st->stack->stack_data[st->start+2]);
  4879. get_val(st,data);
  4880. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4881. const char *name=conv_str(st,data);
  4882. struct item_data *item_data = itemdb_searchname(name);
  4883. if( item_data == NULL)
  4884. { //Failed
  4885. push_val(st->stack,C_INT,0);
  4886. return 0;
  4887. }
  4888. nameid = item_data->nameid;
  4889. }else
  4890. nameid = conv_num(st,data);
  4891. if(!itemdb_exists(nameid)/* || itemdb_isstackable(nameid)*/)
  4892. { //Even though named stackable items "could" be risky, they are required for certain quests.
  4893. push_val(st->stack,C_INT,0);
  4894. return 0;
  4895. }
  4896. data=&(st->stack->stack_data[st->start+3]);
  4897. get_val(st,data);
  4898. if( data->type==C_STR || data->type==C_CONSTSTR ) //Char Name
  4899. tsd=map_nick2sd(conv_str(st,data));
  4900. else //Char Id was given
  4901. tsd=map_charid2sd(conv_num(st,data));
  4902. if( tsd == NULL )
  4903. { //Failed
  4904. push_val(st->stack,C_INT,0);
  4905. return 0;
  4906. }
  4907. memset(&item_tmp,0,sizeof(item_tmp));
  4908. item_tmp.nameid=nameid;
  4909. item_tmp.amount=1;
  4910. item_tmp.identify=1;
  4911. item_tmp.card[0]=254; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
  4912. item_tmp.card[2]=tsd->status.char_id;
  4913. item_tmp.card[3]=tsd->status.char_id >> 16;
  4914. if(pc_additem(sd,&item_tmp,1)) {
  4915. push_val(st->stack,C_INT,0);
  4916. return 0; //Failed to add item, we will not drop if they don't fit
  4917. }
  4918. //Logs items, got from (N)PC scripts [Lupus]
  4919. if(log_config.enable_logs&0x40)
  4920. log_pick(sd, "N", 0, item_tmp.nameid, item_tmp.amount, &item_tmp);
  4921. push_val(st->stack,C_INT,1);
  4922. return 0;
  4923. }
  4924. /*==========================================
  4925. * gets a random item ID from an item group [Skotlex]
  4926. * groupranditem group_num
  4927. *------------------------------------------
  4928. */
  4929. int buildin_grouprandomitem(struct script_state *st)
  4930. {
  4931. int group;
  4932. group = conv_num(st,& (st->stack->stack_data[st->start+2]));
  4933. push_val(st->stack, C_INT, itemdb_searchrandomid(group));
  4934. return 0;
  4935. }
  4936. /*==========================================
  4937. *
  4938. *------------------------------------------
  4939. */
  4940. int buildin_makeitem(struct script_state *st)
  4941. {
  4942. int nameid,amount,flag = 0;
  4943. int x,y,m;
  4944. char *mapname;
  4945. struct item item_tmp;
  4946. struct script_data *data;
  4947. data=&(st->stack->stack_data[st->start+2]);
  4948. get_val(st,data);
  4949. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4950. const char *name=conv_str(st,data);
  4951. struct item_data *item_data = itemdb_searchname(name);
  4952. nameid=UNKNOWN_ITEM_ID;
  4953. if( item_data )
  4954. nameid=item_data->nameid;
  4955. }else
  4956. nameid=conv_num(st,data);
  4957. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4958. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  4959. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  4960. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  4961. if(strcmp(mapname,"this")==0)
  4962. {
  4963. struct map_session_data *sd;
  4964. sd = script_rid2sd(st);
  4965. if (!sd) return 0; //Failed...
  4966. m=sd->bl.m;
  4967. } else
  4968. m=map_mapname2mapid(mapname);
  4969. if(nameid<0) { // ランダム
  4970. nameid=itemdb_searchrandomid(-nameid);
  4971. flag = 1;
  4972. }
  4973. if(nameid > 0) {
  4974. memset(&item_tmp,0,sizeof(item_tmp));
  4975. item_tmp.nameid=nameid;
  4976. if(!flag)
  4977. item_tmp.identify=1;
  4978. else
  4979. item_tmp.identify=itemdb_isidentified(nameid);
  4980. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  4981. }
  4982. return 0;
  4983. }
  4984. /*==========================================
  4985. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  4986. *------------------------------------------
  4987. */
  4988. int buildin_delitem(struct script_state *st)
  4989. {
  4990. int nameid=0,amount,i,important_item=0;
  4991. struct map_session_data *sd;
  4992. struct script_data *data;
  4993. sd = script_rid2sd(st);
  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. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5006. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5007. return 0;
  5008. }
  5009. //1st pass
  5010. //here we won't delete items with CARDS, named items but we count them
  5011. for(i=0;i<MAX_INVENTORY;i++){
  5012. //we don't delete wrong item or equipped item
  5013. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5014. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid)
  5015. continue;
  5016. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5017. if(sd->inventory_data[i]->type==IT_PETEGG &&
  5018. sd->status.inventory[i].card[0] == CARD0_PET)
  5019. {
  5020. if (intif_delete_petdata(MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5021. continue; //pet couldn't be sent for deletion.
  5022. }
  5023. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  5024. if(itemdb_isspecial(sd->status.inventory[i].card[0]) ||
  5025. sd->status.inventory[i].card[0] ||
  5026. sd->status.inventory[i].refine) {
  5027. //this is important item, count it (except for pet eggs)
  5028. if(sd->status.inventory[i].card[0] != CARD0_PET)
  5029. important_item++;
  5030. continue;
  5031. }
  5032. if(sd->status.inventory[i].amount>=amount){
  5033. //Logs items, got from (N)PC scripts [Lupus]
  5034. if(log_config.enable_logs&0x40)
  5035. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5036. pc_delitem(sd,i,amount,0);
  5037. return 0; //we deleted exact amount of items. now exit
  5038. } else {
  5039. amount-=sd->status.inventory[i].amount;
  5040. //Logs items, got from (N)PC scripts [Lupus]
  5041. if(log_config.enable_logs&0x40) {
  5042. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5043. }
  5044. //Logs
  5045. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5046. }
  5047. }
  5048. //2nd pass
  5049. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  5050. if (important_item>0 && amount>0)
  5051. for(i=0;i<MAX_INVENTORY;i++){
  5052. //we don't delete wrong item
  5053. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5054. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  5055. continue;
  5056. if(sd->status.inventory[i].amount>=amount){
  5057. //Logs items, got from (N)PC scripts [Lupus]
  5058. if(log_config.enable_logs&0x40)
  5059. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5060. pc_delitem(sd,i,amount,0);
  5061. return 0; //we deleted exact amount of items. now exit
  5062. } else {
  5063. amount-=sd->status.inventory[i].amount;
  5064. //Logs items, got from (N)PC scripts [Lupus]
  5065. if(log_config.enable_logs&0x40)
  5066. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5067. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5068. }
  5069. }
  5070. return 0;
  5071. }
  5072. /*==========================================
  5073. * advanced version of delitem [modified by Mihilion]
  5074. *------------------------------------------
  5075. */
  5076. int buildin_delitem2(struct script_state *st)
  5077. {
  5078. int nameid=0,amount,i=0;
  5079. int iden,ref,attr,c1,c2,c3,c4;
  5080. struct map_session_data *sd;
  5081. struct script_data *data;
  5082. sd = script_rid2sd(st);
  5083. data=&(st->stack->stack_data[st->start+2]);
  5084. get_val(st,data);
  5085. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5086. const char *name=conv_str(st,data);
  5087. struct item_data *item_data = itemdb_searchname(name);
  5088. //nameid=UNKNOWN_ITEM_ID;
  5089. if( item_data )
  5090. nameid=item_data->nameid;
  5091. }else
  5092. nameid=conv_num(st,data);
  5093. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5094. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5095. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5096. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5097. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5098. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5099. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5100. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  5101. if (!itemdb_exists(nameid) || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5102. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5103. return 0;
  5104. }
  5105. for(i=0;i<MAX_INVENTORY;i++){
  5106. //we don't delete wrong item or equipped item
  5107. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5108. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  5109. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  5110. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  5111. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  5112. sd->status.inventory[i].card[3]!=c4)
  5113. continue;
  5114. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5115. if(sd->inventory_data[i]->type==IT_PETEGG && sd->status.inventory[i].card[0] == CARD0_PET)
  5116. {
  5117. if (!intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5118. continue; //Failed to send delete the pet.
  5119. }
  5120. if(sd->status.inventory[i].amount>=amount){
  5121. //Logs items, got from (N)PC scripts [Lupus]
  5122. if(log_config.enable_logs&0x40)
  5123. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5124. pc_delitem(sd,i,amount,0);
  5125. return 0; //we deleted exact amount of items. now exit
  5126. } else {
  5127. amount-=sd->status.inventory[i].amount;
  5128. //Logs items, got from (N)PC scripts [Lupus]
  5129. if(log_config.enable_logs&0x40)
  5130. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5131. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5132. }
  5133. }
  5134. return 0;
  5135. }
  5136. /*==========================================
  5137. * Enables/Disables use of items while in an NPC [Skotlex]
  5138. *------------------------------------------
  5139. */
  5140. int buildin_enableitemuse(struct script_state *st) {
  5141. struct map_session_data *sd;
  5142. sd=script_rid2sd(st);
  5143. if (sd)
  5144. sd->npc_item_flag = st->oid;
  5145. return 0;
  5146. }
  5147. int buildin_disableitemuse(struct script_state *st) {
  5148. struct map_session_data *sd;
  5149. sd=script_rid2sd(st);
  5150. if (sd)
  5151. sd->npc_item_flag = 0;
  5152. return 0;
  5153. }
  5154. /*==========================================
  5155. *キャラ関係のパラメータ取得
  5156. *------------------------------------------
  5157. */
  5158. int buildin_readparam(struct script_state *st)
  5159. {
  5160. int type;
  5161. struct map_session_data *sd;
  5162. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5163. if( st->end>st->start+3 )
  5164. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5165. else
  5166. sd=script_rid2sd(st);
  5167. if(sd==NULL){
  5168. push_val(st->stack,C_INT,-1);
  5169. return 0;
  5170. }
  5171. push_val(st->stack,C_INT,pc_readparam(sd,type));
  5172. return 0;
  5173. }
  5174. /*==========================================
  5175. *キャラ関係のID取得
  5176. *------------------------------------------
  5177. */
  5178. int buildin_getcharid(struct script_state *st)
  5179. {
  5180. int num;
  5181. struct map_session_data *sd;
  5182. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5183. if( st->end>st->start+3 )
  5184. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5185. else
  5186. sd=script_rid2sd(st);
  5187. if(sd==NULL){
  5188. push_val(st->stack,C_INT,-1);
  5189. return 0;
  5190. }
  5191. if(num==0)
  5192. push_val(st->stack,C_INT,sd->status.char_id);
  5193. if(num==1)
  5194. push_val(st->stack,C_INT,sd->status.party_id);
  5195. if(num==2)
  5196. push_val(st->stack,C_INT,sd->status.guild_id);
  5197. if(num==3)
  5198. push_val(st->stack,C_INT,sd->status.account_id);
  5199. return 0;
  5200. }
  5201. /*==========================================
  5202. *指定IDのPT名取得
  5203. *------------------------------------------
  5204. */
  5205. char *buildin_getpartyname_sub(int party_id)
  5206. {
  5207. struct party_data *p;
  5208. p=party_search(party_id);
  5209. if(p!=NULL){
  5210. char *buf;
  5211. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5212. memcpy(buf, p->party.name, NAME_LENGTH-1);
  5213. buf[NAME_LENGTH-1] = '\0';
  5214. return buf;
  5215. }
  5216. return 0;
  5217. }
  5218. int buildin_getpartyname(struct script_state *st)
  5219. {
  5220. char *name;
  5221. int party_id;
  5222. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5223. name=buildin_getpartyname_sub(party_id);
  5224. if(name != NULL)
  5225. push_str(st->stack,C_STR,(unsigned char *)name);
  5226. else
  5227. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  5228. return 0;
  5229. }
  5230. /*==========================================
  5231. *指定IDのPT人数とメンバーID取得
  5232. *------------------------------------------
  5233. */
  5234. int buildin_getpartymember(struct script_state *st)
  5235. {
  5236. struct party_data *p;
  5237. int i,j=0,type=0;
  5238. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  5239. if( st->end>st->start+3 )
  5240. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5241. if(p!=NULL){
  5242. for(i=0;i<MAX_PARTY;i++){
  5243. if(p->party.member[i].account_id){
  5244. switch (type) {
  5245. case 2:
  5246. mapreg_setreg(add_str((unsigned char *) "$@partymemberaid")+(j<<24),p->party.member[i].account_id);
  5247. break;
  5248. case 1:
  5249. mapreg_setreg(add_str((unsigned char *) "$@partymembercid")+(j<<24),p->party.member[i].char_id);
  5250. break;
  5251. default:
  5252. mapreg_setregstr(add_str((unsigned char *) "$@partymembername$")+(j<<24),p->party.member[i].name);
  5253. }
  5254. j++;
  5255. }
  5256. }
  5257. }
  5258. mapreg_setreg(add_str((unsigned char *) "$@partymembercount"),j);
  5259. return 0;
  5260. }
  5261. /*==========================================
  5262. * Retrieves party leader. if flag is specified,
  5263. * return some of the leader data. Otherwise, return name.
  5264. *------------------------------------------
  5265. */
  5266. int buildin_getpartyleader(struct script_state *st)
  5267. {
  5268. int party_id, type = 0, i=0;
  5269. struct party_data *p;
  5270. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5271. if( st->end>st->start+3 )
  5272. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5273. p=party_search(party_id);
  5274. if (p) //Search leader
  5275. for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++);
  5276. if (!p || i == MAX_PARTY) { //leader not found
  5277. if (type)
  5278. push_val(st->stack,C_INT,-1);
  5279. else
  5280. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  5281. return 0;
  5282. }
  5283. switch (type) {
  5284. case 1:
  5285. push_val(st->stack,C_INT,p->party.member[i].account_id);
  5286. break;
  5287. case 2:
  5288. push_val(st->stack,C_INT,p->party.member[i].char_id);
  5289. break;
  5290. case 3:
  5291. push_val(st->stack,C_INT,p->party.member[i].class_);
  5292. break;
  5293. case 4:
  5294. push_val(st->stack,C_INT,p->party.member[i].map);
  5295. break;
  5296. case 5:
  5297. push_val(st->stack,C_INT,p->party.member[i].lv);
  5298. break;
  5299. default:
  5300. push_str(st->stack,C_STR,(unsigned char *)p->party.member[i].name);
  5301. break;
  5302. }
  5303. return 0;
  5304. }
  5305. /*==========================================
  5306. *指定IDのギルド名取得
  5307. *------------------------------------------
  5308. */
  5309. char *buildin_getguildname_sub(int guild_id)
  5310. {
  5311. struct guild *g=NULL;
  5312. g=guild_search(guild_id);
  5313. if(g!=NULL){
  5314. char *buf;
  5315. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5316. memcpy(buf, g->name, NAME_LENGTH-1);
  5317. buf[NAME_LENGTH-1] = '\0';
  5318. return buf;
  5319. }
  5320. return NULL;
  5321. }
  5322. int buildin_getguildname(struct script_state *st)
  5323. {
  5324. char *name;
  5325. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5326. name=buildin_getguildname_sub(guild_id);
  5327. if(name != NULL)
  5328. push_str(st->stack,C_STR,(unsigned char *) name);
  5329. else
  5330. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  5331. return 0;
  5332. }
  5333. /*==========================================
  5334. *指定IDのGuildMaster名取得
  5335. *------------------------------------------
  5336. */
  5337. char *buildin_getguildmaster_sub(int guild_id)
  5338. {
  5339. struct guild *g=NULL;
  5340. g=guild_search(guild_id);
  5341. if(g!=NULL){
  5342. char *buf;
  5343. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5344. memcpy(buf, g->master, NAME_LENGTH-1);
  5345. buf[NAME_LENGTH-1] = '\0';
  5346. return buf;
  5347. }
  5348. return 0;
  5349. }
  5350. int buildin_getguildmaster(struct script_state *st)
  5351. {
  5352. char *master;
  5353. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5354. master=buildin_getguildmaster_sub(guild_id);
  5355. if(master!=0)
  5356. push_str(st->stack,C_STR,(unsigned char *) master);
  5357. else
  5358. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  5359. return 0;
  5360. }
  5361. int buildin_getguildmasterid(struct script_state *st)
  5362. {
  5363. char *master;
  5364. struct map_session_data *sd=NULL;
  5365. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5366. master=buildin_getguildmaster_sub(guild_id);
  5367. if(master!=0){
  5368. if((sd=map_nick2sd(master)) == NULL){
  5369. push_val(st->stack,C_INT,0);
  5370. return 0;
  5371. }
  5372. push_val(st->stack,C_INT,sd->status.char_id);
  5373. }else{
  5374. push_val(st->stack,C_INT,0);
  5375. }
  5376. return 0;
  5377. }
  5378. /*==========================================
  5379. * キャラクタの名前
  5380. *------------------------------------------
  5381. */
  5382. int buildin_strcharinfo(struct script_state *st)
  5383. {
  5384. struct map_session_data *sd;
  5385. int num;
  5386. char *buf;
  5387. sd=script_rid2sd(st);
  5388. if (!sd) { //Avoid crashing....
  5389. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5390. return 0;
  5391. }
  5392. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5393. switch(num){
  5394. case 0:
  5395. push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->status.name);
  5396. break;
  5397. case 1:
  5398. buf=buildin_getpartyname_sub(sd->status.party_id);
  5399. if(buf!=0)
  5400. push_str(st->stack,C_STR,(unsigned char *) buf);
  5401. else
  5402. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5403. break;
  5404. case 2:
  5405. buf=buildin_getguildname_sub(sd->status.guild_id);
  5406. if(buf != NULL)
  5407. push_str(st->stack,C_STR,(unsigned char *) buf);
  5408. else
  5409. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5410. break;
  5411. default:
  5412. ShowWarning("buildin_strcharinfo: unknown parameter.");
  5413. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  5414. break;
  5415. }
  5416. return 0;
  5417. }
  5418. 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};
  5419. /*==========================================
  5420. * GetEquipID(Pos); Pos: 1-10
  5421. *------------------------------------------
  5422. */
  5423. int buildin_getequipid(struct script_state *st)
  5424. {
  5425. int i,num;
  5426. struct map_session_data *sd;
  5427. struct item_data* item;
  5428. sd=script_rid2sd(st);
  5429. if(sd == NULL)
  5430. {
  5431. ShowError("getequipid: sd == NULL\n");
  5432. return 0;
  5433. }
  5434. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5435. i=pc_checkequip(sd,equip[num-1]);
  5436. if(i >= 0){
  5437. item=sd->inventory_data[i];
  5438. if(item)
  5439. push_val(st->stack,C_INT,item->nameid);
  5440. else
  5441. push_val(st->stack,C_INT,0);
  5442. }else{
  5443. push_val(st->stack,C_INT,-1);
  5444. }
  5445. return 0;
  5446. }
  5447. /*==========================================
  5448. * 装備名文字列(精錬メニュー用)
  5449. *------------------------------------------
  5450. */
  5451. int buildin_getequipname(struct script_state *st)
  5452. {
  5453. int i,num;
  5454. struct map_session_data *sd;
  5455. struct item_data* item;
  5456. char *buf;
  5457. buf=(char *)aMallocA(64*sizeof(char));
  5458. sd=script_rid2sd(st);
  5459. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5460. i=pc_checkequip(sd,equip[num-1]);
  5461. if(i >= 0){
  5462. item=sd->inventory_data[i];
  5463. if(item)
  5464. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  5465. else
  5466. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5467. }else{
  5468. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5469. }
  5470. push_str(st->stack,C_STR,(unsigned char *) buf);
  5471. return 0;
  5472. }
  5473. /*==========================================
  5474. * getbrokenid [Valaris]
  5475. *------------------------------------------
  5476. */
  5477. int buildin_getbrokenid(struct script_state *st)
  5478. {
  5479. int i,num,id=0,brokencounter=0;
  5480. struct map_session_data *sd;
  5481. sd=script_rid2sd(st);
  5482. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5483. for(i=0; i<MAX_INVENTORY; i++) {
  5484. if(sd->status.inventory[i].attribute==1){
  5485. brokencounter++;
  5486. if(num==brokencounter){
  5487. id=sd->status.inventory[i].nameid;
  5488. break;
  5489. }
  5490. }
  5491. }
  5492. push_val(st->stack,C_INT,id);
  5493. return 0;
  5494. }
  5495. /*==========================================
  5496. * repair [Valaris]
  5497. *------------------------------------------
  5498. */
  5499. int buildin_repair(struct script_state *st)
  5500. {
  5501. int i,num;
  5502. int repaircounter=0;
  5503. struct map_session_data *sd;
  5504. sd=script_rid2sd(st);
  5505. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5506. for(i=0; i<MAX_INVENTORY; i++) {
  5507. if(sd->status.inventory[i].attribute==1){
  5508. repaircounter++;
  5509. if(num==repaircounter){
  5510. sd->status.inventory[i].attribute=0;
  5511. clif_equiplist(sd);
  5512. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  5513. clif_misceffect(&sd->bl, 3);
  5514. clif_displaymessage(sd->fd,"Item has been repaired.");
  5515. break;
  5516. }
  5517. }
  5518. }
  5519. return 0;
  5520. }
  5521. /*==========================================
  5522. * 装備チェック
  5523. *------------------------------------------
  5524. */
  5525. int buildin_getequipisequiped(struct script_state *st)
  5526. {
  5527. int i,num;
  5528. struct map_session_data *sd;
  5529. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5530. sd=script_rid2sd(st);
  5531. if ((num - 1) >= (sizeof(equip) / sizeof(equip[0])))
  5532. i = -1;
  5533. else
  5534. i=pc_checkequip(sd,equip[num-1]);
  5535. if(i >= 0)
  5536. push_val(st->stack,C_INT,1);
  5537. else
  5538. push_val(st->stack,C_INT,0);
  5539. return 0;
  5540. }
  5541. /*==========================================
  5542. * 装備品精錬可能チェック
  5543. *------------------------------------------
  5544. */
  5545. int buildin_getequipisenableref(struct script_state *st)
  5546. {
  5547. int i,num;
  5548. struct map_session_data *sd;
  5549. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5550. sd=script_rid2sd(st);
  5551. i=pc_checkequip(sd,equip[num-1]);
  5552. if(i >= 0 && num<7 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
  5553. {
  5554. push_val(st->stack,C_INT,1);
  5555. } else {
  5556. push_val(st->stack,C_INT,0);
  5557. }
  5558. return 0;
  5559. }
  5560. /*==========================================
  5561. * 装備品鑑定チェック
  5562. *------------------------------------------
  5563. */
  5564. int buildin_getequipisidentify(struct script_state *st)
  5565. {
  5566. int i,num;
  5567. struct map_session_data *sd;
  5568. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5569. sd=script_rid2sd(st);
  5570. i=pc_checkequip(sd,equip[num-1]);
  5571. if(i >= 0)
  5572. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  5573. else
  5574. push_val(st->stack,C_INT,0);
  5575. return 0;
  5576. }
  5577. /*==========================================
  5578. * 装備品精錬度
  5579. *------------------------------------------
  5580. */
  5581. int buildin_getequiprefinerycnt(struct script_state *st)
  5582. {
  5583. int i,num;
  5584. struct map_session_data *sd;
  5585. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5586. sd=script_rid2sd(st);
  5587. i=pc_checkequip(sd,equip[num-1]);
  5588. if(i >= 0)
  5589. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  5590. else
  5591. push_val(st->stack,C_INT,0);
  5592. return 0;
  5593. }
  5594. /*==========================================
  5595. * 装備品武器LV
  5596. *------------------------------------------
  5597. */
  5598. int buildin_getequipweaponlv(struct script_state *st)
  5599. {
  5600. int i,num;
  5601. struct map_session_data *sd;
  5602. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5603. sd=script_rid2sd(st);
  5604. i=pc_checkequip(sd,equip[num-1]);
  5605. if(i >= 0 && sd->inventory_data[i])
  5606. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  5607. else
  5608. push_val(st->stack,C_INT,0);
  5609. return 0;
  5610. }
  5611. /*==========================================
  5612. * 装備品精錬成功率
  5613. *------------------------------------------
  5614. */
  5615. int buildin_getequippercentrefinery(struct script_state *st)
  5616. {
  5617. int i,num;
  5618. struct map_session_data *sd;
  5619. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5620. sd=script_rid2sd(st);
  5621. i=pc_checkequip(sd,equip[num-1]);
  5622. if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
  5623. push_val(st->stack,C_INT,percentrefinery[itemdb_wlv(sd->status.inventory[i].nameid)][(int)sd->status.inventory[i].refine]);
  5624. else
  5625. push_val(st->stack,C_INT,0);
  5626. return 0;
  5627. }
  5628. /*==========================================
  5629. * 精錬成功
  5630. *------------------------------------------
  5631. */
  5632. int buildin_successrefitem(struct script_state *st)
  5633. {
  5634. int i,num,ep;
  5635. struct map_session_data *sd;
  5636. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5637. sd=script_rid2sd(st);
  5638. i=pc_checkequip(sd,equip[num-1]);
  5639. if(i >= 0) {
  5640. ep=sd->status.inventory[i].equip;
  5641. //Logs items, got from (N)PC scripts [Lupus]
  5642. if(log_config.enable_logs&0x40)
  5643. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5644. sd->status.inventory[i].refine++;
  5645. pc_unequipitem(sd,i,2);
  5646. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  5647. clif_delitem(sd,i,1);
  5648. //Logs items, got from (N)PC scripts [Lupus]
  5649. if(log_config.enable_logs&0x40)
  5650. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]);
  5651. clif_additem(sd,i,1,0);
  5652. pc_equipitem(sd,i,ep);
  5653. clif_misceffect(&sd->bl,3);
  5654. if(sd->status.inventory[i].refine == MAX_REFINE &&
  5655. sd->status.inventory[i].card[0] == CARD0_FORGE &&
  5656. sd->char_id == MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])
  5657. ){ // Fame point system [DracoRPG]
  5658. switch (sd->inventory_data[i]->wlv){
  5659. case 1:
  5660. pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
  5661. break;
  5662. case 2:
  5663. pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
  5664. break;
  5665. case 3:
  5666. pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
  5667. break;
  5668. }
  5669. }
  5670. }
  5671. return 0;
  5672. }
  5673. /*==========================================
  5674. * 精錬失敗
  5675. *------------------------------------------
  5676. */
  5677. int buildin_failedrefitem(struct script_state *st)
  5678. {
  5679. int i,num;
  5680. struct map_session_data *sd;
  5681. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5682. sd=script_rid2sd(st);
  5683. i=pc_checkequip(sd,equip[num-1]);
  5684. if(i >= 0) {
  5685. //Logs items, got from (N)PC scripts [Lupus]
  5686. if(log_config.enable_logs&0x40)
  5687. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5688. sd->status.inventory[i].refine = 0;
  5689. pc_unequipitem(sd,i,3);
  5690. // 精錬失敗エフェクトのパケット
  5691. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  5692. pc_delitem(sd,i,1,0);
  5693. // 他の人にも失敗を通知
  5694. clif_misceffect(&sd->bl,2);
  5695. }
  5696. return 0;
  5697. }
  5698. /*==========================================
  5699. *
  5700. *------------------------------------------
  5701. */
  5702. int buildin_statusup(struct script_state *st)
  5703. {
  5704. int type;
  5705. struct map_session_data *sd;
  5706. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5707. sd=script_rid2sd(st);
  5708. pc_statusup(sd,type);
  5709. return 0;
  5710. }
  5711. /*==========================================
  5712. *
  5713. *------------------------------------------
  5714. */
  5715. int buildin_statusup2(struct script_state *st)
  5716. {
  5717. int type,val;
  5718. struct map_session_data *sd;
  5719. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5720. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5721. sd=script_rid2sd(st);
  5722. pc_statusup2(sd,type,val);
  5723. return 0;
  5724. }
  5725. /*==========================================
  5726. * 装備品による能力値ボーナス
  5727. *------------------------------------------
  5728. */
  5729. int buildin_bonus(struct script_state *st)
  5730. {
  5731. int type,val;
  5732. struct map_session_data *sd;
  5733. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5734. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5735. sd=script_rid2sd(st);
  5736. pc_bonus(sd,type,val);
  5737. return 0;
  5738. }
  5739. /*==========================================
  5740. * 装備品による能力値ボーナス
  5741. *------------------------------------------
  5742. */
  5743. int buildin_bonus2(struct script_state *st)
  5744. {
  5745. int type,type2,val;
  5746. struct map_session_data *sd;
  5747. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5748. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5749. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5750. sd=script_rid2sd(st);
  5751. pc_bonus2(sd,type,type2,val);
  5752. return 0;
  5753. }
  5754. /*==========================================
  5755. * 装備品による能力値ボーナス
  5756. *------------------------------------------
  5757. */
  5758. int buildin_bonus3(struct script_state *st)
  5759. {
  5760. int type,type2,type3,val;
  5761. struct map_session_data *sd;
  5762. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5763. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5764. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5765. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5766. sd=script_rid2sd(st);
  5767. pc_bonus3(sd,type,type2,type3,val);
  5768. return 0;
  5769. }
  5770. int buildin_bonus4(struct script_state *st)
  5771. {
  5772. int type,type2,type3,type4,val;
  5773. struct map_session_data *sd;
  5774. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5775. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5776. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5777. type4=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5778. val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5779. sd=script_rid2sd(st);
  5780. pc_bonus4(sd,type,type2,type3,type4,val);
  5781. return 0;
  5782. }
  5783. /*==========================================
  5784. * スキル所得
  5785. *------------------------------------------
  5786. */
  5787. int buildin_skill(struct script_state *st)
  5788. {
  5789. int id,level,flag=1;
  5790. struct map_session_data *sd;
  5791. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5792. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5793. if( st->end>st->start+4 )
  5794. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5795. sd=script_rid2sd(st);
  5796. pc_skill(sd,id,level,flag);
  5797. return 0;
  5798. }
  5799. // add x levels of skill (stackable) [Valaris]
  5800. int buildin_addtoskill(struct script_state *st)
  5801. {
  5802. int id,level,flag=2;
  5803. struct map_session_data *sd;
  5804. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5805. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5806. if( st->end>st->start+4 )
  5807. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5808. sd=script_rid2sd(st);
  5809. pc_skill(sd,id,level,flag);
  5810. return 0;
  5811. }
  5812. /*==========================================
  5813. * ギルドスキル取得
  5814. *------------------------------------------
  5815. */
  5816. int buildin_guildskill(struct script_state *st)
  5817. {
  5818. int id,level,flag=0;
  5819. struct map_session_data *sd;
  5820. int i=0;
  5821. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5822. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5823. if( st->end>st->start+4 )
  5824. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5825. sd=script_rid2sd(st);
  5826. for(i=0;i<level;i++)
  5827. guild_skillup(sd,id,flag);
  5828. return 0;
  5829. }
  5830. /*==========================================
  5831. * スキルレベル所得
  5832. *------------------------------------------
  5833. */
  5834. int buildin_getskilllv(struct script_state *st)
  5835. {
  5836. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5837. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  5838. return 0;
  5839. }
  5840. /*==========================================
  5841. * getgdskilllv(Guild_ID, Skill_ID);
  5842. * skill_id = 10000 : GD_APPROVAL
  5843. * 10001 : GD_KAFRACONTRACT
  5844. * 10002 : GD_GUARDIANRESEARCH
  5845. * 10003 : GD_GUARDUP
  5846. * 10004 : GD_EXTENSION
  5847. *------------------------------------------
  5848. */
  5849. int buildin_getgdskilllv(struct script_state *st)
  5850. {
  5851. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5852. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5853. struct guild *g=guild_search(guild_id);
  5854. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  5855. return 0;
  5856. /*
  5857. struct map_session_data *sd=NULL;
  5858. struct guild *g=NULL;
  5859. int skill_id;
  5860. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5861. sd=script_rid2sd(st);
  5862. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  5863. if(sd && g) {
  5864. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  5865. } else {
  5866. push_val(st->stack,C_INT,-1);
  5867. }
  5868. return 0;
  5869. */
  5870. }
  5871. /*==========================================
  5872. *
  5873. *------------------------------------------
  5874. */
  5875. int buildin_basicskillcheck(struct script_state *st)
  5876. {
  5877. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  5878. return 0;
  5879. }
  5880. /*==========================================
  5881. *
  5882. *------------------------------------------
  5883. */
  5884. int buildin_getgmlevel(struct script_state *st)
  5885. {
  5886. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  5887. return 0;
  5888. }
  5889. /*==========================================
  5890. *
  5891. *------------------------------------------
  5892. */
  5893. int buildin_end(struct script_state *st)
  5894. {
  5895. st->state = END;
  5896. return 0;
  5897. }
  5898. /*==========================================
  5899. *
  5900. *------------------------------------------
  5901. */
  5902. int buildin_checkoption(struct script_state *st)
  5903. {
  5904. int type;
  5905. struct map_session_data *sd;
  5906. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5907. sd=script_rid2sd(st);
  5908. if(sd->sc.option & type){
  5909. push_val(st->stack,C_INT,1);
  5910. } else {
  5911. push_val(st->stack,C_INT,0);
  5912. }
  5913. return 0;
  5914. }
  5915. /*==========================================
  5916. *
  5917. *------------------------------------------
  5918. */
  5919. int buildin_checkoption1(struct script_state *st)
  5920. {
  5921. int type;
  5922. struct map_session_data *sd;
  5923. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5924. sd=script_rid2sd(st);
  5925. if(sd->sc.opt1 & type){
  5926. push_val(st->stack,C_INT,1);
  5927. } else {
  5928. push_val(st->stack,C_INT,0);
  5929. }
  5930. return 0;
  5931. }
  5932. /*==========================================
  5933. *
  5934. *------------------------------------------
  5935. */
  5936. int buildin_checkoption2(struct script_state *st)
  5937. {
  5938. int type;
  5939. struct map_session_data *sd;
  5940. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5941. sd=script_rid2sd(st);
  5942. if(sd->sc.opt2 & type){
  5943. push_val(st->stack,C_INT,1);
  5944. } else {
  5945. push_val(st->stack,C_INT,0);
  5946. }
  5947. return 0;
  5948. }
  5949. /*==========================================
  5950. *
  5951. *------------------------------------------
  5952. */
  5953. int buildin_setoption(struct script_state *st)
  5954. {
  5955. int type;
  5956. struct map_session_data *sd;
  5957. int flag=1;
  5958. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5959. if(st->end>st->start+3 )
  5960. flag=conv_num(st,&(st->stack->stack_data[st->start+3]) );
  5961. else if (!type) { //Request to remove everything.
  5962. flag = 0;
  5963. type = OPTION_CART|OPTION_FALCON|OPTION_RIDING;
  5964. }
  5965. sd=script_rid2sd(st);
  5966. if (!sd) return 0;
  5967. if (flag) {//Add option
  5968. if (type&OPTION_WEDDING && !battle_config.wedding_modifydisplay)
  5969. type&=~OPTION_WEDDING; //Do not show the wedding sprites
  5970. pc_setoption(sd,sd->sc.option|type);
  5971. } else//Remove option
  5972. pc_setoption(sd,sd->sc.option&~type);
  5973. return 0;
  5974. }
  5975. /*==========================================
  5976. * Checkcart [Valaris]
  5977. *------------------------------------------
  5978. */
  5979. int buildin_checkcart(struct script_state *st)
  5980. {
  5981. struct map_session_data *sd;
  5982. sd=script_rid2sd(st);
  5983. if(pc_iscarton(sd)){
  5984. push_val(st->stack,C_INT,1);
  5985. } else {
  5986. push_val(st->stack,C_INT,0);
  5987. }
  5988. return 0;
  5989. }
  5990. /*==========================================
  5991. * カートを付ける
  5992. *------------------------------------------
  5993. */
  5994. int buildin_setcart(struct script_state *st)
  5995. {
  5996. struct map_session_data *sd;
  5997. sd=script_rid2sd(st);
  5998. pc_setcart(sd,1);
  5999. return 0;
  6000. }
  6001. /*==========================================
  6002. * checkfalcon [Valaris]
  6003. *------------------------------------------
  6004. */
  6005. int buildin_checkfalcon(struct script_state *st)
  6006. {
  6007. struct map_session_data *sd;
  6008. sd=script_rid2sd(st);
  6009. if(pc_isfalcon(sd)){
  6010. push_val(st->stack,C_INT,1);
  6011. } else {
  6012. push_val(st->stack,C_INT,0);
  6013. }
  6014. return 0;
  6015. }
  6016. /*==========================================
  6017. * 鷹を付ける
  6018. *------------------------------------------
  6019. */
  6020. int buildin_setfalcon(struct script_state *st)
  6021. {
  6022. struct map_session_data *sd;
  6023. sd=script_rid2sd(st);
  6024. pc_setfalcon(sd);
  6025. return 0;
  6026. }
  6027. /*==========================================
  6028. * Checkcart [Valaris]
  6029. *------------------------------------------
  6030. */
  6031. int buildin_checkriding(struct script_state *st)
  6032. {
  6033. struct map_session_data *sd;
  6034. sd=script_rid2sd(st);
  6035. if(pc_isriding(sd)){
  6036. push_val(st->stack,C_INT,1);
  6037. } else {
  6038. push_val(st->stack,C_INT,0);
  6039. }
  6040. return 0;
  6041. }
  6042. /*==========================================
  6043. * ペコペコ乗り
  6044. *------------------------------------------
  6045. */
  6046. int buildin_setriding(struct script_state *st)
  6047. {
  6048. struct map_session_data *sd;
  6049. sd=script_rid2sd(st);
  6050. pc_setriding(sd);
  6051. return 0;
  6052. }
  6053. /*==========================================
  6054. * セーブポイントの保存
  6055. *------------------------------------------
  6056. */
  6057. int buildin_savepoint(struct script_state *st)
  6058. {
  6059. int x,y;
  6060. short map;
  6061. char *str;
  6062. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6063. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6064. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6065. map = mapindex_name2id(str);
  6066. if (map)
  6067. pc_setsavepoint(script_rid2sd(st),map,x,y);
  6068. return 0;
  6069. }
  6070. /*==========================================
  6071. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  6072. *------------------------------------------
  6073. */
  6074. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  6075. {
  6076. int type;
  6077. time_t timer;
  6078. struct tm *t;
  6079. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6080. switch(type){
  6081. case 2:
  6082. //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
  6083. // from the system clock.)
  6084. push_val(st->stack,C_INT,(int)time(NULL));
  6085. break;
  6086. case 1:
  6087. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  6088. time(&timer);
  6089. t=localtime(&timer);
  6090. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  6091. break;
  6092. case 0:
  6093. default:
  6094. //type 0:(System Ticks)
  6095. push_val(st->stack,C_INT,gettick());
  6096. break;
  6097. }
  6098. return 0;
  6099. }
  6100. /*==========================================
  6101. * GetTime(Type);
  6102. * 1: Sec 2: Min 3: Hour
  6103. * 4: WeekDay 5: MonthDay 6: Month
  6104. * 7: Year
  6105. *------------------------------------------
  6106. */
  6107. int buildin_gettime(struct script_state *st) /* Asgard Version */
  6108. {
  6109. int type;
  6110. time_t timer;
  6111. struct tm *t;
  6112. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6113. time(&timer);
  6114. t=localtime(&timer);
  6115. switch(type){
  6116. case 1://Sec(0~59)
  6117. push_val(st->stack,C_INT,t->tm_sec);
  6118. break;
  6119. case 2://Min(0~59)
  6120. push_val(st->stack,C_INT,t->tm_min);
  6121. break;
  6122. case 3://Hour(0~23)
  6123. push_val(st->stack,C_INT,t->tm_hour);
  6124. break;
  6125. case 4://WeekDay(0~6)
  6126. push_val(st->stack,C_INT,t->tm_wday);
  6127. break;
  6128. case 5://MonthDay(01~31)
  6129. push_val(st->stack,C_INT,t->tm_mday);
  6130. break;
  6131. case 6://Month(01~12)
  6132. push_val(st->stack,C_INT,t->tm_mon+1);
  6133. break;
  6134. case 7://Year(20xx)
  6135. push_val(st->stack,C_INT,t->tm_year+1900);
  6136. break;
  6137. case 8://Year Day(01~366)
  6138. push_val(st->stack,C_INT,t->tm_yday+1);
  6139. break;
  6140. default://(format error)
  6141. push_val(st->stack,C_INT,-1);
  6142. break;
  6143. }
  6144. return 0;
  6145. }
  6146. /*==========================================
  6147. * GetTimeStr("TimeFMT", Length);
  6148. *------------------------------------------
  6149. */
  6150. int buildin_gettimestr(struct script_state *st)
  6151. {
  6152. char *tmpstr;
  6153. char *fmtstr;
  6154. int maxlen;
  6155. time_t now = time(NULL);
  6156. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6157. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6158. tmpstr=(char *)aMallocA((maxlen+1)*sizeof(char));
  6159. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  6160. tmpstr[maxlen]='\0';
  6161. push_str(st->stack,C_STR,(unsigned char *) tmpstr);
  6162. return 0;
  6163. }
  6164. /*==========================================
  6165. * カプラ倉庫を開く
  6166. *------------------------------------------
  6167. */
  6168. int buildin_openstorage(struct script_state *st)
  6169. {
  6170. storage_storageopen(script_rid2sd(st));
  6171. return 0;
  6172. }
  6173. int buildin_guildopenstorage(struct script_state *st)
  6174. {
  6175. struct map_session_data *sd=script_rid2sd(st);
  6176. int ret;
  6177. ret = storage_guild_storageopen(sd);
  6178. push_val(st->stack,C_INT,ret);
  6179. return 0;
  6180. }
  6181. /*==========================================
  6182. * アイテムによるスキル発動
  6183. *------------------------------------------
  6184. */
  6185. int buildin_itemskill(struct script_state *st)
  6186. {
  6187. int id,lv;
  6188. char *str;
  6189. struct map_session_data *sd=script_rid2sd(st);
  6190. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6191. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6192. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6193. // 詠唱中にスキルアイテムは使用できない
  6194. if(sd->ud.skilltimer != -1)
  6195. return 0;
  6196. sd->skillitem=id;
  6197. sd->skillitemlv=lv;
  6198. clif_item_skill(sd,id,lv,str);
  6199. return 0;
  6200. }
  6201. /*==========================================
  6202. * アイテム作成
  6203. *------------------------------------------
  6204. */
  6205. int buildin_produce(struct script_state *st)
  6206. {
  6207. int trigger;
  6208. struct map_session_data *sd=script_rid2sd(st);
  6209. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6210. clif_skill_produce_mix_list(sd, trigger);
  6211. return 0;
  6212. }
  6213. /*==========================================
  6214. * NPCでペット作る
  6215. *------------------------------------------
  6216. */
  6217. int buildin_makepet(struct script_state *st)
  6218. {
  6219. struct map_session_data *sd = script_rid2sd(st);
  6220. struct script_data *data;
  6221. int id,pet_id;
  6222. data=&(st->stack->stack_data[st->start+2]);
  6223. get_val(st,data);
  6224. id=conv_num(st,data);
  6225. pet_id = search_petDB_index(id, PET_CLASS);
  6226. if (pet_id < 0)
  6227. pet_id = search_petDB_index(id, PET_EGG);
  6228. if (pet_id >= 0 && sd) {
  6229. sd->catch_target_class = pet_db[pet_id].class_;
  6230. intif_create_pet(
  6231. sd->status.account_id, sd->status.char_id,
  6232. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  6233. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  6234. 100, 0, 1, pet_db[pet_id].jname);
  6235. }
  6236. return 0;
  6237. }
  6238. /*==========================================
  6239. * NPCで経験値上げる
  6240. *------------------------------------------
  6241. */
  6242. int buildin_getexp(struct script_state *st)
  6243. {
  6244. struct map_session_data *sd = script_rid2sd(st);
  6245. int base=0,job=0;
  6246. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6247. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6248. if(base<0 || job<0)
  6249. return 0;
  6250. if(sd)
  6251. pc_gainexp(sd,NULL,base,job);
  6252. return 0;
  6253. }
  6254. /*==========================================
  6255. * Gain guild exp [Celest]
  6256. *------------------------------------------
  6257. */
  6258. int buildin_guildgetexp(struct script_state *st)
  6259. {
  6260. struct map_session_data *sd = script_rid2sd(st);
  6261. int exp;
  6262. exp = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6263. if(exp < 0)
  6264. return 0;
  6265. if(sd && sd->status.guild_id > 0)
  6266. guild_getexp (sd, exp);
  6267. return 0;
  6268. }
  6269. /*==========================================
  6270. * Changes the guild master of a guild [Skotlex]
  6271. *------------------------------------------
  6272. */
  6273. int buildin_guildchangegm(struct script_state *st)
  6274. {
  6275. struct map_session_data *sd;
  6276. int guild_id;
  6277. char *name;
  6278. guild_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6279. name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  6280. sd=map_nick2sd(name);
  6281. if (!sd)
  6282. push_val(st->stack,C_INT,0);
  6283. else
  6284. push_val(st->stack,C_INT,guild_gm_change(guild_id, sd));
  6285. return 0;
  6286. }
  6287. /*==========================================
  6288. * モンスター発生
  6289. *------------------------------------------
  6290. */
  6291. int buildin_monster(struct script_state *st)
  6292. {
  6293. int class_,amount,x,y;
  6294. char *str,*map,*event="";
  6295. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6296. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6297. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6298. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  6299. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6300. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6301. if( st->end>st->start+8 ){
  6302. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  6303. check_event(st, event);
  6304. }
  6305. if (class_ >= 0 && !mobdb_checkid(class_)) {
  6306. ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
  6307. return 1;
  6308. }
  6309. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
  6310. return 0;
  6311. }
  6312. /*==========================================
  6313. * モンスター発生
  6314. *------------------------------------------
  6315. */
  6316. int buildin_areamonster(struct script_state *st)
  6317. {
  6318. int class_,amount,x0,y0,x1,y1;
  6319. char *str,*map,*event="";
  6320. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6321. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6322. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6323. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  6324. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  6325. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  6326. class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6327. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6328. if( st->end>st->start+10 ){
  6329. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  6330. check_event(st, event);
  6331. }
  6332. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
  6333. return 0;
  6334. }
  6335. /*==========================================
  6336. * モンスター削除
  6337. *------------------------------------------
  6338. */
  6339. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  6340. {
  6341. TBL_MOB* md = (TBL_MOB*)bl;
  6342. char *event=va_arg(ap,char *);
  6343. int allflag=va_arg(ap,int);
  6344. if(!allflag){
  6345. if(strcmp(event,md->npc_event)==0)
  6346. status_kill(bl);
  6347. return 0;
  6348. }else{
  6349. if(!md->spawn)
  6350. status_kill(bl);
  6351. return 0;
  6352. }
  6353. return 0;
  6354. }
  6355. int buildin_killmonster(struct script_state *st)
  6356. {
  6357. char *mapname,*event;
  6358. int m,allflag=0;
  6359. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6360. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6361. if(strcmp(event,"All")==0)
  6362. allflag = 1;
  6363. else
  6364. check_event(st, event);
  6365. if( (m=map_mapname2mapid(mapname))<0 )
  6366. return 0;
  6367. map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
  6368. return 0;
  6369. }
  6370. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  6371. {
  6372. status_kill(bl);
  6373. return 0;
  6374. }
  6375. int buildin_killmonsterall(struct script_state *st)
  6376. {
  6377. char *mapname;
  6378. int m;
  6379. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6380. if( (m=map_mapname2mapid(mapname))<0 )
  6381. return 0;
  6382. map_foreachinmap(buildin_killmonsterall_sub,
  6383. m,BL_MOB);
  6384. return 0;
  6385. }
  6386. /*==========================================
  6387. * Creates a clone of a player.
  6388. * clone map, x, y, event, char_id, master_id, mode, flag, duration
  6389. *------------------------------------------
  6390. */
  6391. int buildin_clone(struct script_state *st) {
  6392. struct map_session_data *sd, *msd=NULL;
  6393. int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
  6394. unsigned int duration = 0;
  6395. char *map,*event="";
  6396. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6397. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6398. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6399. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6400. char_id=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6401. if( st->end>st->start+7 )
  6402. master_id=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6403. if( st->end>st->start+8 )
  6404. mode=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6405. if( st->end>st->start+9 )
  6406. flag=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6407. if( st->end>st->start+10 )
  6408. duration=conv_num(st,& (st->stack->stack_data[st->start+10]));
  6409. check_event(st, event);
  6410. m = map_mapname2mapid(map);
  6411. if (m < 0) return 0;
  6412. sd = map_charid2sd(char_id);
  6413. if (master_id) {
  6414. msd = map_charid2sd(master_id);
  6415. if (msd)
  6416. master_id = msd->bl.id;
  6417. else
  6418. master_id = 0;
  6419. }
  6420. if (sd) //Return ID of newly crafted clone.
  6421. push_val(st->stack,C_INT,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
  6422. else //Failed to create clone.
  6423. push_val(st->stack,C_INT,0);
  6424. return 0;
  6425. }
  6426. /*==========================================
  6427. * イベント実行
  6428. *------------------------------------------
  6429. */
  6430. int buildin_doevent(struct script_state *st)
  6431. {
  6432. char *event;
  6433. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6434. check_event(st, event);
  6435. npc_event(map_id2sd(st->rid),event,0);
  6436. return 0;
  6437. }
  6438. /*==========================================
  6439. * NPC主体イベント実行
  6440. *------------------------------------------
  6441. */
  6442. int buildin_donpcevent(struct script_state *st)
  6443. {
  6444. char *event;
  6445. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6446. check_event(st, event);
  6447. npc_event_do(event);
  6448. return 0;
  6449. }
  6450. /*==========================================
  6451. * イベントタイマー追加
  6452. *------------------------------------------
  6453. */
  6454. int buildin_addtimer(struct script_state *st)
  6455. {
  6456. char *event;
  6457. int tick;
  6458. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6459. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6460. check_event(st, event);
  6461. pc_addeventtimer(script_rid2sd(st),tick,event);
  6462. return 0;
  6463. }
  6464. /*==========================================
  6465. * イベントタイマー削除
  6466. *------------------------------------------
  6467. */
  6468. int buildin_deltimer(struct script_state *st)
  6469. {
  6470. char *event;
  6471. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6472. check_event(st, event);
  6473. pc_deleventtimer(script_rid2sd(st),event);
  6474. return 0;
  6475. }
  6476. /*==========================================
  6477. * イベントタイマーのカウント値追加
  6478. *------------------------------------------
  6479. */
  6480. int buildin_addtimercount(struct script_state *st)
  6481. {
  6482. char *event;
  6483. int tick;
  6484. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6485. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6486. check_event(st, event);
  6487. pc_addeventtimercount(script_rid2sd(st),event,tick);
  6488. return 0;
  6489. }
  6490. /*==========================================
  6491. * NPCタイマー初期化
  6492. *------------------------------------------
  6493. */
  6494. int buildin_initnpctimer(struct script_state *st)
  6495. {
  6496. struct npc_data *nd;
  6497. if( st->end > st->start+2 )
  6498. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6499. else
  6500. nd=(struct npc_data *)map_id2bl(st->oid);
  6501. //nd->u.scr.rid = st->rid; //NO, use npcattachtimer if you want a player-attached timer! [Skotlex]
  6502. npc_settimerevent_tick(nd,0);
  6503. npc_timerevent_start(nd, st->rid);
  6504. return 0;
  6505. }
  6506. /*==========================================
  6507. * NPCタイマー開始
  6508. *------------------------------------------
  6509. */
  6510. int buildin_startnpctimer(struct script_state *st)
  6511. {
  6512. struct npc_data *nd;
  6513. if( st->end > st->start+2 )
  6514. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6515. else
  6516. nd=(struct npc_data *)map_id2bl(st->oid);
  6517. npc_timerevent_start(nd, st->rid);
  6518. return 0;
  6519. }
  6520. /*==========================================
  6521. * NPCタイマー停止
  6522. *------------------------------------------
  6523. */
  6524. int buildin_stopnpctimer(struct script_state *st)
  6525. {
  6526. struct npc_data *nd;
  6527. if( st->end > st->start+2 )
  6528. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6529. else
  6530. nd=(struct npc_data *)map_id2bl(st->oid);
  6531. npc_timerevent_stop(nd);
  6532. return 0;
  6533. }
  6534. /*==========================================
  6535. * NPCタイマー情報所得
  6536. *------------------------------------------
  6537. */
  6538. int buildin_getnpctimer(struct script_state *st)
  6539. {
  6540. struct npc_data *nd;
  6541. struct map_session_data *sd;
  6542. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6543. int val=0;
  6544. if( st->end > st->start+3 )
  6545. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6546. else
  6547. nd=(struct npc_data *)map_id2bl(st->oid);
  6548. switch(type){
  6549. case 0: val=npc_gettimerevent_tick(nd); break;
  6550. case 1:
  6551. if (nd->u.scr.rid) {
  6552. sd = map_id2sd(nd->u.scr.rid);
  6553. if (!sd) {
  6554. if(battle_config.error_log)
  6555. ShowError("buildin_getnpctimer: Attached player not found!\n");
  6556. break;
  6557. }
  6558. val = (sd->npc_timer_id != -1);
  6559. } else
  6560. val= (nd->u.scr.timerid !=-1);
  6561. break;
  6562. case 2: val= nd->u.scr.timeramount; break;
  6563. }
  6564. push_val(st->stack,C_INT,val);
  6565. return 0;
  6566. }
  6567. /*==========================================
  6568. * NPCタイマー値設定
  6569. *------------------------------------------
  6570. */
  6571. int buildin_setnpctimer(struct script_state *st)
  6572. {
  6573. int tick;
  6574. struct npc_data *nd;
  6575. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6576. if( st->end > st->start+3 )
  6577. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6578. else
  6579. nd=(struct npc_data *)map_id2bl(st->oid);
  6580. npc_settimerevent_tick(nd,tick);
  6581. return 0;
  6582. }
  6583. /*==========================================
  6584. * attaches the player rid to the timer [Celest]
  6585. *------------------------------------------
  6586. */
  6587. int buildin_attachnpctimer(struct script_state *st)
  6588. {
  6589. struct map_session_data *sd;
  6590. struct npc_data *nd;
  6591. nd=(struct npc_data *)map_id2bl(st->oid);
  6592. if( st->end > st->start+2 ) {
  6593. char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  6594. sd=map_nick2sd(name);
  6595. } else {
  6596. sd = script_rid2sd(st);
  6597. }
  6598. if (sd==NULL)
  6599. return 0;
  6600. nd->u.scr.rid = sd->bl.id;
  6601. return 0;
  6602. }
  6603. /*==========================================
  6604. * detaches a player rid from the timer [Celest]
  6605. *------------------------------------------
  6606. */
  6607. int buildin_detachnpctimer(struct script_state *st)
  6608. {
  6609. struct npc_data *nd;
  6610. if( st->end > st->start+2 )
  6611. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6612. else
  6613. nd=(struct npc_data *)map_id2bl(st->oid);
  6614. nd->u.scr.rid = 0;
  6615. return 0;
  6616. }
  6617. /*==========================================
  6618. * To avoid "player not attached" script errors, this function is provided,
  6619. * it checks if there is a player attached to the current script. [Skotlex]
  6620. * If no, returns 0, if yes, returns the char_id of the attached player.
  6621. *------------------------------------------
  6622. */
  6623. int buildin_playerattached(struct script_state *st)
  6624. {
  6625. struct map_session_data *sd;
  6626. if (st->rid == 0 || (sd = map_id2sd(st->rid)) == NULL)
  6627. push_val(st->stack,C_INT,0);
  6628. else
  6629. push_val(st->stack,C_INT,st->rid);
  6630. return 0;
  6631. }
  6632. /*==========================================
  6633. * 天の声アナウンス
  6634. *------------------------------------------
  6635. */
  6636. int buildin_announce(struct script_state *st)
  6637. {
  6638. char *str, *color=NULL;
  6639. int flag;
  6640. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6641. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6642. if (st->end>st->start+4)
  6643. color=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6644. if(flag&0x0f){
  6645. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  6646. (struct block_list *)script_rid2sd(st);
  6647. if (color)
  6648. clif_announce(bl,str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0),flag);
  6649. else
  6650. clif_GMmessage(bl,str,(int)strlen(str)+1,flag);
  6651. }else {
  6652. if (color)
  6653. intif_announce(str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0), flag);
  6654. else
  6655. intif_GMmessage(str,(int)strlen(str)+1,flag);
  6656. }
  6657. return 0;
  6658. }
  6659. /*==========================================
  6660. * 天の声アナウンス(特定マップ)
  6661. *------------------------------------------
  6662. */
  6663. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  6664. {
  6665. char *str, *color;
  6666. int len,flag;
  6667. str=va_arg(ap,char *);
  6668. len=va_arg(ap,int);
  6669. flag=va_arg(ap,int);
  6670. color=va_arg(ap,char *);
  6671. if (color)
  6672. clif_announce(bl,str,len, strtol(color, (char **)NULL, 0), flag|3);
  6673. else
  6674. clif_GMmessage(bl,str,len,flag|3);
  6675. return 0;
  6676. }
  6677. int buildin_mapannounce(struct script_state *st)
  6678. {
  6679. char *mapname,*str, *color=NULL;
  6680. int flag,m;
  6681. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6682. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6683. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6684. if (st->end>st->start+5)
  6685. color=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6686. if( (m=map_mapname2mapid(mapname))<0 )
  6687. return 0;
  6688. map_foreachinmap(buildin_mapannounce_sub,
  6689. m, BL_PC, str,strlen(str)+1,flag&0x10, color);
  6690. return 0;
  6691. }
  6692. /*==========================================
  6693. * 天の声アナウンス(特定エリア)
  6694. *------------------------------------------
  6695. */
  6696. int buildin_areaannounce(struct script_state *st)
  6697. {
  6698. char *map,*str,*color=NULL;
  6699. int flag,m;
  6700. int x0,y0,x1,y1;
  6701. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6702. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6703. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6704. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6705. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6706. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  6707. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6708. if (st->end>st->start+9)
  6709. color=conv_str(st,& (st->stack->stack_data[st->start+9]));
  6710. if( (m=map_mapname2mapid(map))<0 )
  6711. return 0;
  6712. map_foreachinarea(buildin_mapannounce_sub,
  6713. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10, color);
  6714. return 0;
  6715. }
  6716. /*==========================================
  6717. * ユーザー数所得
  6718. *------------------------------------------
  6719. */
  6720. int buildin_getusers(struct script_state *st)
  6721. {
  6722. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6723. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  6724. int val=0;
  6725. switch(flag&0x07){
  6726. case 0: val=map[bl->m].users; break;
  6727. case 1: val=map_getusers(); break;
  6728. }
  6729. push_val(st->stack,C_INT,val);
  6730. return 0;
  6731. }
  6732. /*==========================================
  6733. * Works like @WHO - displays all online users names in window
  6734. *------------------------------------------
  6735. */
  6736. int buildin_getusersname(struct script_state *st)
  6737. {
  6738. struct map_session_data *pl_sd = NULL, **pl_allsd;
  6739. int i=0,disp_num=1, users;
  6740. pl_allsd = map_getallusers(&users);
  6741. for (i=0;i<users;i++)
  6742. {
  6743. pl_sd = pl_allsd[i];
  6744. if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) )
  6745. {
  6746. if((disp_num++)%10==0)
  6747. clif_scriptnext(script_rid2sd(st),st->oid);
  6748. clif_scriptmes(script_rid2sd(st),st->oid,pl_sd->status.name);
  6749. }
  6750. }
  6751. return 0;
  6752. }
  6753. /*==========================================
  6754. * マップ指定ユーザー数所得
  6755. *------------------------------------------
  6756. */
  6757. int buildin_getmapusers(struct script_state *st)
  6758. {
  6759. char *str;
  6760. int m;
  6761. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6762. if( (m=map_mapname2mapid(str))< 0){
  6763. push_val(st->stack,C_INT,-1);
  6764. return 0;
  6765. }
  6766. push_val(st->stack,C_INT,map[m].users);
  6767. return 0;
  6768. }
  6769. /*==========================================
  6770. * エリア指定ユーザー数所得
  6771. *------------------------------------------
  6772. */
  6773. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  6774. {
  6775. int *users=va_arg(ap,int *);
  6776. (*users)++;
  6777. return 0;
  6778. }
  6779. int buildin_getareausers(struct script_state *st)
  6780. {
  6781. char *str;
  6782. int m,x0,y0,x1,y1,users=0;
  6783. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6784. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6785. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6786. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6787. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6788. if( (m=map_mapname2mapid(str))< 0){
  6789. push_val(st->stack,C_INT,-1);
  6790. return 0;
  6791. }
  6792. map_foreachinarea(buildin_getareausers_sub,
  6793. m,x0,y0,x1,y1,BL_PC,&users);
  6794. push_val(st->stack,C_INT,users);
  6795. return 0;
  6796. }
  6797. /*==========================================
  6798. * エリア指定ドロップアイテム数所得
  6799. *------------------------------------------
  6800. */
  6801. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  6802. {
  6803. int item=va_arg(ap,int);
  6804. int *amount=va_arg(ap,int *);
  6805. struct flooritem_data *drop=(struct flooritem_data *)bl;
  6806. if(drop->item_data.nameid==item)
  6807. (*amount)+=drop->item_data.amount;
  6808. return 0;
  6809. }
  6810. int buildin_getareadropitem(struct script_state *st)
  6811. {
  6812. char *str;
  6813. int m,x0,y0,x1,y1,item,amount=0;
  6814. struct script_data *data;
  6815. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6816. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6817. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6818. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6819. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6820. data=&(st->stack->stack_data[st->start+7]);
  6821. get_val(st,data);
  6822. if( data->type==C_STR || data->type==C_CONSTSTR ){
  6823. const char *name=conv_str(st,data);
  6824. struct item_data *item_data = itemdb_searchname(name);
  6825. item=UNKNOWN_ITEM_ID;
  6826. if( item_data )
  6827. item=item_data->nameid;
  6828. }else
  6829. item=conv_num(st,data);
  6830. if( (m=map_mapname2mapid(str))< 0){
  6831. push_val(st->stack,C_INT,-1);
  6832. return 0;
  6833. }
  6834. map_foreachinarea(buildin_getareadropitem_sub,
  6835. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  6836. push_val(st->stack,C_INT,amount);
  6837. return 0;
  6838. }
  6839. /*==========================================
  6840. * NPCの有効化
  6841. *------------------------------------------
  6842. */
  6843. int buildin_enablenpc(struct script_state *st)
  6844. {
  6845. char *str;
  6846. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6847. npc_enable(str,1);
  6848. return 0;
  6849. }
  6850. /*==========================================
  6851. * NPCの無効化
  6852. *------------------------------------------
  6853. */
  6854. int buildin_disablenpc(struct script_state *st)
  6855. {
  6856. char *str;
  6857. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6858. npc_enable(str,0);
  6859. return 0;
  6860. }
  6861. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  6862. {
  6863. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6864. struct chat_data *cd;
  6865. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  6866. return 0;
  6867. npc_enable(nd->name,1);
  6868. nd->arenaflag=1;
  6869. if(cd->users>=cd->trigger && cd->npc_event[0])
  6870. npc_timer_event(cd->npc_event);
  6871. return 0;
  6872. }
  6873. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  6874. {
  6875. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6876. nd->arenaflag=0;
  6877. return 0;
  6878. }
  6879. /*==========================================
  6880. * 隠れているNPCの表示
  6881. *------------------------------------------
  6882. */
  6883. int buildin_hideoffnpc(struct script_state *st)
  6884. {
  6885. char *str;
  6886. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6887. npc_enable(str,2);
  6888. return 0;
  6889. }
  6890. /*==========================================
  6891. * NPCをハイディング
  6892. *------------------------------------------
  6893. */
  6894. int buildin_hideonnpc(struct script_state *st)
  6895. {
  6896. char *str;
  6897. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6898. npc_enable(str,4);
  6899. return 0;
  6900. }
  6901. /*==========================================
  6902. * 状態異常にかかる
  6903. *------------------------------------------
  6904. */
  6905. int buildin_sc_start(struct script_state *st)
  6906. {
  6907. struct block_list *bl;
  6908. int type,tick,val1,val4=0;
  6909. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6910. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6911. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6912. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  6913. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  6914. else
  6915. bl = map_id2bl(st->rid);
  6916. if (potion_flag==1 && potion_target) {
  6917. bl = map_id2bl(potion_target);
  6918. tick/=2; //Thrown potions only last half.
  6919. val4 = 1; //Mark that this was a thrown sc_effect
  6920. }
  6921. if (type >= 0 && type < SC_MAX && val1 && !tick)
  6922. { //When there isn't a duration specified, try to get it from the skill_db
  6923. tick = StatusSkillChangeTable[type];
  6924. if (tick)
  6925. tick = skill_get_time(tick,val1);
  6926. else //Failed to retrieve duration, reset to what it was.
  6927. tick = 0;
  6928. }
  6929. if (bl)
  6930. status_change_start(bl,type,10000,val1,0,0,val4,tick,11);
  6931. return 0;
  6932. }
  6933. /*==========================================
  6934. * 状態異常にかかる(確率指定)
  6935. *------------------------------------------
  6936. */
  6937. int buildin_sc_start2(struct script_state *st)
  6938. {
  6939. struct block_list *bl;
  6940. int type,tick,val1,val4=0,per;
  6941. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6942. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6943. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6944. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6945. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  6946. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  6947. else
  6948. bl = map_id2bl(st->rid);
  6949. if (type >= 0 && type < SC_MAX && val1 && !tick)
  6950. { //When there isn't a duration specified, try to get it from the skill_db
  6951. tick = StatusSkillChangeTable[type];
  6952. if (tick)
  6953. tick = skill_get_time(tick,val1);
  6954. else //Failed to retrieve duration, reset to what it was.
  6955. tick = 0;
  6956. }
  6957. if (potion_flag==1 && potion_target) {
  6958. bl = map_id2bl(potion_target);
  6959. tick/=2;
  6960. val4 = 1;
  6961. }
  6962. if(bl)
  6963. status_change_start(bl,type,per,val1,0,0,val4,tick,11);
  6964. return 0;
  6965. }
  6966. /*==========================================
  6967. * Starts a SC_ change with the four values passed. [Skotlex]
  6968. * Final optional argument is the ID of player to affect.
  6969. * sc_start4 type, duration, val1, val2, val3, val4, <id>;
  6970. *------------------------------------------
  6971. */
  6972. int buildin_sc_start4(struct script_state *st)
  6973. {
  6974. struct block_list *bl;
  6975. int type,tick,val1,val2,val3,val4;
  6976. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6977. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6978. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6979. val2=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6980. val3=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6981. val4=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6982. if( st->end>st->start+8 )
  6983. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+8])));
  6984. else
  6985. bl = map_id2bl(st->rid);
  6986. if (type >= 0 && type < SC_MAX && val1 && !tick)
  6987. { //When there isn't a duration specified, try to get it from the skill_db
  6988. tick = StatusSkillChangeTable[type];
  6989. if (tick)
  6990. tick = skill_get_time(tick,val1);
  6991. else //Failed to retrieve duration, reset to what it was.
  6992. tick = 0;
  6993. }
  6994. if (potion_flag==1 && potion_target) {
  6995. bl = map_id2bl(potion_target);
  6996. tick/=2;
  6997. }
  6998. if (bl)
  6999. status_change_start(bl,type,10000,val1,val2,val3,val4,tick,11);
  7000. return 0;
  7001. }
  7002. /*==========================================
  7003. * 状態異常が直る
  7004. *------------------------------------------
  7005. */
  7006. int buildin_sc_end(struct script_state *st)
  7007. {
  7008. struct block_list *bl;
  7009. int type;
  7010. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7011. bl = map_id2bl(st->rid);
  7012. if (potion_flag==1 && potion_target)
  7013. bl = map_id2bl(potion_target);
  7014. if (!bl) return 0;
  7015. if (type >= 0)
  7016. status_change_end(bl,type,-1);
  7017. else
  7018. status_change_clear(bl, 2);
  7019. return 0;
  7020. }
  7021. /*==========================================
  7022. * 状態異常耐性を計算した確率を返す
  7023. *------------------------------------------
  7024. */
  7025. int buildin_getscrate(struct script_state *st)
  7026. {
  7027. struct block_list *bl;
  7028. int sc_def=0,type,rate;
  7029. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7030. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7031. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  7032. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  7033. else
  7034. bl = map_id2bl(st->rid);
  7035. if (bl)
  7036. sc_def = status_get_sc_def(bl,type);
  7037. rate = rate*(10000-sc_def)/10000;
  7038. push_val(st->stack,C_INT,rate<0?0:rate);
  7039. return 0;
  7040. }
  7041. /*==========================================
  7042. *
  7043. *------------------------------------------
  7044. */
  7045. int buildin_debugmes(struct script_state *st)
  7046. {
  7047. conv_str(st,& (st->stack->stack_data[st->start+2]));
  7048. ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  7049. return 0;
  7050. }
  7051. /*==========================================
  7052. *捕獲アイテム使用
  7053. *------------------------------------------
  7054. */
  7055. int buildin_catchpet(struct script_state *st)
  7056. {
  7057. int pet_id;
  7058. struct map_session_data *sd;
  7059. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  7060. sd=script_rid2sd(st);
  7061. pet_catch_process1(sd,pet_id);
  7062. return 0;
  7063. }
  7064. /*==========================================
  7065. * [orn]
  7066. *------------------------------------------
  7067. */
  7068. int buildin_homunculus_evolution(struct script_state *st)
  7069. {
  7070. struct map_session_data *sd;
  7071. sd=script_rid2sd(st);
  7072. if ( sd->hd && sd->hd->homunculusDB->evo_class && sd->homunculus.intimacy > 91000 ) {
  7073. return merc_hom_evolution(sd->hd) ;
  7074. }
  7075. clif_emotion(&sd->hd->bl, 4) ; //swt
  7076. return 0;
  7077. }
  7078. /*==========================================
  7079. *携帯卵孵化機使用
  7080. *------------------------------------------
  7081. */
  7082. int buildin_birthpet(struct script_state *st)
  7083. {
  7084. struct map_session_data *sd;
  7085. sd=script_rid2sd(st);
  7086. clif_sendegg(sd);
  7087. return 0;
  7088. }
  7089. /*==========================================
  7090. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  7091. *------------------------------------------
  7092. */
  7093. int buildin_resetlvl(struct script_state *st)
  7094. {
  7095. struct map_session_data *sd;
  7096. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7097. sd=script_rid2sd(st);
  7098. pc_resetlvl(sd,type);
  7099. return 0;
  7100. }
  7101. /*==========================================
  7102. * ステータスリセット
  7103. *------------------------------------------
  7104. */
  7105. int buildin_resetstatus(struct script_state *st)
  7106. {
  7107. struct map_session_data *sd;
  7108. sd=script_rid2sd(st);
  7109. pc_resetstate(sd);
  7110. return 0;
  7111. }
  7112. /*==========================================
  7113. * script command resetskill
  7114. *------------------------------------------
  7115. */
  7116. int buildin_resetskill(struct script_state *st)
  7117. {
  7118. struct map_session_data *sd;
  7119. sd=script_rid2sd(st);
  7120. pc_resetskill(sd,1);
  7121. return 0;
  7122. }
  7123. /*==========================================
  7124. * Counts total amount of skill points.
  7125. *------------------------------------------
  7126. */
  7127. int buildin_skillpointcount(struct script_state *st)
  7128. {
  7129. struct map_session_data *sd;
  7130. sd=script_rid2sd(st);
  7131. push_val(st->stack,C_INT,sd->status.skill_point + pc_resetskill(sd,2));
  7132. return 0;
  7133. }
  7134. /*==========================================
  7135. *
  7136. *------------------------------------------
  7137. */
  7138. int buildin_changebase(struct script_state *st)
  7139. {
  7140. struct map_session_data *sd=NULL;
  7141. int vclass;
  7142. if( st->end>st->start+3 )
  7143. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  7144. else
  7145. sd=script_rid2sd(st);
  7146. if(sd == NULL)
  7147. return 0;
  7148. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7149. if(vclass == JOB_WEDDING)
  7150. {
  7151. if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
  7152. sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore.
  7153. )
  7154. return 0;
  7155. }
  7156. if(!sd->disguise && vclass != sd->vd.class_) {
  7157. status_set_viewdata(&sd->bl, vclass);
  7158. //Updated client view. Base, Weapon and Cloth Colors.
  7159. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_);
  7160. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7161. if (sd->vd.cloth_color)
  7162. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7163. }
  7164. return 0;
  7165. }
  7166. /*==========================================
  7167. * 性別変換
  7168. *------------------------------------------
  7169. */
  7170. int buildin_changesex(struct script_state *st) {
  7171. struct map_session_data *sd = NULL;
  7172. sd = script_rid2sd(st);
  7173. if (sd->status.sex == 0) {
  7174. sd->status.sex = 1;
  7175. sd->sex = 1;
  7176. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7177. sd->status.class_ -= 1;
  7178. } else if (sd->status.sex == 1) {
  7179. sd->status.sex = 0;
  7180. sd->sex = 0;
  7181. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7182. sd->status.class_ += 1;
  7183. }
  7184. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  7185. chrif_save(sd,0);
  7186. return 0;
  7187. }
  7188. /*==========================================
  7189. * npcチャット作成
  7190. *------------------------------------------
  7191. */
  7192. int buildin_waitingroom(struct script_state *st)
  7193. {
  7194. char *name,*ev="";
  7195. int limit, trigger = 0,pub=1;
  7196. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7197. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  7198. if(limit==0)
  7199. pub=3;
  7200. if( (st->end > st->start+5) ){
  7201. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  7202. get_val(st,data);
  7203. if(data->type==C_INT){
  7204. // 新Athena仕様(旧Athena仕様と互換性あり)
  7205. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7206. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7207. }else{
  7208. // eathena仕様
  7209. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7210. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  7211. }
  7212. }else{
  7213. // 旧Athena仕様
  7214. if( st->end > st->start+4 )
  7215. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7216. }
  7217. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  7218. limit,pub,trigger,name,(int)strlen(name)+1,ev);
  7219. return 0;
  7220. }
  7221. /*==========================================
  7222. * Works like 'announce' but outputs in the common chat window
  7223. *------------------------------------------
  7224. */
  7225. int buildin_globalmes(struct script_state *st)
  7226. {
  7227. struct block_list *bl = map_id2bl(st->oid);
  7228. struct npc_data *nd = (struct npc_data *)bl;
  7229. char *name=NULL,*mes;
  7230. mes=conv_str(st,& (st->stack->stack_data[st->start+2])); // メッセージの取得
  7231. if(mes==NULL) return 0;
  7232. if(st->end>st->start+3){ // NPC名の取得(123#456)
  7233. name=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7234. } else {
  7235. name=nd->name;
  7236. }
  7237. npc_globalmessage(name,mes); // グローバルメッセージ送信
  7238. return 0;
  7239. }
  7240. /*==========================================
  7241. * npcチャット削除
  7242. *------------------------------------------
  7243. */
  7244. int buildin_delwaitingroom(struct script_state *st)
  7245. {
  7246. struct npc_data *nd;
  7247. if( st->end > st->start+2 )
  7248. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7249. else
  7250. nd=(struct npc_data *)map_id2bl(st->oid);
  7251. chat_deletenpcchat(nd);
  7252. return 0;
  7253. }
  7254. /*==========================================
  7255. * npcチャット全員蹴り出す
  7256. *------------------------------------------
  7257. */
  7258. int buildin_waitingroomkickall(struct script_state *st)
  7259. {
  7260. struct npc_data *nd;
  7261. struct chat_data *cd;
  7262. if( st->end > st->start+2 )
  7263. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7264. else
  7265. nd=(struct npc_data *)map_id2bl(st->oid);
  7266. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7267. return 0;
  7268. chat_npckickall(cd);
  7269. return 0;
  7270. }
  7271. /*==========================================
  7272. * npcチャットイベント有効化
  7273. *------------------------------------------
  7274. */
  7275. int buildin_enablewaitingroomevent(struct script_state *st)
  7276. {
  7277. struct npc_data *nd;
  7278. struct chat_data *cd;
  7279. if( st->end > st->start+2 )
  7280. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7281. else
  7282. nd=(struct npc_data *)map_id2bl(st->oid);
  7283. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7284. return 0;
  7285. chat_enableevent(cd);
  7286. return 0;
  7287. }
  7288. /*==========================================
  7289. * npcチャットイベント無効化
  7290. *------------------------------------------
  7291. */
  7292. int buildin_disablewaitingroomevent(struct script_state *st)
  7293. {
  7294. struct npc_data *nd;
  7295. struct chat_data *cd;
  7296. if( st->end > st->start+2 )
  7297. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7298. else
  7299. nd=(struct npc_data *)map_id2bl(st->oid);
  7300. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7301. return 0;
  7302. chat_disableevent(cd);
  7303. return 0;
  7304. }
  7305. /*==========================================
  7306. * npcチャット状態所得
  7307. *------------------------------------------
  7308. */
  7309. int buildin_getwaitingroomstate(struct script_state *st)
  7310. {
  7311. struct npc_data *nd;
  7312. struct chat_data *cd;
  7313. int val=0,type;
  7314. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7315. if( st->end > st->start+3 )
  7316. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  7317. else
  7318. nd=(struct npc_data *)map_id2bl(st->oid);
  7319. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  7320. push_val(st->stack,C_INT,-1);
  7321. return 0;
  7322. }
  7323. switch(type){
  7324. case 0: val=cd->users; break;
  7325. case 1: val=cd->limit; break;
  7326. case 2: val=cd->trigger&0x7f; break;
  7327. case 3: val=((cd->trigger&0x80)>0); break;
  7328. case 32: val=(cd->users >= cd->limit); break;
  7329. case 33: val=(cd->users >= cd->trigger); break;
  7330. case 4:
  7331. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->title);
  7332. return 0;
  7333. case 5:
  7334. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->pass);
  7335. return 0;
  7336. case 16:
  7337. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->npc_event);
  7338. return 0;
  7339. }
  7340. push_val(st->stack,C_INT,val);
  7341. return 0;
  7342. }
  7343. /*==========================================
  7344. * チャットメンバー(規定人数)ワープ
  7345. *------------------------------------------
  7346. */
  7347. int buildin_warpwaitingpc(struct script_state *st)
  7348. {
  7349. int x,y,i,n;
  7350. char *str;
  7351. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7352. struct chat_data *cd;
  7353. struct map_session_data *sd;
  7354. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7355. return 0;
  7356. n=cd->trigger&0x7f;
  7357. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7358. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7359. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7360. if( st->end > st->start+5 )
  7361. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7362. for(i=0;i<n;i++){
  7363. sd=cd->usersd[0];
  7364. if (!sd) continue; //Broken npc chat room?
  7365. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpc")+(i<<24),sd->bl.id);
  7366. if(strcmp(str,"Random")==0)
  7367. pc_randomwarp(sd,3);
  7368. else if(strcmp(str,"SavePoint")==0){
  7369. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  7370. return 0;
  7371. pc_setpos(sd,sd->status.save_point.map,
  7372. sd->status.save_point.x,sd->status.save_point.y,3);
  7373. }else
  7374. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  7375. }
  7376. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpcnum"),n);
  7377. return 0;
  7378. }
  7379. /*==========================================
  7380. * RIDのアタッチ
  7381. *------------------------------------------
  7382. */
  7383. int buildin_attachrid(struct script_state *st)
  7384. {
  7385. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7386. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  7387. return 0;
  7388. }
  7389. /*==========================================
  7390. * RIDのデタッチ
  7391. *------------------------------------------
  7392. */
  7393. int buildin_detachrid(struct script_state *st)
  7394. {
  7395. st->rid=0;
  7396. return 0;
  7397. }
  7398. /*==========================================
  7399. * 存在チェック
  7400. *------------------------------------------
  7401. */
  7402. int buildin_isloggedin(struct script_state *st)
  7403. {
  7404. push_val(st->stack,C_INT, map_id2sd(
  7405. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  7406. return 0;
  7407. }
  7408. /*==========================================
  7409. *
  7410. *------------------------------------------
  7411. */
  7412. int buildin_setmapflagnosave(struct script_state *st)
  7413. {
  7414. int m,x,y;
  7415. unsigned short mapindex;
  7416. char *str,*str2;
  7417. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7418. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7419. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7420. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7421. m = map_mapname2mapid(str);
  7422. mapindex = mapindex_name2id(str2);
  7423. if(m >= 0 && mapindex) {
  7424. map[m].flag.nosave=1;
  7425. map[m].save.map=mapindex;
  7426. map[m].save.x=x;
  7427. map[m].save.y=y;
  7428. }
  7429. return 0;
  7430. }
  7431. int buildin_setmapflag(struct script_state *st)
  7432. {
  7433. int m,i;
  7434. char *str;
  7435. char *val=NULL;
  7436. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7437. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7438. if(st->end>st->start+4){
  7439. val=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7440. }
  7441. m = map_mapname2mapid(str);
  7442. if(m >= 0) {
  7443. switch(i) {
  7444. case MF_NOMEMO:
  7445. map[m].flag.nomemo=1;
  7446. break;
  7447. case MF_NOTELEPORT:
  7448. map[m].flag.noteleport=1;
  7449. break;
  7450. case MF_NOBRANCH:
  7451. map[m].flag.nobranch=1;
  7452. break;
  7453. case MF_NOPENALTY:
  7454. map[m].flag.nopenalty=1;
  7455. break;
  7456. case MF_NOZENYPENALTY:
  7457. map[m].flag.nozenypenalty=1;
  7458. break;
  7459. case MF_PVP:
  7460. map[m].flag.pvp=1;
  7461. break;
  7462. case MF_PVP_NOPARTY:
  7463. map[m].flag.pvp_noparty=1;
  7464. break;
  7465. case MF_PVP_NOGUILD:
  7466. map[m].flag.pvp_noguild=1;
  7467. break;
  7468. case MF_GVG:
  7469. map[m].flag.gvg=1;
  7470. break;
  7471. case MF_GVG_NOPARTY:
  7472. map[m].flag.gvg_noparty=1;
  7473. break;
  7474. case MF_GVG_DUNGEON:
  7475. map[m].flag.gvg_dungeon=1;
  7476. break;
  7477. case MF_GVG_CASTLE:
  7478. map[m].flag.gvg_castle=1;
  7479. break;
  7480. case MF_NOTRADE:
  7481. map[m].flag.notrade=1;
  7482. break;
  7483. case MF_NODROP:
  7484. map[m].flag.nodrop=1;
  7485. break;
  7486. case MF_NOSKILL:
  7487. map[m].flag.noskill=1;
  7488. break;
  7489. case MF_NOWARP:
  7490. map[m].flag.nowarp=1;
  7491. break;
  7492. case MF_NOICEWALL: // [Valaris]
  7493. map[m].flag.noicewall=1;
  7494. break;
  7495. case MF_SNOW: // [Valaris]
  7496. map[m].flag.snow=1;
  7497. break;
  7498. case MF_CLOUDS:
  7499. map[m].flag.clouds=1;
  7500. break;
  7501. case MF_CLOUDS2: // [Valaris]
  7502. map[m].flag.clouds2=1;
  7503. break;
  7504. case MF_FOG: // [Valaris]
  7505. map[m].flag.fog=1;
  7506. break;
  7507. case MF_FIREWORKS:
  7508. map[m].flag.fireworks=1;
  7509. break;
  7510. case MF_SAKURA: // [Valaris]
  7511. map[m].flag.sakura=1;
  7512. break;
  7513. case MF_LEAVES: // [Valaris]
  7514. map[m].flag.leaves=1;
  7515. break;
  7516. case MF_RAIN: // [Valaris]
  7517. map[m].flag.rain=1;
  7518. break;
  7519. case MF_INDOORS: // celest
  7520. map[m].flag.indoors=1;
  7521. break;
  7522. case MF_NIGHTENABLED:
  7523. map[m].flag.nightenabled=1;
  7524. break;
  7525. case MF_NOGO: // celest
  7526. map[m].flag.nogo=1;
  7527. break;
  7528. case MF_NOBASEEXP:
  7529. map[m].flag.nobaseexp=1;
  7530. break;
  7531. case MF_NOJOBEXP:
  7532. map[m].flag.nojobexp=1;
  7533. break;
  7534. case MF_NOMOBLOOT:
  7535. map[m].flag.nomobloot=1;
  7536. break;
  7537. case MF_NOMVPLOOT:
  7538. map[m].flag.nomvploot=1;
  7539. break;
  7540. case MF_NORETURN:
  7541. map[m].flag.noreturn=1;
  7542. break;
  7543. case MF_NOWARPTO:
  7544. map[m].flag.nowarpto=1;
  7545. break;
  7546. case MF_NIGHTMAREDROP:
  7547. map[m].flag.pvp_nightmaredrop=1;
  7548. break;
  7549. case MF_RESTRICTED:
  7550. map[m].flag.restricted=1;
  7551. break;
  7552. case MF_NOCOMMAND:
  7553. map[m].flag.nocommand=1;
  7554. break;
  7555. case MF_JEXP:
  7556. map[m].jexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7557. break;
  7558. case MF_BEXP:
  7559. map[m].bexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7560. break;
  7561. case MF_NOVENDING:
  7562. map[m].flag.novending=1;
  7563. break;
  7564. case MF_LOADEVENT:
  7565. map[m].flag.loadevent=1;
  7566. break;
  7567. case MF_NOCHAT:
  7568. map[m].flag.nochat=1;
  7569. }
  7570. }
  7571. return 0;
  7572. }
  7573. int buildin_removemapflag(struct script_state *st)
  7574. {
  7575. int m,i;
  7576. char *str;
  7577. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7578. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7579. m = map_mapname2mapid(str);
  7580. if(m >= 0) {
  7581. switch(i) {
  7582. case MF_NOMEMO:
  7583. map[m].flag.nomemo=0;
  7584. break;
  7585. case MF_NOTELEPORT:
  7586. map[m].flag.noteleport=0;
  7587. break;
  7588. case MF_NOSAVE:
  7589. map[m].flag.nosave=0;
  7590. break;
  7591. case MF_NOBRANCH:
  7592. map[m].flag.nobranch=0;
  7593. break;
  7594. case MF_NOPENALTY:
  7595. map[m].flag.nopenalty=0;
  7596. break;
  7597. case MF_PVP:
  7598. map[m].flag.pvp=0;
  7599. break;
  7600. case MF_PVP_NOPARTY:
  7601. map[m].flag.pvp_noparty=0;
  7602. break;
  7603. case MF_PVP_NOGUILD:
  7604. map[m].flag.pvp_noguild=0;
  7605. break;
  7606. case MF_GVG:
  7607. map[m].flag.gvg=0;
  7608. break;
  7609. case MF_GVG_NOPARTY:
  7610. map[m].flag.gvg_noparty=0;
  7611. break;
  7612. case MF_GVG_DUNGEON:
  7613. map[m].flag.gvg_dungeon=0;
  7614. break;
  7615. case MF_GVG_CASTLE:
  7616. map[m].flag.gvg_castle=0;
  7617. break;
  7618. case MF_NOZENYPENALTY:
  7619. map[m].flag.nozenypenalty=0;
  7620. break;
  7621. case MF_NOTRADE:
  7622. map[m].flag.notrade=0;
  7623. break;
  7624. case MF_NODROP:
  7625. map[m].flag.nodrop=0;
  7626. break;
  7627. case MF_NOSKILL:
  7628. map[m].flag.noskill=0;
  7629. break;
  7630. case MF_NOWARP:
  7631. map[m].flag.nowarp=0;
  7632. break;
  7633. case MF_NOICEWALL: // [Valaris]
  7634. map[m].flag.noicewall=0;
  7635. break;
  7636. case MF_SNOW: // [Valaris]
  7637. map[m].flag.snow=0;
  7638. break;
  7639. case MF_CLOUDS:
  7640. map[m].flag.clouds=0;
  7641. break;
  7642. case MF_CLOUDS2: // [Valaris]
  7643. map[m].flag.clouds2=0;
  7644. break;
  7645. case MF_FOG: // [Valaris]
  7646. map[m].flag.fog=0;
  7647. break;
  7648. case MF_FIREWORKS:
  7649. map[m].flag.fireworks=0;
  7650. break;
  7651. case MF_SAKURA: // [Valaris]
  7652. map[m].flag.sakura=0;
  7653. break;
  7654. case MF_LEAVES: // [Valaris]
  7655. map[m].flag.leaves=0;
  7656. break;
  7657. case MF_RAIN: // [Valaris]
  7658. map[m].flag.rain=0;
  7659. break;
  7660. case MF_INDOORS: // celest
  7661. map[m].flag.indoors=0;
  7662. break;
  7663. case MF_NIGHTENABLED:
  7664. map[m].flag.nightenabled=0;
  7665. break;
  7666. case MF_NOGO: // celest
  7667. map[m].flag.nogo=0;
  7668. break;
  7669. case MF_NOBASEEXP:
  7670. map[m].flag.nobaseexp=0;
  7671. break;
  7672. case MF_NOJOBEXP:
  7673. map[m].flag.nojobexp=0;
  7674. break;
  7675. case MF_NOMOBLOOT:
  7676. map[m].flag.nomobloot=0;
  7677. break;
  7678. case MF_NOMVPLOOT:
  7679. map[m].flag.nomvploot=0;
  7680. break;
  7681. case MF_NORETURN:
  7682. map[m].flag.noreturn=0;
  7683. break;
  7684. case MF_NOWARPTO:
  7685. map[m].flag.nowarpto=0;
  7686. break;
  7687. case MF_NIGHTMAREDROP:
  7688. map[m].flag.pvp_nightmaredrop=0;
  7689. break;
  7690. case MF_RESTRICTED:
  7691. map[m].flag.restricted=0;
  7692. break;
  7693. case MF_NOCOMMAND:
  7694. map[m].flag.nocommand=0;
  7695. break;
  7696. case MF_JEXP:
  7697. map[m].jexp=100;
  7698. break;
  7699. case MF_BEXP:
  7700. map[m].bexp=100;
  7701. break;
  7702. case MF_NOVENDING:
  7703. map[m].flag.novending=0;
  7704. break;
  7705. case MF_LOADEVENT:
  7706. map[m].flag.loadevent=0;
  7707. break;
  7708. case MF_NOCHAT:
  7709. map[m].flag.nochat=0;
  7710. }
  7711. }
  7712. return 0;
  7713. }
  7714. int buildin_pvpon(struct script_state *st)
  7715. {
  7716. int m,i,users;
  7717. char *str;
  7718. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7719. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7720. m = map_mapname2mapid(str);
  7721. if(m >= 0 && !map[m].flag.pvp) {
  7722. map[m].flag.pvp = 1;
  7723. clif_send0199(m,1);
  7724. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  7725. return 0;
  7726. pl_allsd = map_getallusers(&users);
  7727. for(i=0;i<users;i++)
  7728. {
  7729. if ((pl_sd = pl_allsd[i]) && m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
  7730. {
  7731. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  7732. pl_sd->pvp_rank=0;
  7733. pl_sd->pvp_lastusers=0;
  7734. pl_sd->pvp_point=5;
  7735. pl_sd->pvp_won = 0;
  7736. pl_sd->pvp_lost = 0;
  7737. }
  7738. }
  7739. }
  7740. return 0;
  7741. }
  7742. int buildin_pvpoff(struct script_state *st)
  7743. {
  7744. int m,i,users;
  7745. char *str;
  7746. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7747. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7748. m = map_mapname2mapid(str);
  7749. if(m >= 0 && map[m].flag.pvp) { //fixed Lupus
  7750. map[m].flag.pvp = 0;
  7751. clif_send0199(m,0);
  7752. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  7753. return 0;
  7754. pl_allsd = map_getallusers(&users);
  7755. for(i=0;i<users;i++)
  7756. {
  7757. if((pl_sd=pl_allsd[i]) && m == pl_sd->bl.m)
  7758. {
  7759. clif_pvpset(pl_sd,0,0,2);
  7760. if(pl_sd->pvp_timer != -1) {
  7761. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  7762. pl_sd->pvp_timer = -1;
  7763. }
  7764. }
  7765. }
  7766. }
  7767. return 0;
  7768. }
  7769. int buildin_gvgon(struct script_state *st)
  7770. {
  7771. int m;
  7772. char *str;
  7773. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7774. m = map_mapname2mapid(str);
  7775. if(m >= 0 && !map[m].flag.gvg) {
  7776. map[m].flag.gvg = 1;
  7777. clif_send0199(m,3);
  7778. }
  7779. return 0;
  7780. }
  7781. int buildin_gvgoff(struct script_state *st)
  7782. {
  7783. int m;
  7784. char *str;
  7785. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7786. m = map_mapname2mapid(str);
  7787. if(m >= 0 && map[m].flag.gvg) {
  7788. map[m].flag.gvg = 0;
  7789. clif_send0199(m,0);
  7790. }
  7791. return 0;
  7792. }
  7793. /*==========================================
  7794. * Shows an emoticon on top of the player/npc
  7795. * emotion emotion#, <target: 0 - NPC, 1 - PC>
  7796. *------------------------------------------
  7797. */
  7798. //Optional second parameter added by [Skotlex]
  7799. int buildin_emotion(struct script_state *st)
  7800. {
  7801. int type;
  7802. int player=0;
  7803. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7804. if(type < 0 || type > 100)
  7805. return 0;
  7806. if( st->end>st->start+3 )
  7807. player=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7808. if (player) {
  7809. struct map_session_data *sd = script_rid2sd(st);
  7810. if (sd)
  7811. clif_emotion(&sd->bl,type);
  7812. } else
  7813. clif_emotion(map_id2bl(st->oid),type);
  7814. return 0;
  7815. }
  7816. int buildin_maprespawnguildid_sub(struct block_list *bl,va_list ap)
  7817. {
  7818. int g_id=va_arg(ap,int);
  7819. int flag=va_arg(ap,int);
  7820. struct map_session_data *sd=NULL;
  7821. struct mob_data *md=NULL;
  7822. if(bl->type == BL_PC)
  7823. sd=(struct map_session_data*)bl;
  7824. if(bl->type == BL_MOB)
  7825. md=(struct mob_data *)bl;
  7826. if(sd){
  7827. if((sd->status.guild_id == g_id) && (flag&1))
  7828. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  7829. else if((sd->status.guild_id != g_id) && (flag&2))
  7830. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  7831. else if (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  7832. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3); // end addition [Valaris]
  7833. }
  7834. if(md && flag&4){
  7835. if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
  7836. unit_remove_map(bl,1);
  7837. }
  7838. return 0;
  7839. }
  7840. int buildin_maprespawnguildid(struct script_state *st)
  7841. {
  7842. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7843. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7844. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7845. int m=map_mapname2mapid(mapname);
  7846. if(m) map_foreachinmap(buildin_maprespawnguildid_sub,m,BL_CHAR,g_id,flag);
  7847. return 0;
  7848. }
  7849. int buildin_agitstart(struct script_state *st)
  7850. {
  7851. if(agit_flag==1) return 0; // Agit already Start.
  7852. agit_flag=1;
  7853. guild_agit_start();
  7854. return 0;
  7855. }
  7856. int buildin_agitend(struct script_state *st)
  7857. {
  7858. if(agit_flag==0) return 0; // Agit already End.
  7859. agit_flag=0;
  7860. guild_agit_end();
  7861. return 0;
  7862. }
  7863. /*==========================================
  7864. * agitcheck 1; // choice script
  7865. * if(@agit_flag == 1) goto agit;
  7866. * if(agitcheck(0) == 1) goto agit;
  7867. *------------------------------------------
  7868. */
  7869. int buildin_agitcheck(struct script_state *st)
  7870. {
  7871. struct map_session_data *sd;
  7872. int cond;
  7873. cond=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7874. if(cond == 0) {
  7875. if (agit_flag==1) push_val(st->stack,C_INT,1);
  7876. if (agit_flag==0) push_val(st->stack,C_INT,0);
  7877. } else {
  7878. sd=script_rid2sd(st);
  7879. if (agit_flag==1) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),1);
  7880. if (agit_flag==0) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),0);
  7881. }
  7882. return 0;
  7883. }
  7884. int buildin_flagemblem(struct script_state *st)
  7885. {
  7886. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7887. if(g_id < 0) return 0;
  7888. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  7889. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  7890. return 0;
  7891. }
  7892. int buildin_getcastlename(struct script_state *st)
  7893. {
  7894. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7895. struct guild_castle *gc;
  7896. int i;
  7897. for(i=0;i<MAX_GUILDCASTLE;i++){
  7898. if( (gc=guild_castle_search(i)) != NULL ){
  7899. if(strcmp(mapname,gc->map_name)==0){
  7900. break;
  7901. }
  7902. }
  7903. }
  7904. if(gc)
  7905. push_str(st->stack,C_CONSTSTR,(unsigned char *) gc->castle_name);
  7906. else
  7907. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  7908. return 0;
  7909. }
  7910. int buildin_getcastledata(struct script_state *st)
  7911. {
  7912. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7913. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7914. char *event=NULL;
  7915. struct guild_castle *gc;
  7916. int i,j;
  7917. if( st->end>st->start+4 && index==0){
  7918. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  7919. if( (gc=guild_castle_search(i)) != NULL &&
  7920. strcmp(mapname,gc->map_name)==0 )
  7921. j=i;
  7922. if(j>=0){
  7923. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7924. check_event(st, event);
  7925. guild_addcastleinfoevent(j,17,event);
  7926. }
  7927. }
  7928. for(i=0;i<MAX_GUILDCASTLE;i++){
  7929. if( (gc=guild_castle_search(i)) != NULL ){
  7930. if(strcmp(mapname,gc->map_name)==0){
  7931. switch(index){
  7932. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  7933. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  7934. case 2: push_val(st->stack,C_INT,gc->economy); break;
  7935. case 3: push_val(st->stack,C_INT,gc->defense); break;
  7936. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  7937. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  7938. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  7939. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  7940. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  7941. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  7942. case 10:
  7943. case 11:
  7944. case 12:
  7945. case 13:
  7946. case 14:
  7947. case 15:
  7948. case 16:
  7949. case 17:
  7950. push_val(st->stack,C_INT,gc->guardian[index-10].visible); break;
  7951. case 18:
  7952. case 19:
  7953. case 20:
  7954. case 21:
  7955. case 22:
  7956. case 23:
  7957. case 24:
  7958. case 25:
  7959. push_val(st->stack,C_INT,gc->guardian[index-18].hp); break;
  7960. default:
  7961. push_val(st->stack,C_INT,0); break;
  7962. }
  7963. return 0;
  7964. }
  7965. }
  7966. }
  7967. push_val(st->stack,C_INT,0);
  7968. return 0;
  7969. }
  7970. int buildin_setcastledata(struct script_state *st)
  7971. {
  7972. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7973. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7974. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7975. struct guild_castle *gc;
  7976. int i;
  7977. for(i=0;i<MAX_GUILDCASTLE;i++){
  7978. if( (gc=guild_castle_search(i)) != NULL ){
  7979. if(strcmp(mapname,gc->map_name)==0){
  7980. // Save Data byself First
  7981. switch(index){
  7982. case 1: gc->guild_id = value; break;
  7983. case 2: gc->economy = value; break;
  7984. case 3: gc->defense = value; break;
  7985. case 4: gc->triggerE = value; break;
  7986. case 5: gc->triggerD = value; break;
  7987. case 6: gc->nextTime = value; break;
  7988. case 7: gc->payTime = value; break;
  7989. case 8: gc->createTime = value; break;
  7990. case 9: gc->visibleC = value; break;
  7991. case 10:
  7992. case 11:
  7993. case 12:
  7994. case 13:
  7995. case 14:
  7996. case 15:
  7997. case 16:
  7998. case 17:
  7999. gc->guardian[index-10].visible = value; break;
  8000. case 18:
  8001. case 19:
  8002. case 20:
  8003. case 21:
  8004. case 22:
  8005. case 23:
  8006. case 24:
  8007. case 25:
  8008. gc->guardian[index-18].hp = value;
  8009. if (gc->guardian[index-18].id)
  8010. { //Update this mob's HP.
  8011. struct block_list *bl = map_id2bl(gc->guardian[index-18].id);
  8012. if (!bl)
  8013. { //Wrong target?
  8014. gc->guardian[index-18].id = 0;
  8015. break;
  8016. }
  8017. if (value < 1) {
  8018. status_kill(bl);
  8019. break;
  8020. }
  8021. status_set_hp(bl, value, 0);
  8022. }
  8023. break;
  8024. default: return 0;
  8025. }
  8026. guild_castledatasave(gc->castle_id,index,value);
  8027. return 0;
  8028. }
  8029. }
  8030. }
  8031. return 0;
  8032. }
  8033. /* =====================================================================
  8034. * ギルド情報を要求する
  8035. * ---------------------------------------------------------------------
  8036. */
  8037. int buildin_requestguildinfo(struct script_state *st)
  8038. {
  8039. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8040. char *event=NULL;
  8041. if( st->end>st->start+3 ){
  8042. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8043. check_event(st, event);
  8044. }
  8045. if(guild_id>0)
  8046. guild_npc_request_info(guild_id,event);
  8047. return 0;
  8048. }
  8049. /* =====================================================================
  8050. * カードの数を得る
  8051. * ---------------------------------------------------------------------
  8052. */
  8053. int buildin_getequipcardcnt(struct script_state *st)
  8054. {
  8055. int i,num;
  8056. struct map_session_data *sd;
  8057. int c=MAX_SLOTS;
  8058. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8059. sd=script_rid2sd(st);
  8060. i=pc_checkequip(sd,equip[num-1]);
  8061. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8062. {
  8063. push_val(st->stack,C_INT,0);
  8064. return 0;
  8065. }
  8066. do{
  8067. if(sd->status.inventory[i].card[c-1] &&
  8068. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8069. push_val(st->stack,C_INT,(c));
  8070. return 0;
  8071. }
  8072. }while(c--);
  8073. push_val(st->stack,C_INT,0);
  8074. return 0;
  8075. }
  8076. /* ================================================================
  8077. * カード取り外し成功
  8078. * ----------------------------------------------------------------
  8079. */
  8080. int buildin_successremovecards(struct script_state *st)
  8081. {
  8082. int i,j,num,cardflag=0,flag;
  8083. struct map_session_data *sd;
  8084. struct item item_tmp;
  8085. int c=MAX_SLOTS;
  8086. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8087. sd=script_rid2sd(st);
  8088. i=pc_checkequip(sd,equip[num-1]);
  8089. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8090. return 0;
  8091. do{
  8092. if(sd->status.inventory[i].card[c-1] &&
  8093. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8094. cardflag = 1;
  8095. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8096. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8097. item_tmp.attribute=0;
  8098. for (j = 0; j < MAX_SLOTS; j++)
  8099. item_tmp.card[j]=0;
  8100. //Logs items, got from (N)PC scripts [Lupus]
  8101. if(log_config.enable_logs&0x40)
  8102. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  8103. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  8104. clif_additem(sd,0,0,flag);
  8105. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8106. }
  8107. }
  8108. }while(c--);
  8109. if(cardflag == 1){ // カードを取り除いたアイテム所得
  8110. flag=0;
  8111. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8112. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8113. item_tmp.attribute=sd->status.inventory[i].attribute;
  8114. //Logs items, got from (N)PC scripts [Lupus]
  8115. if(log_config.enable_logs&0x40)
  8116. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8117. for (j = 0; j < MAX_SLOTS; j++)
  8118. item_tmp.card[j]=0;
  8119. pc_delitem(sd,i,1,0);
  8120. //Logs items, got from (N)PC scripts [Lupus]
  8121. if(log_config.enable_logs&0x40)
  8122. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  8123. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  8124. clif_additem(sd,0,0,flag);
  8125. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8126. }
  8127. clif_misceffect(&sd->bl,3);
  8128. return 0;
  8129. }
  8130. return 0;
  8131. }
  8132. /* ================================================================
  8133. * カード取り外し失敗 slot,type
  8134. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  8135. * ----------------------------------------------------------------
  8136. */
  8137. int buildin_failedremovecards(struct script_state *st)
  8138. {
  8139. int i,j,num,cardflag=0,flag,typefail;
  8140. struct map_session_data *sd;
  8141. struct item item_tmp;
  8142. int c=MAX_SLOTS;
  8143. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8144. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8145. sd=script_rid2sd(st);
  8146. i=pc_checkequip(sd,equip[num-1]);
  8147. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8148. return 0;
  8149. do{
  8150. if(sd->status.inventory[i].card[c-1] &&
  8151. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8152. cardflag = 1;
  8153. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  8154. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8155. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8156. item_tmp.attribute=0;
  8157. for (j = 0; j < MAX_SLOTS; j++)
  8158. item_tmp.card[j]=0;
  8159. //Logs items, got from (N)PC scripts [Lupus]
  8160. if(log_config.enable_logs&0x40)
  8161. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  8162. if((flag=pc_additem(sd,&item_tmp,1))){
  8163. clif_additem(sd,0,0,flag);
  8164. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8165. }
  8166. }
  8167. }
  8168. }while(c--);
  8169. if(cardflag == 1){
  8170. if(typefail == 0 || typefail == 2){ // 武具損失
  8171. //Logs items, got from (N)PC scripts [Lupus]
  8172. if(log_config.enable_logs&0x40)
  8173. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8174. pc_delitem(sd,i,1,0);
  8175. clif_misceffect(&sd->bl,2);
  8176. return 0;
  8177. }
  8178. if(typefail == 1){ // カードのみ損失(武具を返す)
  8179. flag=0;
  8180. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8181. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8182. item_tmp.attribute=sd->status.inventory[i].attribute;
  8183. //Logs items, got from (N)PC scripts [Lupus]
  8184. if(log_config.enable_logs&0x40)
  8185. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8186. for (j = 0; j < MAX_SLOTS; j++)
  8187. item_tmp.card[j]=0;
  8188. pc_delitem(sd,i,1,0);
  8189. //Logs items, got from (N)PC scripts [Lupus]
  8190. if(log_config.enable_logs&0x40)
  8191. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  8192. if((flag=pc_additem(sd,&item_tmp,1))){
  8193. clif_additem(sd,0,0,flag);
  8194. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8195. }
  8196. }
  8197. clif_misceffect(&sd->bl,2);
  8198. return 0;
  8199. }
  8200. return 0;
  8201. }
  8202. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  8203. {
  8204. int x,y,m;
  8205. char *str;
  8206. char *mapname;
  8207. unsigned int index;
  8208. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8209. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8210. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8211. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8212. if( (m=map_mapname2mapid(mapname))< 0)
  8213. return 0;
  8214. if(!(index=mapindex_name2id(str)))
  8215. return 0;
  8216. map_foreachinmap(buildin_areawarp_sub,
  8217. m,BL_PC,index,x,y);
  8218. return 0;
  8219. }
  8220. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  8221. {
  8222. char *npc,*command;
  8223. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8224. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8225. npc_command(map_id2sd(st->rid),npc,command);
  8226. return 0;
  8227. }
  8228. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  8229. {
  8230. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8231. // nd->lastaction=nd->timer=gettick();
  8232. npc_do_ontimer(st->oid, 1);
  8233. return 0;
  8234. }
  8235. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  8236. {
  8237. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8238. // nd->lastaction=nd->timer=-1;
  8239. npc_do_ontimer(st->oid, 0);
  8240. return 0;
  8241. }
  8242. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  8243. {
  8244. char *event=va_arg(ap,char *);
  8245. int *c=va_arg(ap,int *);
  8246. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  8247. (*c)++;
  8248. return 0;
  8249. }
  8250. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  8251. {
  8252. char *mapname,*event;
  8253. int m,c=0;
  8254. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8255. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8256. check_event(st, event);
  8257. if( (m=map_mapname2mapid(mapname))<0 ) {
  8258. push_val(st->stack,C_INT,-1);
  8259. return 0;
  8260. }
  8261. map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event,&c );
  8262. push_val(st->stack,C_INT, (c));
  8263. return 0;
  8264. }
  8265. int buildin_marriage(struct script_state *st)
  8266. {
  8267. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8268. struct map_session_data *sd=script_rid2sd(st);
  8269. struct map_session_data *p_sd=map_nick2sd(partner);
  8270. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  8271. push_val(st->stack,C_INT,0);
  8272. return 0;
  8273. }
  8274. push_val(st->stack,C_INT,1);
  8275. return 0;
  8276. }
  8277. int buildin_wedding_effect(struct script_state *st)
  8278. {
  8279. struct map_session_data *sd=script_rid2sd(st);
  8280. struct block_list *bl;
  8281. if(sd==NULL) {
  8282. bl=map_id2bl(st->oid);
  8283. } else
  8284. bl=&sd->bl;
  8285. clif_wedding_effect(bl);
  8286. return 0;
  8287. }
  8288. int buildin_divorce(struct script_state *st)
  8289. {
  8290. struct map_session_data *sd=script_rid2sd(st);
  8291. if(sd==NULL || pc_divorce(sd) < 0){
  8292. push_val(st->stack,C_INT,0);
  8293. return 0;
  8294. }
  8295. push_val(st->stack,C_INT,1);
  8296. return 0;
  8297. }
  8298. int buildin_ispartneron(struct script_state *st)
  8299. {
  8300. struct map_session_data *sd=script_rid2sd(st);
  8301. struct map_session_data *p_sd=NULL;
  8302. if(sd==NULL || !pc_ismarried(sd) ||
  8303. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8304. push_val(st->stack,C_INT,0);
  8305. return 0;
  8306. }
  8307. push_val(st->stack,C_INT,1);
  8308. return 0;
  8309. }
  8310. int buildin_getpartnerid(struct script_state *st)
  8311. {
  8312. struct map_session_data *sd=script_rid2sd(st);
  8313. if (sd == NULL) {
  8314. push_val(st->stack,C_INT,0);
  8315. return 0;
  8316. }
  8317. push_val(st->stack,C_INT,sd->status.partner_id);
  8318. return 0;
  8319. }
  8320. int buildin_getchildid(struct script_state *st)
  8321. {
  8322. struct map_session_data *sd=script_rid2sd(st);
  8323. if (sd == NULL) {
  8324. push_val(st->stack,C_INT,0);
  8325. return 0;
  8326. }
  8327. push_val(st->stack,C_INT,sd->status.child);
  8328. return 0;
  8329. }
  8330. int buildin_getmotherid(struct script_state *st)
  8331. {
  8332. struct map_session_data *sd=script_rid2sd(st);
  8333. if (sd == NULL) {
  8334. push_val(st->stack,C_INT,0);
  8335. return 0;
  8336. }
  8337. push_val(st->stack,C_INT,sd->status.mother);
  8338. return 0;
  8339. }
  8340. int buildin_getfatherid(struct script_state *st)
  8341. {
  8342. struct map_session_data *sd=script_rid2sd(st);
  8343. if (sd == NULL) {
  8344. push_val(st->stack,C_INT,0);
  8345. return 0;
  8346. }
  8347. push_val(st->stack,C_INT,sd->status.father);
  8348. return 0;
  8349. }
  8350. int buildin_warppartner(struct script_state *st)
  8351. {
  8352. int x,y;
  8353. unsigned short mapindex;
  8354. char *str;
  8355. struct map_session_data *sd=script_rid2sd(st);
  8356. struct map_session_data *p_sd=NULL;
  8357. if(sd==NULL || !pc_ismarried(sd) ||
  8358. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8359. push_val(st->stack,C_INT,0);
  8360. return 0;
  8361. }
  8362. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8363. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8364. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8365. mapindex = mapindex_name2id(str);
  8366. if (mapindex) {
  8367. pc_setpos(p_sd,mapindex,x,y,0);
  8368. push_val(st->stack,C_INT,1);
  8369. } else
  8370. push_val(st->stack,C_INT,0);
  8371. return 0;
  8372. }
  8373. /*================================================
  8374. * Script for Displaying MOB Information [Valaris]
  8375. *------------------------------------------------
  8376. */
  8377. int buildin_strmobinfo(struct script_state *st)
  8378. {
  8379. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8380. int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8381. if((class_>=0 && class_<=1000) || class_ >2000)
  8382. return 0;
  8383. switch (num) {
  8384. case 1:
  8385. push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->name);
  8386. break;
  8387. case 2:
  8388. push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->jname);
  8389. break;
  8390. case 3:
  8391. push_val(st->stack,C_INT,mob_db(class_)->lv);
  8392. break;
  8393. case 4:
  8394. push_val(st->stack,C_INT,mob_db(class_)->status.max_hp);
  8395. break;
  8396. case 5:
  8397. push_val(st->stack,C_INT,mob_db(class_)->status.max_sp);
  8398. break;
  8399. case 6:
  8400. push_val(st->stack,C_INT,mob_db(class_)->base_exp);
  8401. break;
  8402. case 7:
  8403. push_val(st->stack,C_INT,mob_db(class_)->job_exp);
  8404. break;
  8405. }
  8406. return 0;
  8407. }
  8408. /*==========================================
  8409. * Summon guardians [Valaris]
  8410. *------------------------------------------
  8411. */
  8412. int buildin_guardian(struct script_state *st)
  8413. {
  8414. int class_=0,amount=1,x=0,y=0,guardian=0;
  8415. char *str,*map,*event="";
  8416. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  8417. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  8418. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  8419. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  8420. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8421. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  8422. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  8423. if( st->end>st->start+9 )
  8424. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  8425. check_event(st, event);
  8426. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
  8427. return 0;
  8428. }
  8429. /*================================================
  8430. * Script for Displaying Guardian Info [Valaris]
  8431. *------------------------------------------------
  8432. */
  8433. int buildin_guardianinfo(struct script_state *st)
  8434. {
  8435. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8436. struct map_session_data *sd=script_rid2sd(st);
  8437. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  8438. if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
  8439. {
  8440. push_val(st->stack,C_INT,-1);
  8441. return 0;
  8442. }
  8443. if(gc->guardian[guardian].visible)
  8444. push_val(st->stack,C_INT,gc->guardian[guardian].hp);
  8445. else push_val(st->stack,C_INT,-1);
  8446. return 0;
  8447. }
  8448. /*==========================================
  8449. * IDからItem名
  8450. *------------------------------------------
  8451. */
  8452. int buildin_getitemname(struct script_state *st)
  8453. {
  8454. int item_id=0;
  8455. struct item_data *i_data;
  8456. char *item_name;
  8457. struct script_data *data;
  8458. data=&(st->stack->stack_data[st->start+2]);
  8459. get_val(st,data);
  8460. if( data->type==C_STR || data->type==C_CONSTSTR ){
  8461. const char *name=conv_str(st,data);
  8462. struct item_data *item_data = itemdb_searchname(name);
  8463. if( item_data )
  8464. item_id=item_data->nameid;
  8465. }else
  8466. item_id=conv_num(st,data);
  8467. i_data = itemdb_exists(item_id);
  8468. if (i_data == NULL)
  8469. {
  8470. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  8471. return 0;
  8472. }
  8473. item_name=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  8474. memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
  8475. push_str(st->stack,C_STR,(unsigned char *) item_name);
  8476. return 0;
  8477. }
  8478. /*==========================================
  8479. * Returns number of slots an item has. [Skotlex]
  8480. *------------------------------------------
  8481. */
  8482. int buildin_getitemslots(struct script_state *st)
  8483. {
  8484. int item_id;
  8485. struct item_data *i_data;
  8486. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8487. i_data = itemdb_exists(item_id);
  8488. if (i_data)
  8489. push_val(st->stack,C_INT,i_data->slot);
  8490. else
  8491. push_val(st->stack,C_INT,-1);
  8492. return 0;
  8493. }
  8494. /*==========================================
  8495. * Returns some values of an item [Lupus]
  8496. * Price, Weight, etc...
  8497. getiteminfo(itemID,n), where n
  8498. 0 value_buy;
  8499. 1 value_sell;
  8500. 2 type;
  8501. 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
  8502. if = 0, then monsters don't drop it at all (rare or a quest item)
  8503. if = 10000, then this item is sold in NPC shops only
  8504. 4 sex;
  8505. 5 equip;
  8506. 6 weight;
  8507. 7 atk;
  8508. 8 def;
  8509. 9 range;
  8510. 10 slot;
  8511. 11 look;
  8512. 12 elv;
  8513. 13 wlv;
  8514. *------------------------------------------
  8515. */
  8516. int buildin_getiteminfo(struct script_state *st)
  8517. {
  8518. int item_id,n;
  8519. int *item_arr;
  8520. struct item_data *i_data;
  8521. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8522. n = conv_num(st,& (st->stack->stack_data[st->start+3]));
  8523. i_data = itemdb_exists(item_id);
  8524. if (i_data && n>=0 && n<14) {
  8525. item_arr = (int*)&i_data->value_buy;
  8526. push_val(st->stack,C_INT,item_arr[n]);
  8527. } else
  8528. push_val(st->stack,C_INT,-1);
  8529. return 0;
  8530. }
  8531. /*==========================================
  8532. * Returns value from equipped item slot n [Lupus]
  8533. getequipcardid(num,slot)
  8534. where
  8535. num = eqip position slot
  8536. slot = 0,1,2,3 (Card Slot N)
  8537. This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
  8538. it's useful when you want to check item cards or if it's signed
  8539. Useful for such quests as "Sign this refined item with players name" etc
  8540. Hat[0] +4 -> Player's Hat[0] +4
  8541. *------------------------------------------
  8542. */
  8543. int buildin_getequipcardid(struct script_state *st)
  8544. {
  8545. int i,num,slot;
  8546. struct map_session_data *sd;
  8547. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8548. slot=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8549. sd=script_rid2sd(st);
  8550. i=pc_checkequip(sd,equip[num-1]);
  8551. if(i >= 0 && slot>=0 && slot<4)
  8552. push_val(st->stack,C_INT,sd->status.inventory[i].card[slot]);
  8553. else
  8554. push_val(st->stack,C_INT,0);
  8555. return 0;
  8556. }
  8557. /*==========================================
  8558. * petskillbonus [Valaris] //Rewritten by [Skotlex]
  8559. *------------------------------------------
  8560. */
  8561. int buildin_petskillbonus(struct script_state *st)
  8562. {
  8563. struct pet_data *pd;
  8564. struct map_session_data *sd=script_rid2sd(st);
  8565. if(sd==NULL || sd->pd==NULL)
  8566. return 0;
  8567. pd=sd->pd;
  8568. if (pd->bonus)
  8569. { //Clear previous bonus
  8570. if (pd->bonus->timer != -1)
  8571. delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
  8572. } else //init
  8573. pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
  8574. pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8575. pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8576. pd->bonus->duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8577. pd->bonus->delay=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8578. if (pd->state.skillbonus == 1)
  8579. pd->state.skillbonus=0; // waiting state
  8580. // wait for timer to start
  8581. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  8582. pd->bonus->timer=-1;
  8583. else
  8584. pd->bonus->timer=add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
  8585. return 0;
  8586. }
  8587. /*==========================================
  8588. * pet looting [Valaris] //Rewritten by [Skotlex]
  8589. *------------------------------------------
  8590. */
  8591. int buildin_petloot(struct script_state *st)
  8592. {
  8593. int max;
  8594. struct pet_data *pd;
  8595. struct map_session_data *sd=script_rid2sd(st);
  8596. if(sd==NULL || sd->pd==NULL)
  8597. return 0;
  8598. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8599. if(max < 1)
  8600. max = 1; //Let'em loot at least 1 item.
  8601. else if (max > MAX_PETLOOT_SIZE)
  8602. max = MAX_PETLOOT_SIZE;
  8603. pd = sd->pd;
  8604. if (pd->loot != NULL)
  8605. { //Release whatever was there already and reallocate memory
  8606. pet_lootitem_drop(pd, pd->msd);
  8607. aFree(pd->loot->item);
  8608. }
  8609. else
  8610. pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
  8611. pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
  8612. pd->loot->max=max;
  8613. pd->loot->count = 0;
  8614. pd->loot->weight = 0;
  8615. return 0;
  8616. }
  8617. /*==========================================
  8618. * PCの所持品情報読み取り
  8619. *------------------------------------------
  8620. */
  8621. int buildin_getinventorylist(struct script_state *st)
  8622. {
  8623. struct map_session_data *sd=script_rid2sd(st);
  8624. unsigned char card_var[NAME_LENGTH];
  8625. int i,j=0,k;
  8626. if(!sd) return 0;
  8627. for(i=0;i<MAX_INVENTORY;i++){
  8628. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  8629. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  8630. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  8631. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  8632. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  8633. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  8634. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  8635. for (k = 0; k < MAX_SLOTS; k++)
  8636. {
  8637. sprintf(card_var, "@inventorylist_card%d",k+1);
  8638. pc_setreg(sd,add_str(card_var)+(j<<24),sd->status.inventory[i].card[k]);
  8639. }
  8640. j++;
  8641. }
  8642. }
  8643. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_count"),j);
  8644. return 0;
  8645. }
  8646. int buildin_getskilllist(struct script_state *st)
  8647. {
  8648. struct map_session_data *sd=script_rid2sd(st);
  8649. int i,j=0;
  8650. if(!sd) return 0;
  8651. for(i=0;i<MAX_SKILL;i++){
  8652. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  8653. pc_setreg(sd,add_str((unsigned char *) "@skilllist_id")+(j<<24),sd->status.skill[i].id);
  8654. pc_setreg(sd,add_str((unsigned char *)"@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  8655. pc_setreg(sd,add_str((unsigned char *)"@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  8656. j++;
  8657. }
  8658. }
  8659. pc_setreg(sd,add_str((unsigned char *) "@skilllist_count"),j);
  8660. return 0;
  8661. }
  8662. int buildin_clearitem(struct script_state *st)
  8663. {
  8664. struct map_session_data *sd=script_rid2sd(st);
  8665. int i;
  8666. if(sd==NULL) return 0;
  8667. for (i=0; i<MAX_INVENTORY; i++) {
  8668. if (sd->status.inventory[i].amount) {
  8669. //Logs items, got from (N)PC scripts [Lupus]
  8670. if(log_config.enable_logs&0x40)
  8671. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  8672. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  8673. }
  8674. }
  8675. return 0;
  8676. }
  8677. /*==========================================
  8678. Disguise Player (returns Mob/NPC ID if success, 0 on fail) [Lupus]
  8679. *------------------------------------------
  8680. */
  8681. int buildin_disguise(struct script_state *st)
  8682. {
  8683. struct map_session_data *sd=script_rid2sd(st);
  8684. int id;
  8685. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8686. if (!mobdb_checkid(id) && !npcdb_checkid(id)) {
  8687. push_val(st->stack,C_INT,0);
  8688. return 0;
  8689. }
  8690. pc_disguise(sd, id);
  8691. push_val(st->stack,C_INT,id);
  8692. return 0;
  8693. }
  8694. /*==========================================
  8695. Undisguise Player (returns 1 if success, 0 on fail) [Lupus]
  8696. *------------------------------------------
  8697. */
  8698. int buildin_undisguise(struct script_state *st)
  8699. {
  8700. struct map_session_data *sd=script_rid2sd(st);
  8701. if (sd->disguise) {
  8702. pc_disguise(sd, 0);
  8703. push_val(st->stack,C_INT,0);
  8704. } else {
  8705. push_val(st->stack,C_INT,1);
  8706. }
  8707. return 0;
  8708. }
  8709. /*==========================================
  8710. * NPCクラスチェンジ
  8711. * classは変わりたいclass
  8712. * typeは通常0なのかな?
  8713. *------------------------------------------
  8714. */
  8715. int buildin_classchange(struct script_state *st)
  8716. {
  8717. int _class,type;
  8718. struct block_list *bl=map_id2bl(st->oid);
  8719. if(bl==NULL) return 0;
  8720. _class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8721. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8722. clif_class_change(bl,_class,type);
  8723. return 0;
  8724. }
  8725. /*==========================================
  8726. * NPCから発生するエフェクト
  8727. *------------------------------------------
  8728. */
  8729. int buildin_misceffect(struct script_state *st)
  8730. {
  8731. int type;
  8732. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8733. if(st->oid) {
  8734. struct block_list *bl = map_id2bl(st->oid);
  8735. if (bl)
  8736. clif_misceffect2(bl,type);
  8737. } else{
  8738. struct map_session_data *sd=script_rid2sd(st);
  8739. if(sd)
  8740. clif_misceffect2(&sd->bl,type);
  8741. }
  8742. return 0;
  8743. }
  8744. /*==========================================
  8745. * サウンドエフェクト
  8746. *------------------------------------------
  8747. */
  8748. int buildin_soundeffect(struct script_state *st)
  8749. {
  8750. // Redundn
  8751. struct map_session_data *sd=script_rid2sd(st);
  8752. char *name;
  8753. int type=0;
  8754. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8755. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8756. if(sd){
  8757. if(!st->rid)
  8758. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  8759. else{
  8760. clif_soundeffect(sd,&sd->bl,name,type);
  8761. }
  8762. }
  8763. return 0;
  8764. }
  8765. int soundeffect_sub(struct block_list* bl,va_list ap)
  8766. {
  8767. char *name;
  8768. int type;
  8769. nullpo_retr(0, bl);
  8770. nullpo_retr(0, ap);
  8771. name = va_arg(ap,char *);
  8772. type = va_arg(ap,int);
  8773. clif_soundeffect((struct map_session_data *)bl, bl, name, type);
  8774. return 0;
  8775. }
  8776. int buildin_soundeffectall(struct script_state *st)
  8777. {
  8778. // [Lance] - Improved.
  8779. char *name, *map = NULL;
  8780. struct block_list *bl;
  8781. int type, coverage, x0, y0, x1, y1;
  8782. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8783. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8784. coverage=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8785. if(!st->rid)
  8786. bl = map_id2bl(st->oid);
  8787. else
  8788. bl = &(script_rid2sd(st)->bl);
  8789. if(bl){
  8790. if(coverage < 23){
  8791. clif_soundeffectall(bl,name,type,coverage);
  8792. }else {
  8793. if(st->end > st->start+9){
  8794. map=conv_str(st,& (st->stack->stack_data[st->start+5]));
  8795. x0 = conv_num(st,& (st->stack->stack_data[st->start+6]));
  8796. y0 = conv_num(st,& (st->stack->stack_data[st->start+7]));
  8797. x1 = conv_num(st,& (st->stack->stack_data[st->start+8]));
  8798. y1 = conv_num(st,& (st->stack->stack_data[st->start+9]));
  8799. map_foreachinarea(soundeffect_sub,map_mapname2mapid(map),x0,y0,x1,y1,BL_PC,name,type);
  8800. } else {
  8801. ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
  8802. }
  8803. }
  8804. }
  8805. return 0;
  8806. }
  8807. /*==========================================
  8808. * pet status recovery [Valaris] / Rewritten by [Skotlex]
  8809. *------------------------------------------
  8810. */
  8811. int buildin_petrecovery(struct script_state *st)
  8812. {
  8813. struct pet_data *pd;
  8814. struct map_session_data *sd=script_rid2sd(st);
  8815. if(sd==NULL || sd->pd==NULL)
  8816. return 0;
  8817. pd=sd->pd;
  8818. if (pd->recovery)
  8819. { //Halt previous bonus
  8820. if (pd->recovery->timer != -1)
  8821. delete_timer(pd->recovery->timer, pet_recovery_timer);
  8822. } else //Init
  8823. pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
  8824. pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8825. pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8826. pd->recovery->timer=-1;
  8827. return 0;
  8828. }
  8829. /*==========================================
  8830. * pet healing [Valaris] //Rewritten by [Skotlex]
  8831. *------------------------------------------
  8832. */
  8833. int buildin_petheal(struct script_state *st)
  8834. {
  8835. struct pet_data *pd;
  8836. struct map_session_data *sd=script_rid2sd(st);
  8837. if(sd==NULL || sd->pd==NULL)
  8838. return 0;
  8839. pd=sd->pd;
  8840. if (pd->s_skill)
  8841. { //Clear previous skill
  8842. if (pd->s_skill->timer != -1)
  8843. {
  8844. if (pd->s_skill->id)
  8845. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  8846. else
  8847. delete_timer(pd->s_skill->timer, pet_heal_timer);
  8848. }
  8849. } else //init memory
  8850. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  8851. pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
  8852. //Use the lv as the amount to heal
  8853. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8854. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8855. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8856. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8857. //Use delay as initial offset to avoid skill/heal exploits
  8858. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  8859. pd->s_skill->timer=-1;
  8860. else
  8861. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
  8862. return 0;
  8863. }
  8864. /*==========================================
  8865. * pet attack skills [Valaris] //Rewritten by [Skotlex]
  8866. *------------------------------------------
  8867. */
  8868. int buildin_petskillattack(struct script_state *st)
  8869. {
  8870. struct pet_data *pd;
  8871. struct map_session_data *sd=script_rid2sd(st);
  8872. if(sd==NULL || sd->pd==NULL)
  8873. return 0;
  8874. pd=sd->pd;
  8875. if (pd->a_skill == NULL)
  8876. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  8877. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8878. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8879. pd->a_skill->div_ = 0;
  8880. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8881. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8882. return 0;
  8883. }
  8884. /*==========================================
  8885. * pet attack skills [Valaris]
  8886. *------------------------------------------
  8887. */
  8888. int buildin_petskillattack2(struct script_state *st)
  8889. {
  8890. struct pet_data *pd;
  8891. struct map_session_data *sd=script_rid2sd(st);
  8892. if(sd==NULL || sd->pd==NULL)
  8893. return 0;
  8894. pd=sd->pd;
  8895. if (pd->a_skill == NULL)
  8896. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  8897. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8898. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8899. pd->a_skill->div_ = conv_num(st,& (st->stack->stack_data[st->start+4]));
  8900. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8901. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8902. return 0;
  8903. }
  8904. /*==========================================
  8905. * pet support skills [Skotlex]
  8906. *------------------------------------------
  8907. */
  8908. int buildin_petskillsupport(struct script_state *st)
  8909. {
  8910. struct pet_data *pd;
  8911. struct map_session_data *sd=script_rid2sd(st);
  8912. if(sd==NULL || sd->pd==NULL)
  8913. return 0;
  8914. pd=sd->pd;
  8915. if (pd->s_skill)
  8916. { //Clear previous skill
  8917. if (pd->s_skill->timer != -1)
  8918. {
  8919. if (pd->s_skill->id)
  8920. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  8921. else
  8922. delete_timer(pd->s_skill->timer, pet_heal_timer);
  8923. }
  8924. } else //init memory
  8925. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  8926. pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8927. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8928. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8929. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8930. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8931. //Use delay as initial offset to avoid skill/heal exploits
  8932. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  8933. pd->s_skill->timer=-1;
  8934. else
  8935. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
  8936. return 0;
  8937. }
  8938. /*==========================================
  8939. * Scripted skill effects [Celest]
  8940. *------------------------------------------
  8941. */
  8942. int buildin_skilleffect(struct script_state *st)
  8943. {
  8944. struct map_session_data *sd;
  8945. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8946. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8947. sd=script_rid2sd(st);
  8948. clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
  8949. return 0;
  8950. }
  8951. /*==========================================
  8952. * NPC skill effects [Valaris]
  8953. *------------------------------------------
  8954. */
  8955. int buildin_npcskilleffect(struct script_state *st)
  8956. {
  8957. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  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. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8961. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8962. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  8963. return 0;
  8964. }
  8965. /*==========================================
  8966. * Special effects [Valaris]
  8967. *------------------------------------------
  8968. */
  8969. int buildin_specialeffect(struct script_state *st)
  8970. {
  8971. struct block_list *bl=map_id2bl(st->oid);
  8972. if(bl==NULL)
  8973. return 0;
  8974. 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));
  8975. return 0;
  8976. }
  8977. int buildin_specialeffect2(struct script_state *st)
  8978. {
  8979. struct map_session_data *sd=script_rid2sd(st);
  8980. if(sd==NULL)
  8981. return 0;
  8982. 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));
  8983. return 0;
  8984. }
  8985. /*==========================================
  8986. * Nude [Valaris]
  8987. *------------------------------------------
  8988. */
  8989. int buildin_nude(struct script_state *st)
  8990. {
  8991. struct map_session_data *sd=script_rid2sd(st);
  8992. int i,calcflag=0;
  8993. if(sd==NULL)
  8994. return 0;
  8995. for(i=0;i<11;i++)
  8996. if(sd->equip_index[i] >= 0) {
  8997. if(!calcflag)
  8998. calcflag=1;
  8999. pc_unequipitem(sd,sd->equip_index[i],2);
  9000. }
  9001. if(calcflag)
  9002. status_calc_pc(sd,0);
  9003. return 0;
  9004. }
  9005. /*==========================================
  9006. * gmcommand [MouseJstr]
  9007. *
  9008. * suggested on the forums...
  9009. * splitted into atcommand & charcommand by [Skotlex]
  9010. *------------------------------------------
  9011. */
  9012. int buildin_atcommand(struct script_state *st)
  9013. {
  9014. struct map_session_data *sd=NULL;
  9015. char *cmd;
  9016. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9017. if (st->rid)
  9018. sd = script_rid2sd(st);
  9019. if (sd) is_atcommand(sd->fd, sd, cmd, 99);
  9020. else { //Use a dummy character.
  9021. struct map_session_data dummy_sd;
  9022. struct block_list *bl = NULL;
  9023. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  9024. if (st->oid) bl = map_id2bl(st->oid);
  9025. if (bl) {
  9026. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9027. if (bl->type == BL_NPC)
  9028. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9029. }
  9030. is_atcommand(0, &dummy_sd, cmd, 99);
  9031. }
  9032. return 0;
  9033. }
  9034. int buildin_charcommand(struct script_state *st)
  9035. {
  9036. struct map_session_data *sd=NULL;
  9037. char *cmd;
  9038. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9039. if (st->rid)
  9040. sd = script_rid2sd(st);
  9041. if (sd) is_charcommand(sd->fd, sd, cmd, 99);
  9042. else { //Use a dummy character.
  9043. struct map_session_data dummy_sd;
  9044. struct block_list *bl = NULL;
  9045. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  9046. if (st->oid) bl = map_id2bl(st->oid);
  9047. if (bl) {
  9048. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9049. if (bl->type == BL_NPC)
  9050. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9051. }
  9052. is_charcommand(0, &dummy_sd, cmd, 99);
  9053. }
  9054. return 0;
  9055. }
  9056. /*==========================================
  9057. * Displays a message for the player only (like system messages like "you got an apple" )
  9058. *------------------------------------------
  9059. */
  9060. int buildin_dispbottom(struct script_state *st)
  9061. {
  9062. struct map_session_data *sd=script_rid2sd(st);
  9063. char *message;
  9064. message=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9065. if(sd)
  9066. clif_disp_onlyself(sd,message,(int)strlen(message));
  9067. return 0;
  9068. }
  9069. /*==========================================
  9070. * All The Players Full Recovery
  9071. (HP/SP full restore and resurrect if need)
  9072. *------------------------------------------
  9073. */
  9074. int buildin_recovery(struct script_state *st)
  9075. {
  9076. struct map_session_data *sd, **all_sd;
  9077. int i = 0, users;
  9078. all_sd = map_getallusers(&users);
  9079. for (i = 0; i < users; i++)
  9080. {
  9081. sd = all_sd[i];
  9082. if(pc_isdead(sd))
  9083. status_revive(&sd->bl, 100, 100);
  9084. else
  9085. status_percent_heal(&sd->bl, 100, 100);
  9086. clif_displaymessage(sd->fd,"You have been recovered!");
  9087. }
  9088. return 0;
  9089. }
  9090. /*==========================================
  9091. * Get your pet info: getpetinfo(n)
  9092. * n -> 0:pet_id 1:pet_class 2:pet_name
  9093. 3:friendly 4:hungry
  9094. *------------------------------------------
  9095. */
  9096. int buildin_getpetinfo(struct script_state *st)
  9097. {
  9098. struct map_session_data *sd=script_rid2sd(st);
  9099. struct pet_data *pd;
  9100. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9101. if(sd && sd->status.pet_id && sd->pd){
  9102. pd = sd->pd;
  9103. switch(type){
  9104. case 0:
  9105. push_val(st->stack,C_INT,sd->status.pet_id);
  9106. break;
  9107. case 1:
  9108. push_val(st->stack,C_INT,pd->pet.class_);
  9109. break;
  9110. case 2:
  9111. if(pd->pet.name)
  9112. push_str(st->stack,C_CONSTSTR,(unsigned char *) pd->pet.name);
  9113. else
  9114. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  9115. break;
  9116. case 3:
  9117. push_val(st->stack,C_INT,pd->pet.intimate);
  9118. break;
  9119. case 4:
  9120. push_val(st->stack,C_INT,pd->pet.hungry);
  9121. break;
  9122. default:
  9123. push_val(st->stack,C_INT,0);
  9124. break;
  9125. }
  9126. }else{
  9127. push_val(st->stack,C_INT,0);
  9128. }
  9129. return 0;
  9130. }
  9131. /*==========================================
  9132. * Shows wether your inventory(and equips) contain
  9133. selected card or not.
  9134. checkequipedcard(4001);
  9135. *------------------------------------------
  9136. */
  9137. int buildin_checkequipedcard(struct script_state *st)
  9138. {
  9139. struct map_session_data *sd=script_rid2sd(st);
  9140. int n,i,c=0;
  9141. c=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9142. if(sd){
  9143. for(i=0;i<MAX_INVENTORY;i++){
  9144. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount){
  9145. for(n=0;n<MAX_SLOTS;n++){
  9146. if(sd->status.inventory[i].card[n]==c){
  9147. push_val(st->stack,C_INT,1);
  9148. return 0;
  9149. }
  9150. }
  9151. }
  9152. }
  9153. }
  9154. push_val(st->stack,C_INT,0);
  9155. return 0;
  9156. }
  9157. int buildin_jump_zero(struct script_state *st) {
  9158. int sel;
  9159. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9160. if(!sel) {
  9161. int pos;
  9162. if( st->stack->stack_data[st->start+3].type!=C_POS ){
  9163. ShowError("script: jump_zero: not label !\n");
  9164. st->state=END;
  9165. return 0;
  9166. }
  9167. pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9168. st->pos=pos;
  9169. st->state=GOTO;
  9170. // printf("script: jump_zero: jumpto : %d\n",pos);
  9171. } else {
  9172. // printf("script: jump_zero: fail\n");
  9173. }
  9174. return 0;
  9175. }
  9176. int buildin_select(struct script_state *st)
  9177. {
  9178. char *buf;
  9179. int len,i;
  9180. struct map_session_data *sd;
  9181. sd=script_rid2sd(st);
  9182. if(sd->state.menu_or_input==0){
  9183. st->state=RERUNLINE;
  9184. sd->state.menu_or_input=1;
  9185. for(i=st->start+2,len=16;i<st->end;i++){
  9186. conv_str(st,& (st->stack->stack_data[i]));
  9187. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  9188. }
  9189. buf=(char *)aMalloc((len+1)*sizeof(char));
  9190. buf[0]=0;
  9191. for(i=st->start+2,len=0;i<st->end;i++){
  9192. strcat(buf,st->stack->stack_data[i].u.str);
  9193. strcat(buf,":");
  9194. }
  9195. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  9196. aFree(buf);
  9197. } else if(sd->npc_menu==0xff){ // cansel
  9198. sd->state.menu_or_input=0;
  9199. st->state=END;
  9200. } else {
  9201. // pc_setreg(sd,add_str((unsigned char *) "l15"),sd->npc_menu);
  9202. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  9203. sd->state.menu_or_input=0;
  9204. push_val(st->stack,C_INT,sd->npc_menu);
  9205. }
  9206. return 0;
  9207. }
  9208. /*==========================================
  9209. * GetMapMobs
  9210. returns mob counts on a set map:
  9211. e.g. GetMapMobs("prontera.gat")
  9212. use "this" - for player's map
  9213. *------------------------------------------
  9214. */
  9215. int buildin_getmapmobs(struct script_state *st)
  9216. {
  9217. char *str=NULL;
  9218. int m=-1,bx,by,i;
  9219. int count=0,c;
  9220. struct block_list *bl;
  9221. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9222. if(strcmp(str,"this")==0){
  9223. struct map_session_data *sd=script_rid2sd(st);
  9224. if(sd)
  9225. m=sd->bl.m;
  9226. else{
  9227. push_val(st->stack,C_INT,-1);
  9228. return 0;
  9229. }
  9230. }else
  9231. m=map_mapname2mapid(str);
  9232. if(m < 0){
  9233. push_val(st->stack,C_INT,-1);
  9234. return 0;
  9235. }
  9236. for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++){
  9237. for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++){
  9238. bl = map[m].block_mob[bx+by*map[m].bxs];
  9239. c = map[m].block_mob_count[bx+by*map[m].bxs];
  9240. for(i=0;i<c && bl;i++,bl=bl->next){
  9241. if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
  9242. count++;
  9243. }
  9244. }
  9245. }
  9246. push_val(st->stack,C_INT,count);
  9247. return 0;
  9248. }
  9249. /*==========================================
  9250. * movenpc [MouseJstr]
  9251. *------------------------------------------
  9252. */
  9253. int buildin_movenpc(struct script_state *st)
  9254. {
  9255. TBL_NPC *nd = NULL;
  9256. char *npc;
  9257. int x,y;
  9258. short m;
  9259. npc = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9260. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  9261. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9262. if ((nd = npc_name2id(npc)) == NULL)
  9263. return -1;
  9264. if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  9265. return -1; //Not on a map.
  9266. if (x < 0) x = 0;
  9267. else if (x >= map[m].xs) x = map[m].xs-1;
  9268. if (y < 0) y = 0;
  9269. else if (y >= map[m].ys) y = map[m].ys-1;
  9270. map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9271. map_moveblock(&nd->bl, x, y, gettick());
  9272. map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9273. return 0;
  9274. }
  9275. /*==========================================
  9276. * message [MouseJstr]
  9277. *------------------------------------------
  9278. */
  9279. int buildin_message(struct script_state *st)
  9280. {
  9281. struct map_session_data *sd;
  9282. char *msg,*player;
  9283. struct map_session_data *pl_sd = NULL;
  9284. sd = script_rid2sd(st);
  9285. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9286. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9287. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  9288. return 0;
  9289. clif_displaymessage(pl_sd->fd, msg);
  9290. return 0;
  9291. }
  9292. /*==========================================
  9293. * npctalk (sends message to surrounding
  9294. * area) [Valaris]
  9295. *------------------------------------------
  9296. */
  9297. int buildin_npctalk(struct script_state *st)
  9298. {
  9299. char *str;
  9300. char message[255];
  9301. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9302. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9303. if(nd) {
  9304. memcpy(message, nd->name, NAME_LENGTH);
  9305. strcat(message," : ");
  9306. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  9307. clif_message(&(nd->bl), message);
  9308. }
  9309. return 0;
  9310. }
  9311. /*==========================================
  9312. * hasitems (checks to see if player has any
  9313. * items on them, if so will return a 1)
  9314. * [Valaris]
  9315. *------------------------------------------
  9316. */
  9317. int buildin_hasitems(struct script_state *st)
  9318. {
  9319. int i;
  9320. struct map_session_data *sd;
  9321. sd=script_rid2sd(st);
  9322. for(i=0; i<MAX_INVENTORY; i++) {
  9323. if(sd->status.inventory[i].amount && sd->status.inventory[i].nameid!=2364 && sd->status.inventory[i].nameid!=2365) {
  9324. push_val(st->stack,C_INT,1);
  9325. return 0;
  9326. }
  9327. }
  9328. push_val(st->stack,C_INT,0);
  9329. return 0;
  9330. }
  9331. // change npc walkspeed [Valaris]
  9332. int buildin_npcspeed(struct script_state *st)
  9333. {
  9334. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9335. int x=0;
  9336. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9337. if(nd) {
  9338. nd->speed=x;
  9339. }
  9340. return 0;
  9341. }
  9342. // make an npc walk to a position [Valaris]
  9343. int buildin_npcwalkto(struct script_state *st)
  9344. {
  9345. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9346. int x=0,y=0;
  9347. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9348. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9349. if(nd) {
  9350. unit_walktoxy(&nd->bl,x,y,0);
  9351. }
  9352. return 0;
  9353. }
  9354. // stop an npc's movement [Valaris]
  9355. int buildin_npcstop(struct script_state *st)
  9356. {
  9357. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9358. if(nd) {
  9359. unit_stop_walking(&nd->bl,1);
  9360. }
  9361. return 0;
  9362. }
  9363. /*==========================================
  9364. * getlook char info. getlook(arg)
  9365. *------------------------------------------
  9366. */
  9367. int buildin_getlook(struct script_state *st){
  9368. int type,val;
  9369. struct map_session_data *sd;
  9370. sd=script_rid2sd(st);
  9371. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9372. val=-1;
  9373. switch(type){
  9374. case LOOK_HAIR: //1
  9375. val=sd->status.hair;
  9376. break;
  9377. case LOOK_WEAPON: //2
  9378. val=sd->status.weapon;
  9379. break;
  9380. case LOOK_HEAD_BOTTOM: //3
  9381. val=sd->status.head_bottom;
  9382. break;
  9383. case LOOK_HEAD_TOP: //4
  9384. val=sd->status.head_top;
  9385. break;
  9386. case LOOK_HEAD_MID: //5
  9387. val=sd->status.head_mid;
  9388. break;
  9389. case LOOK_HAIR_COLOR: //6
  9390. val=sd->status.hair_color;
  9391. break;
  9392. case LOOK_CLOTHES_COLOR: //7
  9393. val=sd->status.clothes_color;
  9394. break;
  9395. case LOOK_SHIELD: //8
  9396. val=sd->status.shield;
  9397. break;
  9398. case LOOK_SHOES: //9
  9399. break;
  9400. }
  9401. push_val(st->stack,C_INT,val);
  9402. return 0;
  9403. }
  9404. /*==========================================
  9405. * get char save point. argument: 0- map name, 1- x, 2- y
  9406. *------------------------------------------
  9407. */
  9408. int buildin_getsavepoint(struct script_state *st)
  9409. {
  9410. int x,y,type;
  9411. char *mapname;
  9412. struct map_session_data *sd;
  9413. sd=script_rid2sd(st);
  9414. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9415. x=sd->status.save_point.x;
  9416. y=sd->status.save_point.y;
  9417. switch(type){
  9418. case 0:
  9419. mapname=(char *) aMallocA((MAP_NAME_LENGTH+1)*sizeof(char));
  9420. memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
  9421. mapname[MAP_NAME_LENGTH]='\0';
  9422. push_str(st->stack,C_STR,(unsigned char *) mapname);
  9423. break;
  9424. case 1:
  9425. push_val(st->stack,C_INT,x);
  9426. break;
  9427. case 2:
  9428. push_val(st->stack,C_INT,y);
  9429. break;
  9430. }
  9431. return 0;
  9432. }
  9433. /*==========================================
  9434. * Get position for char/npc/pet/mob objects. Added by Lorky
  9435. *
  9436. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  9437. * where type:
  9438. * MapName$ - String variable for output map name
  9439. * MapX - Integer variable for output coord X
  9440. * MapY - Integer variable for output coord Y
  9441. * type - type of object
  9442. * 0 - Character coord
  9443. * 1 - NPC coord
  9444. * 2 - Pet coord
  9445. * 3 - Mob coord (not released)
  9446. * CharName$ - Name object. If miss or "this" the current object
  9447. *
  9448. * Return:
  9449. * 0 - success
  9450. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  9451. *------------------------------------------
  9452. */
  9453. int buildin_getmapxy(struct script_state *st){
  9454. struct map_session_data *sd=NULL;
  9455. struct npc_data *nd;
  9456. struct pet_data *pd;
  9457. int num;
  9458. char *name;
  9459. char prefix;
  9460. int x,y,type;
  9461. char mapname[MAP_NAME_LENGTH+1];
  9462. memset(mapname, 0, sizeof(mapname));
  9463. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  9464. ShowWarning("script: buildin_getmapxy: not mapname variable\n");
  9465. push_val(st->stack,C_INT,-1);
  9466. return 0;
  9467. }
  9468. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  9469. ShowWarning("script: buildin_getmapxy: not mapx variable\n");
  9470. push_val(st->stack,C_INT,-1);
  9471. return 0;
  9472. }
  9473. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  9474. ShowWarning("script: buildin_getmapxy: not mapy variable\n");
  9475. push_val(st->stack,C_INT,-1);
  9476. return 0;
  9477. }
  9478. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  9479. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9480. switch (type){
  9481. case 0: //Get Character Position
  9482. if( st->end>st->start+6 )
  9483. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9484. else
  9485. sd=script_rid2sd(st);
  9486. if ( sd==NULL ) { //wrong char name or char offline
  9487. push_val(st->stack,C_INT,-1);
  9488. return 0;
  9489. }
  9490. x=sd->bl.x;
  9491. y=sd->bl.y;
  9492. memcpy(mapname,mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  9493. break;
  9494. case 1: //Get NPC Position
  9495. if( st->end > st->start+6 )
  9496. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9497. else
  9498. nd=(struct npc_data *)map_id2bl(st->oid);
  9499. if ( nd==NULL ) { //wrong npc name or char offline
  9500. push_val(st->stack,C_INT,-1);
  9501. return 0;
  9502. }
  9503. x=nd->bl.x;
  9504. y=nd->bl.y;
  9505. memcpy(mapname, map[nd->bl.m].name, MAP_NAME_LENGTH);
  9506. break;
  9507. case 2: //Get Pet Position
  9508. if( st->end>st->start+6 )
  9509. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9510. else
  9511. sd=script_rid2sd(st);
  9512. if ( sd==NULL ) { //wrong char name or char offline
  9513. push_val(st->stack,C_INT,-1);
  9514. return 0;
  9515. }
  9516. pd=sd->pd;
  9517. if(pd==NULL){ //pet data not found
  9518. push_val(st->stack,C_INT,-1);
  9519. return 0;
  9520. }
  9521. x=pd->bl.x;
  9522. y=pd->bl.y;
  9523. memcpy(mapname, map[pd->bl.m].name, MAP_NAME_LENGTH);
  9524. break;
  9525. case 3: //Get Mob Position
  9526. push_val(st->stack,C_INT,-1);
  9527. return 0;
  9528. default: //Wrong type parameter
  9529. push_val(st->stack,C_INT,-1);
  9530. return 0;
  9531. }
  9532. //Set MapName$
  9533. num=st->stack->stack_data[st->start+2].u.num;
  9534. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9535. prefix=*name;
  9536. if(not_server_variable(prefix))
  9537. sd=script_rid2sd(st);
  9538. else
  9539. sd=NULL;
  9540. set_reg(st,sd,num,name,(void*)mapname,st->stack->stack_data[st->start+2].ref);
  9541. //Set MapX
  9542. num=st->stack->stack_data[st->start+3].u.num;
  9543. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9544. prefix=*name;
  9545. if(not_server_variable(prefix))
  9546. sd=script_rid2sd(st);
  9547. else
  9548. sd=NULL;
  9549. set_reg(st,sd,num,name,(void*)x,st->stack->stack_data[st->start+3].ref);
  9550. //Set MapY
  9551. num=st->stack->stack_data[st->start+4].u.num;
  9552. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9553. prefix=*name;
  9554. if(not_server_variable(prefix))
  9555. sd=script_rid2sd(st);
  9556. else
  9557. sd=NULL;
  9558. set_reg(st,sd,num,name,(void*)y,st->stack->stack_data[st->start+4].ref);
  9559. //Return Success value
  9560. push_val(st->stack,C_INT,0);
  9561. return 0;
  9562. }
  9563. /*==========================================
  9564. * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
  9565. *------------------------------------------
  9566. */
  9567. int buildin_logmes(struct script_state *st)
  9568. {
  9569. if (log_config.npc <= 0 ) return 0;
  9570. conv_str(st,& (st->stack->stack_data[st->start+2]));
  9571. log_npc(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str);
  9572. return 0;
  9573. }
  9574. int buildin_summon(struct script_state *st)
  9575. {
  9576. int _class, id, timeout=0;
  9577. char *str,*event="";
  9578. struct map_session_data *sd;
  9579. struct mob_data *md;
  9580. int tick = gettick();
  9581. sd=script_rid2sd(st);
  9582. if (!sd) return 0;
  9583. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  9584. _class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9585. if( st->end>st->start+4 )
  9586. timeout=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9587. if( st->end>st->start+5 ){
  9588. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  9589. check_event(st, event);
  9590. }
  9591. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
  9592. id=mob_once_spawn(sd, "this", 0, 0, str,_class,1,event);
  9593. md=(struct mob_data *)map_id2bl(id);
  9594. if (!md) return 0;
  9595. md->master_id=sd->bl.id;
  9596. md->special_state.ai=1;
  9597. md->deletetimer=add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,id,0);
  9598. clif_misceffect2(&md->bl,344);
  9599. sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  9600. return 0;
  9601. }
  9602. /*==========================================
  9603. * Checks whether it is daytime/nighttime
  9604. *------------------------------------------
  9605. */
  9606. int buildin_isnight(struct script_state *st)
  9607. {
  9608. push_val(st->stack,C_INT, (night_flag == 1));
  9609. return 0;
  9610. }
  9611. int buildin_isday(struct script_state *st)
  9612. {
  9613. push_val(st->stack,C_INT, (night_flag == 0));
  9614. return 0;
  9615. }
  9616. /*================================================
  9617. * Check whether another item/card has been
  9618. * equipped - used for 2/15's cards patch [celest]
  9619. *------------------------------------------------
  9620. */
  9621. // leave this here, just in case
  9622. #if 0
  9623. int buildin_isequipped(struct script_state *st)
  9624. {
  9625. struct map_session_data *sd;
  9626. int i, j, k, id = 1;
  9627. int ret = -1;
  9628. sd = script_rid2sd(st);
  9629. for (i=0; id!=0; i++) {
  9630. int flag = 0;
  9631. FETCH (i+2, id) else id = 0;
  9632. if (id <= 0)
  9633. continue;
  9634. for (j=0; j<EQI_MAX; j++) {
  9635. int index;
  9636. index = sd->equip_index[j];
  9637. if(index < 0) continue;
  9638. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9639. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9640. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9641. if(!sd->inventory_data[index])
  9642. continue;
  9643. if(itemdb_type(id) != IT_CARD) { //Non card
  9644. if (sd->inventory_data[index]->nameid != id)
  9645. continue;
  9646. flag = 1;
  9647. break;
  9648. } else { //Card
  9649. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9650. continue;
  9651. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9652. if (sd->status.inventory[index].card[k] == id)
  9653. {
  9654. flag = 1;
  9655. break;
  9656. }
  9657. }
  9658. }
  9659. if (flag) break;
  9660. }
  9661. if (ret == -1)
  9662. ret = flag;
  9663. else
  9664. ret &= flag;
  9665. if (!ret) break;
  9666. }
  9667. push_val(st->stack,C_INT,ret);
  9668. return 0;
  9669. }
  9670. #endif
  9671. /*================================================
  9672. * Check how many items/cards in the list are
  9673. * equipped - used for 2/15's cards patch [celest]
  9674. *------------------------------------------------
  9675. */
  9676. int buildin_isequippedcnt(struct script_state *st)
  9677. {
  9678. struct map_session_data *sd;
  9679. int i, j, k, id = 1;
  9680. int ret = 0;
  9681. sd = script_rid2sd(st);
  9682. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9683. push_val(st->stack,C_INT,0);
  9684. return 0;
  9685. }
  9686. for (i=0; id!=0; i++) {
  9687. FETCH (i+2, id) else id = 0;
  9688. if (id <= 0)
  9689. continue;
  9690. for (j=0; j<EQI_MAX; j++) {
  9691. int index;
  9692. index = sd->equip_index[j];
  9693. if(index < 0) continue;
  9694. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9695. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9696. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9697. if(!sd->inventory_data[index])
  9698. continue;
  9699. if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
  9700. if (sd->inventory_data[index]->nameid == id)
  9701. ret+= sd->status.inventory[index].amount;
  9702. } else { //Count cards.
  9703. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9704. continue; //No cards
  9705. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9706. if (sd->status.inventory[index].card[k] == id)
  9707. ret++; //[Lupus]
  9708. }
  9709. }
  9710. }
  9711. }
  9712. push_val(st->stack,C_INT,ret);
  9713. return 0;
  9714. }
  9715. /*================================================
  9716. * Check whether another card has been
  9717. * equipped - used for 2/15's cards patch [celest]
  9718. * -- Items checked cannot be reused in another
  9719. * card set to prevent exploits
  9720. *------------------------------------------------
  9721. */
  9722. int buildin_isequipped(struct script_state *st)
  9723. {
  9724. struct map_session_data *sd;
  9725. int i, j, k, id = 1;
  9726. int index, flag;
  9727. int ret = -1;
  9728. //Original hash to reverse it when full check fails.
  9729. unsigned int setitem_hash = 0, setitem_hash2 = 0;
  9730. sd = script_rid2sd(st);
  9731. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9732. push_val(st->stack,C_INT,0);
  9733. return 0;
  9734. }
  9735. setitem_hash = sd->setitem_hash;
  9736. setitem_hash2 = sd->setitem_hash2;
  9737. for (i=0; id!=0; i++)
  9738. {
  9739. FETCH (i+2, id) else id = 0;
  9740. if (id <= 0)
  9741. continue;
  9742. flag = 0;
  9743. for (j=0; j<EQI_MAX; j++)
  9744. {
  9745. index = sd->equip_index[j];
  9746. if(index < 0) continue;
  9747. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9748. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9749. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9750. if(!sd->inventory_data[index])
  9751. continue;
  9752. if (itemdb_type(id) != IT_CARD) {
  9753. if (sd->inventory_data[index]->nameid != id)
  9754. continue;
  9755. flag = 1;
  9756. break;
  9757. } else { //Cards
  9758. if (sd->inventory_data[index]->slot == 0 ||
  9759. itemdb_isspecial(sd->status.inventory[index].card[0]))
  9760. continue;
  9761. for (k = 0; k < sd->inventory_data[index]->slot; k++)
  9762. { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
  9763. unsigned int hash = 0;
  9764. if (sd->status.inventory[index].card[k] != id)
  9765. continue;
  9766. hash = 1<<((j<5?j:j-5)*4 + k);
  9767. // check if card is already used by another set
  9768. if ((j<5?sd->setitem_hash:sd->setitem_hash2) & hash)
  9769. continue;
  9770. // We have found a match
  9771. flag = 1;
  9772. // Set hash so this card cannot be used by another
  9773. if (j<5)
  9774. sd->setitem_hash |= hash;
  9775. else
  9776. sd->setitem_hash2 |= hash;
  9777. break;
  9778. }
  9779. }
  9780. if (flag) break; //Card found
  9781. }
  9782. if (ret == -1)
  9783. ret = flag;
  9784. else
  9785. ret &= flag;
  9786. if (!ret) break;
  9787. }
  9788. if (!ret)
  9789. { //When check fails, restore original hash values. [Skotlex]
  9790. sd->setitem_hash = setitem_hash;
  9791. sd->setitem_hash2 = setitem_hash2;
  9792. }
  9793. push_val(st->stack,C_INT,ret);
  9794. return 0;
  9795. }
  9796. /*================================================
  9797. * Check how many given inserted cards in the CURRENT
  9798. * weapon - used for 2/15's cards patch [Lupus]
  9799. *------------------------------------------------
  9800. */
  9801. int buildin_cardscnt(struct script_state *st)
  9802. {
  9803. struct map_session_data *sd;
  9804. int i, k, id = 1;
  9805. int ret = 0;
  9806. int index;
  9807. sd = script_rid2sd(st);
  9808. for (i=0; id!=0; i++) {
  9809. FETCH (i+2, id) else id = 0;
  9810. if (id <= 0)
  9811. continue;
  9812. index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
  9813. if(index < 0) continue;
  9814. if(!sd->inventory_data[index])
  9815. continue;
  9816. if(itemdb_type(id) != IT_CARD) {
  9817. if (sd->inventory_data[index]->nameid == id)
  9818. ret+= sd->status.inventory[index].amount;
  9819. } else {
  9820. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9821. continue;
  9822. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9823. if (sd->status.inventory[index].card[k] == id)
  9824. ret++;
  9825. }
  9826. }
  9827. }
  9828. push_val(st->stack,C_INT,ret);
  9829. // push_val(st->stack,C_INT,current_equip_item_index);
  9830. return 0;
  9831. }
  9832. /*=======================================================
  9833. * Returns the refined number of the current item, or an
  9834. * item with inventory index specified
  9835. *-------------------------------------------------------
  9836. */
  9837. int buildin_getrefine(struct script_state *st)
  9838. {
  9839. struct map_session_data *sd;
  9840. if ((sd = script_rid2sd(st))!= NULL)
  9841. push_val(st->stack, C_INT, sd->status.inventory[current_equip_item_index].refine);
  9842. return 0;
  9843. }
  9844. /*=======================================================
  9845. * Allows 2 Parents to adopt a character as a Baby
  9846. *-------------------------------------------------------
  9847. */
  9848. int buildin_adopt(struct script_state *st)
  9849. {
  9850. int ret;
  9851. char *parent1 = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9852. char *parent2 = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9853. char *child = conv_str(st,& (st->stack->stack_data[st->start+4]));
  9854. struct map_session_data *p1_sd = map_nick2sd(parent1);
  9855. struct map_session_data *p2_sd = map_nick2sd(parent2);
  9856. struct map_session_data *c_sd = map_nick2sd(child);
  9857. if (!p1_sd || !p2_sd || !c_sd ||
  9858. p1_sd->status.base_level < 70 ||
  9859. p2_sd->status.base_level < 70)
  9860. return 0;
  9861. ret = pc_adoption(p1_sd, p2_sd, c_sd);
  9862. push_val(st->stack, C_INT, ret);
  9863. return 0;
  9864. }
  9865. /*=======================================================
  9866. * Day/Night controls
  9867. *-------------------------------------------------------
  9868. */
  9869. int buildin_night(struct script_state *st)
  9870. {
  9871. if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
  9872. return 0;
  9873. }
  9874. int buildin_day(struct script_state *st)
  9875. {
  9876. if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
  9877. return 0;
  9878. }
  9879. //=======================================================
  9880. // Unequip [Spectre]
  9881. //-------------------------------------------------------
  9882. int buildin_unequip(struct script_state *st)
  9883. {
  9884. int i;
  9885. size_t num;
  9886. struct map_session_data *sd;
  9887. num = conv_num(st,& (st->stack->stack_data[st->start+2])) - 1;
  9888. sd=script_rid2sd(st);
  9889. if(sd!=NULL && num<10)
  9890. {
  9891. i=pc_checkequip(sd,equip[num]);
  9892. pc_unequipitem(sd,i,2);
  9893. return 0;
  9894. }
  9895. return 0;
  9896. }
  9897. int buildin_equip(struct script_state *st)
  9898. {
  9899. int nameid=0,i;
  9900. struct map_session_data *sd;
  9901. struct item_data *item_data;
  9902. sd = script_rid2sd(st);
  9903. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9904. if((item_data = itemdb_exists(nameid)) == NULL)
  9905. {
  9906. if(battle_config.error_log)
  9907. ShowError("wrong item ID : equipitem(%i)\n",nameid);
  9908. return 1;
  9909. }
  9910. for(i=0;i<MAX_INVENTORY && sd->status.inventory[i].nameid!=nameid;i++);
  9911. if(i==MAX_INVENTORY) return 0;
  9912. pc_equipitem(sd,i,item_data->equip);
  9913. return 0;
  9914. }
  9915. int buildin_autoequip(struct script_state *st){
  9916. int nameid, flag;
  9917. struct item_data *item_data;
  9918. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9919. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9920. if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
  9921. item_data->flag.autoequip = flag>0?1:0;
  9922. }
  9923. return 0;
  9924. }
  9925. int buildin_setbattleflag(struct script_state *st){
  9926. char *flag, *value;
  9927. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9928. value = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9929. if (battle_set_value(flag, value) == 0)
  9930. ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'",flag);
  9931. else
  9932. ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.",flag,value);
  9933. return 0;
  9934. }
  9935. int buildin_getbattleflag(struct script_state *st){
  9936. char *flag;
  9937. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9938. push_val(st->stack,C_INT,battle_get_value(flag));
  9939. return 0;
  9940. }
  9941. //=======================================================
  9942. // strlen [Valaris]
  9943. //-------------------------------------------------------
  9944. int buildin_getstrlen(struct script_state *st) {
  9945. char *str = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9946. int len = (str) ? (int)strlen(str) : 0;
  9947. push_val(st->stack,C_INT,len);
  9948. return 0;
  9949. }
  9950. //=======================================================
  9951. // isalpha [Valaris]
  9952. //-------------------------------------------------------
  9953. int buildin_charisalpha(struct script_state *st) {
  9954. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9955. int pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9956. int val = ( str && pos>0 && (unsigned int)pos<strlen(str) ) ? isalpha( str[pos] ) : 0;
  9957. push_val(st->stack,C_INT,val);
  9958. return 0;
  9959. }
  9960. // [Lance]
  9961. int buildin_fakenpcname(struct script_state *st)
  9962. {
  9963. char *name;
  9964. char *newname;
  9965. int look;
  9966. name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9967. newname = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9968. look = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9969. if(look > 32767 || look < -32768) {
  9970. ShowError("buildin_fakenpcname: Invalid look value %d\n",look);
  9971. return 1; // Safety measure to prevent runtime errors
  9972. }
  9973. npc_changename(name,newname,(short)look);
  9974. return 0;
  9975. }
  9976. int buildin_atoi(struct script_state *st) {
  9977. char *value;
  9978. value = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9979. push_val(st->stack, C_INT, atoi(value));
  9980. return 0;
  9981. }
  9982. //-----------------------------------------------------------------------//
  9983. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA START //
  9984. //-----------------------------------------------------------------------//
  9985. int buildin_compare(struct script_state *st) {
  9986. char *message;
  9987. char *cmpstring;
  9988. int j;
  9989. message = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9990. cmpstring = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9991. for (j = 0; message[j]; j++)
  9992. message[j] = tolower(message[j]);
  9993. for (j = 0; cmpstring[j]; j++)
  9994. cmpstring[j] = tolower(cmpstring[j]);
  9995. push_val(st->stack,C_INT,(strstr(message,cmpstring) != NULL));
  9996. return 0;
  9997. }
  9998. //-----------------------------------------------------------------------//
  9999. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA END //
  10000. //-----------------------------------------------------------------------//
  10001. // [zBuffer] List of mathematics commands --->
  10002. int buildin_sqrt(struct script_state *st){
  10003. double i, a;
  10004. i = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10005. a = sqrt(i);
  10006. push_val(st->stack, C_INT, (int)a);
  10007. return 0;
  10008. }
  10009. int buildin_pow(struct script_state *st){
  10010. double i, a, b;
  10011. a = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10012. b = conv_num(st, &(st->stack->stack_data[st->start+3]));
  10013. i = pow(a,b);
  10014. push_val(st->stack, C_INT, (int)i);
  10015. return 0;
  10016. }
  10017. int buildin_distance(struct script_state *st){
  10018. int x0, y0, x1, y1;
  10019. x0 = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10020. y0 = conv_num(st, &(st->stack->stack_data[st->start+3]));
  10021. x1 = conv_num(st, &(st->stack->stack_data[st->start+4]));
  10022. y1 = conv_num(st, &(st->stack->stack_data[st->start+5]));
  10023. push_val(st->stack, C_INT, distance(x0-x1, y0-y1));
  10024. return 0;
  10025. }
  10026. int buildin_checkcell(struct script_state *st){
  10027. int m;
  10028. char *map = conv_str(st, &(st->stack->stack_data[st->start+2]));
  10029. m = mapindex_name2id(map);
  10030. if(m){
  10031. 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]))));
  10032. } else {
  10033. push_val(st->stack, C_INT, 0);
  10034. }
  10035. return 0;
  10036. }
  10037. // <--- [zBuffer] List of mathematics commands
  10038. // [zBuffer] List of dynamic var commands --->
  10039. void setd_sub(struct script_state *st, struct map_session_data *sd, char *varname, int elem, void *value, struct linkdb_node **ref)
  10040. {
  10041. set_reg(st, sd, add_str((unsigned char *) varname)+(elem<<24), varname, value, ref);
  10042. return;
  10043. }
  10044. int buildin_setd(struct script_state *st)
  10045. {
  10046. struct map_session_data *sd=NULL;
  10047. char varname[100], *buffer;
  10048. char *value;
  10049. int elem;
  10050. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10051. value = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10052. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10053. elem = 0;
  10054. if(st->rid)
  10055. sd = script_rid2sd(st);
  10056. if(varname[strlen(varname)-1] != '$') {
  10057. setd_sub(st,sd, varname, elem, (void *)atoi(value),NULL);
  10058. } else {
  10059. setd_sub(st,sd, varname, elem, (void *)value,NULL);
  10060. }
  10061. return 0;
  10062. }
  10063. #ifndef TXT_ONLY
  10064. int buildin_query_sql(struct script_state *st) {
  10065. char *name = NULL, *query;
  10066. int num, i = 0,j, nb_rows;
  10067. struct { char * dst_var_name; char type; } row[32];
  10068. struct map_session_data *sd = (st->rid)? script_rid2sd(st) : NULL;
  10069. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10070. strcpy(tmp_sql, query);
  10071. if(mysql_query(&mmysql_handle,tmp_sql)){
  10072. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10073. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10074. push_val(st->stack,C_INT,0);
  10075. return 1;
  10076. }
  10077. // If some data was returned
  10078. if((sql_res = mysql_store_result(&mmysql_handle))){
  10079. // Count the number of rows to store
  10080. nb_rows = mysql_num_fields(sql_res);
  10081. // Can't store more row than variable
  10082. if (nb_rows > st->end - (st->start+3))
  10083. nb_rows = st->end - (st->start+3);
  10084. if (!nb_rows)
  10085. {
  10086. push_val(st->stack,C_INT,0);
  10087. return 0; // Nothing to store
  10088. }
  10089. if (nb_rows > 32)
  10090. {
  10091. ShowWarning("buildin_query_sql: too much rows!\n");
  10092. push_val(st->stack,C_INT,0);
  10093. return 1;
  10094. }
  10095. memset(row, 0, sizeof(row));
  10096. // Verify argument types
  10097. for(j=0; j < nb_rows; j++)
  10098. {
  10099. if(st->stack->stack_data[st->start+3+j].type != C_NAME){
  10100. ShowWarning("buildin_query_sql: Parameter %d is not a variable!\n", j);
  10101. push_val(st->stack,C_INT,0);
  10102. return 0;
  10103. } else {
  10104. // Store type of variable (string = 0/int = 1)
  10105. num=st->stack->stack_data[st->start+3+j].u.num;
  10106. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10107. if(name[strlen(name)-1] != '$') {
  10108. row[j].type = 1;
  10109. }
  10110. row[j].dst_var_name = name;
  10111. }
  10112. }
  10113. // Store data
  10114. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  10115. for(j=0; j < nb_rows; j++)
  10116. {
  10117. if (row[j].type == 1)
  10118. setd_sub(st,sd, row[j].dst_var_name, i, (void *)atoi(sql_row[j]),st->stack->stack_data[st->start+3+j].ref);
  10119. else
  10120. setd_sub(st,sd, row[j].dst_var_name, i, (void *)sql_row[j],st->stack->stack_data[st->start+3+j].ref);
  10121. }
  10122. i++;
  10123. }
  10124. // Free data
  10125. mysql_free_result(sql_res);
  10126. }
  10127. push_val(st->stack, C_INT, i);
  10128. return 0;
  10129. }
  10130. //Allows escaping of a given string.
  10131. int buildin_escape_sql(struct script_state *st) {
  10132. char *t_query, *query;
  10133. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10134. t_query = aMallocA((strlen(query)*2+1)*sizeof(char));
  10135. jstrescapecpy(t_query,query);
  10136. push_str(st->stack,C_STR,(unsigned char *)t_query);
  10137. return 0;
  10138. }
  10139. #endif
  10140. int buildin_getd (struct script_state *st)
  10141. {
  10142. char varname[100], *buffer;
  10143. //struct script_data dat;
  10144. int elem;
  10145. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10146. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10147. elem = 0;
  10148. /*dat.type=C_NAME;
  10149. dat.u.num=add_str((unsigned char *) varname)+(elem<<24);
  10150. get_val(st,&dat);
  10151. if(dat.type == C_INT)
  10152. push_val(st->stack, C_INT, dat.u.num);
  10153. else if(dat.type == C_CONSTSTR){
  10154. buffer = aStrdup((char *)dat.u.str);
  10155. // dat.u.str holds the actual pointer to the data, must be duplicated.
  10156. // It will be freed later. Tested.
  10157. push_str(st->stack, C_STR, buffer);
  10158. }*/
  10159. // Push the 'pointer' so it's more flexible [Lance]
  10160. push_val(st->stack,C_NAME,
  10161. (elem<<24) | add_str((unsigned char *) varname));
  10162. return 0;
  10163. }
  10164. // <--- [zBuffer] List of dynamic var commands
  10165. // Pet stat [Lance]
  10166. int buildin_petstat(struct script_state *st){
  10167. struct map_session_data *sd = NULL;
  10168. struct pet_data *pd;
  10169. char *tmp;
  10170. int flag = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10171. sd = script_rid2sd(st);
  10172. if(!sd || !sd->status.pet_id || !sd->pd){
  10173. if(flag == 2)
  10174. push_str(st->stack, C_CONSTSTR, "");
  10175. else
  10176. push_val(st->stack, C_INT, 0);
  10177. return 0;
  10178. }
  10179. pd = sd->pd;
  10180. switch(flag){
  10181. case 1:
  10182. push_val(st->stack, C_INT, (int)pd->pet.class_);
  10183. break;
  10184. case 2:
  10185. tmp = aStrdup(pd->pet.name);
  10186. push_str(st->stack, C_STR, tmp);
  10187. break;
  10188. case 3:
  10189. push_val(st->stack, C_INT, (int)pd->pet.level);
  10190. break;
  10191. case 4:
  10192. push_val(st->stack, C_INT, (int)pd->pet.hungry);
  10193. break;
  10194. case 5:
  10195. push_val(st->stack, C_INT, (int)pd->pet.intimate);
  10196. break;
  10197. default:
  10198. push_val(st->stack, C_INT, 0);
  10199. break;
  10200. }
  10201. return 0;
  10202. }
  10203. int buildin_callshop(struct script_state *st)
  10204. {
  10205. struct map_session_data *sd = NULL;
  10206. struct npc_data *nd;
  10207. char *shopname;
  10208. int flag = 0;
  10209. sd = script_rid2sd(st);
  10210. if (!sd) {
  10211. push_val(st->stack,C_INT,0);
  10212. return 0;
  10213. }
  10214. shopname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10215. if( st->end>st->start+3 )
  10216. flag = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10217. nd = npc_name2id(shopname);
  10218. if (!nd || nd->bl.type!=BL_NPC || nd->bl.subtype!=SHOP) {
  10219. ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)", shopname);
  10220. push_val(st->stack,C_INT,0);
  10221. return 1;
  10222. }
  10223. switch (flag) {
  10224. case 1: //Buy window
  10225. npc_buysellsel(sd,nd->bl.id,0);
  10226. break;
  10227. case 2: //Sell window
  10228. npc_buysellsel(sd,nd->bl.id,1);
  10229. break;
  10230. default: //Show menu
  10231. clif_npcbuysell(sd,nd->bl.id);
  10232. break;
  10233. }
  10234. sd->npc_shopid = nd->bl.id;
  10235. push_val(st->stack,C_INT,1);
  10236. return 0;
  10237. }
  10238. #ifndef MAX_SHOPITEM
  10239. #define MAX_SHOPITEM 100
  10240. #endif
  10241. int buildin_npcshopitem(struct script_state *st)
  10242. {
  10243. struct npc_data *nd= NULL;
  10244. int n = 0;
  10245. int i = 3;
  10246. int amount;
  10247. char* npcname = conv_str(st, & (st->stack->stack_data[st->start + 2]));
  10248. nd = npc_name2id(npcname);
  10249. if(nd && nd->bl.subtype==SHOP){
  10250. amount = ((st->end-2)/2)+1;
  10251. // st->end - 2 = nameid + value # ... / 2 = number of items ... + 1 to end it
  10252. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10253. sizeof(nd->u.shop_item[0]) * amount);
  10254. // Reset sell list.
  10255. memset(nd->u.shop_item, 0, sizeof(nd->u.shop_item[0]) * amount);
  10256. n = 0;
  10257. while (st->end > st->start + i) {
  10258. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10259. i++;
  10260. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10261. i++;
  10262. n++;
  10263. }
  10264. map_addiddb(&nd->bl);
  10265. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10266. } else {
  10267. ShowError("buildin_npcshopitem: shop not found.\n");
  10268. }
  10269. return 0;
  10270. }
  10271. int buildin_npcshopadditem(struct script_state *st) {
  10272. struct npc_data *nd=NULL;
  10273. int n = 0;
  10274. int i = 3;
  10275. int amount;
  10276. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10277. nd = npc_name2id(npcname);
  10278. if (nd && nd->bl.subtype==SHOP){
  10279. amount = ((st->end-2)/2)+1;
  10280. while (nd->u.shop_item[n].nameid && n < MAX_SHOPITEM)
  10281. n++;
  10282. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10283. sizeof(nd->u.shop_item[0]) * (amount+n));
  10284. while(st->end > st->start + i){
  10285. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10286. i++;
  10287. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10288. i++;
  10289. n++;
  10290. }
  10291. // Marks the last of our stuff..
  10292. nd->u.shop_item[n].value = 0;
  10293. nd->u.shop_item[n].nameid = 0;
  10294. map_addiddb(&nd->bl);
  10295. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10296. } else {
  10297. ShowError("buildin_npcshopadditem: shop not found.\n");
  10298. }
  10299. return 0;
  10300. }
  10301. int buildin_npcshopdelitem(struct script_state *st)
  10302. {
  10303. struct npc_data *nd=NULL;
  10304. int n=0;
  10305. int i=3;
  10306. int size = 0;
  10307. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10308. nd = npc_name2id(npcname);
  10309. if (nd && nd->bl.subtype==SHOP) {
  10310. while (nd->u.shop_item[size].nameid)
  10311. size++;
  10312. while (st->end > st->start+i) {
  10313. for(n=0;nd->u.shop_item[n].nameid && n < MAX_SHOPITEM;n++) {
  10314. if (nd->u.shop_item[n].nameid == conv_num(st, & (st->stack->stack_data[st->start+i]))) {
  10315. // We're moving 1 extra empty block. Junk data is eliminated later.
  10316. memmove(&nd->u.shop_item[n], &nd->u.shop_item[n+1], sizeof(nd->u.shop_item[0])*(size-n));
  10317. }
  10318. }
  10319. i++;
  10320. }
  10321. size = 0;
  10322. while (nd->u.shop_item[size].nameid)
  10323. size++;
  10324. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10325. sizeof(nd->u.shop_item[0]) * (size+1));
  10326. map_addiddb(&nd->bl);
  10327. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10328. } else {
  10329. ShowError("buildin_npcshopdelitem: shop not found.\n");
  10330. }
  10331. return 0;
  10332. }
  10333. /*==========================================
  10334. * Returns some values of an item [Lupus]
  10335. * Price, Weight, etc...
  10336. setiteminfo(itemID,"{new item bonus script}");
  10337. *------------------------------------------
  10338. */
  10339. int buildin_setitemscript(struct script_state *st)
  10340. {
  10341. int item_id;
  10342. char *script;
  10343. struct item_data *i_data;
  10344. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10345. script = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10346. i_data = itemdb_exists(item_id);
  10347. if (i_data && script!=NULL && script[0]=='{') {
  10348. if(i_data->script!=NULL)
  10349. script_free_code(i_data->script);
  10350. i_data->script = parse_script((unsigned char *) script, "script_setitemscript", 0);
  10351. push_val(st->stack,C_INT,1);
  10352. } else
  10353. push_val(st->stack,C_INT,0);
  10354. return 0;
  10355. }
  10356. /* Work In Progress [Lupus]
  10357. int buildin_addmonsterdrop(struct script_state *st)
  10358. {
  10359. int class_,item_id,chance;
  10360. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10361. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10362. chance=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10363. if(class_>1000 && item_id>500 && chance>0) {
  10364. push_val(st->stack,C_INT,1);
  10365. } else {
  10366. push_val(st->stack,C_INT,0);
  10367. }
  10368. }
  10369. int buildin_delmonsterdrop(struct script_state *st)
  10370. {
  10371. int class_,item_id;
  10372. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10373. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10374. if(class_>1000 && item_id>500) {
  10375. push_val(st->stack,C_INT,1);
  10376. } else {
  10377. push_val(st->stack,C_INT,0);
  10378. }
  10379. }
  10380. */
  10381. /*==========================================
  10382. * Returns some values of a monster [Lupus]
  10383. * Name, Level, race, size, etc...
  10384. getmonsterinfo(monsterID,queryIndex);
  10385. *------------------------------------------
  10386. */
  10387. int buildin_getmonsterinfo(struct script_state *st)
  10388. {
  10389. struct mob_db *mob;
  10390. int mob_id;
  10391. mob_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10392. if (!mobdb_checkid(mob_id)) {
  10393. ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i", mob_id);
  10394. push_val(st->stack, C_INT, -1);
  10395. return -1;
  10396. }
  10397. mob = mob_db(mob_id);
  10398. switch ( conv_num(st,& (st->stack->stack_data[st->start+3])) ) {
  10399. case 0: //Name
  10400. push_str(st->stack,C_CONSTSTR, (unsigned char *) mob->jname);
  10401. break;
  10402. case 1: //Lvl
  10403. push_val(st->stack,C_INT, mob->lv);
  10404. break;
  10405. case 2: //MaxHP
  10406. push_val(st->stack,C_INT, mob->status.max_hp);
  10407. break;
  10408. case 3: //Base EXP
  10409. push_val(st->stack,C_INT, mob->base_exp);
  10410. break;
  10411. case 4: //Job EXP
  10412. push_val(st->stack,C_INT, mob->job_exp);
  10413. break;
  10414. case 5: //Atk1
  10415. push_val(st->stack,C_INT, mob->status.rhw.atk);
  10416. break;
  10417. case 6: //Atk2
  10418. push_val(st->stack,C_INT, mob->status.rhw.atk2);
  10419. break;
  10420. case 7: //Def
  10421. push_val(st->stack,C_INT, mob->status.def);
  10422. break;
  10423. case 8: //Mdef
  10424. push_val(st->stack,C_INT, mob->status.mdef);
  10425. break;
  10426. case 9: //Str
  10427. push_val(st->stack,C_INT, mob->status.str);
  10428. break;
  10429. case 10: //Agi
  10430. push_val(st->stack,C_INT, mob->status.agi);
  10431. break;
  10432. case 11: //Vit
  10433. push_val(st->stack,C_INT, mob->status.vit);
  10434. break;
  10435. case 12: //Int
  10436. push_val(st->stack,C_INT, mob->status.int_);
  10437. break;
  10438. case 13: //Dex
  10439. push_val(st->stack,C_INT, mob->status.dex);
  10440. break;
  10441. case 14: //Luk
  10442. push_val(st->stack,C_INT, mob->status.luk);
  10443. break;
  10444. case 15: //Range
  10445. push_val(st->stack,C_INT, mob->status.rhw.range);
  10446. break;
  10447. case 16: //Range2
  10448. push_val(st->stack,C_INT, mob->range2);
  10449. break;
  10450. case 17: //Range3
  10451. push_val(st->stack,C_INT, mob->range3);
  10452. break;
  10453. case 18: //Size
  10454. push_val(st->stack,C_INT, mob->status.size);
  10455. break;
  10456. case 19: //Race
  10457. push_val(st->stack,C_INT, mob->status.race);
  10458. break;
  10459. case 20: //Element
  10460. push_val(st->stack,C_INT, mob->status.def_ele);
  10461. break;
  10462. case 21: //Mode
  10463. push_val(st->stack,C_INT, mob->status.mode);
  10464. break;
  10465. default: //wrong Index
  10466. push_val(st->stack,C_INT,-1);
  10467. }
  10468. return 0;
  10469. }
  10470. int axtoi(char *hexStg) {
  10471. int n = 0; // position in string
  10472. int m = 0; // position in digit[] to shift
  10473. int count; // loop index
  10474. int intValue = 0; // integer value of hex string
  10475. int digit[11]; // hold values to convert
  10476. while (n < 10) {
  10477. if (hexStg[n]=='\0')
  10478. break;
  10479. if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
  10480. digit[n] = hexStg[n] & 0x0f; //convert to int
  10481. else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
  10482. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10483. else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
  10484. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10485. else break;
  10486. n++;
  10487. }
  10488. count = n;
  10489. m = n - 1;
  10490. n = 0;
  10491. while(n < count) {
  10492. // digit[n] is value of hex digit at position n
  10493. // (m << 2) is the number of positions to shift
  10494. // OR the bits into return value
  10495. intValue = intValue | (digit[n] << (m << 2));
  10496. m--; // adjust the position to set
  10497. n++; // next digit to process
  10498. }
  10499. return (intValue);
  10500. }
  10501. // [Lance] Hex string to integer converter
  10502. int buildin_axtoi(struct script_state *st)
  10503. {
  10504. char *hex = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10505. push_val(st->stack, C_INT, axtoi(hex));
  10506. return 0;
  10507. }
  10508. // [zBuffer] List of player cont commands --->
  10509. int buildin_rid2name(struct script_state *st){
  10510. struct block_list *bl = NULL;
  10511. int rid = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10512. if((bl = map_id2bl(rid))){
  10513. switch(bl->type){
  10514. case BL_MOB:
  10515. push_str(st->stack,C_CONSTSTR,((struct mob_data *)bl)->name);
  10516. break;
  10517. case BL_PC:
  10518. push_str(st->stack,C_CONSTSTR,((struct map_session_data *)bl)->status.name);
  10519. break;
  10520. case BL_NPC:
  10521. push_str(st->stack,C_CONSTSTR,((struct npc_data *)bl)->exname);
  10522. break;
  10523. case BL_PET:
  10524. push_str(st->stack,C_CONSTSTR,((struct pet_data *)bl)->pet.name);
  10525. break;
  10526. case BL_HOM:
  10527. push_str(st->stack,C_CONSTSTR,((struct homun_data *)bl)->master->homunculus.name);
  10528. break;
  10529. default:
  10530. ShowError("buildin_rid2name: BL type unknown.\n");
  10531. push_str(st->stack,C_CONSTSTR,"");
  10532. break;
  10533. }
  10534. } else {
  10535. ShowError("buildin_rid2name: invalid RID\n");
  10536. push_str(st->stack,C_CONSTSTR,"(null)");
  10537. }
  10538. return 0;
  10539. }
  10540. int buildin_pcblockmove(struct script_state *st){
  10541. int id, flag;
  10542. struct map_session_data *sd = NULL;
  10543. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10544. flag = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10545. if(id)
  10546. sd = map_id2sd(id);
  10547. else
  10548. sd = script_rid2sd(st);
  10549. if(sd)
  10550. sd->state.blockedmove = flag > 0;
  10551. return 0;
  10552. }
  10553. int buildin_pcfollow(struct script_state *st) {
  10554. int id, targetid;
  10555. struct map_session_data *sd = NULL;
  10556. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10557. targetid = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10558. if(id)
  10559. sd = map_id2sd(id);
  10560. else
  10561. sd = script_rid2sd(st);
  10562. if(sd)
  10563. pc_follow(sd, targetid);
  10564. return 0;
  10565. }
  10566. int buildin_pcstopfollow(struct script_state *st) {
  10567. int id;
  10568. struct map_session_data *sd = NULL;
  10569. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10570. if(id)
  10571. sd = map_id2sd(id);
  10572. else
  10573. sd = script_rid2sd(st);
  10574. if(sd)
  10575. pc_stop_following(sd);
  10576. return 0;
  10577. }
  10578. // <--- [zBuffer] List of player cont commands
  10579. // [zBuffer] List of mob control commands --->
  10580. int buildin_mobspawn(struct script_state *st){
  10581. int class_,x,y,id;
  10582. char *str,*map;
  10583. // Who?
  10584. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  10585. // What?
  10586. class_ =conv_num(st,& (st->stack->stack_data[st->start+3]));
  10587. // Where?
  10588. map =conv_str(st,& (st->stack->stack_data[st->start+4]));
  10589. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  10590. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  10591. id = mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,1,NULL);
  10592. push_val(st->stack,C_INT,id);
  10593. return 0;
  10594. }
  10595. int buildin_mobremove(struct script_state *st) {
  10596. int id;
  10597. struct block_list *bl = NULL;
  10598. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10599. bl = map_id2bl(id);
  10600. if (bl && bl->type == BL_MOB)
  10601. unit_free(bl,0);
  10602. return 0;
  10603. }
  10604. int buildin_getmobdata(struct script_state *st) {
  10605. int num, id;
  10606. char *name;
  10607. struct mob_data *md = NULL;
  10608. struct map_session_data *sd = st->rid?map_id2sd(st->rid):NULL;
  10609. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10610. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB || st->stack->stack_data[st->start+3].type!=C_NAME ){
  10611. ShowWarning("buildin_getmobdata: Error in argument!\n");
  10612. return -1;
  10613. }
  10614. num=st->stack->stack_data[st->start+3].u.num;
  10615. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10616. setd_sub(st,sd,name,0,(void *)(int)md->class_,st->stack->stack_data[st->start+3].ref);
  10617. setd_sub(st,sd,name,1,(void *)(int)md->level,st->stack->stack_data[st->start+3].ref);
  10618. setd_sub(st,sd,name,2,(void *)(int)md->status.hp,st->stack->stack_data[st->start+3].ref);
  10619. setd_sub(st,sd,name,3,(void *)(int)md->status.max_hp,st->stack->stack_data[st->start+3].ref);
  10620. setd_sub(st,sd,name,4,(void *)(int)md->master_id,st->stack->stack_data[st->start+3].ref);
  10621. setd_sub(st,sd,name,5,(void *)(int)md->bl.m,st->stack->stack_data[st->start+3].ref);
  10622. setd_sub(st,sd,name,6,(void *)(int)md->bl.x,st->stack->stack_data[st->start+3].ref);
  10623. setd_sub(st,sd,name,7,(void *)(int)md->bl.y,st->stack->stack_data[st->start+3].ref);
  10624. setd_sub(st,sd,name,8,(void *)(int)md->status.speed,st->stack->stack_data[st->start+3].ref);
  10625. setd_sub(st,sd,name,9,(void *)(int)md->status.mode,st->stack->stack_data[st->start+3].ref);
  10626. setd_sub(st,sd,name,10,(void *)(int)md->special_state.ai,st->stack->stack_data[st->start+3].ref);
  10627. setd_sub(st,sd,name,11,(void *)(int)md->sc.option,st->stack->stack_data[st->start+3].ref);
  10628. setd_sub(st,sd,name,12,(void *)(int)md->vd->sex,st->stack->stack_data[st->start+3].ref);
  10629. setd_sub(st,sd,name,13,(void *)(int)md->vd->class_,st->stack->stack_data[st->start+3].ref);
  10630. setd_sub(st,sd,name,14,(void *)(int)md->vd->hair_style,st->stack->stack_data[st->start+3].ref);
  10631. setd_sub(st,sd,name,15,(void *)(int)md->vd->hair_color,st->stack->stack_data[st->start+3].ref);
  10632. setd_sub(st,sd,name,16,(void *)(int)md->vd->head_bottom,st->stack->stack_data[st->start+3].ref);
  10633. setd_sub(st,sd,name,17,(void *)(int)md->vd->head_mid,st->stack->stack_data[st->start+3].ref);
  10634. setd_sub(st,sd,name,18,(void *)(int)md->vd->head_top,st->stack->stack_data[st->start+3].ref);
  10635. setd_sub(st,sd,name,19,(void *)(int)md->vd->cloth_color,st->stack->stack_data[st->start+3].ref);
  10636. setd_sub(st,sd,name,20,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10637. setd_sub(st,sd,name,21,(void *)(int)md->vd->weapon,st->stack->stack_data[st->start+3].ref);
  10638. setd_sub(st,sd,name,22,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10639. setd_sub(st,sd,name,23,(void *)(int)md->ud.dir,st->stack->stack_data[st->start+3].ref);
  10640. setd_sub(st,sd,name,24,(void *)(int)md->state.killer,st->stack->stack_data[st->start+3].ref);
  10641. setd_sub(st,sd,name,25,(void *)(int)md->callback_flag,st->stack->stack_data[st->start+3].ref);
  10642. setd_sub(st,sd,name,26,(void *)(int)md->state.no_random_walk, st->stack->stack_data[st->start+3].ref);
  10643. return 0;
  10644. }
  10645. int buildin_setmobdata(struct script_state *st){
  10646. int id, value, value2;
  10647. struct mob_data *md = NULL;
  10648. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10649. value = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10650. value2 = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10651. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB){
  10652. ShowWarning("buildin_setmobdata: Error in argument!\n");
  10653. return -1;
  10654. }
  10655. switch(value){
  10656. case 0:
  10657. md->class_ = (short)value2;
  10658. break;
  10659. case 1:
  10660. md->level = (unsigned short)value2;
  10661. break;
  10662. case 2:
  10663. md->status.hp = value2;
  10664. break;
  10665. case 3:
  10666. md->status.max_hp = value2;
  10667. break;
  10668. case 4:
  10669. md->master_id = value2;
  10670. break;
  10671. case 5:
  10672. md->bl.m = (short)value2;
  10673. break;
  10674. case 6:
  10675. md->bl.x = (short)value2;
  10676. break;
  10677. case 7:
  10678. md->bl.y = (short)value2;
  10679. break;
  10680. case 8:
  10681. md->status.speed = (short)value2;
  10682. break;
  10683. case 9:
  10684. md->status.mode = (short)value2;
  10685. break;
  10686. case 10:
  10687. md->special_state.ai = (unsigned int)value2;
  10688. break;
  10689. case 11:
  10690. md->sc.option = (short)value2;
  10691. break;
  10692. case 12:
  10693. md->vd->sex = value2;
  10694. break;
  10695. case 13:
  10696. md->vd->class_ = value2;
  10697. break;
  10698. case 14:
  10699. md->vd->hair_style = (short)value2;
  10700. break;
  10701. case 15:
  10702. md->vd->hair_color = (short)value2;
  10703. break;
  10704. case 16:
  10705. md->vd->head_bottom = (short)value2;
  10706. break;
  10707. case 17:
  10708. md->vd->head_mid = (short)value2;
  10709. break;
  10710. case 18:
  10711. md->vd->head_top = (short)value2;
  10712. break;
  10713. case 19:
  10714. md->vd->cloth_color = (short)value2;
  10715. break;
  10716. case 20:
  10717. md->vd->shield = value2;
  10718. break;
  10719. case 21:
  10720. md->vd->weapon = (short)value2;
  10721. break;
  10722. case 22:
  10723. md->vd->shield = (short)value2;
  10724. break;
  10725. case 23:
  10726. md->ud.dir = (unsigned char)value2;
  10727. break;
  10728. case 24:
  10729. md->state.killer = value2>0?1:0;
  10730. break;
  10731. case 25:
  10732. md->callback_flag = (short)value2;
  10733. break;
  10734. case 26:
  10735. md->state.no_random_walk = value2>0?1:0;
  10736. break;
  10737. default:
  10738. ShowError("buildin_setmobdata: argument id is not identified.");
  10739. return -1;
  10740. }
  10741. return 0;
  10742. }
  10743. int buildin_mobassist(struct script_state *st) {
  10744. int id;
  10745. char *target;
  10746. struct mob_data *md = NULL;
  10747. struct block_list *bl = NULL;
  10748. struct unit_data *ud;
  10749. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10750. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10751. if((bl =&(map_nick2sd(target)->bl)) || (bl = map_id2bl(atoi(target)))) {
  10752. md = (struct mob_data *)map_id2bl(id);
  10753. if(md && md->bl.type == BL_MOB) {
  10754. ud = unit_bl2ud(bl);
  10755. md->master_id = bl->id;
  10756. md->state.killer = 1;
  10757. mob_convertslave(md);
  10758. if (ud) {
  10759. if (ud->target)
  10760. md->target_id = ud->target;
  10761. else if (ud->skilltarget)
  10762. md->target_id = ud->skilltarget;
  10763. if(md->target_id)
  10764. unit_walktobl(&md->bl, map_id2bl(md->target_id), 65025, 2);
  10765. }
  10766. }
  10767. }
  10768. return 0;
  10769. }
  10770. int buildin_mobattach(struct script_state *st){
  10771. int id;
  10772. struct mob_data *md = NULL;
  10773. struct npc_data *nd = NULL;
  10774. char *npcname = NULL;
  10775. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10776. if(st->end > st->start + 3){
  10777. npcname = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10778. }
  10779. if(npcname)
  10780. nd = npc_name2id(npcname);
  10781. else
  10782. nd = (struct npc_data *)map_id2bl(st->oid);
  10783. if(nd)
  10784. if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB)
  10785. md->nd = nd;
  10786. return 0;
  10787. }
  10788. int buildin_unitwalk(struct script_state *st){
  10789. int id,x,y = 0;
  10790. struct block_list *bl = NULL;
  10791. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10792. x = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10793. if(st->end > st->start+4)
  10794. y = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10795. bl = map_id2bl(id);
  10796. if(bl){
  10797. if(y)
  10798. push_val(st->stack,C_INT,unit_walktoxy(bl,x,y,0)); // We'll use harder calculations.
  10799. else
  10800. push_val(st->stack,C_INT,unit_walktobl(bl,map_id2bl(x),65025,1));
  10801. } else {
  10802. push_val(st->stack,C_INT,0);
  10803. }
  10804. return 0;
  10805. }
  10806. int buildin_unitkill(struct script_state *st){
  10807. struct block_list *bl = map_id2bl(conv_num(st, & (st->stack->stack_data[st->start+2])));
  10808. if(bl)
  10809. status_kill(bl);
  10810. return 0;
  10811. }
  10812. int buildin_unitwarp(struct script_state *st){
  10813. int id,x,y,m = 0;
  10814. char *map;
  10815. struct block_list *bl = NULL;
  10816. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10817. map = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10818. x = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10819. y = conv_num(st, & (st->stack->stack_data[st->start+5]));
  10820. bl = map_id2bl(id);
  10821. m = map_mapname2mapid(map);
  10822. if(m && bl){
  10823. push_val(st->stack,C_INT,unit_warp(bl, m, (short)x, (short)y, 0));
  10824. } else {
  10825. push_val(st->stack,C_INT,0);
  10826. }
  10827. return 0;
  10828. }
  10829. int buildin_unitattack(struct script_state *st) {
  10830. int id = 0, actiontype = 0;
  10831. char *target = NULL;
  10832. struct map_session_data *sd = NULL;
  10833. struct block_list *bl = NULL, *tbl = NULL;
  10834. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10835. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10836. if(st->end > st->start + 4)
  10837. actiontype = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10838. sd = map_nick2sd(target);
  10839. if(!sd)
  10840. tbl = map_id2bl(atoi(target));
  10841. else
  10842. tbl = &sd->bl;
  10843. if((bl = map_id2bl(id))){
  10844. if (bl->type == BL_MOB) {
  10845. ((TBL_MOB *)bl)->state.killer = 1;
  10846. ((TBL_MOB *)bl)->target_id = tbl->id;
  10847. } else if(bl->type == BL_PC){
  10848. clif_parse_ActionRequest_sub(((TBL_PC *)bl), actiontype > 0?0x07:0x00, tbl->id, gettick());
  10849. push_val(st->stack,C_INT,1);
  10850. return 0;
  10851. }
  10852. push_val(st->stack,C_INT,unit_walktobl(bl, tbl, 65025, 2));
  10853. } else {
  10854. push_val(st->stack,C_INT,0);
  10855. }
  10856. return 0;
  10857. }
  10858. int buildin_unitstop(struct script_state *st) {
  10859. int id;
  10860. struct block_list *bl = NULL;
  10861. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10862. bl = map_id2bl(id);
  10863. if(bl){
  10864. unit_stop_attack(bl);
  10865. unit_stop_walking(bl,0);
  10866. if(bl->type == BL_MOB)
  10867. ((TBL_MOB *)bl)->target_id = 0;
  10868. }
  10869. return 0;
  10870. }
  10871. int buildin_unittalk(struct script_state *st)
  10872. {
  10873. char *str;
  10874. int id;
  10875. char message[255];
  10876. struct block_list *bl = NULL;
  10877. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10878. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  10879. bl = map_id2bl(id);
  10880. if(bl) {
  10881. switch(bl->type){
  10882. case BL_MOB:
  10883. memcpy(message, ((TBL_MOB *)bl)->name, NAME_LENGTH);
  10884. break;
  10885. case BL_PC:
  10886. if(strlen(((TBL_PC *)bl)->fakename)>0)
  10887. memcpy(message, ((TBL_PC *)bl)->fakename, NAME_LENGTH);
  10888. else
  10889. memcpy(message, ((TBL_PC *)bl)->status.name, NAME_LENGTH);
  10890. break;
  10891. case BL_NPC:
  10892. memcpy(message, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  10893. break;
  10894. case BL_HOM:
  10895. memcpy(message, ((TBL_HOM *)bl)->master->homunculus.name, NAME_LENGTH);
  10896. break;
  10897. case BL_PET:
  10898. memcpy(message, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  10899. break;
  10900. default:
  10901. strcpy(message, "Unknown");
  10902. }
  10903. strcat(message," : ");
  10904. strncat(message,str, 228); //Prevent overflow possibility. [Skotlex]
  10905. clif_message(bl, message);
  10906. if(bl->type == BL_PC)
  10907. clif_displaymessage(((TBL_PC*)bl)->fd, message);
  10908. }
  10909. return 0;
  10910. }
  10911. int buildin_unitemote(struct script_state *st) {
  10912. int id, emo;
  10913. struct block_list *bl= NULL;
  10914. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10915. emo = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10916. if((bl = map_id2bl(id)))
  10917. clif_emotion(bl,emo);
  10918. return 0;
  10919. }
  10920. int buildin_unitdeadsit(struct script_state *st){
  10921. int id, action;
  10922. struct block_list *bl = NULL;
  10923. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10924. action = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10925. if((bl = map_id2bl(id))){
  10926. if(action > -1 && action < 4){
  10927. unsigned char buf[61] = "";
  10928. switch(bl->type){
  10929. case BL_MOB:
  10930. ((TBL_MOB *)bl)->vd->dead_sit = action;
  10931. break;
  10932. case BL_PC:
  10933. ((TBL_PC *)bl)->vd.dead_sit = action;
  10934. break;
  10935. case BL_NPC:
  10936. ((TBL_NPC *)bl)->vd->dead_sit = action;
  10937. break;
  10938. case BL_HOM:
  10939. ((TBL_HOM *)bl)->vd->dead_sit = action;
  10940. break;
  10941. case BL_PET:
  10942. ((TBL_PET *)bl)->vd.dead_sit = action;
  10943. break;
  10944. WBUFW(buf, 0) = 0x8a;
  10945. WBUFL(buf, 2) = bl->id;
  10946. WBUFB(buf,26) = (unsigned char)action;
  10947. clif_send(buf, 61, bl, AREA);
  10948. }
  10949. }else {
  10950. ShowError("buildin_unitdeadsit: Invalid action.\n");
  10951. report_src(st);
  10952. }
  10953. }else{
  10954. ShowError("buildin_unitdeadsit: Target is not found.\n");
  10955. report_src(st);
  10956. }
  10957. return 0;
  10958. }
  10959. int buildin_unitskilluseid (struct script_state *st)
  10960. {
  10961. int id,skid,sklv;
  10962. struct block_list *bl = NULL;
  10963. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10964. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10965. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10966. if ((bl = map_id2bl(id)))
  10967. unit_skilluse_id(bl,(st->end>st->start+5)?conv_num(st,& (st->stack->stack_data[st->start+5])):bl->id,skid,sklv);
  10968. return 0;
  10969. }
  10970. int buildin_unitskillusepos(struct script_state *st)
  10971. {
  10972. int skid,sklv,x,y,id;
  10973. struct block_list *bl = NULL;
  10974. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10975. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10976. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10977. x=conv_num(st,& (st->stack->stack_data[st->start+5]));
  10978. y=conv_num(st,& (st->stack->stack_data[st->start+6]));
  10979. if ((bl=map_id2bl(id)))
  10980. unit_skilluse_pos(bl,x,y,skid,sklv);
  10981. return 0;
  10982. }
  10983. // <--- [zBuffer] List of mob control commands
  10984. // sleep <mili sec>
  10985. int buildin_sleep(struct script_state *st) {
  10986. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10987. struct map_session_data *sd = map_id2sd(st->rid);
  10988. if(sd && sd->npc_id == st->oid) {
  10989. sd->npc_id = 0;
  10990. }
  10991. st->rid = 0;
  10992. if(tick <= 0) {
  10993. // 何もしない
  10994. } else if( !st->sleep.tick ) {
  10995. // 初回実行
  10996. st->state = RERUNLINE;
  10997. st->sleep.tick = tick;
  10998. } else {
  10999. // 続行
  11000. st->sleep.tick = 0;
  11001. }
  11002. return 0;
  11003. }
  11004. // sleep2 <mili sec>
  11005. int buildin_sleep2(struct script_state *st) {
  11006. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11007. if( tick <= 0 ) {
  11008. // 0ms の待機時間を指定された
  11009. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  11010. } else if( !st->sleep.tick ) {
  11011. // 初回実行時
  11012. st->state = RERUNLINE;
  11013. st->sleep.tick = tick;
  11014. } else {
  11015. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  11016. st->sleep.tick = 0;
  11017. }
  11018. return 0;
  11019. }
  11020. /*==========================================
  11021. * 指定NPCの全てのsleepを再開する
  11022. *------------------------------------------
  11023. */
  11024. int buildin_awake(struct script_state *st)
  11025. {
  11026. struct npc_data *nd;
  11027. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  11028. nd = npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  11029. if(nd == NULL)
  11030. return 0;
  11031. while( node ) {
  11032. if( (int)node->key == nd->bl.id) {
  11033. struct script_state *tst = node->data;
  11034. struct map_session_data *sd = map_id2sd(tst->rid);
  11035. if( tst->sleep.timer == -1 ) {
  11036. node = node->next;
  11037. continue;
  11038. }
  11039. if((sd && sd->char_id != tst->sleep.charid) || (tst->rid && !sd))
  11040. { //Cancel Execution
  11041. tst->state=END;
  11042. tst->rid = 0;
  11043. }
  11044. delete_timer(tst->sleep.timer, run_script_timer);
  11045. node = script_erase_sleepdb(node);
  11046. tst->sleep.timer = -1;
  11047. tst->sleep.tick = 0;
  11048. run_script_main(tst);
  11049. } else {
  11050. node = node->next;
  11051. }
  11052. }
  11053. return 0;
  11054. }
  11055. // getvariableofnpc(<param>, <npc name>);
  11056. int buildin_getvariableofnpc(struct script_state *st)
  11057. {
  11058. if( st->stack->stack_data[st->start+2].type != C_NAME ) {
  11059. // 第一引数が変数名じゃない
  11060. printf("getvariableofnpc: param not name\n");
  11061. push_val(st->stack,C_INT,0);
  11062. } else {
  11063. int num = st->stack->stack_data[st->start+2].u.num;
  11064. char *var_name = str_buf+str_data[num&0x00ffffff].str;
  11065. char *npc_name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  11066. struct npc_data *nd = npc_name2id(npc_name);
  11067. if( var_name[0] != '.' || var_name[1] == '@' ) {
  11068. // ' 変数以外はダメ
  11069. printf("getvariableofnpc: invalid scope %s\n", var_name);
  11070. push_val(st->stack,C_INT,0);
  11071. } else if( nd == NULL || nd->bl.subtype != SCRIPT || !nd->u.scr.script) {
  11072. // NPC が見つからない or SCRIPT以外のNPC
  11073. printf("getvariableofnpc: can't find npc %s\n", npc_name);
  11074. push_val(st->stack,C_INT,0);
  11075. } else {
  11076. push_val2(st->stack,C_NAME,num, &nd->u.scr.script->script_vars );
  11077. }
  11078. }
  11079. return 0;
  11080. }
  11081. // [blackhole89] --->
  11082. // Set a warp portal.
  11083. int buildin_warpportal(struct script_state *st){
  11084. struct skill_unit_group *group;
  11085. unsigned short mapindex;
  11086. long spx,spy,tpx,tpy;
  11087. struct block_list *bl=map_id2bl(st->oid);
  11088. nullpo_retr(0,bl);
  11089. spx=conv_num(st, & (st->stack->stack_data[st->start+2]));
  11090. spy=conv_num(st, & (st->stack->stack_data[st->start+3]));
  11091. mapindex = mapindex_name2id((char*)conv_str(st,& (st->stack->stack_data[st->start+4])));
  11092. printf("mapindex: %d\n",mapindex);
  11093. tpx=conv_num(st, & (st->stack->stack_data[st->start+5]));
  11094. tpy=conv_num(st, & (st->stack->stack_data[st->start+6]));
  11095. if(!mapindex) return 0;
  11096. if((group=skill_unitsetting(bl,AL_WARP,4,spx,spy,1))==NULL) {
  11097. return 0;
  11098. }
  11099. group->val2=(tpx<<16)|tpy;
  11100. group->val3 = mapindex;
  11101. return 0;
  11102. }
  11103. // <-- [blackhole89]