script.c 333 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268
  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. #ifndef _WIN32
  12. #include <sys/time.h>
  13. #endif
  14. #include <time.h>
  15. #include "../common/socket.h"
  16. #include "../common/timer.h"
  17. #include "../common/malloc.h"
  18. #include "../common/lock.h"
  19. #include "../common/nullpo.h"
  20. #include "../common/showmsg.h"
  21. #include "../common/strlib.h"
  22. #include "map.h"
  23. #include "clif.h"
  24. #include "chrif.h"
  25. #include "itemdb.h"
  26. #include "pc.h"
  27. #include "status.h"
  28. #include "script.h"
  29. #include "storage.h"
  30. #include "mob.h"
  31. #include "npc.h"
  32. #include "pet.h"
  33. #include "mercenary.h" //[orn]
  34. #include "intif.h"
  35. #include "skill.h"
  36. #include "chat.h"
  37. #include "battle.h"
  38. #include "party.h"
  39. #include "guild.h"
  40. #include "atcommand.h"
  41. #include "charcommand.h"
  42. #include "log.h"
  43. #include "unit.h"
  44. #include "irc.h"
  45. #include "pet.h"
  46. #define SCRIPT_BLOCK_SIZE 256
  47. #define FETCH(n, t) \
  48. if(st->end>st->start+(n)) \
  49. (t)=conv_num(st,&(st->stack->stack_data[st->start+(n)]));
  50. enum { LABEL_NEXTLINE=1,LABEL_START };
  51. static unsigned char * script_buf = NULL;
  52. static int script_pos,script_size;
  53. char *str_buf;
  54. int str_pos,str_size;
  55. static struct str_data_struct {
  56. int type;
  57. int str;
  58. int backpatch;
  59. int label;
  60. int (*func)(struct script_state *);
  61. int val;
  62. int next;
  63. } *str_data = NULL;
  64. int str_num=LABEL_START,str_data_size;
  65. int str_hash[16];
  66. static struct dbt *mapreg_db=NULL;
  67. static struct dbt *mapregstr_db=NULL;
  68. static int mapreg_dirty=-1;
  69. char mapreg_txt[256]="save/mapreg.txt";
  70. #define MAPREG_AUTOSAVE_INTERVAL (10*1000)
  71. static struct dbt *scriptlabel_db=NULL;
  72. static struct dbt *userfunc_db=NULL;
  73. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  74. struct dbt* script_get_userfunc_db(){ return userfunc_db; }
  75. static char pos[11][100] = {"頭","体","左手","右手","ローブ","靴","アクセサリー1","アクセサリー2","頭2","頭3","装着していない"};
  76. struct Script_Config script_config;
  77. static int parse_cmd;
  78. // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
  79. // [Eoe / jA 1080, 1081, 1094, 1164]
  80. enum { TYPE_NULL = 0 , TYPE_IF , TYPE_SWITCH , TYPE_WHILE , TYPE_FOR , TYPE_DO , TYPE_USERFUNC};
  81. static struct {
  82. struct {
  83. int type;
  84. int index;
  85. int count;
  86. int flag;
  87. } curly[256]; // 右カッコの情報
  88. int curly_count; // 右カッコの数
  89. int index; // スクリプト内で使用した構文の数
  90. } syntax;
  91. unsigned char* parse_curly_close(unsigned char *p);
  92. unsigned char* parse_syntax_close(unsigned char *p);
  93. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag);
  94. unsigned char* parse_syntax(unsigned char *p);
  95. static int parse_syntax_for_flag = 0;
  96. extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
  97. int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
  98. int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
  99. int potion_target=0;
  100. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  101. // [zBuffer] SQL Mapreg Saving/Loading Database Declaration
  102. char mapregsql_db[32] = "mapreg";
  103. char mapregsql_db_varname[32] = "varname";
  104. char mapregsql_db_index[32] = "index";
  105. char mapregsql_db_value[32] = "value";
  106. char tmp_sql[65535];
  107. // --------------------------------------------------------
  108. #endif
  109. static struct linkdb_node *sleep_db;
  110. #define not_server_variable(prefix) (prefix != '$' && prefix != '.')
  111. /*==========================================
  112. * ローカルプロトタイプ宣言 (必要な物のみ)
  113. *------------------------------------------
  114. */
  115. unsigned char* parse_subexpr(unsigned char *,int);
  116. #ifndef TXT_ONLY
  117. int buildin_query_sql(struct script_state *st);
  118. int buildin_escape_sql(struct script_state *st);
  119. #endif
  120. int buildin_atoi(struct script_state *st);
  121. int buildin_axtoi(struct script_state *st);
  122. int buildin_mes(struct script_state *st);
  123. int buildin_goto(struct script_state *st);
  124. int buildin_callsub(struct script_state *st);
  125. int buildin_callfunc(struct script_state *st);
  126. int buildin_return(struct script_state *st);
  127. int buildin_getarg(struct script_state *st);
  128. int buildin_next(struct script_state *st);
  129. int buildin_close(struct script_state *st);
  130. int buildin_close2(struct script_state *st);
  131. int buildin_menu(struct script_state *st);
  132. int buildin_rand(struct script_state *st);
  133. int buildin_warp(struct script_state *st);
  134. int buildin_areawarp(struct script_state *st);
  135. int buildin_warpchar(struct script_state *st); // [LuzZza]
  136. int buildin_warpparty(struct script_state *st); //[Fredzilla]
  137. int buildin_warpguild(struct script_state *st); //[Fredzilla]
  138. int buildin_heal(struct script_state *st);
  139. int buildin_itemheal(struct script_state *st);
  140. int buildin_percentheal(struct script_state *st);
  141. int buildin_jobchange(struct script_state *st);
  142. int buildin_input(struct script_state *st);
  143. int buildin_setlook(struct script_state *st);
  144. int buildin_set(struct script_state *st);
  145. int buildin_setarray(struct script_state *st);
  146. int buildin_cleararray(struct script_state *st);
  147. int buildin_copyarray(struct script_state *st);
  148. int buildin_getarraysize(struct script_state *st);
  149. int buildin_deletearray(struct script_state *st);
  150. int buildin_getelementofarray(struct script_state *st);
  151. int buildin_getitem(struct script_state *st);
  152. int buildin_getitem2(struct script_state *st);
  153. int buildin_getnameditem(struct script_state *st);
  154. int buildin_grouprandomitem(struct script_state *st);
  155. int buildin_makeitem(struct script_state *st);
  156. int buildin_delitem(struct script_state *st);
  157. int buildin_delitem2(struct script_state *st);
  158. int buildin_enableitemuse(struct script_state *st);
  159. int buildin_disableitemuse(struct script_state *st);
  160. int buildin_viewpoint(struct script_state *st);
  161. int buildin_countitem(struct script_state *st);
  162. int buildin_countitem2(struct script_state *st);
  163. int buildin_checkweight(struct script_state *st);
  164. int buildin_readparam(struct script_state *st);
  165. int buildin_getcharid(struct script_state *st);
  166. int buildin_getpartyname(struct script_state *st);
  167. int buildin_getpartymember(struct script_state *st);
  168. int buildin_getguildname(struct script_state *st);
  169. int buildin_getguildmaster(struct script_state *st);
  170. int buildin_getguildmasterid(struct script_state *st);
  171. int buildin_strcharinfo(struct script_state *st);
  172. int buildin_getequipid(struct script_state *st);
  173. int buildin_getequipname(struct script_state *st);
  174. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  175. int buildin_repair(struct script_state *st); // [Valaris]
  176. int buildin_getequipisequiped(struct script_state *st);
  177. int buildin_getequipisenableref(struct script_state *st);
  178. int buildin_getequipisidentify(struct script_state *st);
  179. int buildin_getequiprefinerycnt(struct script_state *st);
  180. int buildin_getequipweaponlv(struct script_state *st);
  181. int buildin_getequippercentrefinery(struct script_state *st);
  182. int buildin_successrefitem(struct script_state *st);
  183. int buildin_failedrefitem(struct script_state *st);
  184. int buildin_cutin(struct script_state *st);
  185. int buildin_cutincard(struct script_state *st);
  186. int buildin_statusup(struct script_state *st);
  187. int buildin_statusup2(struct script_state *st);
  188. int buildin_bonus(struct script_state *st);
  189. int buildin_bonus2(struct script_state *st);
  190. int buildin_bonus3(struct script_state *st);
  191. int buildin_bonus4(struct script_state *st);
  192. int buildin_skill(struct script_state *st);
  193. int buildin_addtoskill(struct script_state *st); // [Valaris]
  194. int buildin_guildskill(struct script_state *st);
  195. int buildin_getskilllv(struct script_state *st);
  196. int buildin_getgdskilllv(struct script_state *st);
  197. int buildin_basicskillcheck(struct script_state *st);
  198. int buildin_getgmlevel(struct script_state *st);
  199. int buildin_end(struct script_state *st);
  200. int buildin_checkoption(struct script_state *st);
  201. int buildin_setoption(struct script_state *st);
  202. int buildin_setcart(struct script_state *st);
  203. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  204. int buildin_setfalcon(struct script_state *st);
  205. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  206. int buildin_setriding(struct script_state *st);
  207. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  208. int buildin_savepoint(struct script_state *st);
  209. int buildin_gettimetick(struct script_state *st);
  210. int buildin_gettime(struct script_state *st);
  211. int buildin_gettimestr(struct script_state *st);
  212. int buildin_openstorage(struct script_state *st);
  213. int buildin_guildopenstorage(struct script_state *st);
  214. int buildin_itemskill(struct script_state *st);
  215. int buildin_produce(struct script_state *st);
  216. int buildin_monster(struct script_state *st);
  217. int buildin_areamonster(struct script_state *st);
  218. int buildin_killmonster(struct script_state *st);
  219. int buildin_killmonsterall(struct script_state *st);
  220. int buildin_clone(struct script_state *st);
  221. int buildin_doevent(struct script_state *st);
  222. int buildin_donpcevent(struct script_state *st);
  223. int buildin_addtimer(struct script_state *st);
  224. int buildin_deltimer(struct script_state *st);
  225. int buildin_addtimercount(struct script_state *st);
  226. int buildin_initnpctimer(struct script_state *st);
  227. int buildin_stopnpctimer(struct script_state *st);
  228. int buildin_startnpctimer(struct script_state *st);
  229. int buildin_setnpctimer(struct script_state *st);
  230. int buildin_getnpctimer(struct script_state *st);
  231. int buildin_attachnpctimer(struct script_state *st); // [celest]
  232. int buildin_detachnpctimer(struct script_state *st); // [celest]
  233. int buildin_playerattached(struct script_state *st); // [Skotlex]
  234. int buildin_announce(struct script_state *st);
  235. int buildin_mapannounce(struct script_state *st);
  236. int buildin_areaannounce(struct script_state *st);
  237. int buildin_getusers(struct script_state *st);
  238. int buildin_getmapusers(struct script_state *st);
  239. int buildin_getareausers(struct script_state *st);
  240. int buildin_getareadropitem(struct script_state *st);
  241. int buildin_enablenpc(struct script_state *st);
  242. int buildin_disablenpc(struct script_state *st);
  243. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  244. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  245. int buildin_hideoffnpc(struct script_state *st);
  246. int buildin_hideonnpc(struct script_state *st);
  247. int buildin_sc_start(struct script_state *st);
  248. int buildin_sc_start2(struct script_state *st);
  249. int buildin_sc_start4(struct script_state *st);
  250. int buildin_sc_end(struct script_state *st);
  251. int buildin_getscrate(struct script_state *st);
  252. int buildin_debugmes(struct script_state *st);
  253. int buildin_catchpet(struct script_state *st);
  254. int buildin_birthpet(struct script_state *st);
  255. int buildin_resetlvl(struct script_state *st);
  256. int buildin_resetstatus(struct script_state *st);
  257. int buildin_resetskill(struct script_state *st);
  258. int buildin_skillpointcount(struct script_state *st);
  259. int buildin_changebase(struct script_state *st);
  260. int buildin_changesex(struct script_state *st);
  261. int buildin_waitingroom(struct script_state *st);
  262. int buildin_delwaitingroom(struct script_state *st);
  263. int buildin_enablewaitingroomevent(struct script_state *st);
  264. int buildin_disablewaitingroomevent(struct script_state *st);
  265. int buildin_getwaitingroomstate(struct script_state *st);
  266. int buildin_warpwaitingpc(struct script_state *st);
  267. int buildin_attachrid(struct script_state *st);
  268. int buildin_detachrid(struct script_state *st);
  269. int buildin_isloggedin(struct script_state *st);
  270. int buildin_setmapflagnosave(struct script_state *st);
  271. int buildin_setmapflag(struct script_state *st);
  272. int buildin_removemapflag(struct script_state *st);
  273. int buildin_pvpon(struct script_state *st);
  274. int buildin_pvpoff(struct script_state *st);
  275. int buildin_gvgon(struct script_state *st);
  276. int buildin_gvgoff(struct script_state *st);
  277. int buildin_emotion(struct script_state *st);
  278. int buildin_maprespawnguildid(struct script_state *st);
  279. int buildin_agitstart(struct script_state *st); // <Agit>
  280. int buildin_agitend(struct script_state *st);
  281. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  282. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  283. int buildin_getcastlename(struct script_state *st);
  284. int buildin_getcastledata(struct script_state *st);
  285. int buildin_setcastledata(struct script_state *st);
  286. int buildin_requestguildinfo(struct script_state *st);
  287. int buildin_getequipcardcnt(struct script_state *st);
  288. int buildin_successremovecards(struct script_state *st);
  289. int buildin_failedremovecards(struct script_state *st);
  290. int buildin_marriage(struct script_state *st);
  291. int buildin_wedding_effect(struct script_state *st);
  292. int buildin_divorce(struct script_state *st);
  293. int buildin_ispartneron(struct script_state *st); // MouseJstr
  294. int buildin_getpartnerid(struct script_state *st); // MouseJstr
  295. int buildin_getchildid(struct script_state *st); // Skotlex
  296. int buildin_getmotherid(struct script_state *st); // Lupus
  297. int buildin_getfatherid(struct script_state *st); // Lupus
  298. int buildin_warppartner(struct script_state *st); // MouseJstr
  299. int buildin_getitemname(struct script_state *st);
  300. int buildin_getitemslots(struct script_state *st);
  301. int buildin_makepet(struct script_state *st);
  302. int buildin_getexp(struct script_state *st);
  303. int buildin_getinventorylist(struct script_state *st);
  304. int buildin_getskilllist(struct script_state *st);
  305. int buildin_clearitem(struct script_state *st);
  306. int buildin_classchange(struct script_state *st);
  307. int buildin_misceffect(struct script_state *st);
  308. int buildin_soundeffect(struct script_state *st);
  309. int buildin_soundeffectall(struct script_state *st);
  310. int buildin_setcastledata(struct script_state *st);
  311. int buildin_mapwarp(struct script_state *st);
  312. int buildin_inittimer(struct script_state *st);
  313. int buildin_stoptimer(struct script_state *st);
  314. int buildin_cmdothernpc(struct script_state *st);
  315. int buildin_mobcount(struct script_state *st);
  316. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  317. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  318. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  319. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  320. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  321. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  322. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  323. //int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  324. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Skotlex]
  325. int buildin_petskillattack2(struct script_state *st); // pet skill attacks [Skotlex]
  326. int buildin_petskillsupport(struct script_state *st); // pet support skill [Valaris]
  327. int buildin_skilleffect(struct script_state *st); // skill effects [Celest]
  328. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  329. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  330. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  331. int buildin_nude(struct script_state *st); // nude [Valaris]
  332. int buildin_atcommand(struct script_state *st); // [MouseJstr]
  333. int buildin_charcommand(struct script_state *st); // [MouseJstr]
  334. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  335. int buildin_message(struct script_state *st); // [MouseJstr]
  336. int buildin_npctalk(struct script_state *st); // [Valaris]
  337. int buildin_hasitems(struct script_state *st); // [Valaris]
  338. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  339. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  340. int buildin_npcspeed(struct script_state *st); // [Valaris]
  341. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  342. int buildin_npcstop(struct script_state *st); // [Valaris]
  343. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  344. int buildin_checkoption1(struct script_state *st); // [celest]
  345. int buildin_checkoption2(struct script_state *st); // [celest]
  346. int buildin_guildgetexp(struct script_state *st); // [celest]
  347. int buildin_guildchangegm(struct script_state *st); // [Skotlex]
  348. int buildin_logmes(struct script_state *st); // [Lupus]
  349. int buildin_summon(struct script_state *st); // [celest]
  350. int buildin_isnight(struct script_state *st); // [celest]
  351. int buildin_isday(struct script_state *st); // [celest]
  352. int buildin_isequipped(struct script_state *st); // [celest]
  353. int buildin_isequippedcnt(struct script_state *st); // [celest]
  354. int buildin_cardscnt(struct script_state *st); // [Lupus]
  355. int buildin_getrefine(struct script_state *st); // [celest]
  356. int buildin_adopt(struct script_state *st);
  357. int buildin_night(struct script_state *st);
  358. int buildin_day(struct script_state *st);
  359. int buildin_getusersname(struct script_state *st); //jA commands added [Lupus]
  360. int buildin_dispbottom(struct script_state *st);
  361. int buildin_recovery(struct script_state *st);
  362. int buildin_getpetinfo(struct script_state *st);
  363. int buildin_checkequipedcard(struct script_state *st);
  364. int buildin_globalmes(struct script_state *st);
  365. int buildin_jump_zero(struct script_state *st);
  366. int buildin_select(struct script_state *st);
  367. int buildin_getmapmobs(struct script_state *st); //jA addition end
  368. int buildin_unequip(struct script_state *st); // unequip [Spectre]
  369. int buildin_getstrlen(struct script_state *st); //strlen [valaris]
  370. int buildin_charisalpha(struct script_state *st);//isalpha [valaris]
  371. int buildin_fakenpcname(struct script_state *st); // [Lance]
  372. int buildin_compare(struct script_state *st); // Lordalfa, to bring strstr to Scripting Engine
  373. int buildin_getiteminfo(struct script_state *st); //[Lupus] returns Items Buy / sell Price, etc info
  374. int buildin_getequipcardid(struct script_state *st); //[Lupus] returns card id from quipped item card slot N
  375. // [zBuffer] List of mathematics commands --->
  376. int buildin_sqrt(struct script_state *st);
  377. int buildin_pow(struct script_state *st);
  378. int buildin_distance(struct script_state *st);
  379. int buildin_checkcell(struct script_state *st);
  380. // <--- [zBuffer] List of mathematics commands
  381. // [zBuffer] List of dynamic var commands --->
  382. int buildin_getd(struct script_state *st);
  383. int buildin_setd(struct script_state *st);
  384. // <--- [zBuffer] List of dynamic var commands
  385. int buildin_petstat(struct script_state *st); // [Lance] Pet Stat Rq: Dubby
  386. int buildin_callshop(struct script_state *st); // [Skotlex]
  387. int buildin_npcshopitem(struct script_state *st); // [Lance]
  388. int buildin_npcshopadditem(struct script_state *st);
  389. int buildin_npcshopdelitem(struct script_state *st);
  390. int buildin_equip(struct script_state *st);
  391. int buildin_autoequip(struct script_state *st);
  392. int buildin_setbattleflag(struct script_state *st);
  393. int buildin_getbattleflag(struct script_state *st);
  394. // [zBuffer] List of player cont commands --->
  395. int buildin_rid2name(struct script_state *st);
  396. int buildin_pcfollow(struct script_state *st);
  397. int buildin_pcstopfollow(struct script_state *st);
  398. int buildin_pcblockmove(struct script_state *st);
  399. // <--- [zBuffer] List of player cont commands
  400. // [zBuffer] List of mob control commands --->
  401. int buildin_mobspawn(struct script_state *st);
  402. int buildin_mobremove(struct script_state *st);
  403. int buildin_getmobdata(struct script_state *st);
  404. int buildin_setmobdata(struct script_state *st);
  405. int buildin_mobassist(struct script_state *st);
  406. int buildin_mobattach(struct script_state *st);
  407. int buildin_unitwalk(struct script_state *st);
  408. int buildin_unitkill(struct script_state *st);
  409. int buildin_unitwarp(struct script_state *st);
  410. int buildin_unitattack(struct script_state *st);
  411. int buildin_unitstop(struct script_state *st);
  412. int buildin_unittalk(struct script_state *st);
  413. int buildin_unitemote(struct script_state *st);
  414. int buildin_unitdeadsit(struct script_state *st);
  415. int buildin_unitskilluseid(struct script_state *st); // originally by Qamera [celest]
  416. int buildin_unitskillusepos(struct script_state *st); // originally by Qamera [celest]
  417. // <--- [zBuffer] List of mob control commands
  418. int buildin_sleep(struct script_state *st);
  419. int buildin_sleep2(struct script_state *st);
  420. int buildin_awake(struct script_state *st);
  421. int buildin_getvariableofnpc(struct script_state *st);
  422. // [blackhole89] -->
  423. int buildin_warpportal(struct script_state *st);
  424. // <-- [blackhole89]
  425. int buildin_homunculus_evolution(struct script_state *st) ; //[orn]
  426. void push_val(struct script_stack *stack,int type,int val);
  427. int run_func(struct script_state *st);
  428. int mapreg_setreg(int num,int val);
  429. int mapreg_setregstr(int num,const char *str);
  430. int buildin_setitemscript(struct script_state *st);
  431. int buildin_disguise(struct script_state *st);
  432. int buildin_undisguise(struct script_state *st);
  433. int buildin_getmonsterinfo(struct script_state *st); // [Lupus]
  434. #ifdef PCRE_SUPPORT
  435. int buildin_defpattern(struct script_state *st); // MouseJstr
  436. int buildin_activatepset(struct script_state *st); // MouseJstr
  437. int buildin_deactivatepset(struct script_state *st); // MouseJstr
  438. int buildin_deletepset(struct script_state *st); // MouseJstr
  439. #endif
  440. struct {
  441. int (*func)(struct script_state *);
  442. char *name;
  443. char *arg;
  444. } buildin_func[]={
  445. {buildin_axtoi,"axtoi","s"},
  446. #ifndef TXT_ONLY
  447. {buildin_query_sql, "query_sql", "s*"},
  448. {buildin_escape_sql, "escape_sql", "s"},
  449. #endif
  450. {buildin_atoi,"atoi","s"},
  451. {buildin_mes,"mes","s"},
  452. {buildin_next,"next",""},
  453. {buildin_close,"close",""},
  454. {buildin_close2,"close2",""},
  455. {buildin_menu,"menu","*"},
  456. {buildin_goto,"goto","l"},
  457. {buildin_callsub,"callsub","i*"},
  458. {buildin_callfunc,"callfunc","s*"},
  459. {buildin_return,"return","*"},
  460. {buildin_getarg,"getarg","i"},
  461. {buildin_jobchange,"jobchange","i*"},
  462. {buildin_input,"input","*"},
  463. {buildin_warp,"warp","sii"},
  464. {buildin_areawarp,"areawarp","siiiisii"},
  465. {buildin_warpchar,"warpchar","siii"}, // [LuzZza]
  466. {buildin_warpparty,"warpparty","siii"}, // [Fredzilla]
  467. {buildin_warpguild,"warpguild","siii"}, // [Fredzilla]
  468. {buildin_setlook,"setlook","ii"},
  469. {buildin_set,"set","ii"},
  470. {buildin_setarray,"setarray","ii*"},
  471. {buildin_cleararray,"cleararray","iii"},
  472. {buildin_copyarray,"copyarray","iii"},
  473. {buildin_getarraysize,"getarraysize","i"},
  474. {buildin_deletearray,"deletearray","ii"},
  475. {buildin_getelementofarray,"getelementofarray","ii"},
  476. {buildin_getitem,"getitem","ii**"},
  477. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  478. {buildin_getnameditem,"getnameditem","is"},
  479. {buildin_grouprandomitem,"groupranditem","i"},
  480. {buildin_makeitem,"makeitem","iisii"},
  481. {buildin_delitem,"delitem","ii"},
  482. {buildin_delitem2,"delitem2","iiiiiiiii"},
  483. {buildin_enableitemuse,"enable_items",""},
  484. {buildin_disableitemuse,"disable_items",""},
  485. {buildin_cutin,"cutin","si"},
  486. {buildin_cutincard,"cutincard","i"},
  487. {buildin_viewpoint,"viewpoint","iiiii"},
  488. {buildin_heal,"heal","ii"},
  489. {buildin_itemheal,"itemheal","ii"},
  490. {buildin_percentheal,"percentheal","ii"},
  491. {buildin_rand,"rand","i*"},
  492. {buildin_countitem,"countitem","i"},
  493. {buildin_countitem2,"countitem2","iiiiiiii"},
  494. {buildin_checkweight,"checkweight","ii"},
  495. {buildin_readparam,"readparam","i*"},
  496. {buildin_getcharid,"getcharid","i*"},
  497. {buildin_getpartyname,"getpartyname","i"},
  498. {buildin_getpartymember,"getpartymember","i*"},
  499. {buildin_getguildname,"getguildname","i"},
  500. {buildin_getguildmaster,"getguildmaster","i"},
  501. {buildin_getguildmasterid,"getguildmasterid","i"},
  502. {buildin_strcharinfo,"strcharinfo","i"},
  503. {buildin_getequipid,"getequipid","i"},
  504. {buildin_getequipname,"getequipname","i"},
  505. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  506. {buildin_repair,"repair","i"}, // [Valaris]
  507. {buildin_getequipisequiped,"getequipisequiped","i"},
  508. {buildin_getequipisenableref,"getequipisenableref","i"},
  509. {buildin_getequipisidentify,"getequipisidentify","i"},
  510. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  511. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  512. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  513. {buildin_successrefitem,"successrefitem","i"},
  514. {buildin_failedrefitem,"failedrefitem","i"},
  515. {buildin_statusup,"statusup","i"},
  516. {buildin_statusup2,"statusup2","ii"},
  517. {buildin_bonus,"bonus","ii"},
  518. {buildin_bonus2,"bonus2","iii"},
  519. {buildin_bonus3,"bonus3","iiii"},
  520. {buildin_bonus4,"bonus4","iiiii"},
  521. {buildin_skill,"skill","ii*"},
  522. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  523. {buildin_guildskill,"guildskill","ii"},
  524. {buildin_getskilllv,"getskilllv","i"},
  525. {buildin_getgdskilllv,"getgdskilllv","ii"},
  526. {buildin_basicskillcheck,"basicskillcheck","*"},
  527. {buildin_getgmlevel,"getgmlevel","*"},
  528. {buildin_end,"end",""},
  529. // {buildin_end,"break",""}, this might confuse advanced scripting support [Eoe]
  530. {buildin_checkoption,"checkoption","i"},
  531. {buildin_setoption,"setoption","i*"},
  532. {buildin_setcart,"setcart",""},
  533. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  534. {buildin_setfalcon,"setfalcon",""},
  535. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  536. {buildin_setriding,"setriding",""},
  537. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  538. {buildin_savepoint,"save","sii"},
  539. {buildin_savepoint,"savepoint","sii"},
  540. {buildin_gettimetick,"gettimetick","i"},
  541. {buildin_gettime,"gettime","i"},
  542. {buildin_gettimestr,"gettimestr","si"},
  543. {buildin_openstorage,"openstorage",""},
  544. {buildin_guildopenstorage,"guildopenstorage","*"},
  545. {buildin_itemskill,"itemskill","iis"},
  546. {buildin_produce,"produce","i"},
  547. {buildin_monster,"monster","siisii*"},
  548. {buildin_areamonster,"areamonster","siiiisii*"},
  549. {buildin_killmonster,"killmonster","ss"},
  550. {buildin_killmonsterall,"killmonsterall","s"},
  551. {buildin_clone,"clone","siisi*"},
  552. {buildin_doevent,"doevent","s"},
  553. {buildin_donpcevent,"donpcevent","s"},
  554. {buildin_addtimer,"addtimer","is"},
  555. {buildin_deltimer,"deltimer","s"},
  556. {buildin_addtimercount,"addtimercount","si"},
  557. {buildin_initnpctimer,"initnpctimer","*"},
  558. {buildin_stopnpctimer,"stopnpctimer","*"},
  559. {buildin_startnpctimer,"startnpctimer","*"},
  560. {buildin_setnpctimer,"setnpctimer","*"},
  561. {buildin_getnpctimer,"getnpctimer","i*"},
  562. {buildin_attachnpctimer,"attachnpctimer","*"}, // attached the player id to the npc timer [Celest]
  563. {buildin_detachnpctimer,"detachnpctimer","*"}, // detached the player id from the npc timer [Celest]
  564. {buildin_playerattached,"playerattached",""}, // returns id of the current attached player. [Skotlex]
  565. {buildin_announce,"announce","si*"},
  566. {buildin_mapannounce,"mapannounce","ssi*"},
  567. {buildin_areaannounce,"areaannounce","siiiisi*"},
  568. {buildin_getusers,"getusers","i"},
  569. {buildin_getmapusers,"getmapusers","s"},
  570. {buildin_getareausers,"getareausers","siiii"},
  571. {buildin_getareadropitem,"getareadropitem","siiiii"},
  572. {buildin_enablenpc,"enablenpc","s"},
  573. {buildin_disablenpc,"disablenpc","s"},
  574. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  575. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  576. {buildin_hideoffnpc,"hideoffnpc","s"},
  577. {buildin_hideonnpc,"hideonnpc","s"},
  578. {buildin_sc_start,"sc_start","iii*"},
  579. {buildin_sc_start2,"sc_start2","iiii*"},
  580. {buildin_sc_start4,"sc_start4","iiiiii*"},
  581. {buildin_sc_end,"sc_end","i"},
  582. {buildin_getscrate,"getscrate","ii*"},
  583. {buildin_debugmes,"debugmes","s"},
  584. {buildin_catchpet,"pet","i"},
  585. {buildin_birthpet,"bpet",""},
  586. {buildin_resetlvl,"resetlvl","i"},
  587. {buildin_resetstatus,"resetstatus",""},
  588. {buildin_resetskill,"resetskill",""},
  589. {buildin_skillpointcount,"skillpointcount",""},
  590. {buildin_changebase,"changebase","i"},
  591. {buildin_changesex,"changesex",""},
  592. {buildin_waitingroom,"waitingroom","si*"},
  593. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  594. {buildin_delwaitingroom,"delwaitingroom","*"},
  595. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  596. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  597. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  598. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  599. {buildin_attachrid,"attachrid","i"},
  600. {buildin_detachrid,"detachrid",""},
  601. {buildin_isloggedin,"isloggedin","i"},
  602. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  603. {buildin_setmapflag,"setmapflag","si*"},
  604. {buildin_removemapflag,"removemapflag","si"},
  605. {buildin_pvpon,"pvpon","s"},
  606. {buildin_pvpoff,"pvpoff","s"},
  607. {buildin_gvgon,"gvgon","s"},
  608. {buildin_gvgoff,"gvgoff","s"},
  609. {buildin_emotion,"emotion","i*"},
  610. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  611. {buildin_agitstart,"agitstart",""}, // <Agit>
  612. {buildin_agitend,"agitend",""},
  613. {buildin_agitcheck,"agitcheck","i"}, // <Agitcheck>
  614. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  615. {buildin_getcastlename,"getcastlename","s"},
  616. {buildin_getcastledata,"getcastledata","si*"},
  617. {buildin_setcastledata,"setcastledata","sii"},
  618. {buildin_requestguildinfo,"requestguildinfo","i*"},
  619. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  620. {buildin_successremovecards,"successremovecards","i"},
  621. {buildin_failedremovecards,"failedremovecards","ii"},
  622. {buildin_marriage,"marriage","s"},
  623. {buildin_wedding_effect,"wedding",""},
  624. {buildin_divorce,"divorce",""},
  625. {buildin_ispartneron,"ispartneron",""},
  626. {buildin_getpartnerid,"getpartnerid",""},
  627. {buildin_getchildid,"getchildid",""},
  628. {buildin_getmotherid,"getmotherid",""},
  629. {buildin_getfatherid,"getfatherid",""},
  630. {buildin_warppartner,"warppartner","sii"},
  631. {buildin_getitemname,"getitemname","i"},
  632. {buildin_getitemslots,"getitemslots","i"},
  633. {buildin_makepet,"makepet","i"},
  634. {buildin_getexp,"getexp","ii"},
  635. {buildin_getinventorylist,"getinventorylist",""},
  636. {buildin_getskilllist,"getskilllist",""},
  637. {buildin_clearitem,"clearitem",""},
  638. {buildin_classchange,"classchange","ii"},
  639. {buildin_misceffect,"misceffect","i"},
  640. {buildin_soundeffect,"soundeffect","si"},
  641. {buildin_soundeffectall,"soundeffectall","si*"}, // SoundEffectAll [Codemaster]
  642. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  643. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  644. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  645. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  646. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  647. {buildin_petloot,"petloot","i"}, // [Valaris]
  648. {buildin_petheal,"petheal","iiii"}, // [Valaris]
  649. // {buildin_petmag,"petmag","iiii"}, // [Valaris]
  650. {buildin_petskillattack,"petskillattack","iiii"}, // [Skotlex]
  651. {buildin_petskillattack2,"petskillattack2","iiiii"}, // [Valaris]
  652. {buildin_petskillsupport,"petskillsupport","iiiii"}, // [Skotlex]
  653. {buildin_skilleffect,"skilleffect","ii"}, // skill effect [Celest]
  654. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  655. {buildin_specialeffect,"specialeffect","i*"}, // npc skill effect [Valaris]
  656. {buildin_specialeffect2,"specialeffect2","i*"}, // skill effect on players[Valaris]
  657. {buildin_nude,"nude",""}, // nude command [Valaris]
  658. {buildin_mapwarp,"mapwarp","ssii"}, // Added by RoVeRT
  659. {buildin_inittimer,"inittimer",""},
  660. {buildin_stoptimer,"stoptimer",""},
  661. {buildin_cmdothernpc,"cmdothernpc","ss"},
  662. {buildin_atcommand,"atcommand","*"}, // [MouseJstr]
  663. {buildin_charcommand,"charcommand","*"}, // [MouseJstr]
  664. {buildin_movenpc,"movenpc","sii"}, // [MouseJstr]
  665. {buildin_message,"message","s*"}, // [MouseJstr]
  666. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  667. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  668. {buildin_mobcount,"mobcount","ss"},
  669. {buildin_getlook,"getlook","i"},
  670. {buildin_getsavepoint,"getsavepoint","i"},
  671. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  672. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  673. {buildin_npcstop,"npcstop",""}, // [Valaris]
  674. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  675. {buildin_checkoption1,"checkoption1","i"},
  676. {buildin_checkoption2,"checkoption2","i"},
  677. {buildin_guildgetexp,"guildgetexp","i"},
  678. {buildin_guildchangegm,"guildchangegm","is"},
  679. {buildin_logmes,"logmes","s"}, //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
  680. {buildin_summon,"summon","si*"}, // summons a slave monster [Celest]
  681. {buildin_isnight,"isnight",""}, // check whether it is night time [Celest]
  682. {buildin_isday,"isday",""}, // check whether it is day time [Celest]
  683. {buildin_isequipped,"isequipped","i*"}, // check whether another item/card has been equipped [Celest]
  684. {buildin_isequippedcnt,"isequippedcnt","i*"}, // check how many items/cards are being equipped [Celest]
  685. {buildin_cardscnt,"cardscnt","i*"}, // check how many items/cards are being equipped in the same arm [Lupus]
  686. {buildin_getrefine,"getrefine","*"}, // returns the refined number of the current item, or an item with index specified [celest]
  687. {buildin_adopt,"adopt","sss"}, // allows 2 parents to adopt a child
  688. {buildin_night,"night",""}, // sets the server to night time
  689. {buildin_day,"day",""}, // sets the server to day time
  690. #ifdef PCRE_SUPPORT
  691. {buildin_defpattern, "defpattern", "iss"}, // Define pattern to listen for [MouseJstr]
  692. {buildin_activatepset, "activatepset", "i"}, // Activate a pattern set [MouseJstr]
  693. {buildin_deactivatepset, "deactivatepset", "i"}, // Deactive a pattern set [MouseJstr]
  694. {buildin_deletepset, "deletepset", "i"}, // Delete a pattern set [MouseJstr]
  695. #endif
  696. {buildin_dispbottom,"dispbottom","s"}, //added from jA [Lupus]
  697. {buildin_getusersname,"getusersname","*"},
  698. {buildin_recovery,"recovery",""},
  699. {buildin_getpetinfo,"getpetinfo","i"},
  700. {buildin_checkequipedcard,"checkequipedcard","i"},
  701. {buildin_jump_zero,"jump_zero","ii"}, //for future jA script compatibility
  702. {buildin_select,"select","*"}, //for future jA script compatibility
  703. {buildin_globalmes,"globalmes","s*"},
  704. {buildin_getmapmobs,"getmapmobs","s"}, //end jA addition
  705. {buildin_unequip,"unequip","i"}, // unequip command [Spectre]
  706. {buildin_getstrlen,"getstrlen","s"}, //strlen [Valaris]
  707. {buildin_charisalpha,"charisalpha","si"}, //isalpha [Valaris]
  708. {buildin_fakenpcname,"fakenpcname","ssi"}, // [Lance]
  709. {buildin_compare,"compare","ss"}, // Lordalfa - To bring strstr to scripting Engine.
  710. {buildin_getiteminfo,"getiteminfo","ii"}, //[Lupus] returns Items Buy / sell Price, etc info
  711. {buildin_getequipcardid,"getequipcardid","ii"}, //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
  712. // [zBuffer] List of mathematics commands --->
  713. {buildin_sqrt,"sqrt","i"},
  714. {buildin_pow,"pow","ii"},
  715. {buildin_distance,"distance","iiii"},
  716. {buildin_checkcell,"checkcell","siii"},
  717. // <--- [zBuffer] List of mathematics commands
  718. // [zBuffer] List of dynamic var commands --->
  719. {buildin_getd,"getd","*"},
  720. {buildin_setd,"setd","*"},
  721. // <--- [zBuffer] List of dynamic var commands
  722. {buildin_petstat,"petstat","i"},
  723. {buildin_callshop,"callshop","si"}, // [Skotlex]
  724. {buildin_npcshopitem,"npcshopitem","sii*"}, // [Lance]
  725. {buildin_npcshopadditem,"npcshopadditem","sii*"},
  726. {buildin_npcshopdelitem,"npcshopdelitem","si*"},
  727. {buildin_equip,"equip","i"},
  728. {buildin_autoequip,"autoequip","ii"},
  729. {buildin_setbattleflag,"setbattleflag","ss"},
  730. {buildin_getbattleflag,"getbattleflag","s"},
  731. {buildin_setitemscript,"setitemscript","is"}, //Set NEW item bonus script. Lupus
  732. {buildin_disguise,"disguise","i"}, //disguise player. Lupus
  733. {buildin_undisguise,"undisguise","i"}, //undisguise player. Lupus
  734. {buildin_getmonsterinfo,"getmonsterinfo","ii"}, //Lupus
  735. // [zBuffer] List of player cont commands --->
  736. {buildin_rid2name,"rid2name","i"},
  737. {buildin_pcfollow,"pcfollow","ii"},
  738. {buildin_pcstopfollow,"pcstopfollow","i"},
  739. {buildin_pcblockmove,"pcblockmove","ii"},
  740. // <--- [zBuffer] List of player cont commands
  741. // [zBuffer] List of mob control commands --->
  742. {buildin_mobspawn,"mobspawn","*"},
  743. {buildin_mobremove,"mobremove","i"},
  744. {buildin_getmobdata,"getmobdata","i*"},
  745. {buildin_setmobdata,"setmobdata","iii"},
  746. {buildin_mobassist,"mobassist","i*"},
  747. {buildin_mobattach,"mobattach","i*"},
  748. {buildin_unitwalk,"unitwalk","i*"},
  749. {buildin_unitkill,"unitkill","i"},
  750. {buildin_unitwarp,"unitwarp","isii"},
  751. {buildin_unitattack,"unitattack","i*"},
  752. {buildin_unitstop,"unitstop","i"},
  753. {buildin_unittalk,"unittalk","is"},
  754. {buildin_unitemote,"unitemote","ii"},
  755. {buildin_unitdeadsit,"unitdeadsit","ii"},
  756. {buildin_unitskilluseid,"unitskilluseid","iii*"}, // originally by Qamera [Celest]
  757. {buildin_unitskillusepos,"unitskillusepos","iiiii"}, // [Celest]
  758. // <--- [zBuffer] List of mob control commands
  759. {buildin_sleep,"sleep","i"},
  760. {buildin_sleep2,"sleep2","i"},
  761. {buildin_awake,"awake","s"},
  762. {buildin_getvariableofnpc,"getvariableofnpc","is"},
  763. // [blackhole89] -->
  764. {buildin_warpportal,"warpportal","iisii"},
  765. // <--- [blackhole89]
  766. {buildin_homunculus_evolution,"homevolution",""}, //[orn]
  767. {NULL,NULL,NULL},
  768. };
  769. enum {
  770. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  771. C_NAME,C_EOL, C_RETINFO,
  772. C_USERFUNC, C_USERFUNC_POS, // user defined functions
  773. C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  774. 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
  775. };
  776. //Reports on the console the src of an script error.
  777. static void report_src(struct script_state *st) {
  778. struct block_list *bl;
  779. if (!st->oid) return; //Can't report source.
  780. bl = map_id2bl(st->oid);
  781. if (!bl) return;
  782. switch (bl->type) {
  783. case BL_NPC:
  784. if (bl->m >=0)
  785. ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
  786. else
  787. ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
  788. break;
  789. default:
  790. if (bl->m >=0)
  791. ShowDebug("Source (Non-NPC): type %d at %s (%d,%d)\n", bl->type, map[bl->m].name, bl->x, bl->y);
  792. else
  793. ShowDebug("Source (Non-NPC): type %d (invisible/not on a map)\n", bl->type);
  794. break;
  795. }
  796. }
  797. static void check_event(struct script_state *st, unsigned char *event){
  798. if(event != NULL && event[0] != '\0' && !strstr(event,"::")){
  799. ShowError("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n",event);
  800. report_src(st);
  801. }
  802. return;
  803. }
  804. /*==========================================
  805. * 文字列のハッシュを計算
  806. *------------------------------------------
  807. */
  808. static int calc_hash(const unsigned char *p)
  809. {
  810. int h=0;
  811. while(*p){
  812. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  813. h+=*p++;
  814. }
  815. return h&15;
  816. }
  817. /*==========================================
  818. * str_dataの中に名前があるか検索する
  819. *------------------------------------------
  820. */
  821. // 既存のであれば番号、無ければ-1
  822. static int search_str(const unsigned char *p)
  823. {
  824. int i;
  825. i=str_hash[calc_hash(p)];
  826. while(i){
  827. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  828. return i;
  829. }
  830. i=str_data[i].next;
  831. }
  832. return -1;
  833. }
  834. /*==========================================
  835. * str_dataに名前を登録
  836. *------------------------------------------
  837. */
  838. // 既存のであれば番号、無ければ登録して新規番号
  839. int add_str(const unsigned char *p)
  840. {
  841. int i;
  842. char *lowcase;
  843. lowcase=aStrdup((char *) p);
  844. for(i=0;lowcase[i];i++)
  845. lowcase[i]=tolower(lowcase[i]);
  846. if((i=search_str((unsigned char *) lowcase))>=0){
  847. aFree(lowcase);
  848. return i;
  849. }
  850. aFree(lowcase);
  851. i=calc_hash(p);
  852. if(str_hash[i]==0){
  853. str_hash[i]=str_num;
  854. } else {
  855. i=str_hash[i];
  856. for(;;){
  857. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  858. return i;
  859. }
  860. if(str_data[i].next==0)
  861. break;
  862. i=str_data[i].next;
  863. }
  864. str_data[i].next=str_num;
  865. }
  866. if(str_num>=str_data_size){
  867. str_data_size+=128;
  868. str_data=(struct str_data_struct *) aRealloc(str_data,sizeof(str_data[0])*str_data_size);
  869. memset(str_data + (str_data_size - 128), '\0', 128);
  870. }
  871. while(str_pos+(int)strlen((char *) p)+1>=str_size){
  872. str_size+=256;
  873. str_buf=(char *)aRealloc(str_buf,str_size);
  874. memset(str_buf + (str_size - 256), '\0', 256);
  875. }
  876. strcpy(str_buf+str_pos, (char *) p);
  877. str_data[str_num].type=C_NOP;
  878. str_data[str_num].str=str_pos;
  879. str_data[str_num].next=0;
  880. str_data[str_num].func=NULL;
  881. str_data[str_num].backpatch=-1;
  882. str_data[str_num].label=-1;
  883. str_pos+=(int)strlen( (char *) p)+1;
  884. return str_num++;
  885. }
  886. /*==========================================
  887. * スクリプトバッファサイズの確認と拡張
  888. *------------------------------------------
  889. */
  890. static void check_script_buf(int size)
  891. {
  892. if(script_pos+size>=script_size){
  893. script_size+=SCRIPT_BLOCK_SIZE;
  894. script_buf=(unsigned char *)aRealloc(script_buf,script_size);
  895. memset(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  896. SCRIPT_BLOCK_SIZE);
  897. }
  898. }
  899. /*==========================================
  900. * スクリプトバッファに1バイト書き込む
  901. *------------------------------------------
  902. */
  903. static void add_scriptb(int a)
  904. {
  905. check_script_buf(1);
  906. script_buf[script_pos++]=a;
  907. }
  908. /*==========================================
  909. * スクリプトバッファにデータタイプを書き込む
  910. *------------------------------------------
  911. */
  912. static void add_scriptc(int a)
  913. {
  914. while(a>=0x40){
  915. add_scriptb((a&0x3f)|0x40);
  916. a=(a-0x40)>>6;
  917. }
  918. add_scriptb(a&0x3f);
  919. }
  920. /*==========================================
  921. * スクリプトバッファに整数を書き込む
  922. *------------------------------------------
  923. */
  924. static void add_scripti(int a)
  925. {
  926. while(a>=0x40){
  927. add_scriptb(a|0xc0);
  928. a=(a-0x40)>>6;
  929. }
  930. add_scriptb(a|0x80);
  931. }
  932. /*==========================================
  933. * スクリプトバッファにラベル/変数/関数を書き込む
  934. *------------------------------------------
  935. */
  936. // 最大16Mまで
  937. static void add_scriptl(int l)
  938. {
  939. int backpatch = str_data[l].backpatch;
  940. switch(str_data[l].type){
  941. case C_POS:
  942. case C_USERFUNC_POS:
  943. add_scriptc(C_POS);
  944. add_scriptb(str_data[l].label);
  945. add_scriptb(str_data[l].label>>8);
  946. add_scriptb(str_data[l].label>>16);
  947. break;
  948. case C_NOP:
  949. case C_USERFUNC:
  950. // ラベルの可能性があるのでbackpatch用データ埋め込み
  951. add_scriptc(C_NAME);
  952. str_data[l].backpatch=script_pos;
  953. add_scriptb(backpatch);
  954. add_scriptb(backpatch>>8);
  955. add_scriptb(backpatch>>16);
  956. break;
  957. case C_INT:
  958. add_scripti(str_data[l].val);
  959. break;
  960. default:
  961. // もう他の用途と確定してるので数字をそのまま
  962. add_scriptc(C_NAME);
  963. add_scriptb(l);
  964. add_scriptb(l>>8);
  965. add_scriptb(l>>16);
  966. break;
  967. }
  968. }
  969. /*==========================================
  970. * ラベルを解決する
  971. *------------------------------------------
  972. */
  973. void set_label(int l,int pos)
  974. {
  975. int i,next;
  976. str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  977. str_data[l].label=pos;
  978. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  979. next=(*(int*)(script_buf+i)) & 0x00ffffff;
  980. script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  981. script_buf[i]=pos;
  982. script_buf[i+1]=pos>>8;
  983. script_buf[i+2]=pos>>16;
  984. i=next;
  985. }
  986. }
  987. /*==========================================
  988. * スペース/コメント読み飛ばし
  989. *------------------------------------------
  990. */
  991. static unsigned char *skip_space(unsigned char *p)
  992. {
  993. while(1){
  994. while(isspace(*p))
  995. p++;
  996. if(p[0]=='/' && p[1]=='/'){
  997. while(*p && *p!='\n')
  998. p++;
  999. } else if(p[0]=='/' && p[1]=='*'){
  1000. p++;
  1001. while(*p && (p[-1]!='*' || p[0]!='/'))
  1002. p++;
  1003. if(*p) p++;
  1004. } else
  1005. break;
  1006. }
  1007. return p;
  1008. }
  1009. /*==========================================
  1010. * 1単語スキップ
  1011. *------------------------------------------
  1012. */
  1013. static unsigned char *skip_word(unsigned char *p)
  1014. {
  1015. // prefix
  1016. if(*p=='.') p++;
  1017. if(*p=='$') p++; // MAP鯖内共有変数用
  1018. if(*p=='@') p++; // 一時的変数用(like weiss)
  1019. if(*p=='#') p++; // account変数用
  1020. if(*p=='#') p++; // ワールドaccount変数用
  1021. while(isalnum(*p)||*p=='_'|| *p>=0x81)
  1022. if(*p>=0x81 && p[1]){
  1023. p+=2;
  1024. } else
  1025. p++;
  1026. // postfix
  1027. if(*p=='$') p++; // 文字列変数
  1028. return p;
  1029. }
  1030. static unsigned char *startptr;
  1031. static int startline;
  1032. /*==========================================
  1033. * エラーメッセージ出力
  1034. *------------------------------------------
  1035. */
  1036. static void disp_error_message(const char *mes,const unsigned char *pos)
  1037. {
  1038. int line,c=0,i;
  1039. unsigned char *p,*linestart,*lineend;
  1040. for(line=startline,p=startptr;p && *p;line++){
  1041. linestart=p;
  1042. lineend=(unsigned char *) strchr((char *) p,'\n');
  1043. if(lineend){
  1044. c=*lineend;
  1045. *lineend=0;
  1046. }
  1047. if(lineend==NULL || pos<lineend){
  1048. fprintf(stderr, "\r"); //To not printout the error next to the spinner...
  1049. ShowError(" "); //Better error display [Skotlex]
  1050. if (current_file) {
  1051. printf("%s in "CL_WHITE"\'%s\'"CL_RESET" line "CL_WHITE"\'%d\'"CL_RESET" : ", mes, current_file, line);
  1052. } else {
  1053. printf("%s line "CL_WHITE"\'%d\'"CL_RESET" : ", mes, line);
  1054. }
  1055. for(i=0;(linestart[i]!='\r') && (linestart[i]!='\n') && linestart[i];i++){
  1056. if(linestart+i!=pos)
  1057. printf("%c",linestart[i]);
  1058. else
  1059. printf("\'%c\'",linestart[i]);
  1060. }
  1061. printf("\a\n");
  1062. if(lineend)
  1063. *lineend=c;
  1064. return;
  1065. }
  1066. *lineend=c;
  1067. p=lineend+1;
  1068. }
  1069. }
  1070. /*==========================================
  1071. * 項の解析
  1072. *------------------------------------------
  1073. */
  1074. unsigned char* parse_simpleexpr(unsigned char *p)
  1075. {
  1076. int i;
  1077. p=skip_space(p);
  1078. #ifdef DEBUG_FUNCIN
  1079. if(battle_config.etc_log)
  1080. ShowDebug("parse_simpleexpr %s\n",p);
  1081. #endif
  1082. if(*p==';' || *p==','){
  1083. disp_error_message("unexpected expr end",p);
  1084. exit(1);
  1085. }
  1086. if(*p=='('){
  1087. p=parse_subexpr(p+1,-1);
  1088. p=skip_space(p);
  1089. if((*p++)!=')'){
  1090. disp_error_message("unmatch ')'",p);
  1091. exit(1);
  1092. }
  1093. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  1094. char *np;
  1095. i=strtoul((char *) p,&np,0);
  1096. add_scripti(i);
  1097. p=(unsigned char *) np;
  1098. } else if(*p=='"'){
  1099. add_scriptc(C_STR);
  1100. p++;
  1101. while(*p && *p!='"'){
  1102. if(p[-1]<=0x7e && *p=='\\')
  1103. p++;
  1104. else if(*p=='\n'){
  1105. disp_error_message("unexpected newline @ string",p);
  1106. exit(1);
  1107. }
  1108. add_scriptb(*p++);
  1109. }
  1110. if(!*p){
  1111. disp_error_message("unexpected eof @ string",p);
  1112. exit(1);
  1113. }
  1114. add_scriptb(0);
  1115. p++; //'"'
  1116. } else {
  1117. int c,l;
  1118. char *p2;
  1119. // label , register , function etc
  1120. if(skip_word(p)==p && !(*p==')' && p[-1]=='(')){
  1121. disp_error_message("unexpected character",p);
  1122. exit(1);
  1123. }
  1124. p2=(char *) skip_word(p);
  1125. c=*p2; *p2=0; // 名前をadd_strする
  1126. l=add_str(p);
  1127. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  1128. *p2=c;
  1129. p=(unsigned char *) p2;
  1130. if(str_data[l].type!=C_FUNC && c=='['){
  1131. // array(name[i] => getelementofarray(name,i) )
  1132. add_scriptl(search_str((unsigned char *) "getelementofarray"));
  1133. add_scriptc(C_ARG);
  1134. add_scriptl(l);
  1135. p=parse_subexpr(p+1,-1);
  1136. p=skip_space(p);
  1137. if((*p++)!=']'){
  1138. disp_error_message("unmatch ']'",p);
  1139. exit(1);
  1140. }
  1141. add_scriptc(C_FUNC);
  1142. } else if(str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS) {
  1143. add_scriptl(search_str((unsigned char*)"callsub"));
  1144. add_scriptc(C_ARG);
  1145. add_scriptl(l);
  1146. }else
  1147. add_scriptl(l);
  1148. }
  1149. #ifdef DEBUG_FUNCIN
  1150. if(battle_config.etc_log)
  1151. ShowDebug("parse_simpleexpr end %s\n",p);
  1152. #endif
  1153. return p;
  1154. }
  1155. /*==========================================
  1156. * 式の解析
  1157. *------------------------------------------
  1158. */
  1159. unsigned char* parse_subexpr(unsigned char *p,int limit)
  1160. {
  1161. int op,opl,len;
  1162. char *tmpp;
  1163. #ifdef DEBUG_FUNCIN
  1164. if(battle_config.etc_log)
  1165. ShowDebug("parse_subexpr %s\n",p);
  1166. #endif
  1167. p=skip_space(p);
  1168. if(*p=='-'){
  1169. tmpp=(char *) skip_space((unsigned char *) (p+1));
  1170. if(*tmpp==';' || *tmpp==','){
  1171. add_scriptl(LABEL_NEXTLINE);
  1172. p++;
  1173. return p;
  1174. }
  1175. }
  1176. tmpp=(char *) p;
  1177. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  1178. p=parse_subexpr(p+1,8);
  1179. add_scriptc(op);
  1180. } else
  1181. p=parse_simpleexpr(p);
  1182. p=skip_space(p);
  1183. while(((op=C_ADD,opl=6,len=1,*p=='+') ||
  1184. (op=C_SUB,opl=6,len=1,*p=='-') ||
  1185. (op=C_MUL,opl=7,len=1,*p=='*') ||
  1186. (op=C_DIV,opl=7,len=1,*p=='/') ||
  1187. (op=C_MOD,opl=7,len=1,*p=='%') ||
  1188. (op=C_FUNC,opl=9,len=1,*p=='(') ||
  1189. (op=C_LAND,opl=1,len=2,*p=='&' && p[1]=='&') ||
  1190. (op=C_AND,opl=5,len=1,*p=='&') ||
  1191. (op=C_LOR,opl=0,len=2,*p=='|' && p[1]=='|') ||
  1192. (op=C_OR,opl=4,len=1,*p=='|') ||
  1193. (op=C_XOR,opl=3,len=1,*p=='^') ||
  1194. (op=C_EQ,opl=2,len=2,*p=='=' && p[1]=='=') ||
  1195. (op=C_NE,opl=2,len=2,*p=='!' && p[1]=='=') ||
  1196. (op=C_R_SHIFT,opl=5,len=2,*p=='>' && p[1]=='>') ||
  1197. (op=C_GE,opl=2,len=2,*p=='>' && p[1]=='=') ||
  1198. (op=C_GT,opl=2,len=1,*p=='>') ||
  1199. (op=C_L_SHIFT,opl=5,len=2,*p=='<' && p[1]=='<') ||
  1200. (op=C_LE,opl=2,len=2,*p=='<' && p[1]=='=') ||
  1201. (op=C_LT,opl=2,len=1,*p=='<')) && opl>limit){
  1202. p+=len;
  1203. if(op==C_FUNC){
  1204. int i=0,func=parse_cmd;
  1205. const char *plist[128];
  1206. if(str_data[parse_cmd].type == C_FUNC){
  1207. // 通常の関数
  1208. add_scriptc(C_ARG);
  1209. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  1210. // ユーザー定義関数呼び出し
  1211. parse_cmd = search_str((unsigned char*)"callsub");
  1212. i++;
  1213. } else {
  1214. disp_error_message(
  1215. "expect command, missing function name or calling undeclared function",(unsigned char *) tmpp
  1216. );
  1217. exit(0);
  1218. }
  1219. func=parse_cmd;
  1220. do {
  1221. plist[i]=(char *) p;
  1222. p=parse_subexpr(p,-1);
  1223. p=skip_space(p);
  1224. if(*p==',') p++;
  1225. else if(*p!=')' && script_config.warn_func_no_comma){
  1226. disp_error_message("expect ',' or ')' at func params",p);
  1227. }
  1228. p=skip_space(p);
  1229. i++;
  1230. } while(*p && *p!=')' && i<128);
  1231. plist[i]=(char *) p;
  1232. if(*(p++)!=')'){
  1233. disp_error_message("func request '(' ')'",p);
  1234. exit(1);
  1235. }
  1236. if (str_data[func].type == C_FUNC && script_config.warn_func_mismatch_paramnum) {
  1237. const char *arg = buildin_func[str_data[func].val].arg;
  1238. int j = 0;
  1239. for (; arg[j]; j++) if (arg[j] == '*') break;
  1240. if (!(i <= 1 && j == 0) && ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j))) {
  1241. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  1242. }
  1243. }
  1244. } else {
  1245. p=parse_subexpr(p,opl);
  1246. }
  1247. add_scriptc(op);
  1248. p=skip_space(p);
  1249. }
  1250. #ifdef DEBUG_FUNCIN
  1251. if(battle_config.etc_log)
  1252. ShowDebug("parse_subexpr end %s\n",p);
  1253. #endif
  1254. return p; /* return first untreated operator */
  1255. }
  1256. /*==========================================
  1257. * 式の評価
  1258. *------------------------------------------
  1259. */
  1260. unsigned char* parse_expr(unsigned char *p)
  1261. {
  1262. #ifdef DEBUG_FUNCIN
  1263. if(battle_config.etc_log)
  1264. ShowDebug("parse_expr %s\n",p);
  1265. #endif
  1266. switch(*p){
  1267. case ')': case ';': case ':': case '[': case ']':
  1268. case '}':
  1269. disp_error_message("unexpected char",p);
  1270. exit(1);
  1271. }
  1272. p=parse_subexpr(p,-1);
  1273. #ifdef DEBUG_FUNCIN
  1274. if(battle_config.etc_log)
  1275. ShowDebug("parse_expr end %s\n",p);
  1276. #endif
  1277. return p;
  1278. }
  1279. /*==========================================
  1280. * 行の解析
  1281. *------------------------------------------
  1282. */
  1283. unsigned char* parse_line(unsigned char *p)
  1284. {
  1285. int i=0,cmd;
  1286. const char *plist[128];
  1287. unsigned char *p2;
  1288. char end;
  1289. p=skip_space(p);
  1290. if(*p==';')
  1291. return p + 1;
  1292. p = skip_space(p);
  1293. if(p[0] == '{') {
  1294. syntax.curly[syntax.curly_count].type = TYPE_NULL;
  1295. syntax.curly[syntax.curly_count].count = -1;
  1296. syntax.curly[syntax.curly_count].index = -1;
  1297. syntax.curly_count++;
  1298. return p + 1;
  1299. } else if(p[0] == '}') {
  1300. return parse_curly_close(p);
  1301. }
  1302. // 構文関連の処理
  1303. p2 = parse_syntax(p);
  1304. if(p2 != NULL) { return p2; }
  1305. // 最初は関数名
  1306. p2=(char *) p;
  1307. p=parse_simpleexpr(p);
  1308. p=skip_space(p);
  1309. if(str_data[parse_cmd].type == C_FUNC){
  1310. // 通常の関数
  1311. add_scriptc(C_ARG);
  1312. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  1313. // ユーザー定義関数呼び出し
  1314. parse_cmd = search_str((unsigned char*)"callsub");
  1315. i++;
  1316. } else {
  1317. disp_error_message(
  1318. "expect command, missing function name or calling undeclared function", (unsigned char *)p2
  1319. );
  1320. // exit(0);
  1321. }
  1322. cmd=parse_cmd;
  1323. if(parse_syntax_for_flag) {
  1324. end = ')';
  1325. } else {
  1326. end = ';';
  1327. }
  1328. while(p && *p && *p!=end && i<128){
  1329. plist[i]=(char *) p;
  1330. p=parse_expr(p);
  1331. p=skip_space(p);
  1332. // 引数区切りの,処理
  1333. if(*p==',') p++;
  1334. else if(*p!=end && script_config.warn_cmd_no_comma && 0 <= i ){
  1335. if(parse_syntax_for_flag) {
  1336. disp_error_message("expect ',' or ')' at cmd params",p);
  1337. } else {
  1338. disp_error_message("expect ',' or ';' at cmd params",p);
  1339. }
  1340. }
  1341. p=skip_space(p);
  1342. i++;
  1343. }
  1344. plist[i]=(char *) p;
  1345. if(!p || *(p++)!=end){
  1346. if(parse_syntax_for_flag) {
  1347. disp_error_message("need ')'",p);
  1348. } else {
  1349. disp_error_message("need ';'",p);
  1350. }
  1351. exit(1);
  1352. }
  1353. add_scriptc(C_FUNC);
  1354. // if, for , while の閉じ判定
  1355. p = parse_syntax_close(p);
  1356. if( str_data[cmd].type==C_FUNC && script_config.warn_cmd_mismatch_paramnum){
  1357. const char *arg=buildin_func[str_data[cmd].val].arg;
  1358. int j=0;
  1359. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  1360. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  1361. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  1362. }
  1363. }
  1364. return p;
  1365. }
  1366. // { ... } の閉じ処理
  1367. unsigned char* parse_curly_close(unsigned char *p) {
  1368. if(syntax.curly_count <= 0) {
  1369. disp_error_message("unexpected string",p);
  1370. return p + 1;
  1371. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
  1372. syntax.curly_count--;
  1373. // if, for , while の閉じ判定
  1374. p = parse_syntax_close(p + 1);
  1375. return p;
  1376. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
  1377. // switch() 閉じ判定
  1378. int pos = syntax.curly_count-1;
  1379. unsigned char label[256];
  1380. int l;
  1381. // 一時変数を消す
  1382. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  1383. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1384. parse_line(label);
  1385. syntax.curly_count--;
  1386. // 無条件で終了ポインタに移動
  1387. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  1388. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1389. parse_line(label);
  1390. syntax.curly_count--;
  1391. // 現在地のラベルを付ける
  1392. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1393. l=add_str(label);
  1394. if(str_data[l].label!=-1){
  1395. disp_error_message("dup label ",p);
  1396. exit(1);
  1397. }
  1398. set_label(l,script_pos);
  1399. if(syntax.curly[pos].flag) {
  1400. // default が存在する
  1401. sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
  1402. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1403. parse_line(label);
  1404. syntax.curly_count--;
  1405. }
  1406. // 終了ラベルを付ける
  1407. sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
  1408. l=add_str(label);
  1409. if(str_data[l].label!=-1){
  1410. disp_error_message("dup label ",p);
  1411. exit(1);
  1412. }
  1413. set_label(l,script_pos);
  1414. syntax.curly_count--;
  1415. return p+1;
  1416. } else {
  1417. disp_error_message("unexpected string",p);
  1418. return p + 1;
  1419. }
  1420. }
  1421. // 構文関連の処理
  1422. // break, case, continue, default, do, for, function,
  1423. // if, switch, while をこの内部で処理します。
  1424. unsigned char* parse_syntax(unsigned char *p) {
  1425. switch(p[0]) {
  1426. case 'b':
  1427. if(!strncmp(p,"break",5) && !isalpha(*(p + 5))) {
  1428. // break の処理
  1429. char label[256];
  1430. int pos = syntax.curly_count - 1;
  1431. while(pos >= 0) {
  1432. if(syntax.curly[pos].type == TYPE_DO) {
  1433. sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
  1434. break;
  1435. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1436. sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
  1437. break;
  1438. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1439. sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
  1440. break;
  1441. } else if(syntax.curly[pos].type == TYPE_SWITCH) {
  1442. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  1443. break;
  1444. }
  1445. pos--;
  1446. }
  1447. if(pos < 0) {
  1448. disp_error_message("unexpected 'break'",p);
  1449. } else {
  1450. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1451. parse_line(label);
  1452. syntax.curly_count--;
  1453. }
  1454. p = skip_word(p);
  1455. p++;
  1456. // if, for , while の閉じ判定
  1457. p = parse_syntax_close(p + 1);
  1458. return p;
  1459. }
  1460. break;
  1461. case 'c':
  1462. if(!strncmp(p,"case",4) && !isalpha(*(p + 4))) {
  1463. // case の処理
  1464. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  1465. disp_error_message("unexpected 'case' ",p);
  1466. return p+1;
  1467. } else {
  1468. char *p2;
  1469. char label[256];
  1470. int l;
  1471. int pos = syntax.curly_count-1;
  1472. if(syntax.curly[pos].count != 1) {
  1473. // FALLTHRU 用のジャンプ
  1474. sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
  1475. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1476. parse_line(label);
  1477. syntax.curly_count--;
  1478. // 現在地のラベルを付ける
  1479. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1480. l=add_str(label);
  1481. if(str_data[l].label!=-1){
  1482. disp_error_message("dup label ",p);
  1483. exit(1);
  1484. }
  1485. set_label(l,script_pos);
  1486. }
  1487. // switch 判定文
  1488. p = skip_word(p);
  1489. p = skip_space(p);
  1490. p2 = p;
  1491. p = skip_word(p);
  1492. p = skip_space(p);
  1493. if(*p != ':') {
  1494. disp_error_message("expect ':'",p);
  1495. exit(1);
  1496. }
  1497. *p = 0;
  1498. sprintf(label,"if(%s != $@__SW%x_VAL) goto __SW%x_%x;",
  1499. p2,syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
  1500. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1501. *p = ':';
  1502. // 2回parse しないとダメ
  1503. p2 = parse_line(label);
  1504. parse_line(p2);
  1505. syntax.curly_count--;
  1506. if(syntax.curly[pos].count != 1) {
  1507. // FALLTHRU 終了後のラベル
  1508. sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
  1509. l=add_str(label);
  1510. if(str_data[l].label!=-1){
  1511. disp_error_message("dup label ",p);
  1512. exit(1);
  1513. }
  1514. set_label(l,script_pos);
  1515. }
  1516. // 一時変数を消す
  1517. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  1518. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1519. parse_line(label);
  1520. syntax.curly_count--;
  1521. syntax.curly[pos].count++;
  1522. }
  1523. return p + 1;
  1524. } else if(!strncmp(p,"continue",8) && !isalpha(*(p + 8))) {
  1525. // continue の処理
  1526. char label[256];
  1527. int pos = syntax.curly_count - 1;
  1528. while(pos >= 0) {
  1529. if(syntax.curly[pos].type == TYPE_DO) {
  1530. sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
  1531. syntax.curly[pos].flag = 1; // continue 用のリンク張るフラグ
  1532. break;
  1533. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1534. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1535. break;
  1536. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1537. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1538. break;
  1539. }
  1540. pos--;
  1541. }
  1542. if(pos < 0) {
  1543. disp_error_message("unexpected 'continue'",p);
  1544. } else {
  1545. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1546. parse_line(label);
  1547. syntax.curly_count--;
  1548. }
  1549. p = skip_word(p);
  1550. p++;
  1551. // if, for , while の閉じ判定
  1552. p = parse_syntax_close(p + 1);
  1553. return p;
  1554. }
  1555. break;
  1556. case 'd':
  1557. if(!strncmp(p,"default",7) && !isalpha(*(p + 7))) {
  1558. // switch - default の処理
  1559. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  1560. disp_error_message("unexpected 'delault'",p);
  1561. return p+1;
  1562. } else if(syntax.curly[syntax.curly_count - 1].flag) {
  1563. disp_error_message("dup 'delault'",p);
  1564. return p+1;
  1565. } else {
  1566. char label[256];
  1567. int l;
  1568. int pos = syntax.curly_count-1;
  1569. // 現在地のラベルを付ける
  1570. p = skip_word(p);
  1571. p = skip_space(p);
  1572. if(*p != ':') {
  1573. disp_error_message("need ':'",p);
  1574. }
  1575. p++;
  1576. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1577. l=add_str(label);
  1578. if(str_data[l].label!=-1){
  1579. disp_error_message("dup label ",p);
  1580. exit(1);
  1581. }
  1582. set_label(l,script_pos);
  1583. // 無条件で次のリンクに飛ばす
  1584. sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
  1585. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1586. parse_line(label);
  1587. syntax.curly_count--;
  1588. // default のラベルを付ける
  1589. sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
  1590. l=add_str(label);
  1591. if(str_data[l].label!=-1){
  1592. disp_error_message("dup label ",p);
  1593. exit(1);
  1594. }
  1595. set_label(l,script_pos);
  1596. syntax.curly[syntax.curly_count - 1].flag = 1;
  1597. syntax.curly[pos].count++;
  1598. p = skip_word(p);
  1599. return p + 1;
  1600. }
  1601. } else if(!strncmp(p,"do",2) && !isalpha(*(p + 2))) {
  1602. int l;
  1603. char label[256];
  1604. p=skip_word(p);
  1605. p=skip_space(p);
  1606. syntax.curly[syntax.curly_count].type = TYPE_DO;
  1607. syntax.curly[syntax.curly_count].count = 1;
  1608. syntax.curly[syntax.curly_count].index = syntax.index++;
  1609. syntax.curly[syntax.curly_count].flag = 0;
  1610. // 現在地のラベル形成する
  1611. sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
  1612. l=add_str(label);
  1613. if(str_data[l].label!=-1){
  1614. disp_error_message("dup label ",p);
  1615. exit(1);
  1616. }
  1617. set_label(l,script_pos);
  1618. syntax.curly_count++;
  1619. return p;
  1620. }
  1621. break;
  1622. case 'f':
  1623. if(!strncmp(p,"for",3) && !isalpha(*(p + 3))) {
  1624. int l;
  1625. unsigned char label[256];
  1626. int pos = syntax.curly_count;
  1627. syntax.curly[syntax.curly_count].type = TYPE_FOR;
  1628. syntax.curly[syntax.curly_count].count = 1;
  1629. syntax.curly[syntax.curly_count].index = syntax.index++;
  1630. syntax.curly[syntax.curly_count].flag = 0;
  1631. syntax.curly_count++;
  1632. p=skip_word(p);
  1633. p=skip_space(p);
  1634. if(*p != '(') {
  1635. disp_error_message("need '('",p);
  1636. return p+1;
  1637. }
  1638. p++;
  1639. // 初期化文を実行する
  1640. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1641. p=parse_line(p);
  1642. syntax.curly_count--;
  1643. // 条件判断開始のラベル形成する
  1644. sprintf(label,"__FR%x_J",syntax.curly[pos].index);
  1645. l=add_str(label);
  1646. if(str_data[l].label!=-1){
  1647. disp_error_message("dup label ",p);
  1648. exit(1);
  1649. }
  1650. set_label(l,script_pos);
  1651. if(*p == ';') {
  1652. // for(;;) のパターンなので必ず真
  1653. ;
  1654. } else {
  1655. // 条件が偽なら終了地点に飛ばす
  1656. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1657. add_scriptl(add_str("jump_zero"));
  1658. add_scriptc(C_ARG);
  1659. p=parse_expr(p);
  1660. p=skip_space(p);
  1661. add_scriptl(add_str(label));
  1662. add_scriptc(C_FUNC);
  1663. }
  1664. if(*p != ';') {
  1665. disp_error_message("need ';'",p);
  1666. return p+1;
  1667. }
  1668. p++;
  1669. // ループ開始に飛ばす
  1670. sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
  1671. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1672. parse_line(label);
  1673. syntax.curly_count--;
  1674. // 次のループへのラベル形成する
  1675. sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
  1676. l=add_str(label);
  1677. if(str_data[l].label!=-1){
  1678. disp_error_message("dup label ",p);
  1679. exit(1);
  1680. }
  1681. set_label(l,script_pos);
  1682. // 次のループに入る時の処理
  1683. // for 最後の '(' を ';' として扱うフラグ
  1684. parse_syntax_for_flag = 1;
  1685. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1686. p=parse_line(p);
  1687. syntax.curly_count--;
  1688. parse_syntax_for_flag = 0;
  1689. // 条件判定処理に飛ばす
  1690. sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
  1691. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1692. parse_line(label);
  1693. syntax.curly_count--;
  1694. // ループ開始のラベル付け
  1695. sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
  1696. l=add_str(label);
  1697. if(str_data[l].label!=-1){
  1698. disp_error_message("dup label ",p);
  1699. exit(1);
  1700. }
  1701. set_label(l,script_pos);
  1702. return p;
  1703. } else if(!strncmp(p,"function",8) && !isalpha(*(p + 8))) {
  1704. unsigned char *func_name;
  1705. // function
  1706. p=skip_word(p);
  1707. p=skip_space(p);
  1708. // function - name
  1709. func_name = p;
  1710. p=skip_word(p);
  1711. if(*skip_space(p) == ';') {
  1712. // 関数の宣言 - 名前を登録して終わり
  1713. unsigned char c = *p;
  1714. int l;
  1715. *p = 0;
  1716. l=add_str(func_name);
  1717. *p = c;
  1718. if(str_data[l].type == C_NOP) {
  1719. str_data[l].type = C_USERFUNC;
  1720. }
  1721. return skip_space(p) + 1;
  1722. } else {
  1723. // 関数の中身
  1724. char label[256];
  1725. unsigned char c = *p;
  1726. int l;
  1727. syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
  1728. syntax.curly[syntax.curly_count].count = 1;
  1729. syntax.curly[syntax.curly_count].index = syntax.index++;
  1730. syntax.curly[syntax.curly_count].flag = 0;
  1731. syntax.curly_count++;
  1732. // 関数終了まで飛ばす
  1733. sprintf(label,"goto __FN%x_FIN;",syntax.curly[syntax.curly_count-1].index);
  1734. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1735. parse_line(label);
  1736. syntax.curly_count--;
  1737. // 関数名のラベルを付ける
  1738. *p = 0;
  1739. l=add_str(func_name);
  1740. if(str_data[l].type == C_NOP) {
  1741. str_data[l].type = C_USERFUNC;
  1742. }
  1743. if(str_data[l].label!=-1){
  1744. *p=c;
  1745. disp_error_message("dup label ",p);
  1746. exit(1);
  1747. }
  1748. set_label(l,script_pos);
  1749. strdb_put(scriptlabel_db,func_name,(void*)script_pos); // 外部用label db登録
  1750. *p = c;
  1751. return skip_space(p);
  1752. }
  1753. }
  1754. break;
  1755. case 'i':
  1756. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1757. // if() の処理
  1758. char label[256];
  1759. p=skip_word(p);
  1760. p=skip_space(p);
  1761. syntax.curly[syntax.curly_count].type = TYPE_IF;
  1762. syntax.curly[syntax.curly_count].count = 1;
  1763. syntax.curly[syntax.curly_count].index = syntax.index++;
  1764. syntax.curly[syntax.curly_count].flag = 0;
  1765. sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
  1766. syntax.curly_count++;
  1767. add_scriptl(add_str("jump_zero"));
  1768. add_scriptc(C_ARG);
  1769. p=parse_expr(p);
  1770. p=skip_space(p);
  1771. add_scriptl(add_str(label));
  1772. add_scriptc(C_FUNC);
  1773. return p;
  1774. }
  1775. break;
  1776. case 's':
  1777. if(!strncmp(p,"switch",6) && !isalpha(*(p + 6))) {
  1778. // switch() の処理
  1779. char label[256];
  1780. syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
  1781. syntax.curly[syntax.curly_count].count = 1;
  1782. syntax.curly[syntax.curly_count].index = syntax.index++;
  1783. syntax.curly[syntax.curly_count].flag = 0;
  1784. sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
  1785. syntax.curly_count++;
  1786. add_scriptl(add_str((unsigned char*)"set"));
  1787. add_scriptc(C_ARG);
  1788. add_scriptl(add_str(label));
  1789. p=skip_word(p);
  1790. p=skip_space(p);
  1791. p=parse_expr(p);
  1792. p=skip_space(p);
  1793. if(*p != '{') {
  1794. disp_error_message("need '{'",p);
  1795. }
  1796. add_scriptc(C_FUNC);
  1797. return p + 1;
  1798. }
  1799. break;
  1800. case 'w':
  1801. if(!strncmp(p,"while",5) && !isalpha(*(p + 5))) {
  1802. int l;
  1803. char label[256];
  1804. p=skip_word(p);
  1805. p=skip_space(p);
  1806. syntax.curly[syntax.curly_count].type = TYPE_WHILE;
  1807. syntax.curly[syntax.curly_count].count = 1;
  1808. syntax.curly[syntax.curly_count].index = syntax.index++;
  1809. syntax.curly[syntax.curly_count].flag = 0;
  1810. // 条件判断開始のラベル形成する
  1811. sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
  1812. l=add_str(label);
  1813. if(str_data[l].label!=-1){
  1814. disp_error_message("dup label ",p);
  1815. exit(1);
  1816. }
  1817. set_label(l,script_pos);
  1818. // 条件が偽なら終了地点に飛ばす
  1819. sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
  1820. add_scriptl(add_str("jump_zero"));
  1821. add_scriptc(C_ARG);
  1822. p=parse_expr(p);
  1823. p=skip_space(p);
  1824. add_scriptl(add_str(label));
  1825. add_scriptc(C_FUNC);
  1826. syntax.curly_count++;
  1827. return p;
  1828. }
  1829. break;
  1830. }
  1831. return NULL;
  1832. }
  1833. unsigned char* parse_syntax_close(unsigned char *p) {
  1834. // if(...) for(...) hoge(); のように、1度閉じられたら再度閉じられるか確認する
  1835. int flag;
  1836. do {
  1837. p = parse_syntax_close_sub(p,&flag);
  1838. } while(flag);
  1839. return p;
  1840. }
  1841. // if, for , while , do の閉じ判定
  1842. // flag == 1 : 閉じられた
  1843. // flag == 0 : 閉じられない
  1844. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
  1845. unsigned char label[256];
  1846. int pos = syntax.curly_count - 1;
  1847. int l;
  1848. *flag = 1;
  1849. if(syntax.curly_count <= 0) {
  1850. *flag = 0;
  1851. return p;
  1852. } else if(syntax.curly[pos].type == TYPE_IF) {
  1853. char *p2 = p;
  1854. // if 最終場所へ飛ばす
  1855. sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
  1856. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1857. parse_line(label);
  1858. syntax.curly_count--;
  1859. // 現在地のラベルを付ける
  1860. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1861. l=add_str(label);
  1862. if(str_data[l].label!=-1){
  1863. disp_error_message("dup label ",p);
  1864. exit(1);
  1865. }
  1866. set_label(l,script_pos);
  1867. syntax.curly[pos].count++;
  1868. p = skip_space(p);
  1869. if(!syntax.curly[pos].flag && !strncmp(p,"else",4) && !isalpha(*(p + 4))) {
  1870. // else or else - if
  1871. p = skip_word(p);
  1872. p = skip_space(p);
  1873. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1874. // else - if
  1875. p=skip_word(p);
  1876. p=skip_space(p);
  1877. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1878. add_scriptl(add_str("jump_zero"));
  1879. add_scriptc(C_ARG);
  1880. p=parse_expr(p);
  1881. p=skip_space(p);
  1882. add_scriptl(add_str(label));
  1883. add_scriptc(C_FUNC);
  1884. *flag = 0;
  1885. return p;
  1886. } else {
  1887. // else
  1888. if(!syntax.curly[pos].flag) {
  1889. syntax.curly[pos].flag = 1;
  1890. *flag = 0;
  1891. return p;
  1892. }
  1893. }
  1894. }
  1895. // if 閉じ
  1896. syntax.curly_count--;
  1897. // 最終地のラベルを付ける
  1898. sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
  1899. l=add_str(label);
  1900. if(str_data[l].label!=-1){
  1901. disp_error_message("dup label ",p);
  1902. exit(1);
  1903. }
  1904. set_label(l,script_pos);
  1905. if(syntax.curly[pos].flag == 1) {
  1906. // このifに対するelseじゃないのでポインタの位置は同じ
  1907. return p2;
  1908. }
  1909. return p;
  1910. } else if(syntax.curly[pos].type == TYPE_DO) {
  1911. int l;
  1912. char label[256];
  1913. unsigned char *p2;
  1914. if(syntax.curly[pos].flag) {
  1915. // 現在地のラベル形成する(continue でここに来る)
  1916. sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
  1917. l=add_str(label);
  1918. if(str_data[l].label!=-1){
  1919. disp_error_message("dup label ",p);
  1920. exit(1);
  1921. }
  1922. set_label(l,script_pos);
  1923. }
  1924. // 条件が偽なら終了地点に飛ばす
  1925. p = skip_space(p);
  1926. p2 = skip_word(p);
  1927. if(p2 - p != 5 || strncmp("while",p,5)) {
  1928. disp_error_message("need 'while'",p);
  1929. }
  1930. p = p2;
  1931. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1932. add_scriptl(add_str("jump_zero"));
  1933. add_scriptc(C_ARG);
  1934. p=parse_expr(p);
  1935. p=skip_space(p);
  1936. add_scriptl(add_str(label));
  1937. add_scriptc(C_FUNC);
  1938. // 開始地点に飛ばす
  1939. sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
  1940. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1941. parse_line(label);
  1942. syntax.curly_count--;
  1943. // 条件終了地点のラベル形成する
  1944. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1945. l=add_str(label);
  1946. if(str_data[l].label!=-1){
  1947. disp_error_message("dup label ",p);
  1948. exit(1);
  1949. }
  1950. set_label(l,script_pos);
  1951. p = skip_space(p);
  1952. if(*p != ';') {
  1953. disp_error_message("need ';'",p);
  1954. return p+1;
  1955. }
  1956. p++;
  1957. syntax.curly_count--;
  1958. return p;
  1959. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1960. // 次のループに飛ばす
  1961. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1962. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1963. parse_line(label);
  1964. syntax.curly_count--;
  1965. // for 終了のラベル付け
  1966. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1967. l=add_str(label);
  1968. if(str_data[l].label!=-1){
  1969. disp_error_message("dup label ",p);
  1970. exit(1);
  1971. }
  1972. set_label(l,script_pos);
  1973. syntax.curly_count--;
  1974. return p;
  1975. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1976. // while 条件判断へ飛ばす
  1977. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1978. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1979. parse_line(label);
  1980. syntax.curly_count--;
  1981. // while 終了のラベル付け
  1982. sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
  1983. l=add_str(label);
  1984. if(str_data[l].label!=-1){
  1985. disp_error_message("dup label ",p);
  1986. exit(1);
  1987. }
  1988. set_label(l,script_pos);
  1989. syntax.curly_count--;
  1990. return p;
  1991. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
  1992. int pos = syntax.curly_count-1;
  1993. char label[256];
  1994. int l;
  1995. // 戻す
  1996. sprintf(label,"return;");
  1997. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1998. parse_line(label);
  1999. syntax.curly_count--;
  2000. // 現在地のラベルを付ける
  2001. sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
  2002. l=add_str(label);
  2003. if(str_data[l].label!=-1){
  2004. disp_error_message("dup label ",p);
  2005. exit(1);
  2006. }
  2007. set_label(l,script_pos);
  2008. syntax.curly_count--;
  2009. return p + 1;
  2010. } else {
  2011. *flag = 0;
  2012. return p;
  2013. }
  2014. }
  2015. /*==========================================
  2016. * 組み込み関数の追加
  2017. *------------------------------------------
  2018. */
  2019. static void add_buildin_func(void)
  2020. {
  2021. int i,n;
  2022. for(i=0;buildin_func[i].func;i++){
  2023. n=add_str((unsigned char *) buildin_func[i].name);
  2024. str_data[n].type=C_FUNC;
  2025. str_data[n].val=i;
  2026. str_data[n].func=buildin_func[i].func;
  2027. }
  2028. }
  2029. /*==========================================
  2030. * 定数データベースの読み込み
  2031. *------------------------------------------
  2032. */
  2033. static void read_constdb(void)
  2034. {
  2035. FILE *fp;
  2036. char line[1024],name[1024];
  2037. int val,n,i,type;
  2038. sprintf(line, "%s/const.txt", db_path);
  2039. fp=fopen(line, "r");
  2040. if(fp==NULL){
  2041. ShowError("can't read %s\n", line);
  2042. return ;
  2043. }
  2044. while(fgets(line,1020,fp)){
  2045. if(line[0]=='/' && line[1]=='/')
  2046. continue;
  2047. type=0;
  2048. if(sscanf(line,"%[A-Za-z0-9_],%d,%d",name,&val,&type)>=2 ||
  2049. sscanf(line,"%[A-Za-z0-9_] %d %d",name,&val,&type)>=2){
  2050. for(i=0;name[i];i++)
  2051. name[i]=tolower(name[i]);
  2052. n=add_str((const unsigned char *) name);
  2053. if(type==0)
  2054. str_data[n].type=C_INT;
  2055. else
  2056. str_data[n].type=C_PARAM;
  2057. str_data[n].val=val;
  2058. }
  2059. }
  2060. fclose(fp);
  2061. }
  2062. /*==========================================
  2063. * スクリプトの解析
  2064. *------------------------------------------
  2065. */
  2066. struct script_code* parse_script(unsigned char *src,int line)
  2067. {
  2068. unsigned char *p, *tmpp;
  2069. int i;
  2070. struct script_code *code;
  2071. static int first = 1;
  2072. if (first) {
  2073. add_buildin_func();
  2074. read_constdb();
  2075. }
  2076. first = 0;
  2077. //////////////////////////////////////////////
  2078. // additional check on the input to filter empty scripts ("{}" and "{ }")
  2079. p = src;
  2080. p = skip_space(p);
  2081. if (*p != '{') {
  2082. disp_error_message("not found '{'", p);
  2083. return NULL;
  2084. }
  2085. p++;
  2086. p = skip_space(p);
  2087. if (*p == '}') {
  2088. // an empty function, just return
  2089. return NULL;
  2090. }
  2091. script_buf = (unsigned char *) aCallocA(SCRIPT_BLOCK_SIZE, sizeof(unsigned char));
  2092. script_pos = 0;
  2093. script_size = SCRIPT_BLOCK_SIZE;
  2094. str_data[LABEL_NEXTLINE].type = C_NOP;
  2095. str_data[LABEL_NEXTLINE].backpatch = -1;
  2096. str_data[LABEL_NEXTLINE].label = -1;
  2097. for (i = LABEL_START; i < str_num; i++) {
  2098. if (
  2099. str_data[i].type == C_POS || str_data[i].type == C_NAME ||
  2100. str_data[i].type == C_USERFUNC || str_data[i].type == C_USERFUNC_POS
  2101. ) {
  2102. str_data[i].type = C_NOP;
  2103. str_data[i].backpatch = -1;
  2104. str_data[i].label = -1;
  2105. }
  2106. }
  2107. //Labels must be reparsed for the script....
  2108. scriptlabel_db->clear(scriptlabel_db, NULL);
  2109. // for error message
  2110. startptr = src;
  2111. startline = line;
  2112. while (p && *p && (*p != '}' || syntax.curly_count != 0)) {
  2113. p = skip_space(p);
  2114. // labelだけ特殊処理
  2115. tmpp = skip_space(skip_word(p));
  2116. if (*tmpp == ':' && !(!strncmp(p,"default",7) && !isalpha(*(p + 7)))) {
  2117. int l, c;
  2118. c = *skip_word(p);
  2119. *skip_word(p) = 0;
  2120. l = add_str(p);
  2121. if (str_data[l].label != -1) {
  2122. *skip_word(p) = c;
  2123. disp_error_message("dup label ", p);
  2124. exit(1);
  2125. }
  2126. set_label(l, script_pos);
  2127. strdb_put(scriptlabel_db, p, (void*)script_pos); // 外部用label db登録
  2128. *skip_word(p) = c;
  2129. p = tmpp + 1;
  2130. continue;
  2131. }
  2132. // 他は全部一緒くた
  2133. p = parse_line(p);
  2134. p = skip_space(p);
  2135. add_scriptc(C_EOL);
  2136. set_label(LABEL_NEXTLINE, script_pos);
  2137. str_data[LABEL_NEXTLINE].type = C_NOP;
  2138. str_data[LABEL_NEXTLINE].backpatch = -1;
  2139. str_data[LABEL_NEXTLINE].label = -1;
  2140. }
  2141. add_scriptc(C_NOP);
  2142. script_size = script_pos;
  2143. script_buf = (unsigned char *)aRealloc(script_buf, script_pos + 1);
  2144. // 未解決のラベルを解決
  2145. for (i = LABEL_START; i < str_num; i++) {
  2146. if (str_data[i].type == C_NOP) {
  2147. int j, next;
  2148. str_data[i].type = C_NAME;
  2149. str_data[i].label = i;
  2150. for (j = str_data[i].backpatch; j >= 0 && j != 0x00ffffff; ) {
  2151. next = (*(int*)(script_buf+j)) & 0x00ffffff;
  2152. script_buf[j] = i;
  2153. script_buf[j+1] = i>>8;
  2154. script_buf[j+2] = i>>16;
  2155. j = next;
  2156. }
  2157. }
  2158. }
  2159. #ifdef DEBUG_DISP
  2160. for (i = 0; i < script_pos; i++) {
  2161. if ((i & 15) == 0) printf("%04x : ", i);
  2162. printf("%02x ", script_buf[i]);
  2163. if((i&15) == 15) printf("\n");
  2164. }
  2165. printf("\n");
  2166. #endif
  2167. startptr = NULL; //Clear pointer to prevent future references to a src that may be free'd. [Skotlex]
  2168. code = aCalloc(1, sizeof(struct script_code));
  2169. code->script_buf = script_buf;
  2170. code->script_size = script_size;
  2171. code->script_vars = NULL;
  2172. return code;
  2173. }
  2174. //
  2175. // 実行系
  2176. //
  2177. enum {RUN = 0,STOP,END,RERUNLINE,GOTO,RETFUNC};
  2178. /*==========================================
  2179. * ridからsdへの解決
  2180. *------------------------------------------
  2181. */
  2182. struct map_session_data *script_rid2sd(struct script_state *st)
  2183. {
  2184. struct map_session_data *sd=map_id2sd(st->rid);
  2185. if(!sd){
  2186. ShowError("script_rid2sd: fatal error ! player not attached!\n");
  2187. report_src(st);
  2188. }
  2189. return sd;
  2190. }
  2191. /*==========================================
  2192. * 変数の読み取り
  2193. *------------------------------------------
  2194. */
  2195. int get_val(struct script_state*st,struct script_data* data)
  2196. {
  2197. struct map_session_data *sd=NULL;
  2198. if(data->type==C_NAME){
  2199. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  2200. char prefix=*name;
  2201. char postfix=name[strlen(name)-1];
  2202. if(not_server_variable(prefix)){
  2203. if((sd=script_rid2sd(st))==NULL)
  2204. ShowError("get_val error name?:%s\n",name);
  2205. }
  2206. if(postfix=='$'){
  2207. data->type=C_CONSTSTR;
  2208. if( prefix=='@'){
  2209. if(sd)
  2210. data->u.str = pc_readregstr(sd,data->u.num);
  2211. }else if(prefix=='$'){
  2212. data->u.str = (char *)idb_get(mapregstr_db,data->u.num);
  2213. }else if(prefix=='#'){
  2214. if( name[1]=='#'){
  2215. if(sd)
  2216. data->u.str = pc_readaccountreg2str(sd,name);
  2217. }else{
  2218. if(sd)
  2219. data->u.str = pc_readaccountregstr(sd,name);
  2220. }
  2221. }else if(prefix=='.') {
  2222. struct linkdb_node **n;
  2223. if( data->ref ) {
  2224. n = data->ref;
  2225. } else if( name[1] == '@' ) {
  2226. n = st->stack->var_function;
  2227. } else {
  2228. n = &st->script->script_vars;
  2229. }
  2230. data->u.str = linkdb_search(n, (void*)data->u.num );
  2231. }else{
  2232. if(sd)
  2233. data->u.str = pc_readglobalreg_str(sd,name);
  2234. } // [zBuffer]
  2235. /*else{
  2236. ShowWarning("script: get_val: illegal scope string variable.\n");
  2237. data->u.str = "!!ERROR!!";
  2238. }*/
  2239. if( data->u.str == NULL )
  2240. data->u.str ="";
  2241. }else{
  2242. data->type=C_INT;
  2243. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  2244. data->u.num = str_data[data->u.num&0x00ffffff].val;
  2245. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  2246. if(sd)
  2247. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  2248. }else if(prefix=='@'){
  2249. if(sd)
  2250. data->u.num = pc_readreg(sd,data->u.num);
  2251. }else if(prefix=='$'){
  2252. data->u.num = (int)idb_get(mapreg_db,data->u.num);
  2253. }else if(prefix=='#'){
  2254. if( name[1]=='#'){
  2255. if(sd)
  2256. data->u.num = pc_readaccountreg2(sd,name);
  2257. }else{
  2258. if(sd)
  2259. data->u.num = pc_readaccountreg(sd,name);
  2260. }
  2261. }else if(prefix=='.'){
  2262. struct linkdb_node **n;
  2263. if( data->ref ) {
  2264. n = data->ref;
  2265. } else if( name[1] == '@' ) {
  2266. n = st->stack->var_function;
  2267. } else {
  2268. n = &st->script->script_vars;
  2269. }
  2270. data->u.num = (int)linkdb_search(n, (void*)data->u.num);
  2271. }else{
  2272. if(sd)
  2273. data->u.num = pc_readglobalreg(sd,name);
  2274. }
  2275. }
  2276. }
  2277. return 0;
  2278. }
  2279. /*==========================================
  2280. * 変数の読み取り2
  2281. *------------------------------------------
  2282. */
  2283. void* get_val2(struct script_state*st,int num,struct linkdb_node **ref)
  2284. {
  2285. struct script_data dat;
  2286. dat.type=C_NAME;
  2287. dat.u.num=num;
  2288. dat.ref = ref;
  2289. get_val(st,&dat);
  2290. if( dat.type==C_INT ) return (void*)dat.u.num;
  2291. else return (void*)dat.u.str;
  2292. }
  2293. /*==========================================
  2294. * 変数設定用
  2295. *------------------------------------------
  2296. */
  2297. static int set_reg(struct script_state*st,struct map_session_data *sd,int num,char *name,void *v,struct linkdb_node** ref)
  2298. {
  2299. char prefix=*name;
  2300. char postfix=name[strlen(name)-1];
  2301. if( postfix=='$' ){
  2302. char *str=(char*)v;
  2303. if( prefix=='@'){
  2304. pc_setregstr(sd,num,str);
  2305. }else if(prefix=='$') {
  2306. mapreg_setregstr(num,str);
  2307. }else if(prefix=='#') {
  2308. if( name[1]=='#' )
  2309. pc_setaccountreg2str(sd,name,str);
  2310. else
  2311. pc_setaccountregstr(sd,name,str);
  2312. }else if(prefix=='.') {
  2313. char *p;
  2314. struct linkdb_node **n;
  2315. if( ref ) {
  2316. n = ref;
  2317. } else if( name[1] == '@' ) {
  2318. n = st->stack->var_function;
  2319. } else {
  2320. n = &st->script->script_vars;
  2321. }
  2322. p = linkdb_search(n, (void*)num);
  2323. if(p) {
  2324. linkdb_erase(n, (void*)num);
  2325. aFree(p);
  2326. }
  2327. if( ((char*)v)[0] )
  2328. linkdb_insert(n, (void*)num, aStrdup(v));
  2329. }else{
  2330. pc_setglobalreg_str(sd,name,str);
  2331. } // [zBuffer]
  2332. /*else{
  2333. ShowWarning("script: set_reg: illegal scope string variable !");
  2334. }*/
  2335. }else{
  2336. // 数値
  2337. int val = (int)v;
  2338. if(str_data[num&0x00ffffff].type==C_PARAM){
  2339. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  2340. }else if(prefix=='@') {
  2341. pc_setreg(sd,num,val);
  2342. }else if(prefix=='$') {
  2343. mapreg_setreg(num,val);
  2344. }else if(prefix=='#') {
  2345. if( name[1]=='#' )
  2346. pc_setaccountreg2(sd,name,val);
  2347. else
  2348. pc_setaccountreg(sd,name,val);
  2349. }else if(prefix == '.') {
  2350. struct linkdb_node **n;
  2351. if( ref ) {
  2352. n = ref;
  2353. } else if( name[1] == '@' ) {
  2354. n = st->stack->var_function;
  2355. } else {
  2356. n = &st->script->script_vars;
  2357. }
  2358. if( val == 0 ) {
  2359. linkdb_erase(n, (void*)num);
  2360. } else {
  2361. linkdb_replace(n, (void*)num, (void*)val);
  2362. }
  2363. }else{
  2364. pc_setglobalreg(sd,name,val);
  2365. }
  2366. }
  2367. return 0;
  2368. }
  2369. int set_var(struct map_session_data *sd, char *name, void *val)
  2370. {
  2371. return set_reg(NULL, sd, add_str((unsigned char *) name), name, val, NULL);
  2372. }
  2373. /*==========================================
  2374. * 文字列への変換
  2375. *------------------------------------------
  2376. */
  2377. char* conv_str(struct script_state *st,struct script_data *data)
  2378. {
  2379. get_val(st,data);
  2380. if(data->type==C_INT){
  2381. char *buf;
  2382. buf=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  2383. snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
  2384. data->type=C_STR;
  2385. data->u.str=buf;
  2386. #if 1
  2387. } else if(data->type==C_NAME){
  2388. // テンポラリ。本来無いはず
  2389. data->type=C_CONSTSTR;
  2390. data->u.str=str_buf+str_data[data->u.num].str;
  2391. #endif
  2392. }
  2393. return data->u.str;
  2394. }
  2395. /*==========================================
  2396. * 数値へ変換
  2397. *------------------------------------------
  2398. */
  2399. int conv_num(struct script_state *st,struct script_data *data)
  2400. {
  2401. char *p;
  2402. get_val(st,data);
  2403. if(data->type==C_STR || data->type==C_CONSTSTR){
  2404. p=data->u.str;
  2405. data->u.num = atoi(p);
  2406. if(data->type==C_STR)
  2407. aFree(p);
  2408. data->type=C_INT;
  2409. }
  2410. return data->u.num;
  2411. }
  2412. /*==========================================
  2413. * スタックへ数値をプッシュ
  2414. *------------------------------------------
  2415. */
  2416. void push_val(struct script_stack *stack,int type,int val)
  2417. {
  2418. if(stack->sp >= stack->sp_max){
  2419. stack->sp_max += 64;
  2420. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  2421. sizeof(stack->stack_data[0]) * stack->sp_max);
  2422. memset(stack->stack_data + (stack->sp_max - 64), 0,
  2423. 64 * sizeof(*(stack->stack_data)));
  2424. }
  2425. // if(battle_config.etc_log)
  2426. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  2427. stack->stack_data[stack->sp].type=type;
  2428. stack->stack_data[stack->sp].u.num=val;
  2429. stack->stack_data[stack->sp].ref = NULL;
  2430. stack->sp++;
  2431. }
  2432. /*==========================================
  2433. * スタックへ数値+リファレンスをプッシュ
  2434. *------------------------------------------
  2435. */
  2436. void push_val2(struct script_stack *stack,int type,int val,struct linkdb_node** ref) {
  2437. push_val(stack,type,val);
  2438. stack->stack_data[stack->sp-1].ref = ref;
  2439. }
  2440. /*==========================================
  2441. * スタックへ文字列をプッシュ
  2442. *------------------------------------------
  2443. */
  2444. void push_str(struct script_stack *stack,int type,unsigned char *str)
  2445. {
  2446. if(stack->sp>=stack->sp_max){
  2447. stack->sp_max += 64;
  2448. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  2449. sizeof(stack->stack_data[0]) * stack->sp_max);
  2450. memset(stack->stack_data + (stack->sp_max - 64), '\0',
  2451. 64 * sizeof(*(stack->stack_data)));
  2452. }
  2453. // if(battle_config.etc_log)
  2454. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  2455. stack->stack_data[stack->sp].type=type;
  2456. stack->stack_data[stack->sp].u.str=(char *) str;
  2457. stack->stack_data[stack->sp].ref = NULL;
  2458. stack->sp++;
  2459. }
  2460. /*==========================================
  2461. * スタックへ複製をプッシュ
  2462. *------------------------------------------
  2463. */
  2464. void push_copy(struct script_stack *stack,int pos)
  2465. {
  2466. switch(stack->stack_data[pos].type){
  2467. case C_CONSTSTR:
  2468. push_str(stack,C_CONSTSTR,(unsigned char *) stack->stack_data[pos].u.str);
  2469. break;
  2470. case C_STR:
  2471. push_str(stack,C_STR,(unsigned char *) aStrdup(stack->stack_data[pos].u.str));
  2472. break;
  2473. default:
  2474. push_val2(
  2475. stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num,
  2476. stack->stack_data[pos].ref
  2477. );
  2478. break;
  2479. }
  2480. }
  2481. /*==========================================
  2482. * スタックからポップ
  2483. *------------------------------------------
  2484. */
  2485. void pop_stack(struct script_stack* stack,int start,int end)
  2486. {
  2487. int i;
  2488. for(i=start;i<end;i++){
  2489. if(stack->stack_data[i].type==C_STR){
  2490. aFree(stack->stack_data[i].u.str);
  2491. stack->stack_data[i].type=C_INT; //Might not be correct, but it's done in case to prevent pointer errors later on. [Skotlex]
  2492. }
  2493. }
  2494. if(stack->sp>end){
  2495. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  2496. }
  2497. stack->sp-=end-start;
  2498. }
  2499. /*==========================================
  2500. * スクリプト依存変数、関数依存変数の解放
  2501. *------------------------------------------
  2502. */
  2503. void script_free_vars(struct linkdb_node **node) {
  2504. struct linkdb_node *n = *node;
  2505. while(n) {
  2506. char *name = str_buf + str_data[(int)(n->key)&0x00ffffff].str;
  2507. char postfix = name[strlen(name)-1];
  2508. if( postfix == '$' ) {
  2509. // 文字型変数なので、データ削除
  2510. aFree(n->data);
  2511. }
  2512. n = n->next;
  2513. }
  2514. linkdb_final( node );
  2515. }
  2516. /*==========================================
  2517. * Free's the whole stack. Invoked when clearing a character. [Skotlex]
  2518. *------------------------------------------
  2519. */
  2520. void script_free_stack(struct script_stack* stack)
  2521. {
  2522. int i;
  2523. for (i = 0; i < stack->sp; i++)
  2524. {
  2525. if(stack->stack_data[i].type==C_STR)
  2526. {
  2527. //ShowDebug ("script_free_stack: freeing %p at sp=%d.\n", stack->stack_data[i].u.str, i);
  2528. aFree(stack->stack_data[i].u.str);
  2529. stack->stack_data[i].type = C_INT;
  2530. }else if( i > 0 && stack->stack_data[i].type == C_RETINFO ) {
  2531. struct linkdb_node** n = (struct linkdb_node**)stack->stack_data[i-1].u.num;
  2532. script_free_vars( n );
  2533. aFree( n );
  2534. }
  2535. }
  2536. script_free_vars( stack->var_function );
  2537. aFree(stack->var_function);
  2538. aFree (stack->stack_data);
  2539. aFree (stack);
  2540. }
  2541. void script_free_code(struct script_code* code) {
  2542. script_free_vars( &code->script_vars );
  2543. aFree( code->script_buf );
  2544. aFree( code );
  2545. }
  2546. int axtoi(char *hexStg) {
  2547. int n = 0; // position in string
  2548. int m = 0; // position in digit[] to shift
  2549. int count; // loop index
  2550. int intValue = 0; // integer value of hex string
  2551. int digit[11]; // hold values to convert
  2552. while (n < 10) {
  2553. if (hexStg[n]=='\0')
  2554. break;
  2555. if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
  2556. digit[n] = hexStg[n] & 0x0f; //convert to int
  2557. else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
  2558. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  2559. else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
  2560. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  2561. else break;
  2562. n++;
  2563. }
  2564. count = n;
  2565. m = n - 1;
  2566. n = 0;
  2567. while(n < count) {
  2568. // digit[n] is value of hex digit at position n
  2569. // (m << 2) is the number of positions to shift
  2570. // OR the bits into return value
  2571. intValue = intValue | (digit[n] << (m << 2));
  2572. m--; // adjust the position to set
  2573. n++; // next digit to process
  2574. }
  2575. return (intValue);
  2576. }
  2577. // [Lance] Hex string to integer converter
  2578. int buildin_axtoi(struct script_state *st)
  2579. {
  2580. char *hex = conv_str(st,& (st->stack->stack_data[st->start+2]));
  2581. push_val(st->stack, C_INT, axtoi(hex));
  2582. return 0;
  2583. }
  2584. //
  2585. // 埋め込み関数
  2586. //
  2587. /*==========================================
  2588. *
  2589. *------------------------------------------
  2590. */
  2591. int buildin_mes(struct script_state *st)
  2592. {
  2593. conv_str(st,& (st->stack->stack_data[st->start+2]));
  2594. clif_scriptmes(script_rid2sd(st),st->oid,st->stack->stack_data[st->start+2].u.str);
  2595. return 0;
  2596. }
  2597. /*==========================================
  2598. *
  2599. *------------------------------------------
  2600. */
  2601. int buildin_goto(struct script_state *st)
  2602. {
  2603. int pos;
  2604. if (st->stack->stack_data[st->start+2].type != C_POS){
  2605. int func = st->stack->stack_data[st->start+2].u.num;
  2606. ShowMessage("script: goto '"CL_WHITE"%s"CL_RESET"': not label!\n", str_buf + str_data[func].str);
  2607. st->state = END;
  2608. return 1;
  2609. }
  2610. pos = conv_num(st,& (st->stack->stack_data[st->start+2]));
  2611. st->pos = pos;
  2612. st->state = GOTO;
  2613. return 0;
  2614. }
  2615. /*==========================================
  2616. * ユーザー定義関数の呼び出し
  2617. *------------------------------------------
  2618. */
  2619. int buildin_callfunc(struct script_state *st)
  2620. {
  2621. struct script_code *scr, *oldscr;
  2622. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2623. if( (scr=(struct script_code *) strdb_get(userfunc_db,(unsigned char*)str)) ){
  2624. int i,j;
  2625. struct linkdb_node **oldval = st->stack->var_function;
  2626. for(i=st->start+3,j=0;i<st->end;i++,j++)
  2627. push_copy(st->stack,i);
  2628. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  2629. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  2630. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  2631. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  2632. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  2633. oldscr = st->script;
  2634. st->pos=0;
  2635. st->script=scr;
  2636. st->stack->defsp=st->start+5+j;
  2637. st->state=GOTO;
  2638. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  2639. // ' 変数の引き継ぎ
  2640. for(i = 0; i < j; i++) {
  2641. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  2642. if( s->type == C_NAME && !s->ref ) {
  2643. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  2644. // '@ 変数の引き継ぎ
  2645. if( name[0] == '.' && name[1] == '@' ) {
  2646. s->ref = oldval;
  2647. } else if( name[0] == '.' ) {
  2648. s->ref = &oldscr->script_vars;
  2649. }
  2650. }
  2651. }
  2652. }else{
  2653. ShowWarning("script:callfunc: function not found! [%s]\n",str);
  2654. st->state=END;
  2655. return 1;
  2656. }
  2657. return 0;
  2658. }
  2659. /*==========================================
  2660. * サブルーティンの呼び出し
  2661. *------------------------------------------
  2662. */
  2663. int buildin_callsub(struct script_state *st)
  2664. {
  2665. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2666. int i,j;
  2667. if(st->stack->stack_data[st->start+2].type != C_POS && st->stack->stack_data[st->start+2].type != C_USERFUNC_POS) {
  2668. ShowError("script: callsub: not label !\n");
  2669. st->state=END;
  2670. return 1;
  2671. } else {
  2672. struct linkdb_node **oldval = st->stack->var_function;
  2673. for(i=st->start+3,j=0;i<st->end;i++,j++)
  2674. push_copy(st->stack,i);
  2675. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  2676. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  2677. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  2678. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  2679. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  2680. st->pos=pos;
  2681. st->stack->defsp=st->start+5+j;
  2682. st->state=GOTO;
  2683. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  2684. // ' 変数の引き継ぎ
  2685. for(i = 0; i < j; i++) {
  2686. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  2687. if( s->type == C_NAME && !s->ref ) {
  2688. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  2689. // '@ 変数の引き継ぎ
  2690. if( name[0] == '.' && name[1] == '@' ) {
  2691. s->ref = oldval;
  2692. }
  2693. }
  2694. }
  2695. }
  2696. return 0;
  2697. }
  2698. /*==========================================
  2699. * 引数の所得
  2700. *------------------------------------------
  2701. */
  2702. int buildin_getarg(struct script_state *st)
  2703. {
  2704. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2705. int max,stsp;
  2706. if( st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO ){
  2707. ShowWarning("script:getarg without callfunc or callsub!\n");
  2708. st->state=END;
  2709. return 1;
  2710. }
  2711. max=conv_num(st,& (st->stack->stack_data[st->stack->defsp-5]));
  2712. stsp=st->stack->defsp - max -5;
  2713. if( num >= max ){
  2714. ShowWarning("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  2715. st->state=END;
  2716. return 1;
  2717. }
  2718. push_copy(st->stack,stsp+num);
  2719. return 0;
  2720. }
  2721. /*==========================================
  2722. * サブルーチン/ユーザー定義関数の終了
  2723. *------------------------------------------
  2724. */
  2725. int buildin_return(struct script_state *st)
  2726. {
  2727. if(st->end>st->start+2){ // 戻り値有り
  2728. struct script_data *sd;
  2729. push_copy(st->stack,st->start+2);
  2730. sd = &st->stack->stack_data[st->stack->sp-1];
  2731. if(sd->type == C_NAME) {
  2732. char *name = str_buf + str_data[sd->u.num&0x00ffffff].str;
  2733. if( name[0] == '.' && name[1] == '@') {
  2734. // '@ 変数を参照渡しにすると危険なので値渡しにする
  2735. get_val(st,sd);
  2736. } else if( name[0] == '.' && !sd->ref) {
  2737. // ' 変数は参照渡しでも良いが、参照元が設定されていないと
  2738. // 元のスクリプトの値を差してしまうので補正する。
  2739. sd->ref = &st->script->script_vars;
  2740. }
  2741. }
  2742. }
  2743. st->state=RETFUNC;
  2744. return 0;
  2745. }
  2746. /*==========================================
  2747. *
  2748. *------------------------------------------
  2749. */
  2750. int buildin_next(struct script_state *st)
  2751. {
  2752. st->state=STOP;
  2753. clif_scriptnext(script_rid2sd(st),st->oid);
  2754. return 0;
  2755. }
  2756. /*==========================================
  2757. *
  2758. *------------------------------------------
  2759. */
  2760. int buildin_close(struct script_state *st)
  2761. {
  2762. st->state=END;
  2763. clif_scriptclose(script_rid2sd(st),st->oid);
  2764. return 0;
  2765. }
  2766. int buildin_close2(struct script_state *st)
  2767. {
  2768. st->state=STOP;
  2769. clif_scriptclose(script_rid2sd(st),st->oid);
  2770. return 0;
  2771. }
  2772. /*==========================================
  2773. *
  2774. *------------------------------------------
  2775. */
  2776. int buildin_menu(struct script_state *st)
  2777. {
  2778. char *buf;
  2779. int len,i;
  2780. struct map_session_data *sd;
  2781. sd=script_rid2sd(st);
  2782. if(sd->state.menu_or_input==0){
  2783. st->state=RERUNLINE;
  2784. sd->state.menu_or_input=1;
  2785. for(i=st->start+2,len=16;i<st->end;i+=2){
  2786. conv_str(st,& (st->stack->stack_data[i]));
  2787. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  2788. }
  2789. buf=(char *)aMallocA((len+1)*sizeof(char));
  2790. buf[0]=0;
  2791. for(i=st->start+2,len=0;i<st->end;i+=2){
  2792. strcat(buf,st->stack->stack_data[i].u.str);
  2793. strcat(buf,":");
  2794. }
  2795. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  2796. aFree(buf);
  2797. } else if(sd->npc_menu==0xff){ // cansel
  2798. sd->state.menu_or_input=0;
  2799. st->state=END;
  2800. } else { // goto動作
  2801. sd->state.menu_or_input=0;
  2802. if(sd->npc_menu>0){
  2803. //Skip empty menu entries which weren't displayed on the client (blackhole89)
  2804. for(i=st->start+2;i<=(st->start+sd->npc_menu*2) && sd->npc_menu<(st->end-st->start)/2;i+=2)
  2805. {
  2806. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  2807. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  2808. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  2809. }
  2810. if(sd->npc_menu >= (st->end-st->start)/2) {
  2811. //Invalid selection.
  2812. st->state=END;
  2813. return 0;
  2814. }
  2815. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  2816. ShowError("script: menu: not label !\n");
  2817. st->state=END;
  2818. return 1;
  2819. }
  2820. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  2821. st->pos= conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  2822. st->state=GOTO;
  2823. }
  2824. }
  2825. return 0;
  2826. }
  2827. /*==========================================
  2828. *
  2829. *------------------------------------------
  2830. */
  2831. int buildin_rand(struct script_state *st)
  2832. {
  2833. int range;
  2834. if (st->end > st->start+3){
  2835. int min, max;
  2836. min = conv_num(st,& (st->stack->stack_data[st->start+2]));
  2837. max = conv_num(st,& (st->stack->stack_data[st->start+3]));
  2838. if (max == min){ //Why would someone do this?
  2839. push_val(st->stack,C_INT,min);
  2840. return 0;
  2841. }
  2842. if (max < min){
  2843. int tmp = min;
  2844. min = max;
  2845. max = tmp;
  2846. }
  2847. range = max - min + 1;
  2848. if (range == 0) range = 1;
  2849. push_val(st->stack,C_INT,rand()%range+min);
  2850. } else {
  2851. range = conv_num(st,& (st->stack->stack_data[st->start+2]));
  2852. if (range == 0) range = 1;
  2853. push_val(st->stack,C_INT,rand()%range);
  2854. }
  2855. return 0;
  2856. }
  2857. /*==========================================
  2858. *
  2859. *------------------------------------------
  2860. */
  2861. int buildin_warp(struct script_state *st)
  2862. {
  2863. int x,y;
  2864. char *str;
  2865. struct map_session_data *sd=script_rid2sd(st);
  2866. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2867. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2868. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2869. if(strcmp(str,"Random")==0)
  2870. pc_randomwarp(sd,3);
  2871. else if(strcmp(str,"SavePoint")==0){
  2872. pc_setpos(sd,sd->status.save_point.map,
  2873. sd->status.save_point.x,sd->status.save_point.y,3);
  2874. }else if(strcmp(str,"Save")==0){
  2875. pc_setpos(sd,sd->status.save_point.map,
  2876. sd->status.save_point.x,sd->status.save_point.y,3);
  2877. }else
  2878. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  2879. return 0;
  2880. }
  2881. /*==========================================
  2882. * エリア指定ワープ
  2883. *------------------------------------------
  2884. */
  2885. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  2886. {
  2887. int x,y;
  2888. unsigned int map;
  2889. map=va_arg(ap, unsigned int);
  2890. x=va_arg(ap,int);
  2891. y=va_arg(ap,int);
  2892. if(map == 0)
  2893. pc_randomwarp((struct map_session_data *)bl,3);
  2894. else
  2895. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  2896. return 0;
  2897. }
  2898. int buildin_areawarp(struct script_state *st)
  2899. {
  2900. int x,y,m;
  2901. unsigned int index;
  2902. char *str;
  2903. char *mapname;
  2904. int x0,y0,x1,y1;
  2905. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2906. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2907. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2908. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2909. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  2910. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  2911. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  2912. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  2913. if( (m=map_mapname2mapid(mapname))< 0)
  2914. return 0;
  2915. if(strcmp(str,"Random")==0)
  2916. index = 0;
  2917. else if(!(index=mapindex_name2id(str)))
  2918. return 0;
  2919. map_foreachinarea(buildin_areawarp_sub,
  2920. m,x0,y0,x1,y1,BL_PC, index,x,y );
  2921. return 0;
  2922. }
  2923. /*==========================================
  2924. * warpchar [LuzZza]
  2925. * Useful for warp one player from
  2926. * another player npc-session.
  2927. * Using: warpchar "mapname.gat",x,y,Char_ID;
  2928. *------------------------------------------
  2929. */
  2930. int buildin_warpchar(struct script_state *st)
  2931. {
  2932. int x,y,a,i;
  2933. char *str;
  2934. struct map_session_data *sd, **pl_allsd;
  2935. int users;
  2936. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2937. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2938. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2939. a=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2940. pl_allsd = map_getallusers(&users);
  2941. for(i=0; i<users; i++) {
  2942. sd = pl_allsd[i];
  2943. if(sd->status.char_id == a) {
  2944. if(strcmp(str, "Random") == 0)
  2945. pc_randomwarp(sd, 3);
  2946. else if(strcmp(str, "SavePoint") == 0)
  2947. pc_setpos(sd, sd->status.save_point.map,
  2948. sd->status.save_point.x, sd->status.save_point.y, 3);
  2949. else
  2950. pc_setpos(sd, mapindex_name2id(str), x, y, 3);
  2951. }
  2952. }
  2953. return 0;
  2954. }
  2955. /*==========================================
  2956. * Warpparty - [Fredzilla]
  2957. * Syntax: warpparty "mapname.gat",x,y,Party_ID;
  2958. *------------------------------------------
  2959. */
  2960. int buildin_warpparty(struct script_state *st)
  2961. {
  2962. int x,y;
  2963. char *str;
  2964. int p_id;
  2965. int i;
  2966. unsigned short mapindex;
  2967. struct map_session_data *pl_sd;
  2968. struct party_data *p=NULL;
  2969. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2970. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2971. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2972. p_id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2973. if(p_id < 1)
  2974. return 0;
  2975. p = party_search(p_id);
  2976. if (!p)
  2977. return 0;
  2978. if(strcmp(str,"Random")==0)
  2979. {
  2980. for (i = 0; i < MAX_PARTY; i++)
  2981. {
  2982. if ((pl_sd = p->data[i].sd))
  2983. {
  2984. if(map[pl_sd->bl.m].flag.nowarp)
  2985. continue;
  2986. pc_randomwarp(pl_sd,3);
  2987. }
  2988. }
  2989. }
  2990. else if(strcmp(str,"SavePointAll")==0)
  2991. {
  2992. for (i = 0; i < MAX_PARTY; i++)
  2993. {
  2994. if ((pl_sd = p->data[i].sd))
  2995. {
  2996. if(map[pl_sd->bl.m].flag.noreturn)
  2997. continue;
  2998. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  2999. }
  3000. }
  3001. }
  3002. else if(strcmp(str,"SavePoint")==0)
  3003. {
  3004. pl_sd=script_rid2sd(st);
  3005. if (!pl_sd) return 0;
  3006. mapindex=pl_sd->status.save_point.map;
  3007. x=pl_sd->status.save_point.x;
  3008. y=pl_sd->status.save_point.y;
  3009. for (i = 0; i < MAX_PARTY; i++)
  3010. {
  3011. if ((pl_sd = p->data[i].sd))
  3012. {
  3013. if(map[pl_sd->bl.m].flag.noreturn)
  3014. continue;
  3015. pc_setpos(pl_sd,mapindex,x,y,3);
  3016. }
  3017. }
  3018. }
  3019. else
  3020. {
  3021. mapindex = mapindex_name2id(str);
  3022. if (!mapindex) //Show source of npc error.
  3023. return 1;
  3024. for (i = 0; i < MAX_PARTY; i++)
  3025. {
  3026. if ((pl_sd = p->data[i].sd))
  3027. {
  3028. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  3029. continue;
  3030. pc_setpos(pl_sd,mapindex,x,y,3);
  3031. }
  3032. }
  3033. }
  3034. return 0;
  3035. }
  3036. /*==========================================
  3037. * Warpguild - [Fredzilla]
  3038. * Syntax: warpguild "mapname.gat",x,y,Guild_ID;
  3039. *------------------------------------------
  3040. */
  3041. int buildin_warpguild(struct script_state *st)
  3042. {
  3043. int x,y;
  3044. unsigned short mapindex;
  3045. char *str;
  3046. int g;
  3047. int i;
  3048. struct map_session_data *pl_sd, **pl_allsd;
  3049. int users;
  3050. struct map_session_data *sd;
  3051. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3052. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3053. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3054. g=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3055. sd=script_rid2sd(st);
  3056. if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
  3057. return 0;
  3058. if(g < 1)
  3059. return 0;
  3060. pl_allsd = map_getallusers(&users);
  3061. if(strcmp(str,"Random")==0)
  3062. {
  3063. for (i = 0; i < users; i++)
  3064. {
  3065. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  3066. {
  3067. if(map[pl_sd->bl.m].flag.nowarp)
  3068. continue;
  3069. pc_randomwarp(pl_sd,3);
  3070. }
  3071. }
  3072. }
  3073. else if(strcmp(str,"SavePointAll")==0)
  3074. {
  3075. if(map[sd->bl.m].flag.noreturn)
  3076. return 0;
  3077. for (i = 0; i < users; i++)
  3078. {
  3079. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  3080. {
  3081. if(map[pl_sd->bl.m].flag.noreturn)
  3082. continue;
  3083. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  3084. }
  3085. }
  3086. }
  3087. else if(strcmp(str,"SavePoint")==0)
  3088. {
  3089. if(map[sd->bl.m].flag.noreturn)
  3090. return 0;
  3091. mapindex=sd->status.save_point.map;
  3092. x=sd->status.save_point.x;
  3093. y=sd->status.save_point.y;
  3094. for (i = 0; i < users; i++)
  3095. {
  3096. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  3097. {
  3098. if(map[pl_sd->bl.m].flag.noreturn)
  3099. continue;
  3100. pc_setpos(pl_sd,mapindex,x,y,3);
  3101. }
  3102. }
  3103. }
  3104. else
  3105. {
  3106. mapindex = mapindex_name2id(str);
  3107. for (i = 0; i < users; i++)
  3108. {
  3109. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  3110. {
  3111. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  3112. continue;
  3113. pc_setpos(pl_sd,mapindex,x,y,3);
  3114. }
  3115. }
  3116. }
  3117. return 0;
  3118. }
  3119. /*==========================================
  3120. *
  3121. *------------------------------------------
  3122. */
  3123. int buildin_heal(struct script_state *st)
  3124. {
  3125. struct map_session_data *sd;
  3126. int hp,sp;
  3127. sd = script_rid2sd(st);
  3128. if (!sd) return 0;
  3129. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3130. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3131. status_heal(&sd->bl, hp, sp, 1);
  3132. return 0;
  3133. }
  3134. /*==========================================
  3135. *
  3136. *------------------------------------------
  3137. */
  3138. int buildin_itemheal(struct script_state *st)
  3139. {
  3140. struct map_session_data *sd;
  3141. int hp,sp;
  3142. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3143. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3144. if(potion_flag==1) {
  3145. potion_hp = hp;
  3146. potion_sp = sp;
  3147. return 0;
  3148. }
  3149. sd = script_rid2sd(st);
  3150. if (!sd) return 0;
  3151. pc_itemheal(sd,sd->itemid,hp,sp);
  3152. return 0;
  3153. }
  3154. /*==========================================
  3155. *
  3156. *------------------------------------------
  3157. */
  3158. int buildin_percentheal(struct script_state *st)
  3159. {
  3160. int hp,sp;
  3161. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3162. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3163. if(potion_flag==1) {
  3164. potion_per_hp = hp;
  3165. potion_per_sp = sp;
  3166. return 0;
  3167. }
  3168. pc_percentheal(script_rid2sd(st),hp,sp);
  3169. return 0;
  3170. }
  3171. /*==========================================
  3172. *
  3173. *------------------------------------------
  3174. */
  3175. int buildin_jobchange(struct script_state *st)
  3176. {
  3177. int job, upper=-1;
  3178. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3179. if( st->end>st->start+3 )
  3180. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3181. if ((job >= 0 && job < MAX_PC_CLASS)){
  3182. pc_jobchange(script_rid2sd(st),job, upper);
  3183. if(use_irc && irc_announce_jobchange_flag)
  3184. irc_announce_jobchange(script_rid2sd(st));
  3185. }
  3186. return 0;
  3187. }
  3188. /*==========================================
  3189. *
  3190. *------------------------------------------
  3191. */
  3192. int buildin_input(struct script_state *st)
  3193. {
  3194. struct map_session_data *sd=NULL;
  3195. int num=(st->end>st->start+2)?st->stack->stack_data[st->start+2].u.num:0;
  3196. char *name=(char *) ((st->end>st->start+2)?str_buf+str_data[num&0x00ffffff].str:"");
  3197. // char prefix=*name;
  3198. char postfix=name[strlen(name)-1];
  3199. sd=script_rid2sd(st);
  3200. if(sd->state.menu_or_input){
  3201. sd->state.menu_or_input=0;
  3202. if( postfix=='$' ){
  3203. // 文字列
  3204. if(st->end>st->start+2){ // 引数1個
  3205. set_reg(st,sd,num,name,(void*)sd->npc_str,st->stack->stack_data[st->start+2].ref);
  3206. }else{
  3207. ShowError("buildin_input: string discarded !!\n");
  3208. return 1;
  3209. }
  3210. return 0;
  3211. }
  3212. // commented by Lupus (check Value Number Input fix in clif.c)
  3213. // readded by Yor: set ammount to 0 instead of cancel trade.
  3214. // ** Fix by fritz :X keeps people from abusing old input bugs
  3215. if (sd->npc_amount < 0) { //** If input amount is less then 0
  3216. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  3217. // buildin_close(st); // ** close
  3218. sd->npc_amount = 0;
  3219. } else if ((unsigned int)sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  3220. sd->npc_amount = battle_config.vending_max_value;
  3221. // 数値
  3222. if(st->end>st->start+2){ // 引数1個
  3223. set_reg(st,sd,num,name,(void*)sd->npc_amount,st->stack->stack_data[st->start+2].ref);
  3224. } else {
  3225. // ragemu互換のため
  3226. //pc_setreg(sd,add_str((unsigned char *) "l14"),sd->npc_amount);
  3227. }
  3228. return 0;
  3229. }
  3230. //state.menu_or_input = 0
  3231. st->state=RERUNLINE;
  3232. if(postfix=='$')
  3233. clif_scriptinputstr(sd,st->oid);
  3234. else
  3235. clif_scriptinput(sd,st->oid);
  3236. sd->state.menu_or_input=1;
  3237. return 0;
  3238. }
  3239. /*==========================================
  3240. * 変数設定
  3241. *------------------------------------------
  3242. */
  3243. int buildin_set(struct script_state *st)
  3244. {
  3245. struct map_session_data *sd=NULL;
  3246. int num=st->stack->stack_data[st->start+2].u.num;
  3247. char *name=str_buf+str_data[num&0x00ffffff].str;
  3248. char prefix=*name;
  3249. char postfix=name[strlen(name)-1];
  3250. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  3251. ShowError("script: buildin_set: not name\n");
  3252. return 1;
  3253. }
  3254. if(not_server_variable(prefix))
  3255. sd=script_rid2sd(st);
  3256. if( postfix=='$' ){
  3257. // 文字列
  3258. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  3259. set_reg(st,sd,num,name,(void*)str,st->stack->stack_data[st->start+2].ref);
  3260. }else{
  3261. // 数値
  3262. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  3263. set_reg(st,sd,num,name,(void*)val,st->stack->stack_data[st->start+2].ref);
  3264. }
  3265. return 0;
  3266. }
  3267. /*==========================================
  3268. * 配列変数設定
  3269. *------------------------------------------
  3270. */
  3271. int buildin_setarray(struct script_state *st)
  3272. {
  3273. struct map_session_data *sd=NULL;
  3274. int num=st->stack->stack_data[st->start+2].u.num;
  3275. char *name=str_buf+str_data[num&0x00ffffff].str;
  3276. char prefix=*name;
  3277. char postfix=name[strlen(name)-1];
  3278. int i,j;
  3279. if( prefix!='$' && prefix!='@' && prefix!='.'){
  3280. ShowWarning("buildin_setarray: illegal scope !\n");
  3281. return 1;
  3282. }
  3283. if(not_server_variable(prefix))
  3284. sd=script_rid2sd(st);
  3285. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  3286. void *v;
  3287. if( postfix=='$' )
  3288. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  3289. else
  3290. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  3291. set_reg(st, sd, num+(j<<24), name, v, st->stack->stack_data[st->start+2].ref);
  3292. }
  3293. return 0;
  3294. }
  3295. /*==========================================
  3296. * 配列変数クリア
  3297. *------------------------------------------
  3298. */
  3299. int buildin_cleararray(struct script_state *st)
  3300. {
  3301. struct map_session_data *sd=NULL;
  3302. int num=st->stack->stack_data[st->start+2].u.num;
  3303. char *name=str_buf+str_data[num&0x00ffffff].str;
  3304. char prefix=*name;
  3305. char postfix=name[strlen(name)-1];
  3306. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3307. int i;
  3308. void *v;
  3309. if( prefix!='$' && prefix!='@' && prefix!='.'){
  3310. ShowWarning("buildin_cleararray: illegal scope !\n");
  3311. return 1;
  3312. }
  3313. if( not_server_variable(prefix) )
  3314. sd=script_rid2sd(st);
  3315. if( postfix=='$' )
  3316. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  3317. else
  3318. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  3319. for(i=0;i<sz;i++)
  3320. set_reg(st,sd,num+(i<<24),name,v,st->stack->stack_data[st->start+2].ref);
  3321. return 0;
  3322. }
  3323. /*==========================================
  3324. * 配列変数コピー
  3325. *------------------------------------------
  3326. */
  3327. int buildin_copyarray(struct script_state *st)
  3328. {
  3329. struct map_session_data *sd=NULL;
  3330. int num=st->stack->stack_data[st->start+2].u.num;
  3331. char *name=str_buf+str_data[num&0x00ffffff].str;
  3332. char prefix=*name;
  3333. char postfix=name[strlen(name)-1];
  3334. int num2=st->stack->stack_data[st->start+3].u.num;
  3335. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  3336. char prefix2=*name2;
  3337. char postfix2=name2[strlen(name2)-1];
  3338. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3339. int i;
  3340. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  3341. printf("buildin_copyarray: illeagal scope !\n");
  3342. return 0;
  3343. }
  3344. if( prefix2!='$' && prefix2!='@' && prefix2!='.' ) {
  3345. printf("buildin_copyarray: illeagal scope !\n");
  3346. return 0;
  3347. }
  3348. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  3349. printf("buildin_copyarray: type mismatch !\n");
  3350. return 0;
  3351. }
  3352. if( not_server_variable(prefix) || not_server_variable(prefix2) )
  3353. sd=script_rid2sd(st);
  3354. if((num & 0x00FFFFFF) == (num2 & 0x00FFFFFF) && (num & 0xFF000000) > (num2 & 0xFF000000)) {
  3355. // 同じ配列で、num > num2 の場合大きい方からコピーしないといけない
  3356. for(i=sz-1;i>=0;i--)
  3357. set_reg(
  3358. st,sd,num+(i<<24),name,
  3359. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  3360. st->stack->stack_data[st->start+2].ref
  3361. );
  3362. } else {
  3363. for(i=0;i<sz;i++)
  3364. set_reg(
  3365. st,sd,num+(i<<24),name,
  3366. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  3367. st->stack->stack_data[st->start+2].ref
  3368. );
  3369. }
  3370. return 0;
  3371. }
  3372. /*==========================================
  3373. * 配列変数のサイズ所得
  3374. *------------------------------------------
  3375. */
  3376. static int getarraysize(struct script_state *st,int num,int postfix,struct linkdb_node** ref)
  3377. {
  3378. 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]
  3379. if(postfix == '$'){
  3380. for(;i<128;i++){
  3381. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  3382. if(*((char*)v)) c=i;
  3383. }
  3384. }else{
  3385. for(;i<128;i++){
  3386. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  3387. if((int)v) c=i;
  3388. }
  3389. }
  3390. return c+1;
  3391. }
  3392. int buildin_getarraysize(struct script_state *st)
  3393. {
  3394. int num=st->stack->stack_data[st->start+2].u.num;
  3395. char *name=str_buf+str_data[num&0x00ffffff].str;
  3396. char prefix=*name;
  3397. char postfix=name[strlen(name)-1];
  3398. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  3399. ShowWarning("buildin_copyarray: illegal scope !\n");
  3400. return 1;
  3401. }
  3402. push_val(st->stack,C_INT,getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref));
  3403. return 0;
  3404. }
  3405. /*==========================================
  3406. * 配列変数から要素削除
  3407. *------------------------------------------
  3408. */
  3409. int buildin_deletearray(struct script_state *st)
  3410. {
  3411. struct map_session_data *sd=NULL;
  3412. int num=st->stack->stack_data[st->start+2].u.num;
  3413. char *name=str_buf+str_data[num&0x00ffffff].str;
  3414. char prefix=*name;
  3415. char postfix=name[strlen(name)-1];
  3416. int count=1;
  3417. int i,sz=getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref)-(num>>24)-count+1;
  3418. if( (st->end > st->start+3) )
  3419. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3420. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  3421. ShowWarning("buildin_deletearray: illegal scope !\n");
  3422. return 1;
  3423. }
  3424. if( not_server_variable(prefix) )
  3425. sd=script_rid2sd(st);
  3426. for(i=0;i<sz;i++){
  3427. set_reg(
  3428. st,sd,num+(i<<24),name,
  3429. get_val2(st,num+((i+count)<<24),st->stack->stack_data[st->start+2].ref),
  3430. st->stack->stack_data[st->start+2].ref
  3431. );
  3432. }
  3433. if(postfix != '$'){
  3434. for(;i<(128-(num>>24));i++)
  3435. set_reg(st,sd,num+(i<<24),name, 0,st->stack->stack_data[st->start+2].ref);
  3436. } else {
  3437. for(;i<(128-(num>>24));i++)
  3438. set_reg(st,sd,num+(i<<24),name, (void *) "",st->stack->stack_data[st->start+2].ref);
  3439. }
  3440. return 0;
  3441. }
  3442. /*==========================================
  3443. * 指定要素を表す値(キー)を所得する
  3444. *------------------------------------------
  3445. */
  3446. int buildin_getelementofarray(struct script_state *st)
  3447. {
  3448. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  3449. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3450. if(i>127 || i<0){
  3451. ShowWarning("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  3452. push_val(st->stack,C_INT,0);
  3453. return 1;
  3454. }else{
  3455. push_val2(st->stack,C_NAME,
  3456. (i<<24) | st->stack->stack_data[st->start+2].u.num, st->stack->stack_data[st->start+2].ref );
  3457. }
  3458. }else{
  3459. ShowError("script: getelementofarray (operator[]): param1 not name !\n");
  3460. push_val(st->stack,C_INT,0);
  3461. }
  3462. return 0;
  3463. }
  3464. /*==========================================
  3465. *
  3466. *------------------------------------------
  3467. */
  3468. int buildin_setlook(struct script_state *st)
  3469. {
  3470. int type,val;
  3471. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3472. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3473. pc_changelook(script_rid2sd(st),type,val);
  3474. return 0;
  3475. }
  3476. /*==========================================
  3477. *
  3478. *------------------------------------------
  3479. */
  3480. int buildin_cutin(struct script_state *st)
  3481. {
  3482. int type;
  3483. conv_str(st,& (st->stack->stack_data[st->start+2]));
  3484. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3485. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  3486. return 0;
  3487. }
  3488. /*==========================================
  3489. * カードのイラストを表示する
  3490. *------------------------------------------
  3491. */
  3492. int buildin_cutincard(struct script_state *st)
  3493. {
  3494. int itemid;
  3495. struct item_data *i_data;
  3496. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3497. i_data = itemdb_exists(itemid);
  3498. if (i_data)
  3499. clif_cutin(script_rid2sd(st),i_data->cardillustname,4);
  3500. return 0;
  3501. }
  3502. /*==========================================
  3503. *
  3504. *------------------------------------------
  3505. */
  3506. int buildin_viewpoint(struct script_state *st)
  3507. {
  3508. int type,x,y,id,color;
  3509. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3510. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3511. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3512. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3513. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3514. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  3515. return 0;
  3516. }
  3517. /*==========================================
  3518. *
  3519. *------------------------------------------
  3520. */
  3521. int buildin_countitem(struct script_state *st)
  3522. {
  3523. int nameid=0,count=0,i;
  3524. struct map_session_data *sd;
  3525. struct script_data *data;
  3526. sd = script_rid2sd(st);
  3527. data=&(st->stack->stack_data[st->start+2]);
  3528. get_val(st,data);
  3529. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3530. const char *name=conv_str(st,data);
  3531. struct item_data *item_data;
  3532. if( (item_data = itemdb_searchname(name)) != NULL)
  3533. nameid=item_data->nameid;
  3534. }else
  3535. nameid=conv_num(st,data);
  3536. if (nameid>=500) //if no such ID then skip this iteration
  3537. for(i=0;i<MAX_INVENTORY;i++){
  3538. if(sd->status.inventory[i].nameid==nameid)
  3539. count+=sd->status.inventory[i].amount;
  3540. }
  3541. else{
  3542. if(battle_config.error_log)
  3543. ShowError("wrong item ID : countitem(%i)\n",nameid);
  3544. push_val(st->stack,C_INT,0);
  3545. return 1;
  3546. }
  3547. push_val(st->stack,C_INT,count);
  3548. return 0;
  3549. }
  3550. /*==========================================
  3551. * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
  3552. * returns number of items that met the conditions
  3553. *------------------------------------------
  3554. */
  3555. int buildin_countitem2(struct script_state *st)
  3556. {
  3557. int nameid=0,count=0,i;
  3558. int iden,ref,attr,c1,c2,c3,c4;
  3559. struct map_session_data *sd;
  3560. struct script_data *data;
  3561. sd = script_rid2sd(st);
  3562. data=&(st->stack->stack_data[st->start+2]);
  3563. get_val(st,data);
  3564. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3565. const char *name=conv_str(st,data);
  3566. struct item_data *item_data;
  3567. if( (item_data = itemdb_searchname(name)) != NULL)
  3568. nameid=item_data->nameid;
  3569. }else
  3570. nameid=conv_num(st,data);
  3571. iden=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3572. ref=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3573. attr=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3574. c1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3575. c2=conv_num(st,& (st->stack->stack_data[st->start+7]));
  3576. c3=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3577. c4=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3578. if (nameid>=500) //if no such ID then skip this iteration
  3579. for(i=0;i<MAX_INVENTORY;i++){
  3580. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  3581. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  3582. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  3583. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  3584. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  3585. sd->status.inventory[i].card[3]!=c4)
  3586. continue;
  3587. count+=sd->status.inventory[i].amount;
  3588. }
  3589. else{
  3590. if(battle_config.error_log)
  3591. ShowError("wrong item ID : countitem2(%i)\n",nameid);
  3592. push_val(st->stack,C_INT,0);
  3593. return 1;
  3594. }
  3595. push_val(st->stack,C_INT,count);
  3596. return 0;
  3597. }
  3598. /*==========================================
  3599. * 重量チェック
  3600. *------------------------------------------
  3601. */
  3602. int buildin_checkweight(struct script_state *st)
  3603. {
  3604. int nameid=0,amount,i;
  3605. unsigned long weight;
  3606. struct map_session_data *sd;
  3607. struct script_data *data;
  3608. sd = script_rid2sd(st);
  3609. data=&(st->stack->stack_data[st->start+2]);
  3610. get_val(st,data);
  3611. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3612. const char *name=conv_str(st,data);
  3613. struct item_data *item_data = itemdb_searchname(name);
  3614. if( item_data )
  3615. nameid=item_data->nameid;
  3616. }else
  3617. nameid=conv_num(st,data);
  3618. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3619. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  3620. push_val(st->stack,C_INT,0);
  3621. ShowError("buildin_checkweight: Wrong item ID or amount.\n");
  3622. return 1;
  3623. }
  3624. weight = itemdb_weight(nameid)*amount;
  3625. if(amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight){
  3626. push_val(st->stack,C_INT,0);
  3627. } else {
  3628. //Check if the inventory ain't full.
  3629. //TODO: Currently does not checks if you can just stack it on top of another item you already have....
  3630. i = pc_search_inventory(sd,0);
  3631. if (i >= 0) //Empty slot available.
  3632. push_val(st->stack,C_INT,1);
  3633. else //Inventory full
  3634. push_val(st->stack,C_INT,0);
  3635. }
  3636. return 0;
  3637. }
  3638. /*==========================================
  3639. *
  3640. *------------------------------------------
  3641. */
  3642. int buildin_getitem(struct script_state *st)
  3643. {
  3644. int nameid,amount,flag = 0;
  3645. struct item item_tmp;
  3646. struct map_session_data *sd;
  3647. struct script_data *data;
  3648. sd = script_rid2sd(st);
  3649. data=&(st->stack->stack_data[st->start+2]);
  3650. get_val(st,data);
  3651. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3652. const char *name=conv_str(st,data);
  3653. struct item_data *item_data = itemdb_searchname(name);
  3654. if( item_data == NULL) {
  3655. ShowWarning("buildin_getitem: Nonexistant item %s requested.\n", name);
  3656. return 1; //No item created.
  3657. }
  3658. nameid=item_data->nameid;
  3659. }else
  3660. nameid=conv_num(st,data);
  3661. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0)
  3662. return 0; //return if amount <=0, skip the useles iteration
  3663. //Violet Box, Blue Box, etc - random item pick
  3664. if(nameid <0) {
  3665. nameid=itemdb_searchrandomid(-nameid);
  3666. flag = 1;
  3667. }
  3668. if(nameid <= 0 || !itemdb_exists(nameid)) {
  3669. ShowWarning("buildin_getitem: Nonexistant item %d requested.\n", nameid);
  3670. return 1; //No item created.
  3671. }
  3672. memset(&item_tmp,0,sizeof(item_tmp));
  3673. item_tmp.nameid=nameid;
  3674. if(!flag)
  3675. item_tmp.identify=1;
  3676. else
  3677. item_tmp.identify=itemdb_isidentified(nameid);
  3678. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  3679. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  3680. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  3681. return 0;
  3682. if(pet_create_egg(sd, nameid))
  3683. amount = 1; //This is a pet!
  3684. else
  3685. if((flag = pc_additem(sd,&item_tmp,amount))) {
  3686. clif_additem(sd,0,0,flag);
  3687. if (pc_candrop(sd, &item_tmp))
  3688. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  3689. }
  3690. //Logs items, got from (N)PC scripts [Lupus]
  3691. if(log_config.pick > 0 ) {
  3692. log_pick(sd, "N", 0, nameid, amount, NULL);
  3693. }
  3694. //Logs
  3695. return 0;
  3696. }
  3697. /*==========================================
  3698. *
  3699. *------------------------------------------
  3700. */
  3701. int buildin_getitem2(struct script_state *st)
  3702. {
  3703. int nameid,amount,flag = 0;
  3704. int iden,ref,attr,c1,c2,c3,c4;
  3705. struct item_data *item_data;
  3706. struct item item_tmp;
  3707. struct map_session_data *sd;
  3708. struct script_data *data;
  3709. sd = script_rid2sd(st);
  3710. data=&(st->stack->stack_data[st->start+2]);
  3711. get_val(st,data);
  3712. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3713. const char *name=conv_str(st,data);
  3714. struct item_data *item_data = itemdb_searchname(name);
  3715. nameid=UNKNOWN_ITEM_ID;
  3716. if( item_data )
  3717. nameid=item_data->nameid;
  3718. }else
  3719. nameid=conv_num(st,data);
  3720. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3721. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3722. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3723. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3724. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  3725. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3726. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3727. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  3728. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  3729. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  3730. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  3731. return 0;
  3732. if(nameid<0) { // ランダム
  3733. nameid=itemdb_searchrandomid(-nameid);
  3734. flag = 1;
  3735. }
  3736. if(nameid > 0) {
  3737. memset(&item_tmp,0,sizeof(item_tmp));
  3738. item_data=itemdb_exists(nameid);
  3739. if (item_data == NULL)
  3740. return -1;
  3741. if(item_data->type==4 || item_data->type==5){
  3742. if(ref > 10) ref = 10;
  3743. }
  3744. else if(item_data->type==7) {
  3745. iden = 1;
  3746. ref = 0;
  3747. }
  3748. else {
  3749. iden = 1;
  3750. ref = attr = 0;
  3751. }
  3752. item_tmp.nameid=nameid;
  3753. if(!flag)
  3754. item_tmp.identify=iden;
  3755. else if(item_data->type==4 || item_data->type==5)
  3756. item_tmp.identify=0;
  3757. item_tmp.refine=ref;
  3758. item_tmp.attribute=attr;
  3759. item_tmp.card[0]=c1;
  3760. item_tmp.card[1]=c2;
  3761. item_tmp.card[2]=c3;
  3762. item_tmp.card[3]=c4;
  3763. if((flag = pc_additem(sd,&item_tmp,amount))) {
  3764. clif_additem(sd,0,0,flag);
  3765. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  3766. }
  3767. //Logs items, got from (N)PC scripts [Lupus]
  3768. if(log_config.pick > 0 ) {
  3769. log_pick(sd, "N", 0, nameid, amount, &item_tmp);
  3770. }
  3771. //Logs
  3772. }
  3773. return 0;
  3774. }
  3775. /*==========================================
  3776. * gets an item with someone's name inscribed [Skotlex]
  3777. * getinscribeditem item_num, character_name
  3778. * Returned Qty is always 1, only works on equip-able
  3779. * equipment
  3780. *------------------------------------------
  3781. */
  3782. int buildin_getnameditem(struct script_state *st)
  3783. {
  3784. int nameid;
  3785. struct item item_tmp;
  3786. struct map_session_data *sd, *tsd;
  3787. struct script_data *data;
  3788. sd = script_rid2sd(st);
  3789. if (sd == NULL)
  3790. { //Player not attached!
  3791. push_val(st->stack,C_INT,0);
  3792. return 0;
  3793. }
  3794. data=&(st->stack->stack_data[st->start+2]);
  3795. get_val(st,data);
  3796. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3797. const char *name=conv_str(st,data);
  3798. struct item_data *item_data = itemdb_searchname(name);
  3799. if( item_data == NULL)
  3800. { //Failed
  3801. push_val(st->stack,C_INT,0);
  3802. return 0;
  3803. }
  3804. nameid = item_data->nameid;
  3805. }else
  3806. nameid = conv_num(st,data);
  3807. if(!itemdb_exists(nameid) || itemdb_isstackable(nameid))
  3808. { //We don't allow non-equipable/stackable items to be named
  3809. //to avoid any qty exploits that could happen because of it.
  3810. push_val(st->stack,C_INT,0);
  3811. return 0;
  3812. }
  3813. data=&(st->stack->stack_data[st->start+3]);
  3814. get_val(st,data);
  3815. if( data->type==C_STR || data->type==C_CONSTSTR ) //Char Name
  3816. tsd=map_nick2sd(conv_str(st,data));
  3817. else //Char Id was given
  3818. tsd=map_charid2sd(conv_num(st,data));
  3819. if( tsd == NULL )
  3820. { //Failed
  3821. push_val(st->stack,C_INT,0);
  3822. return 0;
  3823. }
  3824. memset(&item_tmp,0,sizeof(item_tmp));
  3825. item_tmp.nameid=nameid;
  3826. item_tmp.amount=1;
  3827. item_tmp.identify=1;
  3828. item_tmp.card[0]=254; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
  3829. item_tmp.card[2]=tsd->status.char_id;
  3830. item_tmp.card[3]=tsd->status.char_id >> 16;
  3831. if(pc_additem(sd,&item_tmp,1)) {
  3832. push_val(st->stack,C_INT,0);
  3833. return 0; //Failed to add item, we will not drop if they don't fit
  3834. }
  3835. //Logs items, got from (N)PC scripts [Lupus]
  3836. if(log_config.pick > 0 ) {
  3837. log_pick(sd, "N", 0, item_tmp.nameid, item_tmp.amount, &item_tmp);
  3838. }
  3839. //Logs
  3840. push_val(st->stack,C_INT,1);
  3841. return 0;
  3842. }
  3843. /*==========================================
  3844. * gets a random item ID from an item group [Skotlex]
  3845. * groupranditem group_num
  3846. *------------------------------------------
  3847. */
  3848. int buildin_grouprandomitem(struct script_state *st)
  3849. {
  3850. int group;
  3851. group = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3852. push_val(st->stack, C_INT, itemdb_searchrandomid(group));
  3853. return 0;
  3854. }
  3855. /*==========================================
  3856. *
  3857. *------------------------------------------
  3858. */
  3859. int buildin_makeitem(struct script_state *st)
  3860. {
  3861. int nameid,amount,flag = 0;
  3862. int x,y,m;
  3863. char *mapname;
  3864. struct item item_tmp;
  3865. struct script_data *data;
  3866. data=&(st->stack->stack_data[st->start+2]);
  3867. get_val(st,data);
  3868. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3869. const char *name=conv_str(st,data);
  3870. struct item_data *item_data = itemdb_searchname(name);
  3871. nameid=UNKNOWN_ITEM_ID;
  3872. if( item_data )
  3873. nameid=item_data->nameid;
  3874. }else
  3875. nameid=conv_num(st,data);
  3876. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3877. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  3878. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  3879. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  3880. if(strcmp(mapname,"this")==0)
  3881. {
  3882. struct map_session_data *sd;
  3883. sd = script_rid2sd(st);
  3884. if (!sd) return 0; //Failed...
  3885. m=sd->bl.m;
  3886. } else
  3887. m=map_mapname2mapid(mapname);
  3888. if(nameid<0) { // ランダム
  3889. nameid=itemdb_searchrandomid(-nameid);
  3890. flag = 1;
  3891. }
  3892. if(nameid > 0) {
  3893. memset(&item_tmp,0,sizeof(item_tmp));
  3894. item_tmp.nameid=nameid;
  3895. if(!flag)
  3896. item_tmp.identify=1;
  3897. else
  3898. item_tmp.identify=itemdb_isidentified(nameid);
  3899. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  3900. }
  3901. return 0;
  3902. }
  3903. /*==========================================
  3904. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  3905. *------------------------------------------
  3906. */
  3907. int buildin_delitem(struct script_state *st)
  3908. {
  3909. int nameid=0,amount,i,important_item=0;
  3910. struct map_session_data *sd;
  3911. struct script_data *data;
  3912. sd = script_rid2sd(st);
  3913. data=&(st->stack->stack_data[st->start+2]);
  3914. get_val(st,data);
  3915. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3916. const char *name=conv_str(st,data);
  3917. struct item_data *item_data = itemdb_searchname(name);
  3918. //nameid=UNKNOWN_ITEM_ID;
  3919. if( item_data )
  3920. nameid=item_data->nameid;
  3921. }else
  3922. nameid=conv_num(st,data);
  3923. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3924. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  3925. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  3926. return 0;
  3927. }
  3928. //1st pass
  3929. //here we won't delete items with CARDS, named items but we count them
  3930. for(i=0;i<MAX_INVENTORY;i++){
  3931. //we don't delete wrong item or equipped item
  3932. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  3933. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid)
  3934. continue;
  3935. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  3936. if(sd->inventory_data[i]->type==IT_PETEGG &&
  3937. sd->status.inventory[i].card[0] == CARD0_PET)
  3938. {
  3939. if (intif_delete_petdata(MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  3940. continue; //pet couldn't be sent for deletion.
  3941. }
  3942. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  3943. if(itemdb_isspecial(sd->status.inventory[i].card[0]) ||
  3944. sd->status.inventory[i].card[1] ||
  3945. sd->status.inventory[i].card[2] ||
  3946. sd->status.inventory[i].card[3] ||
  3947. sd->status.inventory[i].refine) {
  3948. //this is important item, count it (except for pet eggs)
  3949. if(sd->status.inventory[i].card[0] != CARD0_PET)
  3950. important_item++;
  3951. continue;
  3952. }
  3953. if(sd->status.inventory[i].amount>=amount){
  3954. //Logs items, got from (N)PC scripts [Lupus]
  3955. if(log_config.pick > 0 ) {
  3956. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  3957. }
  3958. //Logs
  3959. pc_delitem(sd,i,amount,0);
  3960. return 0; //we deleted exact amount of items. now exit
  3961. } else {
  3962. amount-=sd->status.inventory[i].amount;
  3963. //Logs items, got from (N)PC scripts [Lupus]
  3964. if(log_config.pick > 0 ) {
  3965. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  3966. }
  3967. //Logs
  3968. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  3969. }
  3970. }
  3971. //2nd pass
  3972. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  3973. if (important_item>0 && amount>0)
  3974. for(i=0;i<MAX_INVENTORY;i++){
  3975. //we don't delete wrong item
  3976. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  3977. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  3978. continue;
  3979. if(sd->status.inventory[i].amount>=amount){
  3980. //Logs items, got from (N)PC scripts [Lupus]
  3981. if(log_config.pick > 0 ) {
  3982. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  3983. }
  3984. //Logs
  3985. pc_delitem(sd,i,amount,0);
  3986. return 0; //we deleted exact amount of items. now exit
  3987. } else {
  3988. amount-=sd->status.inventory[i].amount;
  3989. //Logs items, got from (N)PC scripts [Lupus]
  3990. if(log_config.pick > 0 ) {
  3991. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  3992. }
  3993. //Logs
  3994. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  3995. }
  3996. }
  3997. return 0;
  3998. }
  3999. /*==========================================
  4000. * advanced version of delitem [modified by Mihilion]
  4001. *------------------------------------------
  4002. */
  4003. int buildin_delitem2(struct script_state *st)
  4004. {
  4005. int nameid=0,amount,i=0;
  4006. int iden,ref,attr,c1,c2,c3,c4;
  4007. struct map_session_data *sd;
  4008. struct script_data *data;
  4009. sd = script_rid2sd(st);
  4010. data=&(st->stack->stack_data[st->start+2]);
  4011. get_val(st,data);
  4012. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4013. const char *name=conv_str(st,data);
  4014. struct item_data *item_data = itemdb_searchname(name);
  4015. //nameid=UNKNOWN_ITEM_ID;
  4016. if( item_data )
  4017. nameid=item_data->nameid;
  4018. }else
  4019. nameid=conv_num(st,data);
  4020. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4021. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4022. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4023. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4024. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4025. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4026. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4027. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  4028. if (!itemdb_exists(nameid) || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  4029. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  4030. return 0;
  4031. }
  4032. for(i=0;i<MAX_INVENTORY;i++){
  4033. //we don't delete wrong item or equipped item
  4034. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  4035. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  4036. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  4037. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  4038. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  4039. sd->status.inventory[i].card[3]!=c4)
  4040. continue;
  4041. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  4042. if(sd->inventory_data[i]->type==IT_PETEGG && sd->status.inventory[i].card[0] == CARD0_PET)
  4043. {
  4044. if (!intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  4045. continue; //Failed to send delete the pet.
  4046. }
  4047. if(sd->status.inventory[i].amount>=amount){
  4048. //Logs items, got from (N)PC scripts [Lupus]
  4049. if(log_config.pick > 0 ) {
  4050. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  4051. }
  4052. //Logs
  4053. pc_delitem(sd,i,amount,0);
  4054. return 0; //we deleted exact amount of items. now exit
  4055. } else {
  4056. amount-=sd->status.inventory[i].amount;
  4057. //Logs items, got from (N)PC scripts [Lupus]
  4058. if(log_config.pick > 0 ) {
  4059. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  4060. }
  4061. //Logs
  4062. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  4063. }
  4064. }
  4065. return 0;
  4066. }
  4067. /*==========================================
  4068. * Enables/Disables use of items while in an NPC [Skotlex]
  4069. *------------------------------------------
  4070. */
  4071. int buildin_enableitemuse(struct script_state *st) {
  4072. struct map_session_data *sd;
  4073. sd=script_rid2sd(st);
  4074. if (sd)
  4075. sd->npc_item_flag = st->oid;
  4076. return 0;
  4077. }
  4078. int buildin_disableitemuse(struct script_state *st) {
  4079. struct map_session_data *sd;
  4080. sd=script_rid2sd(st);
  4081. if (sd)
  4082. sd->npc_item_flag = 0;
  4083. return 0;
  4084. }
  4085. /*==========================================
  4086. *キャラ関係のパラメータ取得
  4087. *------------------------------------------
  4088. */
  4089. int buildin_readparam(struct script_state *st)
  4090. {
  4091. int type;
  4092. struct map_session_data *sd;
  4093. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4094. if( st->end>st->start+3 )
  4095. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  4096. else
  4097. sd=script_rid2sd(st);
  4098. if(sd==NULL){
  4099. push_val(st->stack,C_INT,-1);
  4100. return 0;
  4101. }
  4102. push_val(st->stack,C_INT,pc_readparam(sd,type));
  4103. return 0;
  4104. }
  4105. /*==========================================
  4106. *キャラ関係のID取得
  4107. *------------------------------------------
  4108. */
  4109. int buildin_getcharid(struct script_state *st)
  4110. {
  4111. int num;
  4112. struct map_session_data *sd;
  4113. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4114. if( st->end>st->start+3 )
  4115. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  4116. else
  4117. sd=script_rid2sd(st);
  4118. if(sd==NULL){
  4119. push_val(st->stack,C_INT,-1);
  4120. return 0;
  4121. }
  4122. if(num==0)
  4123. push_val(st->stack,C_INT,sd->status.char_id);
  4124. if(num==1)
  4125. push_val(st->stack,C_INT,sd->status.party_id);
  4126. if(num==2)
  4127. push_val(st->stack,C_INT,sd->status.guild_id);
  4128. if(num==3)
  4129. push_val(st->stack,C_INT,sd->status.account_id);
  4130. return 0;
  4131. }
  4132. /*==========================================
  4133. *指定IDのPT名取得
  4134. *------------------------------------------
  4135. */
  4136. char *buildin_getpartyname_sub(int party_id)
  4137. {
  4138. struct party_data *p;
  4139. p=party_search(party_id);
  4140. if(p!=NULL){
  4141. char *buf;
  4142. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  4143. memcpy(buf, p->party.name, NAME_LENGTH-1);
  4144. buf[NAME_LENGTH-1] = '\0';
  4145. return buf;
  4146. }
  4147. return 0;
  4148. }
  4149. int buildin_getpartyname(struct script_state *st)
  4150. {
  4151. char *name;
  4152. int party_id;
  4153. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4154. name=buildin_getpartyname_sub(party_id);
  4155. if(name != NULL)
  4156. push_str(st->stack,C_STR,(unsigned char *)name);
  4157. else
  4158. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  4159. return 0;
  4160. }
  4161. /*==========================================
  4162. *指定IDのPT人数とメンバーID取得
  4163. *------------------------------------------
  4164. */
  4165. int buildin_getpartymember(struct script_state *st)
  4166. {
  4167. struct party_data *p;
  4168. int i,j=0,type=0;
  4169. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  4170. if( st->end>st->start+3 )
  4171. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4172. if(p!=NULL){
  4173. for(i=0;i<MAX_PARTY;i++){
  4174. if(p->party.member[i].account_id){
  4175. switch (type) {
  4176. case 2:
  4177. mapreg_setreg(add_str((unsigned char *) "$@partymemberaid")+(j<<24),p->party.member[i].account_id);
  4178. break;
  4179. case 1:
  4180. mapreg_setreg(add_str((unsigned char *) "$@partymembercid")+(j<<24),p->party.member[i].char_id);
  4181. break;
  4182. default:
  4183. mapreg_setregstr(add_str((unsigned char *) "$@partymembername$")+(j<<24),p->party.member[i].name);
  4184. }
  4185. j++;
  4186. }
  4187. }
  4188. }
  4189. mapreg_setreg(add_str((unsigned char *) "$@partymembercount"),j);
  4190. return 0;
  4191. }
  4192. /*==========================================
  4193. *指定IDのギルド名取得
  4194. *------------------------------------------
  4195. */
  4196. char *buildin_getguildname_sub(int guild_id)
  4197. {
  4198. struct guild *g=NULL;
  4199. g=guild_search(guild_id);
  4200. if(g!=NULL){
  4201. char *buf;
  4202. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  4203. memcpy(buf, g->name, NAME_LENGTH-1);
  4204. buf[NAME_LENGTH-1] = '\0';
  4205. return buf;
  4206. }
  4207. return NULL;
  4208. }
  4209. int buildin_getguildname(struct script_state *st)
  4210. {
  4211. char *name;
  4212. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4213. name=buildin_getguildname_sub(guild_id);
  4214. if(name != NULL)
  4215. push_str(st->stack,C_STR,(unsigned char *) name);
  4216. else
  4217. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  4218. return 0;
  4219. }
  4220. /*==========================================
  4221. *指定IDのGuildMaster名取得
  4222. *------------------------------------------
  4223. */
  4224. char *buildin_getguildmaster_sub(int guild_id)
  4225. {
  4226. struct guild *g=NULL;
  4227. g=guild_search(guild_id);
  4228. if(g!=NULL){
  4229. char *buf;
  4230. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  4231. memcpy(buf, g->master, NAME_LENGTH-1);
  4232. buf[NAME_LENGTH-1] = '\0';
  4233. return buf;
  4234. }
  4235. return 0;
  4236. }
  4237. int buildin_getguildmaster(struct script_state *st)
  4238. {
  4239. char *master;
  4240. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4241. master=buildin_getguildmaster_sub(guild_id);
  4242. if(master!=0)
  4243. push_str(st->stack,C_STR,(unsigned char *) master);
  4244. else
  4245. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  4246. return 0;
  4247. }
  4248. int buildin_getguildmasterid(struct script_state *st)
  4249. {
  4250. char *master;
  4251. struct map_session_data *sd=NULL;
  4252. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4253. master=buildin_getguildmaster_sub(guild_id);
  4254. if(master!=0){
  4255. if((sd=map_nick2sd(master)) == NULL){
  4256. push_val(st->stack,C_INT,0);
  4257. return 0;
  4258. }
  4259. push_val(st->stack,C_INT,sd->status.char_id);
  4260. }else{
  4261. push_val(st->stack,C_INT,0);
  4262. }
  4263. return 0;
  4264. }
  4265. /*==========================================
  4266. * キャラクタの名前
  4267. *------------------------------------------
  4268. */
  4269. int buildin_strcharinfo(struct script_state *st)
  4270. {
  4271. struct map_session_data *sd;
  4272. int num;
  4273. char *buf;
  4274. sd=script_rid2sd(st);
  4275. if (!sd) { //Avoid crashing....
  4276. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  4277. return 0;
  4278. }
  4279. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4280. switch(num){
  4281. case 0:
  4282. push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->status.name);
  4283. break;
  4284. case 1:
  4285. buf=buildin_getpartyname_sub(sd->status.party_id);
  4286. if(buf!=0)
  4287. push_str(st->stack,C_STR,(unsigned char *) buf);
  4288. else
  4289. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  4290. break;
  4291. case 2:
  4292. buf=buildin_getguildname_sub(sd->status.guild_id);
  4293. if(buf != NULL)
  4294. push_str(st->stack,C_STR,(unsigned char *) buf);
  4295. else
  4296. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  4297. break;
  4298. default:
  4299. ShowWarning("buildin_strcharinfo: unknown parameter.");
  4300. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  4301. break;
  4302. }
  4303. return 0;
  4304. }
  4305. 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};
  4306. /*==========================================
  4307. * GetEquipID(Pos); Pos: 1-10
  4308. *------------------------------------------
  4309. */
  4310. int buildin_getequipid(struct script_state *st)
  4311. {
  4312. int i,num;
  4313. struct map_session_data *sd;
  4314. struct item_data* item;
  4315. sd=script_rid2sd(st);
  4316. if(sd == NULL)
  4317. {
  4318. ShowError("getequipid: sd == NULL\n");
  4319. return 0;
  4320. }
  4321. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4322. i=pc_checkequip(sd,equip[num-1]);
  4323. if(i >= 0){
  4324. item=sd->inventory_data[i];
  4325. if(item)
  4326. push_val(st->stack,C_INT,item->nameid);
  4327. else
  4328. push_val(st->stack,C_INT,0);
  4329. }else{
  4330. push_val(st->stack,C_INT,-1);
  4331. }
  4332. return 0;
  4333. }
  4334. /*==========================================
  4335. * 装備名文字列(精錬メニュー用)
  4336. *------------------------------------------
  4337. */
  4338. int buildin_getequipname(struct script_state *st)
  4339. {
  4340. int i,num;
  4341. struct map_session_data *sd;
  4342. struct item_data* item;
  4343. char *buf;
  4344. buf=(char *)aMallocA(64*sizeof(char));
  4345. sd=script_rid2sd(st);
  4346. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4347. i=pc_checkequip(sd,equip[num-1]);
  4348. if(i >= 0){
  4349. item=sd->inventory_data[i];
  4350. if(item)
  4351. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  4352. else
  4353. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  4354. }else{
  4355. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  4356. }
  4357. push_str(st->stack,C_STR,(unsigned char *) buf);
  4358. return 0;
  4359. }
  4360. /*==========================================
  4361. * getbrokenid [Valaris]
  4362. *------------------------------------------
  4363. */
  4364. int buildin_getbrokenid(struct script_state *st)
  4365. {
  4366. int i,num,id=0,brokencounter=0;
  4367. struct map_session_data *sd;
  4368. sd=script_rid2sd(st);
  4369. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4370. for(i=0; i<MAX_INVENTORY; i++) {
  4371. if(sd->status.inventory[i].attribute==1){
  4372. brokencounter++;
  4373. if(num==brokencounter){
  4374. id=sd->status.inventory[i].nameid;
  4375. break;
  4376. }
  4377. }
  4378. }
  4379. push_val(st->stack,C_INT,id);
  4380. return 0;
  4381. }
  4382. /*==========================================
  4383. * repair [Valaris]
  4384. *------------------------------------------
  4385. */
  4386. int buildin_repair(struct script_state *st)
  4387. {
  4388. int i,num;
  4389. int repaircounter=0;
  4390. struct map_session_data *sd;
  4391. sd=script_rid2sd(st);
  4392. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4393. for(i=0; i<MAX_INVENTORY; i++) {
  4394. if(sd->status.inventory[i].attribute==1){
  4395. repaircounter++;
  4396. if(num==repaircounter){
  4397. sd->status.inventory[i].attribute=0;
  4398. clif_equiplist(sd);
  4399. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  4400. clif_misceffect(&sd->bl, 3);
  4401. clif_displaymessage(sd->fd,"Item has been repaired.");
  4402. break;
  4403. }
  4404. }
  4405. }
  4406. return 0;
  4407. }
  4408. /*==========================================
  4409. * 装備チェック
  4410. *------------------------------------------
  4411. */
  4412. int buildin_getequipisequiped(struct script_state *st)
  4413. {
  4414. int i,num;
  4415. struct map_session_data *sd;
  4416. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4417. sd=script_rid2sd(st);
  4418. if ((num - 1) >= (sizeof(equip) / sizeof(equip[0])))
  4419. i = -1;
  4420. else
  4421. i=pc_checkequip(sd,equip[num-1]);
  4422. if(i >= 0)
  4423. push_val(st->stack,C_INT,1);
  4424. else
  4425. push_val(st->stack,C_INT,0);
  4426. return 0;
  4427. }
  4428. /*==========================================
  4429. * 装備品精錬可能チェック
  4430. *------------------------------------------
  4431. */
  4432. int buildin_getequipisenableref(struct script_state *st)
  4433. {
  4434. int i,num;
  4435. struct map_session_data *sd;
  4436. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4437. sd=script_rid2sd(st);
  4438. i=pc_checkequip(sd,equip[num-1]);
  4439. if(i >= 0 && num<7 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
  4440. {
  4441. push_val(st->stack,C_INT,1);
  4442. } else {
  4443. push_val(st->stack,C_INT,0);
  4444. }
  4445. return 0;
  4446. }
  4447. /*==========================================
  4448. * 装備品鑑定チェック
  4449. *------------------------------------------
  4450. */
  4451. int buildin_getequipisidentify(struct script_state *st)
  4452. {
  4453. int i,num;
  4454. struct map_session_data *sd;
  4455. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4456. sd=script_rid2sd(st);
  4457. i=pc_checkequip(sd,equip[num-1]);
  4458. if(i >= 0)
  4459. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  4460. else
  4461. push_val(st->stack,C_INT,0);
  4462. return 0;
  4463. }
  4464. /*==========================================
  4465. * 装備品精錬度
  4466. *------------------------------------------
  4467. */
  4468. int buildin_getequiprefinerycnt(struct script_state *st)
  4469. {
  4470. int i,num;
  4471. struct map_session_data *sd;
  4472. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4473. sd=script_rid2sd(st);
  4474. i=pc_checkequip(sd,equip[num-1]);
  4475. if(i >= 0)
  4476. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  4477. else
  4478. push_val(st->stack,C_INT,0);
  4479. return 0;
  4480. }
  4481. /*==========================================
  4482. * 装備品武器LV
  4483. *------------------------------------------
  4484. */
  4485. int buildin_getequipweaponlv(struct script_state *st)
  4486. {
  4487. int i,num;
  4488. struct map_session_data *sd;
  4489. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4490. sd=script_rid2sd(st);
  4491. i=pc_checkequip(sd,equip[num-1]);
  4492. if(i >= 0 && sd->inventory_data[i])
  4493. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  4494. else
  4495. push_val(st->stack,C_INT,0);
  4496. return 0;
  4497. }
  4498. /*==========================================
  4499. * 装備品精錬成功率
  4500. *------------------------------------------
  4501. */
  4502. int buildin_getequippercentrefinery(struct script_state *st)
  4503. {
  4504. int i,num;
  4505. struct map_session_data *sd;
  4506. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4507. sd=script_rid2sd(st);
  4508. i=pc_checkequip(sd,equip[num-1]);
  4509. if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
  4510. push_val(st->stack,C_INT,percentrefinery[itemdb_wlv(sd->status.inventory[i].nameid)][(int)sd->status.inventory[i].refine]);
  4511. else
  4512. push_val(st->stack,C_INT,0);
  4513. return 0;
  4514. }
  4515. /*==========================================
  4516. * 精錬成功
  4517. *------------------------------------------
  4518. */
  4519. int buildin_successrefitem(struct script_state *st)
  4520. {
  4521. int i,num,ep;
  4522. struct map_session_data *sd;
  4523. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4524. sd=script_rid2sd(st);
  4525. i=pc_checkequip(sd,equip[num-1]);
  4526. if(i >= 0) {
  4527. ep=sd->status.inventory[i].equip;
  4528. //Logs items, got from (N)PC scripts [Lupus]
  4529. if(log_config.pick > 0 ) {
  4530. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  4531. }
  4532. //Logs
  4533. sd->status.inventory[i].refine++;
  4534. pc_unequipitem(sd,i,2);
  4535. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  4536. clif_delitem(sd,i,1);
  4537. //Logs items, got from (N)PC scripts [Lupus]
  4538. if(log_config.pick > 0 ) {
  4539. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]);
  4540. }
  4541. //Logs
  4542. clif_additem(sd,i,1,0);
  4543. pc_equipitem(sd,i,ep);
  4544. clif_misceffect(&sd->bl,3);
  4545. if(sd->status.inventory[i].refine == MAX_REFINE &&
  4546. sd->status.inventory[i].card[0] == CARD0_FORGE &&
  4547. sd->char_id == MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])
  4548. ){ // Fame point system [DracoRPG]
  4549. switch (sd->inventory_data[i]->wlv){
  4550. case 1:
  4551. pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
  4552. break;
  4553. case 2:
  4554. pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
  4555. break;
  4556. case 3:
  4557. pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
  4558. break;
  4559. }
  4560. }
  4561. }
  4562. return 0;
  4563. }
  4564. /*==========================================
  4565. * 精錬失敗
  4566. *------------------------------------------
  4567. */
  4568. int buildin_failedrefitem(struct script_state *st)
  4569. {
  4570. int i,num;
  4571. struct map_session_data *sd;
  4572. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4573. sd=script_rid2sd(st);
  4574. i=pc_checkequip(sd,equip[num-1]);
  4575. if(i >= 0) {
  4576. //Logs items, got from (N)PC scripts [Lupus]
  4577. if(log_config.pick > 0 ) {
  4578. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  4579. }
  4580. //Logs
  4581. sd->status.inventory[i].refine = 0;
  4582. pc_unequipitem(sd,i,3);
  4583. // 精錬失敗エフェクトのパケット
  4584. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  4585. pc_delitem(sd,i,1,0);
  4586. // 他の人にも失敗を通知
  4587. clif_misceffect(&sd->bl,2);
  4588. }
  4589. return 0;
  4590. }
  4591. /*==========================================
  4592. *
  4593. *------------------------------------------
  4594. */
  4595. int buildin_statusup(struct script_state *st)
  4596. {
  4597. int type;
  4598. struct map_session_data *sd;
  4599. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4600. sd=script_rid2sd(st);
  4601. pc_statusup(sd,type);
  4602. return 0;
  4603. }
  4604. /*==========================================
  4605. *
  4606. *------------------------------------------
  4607. */
  4608. int buildin_statusup2(struct script_state *st)
  4609. {
  4610. int type,val;
  4611. struct map_session_data *sd;
  4612. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4613. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4614. sd=script_rid2sd(st);
  4615. pc_statusup2(sd,type,val);
  4616. return 0;
  4617. }
  4618. /*==========================================
  4619. * 装備品による能力値ボーナス
  4620. *------------------------------------------
  4621. */
  4622. int buildin_bonus(struct script_state *st)
  4623. {
  4624. int type,val;
  4625. struct map_session_data *sd;
  4626. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4627. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4628. sd=script_rid2sd(st);
  4629. pc_bonus(sd,type,val);
  4630. return 0;
  4631. }
  4632. /*==========================================
  4633. * 装備品による能力値ボーナス
  4634. *------------------------------------------
  4635. */
  4636. int buildin_bonus2(struct script_state *st)
  4637. {
  4638. int type,type2,val;
  4639. struct map_session_data *sd;
  4640. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4641. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4642. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4643. sd=script_rid2sd(st);
  4644. pc_bonus2(sd,type,type2,val);
  4645. return 0;
  4646. }
  4647. /*==========================================
  4648. * 装備品による能力値ボーナス
  4649. *------------------------------------------
  4650. */
  4651. int buildin_bonus3(struct script_state *st)
  4652. {
  4653. int type,type2,type3,val;
  4654. struct map_session_data *sd;
  4655. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4656. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4657. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4658. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4659. sd=script_rid2sd(st);
  4660. pc_bonus3(sd,type,type2,type3,val);
  4661. return 0;
  4662. }
  4663. int buildin_bonus4(struct script_state *st)
  4664. {
  4665. int type,type2,type3,type4,val;
  4666. struct map_session_data *sd;
  4667. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4668. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4669. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4670. type4=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4671. val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4672. sd=script_rid2sd(st);
  4673. pc_bonus4(sd,type,type2,type3,type4,val);
  4674. return 0;
  4675. }
  4676. /*==========================================
  4677. * スキル所得
  4678. *------------------------------------------
  4679. */
  4680. int buildin_skill(struct script_state *st)
  4681. {
  4682. int id,level,flag=1;
  4683. struct map_session_data *sd;
  4684. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4685. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4686. if( st->end>st->start+4 )
  4687. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  4688. sd=script_rid2sd(st);
  4689. pc_skill(sd,id,level,flag);
  4690. return 0;
  4691. }
  4692. // add x levels of skill (stackable) [Valaris]
  4693. int buildin_addtoskill(struct script_state *st)
  4694. {
  4695. int id,level,flag=2;
  4696. struct map_session_data *sd;
  4697. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4698. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4699. if( st->end>st->start+4 )
  4700. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  4701. sd=script_rid2sd(st);
  4702. pc_skill(sd,id,level,flag);
  4703. return 0;
  4704. }
  4705. /*==========================================
  4706. * ギルドスキル取得
  4707. *------------------------------------------
  4708. */
  4709. int buildin_guildskill(struct script_state *st)
  4710. {
  4711. int id,level,flag=0;
  4712. struct map_session_data *sd;
  4713. int i=0;
  4714. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4715. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4716. if( st->end>st->start+4 )
  4717. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  4718. sd=script_rid2sd(st);
  4719. for(i=0;i<level;i++)
  4720. guild_skillup(sd,id,flag);
  4721. return 0;
  4722. }
  4723. /*==========================================
  4724. * スキルレベル所得
  4725. *------------------------------------------
  4726. */
  4727. int buildin_getskilllv(struct script_state *st)
  4728. {
  4729. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4730. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  4731. return 0;
  4732. }
  4733. /*==========================================
  4734. * getgdskilllv(Guild_ID, Skill_ID);
  4735. * skill_id = 10000 : GD_APPROVAL
  4736. * 10001 : GD_KAFRACONTRACT
  4737. * 10002 : GD_GUARDIANRESEARCH
  4738. * 10003 : GD_GUARDUP
  4739. * 10004 : GD_EXTENSION
  4740. *------------------------------------------
  4741. */
  4742. int buildin_getgdskilllv(struct script_state *st)
  4743. {
  4744. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4745. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4746. struct guild *g=guild_search(guild_id);
  4747. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  4748. return 0;
  4749. /*
  4750. struct map_session_data *sd=NULL;
  4751. struct guild *g=NULL;
  4752. int skill_id;
  4753. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4754. sd=script_rid2sd(st);
  4755. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  4756. if(sd && g) {
  4757. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  4758. } else {
  4759. push_val(st->stack,C_INT,-1);
  4760. }
  4761. return 0;
  4762. */
  4763. }
  4764. /*==========================================
  4765. *
  4766. *------------------------------------------
  4767. */
  4768. int buildin_basicskillcheck(struct script_state *st)
  4769. {
  4770. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  4771. return 0;
  4772. }
  4773. /*==========================================
  4774. *
  4775. *------------------------------------------
  4776. */
  4777. int buildin_getgmlevel(struct script_state *st)
  4778. {
  4779. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  4780. return 0;
  4781. }
  4782. /*==========================================
  4783. *
  4784. *------------------------------------------
  4785. */
  4786. int buildin_end(struct script_state *st)
  4787. {
  4788. st->state = END;
  4789. return 0;
  4790. }
  4791. /*==========================================
  4792. *
  4793. *------------------------------------------
  4794. */
  4795. int buildin_checkoption(struct script_state *st)
  4796. {
  4797. int type;
  4798. struct map_session_data *sd;
  4799. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4800. sd=script_rid2sd(st);
  4801. if(sd->sc.option & type){
  4802. push_val(st->stack,C_INT,1);
  4803. } else {
  4804. push_val(st->stack,C_INT,0);
  4805. }
  4806. return 0;
  4807. }
  4808. /*==========================================
  4809. *
  4810. *------------------------------------------
  4811. */
  4812. int buildin_checkoption1(struct script_state *st)
  4813. {
  4814. int type;
  4815. struct map_session_data *sd;
  4816. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4817. sd=script_rid2sd(st);
  4818. if(sd->sc.opt1 & type){
  4819. push_val(st->stack,C_INT,1);
  4820. } else {
  4821. push_val(st->stack,C_INT,0);
  4822. }
  4823. return 0;
  4824. }
  4825. /*==========================================
  4826. *
  4827. *------------------------------------------
  4828. */
  4829. int buildin_checkoption2(struct script_state *st)
  4830. {
  4831. int type;
  4832. struct map_session_data *sd;
  4833. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4834. sd=script_rid2sd(st);
  4835. if(sd->sc.opt2 & type){
  4836. push_val(st->stack,C_INT,1);
  4837. } else {
  4838. push_val(st->stack,C_INT,0);
  4839. }
  4840. return 0;
  4841. }
  4842. /*==========================================
  4843. *
  4844. *------------------------------------------
  4845. */
  4846. int buildin_setoption(struct script_state *st)
  4847. {
  4848. int type;
  4849. struct map_session_data *sd;
  4850. int flag=1;
  4851. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4852. if(st->end>st->start+3 )
  4853. flag=conv_num(st,&(st->stack->stack_data[st->start+3]) );
  4854. else if (!type) { //Request to remove everything.
  4855. flag = 0;
  4856. type = OPTION_CART|OPTION_FALCON|OPTION_RIDING;
  4857. }
  4858. sd=script_rid2sd(st);
  4859. if (!sd) return 0;
  4860. if (flag) {//Add option
  4861. if (type&OPTION_WEDDING && !battle_config.wedding_modifydisplay)
  4862. type&=~OPTION_WEDDING; //Do not show the wedding sprites
  4863. pc_setoption(sd,sd->sc.option|type);
  4864. } else//Remove option
  4865. pc_setoption(sd,sd->sc.option&~type);
  4866. return 0;
  4867. }
  4868. /*==========================================
  4869. * Checkcart [Valaris]
  4870. *------------------------------------------
  4871. */
  4872. int buildin_checkcart(struct script_state *st)
  4873. {
  4874. struct map_session_data *sd;
  4875. sd=script_rid2sd(st);
  4876. if(pc_iscarton(sd)){
  4877. push_val(st->stack,C_INT,1);
  4878. } else {
  4879. push_val(st->stack,C_INT,0);
  4880. }
  4881. return 0;
  4882. }
  4883. /*==========================================
  4884. * カートを付ける
  4885. *------------------------------------------
  4886. */
  4887. int buildin_setcart(struct script_state *st)
  4888. {
  4889. struct map_session_data *sd;
  4890. sd=script_rid2sd(st);
  4891. pc_setcart(sd,1);
  4892. return 0;
  4893. }
  4894. /*==========================================
  4895. * checkfalcon [Valaris]
  4896. *------------------------------------------
  4897. */
  4898. int buildin_checkfalcon(struct script_state *st)
  4899. {
  4900. struct map_session_data *sd;
  4901. sd=script_rid2sd(st);
  4902. if(pc_isfalcon(sd)){
  4903. push_val(st->stack,C_INT,1);
  4904. } else {
  4905. push_val(st->stack,C_INT,0);
  4906. }
  4907. return 0;
  4908. }
  4909. /*==========================================
  4910. * 鷹を付ける
  4911. *------------------------------------------
  4912. */
  4913. int buildin_setfalcon(struct script_state *st)
  4914. {
  4915. struct map_session_data *sd;
  4916. sd=script_rid2sd(st);
  4917. pc_setfalcon(sd);
  4918. return 0;
  4919. }
  4920. /*==========================================
  4921. * Checkcart [Valaris]
  4922. *------------------------------------------
  4923. */
  4924. int buildin_checkriding(struct script_state *st)
  4925. {
  4926. struct map_session_data *sd;
  4927. sd=script_rid2sd(st);
  4928. if(pc_isriding(sd)){
  4929. push_val(st->stack,C_INT,1);
  4930. } else {
  4931. push_val(st->stack,C_INT,0);
  4932. }
  4933. return 0;
  4934. }
  4935. /*==========================================
  4936. * ペコペコ乗り
  4937. *------------------------------------------
  4938. */
  4939. int buildin_setriding(struct script_state *st)
  4940. {
  4941. struct map_session_data *sd;
  4942. sd=script_rid2sd(st);
  4943. pc_setriding(sd);
  4944. return 0;
  4945. }
  4946. /*==========================================
  4947. * セーブポイントの保存
  4948. *------------------------------------------
  4949. */
  4950. int buildin_savepoint(struct script_state *st)
  4951. {
  4952. int x,y;
  4953. short map;
  4954. char *str;
  4955. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4956. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4957. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4958. map = mapindex_name2id(str);
  4959. if (map)
  4960. pc_setsavepoint(script_rid2sd(st),map,x,y);
  4961. return 0;
  4962. }
  4963. /*==========================================
  4964. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  4965. *------------------------------------------
  4966. */
  4967. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  4968. {
  4969. int type;
  4970. time_t timer;
  4971. struct tm *t;
  4972. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4973. switch(type){
  4974. case 2:
  4975. //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
  4976. // from the system clock.)
  4977. push_val(st->stack,C_INT,(int)time(NULL));
  4978. break;
  4979. case 1:
  4980. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  4981. time(&timer);
  4982. t=localtime(&timer);
  4983. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  4984. break;
  4985. case 0:
  4986. default:
  4987. //type 0:(System Ticks)
  4988. push_val(st->stack,C_INT,gettick());
  4989. break;
  4990. }
  4991. return 0;
  4992. }
  4993. /*==========================================
  4994. * GetTime(Type);
  4995. * 1: Sec 2: Min 3: Hour
  4996. * 4: WeekDay 5: MonthDay 6: Month
  4997. * 7: Year
  4998. *------------------------------------------
  4999. */
  5000. int buildin_gettime(struct script_state *st) /* Asgard Version */
  5001. {
  5002. int type;
  5003. time_t timer;
  5004. struct tm *t;
  5005. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5006. time(&timer);
  5007. t=localtime(&timer);
  5008. switch(type){
  5009. case 1://Sec(0~59)
  5010. push_val(st->stack,C_INT,t->tm_sec);
  5011. break;
  5012. case 2://Min(0~59)
  5013. push_val(st->stack,C_INT,t->tm_min);
  5014. break;
  5015. case 3://Hour(0~23)
  5016. push_val(st->stack,C_INT,t->tm_hour);
  5017. break;
  5018. case 4://WeekDay(0~6)
  5019. push_val(st->stack,C_INT,t->tm_wday);
  5020. break;
  5021. case 5://MonthDay(01~31)
  5022. push_val(st->stack,C_INT,t->tm_mday);
  5023. break;
  5024. case 6://Month(01~12)
  5025. push_val(st->stack,C_INT,t->tm_mon+1);
  5026. break;
  5027. case 7://Year(20xx)
  5028. push_val(st->stack,C_INT,t->tm_year+1900);
  5029. break;
  5030. case 8://Year Day(01~366)
  5031. push_val(st->stack,C_INT,t->tm_yday+1);
  5032. break;
  5033. default://(format error)
  5034. push_val(st->stack,C_INT,-1);
  5035. break;
  5036. }
  5037. return 0;
  5038. }
  5039. /*==========================================
  5040. * GetTimeStr("TimeFMT", Length);
  5041. *------------------------------------------
  5042. */
  5043. int buildin_gettimestr(struct script_state *st)
  5044. {
  5045. char *tmpstr;
  5046. char *fmtstr;
  5047. int maxlen;
  5048. time_t now = time(NULL);
  5049. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5050. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5051. tmpstr=(char *)aMallocA((maxlen+1)*sizeof(char));
  5052. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  5053. tmpstr[maxlen]='\0';
  5054. push_str(st->stack,C_STR,(unsigned char *) tmpstr);
  5055. return 0;
  5056. }
  5057. /*==========================================
  5058. * カプラ倉庫を開く
  5059. *------------------------------------------
  5060. */
  5061. int buildin_openstorage(struct script_state *st)
  5062. {
  5063. storage_storageopen(script_rid2sd(st));
  5064. return 0;
  5065. }
  5066. int buildin_guildopenstorage(struct script_state *st)
  5067. {
  5068. struct map_session_data *sd=script_rid2sd(st);
  5069. int ret;
  5070. ret = storage_guild_storageopen(sd);
  5071. push_val(st->stack,C_INT,ret);
  5072. return 0;
  5073. }
  5074. /*==========================================
  5075. * アイテムによるスキル発動
  5076. *------------------------------------------
  5077. */
  5078. int buildin_itemskill(struct script_state *st)
  5079. {
  5080. int id,lv;
  5081. char *str;
  5082. struct map_session_data *sd=script_rid2sd(st);
  5083. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5084. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5085. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  5086. // 詠唱中にスキルアイテムは使用できない
  5087. if(sd->ud.skilltimer != -1)
  5088. return 0;
  5089. sd->skillitem=id;
  5090. sd->skillitemlv=lv;
  5091. clif_item_skill(sd,id,lv,str);
  5092. return 0;
  5093. }
  5094. /*==========================================
  5095. * アイテム作成
  5096. *------------------------------------------
  5097. */
  5098. int buildin_produce(struct script_state *st)
  5099. {
  5100. int trigger;
  5101. struct map_session_data *sd=script_rid2sd(st);
  5102. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5103. clif_skill_produce_mix_list(sd, trigger);
  5104. return 0;
  5105. }
  5106. /*==========================================
  5107. * NPCでペット作る
  5108. *------------------------------------------
  5109. */
  5110. int buildin_makepet(struct script_state *st)
  5111. {
  5112. struct map_session_data *sd = script_rid2sd(st);
  5113. struct script_data *data;
  5114. int id,pet_id;
  5115. data=&(st->stack->stack_data[st->start+2]);
  5116. get_val(st,data);
  5117. id=conv_num(st,data);
  5118. pet_id = search_petDB_index(id, PET_CLASS);
  5119. if (pet_id < 0)
  5120. pet_id = search_petDB_index(id, PET_EGG);
  5121. if (pet_id >= 0 && sd) {
  5122. sd->catch_target_class = pet_db[pet_id].class_;
  5123. intif_create_pet(
  5124. sd->status.account_id, sd->status.char_id,
  5125. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  5126. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  5127. 100, 0, 1, pet_db[pet_id].jname);
  5128. }
  5129. return 0;
  5130. }
  5131. /*==========================================
  5132. * NPCで経験値上げる
  5133. *------------------------------------------
  5134. */
  5135. int buildin_getexp(struct script_state *st)
  5136. {
  5137. struct map_session_data *sd = script_rid2sd(st);
  5138. int base=0,job=0;
  5139. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5140. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  5141. if(base<0 || job<0)
  5142. return 0;
  5143. if(sd)
  5144. pc_gainexp(sd,NULL,base,job);
  5145. return 0;
  5146. }
  5147. /*==========================================
  5148. * Gain guild exp [Celest]
  5149. *------------------------------------------
  5150. */
  5151. int buildin_guildgetexp(struct script_state *st)
  5152. {
  5153. struct map_session_data *sd = script_rid2sd(st);
  5154. int exp;
  5155. exp = conv_num(st,& (st->stack->stack_data[st->start+2]));
  5156. if(exp < 0)
  5157. return 0;
  5158. if(sd && sd->status.guild_id > 0)
  5159. guild_getexp (sd, exp);
  5160. return 0;
  5161. }
  5162. /*==========================================
  5163. * Changes the guild master of a guild [Skotlex]
  5164. *------------------------------------------
  5165. */
  5166. int buildin_guildchangegm(struct script_state *st)
  5167. {
  5168. struct map_session_data *sd;
  5169. int guild_id;
  5170. char *name;
  5171. guild_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  5172. name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  5173. sd=map_nick2sd(name);
  5174. if (!sd)
  5175. push_val(st->stack,C_INT,0);
  5176. else
  5177. push_val(st->stack,C_INT,guild_gm_change(guild_id, sd));
  5178. return 0;
  5179. }
  5180. /*==========================================
  5181. * モンスター発生
  5182. *------------------------------------------
  5183. */
  5184. int buildin_monster(struct script_state *st)
  5185. {
  5186. int class_,amount,x,y;
  5187. char *str,*map,*event="";
  5188. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  5189. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  5190. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  5191. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  5192. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5193. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5194. if( st->end>st->start+8 ){
  5195. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  5196. check_event(st, event);
  5197. }
  5198. if (class_ >= 0 && !mobdb_checkid(class_)) {
  5199. ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
  5200. return 1;
  5201. }
  5202. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
  5203. return 0;
  5204. }
  5205. /*==========================================
  5206. * モンスター発生
  5207. *------------------------------------------
  5208. */
  5209. int buildin_areamonster(struct script_state *st)
  5210. {
  5211. int class_,amount,x0,y0,x1,y1;
  5212. char *str,*map,*event="";
  5213. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  5214. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  5215. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  5216. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  5217. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  5218. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  5219. class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5220. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5221. if( st->end>st->start+10 ){
  5222. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  5223. check_event(st, event);
  5224. }
  5225. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
  5226. return 0;
  5227. }
  5228. /*==========================================
  5229. * モンスター削除
  5230. *------------------------------------------
  5231. */
  5232. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  5233. {
  5234. TBL_MOB* md = (TBL_MOB*)bl;
  5235. char *event=va_arg(ap,char *);
  5236. int allflag=va_arg(ap,int);
  5237. if(!allflag){
  5238. if(strcmp(event,md->npc_event)==0)
  5239. status_kill(bl);
  5240. return 0;
  5241. }else{
  5242. if(!md->spawn)
  5243. status_kill(bl);
  5244. return 0;
  5245. }
  5246. return 0;
  5247. }
  5248. int buildin_killmonster(struct script_state *st)
  5249. {
  5250. char *mapname,*event;
  5251. int m,allflag=0;
  5252. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5253. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  5254. if(strcmp(event,"All")==0)
  5255. allflag = 1;
  5256. else
  5257. check_event(st, event);
  5258. if( (m=map_mapname2mapid(mapname))<0 )
  5259. return 0;
  5260. map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
  5261. return 0;
  5262. }
  5263. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  5264. {
  5265. status_kill(bl);
  5266. return 0;
  5267. }
  5268. int buildin_killmonsterall(struct script_state *st)
  5269. {
  5270. char *mapname;
  5271. int m;
  5272. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5273. if( (m=map_mapname2mapid(mapname))<0 )
  5274. return 0;
  5275. map_foreachinmap(buildin_killmonsterall_sub,
  5276. m,BL_MOB);
  5277. return 0;
  5278. }
  5279. /*==========================================
  5280. * Creates a clone of a player.
  5281. * clone map, x, y, event, char_id, master_id, mode, flag, duration
  5282. *------------------------------------------
  5283. */
  5284. int buildin_clone(struct script_state *st) {
  5285. struct map_session_data *sd, *msd=NULL;
  5286. int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
  5287. unsigned int duration = 0;
  5288. char *map,*event="";
  5289. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5290. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5291. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5292. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  5293. char_id=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5294. if( st->end>st->start+7 )
  5295. master_id=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5296. if( st->end>st->start+8 )
  5297. mode=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5298. if( st->end>st->start+9 )
  5299. flag=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5300. if( st->end>st->start+10 )
  5301. duration=conv_num(st,& (st->stack->stack_data[st->start+10]));
  5302. check_event(st, event);
  5303. m = map_mapname2mapid(map);
  5304. if (m < 0) return 0;
  5305. sd = map_charid2sd(char_id);
  5306. if (master_id) {
  5307. msd = map_charid2sd(master_id);
  5308. if (msd)
  5309. master_id = msd->bl.id;
  5310. else
  5311. master_id = 0;
  5312. }
  5313. if (sd) //Return ID of newly crafted clone.
  5314. push_val(st->stack,C_INT,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
  5315. else //Failed to create clone.
  5316. push_val(st->stack,C_INT,0);
  5317. return 0;
  5318. }
  5319. /*==========================================
  5320. * イベント実行
  5321. *------------------------------------------
  5322. */
  5323. int buildin_doevent(struct script_state *st)
  5324. {
  5325. char *event;
  5326. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5327. check_event(st, event);
  5328. npc_event(map_id2sd(st->rid),event,0);
  5329. return 0;
  5330. }
  5331. /*==========================================
  5332. * NPC主体イベント実行
  5333. *------------------------------------------
  5334. */
  5335. int buildin_donpcevent(struct script_state *st)
  5336. {
  5337. char *event;
  5338. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5339. check_event(st, event);
  5340. npc_event_do(event);
  5341. return 0;
  5342. }
  5343. /*==========================================
  5344. * イベントタイマー追加
  5345. *------------------------------------------
  5346. */
  5347. int buildin_addtimer(struct script_state *st)
  5348. {
  5349. char *event;
  5350. int tick;
  5351. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5352. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  5353. check_event(st, event);
  5354. pc_addeventtimer(script_rid2sd(st),tick,event);
  5355. return 0;
  5356. }
  5357. /*==========================================
  5358. * イベントタイマー削除
  5359. *------------------------------------------
  5360. */
  5361. int buildin_deltimer(struct script_state *st)
  5362. {
  5363. char *event;
  5364. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5365. check_event(st, event);
  5366. pc_deleventtimer(script_rid2sd(st),event);
  5367. return 0;
  5368. }
  5369. /*==========================================
  5370. * イベントタイマーのカウント値追加
  5371. *------------------------------------------
  5372. */
  5373. int buildin_addtimercount(struct script_state *st)
  5374. {
  5375. char *event;
  5376. int tick;
  5377. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5378. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5379. check_event(st, event);
  5380. pc_addeventtimercount(script_rid2sd(st),event,tick);
  5381. return 0;
  5382. }
  5383. /*==========================================
  5384. * NPCタイマー初期化
  5385. *------------------------------------------
  5386. */
  5387. int buildin_initnpctimer(struct script_state *st)
  5388. {
  5389. struct npc_data *nd;
  5390. if( st->end > st->start+2 )
  5391. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5392. else
  5393. nd=(struct npc_data *)map_id2bl(st->oid);
  5394. //nd->u.scr.rid = st->rid; //NO, use npcattachtimer if you want a player-attached timer! [Skotlex]
  5395. npc_settimerevent_tick(nd,0);
  5396. npc_timerevent_start(nd, st->rid);
  5397. return 0;
  5398. }
  5399. /*==========================================
  5400. * NPCタイマー開始
  5401. *------------------------------------------
  5402. */
  5403. int buildin_startnpctimer(struct script_state *st)
  5404. {
  5405. struct npc_data *nd;
  5406. if( st->end > st->start+2 )
  5407. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5408. else
  5409. nd=(struct npc_data *)map_id2bl(st->oid);
  5410. npc_timerevent_start(nd, st->rid);
  5411. return 0;
  5412. }
  5413. /*==========================================
  5414. * NPCタイマー停止
  5415. *------------------------------------------
  5416. */
  5417. int buildin_stopnpctimer(struct script_state *st)
  5418. {
  5419. struct npc_data *nd;
  5420. if( st->end > st->start+2 )
  5421. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5422. else
  5423. nd=(struct npc_data *)map_id2bl(st->oid);
  5424. npc_timerevent_stop(nd);
  5425. return 0;
  5426. }
  5427. /*==========================================
  5428. * NPCタイマー情報所得
  5429. *------------------------------------------
  5430. */
  5431. int buildin_getnpctimer(struct script_state *st)
  5432. {
  5433. struct npc_data *nd;
  5434. struct map_session_data *sd;
  5435. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5436. int val=0;
  5437. if( st->end > st->start+3 )
  5438. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5439. else
  5440. nd=(struct npc_data *)map_id2bl(st->oid);
  5441. switch(type){
  5442. case 0: val=npc_gettimerevent_tick(nd); break;
  5443. case 1:
  5444. if (nd->u.scr.rid) {
  5445. sd = map_id2sd(nd->u.scr.rid);
  5446. if (!sd) {
  5447. if(battle_config.error_log)
  5448. ShowError("buildin_getnpctimer: Attached player not found!\n");
  5449. break;
  5450. }
  5451. val = (sd->npc_timer_id != -1);
  5452. } else
  5453. val= (nd->u.scr.timerid !=-1);
  5454. break;
  5455. case 2: val= nd->u.scr.timeramount; break;
  5456. }
  5457. push_val(st->stack,C_INT,val);
  5458. return 0;
  5459. }
  5460. /*==========================================
  5461. * NPCタイマー値設定
  5462. *------------------------------------------
  5463. */
  5464. int buildin_setnpctimer(struct script_state *st)
  5465. {
  5466. int tick;
  5467. struct npc_data *nd;
  5468. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5469. if( st->end > st->start+3 )
  5470. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5471. else
  5472. nd=(struct npc_data *)map_id2bl(st->oid);
  5473. npc_settimerevent_tick(nd,tick);
  5474. return 0;
  5475. }
  5476. /*==========================================
  5477. * attaches the player rid to the timer [Celest]
  5478. *------------------------------------------
  5479. */
  5480. int buildin_attachnpctimer(struct script_state *st)
  5481. {
  5482. struct map_session_data *sd;
  5483. struct npc_data *nd;
  5484. nd=(struct npc_data *)map_id2bl(st->oid);
  5485. if( st->end > st->start+2 ) {
  5486. char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  5487. sd=map_nick2sd(name);
  5488. } else {
  5489. sd = script_rid2sd(st);
  5490. }
  5491. if (sd==NULL)
  5492. return 0;
  5493. nd->u.scr.rid = sd->bl.id;
  5494. return 0;
  5495. }
  5496. /*==========================================
  5497. * detaches a player rid from the timer [Celest]
  5498. *------------------------------------------
  5499. */
  5500. int buildin_detachnpctimer(struct script_state *st)
  5501. {
  5502. struct npc_data *nd;
  5503. if( st->end > st->start+2 )
  5504. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5505. else
  5506. nd=(struct npc_data *)map_id2bl(st->oid);
  5507. nd->u.scr.rid = 0;
  5508. return 0;
  5509. }
  5510. /*==========================================
  5511. * To avoid "player not attached" script errors, this function is provided,
  5512. * it checks if there is a player attached to the current script. [Skotlex]
  5513. * If no, returns 0, if yes, returns the char_id of the attached player.
  5514. *------------------------------------------
  5515. */
  5516. int buildin_playerattached(struct script_state *st)
  5517. {
  5518. struct map_session_data *sd;
  5519. if (st->rid == 0 || (sd = map_id2sd(st->rid)) == NULL)
  5520. push_val(st->stack,C_INT,0);
  5521. else
  5522. push_val(st->stack,C_INT,st->rid);
  5523. return 0;
  5524. }
  5525. /*==========================================
  5526. * 天の声アナウンス
  5527. *------------------------------------------
  5528. */
  5529. int buildin_announce(struct script_state *st)
  5530. {
  5531. char *str, *color=NULL;
  5532. int flag;
  5533. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5534. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5535. if (st->end>st->start+4)
  5536. color=conv_str(st,& (st->stack->stack_data[st->start+4]));
  5537. if(flag&0x0f){
  5538. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  5539. (struct block_list *)script_rid2sd(st);
  5540. if (color)
  5541. clif_announce(bl,str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0),flag);
  5542. else
  5543. clif_GMmessage(bl,str,(int)strlen(str)+1,flag);
  5544. }else {
  5545. if (color)
  5546. intif_announce(str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0), flag);
  5547. else
  5548. intif_GMmessage(str,(int)strlen(str)+1,flag);
  5549. }
  5550. return 0;
  5551. }
  5552. /*==========================================
  5553. * 天の声アナウンス(特定マップ)
  5554. *------------------------------------------
  5555. */
  5556. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  5557. {
  5558. char *str, *color;
  5559. int len,flag;
  5560. str=va_arg(ap,char *);
  5561. len=va_arg(ap,int);
  5562. flag=va_arg(ap,int);
  5563. color=va_arg(ap,char *);
  5564. if (color)
  5565. clif_announce(bl,str,len, strtol(color, (char **)NULL, 0), flag|3);
  5566. else
  5567. clif_GMmessage(bl,str,len,flag|3);
  5568. return 0;
  5569. }
  5570. int buildin_mapannounce(struct script_state *st)
  5571. {
  5572. char *mapname,*str, *color=NULL;
  5573. int flag,m;
  5574. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5575. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  5576. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5577. if (st->end>st->start+5)
  5578. color=conv_str(st,& (st->stack->stack_data[st->start+5]));
  5579. if( (m=map_mapname2mapid(mapname))<0 )
  5580. return 0;
  5581. map_foreachinmap(buildin_mapannounce_sub,
  5582. m, BL_PC, str,strlen(str)+1,flag&0x10, color);
  5583. return 0;
  5584. }
  5585. /*==========================================
  5586. * 天の声アナウンス(特定エリア)
  5587. *------------------------------------------
  5588. */
  5589. int buildin_areaannounce(struct script_state *st)
  5590. {
  5591. char *map,*str,*color=NULL;
  5592. int flag,m;
  5593. int x0,y0,x1,y1;
  5594. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5595. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5596. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5597. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5598. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5599. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  5600. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5601. if (st->end>st->start+9)
  5602. color=conv_str(st,& (st->stack->stack_data[st->start+9]));
  5603. if( (m=map_mapname2mapid(map))<0 )
  5604. return 0;
  5605. map_foreachinarea(buildin_mapannounce_sub,
  5606. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10, color);
  5607. return 0;
  5608. }
  5609. /*==========================================
  5610. * ユーザー数所得
  5611. *------------------------------------------
  5612. */
  5613. int buildin_getusers(struct script_state *st)
  5614. {
  5615. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5616. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  5617. int val=0;
  5618. switch(flag&0x07){
  5619. case 0: val=map[bl->m].users; break;
  5620. case 1: val=map_getusers(); break;
  5621. }
  5622. push_val(st->stack,C_INT,val);
  5623. return 0;
  5624. }
  5625. /*==========================================
  5626. * Works like @WHO - displays all online users names in window
  5627. *------------------------------------------
  5628. */
  5629. int buildin_getusersname(struct script_state *st)
  5630. {
  5631. struct map_session_data *pl_sd = NULL, **pl_allsd;
  5632. int i=0,disp_num=1, users;
  5633. pl_allsd = map_getallusers(&users);
  5634. for (i=0;i<users;i++)
  5635. {
  5636. pl_sd = pl_allsd[i];
  5637. if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) )
  5638. {
  5639. if((disp_num++)%10==0)
  5640. clif_scriptnext(script_rid2sd(st),st->oid);
  5641. clif_scriptmes(script_rid2sd(st),st->oid,pl_sd->status.name);
  5642. }
  5643. }
  5644. return 0;
  5645. }
  5646. /*==========================================
  5647. * マップ指定ユーザー数所得
  5648. *------------------------------------------
  5649. */
  5650. int buildin_getmapusers(struct script_state *st)
  5651. {
  5652. char *str;
  5653. int m;
  5654. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5655. if( (m=map_mapname2mapid(str))< 0){
  5656. push_val(st->stack,C_INT,-1);
  5657. return 0;
  5658. }
  5659. push_val(st->stack,C_INT,map[m].users);
  5660. return 0;
  5661. }
  5662. /*==========================================
  5663. * エリア指定ユーザー数所得
  5664. *------------------------------------------
  5665. */
  5666. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  5667. {
  5668. int *users=va_arg(ap,int *);
  5669. (*users)++;
  5670. return 0;
  5671. }
  5672. int buildin_getareausers(struct script_state *st)
  5673. {
  5674. char *str;
  5675. int m,x0,y0,x1,y1,users=0;
  5676. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5677. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5678. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5679. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5680. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5681. if( (m=map_mapname2mapid(str))< 0){
  5682. push_val(st->stack,C_INT,-1);
  5683. return 0;
  5684. }
  5685. map_foreachinarea(buildin_getareausers_sub,
  5686. m,x0,y0,x1,y1,BL_PC,&users);
  5687. push_val(st->stack,C_INT,users);
  5688. return 0;
  5689. }
  5690. /*==========================================
  5691. * エリア指定ドロップアイテム数所得
  5692. *------------------------------------------
  5693. */
  5694. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  5695. {
  5696. int item=va_arg(ap,int);
  5697. int *amount=va_arg(ap,int *);
  5698. struct flooritem_data *drop=(struct flooritem_data *)bl;
  5699. if(drop->item_data.nameid==item)
  5700. (*amount)+=drop->item_data.amount;
  5701. return 0;
  5702. }
  5703. int buildin_getareadropitem(struct script_state *st)
  5704. {
  5705. char *str;
  5706. int m,x0,y0,x1,y1,item,amount=0;
  5707. struct script_data *data;
  5708. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5709. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5710. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5711. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5712. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5713. data=&(st->stack->stack_data[st->start+7]);
  5714. get_val(st,data);
  5715. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5716. const char *name=conv_str(st,data);
  5717. struct item_data *item_data = itemdb_searchname(name);
  5718. item=UNKNOWN_ITEM_ID;
  5719. if( item_data )
  5720. item=item_data->nameid;
  5721. }else
  5722. item=conv_num(st,data);
  5723. if( (m=map_mapname2mapid(str))< 0){
  5724. push_val(st->stack,C_INT,-1);
  5725. return 0;
  5726. }
  5727. map_foreachinarea(buildin_getareadropitem_sub,
  5728. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  5729. push_val(st->stack,C_INT,amount);
  5730. return 0;
  5731. }
  5732. /*==========================================
  5733. * NPCの有効化
  5734. *------------------------------------------
  5735. */
  5736. int buildin_enablenpc(struct script_state *st)
  5737. {
  5738. char *str;
  5739. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5740. npc_enable(str,1);
  5741. return 0;
  5742. }
  5743. /*==========================================
  5744. * NPCの無効化
  5745. *------------------------------------------
  5746. */
  5747. int buildin_disablenpc(struct script_state *st)
  5748. {
  5749. char *str;
  5750. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5751. npc_enable(str,0);
  5752. return 0;
  5753. }
  5754. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  5755. {
  5756. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5757. struct chat_data *cd;
  5758. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  5759. return 0;
  5760. npc_enable(nd->name,1);
  5761. nd->arenaflag=1;
  5762. if(cd->users>=cd->trigger && cd->npc_event[0])
  5763. npc_timer_event(cd->npc_event);
  5764. return 0;
  5765. }
  5766. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  5767. {
  5768. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5769. nd->arenaflag=0;
  5770. return 0;
  5771. }
  5772. /*==========================================
  5773. * 隠れているNPCの表示
  5774. *------------------------------------------
  5775. */
  5776. int buildin_hideoffnpc(struct script_state *st)
  5777. {
  5778. char *str;
  5779. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5780. npc_enable(str,2);
  5781. return 0;
  5782. }
  5783. /*==========================================
  5784. * NPCをハイディング
  5785. *------------------------------------------
  5786. */
  5787. int buildin_hideonnpc(struct script_state *st)
  5788. {
  5789. char *str;
  5790. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5791. npc_enable(str,4);
  5792. return 0;
  5793. }
  5794. /*==========================================
  5795. * 状態異常にかかる
  5796. *------------------------------------------
  5797. */
  5798. int buildin_sc_start(struct script_state *st)
  5799. {
  5800. struct block_list *bl;
  5801. int type,tick,val1,val4=0;
  5802. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5803. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5804. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5805. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  5806. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  5807. else
  5808. bl = map_id2bl(st->rid);
  5809. if (potion_flag==1 && potion_target) {
  5810. bl = map_id2bl(potion_target);
  5811. tick/=2; //Thrown potions only last half.
  5812. val4 = 1; //Mark that this was a thrown sc_effect
  5813. }
  5814. if (bl)
  5815. status_change_start(bl,type,10000,val1,0,0,val4,tick,11);
  5816. return 0;
  5817. }
  5818. /*==========================================
  5819. * 状態異常にかかる(確率指定)
  5820. *------------------------------------------
  5821. */
  5822. int buildin_sc_start2(struct script_state *st)
  5823. {
  5824. struct block_list *bl;
  5825. int type,tick,val1,val4=0,per;
  5826. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5827. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5828. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5829. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5830. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  5831. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  5832. else
  5833. bl = map_id2bl(st->rid);
  5834. if (potion_flag==1 && potion_target) {
  5835. bl = map_id2bl(potion_target);
  5836. tick/=2;
  5837. val4 = 1;
  5838. }
  5839. if(bl)
  5840. status_change_start(bl,type,per,val1,0,0,val4,tick,11);
  5841. return 0;
  5842. }
  5843. /*==========================================
  5844. * Starts a SC_ change with the four values passed. [Skotlex]
  5845. * Final optional argument is the ID of player to affect.
  5846. * sc_start4 type, duration, val1, val2, val3, val4, <id>;
  5847. *------------------------------------------
  5848. */
  5849. int buildin_sc_start4(struct script_state *st)
  5850. {
  5851. struct block_list *bl;
  5852. int type,tick,val1,val2,val3,val4;
  5853. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5854. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5855. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5856. val2=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5857. val3=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5858. val4=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5859. if( st->end>st->start+8 )
  5860. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+8])));
  5861. else
  5862. bl = map_id2bl(st->rid);
  5863. if (potion_flag==1 && potion_target) {
  5864. bl = map_id2bl(potion_target);
  5865. tick/=2;
  5866. }
  5867. if (bl)
  5868. status_change_start(bl,type,10000,val1,val2,val3,val4,tick,11);
  5869. return 0;
  5870. }
  5871. /*==========================================
  5872. * 状態異常が直る
  5873. *------------------------------------------
  5874. */
  5875. int buildin_sc_end(struct script_state *st)
  5876. {
  5877. struct block_list *bl;
  5878. int type;
  5879. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5880. bl = map_id2bl(st->rid);
  5881. if (potion_flag==1 && potion_target)
  5882. bl = map_id2bl(potion_target);
  5883. if (!bl) return 0;
  5884. if (type >= 0)
  5885. status_change_end(bl,type,-1);
  5886. else
  5887. status_change_clear(bl, 2);
  5888. return 0;
  5889. }
  5890. /*==========================================
  5891. * 状態異常耐性を計算した確率を返す
  5892. *------------------------------------------
  5893. */
  5894. int buildin_getscrate(struct script_state *st)
  5895. {
  5896. struct block_list *bl;
  5897. int sc_def=0,type,rate;
  5898. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5899. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5900. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  5901. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  5902. else
  5903. bl = map_id2bl(st->rid);
  5904. if (bl)
  5905. sc_def = status_get_sc_def(bl,type);
  5906. rate = rate*(10000-sc_def)/10000;
  5907. push_val(st->stack,C_INT,rate<0?0:rate);
  5908. return 0;
  5909. }
  5910. /*==========================================
  5911. *
  5912. *------------------------------------------
  5913. */
  5914. int buildin_debugmes(struct script_state *st)
  5915. {
  5916. conv_str(st,& (st->stack->stack_data[st->start+2]));
  5917. ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  5918. return 0;
  5919. }
  5920. /*==========================================
  5921. *捕獲アイテム使用
  5922. *------------------------------------------
  5923. */
  5924. int buildin_catchpet(struct script_state *st)
  5925. {
  5926. int pet_id;
  5927. struct map_session_data *sd;
  5928. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  5929. sd=script_rid2sd(st);
  5930. pet_catch_process1(sd,pet_id);
  5931. return 0;
  5932. }
  5933. /*==========================================
  5934. * [orn]
  5935. *------------------------------------------
  5936. */
  5937. int buildin_homunculus_evolution(struct script_state *st)
  5938. {
  5939. struct map_session_data *sd;
  5940. sd=script_rid2sd(st);
  5941. if ( sd->hd && sd->hd->homunculusDB->evo_class && sd->homunculus.intimacy > 91000 ) {
  5942. return merc_hom_evolution(sd->hd) ;
  5943. }
  5944. clif_emotion(&sd->hd->bl, 4) ; //swt
  5945. return 0;
  5946. }
  5947. /*==========================================
  5948. *携帯卵孵化機使用
  5949. *------------------------------------------
  5950. */
  5951. int buildin_birthpet(struct script_state *st)
  5952. {
  5953. struct map_session_data *sd;
  5954. sd=script_rid2sd(st);
  5955. clif_sendegg(sd);
  5956. return 0;
  5957. }
  5958. /*==========================================
  5959. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  5960. *------------------------------------------
  5961. */
  5962. int buildin_resetlvl(struct script_state *st)
  5963. {
  5964. struct map_session_data *sd;
  5965. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5966. sd=script_rid2sd(st);
  5967. pc_resetlvl(sd,type);
  5968. return 0;
  5969. }
  5970. /*==========================================
  5971. * ステータスリセット
  5972. *------------------------------------------
  5973. */
  5974. int buildin_resetstatus(struct script_state *st)
  5975. {
  5976. struct map_session_data *sd;
  5977. sd=script_rid2sd(st);
  5978. pc_resetstate(sd);
  5979. return 0;
  5980. }
  5981. /*==========================================
  5982. * script command resetskill
  5983. *------------------------------------------
  5984. */
  5985. int buildin_resetskill(struct script_state *st)
  5986. {
  5987. struct map_session_data *sd;
  5988. sd=script_rid2sd(st);
  5989. pc_resetskill(sd,1);
  5990. return 0;
  5991. }
  5992. /*==========================================
  5993. * Counts total amount of skill points.
  5994. *------------------------------------------
  5995. */
  5996. int buildin_skillpointcount(struct script_state *st)
  5997. {
  5998. struct map_session_data *sd;
  5999. sd=script_rid2sd(st);
  6000. push_val(st->stack,C_INT,sd->status.skill_point + pc_resetskill(sd,2));
  6001. return 0;
  6002. }
  6003. /*==========================================
  6004. *
  6005. *------------------------------------------
  6006. */
  6007. int buildin_changebase(struct script_state *st)
  6008. {
  6009. struct map_session_data *sd=NULL;
  6010. int vclass;
  6011. if( st->end>st->start+3 )
  6012. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  6013. else
  6014. sd=script_rid2sd(st);
  6015. if(sd == NULL)
  6016. return 0;
  6017. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6018. if(vclass == JOB_WEDDING)
  6019. {
  6020. if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
  6021. sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore.
  6022. )
  6023. return 0;
  6024. }
  6025. if(!sd->disguise && vclass != sd->vd.class_) {
  6026. status_set_viewdata(&sd->bl, vclass);
  6027. //Updated client view. Base, Weapon and Cloth Colors.
  6028. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_);
  6029. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6030. if (sd->vd.cloth_color)
  6031. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  6032. }
  6033. return 0;
  6034. }
  6035. /*==========================================
  6036. * 性別変換
  6037. *------------------------------------------
  6038. */
  6039. int buildin_changesex(struct script_state *st) {
  6040. struct map_session_data *sd = NULL;
  6041. sd = script_rid2sd(st);
  6042. if (sd->status.sex == 0) {
  6043. sd->status.sex = 1;
  6044. sd->sex = 1;
  6045. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  6046. sd->status.class_ -= 1;
  6047. } else if (sd->status.sex == 1) {
  6048. sd->status.sex = 0;
  6049. sd->sex = 0;
  6050. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  6051. sd->status.class_ += 1;
  6052. }
  6053. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  6054. chrif_save(sd,0);
  6055. return 0;
  6056. }
  6057. /*==========================================
  6058. * npcチャット作成
  6059. *------------------------------------------
  6060. */
  6061. int buildin_waitingroom(struct script_state *st)
  6062. {
  6063. char *name,*ev="";
  6064. int limit, trigger = 0,pub=1;
  6065. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6066. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  6067. if(limit==0)
  6068. pub=3;
  6069. if( (st->end > st->start+5) ){
  6070. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  6071. get_val(st,data);
  6072. if(data->type==C_INT){
  6073. // 新Athena仕様(旧Athena仕様と互換性あり)
  6074. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6075. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6076. }else{
  6077. // eathena仕様
  6078. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6079. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6080. }
  6081. }else{
  6082. // 旧Athena仕様
  6083. if( st->end > st->start+4 )
  6084. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6085. }
  6086. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  6087. limit,pub,trigger,name,(int)strlen(name)+1,ev);
  6088. return 0;
  6089. }
  6090. /*==========================================
  6091. * Works like 'announce' but outputs in the common chat window
  6092. *------------------------------------------
  6093. */
  6094. int buildin_globalmes(struct script_state *st)
  6095. {
  6096. struct block_list *bl = map_id2bl(st->oid);
  6097. struct npc_data *nd = (struct npc_data *)bl;
  6098. char *name=NULL,*mes;
  6099. mes=conv_str(st,& (st->stack->stack_data[st->start+2])); // メッセージの取得
  6100. if(mes==NULL) return 0;
  6101. if(st->end>st->start+3){ // NPC名の取得(123#456)
  6102. name=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6103. } else {
  6104. name=nd->name;
  6105. }
  6106. npc_globalmessage(name,mes); // グローバルメッセージ送信
  6107. return 0;
  6108. }
  6109. /*==========================================
  6110. * npcチャット削除
  6111. *------------------------------------------
  6112. */
  6113. int buildin_delwaitingroom(struct script_state *st)
  6114. {
  6115. struct npc_data *nd;
  6116. if( st->end > st->start+2 )
  6117. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6118. else
  6119. nd=(struct npc_data *)map_id2bl(st->oid);
  6120. chat_deletenpcchat(nd);
  6121. return 0;
  6122. }
  6123. /*==========================================
  6124. * npcチャット全員蹴り出す
  6125. *------------------------------------------
  6126. */
  6127. int buildin_waitingroomkickall(struct script_state *st)
  6128. {
  6129. struct npc_data *nd;
  6130. struct chat_data *cd;
  6131. if( st->end > st->start+2 )
  6132. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6133. else
  6134. nd=(struct npc_data *)map_id2bl(st->oid);
  6135. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  6136. return 0;
  6137. chat_npckickall(cd);
  6138. return 0;
  6139. }
  6140. /*==========================================
  6141. * npcチャットイベント有効化
  6142. *------------------------------------------
  6143. */
  6144. int buildin_enablewaitingroomevent(struct script_state *st)
  6145. {
  6146. struct npc_data *nd;
  6147. struct chat_data *cd;
  6148. if( st->end > st->start+2 )
  6149. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6150. else
  6151. nd=(struct npc_data *)map_id2bl(st->oid);
  6152. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  6153. return 0;
  6154. chat_enableevent(cd);
  6155. return 0;
  6156. }
  6157. /*==========================================
  6158. * npcチャットイベント無効化
  6159. *------------------------------------------
  6160. */
  6161. int buildin_disablewaitingroomevent(struct script_state *st)
  6162. {
  6163. struct npc_data *nd;
  6164. struct chat_data *cd;
  6165. if( st->end > st->start+2 )
  6166. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6167. else
  6168. nd=(struct npc_data *)map_id2bl(st->oid);
  6169. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  6170. return 0;
  6171. chat_disableevent(cd);
  6172. return 0;
  6173. }
  6174. /*==========================================
  6175. * npcチャット状態所得
  6176. *------------------------------------------
  6177. */
  6178. int buildin_getwaitingroomstate(struct script_state *st)
  6179. {
  6180. struct npc_data *nd;
  6181. struct chat_data *cd;
  6182. int val=0,type;
  6183. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6184. if( st->end > st->start+3 )
  6185. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6186. else
  6187. nd=(struct npc_data *)map_id2bl(st->oid);
  6188. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  6189. push_val(st->stack,C_INT,-1);
  6190. return 0;
  6191. }
  6192. switch(type){
  6193. case 0: val=cd->users; break;
  6194. case 1: val=cd->limit; break;
  6195. case 2: val=cd->trigger&0x7f; break;
  6196. case 3: val=((cd->trigger&0x80)>0); break;
  6197. case 32: val=(cd->users >= cd->limit); break;
  6198. case 33: val=(cd->users >= cd->trigger); break;
  6199. case 4:
  6200. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->title);
  6201. return 0;
  6202. case 5:
  6203. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->pass);
  6204. return 0;
  6205. case 16:
  6206. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->npc_event);
  6207. return 0;
  6208. }
  6209. push_val(st->stack,C_INT,val);
  6210. return 0;
  6211. }
  6212. /*==========================================
  6213. * チャットメンバー(規定人数)ワープ
  6214. *------------------------------------------
  6215. */
  6216. int buildin_warpwaitingpc(struct script_state *st)
  6217. {
  6218. int x,y,i,n;
  6219. char *str;
  6220. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6221. struct chat_data *cd;
  6222. struct map_session_data *sd;
  6223. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  6224. return 0;
  6225. n=cd->trigger&0x7f;
  6226. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6227. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6228. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6229. if( st->end > st->start+5 )
  6230. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6231. for(i=0;i<n;i++){
  6232. sd=cd->usersd[0];
  6233. if (!sd) continue; //Broken npc chat room?
  6234. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpc")+(i<<24),sd->bl.id);
  6235. if(strcmp(str,"Random")==0)
  6236. pc_randomwarp(sd,3);
  6237. else if(strcmp(str,"SavePoint")==0){
  6238. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  6239. return 0;
  6240. pc_setpos(sd,sd->status.save_point.map,
  6241. sd->status.save_point.x,sd->status.save_point.y,3);
  6242. }else
  6243. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  6244. }
  6245. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpcnum"),n);
  6246. return 0;
  6247. }
  6248. /*==========================================
  6249. * RIDのアタッチ
  6250. *------------------------------------------
  6251. */
  6252. int buildin_attachrid(struct script_state *st)
  6253. {
  6254. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6255. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  6256. return 0;
  6257. }
  6258. /*==========================================
  6259. * RIDのデタッチ
  6260. *------------------------------------------
  6261. */
  6262. int buildin_detachrid(struct script_state *st)
  6263. {
  6264. st->rid=0;
  6265. return 0;
  6266. }
  6267. /*==========================================
  6268. * 存在チェック
  6269. *------------------------------------------
  6270. */
  6271. int buildin_isloggedin(struct script_state *st)
  6272. {
  6273. push_val(st->stack,C_INT, map_id2sd(
  6274. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  6275. return 0;
  6276. }
  6277. /*==========================================
  6278. *
  6279. *------------------------------------------
  6280. */
  6281. enum { MF_NOMEMO,MF_NOTELEPORT,MF_NOSAVE,MF_NOBRANCH,MF_NOPENALTY,MF_NOZENYPENALTY,
  6282. MF_PVP,MF_PVP_NOPARTY,MF_PVP_NOGUILD,MF_GVG,MF_GVG_NOPARTY,MF_NOTRADE,MF_NOSKILL,
  6283. MF_NOWARP,MF_FREE,MF_NOICEWALL,MF_SNOW,MF_FOG,MF_SAKURA,MF_LEAVES,MF_RAIN,
  6284. MF_INDOORS,MF_NOGO,MF_CLOUDS,MF_CLOUDS2,MF_FIREWORKS,MF_GVG_CASTLE,MF_GVG_DUNGEON,MF_NIGHTENABLED,
  6285. MF_NOBASEEXP, MF_NOJOBEXP, MF_NOMOBLOOT, MF_NOMVPLOOT, MF_NORETURN, MF_NOWARPTO, MF_NIGHTMAREDROP,
  6286. MF_RESTRICTED, MF_NOCOMMAND, MF_NODROP, MF_JEXP, MF_BEXP, MF_NOVENDING, MF_LOADEVENT, MF_NOCHAT };
  6287. int buildin_setmapflagnosave(struct script_state *st)
  6288. {
  6289. int m,x,y;
  6290. unsigned short mapindex;
  6291. char *str,*str2;
  6292. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6293. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6294. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6295. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6296. m = map_mapname2mapid(str);
  6297. mapindex = mapindex_name2id(str2);
  6298. if(m >= 0 && mapindex) {
  6299. map[m].flag.nosave=1;
  6300. map[m].save.map=mapindex;
  6301. map[m].save.x=x;
  6302. map[m].save.y=y;
  6303. }
  6304. return 0;
  6305. }
  6306. int buildin_setmapflag(struct script_state *st)
  6307. {
  6308. int m,i;
  6309. char *str;
  6310. char *val=NULL;
  6311. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6312. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6313. if(st->end>st->start+4){
  6314. val=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6315. }
  6316. m = map_mapname2mapid(str);
  6317. if(m >= 0) {
  6318. switch(i) {
  6319. case MF_NOMEMO:
  6320. map[m].flag.nomemo=1;
  6321. break;
  6322. case MF_NOTELEPORT:
  6323. map[m].flag.noteleport=1;
  6324. break;
  6325. case MF_NOBRANCH:
  6326. map[m].flag.nobranch=1;
  6327. break;
  6328. case MF_NOPENALTY:
  6329. map[m].flag.nopenalty=1;
  6330. break;
  6331. case MF_NOZENYPENALTY:
  6332. map[m].flag.nozenypenalty=1;
  6333. break;
  6334. case MF_PVP:
  6335. map[m].flag.pvp=1;
  6336. break;
  6337. case MF_PVP_NOPARTY:
  6338. map[m].flag.pvp_noparty=1;
  6339. break;
  6340. case MF_PVP_NOGUILD:
  6341. map[m].flag.pvp_noguild=1;
  6342. break;
  6343. case MF_GVG:
  6344. map[m].flag.gvg=1;
  6345. break;
  6346. case MF_GVG_NOPARTY:
  6347. map[m].flag.gvg_noparty=1;
  6348. break;
  6349. case MF_GVG_DUNGEON:
  6350. map[m].flag.gvg_dungeon=1;
  6351. break;
  6352. case MF_GVG_CASTLE:
  6353. map[m].flag.gvg_castle=1;
  6354. break;
  6355. case MF_NOTRADE:
  6356. map[m].flag.notrade=1;
  6357. break;
  6358. case MF_NODROP:
  6359. map[m].flag.nodrop=1;
  6360. break;
  6361. case MF_NOSKILL:
  6362. map[m].flag.noskill=1;
  6363. break;
  6364. case MF_NOWARP:
  6365. map[m].flag.nowarp=1;
  6366. break;
  6367. case MF_NOICEWALL: // [Valaris]
  6368. map[m].flag.noicewall=1;
  6369. break;
  6370. case MF_SNOW: // [Valaris]
  6371. map[m].flag.snow=1;
  6372. break;
  6373. case MF_CLOUDS:
  6374. map[m].flag.clouds=1;
  6375. break;
  6376. case MF_CLOUDS2: // [Valaris]
  6377. map[m].flag.clouds2=1;
  6378. break;
  6379. case MF_FOG: // [Valaris]
  6380. map[m].flag.fog=1;
  6381. break;
  6382. case MF_FIREWORKS:
  6383. map[m].flag.fireworks=1;
  6384. break;
  6385. case MF_SAKURA: // [Valaris]
  6386. map[m].flag.sakura=1;
  6387. break;
  6388. case MF_LEAVES: // [Valaris]
  6389. map[m].flag.leaves=1;
  6390. break;
  6391. case MF_RAIN: // [Valaris]
  6392. map[m].flag.rain=1;
  6393. break;
  6394. case MF_INDOORS: // celest
  6395. map[m].flag.indoors=1;
  6396. break;
  6397. case MF_NIGHTENABLED:
  6398. map[m].flag.nightenabled=1;
  6399. break;
  6400. case MF_NOGO: // celest
  6401. map[m].flag.nogo=1;
  6402. break;
  6403. case MF_NOBASEEXP:
  6404. map[m].flag.nobaseexp=1;
  6405. break;
  6406. case MF_NOJOBEXP:
  6407. map[m].flag.nojobexp=1;
  6408. break;
  6409. case MF_NOMOBLOOT:
  6410. map[m].flag.nomobloot=1;
  6411. break;
  6412. case MF_NOMVPLOOT:
  6413. map[m].flag.nomvploot=1;
  6414. break;
  6415. case MF_NORETURN:
  6416. map[m].flag.noreturn=1;
  6417. break;
  6418. case MF_NOWARPTO:
  6419. map[m].flag.nowarpto=1;
  6420. break;
  6421. case MF_NIGHTMAREDROP:
  6422. map[m].flag.pvp_nightmaredrop=1;
  6423. break;
  6424. case MF_RESTRICTED:
  6425. map[m].flag.restricted=1;
  6426. break;
  6427. case MF_NOCOMMAND:
  6428. map[m].flag.nocommand=1;
  6429. break;
  6430. case MF_JEXP:
  6431. map[m].jexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  6432. break;
  6433. case MF_BEXP:
  6434. map[m].bexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  6435. break;
  6436. case MF_NOVENDING:
  6437. map[m].flag.novending=1;
  6438. break;
  6439. case MF_LOADEVENT:
  6440. map[m].flag.loadevent=1;
  6441. break;
  6442. case MF_NOCHAT:
  6443. map[m].flag.nochat=1;
  6444. }
  6445. }
  6446. return 0;
  6447. }
  6448. int buildin_removemapflag(struct script_state *st)
  6449. {
  6450. int m,i;
  6451. char *str;
  6452. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6453. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6454. m = map_mapname2mapid(str);
  6455. if(m >= 0) {
  6456. switch(i) {
  6457. case MF_NOMEMO:
  6458. map[m].flag.nomemo=0;
  6459. break;
  6460. case MF_NOTELEPORT:
  6461. map[m].flag.noteleport=0;
  6462. break;
  6463. case MF_NOSAVE:
  6464. map[m].flag.nosave=0;
  6465. break;
  6466. case MF_NOBRANCH:
  6467. map[m].flag.nobranch=0;
  6468. break;
  6469. case MF_NOPENALTY:
  6470. map[m].flag.nopenalty=0;
  6471. break;
  6472. case MF_PVP:
  6473. map[m].flag.pvp=0;
  6474. break;
  6475. case MF_PVP_NOPARTY:
  6476. map[m].flag.pvp_noparty=0;
  6477. break;
  6478. case MF_PVP_NOGUILD:
  6479. map[m].flag.pvp_noguild=0;
  6480. break;
  6481. case MF_GVG:
  6482. map[m].flag.gvg=0;
  6483. break;
  6484. case MF_GVG_NOPARTY:
  6485. map[m].flag.gvg_noparty=0;
  6486. break;
  6487. case MF_GVG_DUNGEON:
  6488. map[m].flag.gvg_dungeon=0;
  6489. break;
  6490. case MF_GVG_CASTLE:
  6491. map[m].flag.gvg_castle=0;
  6492. break;
  6493. case MF_NOZENYPENALTY:
  6494. map[m].flag.nozenypenalty=0;
  6495. break;
  6496. case MF_NOTRADE:
  6497. map[m].flag.notrade=0;
  6498. break;
  6499. case MF_NODROP:
  6500. map[m].flag.nodrop=0;
  6501. break;
  6502. case MF_NOSKILL:
  6503. map[m].flag.noskill=0;
  6504. break;
  6505. case MF_NOWARP:
  6506. map[m].flag.nowarp=0;
  6507. break;
  6508. case MF_NOICEWALL: // [Valaris]
  6509. map[m].flag.noicewall=0;
  6510. break;
  6511. case MF_SNOW: // [Valaris]
  6512. map[m].flag.snow=0;
  6513. break;
  6514. case MF_CLOUDS:
  6515. map[m].flag.clouds=0;
  6516. break;
  6517. case MF_CLOUDS2: // [Valaris]
  6518. map[m].flag.clouds2=0;
  6519. break;
  6520. case MF_FOG: // [Valaris]
  6521. map[m].flag.fog=0;
  6522. break;
  6523. case MF_FIREWORKS:
  6524. map[m].flag.fireworks=0;
  6525. break;
  6526. case MF_SAKURA: // [Valaris]
  6527. map[m].flag.sakura=0;
  6528. break;
  6529. case MF_LEAVES: // [Valaris]
  6530. map[m].flag.leaves=0;
  6531. break;
  6532. case MF_RAIN: // [Valaris]
  6533. map[m].flag.rain=0;
  6534. break;
  6535. case MF_INDOORS: // celest
  6536. map[m].flag.indoors=0;
  6537. break;
  6538. case MF_NIGHTENABLED:
  6539. map[m].flag.nightenabled=0;
  6540. break;
  6541. case MF_NOGO: // celest
  6542. map[m].flag.nogo=0;
  6543. break;
  6544. case MF_NOBASEEXP:
  6545. map[m].flag.nobaseexp=0;
  6546. break;
  6547. case MF_NOJOBEXP:
  6548. map[m].flag.nojobexp=0;
  6549. break;
  6550. case MF_NOMOBLOOT:
  6551. map[m].flag.nomobloot=0;
  6552. break;
  6553. case MF_NOMVPLOOT:
  6554. map[m].flag.nomvploot=0;
  6555. break;
  6556. case MF_NORETURN:
  6557. map[m].flag.noreturn=0;
  6558. break;
  6559. case MF_NOWARPTO:
  6560. map[m].flag.nowarpto=0;
  6561. break;
  6562. case MF_NIGHTMAREDROP:
  6563. map[m].flag.pvp_nightmaredrop=0;
  6564. break;
  6565. case MF_RESTRICTED:
  6566. map[m].flag.restricted=0;
  6567. break;
  6568. case MF_NOCOMMAND:
  6569. map[m].flag.nocommand=0;
  6570. break;
  6571. case MF_JEXP:
  6572. map[m].jexp=100;
  6573. break;
  6574. case MF_BEXP:
  6575. map[m].bexp=100;
  6576. break;
  6577. case MF_NOVENDING:
  6578. map[m].flag.novending=0;
  6579. break;
  6580. case MF_LOADEVENT:
  6581. map[m].flag.loadevent=0;
  6582. break;
  6583. case MF_NOCHAT:
  6584. map[m].flag.nochat=0;
  6585. }
  6586. }
  6587. return 0;
  6588. }
  6589. int buildin_pvpon(struct script_state *st)
  6590. {
  6591. int m,i,users;
  6592. char *str;
  6593. struct map_session_data *pl_sd=NULL, **pl_allsd;
  6594. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6595. m = map_mapname2mapid(str);
  6596. if(m >= 0 && !map[m].flag.pvp) {
  6597. map[m].flag.pvp = 1;
  6598. clif_send0199(m,1);
  6599. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  6600. return 0;
  6601. pl_allsd = map_getallusers(&users);
  6602. for(i=0;i<users;i++)
  6603. {
  6604. if ((pl_sd = pl_allsd[i]) && m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
  6605. {
  6606. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  6607. pl_sd->pvp_rank=0;
  6608. pl_sd->pvp_lastusers=0;
  6609. pl_sd->pvp_point=5;
  6610. pl_sd->pvp_won = 0;
  6611. pl_sd->pvp_lost = 0;
  6612. }
  6613. }
  6614. }
  6615. return 0;
  6616. }
  6617. int buildin_pvpoff(struct script_state *st)
  6618. {
  6619. int m,i,users;
  6620. char *str;
  6621. struct map_session_data *pl_sd=NULL, **pl_allsd;
  6622. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6623. m = map_mapname2mapid(str);
  6624. if(m >= 0 && map[m].flag.pvp) { //fixed Lupus
  6625. map[m].flag.pvp = 0;
  6626. clif_send0199(m,0);
  6627. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  6628. return 0;
  6629. pl_allsd = map_getallusers(&users);
  6630. for(i=0;i<users;i++)
  6631. {
  6632. if((pl_sd=pl_allsd[i]) && m == pl_sd->bl.m)
  6633. {
  6634. clif_pvpset(pl_sd,0,0,2);
  6635. if(pl_sd->pvp_timer != -1) {
  6636. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  6637. pl_sd->pvp_timer = -1;
  6638. }
  6639. }
  6640. }
  6641. }
  6642. return 0;
  6643. }
  6644. int buildin_gvgon(struct script_state *st)
  6645. {
  6646. int m;
  6647. char *str;
  6648. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6649. m = map_mapname2mapid(str);
  6650. if(m >= 0 && !map[m].flag.gvg) {
  6651. map[m].flag.gvg = 1;
  6652. clif_send0199(m,3);
  6653. }
  6654. return 0;
  6655. }
  6656. int buildin_gvgoff(struct script_state *st)
  6657. {
  6658. int m;
  6659. char *str;
  6660. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6661. m = map_mapname2mapid(str);
  6662. if(m >= 0 && map[m].flag.gvg) {
  6663. map[m].flag.gvg = 0;
  6664. clif_send0199(m,0);
  6665. }
  6666. return 0;
  6667. }
  6668. /*==========================================
  6669. * Shows an emoticon on top of the player/npc
  6670. * emotion emotion#, <target: 0 - NPC, 1 - PC>
  6671. *------------------------------------------
  6672. */
  6673. //Optional second parameter added by [Skotlex]
  6674. int buildin_emotion(struct script_state *st)
  6675. {
  6676. int type;
  6677. int player=0;
  6678. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6679. if(type < 0 || type > 100)
  6680. return 0;
  6681. if( st->end>st->start+3 )
  6682. player=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6683. if (player) {
  6684. struct map_session_data *sd = script_rid2sd(st);
  6685. if (sd)
  6686. clif_emotion(&sd->bl,type);
  6687. } else
  6688. clif_emotion(map_id2bl(st->oid),type);
  6689. return 0;
  6690. }
  6691. int buildin_maprespawnguildid_sub(struct block_list *bl,va_list ap)
  6692. {
  6693. int g_id=va_arg(ap,int);
  6694. int flag=va_arg(ap,int);
  6695. struct map_session_data *sd=NULL;
  6696. struct mob_data *md=NULL;
  6697. if(bl->type == BL_PC)
  6698. sd=(struct map_session_data*)bl;
  6699. if(bl->type == BL_MOB)
  6700. md=(struct mob_data *)bl;
  6701. if(sd){
  6702. if((sd->status.guild_id == g_id) && (flag&1))
  6703. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  6704. else if((sd->status.guild_id != g_id) && (flag&2))
  6705. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  6706. else if (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  6707. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3); // end addition [Valaris]
  6708. }
  6709. if(md && flag&4){
  6710. if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
  6711. unit_remove_map(bl,1);
  6712. }
  6713. return 0;
  6714. }
  6715. int buildin_maprespawnguildid(struct script_state *st)
  6716. {
  6717. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6718. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6719. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6720. int m=map_mapname2mapid(mapname);
  6721. if(m) map_foreachinmap(buildin_maprespawnguildid_sub,m,BL_CHAR,g_id,flag);
  6722. return 0;
  6723. }
  6724. int buildin_agitstart(struct script_state *st)
  6725. {
  6726. if(agit_flag==1) return 0; // Agit already Start.
  6727. agit_flag=1;
  6728. guild_agit_start();
  6729. return 0;
  6730. }
  6731. int buildin_agitend(struct script_state *st)
  6732. {
  6733. if(agit_flag==0) return 0; // Agit already End.
  6734. agit_flag=0;
  6735. guild_agit_end();
  6736. return 0;
  6737. }
  6738. /*==========================================
  6739. * agitcheck 1; // choice script
  6740. * if(@agit_flag == 1) goto agit;
  6741. * if(agitcheck(0) == 1) goto agit;
  6742. *------------------------------------------
  6743. */
  6744. int buildin_agitcheck(struct script_state *st)
  6745. {
  6746. struct map_session_data *sd;
  6747. int cond;
  6748. cond=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6749. if(cond == 0) {
  6750. if (agit_flag==1) push_val(st->stack,C_INT,1);
  6751. if (agit_flag==0) push_val(st->stack,C_INT,0);
  6752. } else {
  6753. sd=script_rid2sd(st);
  6754. if (agit_flag==1) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),1);
  6755. if (agit_flag==0) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),0);
  6756. }
  6757. return 0;
  6758. }
  6759. int buildin_flagemblem(struct script_state *st)
  6760. {
  6761. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6762. if(g_id < 0) return 0;
  6763. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  6764. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  6765. return 0;
  6766. }
  6767. int buildin_getcastlename(struct script_state *st)
  6768. {
  6769. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6770. struct guild_castle *gc;
  6771. int i;
  6772. for(i=0;i<MAX_GUILDCASTLE;i++){
  6773. if( (gc=guild_castle_search(i)) != NULL ){
  6774. if(strcmp(mapname,gc->map_name)==0){
  6775. break;
  6776. }
  6777. }
  6778. }
  6779. if(gc)
  6780. push_str(st->stack,C_CONSTSTR,(unsigned char *) gc->castle_name);
  6781. else
  6782. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  6783. return 0;
  6784. }
  6785. int buildin_getcastledata(struct script_state *st)
  6786. {
  6787. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6788. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6789. char *event=NULL;
  6790. struct guild_castle *gc;
  6791. int i,j;
  6792. if( st->end>st->start+4 && index==0){
  6793. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  6794. if( (gc=guild_castle_search(i)) != NULL &&
  6795. strcmp(mapname,gc->map_name)==0 )
  6796. j=i;
  6797. if(j>=0){
  6798. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6799. check_event(st, event);
  6800. guild_addcastleinfoevent(j,17,event);
  6801. }
  6802. }
  6803. for(i=0;i<MAX_GUILDCASTLE;i++){
  6804. if( (gc=guild_castle_search(i)) != NULL ){
  6805. if(strcmp(mapname,gc->map_name)==0){
  6806. switch(index){
  6807. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  6808. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  6809. case 2: push_val(st->stack,C_INT,gc->economy); break;
  6810. case 3: push_val(st->stack,C_INT,gc->defense); break;
  6811. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  6812. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  6813. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  6814. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  6815. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  6816. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  6817. case 10:
  6818. case 11:
  6819. case 12:
  6820. case 13:
  6821. case 14:
  6822. case 15:
  6823. case 16:
  6824. case 17:
  6825. push_val(st->stack,C_INT,gc->guardian[index-10].visible); break;
  6826. case 18:
  6827. case 19:
  6828. case 20:
  6829. case 21:
  6830. case 22:
  6831. case 23:
  6832. case 24:
  6833. case 25:
  6834. push_val(st->stack,C_INT,gc->guardian[index-18].hp); break;
  6835. default:
  6836. push_val(st->stack,C_INT,0); break;
  6837. }
  6838. return 0;
  6839. }
  6840. }
  6841. }
  6842. push_val(st->stack,C_INT,0);
  6843. return 0;
  6844. }
  6845. int buildin_setcastledata(struct script_state *st)
  6846. {
  6847. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6848. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6849. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6850. struct guild_castle *gc;
  6851. int i;
  6852. for(i=0;i<MAX_GUILDCASTLE;i++){
  6853. if( (gc=guild_castle_search(i)) != NULL ){
  6854. if(strcmp(mapname,gc->map_name)==0){
  6855. // Save Data byself First
  6856. switch(index){
  6857. case 1: gc->guild_id = value; break;
  6858. case 2: gc->economy = value; break;
  6859. case 3: gc->defense = value; break;
  6860. case 4: gc->triggerE = value; break;
  6861. case 5: gc->triggerD = value; break;
  6862. case 6: gc->nextTime = value; break;
  6863. case 7: gc->payTime = value; break;
  6864. case 8: gc->createTime = value; break;
  6865. case 9: gc->visibleC = value; break;
  6866. case 10:
  6867. case 11:
  6868. case 12:
  6869. case 13:
  6870. case 14:
  6871. case 15:
  6872. case 16:
  6873. case 17:
  6874. gc->guardian[index-10].visible = value; break;
  6875. case 18:
  6876. case 19:
  6877. case 20:
  6878. case 21:
  6879. case 22:
  6880. case 23:
  6881. case 24:
  6882. case 25:
  6883. gc->guardian[index-18].hp = value; break;
  6884. default: return 0;
  6885. }
  6886. guild_castledatasave(gc->castle_id,index,value);
  6887. return 0;
  6888. }
  6889. }
  6890. }
  6891. return 0;
  6892. }
  6893. /* =====================================================================
  6894. * ギルド情報を要求する
  6895. * ---------------------------------------------------------------------
  6896. */
  6897. int buildin_requestguildinfo(struct script_state *st)
  6898. {
  6899. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6900. char *event=NULL;
  6901. if( st->end>st->start+3 ){
  6902. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6903. check_event(st, event);
  6904. }
  6905. if(guild_id>0)
  6906. guild_npc_request_info(guild_id,event);
  6907. return 0;
  6908. }
  6909. /* =====================================================================
  6910. * カードの数を得る
  6911. * ---------------------------------------------------------------------
  6912. */
  6913. int buildin_getequipcardcnt(struct script_state *st)
  6914. {
  6915. int i,num;
  6916. struct map_session_data *sd;
  6917. int c=MAX_SLOTS;
  6918. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6919. sd=script_rid2sd(st);
  6920. i=pc_checkequip(sd,equip[num-1]);
  6921. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  6922. {
  6923. push_val(st->stack,C_INT,0);
  6924. return 0;
  6925. }
  6926. do{
  6927. if(sd->status.inventory[i].card[c-1] &&
  6928. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  6929. push_val(st->stack,C_INT,(c));
  6930. return 0;
  6931. }
  6932. }while(c--);
  6933. push_val(st->stack,C_INT,0);
  6934. return 0;
  6935. }
  6936. /* ================================================================
  6937. * カード取り外し成功
  6938. * ----------------------------------------------------------------
  6939. */
  6940. int buildin_successremovecards(struct script_state *st)
  6941. {
  6942. int i,j,num,cardflag=0,flag;
  6943. struct map_session_data *sd;
  6944. struct item item_tmp;
  6945. int c=MAX_SLOTS;
  6946. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6947. sd=script_rid2sd(st);
  6948. i=pc_checkequip(sd,equip[num-1]);
  6949. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  6950. return 0;
  6951. do{
  6952. if(sd->status.inventory[i].card[c-1] &&
  6953. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  6954. cardflag = 1;
  6955. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  6956. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  6957. item_tmp.attribute=0;
  6958. for (j = 0; j < MAX_SLOTS; j++)
  6959. item_tmp.card[j]=0;
  6960. //Logs items, got from (N)PC scripts [Lupus]
  6961. if(log_config.pick > 0 ) {
  6962. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  6963. }
  6964. //Logs
  6965. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  6966. clif_additem(sd,0,0,flag);
  6967. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  6968. }
  6969. }
  6970. }while(c--);
  6971. if(cardflag == 1){ // カードを取り除いたアイテム所得
  6972. flag=0;
  6973. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  6974. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  6975. item_tmp.attribute=sd->status.inventory[i].attribute;
  6976. //Logs items, got from (N)PC scripts [Lupus]
  6977. if(log_config.pick > 0 ) {
  6978. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  6979. }
  6980. //Logs
  6981. for (j = 0; j < MAX_SLOTS; j++)
  6982. item_tmp.card[j]=0;
  6983. pc_delitem(sd,i,1,0);
  6984. //Logs items, got from (N)PC scripts [Lupus]
  6985. if(log_config.pick > 0 ) {
  6986. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  6987. }
  6988. //Logs
  6989. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  6990. clif_additem(sd,0,0,flag);
  6991. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  6992. }
  6993. clif_misceffect(&sd->bl,3);
  6994. return 0;
  6995. }
  6996. return 0;
  6997. }
  6998. /* ================================================================
  6999. * カード取り外し失敗 slot,type
  7000. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  7001. * ----------------------------------------------------------------
  7002. */
  7003. int buildin_failedremovecards(struct script_state *st)
  7004. {
  7005. int i,j,num,cardflag=0,flag,typefail;
  7006. struct map_session_data *sd;
  7007. struct item item_tmp;
  7008. int c=MAX_SLOTS;
  7009. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7010. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7011. sd=script_rid2sd(st);
  7012. i=pc_checkequip(sd,equip[num-1]);
  7013. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  7014. return 0;
  7015. do{
  7016. if(sd->status.inventory[i].card[c-1] &&
  7017. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  7018. cardflag = 1;
  7019. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  7020. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  7021. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  7022. item_tmp.attribute=0;
  7023. for (j = 0; j < MAX_SLOTS; j++)
  7024. item_tmp.card[j]=0;
  7025. //Logs items, got from (N)PC scripts [Lupus]
  7026. if(log_config.pick > 0 ) {
  7027. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  7028. }
  7029. //Logs
  7030. if((flag=pc_additem(sd,&item_tmp,1))){
  7031. clif_additem(sd,0,0,flag);
  7032. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  7033. }
  7034. }
  7035. }
  7036. }while(c--);
  7037. if(cardflag == 1){
  7038. if(typefail == 0 || typefail == 2){ // 武具損失
  7039. //Logs items, got from (N)PC scripts [Lupus]
  7040. if(log_config.pick > 0 ) {
  7041. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  7042. }
  7043. //Logs
  7044. pc_delitem(sd,i,1,0);
  7045. clif_misceffect(&sd->bl,2);
  7046. return 0;
  7047. }
  7048. if(typefail == 1){ // カードのみ損失(武具を返す)
  7049. flag=0;
  7050. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  7051. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  7052. item_tmp.attribute=sd->status.inventory[i].attribute;
  7053. //Logs items, got from (N)PC scripts [Lupus]
  7054. if(log_config.pick > 0 ) {
  7055. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  7056. }
  7057. //Logs
  7058. for (j = 0; j < MAX_SLOTS; j++)
  7059. item_tmp.card[j]=0;
  7060. pc_delitem(sd,i,1,0);
  7061. //Logs items, got from (N)PC scripts [Lupus]
  7062. if(log_config.pick > 0 ) {
  7063. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  7064. }
  7065. //Logs
  7066. if((flag=pc_additem(sd,&item_tmp,1))){
  7067. clif_additem(sd,0,0,flag);
  7068. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  7069. }
  7070. }
  7071. clif_misceffect(&sd->bl,2);
  7072. return 0;
  7073. }
  7074. return 0;
  7075. }
  7076. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  7077. {
  7078. int x,y,m;
  7079. char *str;
  7080. char *mapname;
  7081. unsigned int index;
  7082. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7083. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7084. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7085. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7086. if( (m=map_mapname2mapid(mapname))< 0)
  7087. return 0;
  7088. if(!(index=mapindex_name2id(str)))
  7089. return 0;
  7090. map_foreachinmap(buildin_areawarp_sub,
  7091. m,BL_PC,index,x,y);
  7092. return 0;
  7093. }
  7094. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  7095. {
  7096. char *npc,*command;
  7097. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7098. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7099. npc_command(map_id2sd(st->rid),npc,command);
  7100. return 0;
  7101. }
  7102. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  7103. {
  7104. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  7105. // nd->lastaction=nd->timer=gettick();
  7106. npc_do_ontimer(st->oid, 1);
  7107. return 0;
  7108. }
  7109. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  7110. {
  7111. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  7112. // nd->lastaction=nd->timer=-1;
  7113. npc_do_ontimer(st->oid, 0);
  7114. return 0;
  7115. }
  7116. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  7117. {
  7118. char *event=va_arg(ap,char *);
  7119. int *c=va_arg(ap,int *);
  7120. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  7121. (*c)++;
  7122. return 0;
  7123. }
  7124. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  7125. {
  7126. char *mapname,*event;
  7127. int m,c=0;
  7128. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7129. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7130. check_event(st, event);
  7131. if( (m=map_mapname2mapid(mapname))<0 ) {
  7132. push_val(st->stack,C_INT,-1);
  7133. return 0;
  7134. }
  7135. map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event,&c );
  7136. push_val(st->stack,C_INT, (c));
  7137. return 0;
  7138. }
  7139. int buildin_marriage(struct script_state *st)
  7140. {
  7141. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7142. struct map_session_data *sd=script_rid2sd(st);
  7143. struct map_session_data *p_sd=map_nick2sd(partner);
  7144. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  7145. push_val(st->stack,C_INT,0);
  7146. return 0;
  7147. }
  7148. push_val(st->stack,C_INT,1);
  7149. return 0;
  7150. }
  7151. int buildin_wedding_effect(struct script_state *st)
  7152. {
  7153. struct map_session_data *sd=script_rid2sd(st);
  7154. struct block_list *bl;
  7155. if(sd==NULL) {
  7156. bl=map_id2bl(st->oid);
  7157. } else
  7158. bl=&sd->bl;
  7159. clif_wedding_effect(bl);
  7160. return 0;
  7161. }
  7162. int buildin_divorce(struct script_state *st)
  7163. {
  7164. struct map_session_data *sd=script_rid2sd(st);
  7165. if(sd==NULL || pc_divorce(sd) < 0){
  7166. push_val(st->stack,C_INT,0);
  7167. return 0;
  7168. }
  7169. push_val(st->stack,C_INT,1);
  7170. return 0;
  7171. }
  7172. int buildin_ispartneron(struct script_state *st)
  7173. {
  7174. struct map_session_data *sd=script_rid2sd(st);
  7175. struct map_session_data *p_sd=NULL;
  7176. if(sd==NULL || !pc_ismarried(sd) ||
  7177. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  7178. push_val(st->stack,C_INT,0);
  7179. return 0;
  7180. }
  7181. push_val(st->stack,C_INT,1);
  7182. return 0;
  7183. }
  7184. int buildin_getpartnerid(struct script_state *st)
  7185. {
  7186. struct map_session_data *sd=script_rid2sd(st);
  7187. if (sd == NULL) {
  7188. push_val(st->stack,C_INT,0);
  7189. return 0;
  7190. }
  7191. push_val(st->stack,C_INT,sd->status.partner_id);
  7192. return 0;
  7193. }
  7194. int buildin_getchildid(struct script_state *st)
  7195. {
  7196. struct map_session_data *sd=script_rid2sd(st);
  7197. if (sd == NULL) {
  7198. push_val(st->stack,C_INT,0);
  7199. return 0;
  7200. }
  7201. push_val(st->stack,C_INT,sd->status.child);
  7202. return 0;
  7203. }
  7204. int buildin_getmotherid(struct script_state *st)
  7205. {
  7206. struct map_session_data *sd=script_rid2sd(st);
  7207. if (sd == NULL) {
  7208. push_val(st->stack,C_INT,0);
  7209. return 0;
  7210. }
  7211. push_val(st->stack,C_INT,sd->status.mother);
  7212. return 0;
  7213. }
  7214. int buildin_getfatherid(struct script_state *st)
  7215. {
  7216. struct map_session_data *sd=script_rid2sd(st);
  7217. if (sd == NULL) {
  7218. push_val(st->stack,C_INT,0);
  7219. return 0;
  7220. }
  7221. push_val(st->stack,C_INT,sd->status.father);
  7222. return 0;
  7223. }
  7224. int buildin_warppartner(struct script_state *st)
  7225. {
  7226. int x,y;
  7227. unsigned short mapindex;
  7228. char *str;
  7229. struct map_session_data *sd=script_rid2sd(st);
  7230. struct map_session_data *p_sd=NULL;
  7231. if(sd==NULL || !pc_ismarried(sd) ||
  7232. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  7233. push_val(st->stack,C_INT,0);
  7234. return 0;
  7235. }
  7236. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7237. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7238. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7239. mapindex = mapindex_name2id(str);
  7240. if (mapindex) {
  7241. pc_setpos(p_sd,mapindex,x,y,0);
  7242. push_val(st->stack,C_INT,1);
  7243. } else
  7244. push_val(st->stack,C_INT,0);
  7245. return 0;
  7246. }
  7247. /*================================================
  7248. * Script for Displaying MOB Information [Valaris]
  7249. *------------------------------------------------
  7250. */
  7251. int buildin_strmobinfo(struct script_state *st)
  7252. {
  7253. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7254. int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7255. if((class_>=0 && class_<=1000) || class_ >2000)
  7256. return 0;
  7257. switch (num) {
  7258. case 1:
  7259. push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->name);
  7260. break;
  7261. case 2:
  7262. push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->jname);
  7263. break;
  7264. case 3:
  7265. push_val(st->stack,C_INT,mob_db(class_)->lv);
  7266. break;
  7267. case 4:
  7268. push_val(st->stack,C_INT,mob_db(class_)->status.max_hp);
  7269. break;
  7270. case 5:
  7271. push_val(st->stack,C_INT,mob_db(class_)->status.max_sp);
  7272. break;
  7273. case 6:
  7274. push_val(st->stack,C_INT,mob_db(class_)->base_exp);
  7275. break;
  7276. case 7:
  7277. push_val(st->stack,C_INT,mob_db(class_)->job_exp);
  7278. break;
  7279. }
  7280. return 0;
  7281. }
  7282. /*==========================================
  7283. * Summon guardians [Valaris]
  7284. *------------------------------------------
  7285. */
  7286. int buildin_guardian(struct script_state *st)
  7287. {
  7288. int class_=0,amount=1,x=0,y=0,guardian=0;
  7289. char *str,*map,*event="";
  7290. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  7291. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  7292. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  7293. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  7294. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  7295. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  7296. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  7297. if( st->end>st->start+9 )
  7298. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  7299. check_event(st, event);
  7300. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
  7301. return 0;
  7302. }
  7303. /*================================================
  7304. * Script for Displaying Guardian Info [Valaris]
  7305. *------------------------------------------------
  7306. */
  7307. int buildin_guardianinfo(struct script_state *st)
  7308. {
  7309. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7310. struct map_session_data *sd=script_rid2sd(st);
  7311. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  7312. if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
  7313. {
  7314. push_val(st->stack,C_INT,-1);
  7315. return 0;
  7316. }
  7317. if(gc->guardian[guardian].visible)
  7318. push_val(st->stack,C_INT,gc->guardian[guardian].hp);
  7319. else push_val(st->stack,C_INT,-1);
  7320. return 0;
  7321. }
  7322. /*==========================================
  7323. * IDからItem名
  7324. *------------------------------------------
  7325. */
  7326. int buildin_getitemname(struct script_state *st)
  7327. {
  7328. int item_id=0;
  7329. struct item_data *i_data;
  7330. char *item_name;
  7331. struct script_data *data;
  7332. data=&(st->stack->stack_data[st->start+2]);
  7333. get_val(st,data);
  7334. if( data->type==C_STR || data->type==C_CONSTSTR ){
  7335. const char *name=conv_str(st,data);
  7336. struct item_data *item_data = itemdb_searchname(name);
  7337. if( item_data )
  7338. item_id=item_data->nameid;
  7339. }else
  7340. item_id=conv_num(st,data);
  7341. i_data = itemdb_exists(item_id);
  7342. if (i_data == NULL)
  7343. {
  7344. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  7345. return 0;
  7346. }
  7347. item_name=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  7348. memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
  7349. push_str(st->stack,C_STR,(unsigned char *) item_name);
  7350. return 0;
  7351. }
  7352. /*==========================================
  7353. * Returns number of slots an item has. [Skotlex]
  7354. *------------------------------------------
  7355. */
  7356. int buildin_getitemslots(struct script_state *st)
  7357. {
  7358. int item_id;
  7359. struct item_data *i_data;
  7360. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7361. i_data = itemdb_exists(item_id);
  7362. if (i_data)
  7363. push_val(st->stack,C_INT,i_data->slot);
  7364. else
  7365. push_val(st->stack,C_INT,-1);
  7366. return 0;
  7367. }
  7368. /*==========================================
  7369. * Returns some values of an item [Lupus]
  7370. * Price, Weight, etc...
  7371. getiteminfo(itemID,n), where n
  7372. 0 value_buy;
  7373. 1 value_sell;
  7374. 2 type;
  7375. 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
  7376. if = 0, then monsters don't drop it at all (rare or a quest item)
  7377. if = 10000, then this item is sold in NPC shops only
  7378. 4 sex;
  7379. 5 equip;
  7380. 6 weight;
  7381. 7 atk;
  7382. 8 def;
  7383. 9 range;
  7384. 10 slot;
  7385. 11 look;
  7386. 12 elv;
  7387. 13 wlv;
  7388. *------------------------------------------
  7389. */
  7390. int buildin_getiteminfo(struct script_state *st)
  7391. {
  7392. int item_id,n;
  7393. int *item_arr;
  7394. struct item_data *i_data;
  7395. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7396. n = conv_num(st,& (st->stack->stack_data[st->start+3]));
  7397. i_data = itemdb_exists(item_id);
  7398. if (i_data && n>=0 && n<14) {
  7399. item_arr = (int*)&i_data->value_buy;
  7400. push_val(st->stack,C_INT,item_arr[n]);
  7401. } else
  7402. push_val(st->stack,C_INT,-1);
  7403. return 0;
  7404. }
  7405. /*==========================================
  7406. * Returns value from equipped item slot n [Lupus]
  7407. getequipcardid(num,slot)
  7408. where
  7409. num = eqip position slot
  7410. slot = 0,1,2,3 (Card Slot N)
  7411. This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
  7412. it's useful when you want to check item cards or if it's signed
  7413. Useful for such quests as "Sign this refined item with players name" etc
  7414. Hat[0] +4 -> Player's Hat[0] +4
  7415. *------------------------------------------
  7416. */
  7417. int buildin_getequipcardid(struct script_state *st)
  7418. {
  7419. int i,num,slot;
  7420. struct map_session_data *sd;
  7421. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7422. slot=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7423. sd=script_rid2sd(st);
  7424. i=pc_checkequip(sd,equip[num-1]);
  7425. if(i >= 0 && slot>=0 && slot<4)
  7426. push_val(st->stack,C_INT,sd->status.inventory[i].card[slot]);
  7427. else
  7428. push_val(st->stack,C_INT,0);
  7429. return 0;
  7430. }
  7431. /*==========================================
  7432. * petskillbonus [Valaris] //Rewritten by [Skotlex]
  7433. *------------------------------------------
  7434. */
  7435. int buildin_petskillbonus(struct script_state *st)
  7436. {
  7437. struct pet_data *pd;
  7438. struct map_session_data *sd=script_rid2sd(st);
  7439. if(sd==NULL || sd->pd==NULL)
  7440. return 0;
  7441. pd=sd->pd;
  7442. if (pd->bonus)
  7443. { //Clear previous bonus
  7444. if (pd->bonus->timer != -1)
  7445. delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
  7446. } else //init
  7447. pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
  7448. pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7449. pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7450. pd->bonus->duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7451. pd->bonus->delay=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7452. if (pd->state.skillbonus == 1)
  7453. pd->state.skillbonus=0; // waiting state
  7454. // wait for timer to start
  7455. if (battle_config.pet_equip_required && pd->equip == 0)
  7456. pd->bonus->timer=-1;
  7457. else
  7458. pd->bonus->timer=add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
  7459. return 0;
  7460. }
  7461. /*==========================================
  7462. * pet looting [Valaris] //Rewritten by [Skotlex]
  7463. *------------------------------------------
  7464. */
  7465. int buildin_petloot(struct script_state *st)
  7466. {
  7467. int max;
  7468. struct pet_data *pd;
  7469. struct map_session_data *sd=script_rid2sd(st);
  7470. if(sd==NULL || sd->pd==NULL)
  7471. return 0;
  7472. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7473. if(max < 1)
  7474. max = 1; //Let'em loot at least 1 item.
  7475. else if (max > MAX_PETLOOT_SIZE)
  7476. max = MAX_PETLOOT_SIZE;
  7477. pd = sd->pd;
  7478. if (pd->loot != NULL)
  7479. { //Release whatever was there already and reallocate memory
  7480. pet_lootitem_drop(pd, pd->msd);
  7481. aFree(pd->loot->item);
  7482. }
  7483. else
  7484. pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
  7485. pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
  7486. pd->loot->max=max;
  7487. pd->loot->count = 0;
  7488. pd->loot->weight = 0;
  7489. return 0;
  7490. }
  7491. /*==========================================
  7492. * PCの所持品情報読み取り
  7493. *------------------------------------------
  7494. */
  7495. int buildin_getinventorylist(struct script_state *st)
  7496. {
  7497. struct map_session_data *sd=script_rid2sd(st);
  7498. unsigned char card_var[NAME_LENGTH];
  7499. int i,j=0,k;
  7500. if(!sd) return 0;
  7501. for(i=0;i<MAX_INVENTORY;i++){
  7502. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  7503. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  7504. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  7505. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  7506. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  7507. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  7508. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  7509. for (k = 0; k < MAX_SLOTS; k++)
  7510. {
  7511. sprintf(card_var, "@inventorylist_card%d",k+1);
  7512. pc_setreg(sd,add_str(card_var)+(j<<24),sd->status.inventory[i].card[k]);
  7513. }
  7514. j++;
  7515. }
  7516. }
  7517. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_count"),j);
  7518. return 0;
  7519. }
  7520. int buildin_getskilllist(struct script_state *st)
  7521. {
  7522. struct map_session_data *sd=script_rid2sd(st);
  7523. int i,j=0;
  7524. if(!sd) return 0;
  7525. for(i=0;i<MAX_SKILL;i++){
  7526. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  7527. pc_setreg(sd,add_str((unsigned char *) "@skilllist_id")+(j<<24),sd->status.skill[i].id);
  7528. pc_setreg(sd,add_str((unsigned char *)"@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  7529. pc_setreg(sd,add_str((unsigned char *)"@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  7530. j++;
  7531. }
  7532. }
  7533. pc_setreg(sd,add_str((unsigned char *) "@skilllist_count"),j);
  7534. return 0;
  7535. }
  7536. int buildin_clearitem(struct script_state *st)
  7537. {
  7538. struct map_session_data *sd=script_rid2sd(st);
  7539. int i;
  7540. if(sd==NULL) return 0;
  7541. for (i=0; i<MAX_INVENTORY; i++) {
  7542. if (sd->status.inventory[i].amount) {
  7543. //Logs items, got from (N)PC scripts [Lupus]
  7544. if(log_config.pick > 0 ) {
  7545. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  7546. }
  7547. //Logs
  7548. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  7549. }
  7550. }
  7551. return 0;
  7552. }
  7553. /*==========================================
  7554. Disguise Player (returns Mob/NPC ID if success, 0 on fail) [Lupus]
  7555. *------------------------------------------
  7556. */
  7557. int buildin_disguise(struct script_state *st)
  7558. {
  7559. struct map_session_data *sd=script_rid2sd(st);
  7560. int id;
  7561. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7562. if (!mobdb_checkid(id) && !npcdb_checkid(id)) {
  7563. push_val(st->stack,C_INT,0);
  7564. return 0;
  7565. }
  7566. pc_disguise(sd, id);
  7567. push_val(st->stack,C_INT,id);
  7568. return 0;
  7569. }
  7570. /*==========================================
  7571. Undisguise Player (returns 1 if success, 0 on fail) [Lupus]
  7572. *------------------------------------------
  7573. */
  7574. int buildin_undisguise(struct script_state *st)
  7575. {
  7576. struct map_session_data *sd=script_rid2sd(st);
  7577. if (sd->disguise) {
  7578. pc_disguise(sd, 0);
  7579. push_val(st->stack,C_INT,0);
  7580. } else {
  7581. push_val(st->stack,C_INT,1);
  7582. }
  7583. return 0;
  7584. }
  7585. /*==========================================
  7586. * NPCクラスチェンジ
  7587. * classは変わりたいclass
  7588. * typeは通常0なのかな?
  7589. *------------------------------------------
  7590. */
  7591. int buildin_classchange(struct script_state *st)
  7592. {
  7593. int _class,type;
  7594. struct block_list *bl=map_id2bl(st->oid);
  7595. if(bl==NULL) return 0;
  7596. _class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7597. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7598. clif_class_change(bl,_class,type);
  7599. return 0;
  7600. }
  7601. /*==========================================
  7602. * NPCから発生するエフェクト
  7603. *------------------------------------------
  7604. */
  7605. int buildin_misceffect(struct script_state *st)
  7606. {
  7607. int type;
  7608. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7609. if(st->oid) {
  7610. struct block_list *bl = map_id2bl(st->oid);
  7611. if (bl)
  7612. clif_misceffect2(bl,type);
  7613. } else{
  7614. struct map_session_data *sd=script_rid2sd(st);
  7615. if(sd)
  7616. clif_misceffect2(&sd->bl,type);
  7617. }
  7618. return 0;
  7619. }
  7620. /*==========================================
  7621. * サウンドエフェクト
  7622. *------------------------------------------
  7623. */
  7624. int buildin_soundeffect(struct script_state *st)
  7625. {
  7626. // Redundn
  7627. struct map_session_data *sd=script_rid2sd(st);
  7628. char *name;
  7629. int type=0;
  7630. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7631. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7632. if(sd){
  7633. if(!st->rid)
  7634. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  7635. else{
  7636. clif_soundeffect(sd,&sd->bl,name,type);
  7637. }
  7638. }
  7639. return 0;
  7640. }
  7641. int soundeffect_sub(struct block_list* bl,va_list ap)
  7642. {
  7643. char *name;
  7644. int type;
  7645. nullpo_retr(0, bl);
  7646. nullpo_retr(0, ap);
  7647. name = va_arg(ap,char *);
  7648. type = va_arg(ap,int);
  7649. clif_soundeffect((struct map_session_data *)bl, bl, name, type);
  7650. return 0;
  7651. }
  7652. int buildin_soundeffectall(struct script_state *st)
  7653. {
  7654. // [Lance] - Improved.
  7655. char *name, *map = NULL;
  7656. struct block_list *bl;
  7657. int type, coverage, x0, y0, x1, y1;
  7658. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7659. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7660. coverage=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7661. if(!st->rid)
  7662. bl = map_id2bl(st->oid);
  7663. else
  7664. bl = &(script_rid2sd(st)->bl);
  7665. if(bl){
  7666. if(coverage < 23){
  7667. clif_soundeffectall(bl,name,type,coverage);
  7668. }else {
  7669. if(st->end > st->start+9){
  7670. map=conv_str(st,& (st->stack->stack_data[st->start+5]));
  7671. x0 = conv_num(st,& (st->stack->stack_data[st->start+6]));
  7672. y0 = conv_num(st,& (st->stack->stack_data[st->start+7]));
  7673. x1 = conv_num(st,& (st->stack->stack_data[st->start+8]));
  7674. y1 = conv_num(st,& (st->stack->stack_data[st->start+9]));
  7675. map_foreachinarea(soundeffect_sub,map_mapname2mapid(map),x0,y0,x1,y1,BL_PC,name,type);
  7676. } else {
  7677. ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
  7678. }
  7679. }
  7680. }
  7681. return 0;
  7682. }
  7683. /*==========================================
  7684. * pet status recovery [Valaris] / Rewritten by [Skotlex]
  7685. *------------------------------------------
  7686. */
  7687. int buildin_petrecovery(struct script_state *st)
  7688. {
  7689. struct pet_data *pd;
  7690. struct map_session_data *sd=script_rid2sd(st);
  7691. if(sd==NULL || sd->pd==NULL)
  7692. return 0;
  7693. pd=sd->pd;
  7694. if (pd->recovery)
  7695. { //Halt previous bonus
  7696. if (pd->recovery->timer != -1)
  7697. delete_timer(pd->recovery->timer, pet_recovery_timer);
  7698. } else //Init
  7699. pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
  7700. pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7701. pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7702. pd->recovery->timer=-1;
  7703. return 0;
  7704. }
  7705. /*==========================================
  7706. * pet healing [Valaris] //Rewritten by [Skotlex]
  7707. *------------------------------------------
  7708. */
  7709. int buildin_petheal(struct script_state *st)
  7710. {
  7711. struct pet_data *pd;
  7712. struct map_session_data *sd=script_rid2sd(st);
  7713. if(sd==NULL || sd->pd==NULL)
  7714. return 0;
  7715. pd=sd->pd;
  7716. if (pd->s_skill)
  7717. { //Clear previous skill
  7718. if (pd->s_skill->timer != -1)
  7719. {
  7720. if (pd->s_skill->id)
  7721. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  7722. else
  7723. delete_timer(pd->s_skill->timer, pet_heal_timer);
  7724. }
  7725. } else //init memory
  7726. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  7727. pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
  7728. //Use the lv as the amount to heal
  7729. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7730. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7731. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7732. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7733. //Use delay as initial offset to avoid skill/heal exploits
  7734. if (battle_config.pet_equip_required && pd->equip == 0)
  7735. pd->s_skill->timer=-1;
  7736. else
  7737. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
  7738. return 0;
  7739. }
  7740. /*==========================================
  7741. * pet attack skills [Valaris] //Rewritten by [Skotlex]
  7742. *------------------------------------------
  7743. */
  7744. int buildin_petskillattack(struct script_state *st)
  7745. {
  7746. struct pet_data *pd;
  7747. struct map_session_data *sd=script_rid2sd(st);
  7748. if(sd==NULL || sd->pd==NULL)
  7749. return 0;
  7750. pd=sd->pd;
  7751. if (pd->a_skill == NULL)
  7752. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  7753. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7754. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7755. pd->a_skill->div_ = 0;
  7756. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7757. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7758. return 0;
  7759. }
  7760. /*==========================================
  7761. * pet attack skills [Valaris]
  7762. *------------------------------------------
  7763. */
  7764. int buildin_petskillattack2(struct script_state *st)
  7765. {
  7766. struct pet_data *pd;
  7767. struct map_session_data *sd=script_rid2sd(st);
  7768. if(sd==NULL || sd->pd==NULL)
  7769. return 0;
  7770. pd=sd->pd;
  7771. if (pd->a_skill == NULL)
  7772. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  7773. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7774. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7775. pd->a_skill->div_ = conv_num(st,& (st->stack->stack_data[st->start+4]));
  7776. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7777. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+6]));
  7778. return 0;
  7779. }
  7780. /*==========================================
  7781. * pet support skills [Skotlex]
  7782. *------------------------------------------
  7783. */
  7784. int buildin_petskillsupport(struct script_state *st)
  7785. {
  7786. struct pet_data *pd;
  7787. struct map_session_data *sd=script_rid2sd(st);
  7788. if(sd==NULL || sd->pd==NULL)
  7789. return 0;
  7790. pd=sd->pd;
  7791. if (pd->s_skill)
  7792. { //Clear previous skill
  7793. if (pd->s_skill->timer != -1)
  7794. {
  7795. if (pd->s_skill->id)
  7796. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  7797. else
  7798. delete_timer(pd->s_skill->timer, pet_heal_timer);
  7799. }
  7800. } else //init memory
  7801. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  7802. pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7803. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7804. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7805. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7806. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+6]));
  7807. //Use delay as initial offset to avoid skill/heal exploits
  7808. if (battle_config.pet_equip_required && pd->equip == 0)
  7809. pd->s_skill->timer=-1;
  7810. else
  7811. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
  7812. return 0;
  7813. }
  7814. /*==========================================
  7815. * Scripted skill effects [Celest]
  7816. *------------------------------------------
  7817. */
  7818. int buildin_skilleffect(struct script_state *st)
  7819. {
  7820. struct map_session_data *sd;
  7821. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7822. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7823. sd=script_rid2sd(st);
  7824. clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
  7825. return 0;
  7826. }
  7827. /*==========================================
  7828. * NPC skill effects [Valaris]
  7829. *------------------------------------------
  7830. */
  7831. int buildin_npcskilleffect(struct script_state *st)
  7832. {
  7833. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7834. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7835. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7836. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7837. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7838. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  7839. return 0;
  7840. }
  7841. /*==========================================
  7842. * Special effects [Valaris]
  7843. *------------------------------------------
  7844. */
  7845. int buildin_specialeffect(struct script_state *st)
  7846. {
  7847. struct block_list *bl=map_id2bl(st->oid);
  7848. if(bl==NULL)
  7849. return 0;
  7850. 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));
  7851. return 0;
  7852. }
  7853. int buildin_specialeffect2(struct script_state *st)
  7854. {
  7855. struct map_session_data *sd=script_rid2sd(st);
  7856. if(sd==NULL)
  7857. return 0;
  7858. 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));
  7859. return 0;
  7860. }
  7861. /*==========================================
  7862. * Nude [Valaris]
  7863. *------------------------------------------
  7864. */
  7865. int buildin_nude(struct script_state *st)
  7866. {
  7867. struct map_session_data *sd=script_rid2sd(st);
  7868. int i,calcflag=0;
  7869. if(sd==NULL)
  7870. return 0;
  7871. for(i=0;i<11;i++)
  7872. if(sd->equip_index[i] >= 0) {
  7873. if(!calcflag)
  7874. calcflag=1;
  7875. pc_unequipitem(sd,sd->equip_index[i],2);
  7876. }
  7877. if(calcflag)
  7878. status_calc_pc(sd,0);
  7879. return 0;
  7880. }
  7881. /*==========================================
  7882. * gmcommand [MouseJstr]
  7883. *
  7884. * suggested on the forums...
  7885. * splitted into atcommand & charcommand by [Skotlex]
  7886. *------------------------------------------
  7887. */
  7888. int buildin_atcommand(struct script_state *st)
  7889. {
  7890. struct map_session_data *sd=NULL;
  7891. char *cmd;
  7892. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  7893. if (st->rid)
  7894. sd = script_rid2sd(st);
  7895. if (sd) is_atcommand(sd->fd, sd, cmd, 99);
  7896. else { //Use a dummy character.
  7897. struct map_session_data dummy_sd;
  7898. struct block_list *bl = NULL;
  7899. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  7900. if (st->oid) bl = map_id2bl(st->oid);
  7901. if (bl) {
  7902. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  7903. if (bl->type == BL_NPC)
  7904. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7905. }
  7906. is_atcommand(0, &dummy_sd, cmd, 99);
  7907. }
  7908. return 0;
  7909. }
  7910. int buildin_charcommand(struct script_state *st)
  7911. {
  7912. struct map_session_data *sd=NULL;
  7913. char *cmd;
  7914. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  7915. if (st->rid)
  7916. sd = script_rid2sd(st);
  7917. if (sd) is_charcommand(sd->fd, sd, cmd, 99);
  7918. else { //Use a dummy character.
  7919. struct map_session_data dummy_sd;
  7920. struct block_list *bl = NULL;
  7921. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  7922. if (st->oid) bl = map_id2bl(st->oid);
  7923. if (bl) {
  7924. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  7925. if (bl->type == BL_NPC)
  7926. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7927. }
  7928. is_charcommand(0, &dummy_sd, cmd, 99);
  7929. }
  7930. return 0;
  7931. }
  7932. /*==========================================
  7933. * Displays a message for the player only (like system messages like "you got an apple" )
  7934. *------------------------------------------
  7935. */
  7936. int buildin_dispbottom(struct script_state *st)
  7937. {
  7938. struct map_session_data *sd=script_rid2sd(st);
  7939. char *message;
  7940. message=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7941. if(sd)
  7942. clif_disp_onlyself(sd,message,(int)strlen(message));
  7943. return 0;
  7944. }
  7945. /*==========================================
  7946. * All The Players Full Recovery
  7947. (HP/SP full restore and resurrect if need)
  7948. *------------------------------------------
  7949. */
  7950. int buildin_recovery(struct script_state *st)
  7951. {
  7952. struct map_session_data *sd, **all_sd;
  7953. int i = 0, users;
  7954. all_sd = map_getallusers(&users);
  7955. for (i = 0; i < users; i++)
  7956. {
  7957. sd = all_sd[i];
  7958. if(pc_isdead(sd))
  7959. status_revive(&sd->bl, 100, 100);
  7960. else
  7961. status_percent_heal(&sd->bl, 100, 100);
  7962. clif_displaymessage(sd->fd,"You have been recovered!");
  7963. }
  7964. return 0;
  7965. }
  7966. /*==========================================
  7967. * Get your pet info: getpetinfo(n)
  7968. * n -> 0:pet_id 1:pet_class 2:pet_name
  7969. 3:friendly 4:hungry
  7970. *------------------------------------------
  7971. */
  7972. int buildin_getpetinfo(struct script_state *st)
  7973. {
  7974. struct map_session_data *sd=script_rid2sd(st);
  7975. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7976. if(sd && sd->status.pet_id){
  7977. switch(type){
  7978. case 0:
  7979. push_val(st->stack,C_INT,sd->status.pet_id);
  7980. break;
  7981. case 1:
  7982. push_val(st->stack,C_INT,sd->pet.class_);
  7983. break;
  7984. case 2:
  7985. if(sd->pet.name)
  7986. {
  7987. push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->pet.name);
  7988. }
  7989. else
  7990. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  7991. break;
  7992. case 3:
  7993. //if(sd->pet.intimate)
  7994. push_val(st->stack,C_INT,sd->pet.intimate);
  7995. break;
  7996. case 4:
  7997. //if(sd->pet.hungry)
  7998. push_val(st->stack,C_INT,sd->pet.hungry);
  7999. break;
  8000. default:
  8001. push_val(st->stack,C_INT,0);
  8002. break;
  8003. }
  8004. }else{
  8005. push_val(st->stack,C_INT,0);
  8006. }
  8007. return 0;
  8008. }
  8009. /*==========================================
  8010. * Shows wether your inventory(and equips) contain
  8011. selected card or not.
  8012. checkequipedcard(4001);
  8013. *------------------------------------------
  8014. */
  8015. int buildin_checkequipedcard(struct script_state *st)
  8016. {
  8017. struct map_session_data *sd=script_rid2sd(st);
  8018. int n,i,c=0;
  8019. c=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8020. if(sd){
  8021. for(i=0;i<MAX_INVENTORY;i++){
  8022. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount){
  8023. for(n=0;n<MAX_SLOTS;n++){
  8024. if(sd->status.inventory[i].card[n]==c){
  8025. push_val(st->stack,C_INT,1);
  8026. return 0;
  8027. }
  8028. }
  8029. }
  8030. }
  8031. }
  8032. push_val(st->stack,C_INT,0);
  8033. return 0;
  8034. }
  8035. int buildin_jump_zero(struct script_state *st) {
  8036. int sel;
  8037. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8038. if(!sel) {
  8039. int pos;
  8040. if( st->stack->stack_data[st->start+3].type!=C_POS ){
  8041. ShowError("script: jump_zero: not label !\n");
  8042. st->state=END;
  8043. return 0;
  8044. }
  8045. pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8046. st->pos=pos;
  8047. st->state=GOTO;
  8048. // printf("script: jump_zero: jumpto : %d\n",pos);
  8049. } else {
  8050. // printf("script: jump_zero: fail\n");
  8051. }
  8052. return 0;
  8053. }
  8054. int buildin_select(struct script_state *st)
  8055. {
  8056. char *buf;
  8057. int len,i;
  8058. struct map_session_data *sd;
  8059. sd=script_rid2sd(st);
  8060. if(sd->state.menu_or_input==0){
  8061. st->state=RERUNLINE;
  8062. sd->state.menu_or_input=1;
  8063. for(i=st->start+2,len=16;i<st->end;i++){
  8064. conv_str(st,& (st->stack->stack_data[i]));
  8065. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  8066. }
  8067. buf=(char *)aMalloc((len+1)*sizeof(char));
  8068. buf[0]=0;
  8069. for(i=st->start+2,len=0;i<st->end;i++){
  8070. strcat(buf,st->stack->stack_data[i].u.str);
  8071. strcat(buf,":");
  8072. }
  8073. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  8074. aFree(buf);
  8075. } else if(sd->npc_menu==0xff){ // cansel
  8076. sd->state.menu_or_input=0;
  8077. st->state=END;
  8078. } else {
  8079. // pc_setreg(sd,add_str((unsigned char *) "l15"),sd->npc_menu);
  8080. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  8081. sd->state.menu_or_input=0;
  8082. push_val(st->stack,C_INT,sd->npc_menu);
  8083. }
  8084. return 0;
  8085. }
  8086. /*==========================================
  8087. * GetMapMobs
  8088. returns mob counts on a set map:
  8089. e.g. GetMapMobs("prontera.gat")
  8090. use "this" - for player's map
  8091. *------------------------------------------
  8092. */
  8093. int buildin_getmapmobs(struct script_state *st)
  8094. {
  8095. char *str=NULL;
  8096. int m=-1,bx,by,i;
  8097. int count=0,c;
  8098. struct block_list *bl;
  8099. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8100. if(strcmp(str,"this")==0){
  8101. struct map_session_data *sd=script_rid2sd(st);
  8102. if(sd)
  8103. m=sd->bl.m;
  8104. else{
  8105. push_val(st->stack,C_INT,-1);
  8106. return 0;
  8107. }
  8108. }else
  8109. m=map_mapname2mapid(str);
  8110. if(m < 0){
  8111. push_val(st->stack,C_INT,-1);
  8112. return 0;
  8113. }
  8114. for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++){
  8115. for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++){
  8116. bl = map[m].block_mob[bx+by*map[m].bxs];
  8117. c = map[m].block_mob_count[bx+by*map[m].bxs];
  8118. for(i=0;i<c && bl;i++,bl=bl->next){
  8119. if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
  8120. count++;
  8121. }
  8122. }
  8123. }
  8124. push_val(st->stack,C_INT,count);
  8125. return 0;
  8126. }
  8127. /*==========================================
  8128. * movenpc [MouseJstr]
  8129. *------------------------------------------
  8130. */
  8131. int buildin_movenpc(struct script_state *st)
  8132. {
  8133. TBL_NPC *nd = NULL;
  8134. char *npc;
  8135. int x,y;
  8136. short m;
  8137. npc = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8138. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  8139. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  8140. if ((nd = npc_name2id(npc)) == NULL)
  8141. return -1;
  8142. if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  8143. return -1; //Not on a map.
  8144. if (x < 0) x = 0;
  8145. else if (x >= map[m].xs) x = map[m].xs-1;
  8146. if (y < 0) y = 0;
  8147. else if (y >= map[m].ys) y = map[m].ys-1;
  8148. map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  8149. map_moveblock(&nd->bl, x, y, gettick());
  8150. map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  8151. return 0;
  8152. }
  8153. /*==========================================
  8154. * message [MouseJstr]
  8155. *------------------------------------------
  8156. */
  8157. int buildin_message(struct script_state *st)
  8158. {
  8159. struct map_session_data *sd;
  8160. char *msg,*player;
  8161. struct map_session_data *pl_sd = NULL;
  8162. sd = script_rid2sd(st);
  8163. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8164. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8165. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  8166. return 0;
  8167. clif_displaymessage(pl_sd->fd, msg);
  8168. return 0;
  8169. }
  8170. /*==========================================
  8171. * npctalk (sends message to surrounding
  8172. * area) [Valaris]
  8173. *------------------------------------------
  8174. */
  8175. int buildin_npctalk(struct script_state *st)
  8176. {
  8177. char *str;
  8178. char message[255];
  8179. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  8180. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8181. if(nd) {
  8182. memcpy(message, nd->name, NAME_LENGTH);
  8183. strcat(message," : ");
  8184. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  8185. clif_message(&(nd->bl), message);
  8186. }
  8187. return 0;
  8188. }
  8189. /*==========================================
  8190. * hasitems (checks to see if player has any
  8191. * items on them, if so will return a 1)
  8192. * [Valaris]
  8193. *------------------------------------------
  8194. */
  8195. int buildin_hasitems(struct script_state *st)
  8196. {
  8197. int i;
  8198. struct map_session_data *sd;
  8199. sd=script_rid2sd(st);
  8200. for(i=0; i<MAX_INVENTORY; i++) {
  8201. if(sd->status.inventory[i].amount && sd->status.inventory[i].nameid!=2364 && sd->status.inventory[i].nameid!=2365) {
  8202. push_val(st->stack,C_INT,1);
  8203. return 0;
  8204. }
  8205. }
  8206. push_val(st->stack,C_INT,0);
  8207. return 0;
  8208. }
  8209. // change npc walkspeed [Valaris]
  8210. int buildin_npcspeed(struct script_state *st)
  8211. {
  8212. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  8213. int x=0;
  8214. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8215. if(nd) {
  8216. nd->speed=x;
  8217. }
  8218. return 0;
  8219. }
  8220. // make an npc walk to a position [Valaris]
  8221. int buildin_npcwalkto(struct script_state *st)
  8222. {
  8223. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  8224. int x=0,y=0;
  8225. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8226. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8227. if(nd) {
  8228. unit_walktoxy(&nd->bl,x,y,0);
  8229. }
  8230. return 0;
  8231. }
  8232. // stop an npc's movement [Valaris]
  8233. int buildin_npcstop(struct script_state *st)
  8234. {
  8235. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  8236. if(nd) {
  8237. unit_stop_walking(&nd->bl,1);
  8238. }
  8239. return 0;
  8240. }
  8241. /*==========================================
  8242. * getlook char info. getlook(arg)
  8243. *------------------------------------------
  8244. */
  8245. int buildin_getlook(struct script_state *st){
  8246. int type,val;
  8247. struct map_session_data *sd;
  8248. sd=script_rid2sd(st);
  8249. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8250. val=-1;
  8251. switch(type){
  8252. case LOOK_HAIR: //1
  8253. val=sd->status.hair;
  8254. break;
  8255. case LOOK_WEAPON: //2
  8256. val=sd->status.weapon;
  8257. break;
  8258. case LOOK_HEAD_BOTTOM: //3
  8259. val=sd->status.head_bottom;
  8260. break;
  8261. case LOOK_HEAD_TOP: //4
  8262. val=sd->status.head_top;
  8263. break;
  8264. case LOOK_HEAD_MID: //5
  8265. val=sd->status.head_mid;
  8266. break;
  8267. case LOOK_HAIR_COLOR: //6
  8268. val=sd->status.hair_color;
  8269. break;
  8270. case LOOK_CLOTHES_COLOR: //7
  8271. val=sd->status.clothes_color;
  8272. break;
  8273. case LOOK_SHIELD: //8
  8274. val=sd->status.shield;
  8275. break;
  8276. case LOOK_SHOES: //9
  8277. break;
  8278. }
  8279. push_val(st->stack,C_INT,val);
  8280. return 0;
  8281. }
  8282. /*==========================================
  8283. * get char save point. argument: 0- map name, 1- x, 2- y
  8284. *------------------------------------------
  8285. */
  8286. int buildin_getsavepoint(struct script_state *st)
  8287. {
  8288. int x,y,type;
  8289. char *mapname;
  8290. struct map_session_data *sd;
  8291. sd=script_rid2sd(st);
  8292. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8293. x=sd->status.save_point.x;
  8294. y=sd->status.save_point.y;
  8295. switch(type){
  8296. case 0:
  8297. mapname=(char *) aMallocA((MAP_NAME_LENGTH+1)*sizeof(char));
  8298. memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
  8299. mapname[MAP_NAME_LENGTH]='\0';
  8300. push_str(st->stack,C_STR,(unsigned char *) mapname);
  8301. break;
  8302. case 1:
  8303. push_val(st->stack,C_INT,x);
  8304. break;
  8305. case 2:
  8306. push_val(st->stack,C_INT,y);
  8307. break;
  8308. }
  8309. return 0;
  8310. }
  8311. /*==========================================
  8312. * Get position for char/npc/pet/mob objects. Added by Lorky
  8313. *
  8314. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  8315. * where type:
  8316. * MapName$ - String variable for output map name
  8317. * MapX - Integer variable for output coord X
  8318. * MapY - Integer variable for output coord Y
  8319. * type - type of object
  8320. * 0 - Character coord
  8321. * 1 - NPC coord
  8322. * 2 - Pet coord
  8323. * 3 - Mob coord (not released)
  8324. * CharName$ - Name object. If miss or "this" the current object
  8325. *
  8326. * Return:
  8327. * 0 - success
  8328. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  8329. *------------------------------------------
  8330. */
  8331. int buildin_getmapxy(struct script_state *st){
  8332. struct map_session_data *sd=NULL;
  8333. struct npc_data *nd;
  8334. struct pet_data *pd;
  8335. int num;
  8336. char *name;
  8337. char prefix;
  8338. int x,y,type;
  8339. char mapname[MAP_NAME_LENGTH+1];
  8340. memset(mapname, 0, sizeof(mapname));
  8341. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  8342. ShowWarning("script: buildin_getmapxy: not mapname variable\n");
  8343. push_val(st->stack,C_INT,-1);
  8344. return 0;
  8345. }
  8346. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  8347. ShowWarning("script: buildin_getmapxy: not mapx variable\n");
  8348. push_val(st->stack,C_INT,-1);
  8349. return 0;
  8350. }
  8351. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  8352. ShowWarning("script: buildin_getmapxy: not mapy variable\n");
  8353. push_val(st->stack,C_INT,-1);
  8354. return 0;
  8355. }
  8356. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  8357. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8358. switch (type){
  8359. case 0: //Get Character Position
  8360. if( st->end>st->start+6 )
  8361. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  8362. else
  8363. sd=script_rid2sd(st);
  8364. if ( sd==NULL ) { //wrong char name or char offline
  8365. push_val(st->stack,C_INT,-1);
  8366. return 0;
  8367. }
  8368. x=sd->bl.x;
  8369. y=sd->bl.y;
  8370. memcpy(mapname,mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  8371. break;
  8372. case 1: //Get NPC Position
  8373. if( st->end > st->start+6 )
  8374. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  8375. else
  8376. nd=(struct npc_data *)map_id2bl(st->oid);
  8377. if ( nd==NULL ) { //wrong npc name or char offline
  8378. push_val(st->stack,C_INT,-1);
  8379. return 0;
  8380. }
  8381. x=nd->bl.x;
  8382. y=nd->bl.y;
  8383. memcpy(mapname, map[nd->bl.m].name, MAP_NAME_LENGTH);
  8384. break;
  8385. case 2: //Get Pet Position
  8386. if( st->end>st->start+6 )
  8387. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  8388. else
  8389. sd=script_rid2sd(st);
  8390. if ( sd==NULL ) { //wrong char name or char offline
  8391. push_val(st->stack,C_INT,-1);
  8392. return 0;
  8393. }
  8394. pd=sd->pd;
  8395. if(pd==NULL){ //pet data not found
  8396. push_val(st->stack,C_INT,-1);
  8397. return 0;
  8398. }
  8399. x=pd->bl.x;
  8400. y=pd->bl.y;
  8401. memcpy(mapname, map[pd->bl.m].name, MAP_NAME_LENGTH);
  8402. break;
  8403. case 3: //Get Mob Position
  8404. push_val(st->stack,C_INT,-1);
  8405. return 0;
  8406. default: //Wrong type parameter
  8407. push_val(st->stack,C_INT,-1);
  8408. return 0;
  8409. }
  8410. //Set MapName$
  8411. num=st->stack->stack_data[st->start+2].u.num;
  8412. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  8413. prefix=*name;
  8414. if(not_server_variable(prefix))
  8415. sd=script_rid2sd(st);
  8416. else
  8417. sd=NULL;
  8418. set_reg(st,sd,num,name,(void*)mapname,st->stack->stack_data[st->start+2].ref);
  8419. //Set MapX
  8420. num=st->stack->stack_data[st->start+3].u.num;
  8421. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  8422. prefix=*name;
  8423. if(not_server_variable(prefix))
  8424. sd=script_rid2sd(st);
  8425. else
  8426. sd=NULL;
  8427. set_reg(st,sd,num,name,(void*)x,st->stack->stack_data[st->start+3].ref);
  8428. //Set MapY
  8429. num=st->stack->stack_data[st->start+4].u.num;
  8430. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  8431. prefix=*name;
  8432. if(not_server_variable(prefix))
  8433. sd=script_rid2sd(st);
  8434. else
  8435. sd=NULL;
  8436. set_reg(st,sd,num,name,(void*)y,st->stack->stack_data[st->start+4].ref);
  8437. //Return Success value
  8438. push_val(st->stack,C_INT,0);
  8439. return 0;
  8440. }
  8441. /*==========================================
  8442. * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
  8443. *------------------------------------------
  8444. */
  8445. int buildin_logmes(struct script_state *st)
  8446. {
  8447. if (log_config.npc <= 0 ) return 0;
  8448. conv_str(st,& (st->stack->stack_data[st->start+2]));
  8449. log_npc(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str);
  8450. return 0;
  8451. }
  8452. int buildin_summon(struct script_state *st)
  8453. {
  8454. int _class, id, timeout=0;
  8455. char *str,*event="";
  8456. struct map_session_data *sd;
  8457. struct mob_data *md;
  8458. int tick = gettick();
  8459. sd=script_rid2sd(st);
  8460. if (!sd) return 0;
  8461. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  8462. _class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8463. if( st->end>st->start+4 )
  8464. timeout=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8465. if( st->end>st->start+5 ){
  8466. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  8467. check_event(st, event);
  8468. }
  8469. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
  8470. id=mob_once_spawn(sd, "this", 0, 0, str,_class,1,event);
  8471. md=(struct mob_data *)map_id2bl(id);
  8472. if (!md) return 0;
  8473. md->master_id=sd->bl.id;
  8474. md->special_state.ai=1;
  8475. md->deletetimer=add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,id,0);
  8476. clif_misceffect2(&md->bl,344);
  8477. sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  8478. return 0;
  8479. }
  8480. /*==========================================
  8481. * Checks whether it is daytime/nighttime
  8482. *------------------------------------------
  8483. */
  8484. int buildin_isnight(struct script_state *st)
  8485. {
  8486. push_val(st->stack,C_INT, (night_flag == 1));
  8487. return 0;
  8488. }
  8489. int buildin_isday(struct script_state *st)
  8490. {
  8491. push_val(st->stack,C_INT, (night_flag == 0));
  8492. return 0;
  8493. }
  8494. /*================================================
  8495. * Check whether another item/card has been
  8496. * equipped - used for 2/15's cards patch [celest]
  8497. *------------------------------------------------
  8498. */
  8499. // leave this here, just in case
  8500. #if 0
  8501. int buildin_isequipped(struct script_state *st)
  8502. {
  8503. struct map_session_data *sd;
  8504. int i, j, k, id = 1;
  8505. int ret = -1;
  8506. sd = script_rid2sd(st);
  8507. for (i=0; id!=0; i++) {
  8508. int flag = 0;
  8509. FETCH (i+2, id) else id = 0;
  8510. if (id <= 0)
  8511. continue;
  8512. for (j=0; j<EQI_MAX; j++) {
  8513. int index;
  8514. index = sd->equip_index[j];
  8515. if(index < 0) continue;
  8516. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  8517. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  8518. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  8519. if(!sd->inventory_data[index])
  8520. continue;
  8521. if(itemdb_type(id) != IT_CARD) { //Non card
  8522. if (sd->inventory_data[index]->nameid != id)
  8523. continue;
  8524. flag = 1;
  8525. break;
  8526. } else { //Card
  8527. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  8528. continue;
  8529. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  8530. if (sd->status.inventory[index].card[k] == id)
  8531. {
  8532. flag = 1;
  8533. break;
  8534. }
  8535. }
  8536. }
  8537. if (flag) break;
  8538. }
  8539. if (ret == -1)
  8540. ret = flag;
  8541. else
  8542. ret &= flag;
  8543. if (!ret) break;
  8544. }
  8545. push_val(st->stack,C_INT,ret);
  8546. return 0;
  8547. }
  8548. #endif
  8549. /*================================================
  8550. * Check how many items/cards in the list are
  8551. * equipped - used for 2/15's cards patch [celest]
  8552. *------------------------------------------------
  8553. */
  8554. int buildin_isequippedcnt(struct script_state *st)
  8555. {
  8556. struct map_session_data *sd;
  8557. int i, j, k, id = 1;
  8558. int ret = 0;
  8559. sd = script_rid2sd(st);
  8560. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  8561. push_val(st->stack,C_INT,0);
  8562. return 0;
  8563. }
  8564. for (i=0; id!=0; i++) {
  8565. FETCH (i+2, id) else id = 0;
  8566. if (id <= 0)
  8567. continue;
  8568. for (j=0; j<EQI_MAX; j++) {
  8569. int index;
  8570. index = sd->equip_index[j];
  8571. if(index < 0) continue;
  8572. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  8573. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  8574. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  8575. if(!sd->inventory_data[index])
  8576. continue;
  8577. if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
  8578. if (sd->inventory_data[index]->nameid == id)
  8579. ret+= sd->status.inventory[index].amount;
  8580. } else { //Count cards.
  8581. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  8582. continue; //No cards
  8583. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  8584. if (sd->status.inventory[index].card[k] == id)
  8585. ret++; //[Lupus]
  8586. }
  8587. }
  8588. }
  8589. }
  8590. push_val(st->stack,C_INT,ret);
  8591. return 0;
  8592. }
  8593. /*================================================
  8594. * Check whether another card has been
  8595. * equipped - used for 2/15's cards patch [celest]
  8596. * -- Items checked cannot be reused in another
  8597. * card set to prevent exploits
  8598. *------------------------------------------------
  8599. */
  8600. int buildin_isequipped(struct script_state *st)
  8601. {
  8602. struct map_session_data *sd;
  8603. int i, j, k, id = 1;
  8604. int index, flag;
  8605. int ret = -1;
  8606. sd = script_rid2sd(st);
  8607. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  8608. push_val(st->stack,C_INT,0);
  8609. return 0;
  8610. }
  8611. for (i=0; id!=0; i++)
  8612. {
  8613. FETCH (i+2, id) else id = 0;
  8614. if (id <= 0)
  8615. continue;
  8616. flag = 0;
  8617. for (j=0; j<EQI_MAX; j++)
  8618. {
  8619. index = sd->equip_index[j];
  8620. if(index < 0) continue;
  8621. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  8622. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  8623. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  8624. if(!sd->inventory_data[index])
  8625. continue;
  8626. if (itemdb_type(id) != IT_CARD) {
  8627. if (sd->inventory_data[index]->nameid != id)
  8628. continue;
  8629. flag = 1;
  8630. break;
  8631. } else { //Cards
  8632. if (sd->inventory_data[index]->slot == 0 ||
  8633. itemdb_isspecial(sd->status.inventory[index].card[0]))
  8634. continue;
  8635. for (k = 0; k < sd->inventory_data[index]->slot; k++)
  8636. { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
  8637. unsigned int hash = 0;
  8638. if (sd->status.inventory[index].card[k] != id)
  8639. continue;
  8640. hash = 1<<((j<5?j:j-5)*4 + k);
  8641. // check if card is already used by another set
  8642. if ((j<5?sd->setitem_hash:sd->setitem_hash2) & hash)
  8643. continue;
  8644. // We have found a match
  8645. flag = 1;
  8646. // Set hash so this card cannot be used by another
  8647. if (j<5)
  8648. sd->setitem_hash |= hash;
  8649. else
  8650. sd->setitem_hash2 |= hash;
  8651. break;
  8652. }
  8653. }
  8654. if (flag) break; //Card found
  8655. }
  8656. if (ret == -1)
  8657. ret = flag;
  8658. else
  8659. ret &= flag;
  8660. if (!ret) break;
  8661. }
  8662. push_val(st->stack,C_INT,ret);
  8663. return 0;
  8664. }
  8665. /*================================================
  8666. * Check how many given inserted cards in the CURRENT
  8667. * weapon - used for 2/15's cards patch [Lupus]
  8668. *------------------------------------------------
  8669. */
  8670. int buildin_cardscnt(struct script_state *st)
  8671. {
  8672. struct map_session_data *sd;
  8673. int i, k, id = 1;
  8674. int ret = 0;
  8675. int index;
  8676. sd = script_rid2sd(st);
  8677. for (i=0; id!=0; i++) {
  8678. FETCH (i+2, id) else id = 0;
  8679. if (id <= 0)
  8680. continue;
  8681. index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
  8682. if(index < 0) continue;
  8683. if(!sd->inventory_data[index])
  8684. continue;
  8685. if(itemdb_type(id) != IT_CARD) {
  8686. if (sd->inventory_data[index]->nameid == id)
  8687. ret+= sd->status.inventory[index].amount;
  8688. } else {
  8689. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  8690. continue;
  8691. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  8692. if (sd->status.inventory[index].card[k] == id)
  8693. ret++;
  8694. }
  8695. }
  8696. }
  8697. push_val(st->stack,C_INT,ret);
  8698. // push_val(st->stack,C_INT,current_equip_item_index);
  8699. return 0;
  8700. }
  8701. /*=======================================================
  8702. * Returns the refined number of the current item, or an
  8703. * item with inventory index specified
  8704. *-------------------------------------------------------
  8705. */
  8706. int buildin_getrefine(struct script_state *st)
  8707. {
  8708. struct map_session_data *sd;
  8709. if ((sd = script_rid2sd(st))!= NULL)
  8710. push_val(st->stack, C_INT, sd->status.inventory[current_equip_item_index].refine);
  8711. return 0;
  8712. }
  8713. /*=======================================================
  8714. * Allows 2 Parents to adopt a character as a Baby
  8715. *-------------------------------------------------------
  8716. */
  8717. int buildin_adopt(struct script_state *st)
  8718. {
  8719. int ret;
  8720. char *parent1 = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8721. char *parent2 = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8722. char *child = conv_str(st,& (st->stack->stack_data[st->start+4]));
  8723. struct map_session_data *p1_sd = map_nick2sd(parent1);
  8724. struct map_session_data *p2_sd = map_nick2sd(parent2);
  8725. struct map_session_data *c_sd = map_nick2sd(child);
  8726. if (!p1_sd || !p2_sd || !c_sd ||
  8727. p1_sd->status.base_level < 70 ||
  8728. p2_sd->status.base_level < 70)
  8729. return 0;
  8730. ret = pc_adoption(p1_sd, p2_sd, c_sd);
  8731. push_val(st->stack, C_INT, ret);
  8732. return 0;
  8733. }
  8734. /*=======================================================
  8735. * Day/Night controls
  8736. *-------------------------------------------------------
  8737. */
  8738. int buildin_night(struct script_state *st)
  8739. {
  8740. if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
  8741. return 0;
  8742. }
  8743. int buildin_day(struct script_state *st)
  8744. {
  8745. if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
  8746. return 0;
  8747. }
  8748. //=======================================================
  8749. // Unequip [Spectre]
  8750. //-------------------------------------------------------
  8751. int buildin_unequip(struct script_state *st)
  8752. {
  8753. int i;
  8754. size_t num;
  8755. struct map_session_data *sd;
  8756. num = conv_num(st,& (st->stack->stack_data[st->start+2])) - 1;
  8757. sd=script_rid2sd(st);
  8758. if(sd!=NULL && num<10)
  8759. {
  8760. i=pc_checkequip(sd,equip[num]);
  8761. pc_unequipitem(sd,i,2);
  8762. return 0;
  8763. }
  8764. return 0;
  8765. }
  8766. int buildin_equip(struct script_state *st)
  8767. {
  8768. int nameid=0,i;
  8769. struct map_session_data *sd;
  8770. struct item_data *item_data;
  8771. sd = script_rid2sd(st);
  8772. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8773. if((item_data = itemdb_exists(nameid)) == NULL)
  8774. {
  8775. if(battle_config.error_log)
  8776. ShowError("wrong item ID : equipitem(%i)\n",nameid);
  8777. return 1;
  8778. }
  8779. for(i=0;i<MAX_INVENTORY && sd->status.inventory[i].nameid!=nameid;i++);
  8780. if(i==MAX_INVENTORY) return 0;
  8781. pc_equipitem(sd,i,item_data->equip);
  8782. return 0;
  8783. }
  8784. int buildin_autoequip(struct script_state *st){
  8785. int nameid, flag;
  8786. struct item_data *item_data;
  8787. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8788. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8789. if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
  8790. item_data->flag.autoequip = flag>0?1:0;
  8791. }
  8792. return 0;
  8793. }
  8794. int buildin_setbattleflag(struct script_state *st){
  8795. char *flag, *value;
  8796. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8797. value = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8798. if (battle_set_value(flag, value) == 0)
  8799. ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'",flag);
  8800. else
  8801. ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.",flag,value);
  8802. return 0;
  8803. }
  8804. int buildin_getbattleflag(struct script_state *st){
  8805. char *flag;
  8806. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8807. push_val(st->stack,C_INT,battle_get_value(flag));
  8808. return 0;
  8809. }
  8810. //=======================================================
  8811. // strlen [Valaris]
  8812. //-------------------------------------------------------
  8813. int buildin_getstrlen(struct script_state *st) {
  8814. char *str = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8815. int len = (str) ? (int)strlen(str) : 0;
  8816. push_val(st->stack,C_INT,len);
  8817. return 0;
  8818. }
  8819. //=======================================================
  8820. // isalpha [Valaris]
  8821. //-------------------------------------------------------
  8822. int buildin_charisalpha(struct script_state *st) {
  8823. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8824. int pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8825. int val = ( str && pos>0 && (unsigned int)pos<strlen(str) ) ? isalpha( str[pos] ) : 0;
  8826. push_val(st->stack,C_INT,val);
  8827. return 0;
  8828. }
  8829. // [Lance]
  8830. int buildin_fakenpcname(struct script_state *st)
  8831. {
  8832. char *name;
  8833. char *newname;
  8834. int look;
  8835. name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8836. newname = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8837. look = conv_num(st,& (st->stack->stack_data[st->start+4]));
  8838. if(look > 32767 || look < -32768) {
  8839. ShowError("buildin_fakenpcname: Invalid look value %d\n",look);
  8840. return 1; // Safety measure to prevent runtime errors
  8841. }
  8842. npc_changename(name,newname,(short)look);
  8843. return 0;
  8844. }
  8845. int buildin_atoi(struct script_state *st) {
  8846. char *value;
  8847. value = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8848. push_val(st->stack, C_INT, atoi(value));
  8849. return 0;
  8850. }
  8851. //-----------------------------------------------------------------------//
  8852. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA START //
  8853. //-----------------------------------------------------------------------//
  8854. int buildin_compare(struct script_state *st) {
  8855. char *message;
  8856. char *cmpstring;
  8857. int j;
  8858. message = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8859. cmpstring = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8860. for (j = 0; message[j]; j++)
  8861. message[j] = tolower(message[j]);
  8862. for (j = 0; cmpstring[j]; j++)
  8863. cmpstring[j] = tolower(cmpstring[j]);
  8864. push_val(st->stack,C_INT,(strstr(message,cmpstring) != NULL));
  8865. return 0;
  8866. }
  8867. //-----------------------------------------------------------------------//
  8868. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA END //
  8869. //-----------------------------------------------------------------------//
  8870. // [zBuffer] List of mathematics commands --->
  8871. int buildin_sqrt(struct script_state *st){
  8872. double i, a;
  8873. i = conv_num(st, &(st->stack->stack_data[st->start+2]));
  8874. a = sqrt(i);
  8875. push_val(st->stack, C_INT, (int)a);
  8876. return 0;
  8877. }
  8878. int buildin_pow(struct script_state *st){
  8879. double i, a, b;
  8880. a = conv_num(st, &(st->stack->stack_data[st->start+2]));
  8881. b = conv_num(st, &(st->stack->stack_data[st->start+3]));
  8882. i = pow(a,b);
  8883. push_val(st->stack, C_INT, (int)i);
  8884. return 0;
  8885. }
  8886. int buildin_distance(struct script_state *st){
  8887. int x0, y0, x1, y1;
  8888. x0 = conv_num(st, &(st->stack->stack_data[st->start+2]));
  8889. y0 = conv_num(st, &(st->stack->stack_data[st->start+3]));
  8890. x1 = conv_num(st, &(st->stack->stack_data[st->start+4]));
  8891. y1 = conv_num(st, &(st->stack->stack_data[st->start+5]));
  8892. push_val(st->stack, C_INT, distance(x0-x1, y0-y1));
  8893. return 0;
  8894. }
  8895. int buildin_checkcell(struct script_state *st){
  8896. int m;
  8897. char *map = conv_str(st, &(st->stack->stack_data[st->start+2]));
  8898. m = mapindex_name2id(map);
  8899. if(m){
  8900. 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]))));
  8901. } else {
  8902. push_val(st->stack, C_INT, 0);
  8903. }
  8904. return 0;
  8905. }
  8906. // <--- [zBuffer] List of mathematics commands
  8907. // [zBuffer] List of dynamic var commands --->
  8908. void setd_sub(struct script_state *st, struct map_session_data *sd, char *varname, int elem, void *value, struct linkdb_node **ref)
  8909. {
  8910. set_reg(st, sd, add_str((unsigned char *) varname)+(elem<<24), varname, value, ref);
  8911. return;
  8912. }
  8913. int buildin_setd(struct script_state *st)
  8914. {
  8915. struct map_session_data *sd=NULL;
  8916. char varname[100], *buffer;
  8917. char *value;
  8918. int elem;
  8919. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  8920. value = conv_str(st, & (st->stack->stack_data[st->start+3]));
  8921. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  8922. elem = 0;
  8923. if(st->rid)
  8924. sd = script_rid2sd(st);
  8925. if(varname[strlen(varname)-1] != '$') {
  8926. setd_sub(st,sd, varname, elem, (void *)atoi(value),NULL);
  8927. } else {
  8928. setd_sub(st,sd, varname, elem, (void *)value,NULL);
  8929. }
  8930. return 0;
  8931. }
  8932. #ifndef TXT_ONLY
  8933. int buildin_query_sql(struct script_state *st) {
  8934. char *name, *query;
  8935. int num, i = 0;
  8936. struct map_session_data *sd = (st->rid)? script_rid2sd(st) : NULL;
  8937. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8938. strcpy(tmp_sql, query);
  8939. if(mysql_query(&mmysql_handle,tmp_sql)){
  8940. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  8941. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  8942. return 1;
  8943. }
  8944. if(st->end > st->start+3) {
  8945. if(st->stack->stack_data[st->start+3].type != C_NAME){
  8946. ShowWarning("buildin_query_sql: 2nd parameter is not a variable!\n");
  8947. } else {
  8948. num=st->stack->stack_data[st->start+3].u.num;
  8949. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  8950. if((sql_res = mysql_store_result(&mmysql_handle))){
  8951. if(name[strlen(name)-1] != '$') {
  8952. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  8953. setd_sub(st,sd, name, i, (void *)atoi(sql_row[0]),st->stack->stack_data[st->start+3].ref);
  8954. i++;
  8955. }
  8956. } else {
  8957. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  8958. setd_sub(st,sd, name, i, (void *)sql_row[0],st->stack->stack_data[st->start+3].ref);
  8959. i++;
  8960. }
  8961. }
  8962. mysql_free_result(sql_res);
  8963. }
  8964. }
  8965. }
  8966. return 0;
  8967. }
  8968. //Allows escaping of a given string.
  8969. int buildin_escape_sql(struct script_state *st) {
  8970. char *t_query, *query;
  8971. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8972. t_query = aMallocA((strlen(query)*2+1)*sizeof(char));
  8973. jstrescapecpy(t_query,query);
  8974. push_str(st->stack,C_STR,(unsigned char *)t_query);
  8975. return 0;
  8976. }
  8977. #endif
  8978. int buildin_getd (struct script_state *st)
  8979. {
  8980. char varname[100], *buffer;
  8981. //struct script_data dat;
  8982. int elem;
  8983. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  8984. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  8985. elem = 0;
  8986. /*dat.type=C_NAME;
  8987. dat.u.num=add_str((unsigned char *) varname)+(elem<<24);
  8988. get_val(st,&dat);
  8989. if(dat.type == C_INT)
  8990. push_val(st->stack, C_INT, dat.u.num);
  8991. else if(dat.type == C_CONSTSTR){
  8992. buffer = aStrdup((char *)dat.u.str);
  8993. // dat.u.str holds the actual pointer to the data, must be duplicated.
  8994. // It will be freed later. Tested.
  8995. push_str(st->stack, C_STR, buffer);
  8996. }*/
  8997. // Push the 'pointer' so it's more flexible [Lance]
  8998. push_val(st->stack,C_NAME,
  8999. (elem<<24) | add_str((unsigned char *) varname));
  9000. return 0;
  9001. }
  9002. // <--- [zBuffer] List of dynamic var commands
  9003. // Pet stat [Lance]
  9004. int buildin_petstat(struct script_state *st){
  9005. struct map_session_data *sd = NULL;
  9006. char *tmp;
  9007. int flag = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9008. sd = script_rid2sd(st);
  9009. if(!sd || !sd->pet.pet_id){
  9010. if(flag == 2)
  9011. push_str(st->stack, C_CONSTSTR, "");
  9012. else
  9013. push_val(st->stack, C_INT, 0);
  9014. }
  9015. else {
  9016. switch(flag){
  9017. case 1:
  9018. push_val(st->stack, C_INT, (int)sd->pet.class_);
  9019. break;
  9020. case 2:
  9021. tmp = aStrdup(sd->pet.name);
  9022. push_str(st->stack, C_STR, tmp);
  9023. break;
  9024. case 3:
  9025. push_val(st->stack, C_INT, (int)sd->pet.level);
  9026. break;
  9027. case 4:
  9028. push_val(st->stack, C_INT, (int)sd->pet.hungry);
  9029. break;
  9030. case 5:
  9031. push_val(st->stack, C_INT, (int)sd->pet.intimate);
  9032. break;
  9033. default:
  9034. push_val(st->stack, C_INT, 0);
  9035. break;
  9036. }
  9037. }
  9038. return 0;
  9039. }
  9040. int buildin_callshop(struct script_state *st)
  9041. {
  9042. struct map_session_data *sd = NULL;
  9043. struct npc_data *nd;
  9044. char *shopname;
  9045. int flag = 0;
  9046. sd = script_rid2sd(st);
  9047. if (!sd) {
  9048. push_val(st->stack,C_INT,0);
  9049. return 0;
  9050. }
  9051. shopname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  9052. if( st->end>st->start+3 )
  9053. flag = conv_num(st, & (st->stack->stack_data[st->start+3]));
  9054. nd = npc_name2id(shopname);
  9055. if (!nd || nd->bl.type!=BL_NPC || nd->bl.subtype!=SHOP) {
  9056. ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)", shopname);
  9057. push_val(st->stack,C_INT,0);
  9058. return 1;
  9059. }
  9060. switch (flag) {
  9061. case 1: //Buy window
  9062. npc_buysellsel(sd,nd->bl.id,0);
  9063. break;
  9064. case 2: //Sell window
  9065. npc_buysellsel(sd,nd->bl.id,1);
  9066. break;
  9067. default: //Show menu
  9068. clif_npcbuysell(sd,nd->bl.id);
  9069. break;
  9070. }
  9071. sd->npc_shopid = nd->bl.id;
  9072. push_val(st->stack,C_INT,1);
  9073. return 0;
  9074. }
  9075. #ifndef MAX_SHOPITEM
  9076. #define MAX_SHOPITEM 100
  9077. #endif
  9078. int buildin_npcshopitem(struct script_state *st)
  9079. {
  9080. struct npc_data *nd= NULL;
  9081. int n = 0;
  9082. int i = 3;
  9083. int amount;
  9084. char* npcname = conv_str(st, & (st->stack->stack_data[st->start + 2]));
  9085. nd = npc_name2id(npcname);
  9086. if(nd && nd->bl.subtype==SHOP){
  9087. amount = ((st->end-2)/2)+1;
  9088. // st->end - 2 = nameid + value # ... / 2 = number of items ... + 1 to end it
  9089. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  9090. sizeof(nd->u.shop_item[0]) * amount);
  9091. // Reset sell list.
  9092. memset(nd->u.shop_item, 0, sizeof(nd->u.shop_item[0]) * amount);
  9093. n = 0;
  9094. while (st->end > st->start + i) {
  9095. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  9096. i++;
  9097. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  9098. i++;
  9099. n++;
  9100. }
  9101. map_addiddb(&nd->bl);
  9102. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  9103. } else {
  9104. ShowError("buildin_npcshopitem: shop not found.\n");
  9105. }
  9106. return 0;
  9107. }
  9108. int buildin_npcshopadditem(struct script_state *st) {
  9109. struct npc_data *nd=NULL;
  9110. int n = 0;
  9111. int i = 3;
  9112. int amount;
  9113. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  9114. nd = npc_name2id(npcname);
  9115. if (nd && nd->bl.subtype==SHOP){
  9116. amount = ((st->end-2)/2)+1;
  9117. while (nd->u.shop_item[n].nameid && n < MAX_SHOPITEM)
  9118. n++;
  9119. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  9120. sizeof(nd->u.shop_item[0]) * (amount+n));
  9121. while(st->end > st->start + i){
  9122. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  9123. i++;
  9124. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  9125. i++;
  9126. n++;
  9127. }
  9128. // Marks the last of our stuff..
  9129. nd->u.shop_item[n].value = 0;
  9130. nd->u.shop_item[n].nameid = 0;
  9131. map_addiddb(&nd->bl);
  9132. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  9133. } else {
  9134. ShowError("buildin_npcshopadditem: shop not found.\n");
  9135. }
  9136. return 0;
  9137. }
  9138. int buildin_npcshopdelitem(struct script_state *st)
  9139. {
  9140. struct npc_data *nd=NULL;
  9141. int n=0;
  9142. int i=3;
  9143. int size = 0;
  9144. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  9145. nd = npc_name2id(npcname);
  9146. if (nd && nd->bl.subtype==SHOP) {
  9147. while (nd->u.shop_item[size].nameid)
  9148. size++;
  9149. while (st->end > st->start+i) {
  9150. for(n=0;nd->u.shop_item[n].nameid && n < MAX_SHOPITEM;n++) {
  9151. if (nd->u.shop_item[n].nameid == conv_num(st, & (st->stack->stack_data[st->start+i]))) {
  9152. // We're moving 1 extra empty block. Junk data is eliminated later.
  9153. memmove(&nd->u.shop_item[n], &nd->u.shop_item[n+1], sizeof(nd->u.shop_item[0])*(size-n));
  9154. }
  9155. }
  9156. i++;
  9157. }
  9158. size = 0;
  9159. while (nd->u.shop_item[size].nameid)
  9160. size++;
  9161. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  9162. sizeof(nd->u.shop_item[0]) * (size+1));
  9163. map_addiddb(&nd->bl);
  9164. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  9165. } else {
  9166. ShowError("buildin_npcshopdelitem: shop not found.\n");
  9167. }
  9168. return 0;
  9169. }
  9170. /*==========================================
  9171. * Returns some values of an item [Lupus]
  9172. * Price, Weight, etc...
  9173. setiteminfo(itemID,"{new item bonus script}");
  9174. *------------------------------------------
  9175. */
  9176. int buildin_setitemscript(struct script_state *st)
  9177. {
  9178. int item_id;
  9179. char *script;
  9180. struct item_data *i_data;
  9181. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  9182. script = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9183. i_data = itemdb_exists(item_id);
  9184. if (i_data && script!=NULL && script[0]=='{') {
  9185. if(i_data->script!=NULL)
  9186. script_free_code(i_data->script);
  9187. i_data->script = parse_script((unsigned char *) script, 0);
  9188. push_val(st->stack,C_INT,1);
  9189. } else
  9190. push_val(st->stack,C_INT,0);
  9191. return 0;
  9192. }
  9193. /* Work In Progress [Lupus]
  9194. int buildin_addmonsterdrop(struct script_state *st)
  9195. {
  9196. int class_,item_id,chance;
  9197. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9198. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9199. chance=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9200. if(class_>1000 && item_id>500 && chance>0) {
  9201. push_val(st->stack,C_INT,1);
  9202. } else {
  9203. push_val(st->stack,C_INT,0);
  9204. }
  9205. }
  9206. int buildin_delmonsterdrop(struct script_state *st)
  9207. {
  9208. int class_,item_id;
  9209. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9210. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9211. if(class_>1000 && item_id>500) {
  9212. push_val(st->stack,C_INT,1);
  9213. } else {
  9214. push_val(st->stack,C_INT,0);
  9215. }
  9216. }
  9217. */
  9218. /*==========================================
  9219. * Returns some values of a monster [Lupus]
  9220. * Name, Level, race, size, etc...
  9221. getmonsterinfo(monsterID,queryIndex);
  9222. *------------------------------------------
  9223. */
  9224. int buildin_getmonsterinfo(struct script_state *st)
  9225. {
  9226. struct mob_db *mob;
  9227. int mob_id;
  9228. mob_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  9229. if (!mobdb_checkid(mob_id)) {
  9230. ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i", mob_id);
  9231. push_val(st->stack, C_INT, -1);
  9232. return -1;
  9233. }
  9234. mob = mob_db(mob_id);
  9235. switch ( conv_num(st,& (st->stack->stack_data[st->start+3])) ) {
  9236. case 0: //Name
  9237. push_str(st->stack,C_CONSTSTR, (unsigned char *) mob->jname);
  9238. break;
  9239. case 1: //Lvl
  9240. push_val(st->stack,C_INT, mob->lv);
  9241. break;
  9242. case 2: //MaxHP
  9243. push_val(st->stack,C_INT, mob->status.max_hp);
  9244. break;
  9245. case 3: //Base EXP
  9246. push_val(st->stack,C_INT, mob->base_exp);
  9247. break;
  9248. case 4: //Job EXP
  9249. push_val(st->stack,C_INT, mob->job_exp);
  9250. break;
  9251. case 5: //Atk1
  9252. push_val(st->stack,C_INT, mob->status.rhw.atk);
  9253. break;
  9254. case 6: //Atk2
  9255. push_val(st->stack,C_INT, mob->status.rhw.atk2);
  9256. break;
  9257. case 7: //Def
  9258. push_val(st->stack,C_INT, mob->status.def);
  9259. break;
  9260. case 8: //Mdef
  9261. push_val(st->stack,C_INT, mob->status.mdef);
  9262. break;
  9263. case 9: //Str
  9264. push_val(st->stack,C_INT, mob->status.str);
  9265. break;
  9266. case 10: //Agi
  9267. push_val(st->stack,C_INT, mob->status.agi);
  9268. break;
  9269. case 11: //Vit
  9270. push_val(st->stack,C_INT, mob->status.vit);
  9271. break;
  9272. case 12: //Int
  9273. push_val(st->stack,C_INT, mob->status.int_);
  9274. break;
  9275. case 13: //Dex
  9276. push_val(st->stack,C_INT, mob->status.dex);
  9277. break;
  9278. case 14: //Luk
  9279. push_val(st->stack,C_INT, mob->status.luk);
  9280. break;
  9281. case 15: //Range
  9282. push_val(st->stack,C_INT, mob->status.rhw.range);
  9283. break;
  9284. case 16: //Range2
  9285. push_val(st->stack,C_INT, mob->range2);
  9286. break;
  9287. case 17: //Range3
  9288. push_val(st->stack,C_INT, mob->range3);
  9289. break;
  9290. case 18: //Size
  9291. push_val(st->stack,C_INT, mob->status.size);
  9292. break;
  9293. case 19: //Race
  9294. push_val(st->stack,C_INT, mob->status.race);
  9295. break;
  9296. case 20: //Element
  9297. push_val(st->stack,C_INT, mob->status.def_ele);
  9298. break;
  9299. case 21: //Mode
  9300. push_val(st->stack,C_INT, mob->status.mode);
  9301. break;
  9302. default: //wrong Index
  9303. push_val(st->stack,C_INT,-1);
  9304. }
  9305. return 0;
  9306. }
  9307. // [zBuffer] List of player cont commands --->
  9308. int buildin_rid2name(struct script_state *st){
  9309. struct block_list *bl = NULL;
  9310. int rid = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9311. if((bl = map_id2bl(rid))){
  9312. switch(bl->type){
  9313. case BL_MOB:
  9314. push_str(st->stack,C_CONSTSTR,((struct mob_data *)bl)->name);
  9315. break;
  9316. case BL_PC:
  9317. push_str(st->stack,C_CONSTSTR,((struct map_session_data *)bl)->status.name);
  9318. break;
  9319. case BL_NPC:
  9320. push_str(st->stack,C_CONSTSTR,((struct npc_data *)bl)->exname);
  9321. break;
  9322. case BL_PET:
  9323. push_str(st->stack,C_CONSTSTR,((struct pet_data *)bl)->name);
  9324. break;
  9325. case BL_HOMUNCULUS:
  9326. push_str(st->stack,C_CONSTSTR,((struct homun_data *)bl)->master->homunculus.name);
  9327. break;
  9328. default:
  9329. ShowError("buildin_rid2name: BL type unknown.\n");
  9330. push_str(st->stack,C_CONSTSTR,"");
  9331. break;
  9332. }
  9333. }
  9334. return 0;
  9335. }
  9336. int buildin_pcblockmove(struct script_state *st){
  9337. int id, flag;
  9338. struct map_session_data *sd = NULL;
  9339. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9340. flag = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  9341. if(id)
  9342. sd = map_id2sd(id);
  9343. else
  9344. sd = script_rid2sd(st);
  9345. if(sd)
  9346. sd->state.blockedmove = flag > 0;
  9347. return 0;
  9348. }
  9349. int buildin_pcfollow(struct script_state *st) {
  9350. int id, targetid;
  9351. struct map_session_data *sd = NULL;
  9352. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9353. targetid = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  9354. if(id)
  9355. sd = map_id2sd(id);
  9356. else
  9357. sd = script_rid2sd(st);
  9358. if(sd)
  9359. pc_follow(sd, targetid);
  9360. return 0;
  9361. }
  9362. int buildin_pcstopfollow(struct script_state *st) {
  9363. int id;
  9364. struct map_session_data *sd = NULL;
  9365. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9366. if(id)
  9367. sd = map_id2sd(id);
  9368. else
  9369. sd = script_rid2sd(st);
  9370. if(sd)
  9371. pc_stop_following(sd);
  9372. return 0;
  9373. }
  9374. // <--- [zBuffer] List of player cont commands
  9375. // [zBuffer] List of mob control commands --->
  9376. int buildin_mobspawn(struct script_state *st){
  9377. int class_,x,y,id;
  9378. char *str,*map;
  9379. // Who?
  9380. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  9381. // What?
  9382. class_ =conv_num(st,& (st->stack->stack_data[st->start+3]));
  9383. // Where?
  9384. map =conv_str(st,& (st->stack->stack_data[st->start+4]));
  9385. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  9386. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  9387. id = mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,1,NULL);
  9388. push_val(st->stack,C_INT,id);
  9389. return 0;
  9390. }
  9391. int buildin_mobremove(struct script_state *st) {
  9392. int id;
  9393. struct block_list *bl = NULL;
  9394. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9395. bl = map_id2bl(id);
  9396. if (bl && bl->type == BL_MOB)
  9397. unit_free(bl);
  9398. return 0;
  9399. }
  9400. int buildin_getmobdata(struct script_state *st) {
  9401. int num, id;
  9402. char *name;
  9403. struct mob_data *md = NULL;
  9404. struct map_session_data *sd = st->rid?map_id2sd(st->rid):NULL;
  9405. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9406. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB || st->stack->stack_data[st->start+3].type!=C_NAME ){
  9407. ShowWarning("buildin_getmobdata: Error in argument!\n");
  9408. return -1;
  9409. }
  9410. num=st->stack->stack_data[st->start+3].u.num;
  9411. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9412. setd_sub(st,sd,name,0,(void *)(int)md->class_,st->stack->stack_data[st->start+3].ref);
  9413. setd_sub(st,sd,name,1,(void *)(int)md->level,st->stack->stack_data[st->start+3].ref);
  9414. setd_sub(st,sd,name,2,(void *)(int)md->status.hp,st->stack->stack_data[st->start+3].ref);
  9415. setd_sub(st,sd,name,3,(void *)(int)md->status.max_hp,st->stack->stack_data[st->start+3].ref);
  9416. setd_sub(st,sd,name,4,(void *)(int)md->master_id,st->stack->stack_data[st->start+3].ref);
  9417. setd_sub(st,sd,name,5,(void *)(int)md->bl.m,st->stack->stack_data[st->start+3].ref);
  9418. setd_sub(st,sd,name,6,(void *)(int)md->bl.x,st->stack->stack_data[st->start+3].ref);
  9419. setd_sub(st,sd,name,7,(void *)(int)md->bl.y,st->stack->stack_data[st->start+3].ref);
  9420. setd_sub(st,sd,name,8,(void *)(int)md->status.speed,st->stack->stack_data[st->start+3].ref);
  9421. setd_sub(st,sd,name,9,(void *)(int)md->status.mode,st->stack->stack_data[st->start+3].ref);
  9422. setd_sub(st,sd,name,10,(void *)(int)md->special_state.ai,st->stack->stack_data[st->start+3].ref);
  9423. setd_sub(st,sd,name,11,(void *)(int)md->sc.option,st->stack->stack_data[st->start+3].ref);
  9424. setd_sub(st,sd,name,12,(void *)(int)md->vd->sex,st->stack->stack_data[st->start+3].ref);
  9425. setd_sub(st,sd,name,13,(void *)(int)md->vd->class_,st->stack->stack_data[st->start+3].ref);
  9426. setd_sub(st,sd,name,14,(void *)(int)md->vd->hair_style,st->stack->stack_data[st->start+3].ref);
  9427. setd_sub(st,sd,name,15,(void *)(int)md->vd->hair_color,st->stack->stack_data[st->start+3].ref);
  9428. setd_sub(st,sd,name,16,(void *)(int)md->vd->head_bottom,st->stack->stack_data[st->start+3].ref);
  9429. setd_sub(st,sd,name,17,(void *)(int)md->vd->head_mid,st->stack->stack_data[st->start+3].ref);
  9430. setd_sub(st,sd,name,18,(void *)(int)md->vd->head_top,st->stack->stack_data[st->start+3].ref);
  9431. setd_sub(st,sd,name,19,(void *)(int)md->vd->cloth_color,st->stack->stack_data[st->start+3].ref);
  9432. setd_sub(st,sd,name,20,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  9433. setd_sub(st,sd,name,21,(void *)(int)md->vd->weapon,st->stack->stack_data[st->start+3].ref);
  9434. setd_sub(st,sd,name,22,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  9435. setd_sub(st,sd,name,23,(void *)(int)md->ud.dir,st->stack->stack_data[st->start+3].ref);
  9436. setd_sub(st,sd,name,24,(void *)(int)md->state.killer,st->stack->stack_data[st->start+3].ref);
  9437. setd_sub(st,sd,name,25,(void *)(int)md->callback_flag,st->stack->stack_data[st->start+3].ref);
  9438. setd_sub(st,sd,name,26,(void *)(int)md->state.no_random_walk, st->stack->stack_data[st->start+3].ref);
  9439. return 0;
  9440. }
  9441. int buildin_setmobdata(struct script_state *st){
  9442. int id, value, value2;
  9443. struct mob_data *md = NULL;
  9444. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9445. value = conv_num(st, & (st->stack->stack_data[st->start+3]));
  9446. value2 = conv_num(st, & (st->stack->stack_data[st->start+4]));
  9447. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB){
  9448. ShowWarning("buildin_setmobdata: Error in argument!\n");
  9449. return -1;
  9450. }
  9451. switch(value){
  9452. case 0:
  9453. md->class_ = (short)value2;
  9454. break;
  9455. case 1:
  9456. md->level = (unsigned short)value2;
  9457. break;
  9458. case 2:
  9459. md->status.hp = value2;
  9460. break;
  9461. case 3:
  9462. md->status.max_hp = value2;
  9463. break;
  9464. case 4:
  9465. md->master_id = value2;
  9466. break;
  9467. case 5:
  9468. md->bl.m = (short)value2;
  9469. break;
  9470. case 6:
  9471. md->bl.x = (short)value2;
  9472. break;
  9473. case 7:
  9474. md->bl.y = (short)value2;
  9475. break;
  9476. case 8:
  9477. md->status.speed = (short)value2;
  9478. break;
  9479. case 9:
  9480. md->status.mode = (short)value2;
  9481. break;
  9482. case 10:
  9483. md->special_state.ai = (unsigned int)value2;
  9484. break;
  9485. case 11:
  9486. md->sc.option = (short)value2;
  9487. break;
  9488. case 12:
  9489. md->vd->sex = value2;
  9490. break;
  9491. case 13:
  9492. md->vd->class_ = value2;
  9493. break;
  9494. case 14:
  9495. md->vd->hair_style = (short)value2;
  9496. break;
  9497. case 15:
  9498. md->vd->hair_color = (short)value2;
  9499. break;
  9500. case 16:
  9501. md->vd->head_bottom = (short)value2;
  9502. break;
  9503. case 17:
  9504. md->vd->head_mid = (short)value2;
  9505. break;
  9506. case 18:
  9507. md->vd->head_top = (short)value2;
  9508. break;
  9509. case 19:
  9510. md->vd->cloth_color = (short)value2;
  9511. break;
  9512. case 20:
  9513. md->vd->shield = value2;
  9514. break;
  9515. case 21:
  9516. md->vd->weapon = (short)value2;
  9517. break;
  9518. case 22:
  9519. md->vd->shield = (short)value2;
  9520. break;
  9521. case 23:
  9522. md->ud.dir = (unsigned char)value2;
  9523. break;
  9524. case 24:
  9525. md->state.killer = value2>0?1:0;
  9526. break;
  9527. case 25:
  9528. md->callback_flag = (short)value2;
  9529. break;
  9530. case 26:
  9531. md->state.no_random_walk = value2>0?1:0;
  9532. break;
  9533. default:
  9534. ShowError("buildin_setmobdata: argument id is not identified.");
  9535. return -1;
  9536. }
  9537. return 0;
  9538. }
  9539. int buildin_mobassist(struct script_state *st) {
  9540. int id;
  9541. char *target;
  9542. struct mob_data *md = NULL;
  9543. struct block_list *bl = NULL;
  9544. struct unit_data *ud;
  9545. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9546. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  9547. if((bl =&(map_nick2sd(target)->bl)) || (bl = map_id2bl(atoi(target)))) {
  9548. md = (struct mob_data *)map_id2bl(id);
  9549. if(md && md->bl.type == BL_MOB) {
  9550. ud = unit_bl2ud(bl);
  9551. md->master_id = bl->id;
  9552. md->state.killer = 1;
  9553. mob_convertslave(md);
  9554. if (ud) {
  9555. if (ud->target)
  9556. md->target_id = ud->target;
  9557. else if (ud->skilltarget)
  9558. md->target_id = ud->skilltarget;
  9559. if(md->target_id)
  9560. unit_walktobl(&md->bl, map_id2bl(md->target_id), 65025, 2);
  9561. }
  9562. }
  9563. }
  9564. return 0;
  9565. }
  9566. int buildin_mobattach(struct script_state *st){
  9567. int id;
  9568. struct mob_data *md = NULL;
  9569. struct npc_data *nd = NULL;
  9570. char *npcname = NULL;
  9571. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9572. if(st->end > st->start + 3){
  9573. npcname = conv_str(st, & (st->stack->stack_data[st->start+3]));
  9574. }
  9575. if(npcname)
  9576. nd = npc_name2id(npcname);
  9577. else
  9578. nd = (struct npc_data *)map_id2bl(st->oid);
  9579. if(nd)
  9580. if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB)
  9581. md->nd = nd;
  9582. return 0;
  9583. }
  9584. int buildin_unitwalk(struct script_state *st){
  9585. int id,x,y = 0;
  9586. struct block_list *bl = NULL;
  9587. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9588. x = conv_num(st, & (st->stack->stack_data[st->start+3]));
  9589. if(st->end > st->start+4)
  9590. y = conv_num(st, & (st->stack->stack_data[st->start+4]));
  9591. bl = map_id2bl(id);
  9592. if(bl){
  9593. if(y)
  9594. push_val(st->stack,C_INT,unit_walktoxy(bl,x,y,0)); // We'll use harder calculations.
  9595. else
  9596. push_val(st->stack,C_INT,unit_walktobl(bl,map_id2bl(x),65025,1));
  9597. } else {
  9598. push_val(st->stack,C_INT,0);
  9599. }
  9600. return 0;
  9601. }
  9602. int buildin_unitkill(struct script_state *st){
  9603. struct block_list *bl = map_id2bl(conv_num(st, & (st->stack->stack_data[st->start+2])));
  9604. if(bl)
  9605. status_kill(bl);
  9606. return 0;
  9607. }
  9608. int buildin_unitwarp(struct script_state *st){
  9609. int id,x,y,m = 0;
  9610. char *map;
  9611. struct block_list *bl = NULL;
  9612. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9613. map = conv_str(st, & (st->stack->stack_data[st->start+3]));
  9614. x = conv_num(st, & (st->stack->stack_data[st->start+4]));
  9615. y = conv_num(st, & (st->stack->stack_data[st->start+5]));
  9616. bl = map_id2bl(id);
  9617. m = map_mapname2mapid(map);
  9618. if(m && bl){
  9619. push_val(st->stack,C_INT,unit_warp(bl, m, (short)x, (short)y, 0));
  9620. } else {
  9621. push_val(st->stack,C_INT,0);
  9622. }
  9623. return 0;
  9624. }
  9625. int buildin_unitattack(struct script_state *st) {
  9626. int id = 0, actiontype = 0;
  9627. char *target = NULL;
  9628. struct map_session_data *sd = NULL;
  9629. struct block_list *bl = NULL, *tbl = NULL;
  9630. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9631. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  9632. if(st->end > st->start + 4)
  9633. actiontype = conv_num(st, & (st->stack->stack_data[st->start+4]));
  9634. sd = map_nick2sd(target);
  9635. if(!sd)
  9636. tbl = map_id2bl(atoi(target));
  9637. else
  9638. tbl = &sd->bl;
  9639. if((bl = map_id2bl(id))){
  9640. if (bl->type == BL_MOB) {
  9641. ((TBL_MOB *)bl)->state.killer = 1;
  9642. ((TBL_MOB *)bl)->target_id = tbl->id;
  9643. } else if(bl->type == BL_PC){
  9644. clif_parse_ActionRequest_sub(((TBL_PC *)bl), actiontype > 0?0x07:0x00, tbl->id, gettick());
  9645. push_val(st->stack,C_INT,1);
  9646. return 0;
  9647. }
  9648. push_val(st->stack,C_INT,unit_walktobl(bl, tbl, 65025, 2));
  9649. } else {
  9650. push_val(st->stack,C_INT,0);
  9651. }
  9652. return 0;
  9653. }
  9654. int buildin_unitstop(struct script_state *st) {
  9655. int id;
  9656. struct block_list *bl = NULL;
  9657. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9658. bl = map_id2bl(id);
  9659. if(bl){
  9660. unit_stop_attack(bl);
  9661. unit_stop_walking(bl,0);
  9662. if(bl->type == BL_MOB)
  9663. ((TBL_MOB *)bl)->target_id = 0;
  9664. }
  9665. return 0;
  9666. }
  9667. int buildin_unittalk(struct script_state *st)
  9668. {
  9669. char *str;
  9670. int id;
  9671. char message[255];
  9672. struct block_list *bl = NULL;
  9673. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9674. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  9675. bl = map_id2bl(id);
  9676. if(bl) {
  9677. switch(bl->type){
  9678. case BL_MOB:
  9679. memcpy(message, ((TBL_MOB *)bl)->name, NAME_LENGTH);
  9680. break;
  9681. case BL_PC:
  9682. if(strlen(((TBL_PC *)bl)->fakename)>0)
  9683. memcpy(message, ((TBL_PC *)bl)->fakename, NAME_LENGTH);
  9684. else
  9685. memcpy(message, ((TBL_PC *)bl)->status.name, NAME_LENGTH);
  9686. break;
  9687. case BL_NPC:
  9688. memcpy(message, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  9689. break;
  9690. case BL_HOMUNCULUS:
  9691. memcpy(message, ((TBL_HOMUNCULUS *)bl)->master->homunculus.name, NAME_LENGTH);
  9692. break;
  9693. case BL_PET:
  9694. memcpy(message, ((TBL_PET *)bl)->name, NAME_LENGTH);
  9695. break;
  9696. default:
  9697. strcpy(message, "Unknown");
  9698. }
  9699. strcat(message," : ");
  9700. strncat(message,str, 228); //Prevent overflow possibility. [Skotlex]
  9701. clif_message(bl, message);
  9702. if(bl->type == BL_PC)
  9703. clif_displaymessage(((TBL_PC*)bl)->fd, message);
  9704. }
  9705. return 0;
  9706. }
  9707. int buildin_unitemote(struct script_state *st) {
  9708. int id, emo;
  9709. struct block_list *bl= NULL;
  9710. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9711. emo = conv_num(st, & (st->stack->stack_data[st->start+3]));
  9712. if((bl = map_id2bl(id)))
  9713. clif_emotion(bl,emo);
  9714. return 0;
  9715. }
  9716. int buildin_unitdeadsit(struct script_state *st){
  9717. int id, action;
  9718. struct block_list *bl = NULL;
  9719. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9720. action = conv_num(st, & (st->stack->stack_data[st->start+3]));
  9721. if((bl = map_id2bl(id))){
  9722. if(action > -1 && action < 4){
  9723. unsigned char buf[61] = "";
  9724. switch(bl->type){
  9725. case BL_MOB:
  9726. ((TBL_MOB *)bl)->vd->dead_sit = action;
  9727. break;
  9728. case BL_PC:
  9729. ((TBL_PC *)bl)->vd.dead_sit = action;
  9730. break;
  9731. case BL_NPC:
  9732. ((TBL_NPC *)bl)->vd->dead_sit = action;
  9733. break;
  9734. case BL_HOMUNCULUS:
  9735. ((TBL_HOMUNCULUS *)bl)->vd->dead_sit = action;
  9736. break;
  9737. case BL_PET:
  9738. ((TBL_PET *)bl)->vd.dead_sit = action;
  9739. break;
  9740. WBUFW(buf, 0) = 0x8a;
  9741. WBUFL(buf, 2) = bl->id;
  9742. WBUFB(buf,26) = (unsigned char)action;
  9743. clif_send(buf, 61, bl, AREA);
  9744. }
  9745. }else {
  9746. ShowError("buildin_unitdeadsit: Invalid action.\n");
  9747. report_src(st);
  9748. }
  9749. }else{
  9750. ShowError("buildin_unitdeadsit: Target is not found.\n");
  9751. report_src(st);
  9752. }
  9753. return 0;
  9754. }
  9755. int buildin_unitskilluseid (struct script_state *st)
  9756. {
  9757. int id,skid,sklv;
  9758. struct block_list *bl = NULL;
  9759. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  9760. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9761. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9762. if ((bl = map_id2bl(id)))
  9763. unit_skilluse_id(bl,(st->end>st->start+5)?conv_num(st,& (st->stack->stack_data[st->start+5])):bl->id,skid,sklv);
  9764. return 0;
  9765. }
  9766. int buildin_unitskillusepos(struct script_state *st)
  9767. {
  9768. int skid,sklv,x,y,id;
  9769. struct block_list *bl = NULL;
  9770. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  9771. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9772. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9773. x=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9774. y=conv_num(st,& (st->stack->stack_data[st->start+6]));
  9775. if ((bl=map_id2bl(id)))
  9776. unit_skilluse_pos(bl,x,y,skid,sklv);
  9777. return 0;
  9778. }
  9779. // <--- [zBuffer] List of mob control commands
  9780. // sleep <mili sec>
  9781. int buildin_sleep(struct script_state *st) {
  9782. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  9783. struct map_session_data *sd = map_id2sd(st->rid);
  9784. if(sd && sd->npc_id == st->oid) {
  9785. sd->npc_id = 0;
  9786. }
  9787. st->rid = 0;
  9788. if(tick <= 0) {
  9789. // 何もしない
  9790. } else if( !st->sleep.tick ) {
  9791. // 初回実行
  9792. st->state = RERUNLINE;
  9793. st->sleep.tick = tick;
  9794. } else {
  9795. // 続行
  9796. st->sleep.tick = 0;
  9797. }
  9798. return 0;
  9799. }
  9800. // sleep2 <mili sec>
  9801. int buildin_sleep2(struct script_state *st) {
  9802. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  9803. if( tick <= 0 ) {
  9804. // 0ms の待機時間を指定された
  9805. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  9806. } else if( !st->sleep.tick ) {
  9807. // 初回実行時
  9808. st->state = RERUNLINE;
  9809. st->sleep.tick = tick;
  9810. } else {
  9811. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  9812. st->sleep.tick = 0;
  9813. }
  9814. return 0;
  9815. }
  9816. /*==========================================
  9817. * 指定NPCの全てのsleepを再開する
  9818. *------------------------------------------
  9819. */
  9820. int buildin_awake(struct script_state *st)
  9821. {
  9822. struct npc_data *nd;
  9823. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  9824. nd = npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  9825. if(nd == NULL)
  9826. return 0;
  9827. while( node ) {
  9828. if( (int)node->key == nd->bl.id) {
  9829. struct script_state *tst = node->data;
  9830. struct map_session_data *sd = map_id2sd(tst->rid);
  9831. if( tst->sleep.timer == -1 ) {
  9832. node = node->next;
  9833. continue;
  9834. }
  9835. if((sd && sd->char_id != tst->sleep.charid) || (tst->rid && !sd))
  9836. { //Cancel Execution
  9837. tst->state=END;
  9838. tst->rid = 0;
  9839. }
  9840. delete_timer(tst->sleep.timer, run_script_timer);
  9841. node = script_erase_sleepdb(node);
  9842. tst->sleep.timer = -1;
  9843. run_script_main(tst);
  9844. } else {
  9845. node = node->next;
  9846. }
  9847. }
  9848. return 0;
  9849. }
  9850. // getvariableofnpc(<param>, <npc name>);
  9851. int buildin_getvariableofnpc(struct script_state *st)
  9852. {
  9853. if( st->stack->stack_data[st->start+2].type != C_NAME ) {
  9854. // 第一引数が変数名じゃない
  9855. printf("getvariableofnpc: param not name\n");
  9856. push_val(st->stack,C_INT,0);
  9857. } else {
  9858. int num = st->stack->stack_data[st->start+2].u.num;
  9859. char *var_name = str_buf+str_data[num&0x00ffffff].str;
  9860. char *npc_name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9861. struct npc_data *nd = npc_name2id(npc_name);
  9862. if( var_name[0] != '.' || var_name[1] == '@' ) {
  9863. // ' 変数以外はダメ
  9864. printf("getvariableofnpc: invalid scope %s\n", var_name);
  9865. push_val(st->stack,C_INT,0);
  9866. } else if( nd == NULL || nd->bl.subtype != SCRIPT || !nd->u.scr.script) {
  9867. // NPC が見つからない or SCRIPT以外のNPC
  9868. printf("getvariableofnpc: can't find npc %s\n", npc_name);
  9869. push_val(st->stack,C_INT,0);
  9870. } else {
  9871. push_val2(st->stack,C_NAME,num, &nd->u.scr.script->script_vars );
  9872. }
  9873. }
  9874. return 0;
  9875. }
  9876. // [blackhole89] --->
  9877. // Set a warp portal.
  9878. int buildin_warpportal(struct script_state *st){
  9879. struct skill_unit_group *group;
  9880. unsigned short mapindex;
  9881. long spx,spy,tpx,tpy;
  9882. struct block_list *bl=map_id2bl(st->oid);
  9883. nullpo_retr(0,bl);
  9884. spx=conv_num(st, & (st->stack->stack_data[st->start+2]));
  9885. spy=conv_num(st, & (st->stack->stack_data[st->start+3]));
  9886. mapindex = mapindex_name2id((char*)conv_str(st,& (st->stack->stack_data[st->start+4])));
  9887. printf("mapindex: %d\n",mapindex);
  9888. tpx=conv_num(st, & (st->stack->stack_data[st->start+5]));
  9889. tpy=conv_num(st, & (st->stack->stack_data[st->start+6]));
  9890. if(!mapindex) return 0;
  9891. if((group=skill_unitsetting(bl,AL_WARP,4,spx,spy,1))==NULL) {
  9892. return 0;
  9893. }
  9894. group->val2=(tpx<<16)|tpy;
  9895. group->val3 = mapindex;
  9896. return 0;
  9897. }
  9898. // <-- [blackhole89]
  9899. //
  9900. // 実行部main
  9901. //
  9902. /*==========================================
  9903. * コマンドの読み取り
  9904. *------------------------------------------
  9905. */
  9906. static int unget_com_data=-1;
  9907. int get_com(unsigned char *script,int *pos)
  9908. {
  9909. int i,j;
  9910. if(unget_com_data>=0){
  9911. i=unget_com_data;
  9912. unget_com_data=-1;
  9913. return i;
  9914. }
  9915. if(script[*pos]>=0x80){
  9916. return C_INT;
  9917. }
  9918. i=0; j=0;
  9919. while(script[*pos]>=0x40){
  9920. i=script[(*pos)++]<<j;
  9921. j+=6;
  9922. }
  9923. return i+(script[(*pos)++]<<j);
  9924. }
  9925. /*==========================================
  9926. * コマンドのプッシュバック
  9927. *------------------------------------------
  9928. */
  9929. void unget_com(int c)
  9930. {
  9931. if(unget_com_data!=-1){
  9932. if(battle_config.error_log)
  9933. ShowError("unget_com can back only 1 data\n");
  9934. }
  9935. unget_com_data=c;
  9936. }
  9937. /*==========================================
  9938. * 数値の所得
  9939. *------------------------------------------
  9940. */
  9941. int get_num(unsigned char *script,int *pos)
  9942. {
  9943. int i,j;
  9944. i=0; j=0;
  9945. while(script[*pos]>=0xc0){
  9946. i+=(script[(*pos)++]&0x7f)<<j;
  9947. j+=6;
  9948. }
  9949. return i+((script[(*pos)++]&0x7f)<<j);
  9950. }
  9951. /*==========================================
  9952. * スタックから値を取り出す
  9953. *------------------------------------------
  9954. */
  9955. int pop_val(struct script_state* st)
  9956. {
  9957. if(st->stack->sp<=0)
  9958. return 0;
  9959. st->stack->sp--;
  9960. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  9961. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  9962. return st->stack->stack_data[st->stack->sp].u.num;
  9963. return 0;
  9964. }
  9965. #define isstr(c) ((c).type==C_STR || (c).type==C_CONSTSTR)
  9966. /*==========================================
  9967. * 加算演算子
  9968. *------------------------------------------
  9969. */
  9970. void op_add(struct script_state* st)
  9971. {
  9972. st->stack->sp--;
  9973. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  9974. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  9975. if(isstr(st->stack->stack_data[st->stack->sp]) || isstr(st->stack->stack_data[st->stack->sp-1])){
  9976. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  9977. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  9978. }
  9979. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  9980. st->stack->stack_data[st->stack->sp-1].u.num += st->stack->stack_data[st->stack->sp].u.num;
  9981. } else { // ssの予定
  9982. char *buf;
  9983. buf=(char *)aMallocA((strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  9984. strlen(st->stack->stack_data[st->stack->sp].u.str)+1)*sizeof(char));
  9985. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  9986. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  9987. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  9988. {
  9989. aFree(st->stack->stack_data[st->stack->sp-1].u.str);
  9990. st->stack->stack_data[st->stack->sp-1].type=C_INT;
  9991. }
  9992. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  9993. {
  9994. aFree(st->stack->stack_data[st->stack->sp].u.str);
  9995. st->stack->stack_data[st->stack->sp].type=C_INT;
  9996. }
  9997. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  9998. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  9999. }
  10000. }
  10001. /*==========================================
  10002. * 二項演算子(文字列)
  10003. *------------------------------------------
  10004. */
  10005. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  10006. {
  10007. char *s1=st->stack->stack_data[sp1].u.str,
  10008. *s2=st->stack->stack_data[sp2].u.str;
  10009. int a=0;
  10010. switch(op){
  10011. case C_EQ:
  10012. a= (strcmp(s1,s2)==0);
  10013. break;
  10014. case C_NE:
  10015. a= (strcmp(s1,s2)!=0);
  10016. break;
  10017. case C_GT:
  10018. a= (strcmp(s1,s2)> 0);
  10019. break;
  10020. case C_GE:
  10021. a= (strcmp(s1,s2)>=0);
  10022. break;
  10023. case C_LT:
  10024. a= (strcmp(s1,s2)< 0);
  10025. break;
  10026. case C_LE:
  10027. a= (strcmp(s1,s2)<=0);
  10028. break;
  10029. default:
  10030. ShowWarning("script: illegal string operator\n");
  10031. break;
  10032. }
  10033. // Because push_val() overwrite stack_data[sp1], C_STR on stack_data[sp1] won't be freed.
  10034. // So, call push_val() after freeing strings. [jA1783]
  10035. // push_val(st->stack,C_INT,a);
  10036. if(st->stack->stack_data[sp1].type==C_STR)
  10037. {
  10038. aFree(s1);
  10039. st->stack->stack_data[sp1].type=C_INT;
  10040. }
  10041. if(st->stack->stack_data[sp2].type==C_STR)
  10042. {
  10043. aFree(s2);
  10044. st->stack->stack_data[sp2].type=C_INT;
  10045. }
  10046. push_val(st->stack,C_INT,a);
  10047. }
  10048. /*==========================================
  10049. * 二項演算子(数値)
  10050. *------------------------------------------
  10051. */
  10052. void op_2num(struct script_state *st,int op,int i1,int i2)
  10053. {
  10054. switch(op){
  10055. case C_SUB:
  10056. i1-=i2;
  10057. break;
  10058. case C_MUL:
  10059. {
  10060. #ifndef _MSC_VER
  10061. long long res = i1 * i2;
  10062. #else
  10063. __int64 res = i1 * i2;
  10064. #endif
  10065. if (res > 2147483647 )
  10066. i1 = 2147483647;
  10067. else
  10068. i1*=i2;
  10069. }
  10070. break;
  10071. case C_DIV:
  10072. if (i2 != 0)
  10073. i1/=i2;
  10074. else
  10075. ShowWarning("op_2num: Attempted to divide by 0 in a script (operation C_DIV)!\n");
  10076. break;
  10077. case C_MOD:
  10078. if (i2 != 0)
  10079. i1%=i2;
  10080. else
  10081. ShowWarning("op_2num: Attempted to divide by 0 in a script (operation C_MOD)!\n");
  10082. break;
  10083. case C_AND:
  10084. i1&=i2;
  10085. break;
  10086. case C_OR:
  10087. i1|=i2;
  10088. break;
  10089. case C_XOR:
  10090. i1^=i2;
  10091. break;
  10092. case C_LAND:
  10093. i1=i1&&i2;
  10094. break;
  10095. case C_LOR:
  10096. i1=i1||i2;
  10097. break;
  10098. case C_EQ:
  10099. i1=i1==i2;
  10100. break;
  10101. case C_NE:
  10102. i1=i1!=i2;
  10103. break;
  10104. case C_GT:
  10105. i1=i1>i2;
  10106. break;
  10107. case C_GE:
  10108. i1=i1>=i2;
  10109. break;
  10110. case C_LT:
  10111. i1=i1<i2;
  10112. break;
  10113. case C_LE:
  10114. i1=i1<=i2;
  10115. break;
  10116. case C_R_SHIFT:
  10117. i1=i1>>i2;
  10118. break;
  10119. case C_L_SHIFT:
  10120. i1=i1<<i2;
  10121. break;
  10122. }
  10123. push_val(st->stack,C_INT,i1);
  10124. }
  10125. /*==========================================
  10126. * 二項演算子
  10127. *------------------------------------------
  10128. */
  10129. void op_2(struct script_state *st,int op)
  10130. {
  10131. int i1,i2;
  10132. char *s1=NULL,*s2=NULL;
  10133. i2=pop_val(st);
  10134. if( isstr(st->stack->stack_data[st->stack->sp]) )
  10135. s2=st->stack->stack_data[st->stack->sp].u.str;
  10136. i1=pop_val(st);
  10137. if( isstr(st->stack->stack_data[st->stack->sp]) )
  10138. s1=st->stack->stack_data[st->stack->sp].u.str;
  10139. if( s1!=NULL && s2!=NULL ){
  10140. // ss => op_2str
  10141. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  10142. }else if( s1==NULL && s2==NULL ){
  10143. // ii => op_2num
  10144. op_2num(st,op,i1,i2);
  10145. }else{
  10146. // si,is => error
  10147. ShowWarning("script: op_2: int&str, str&int not allow.");
  10148. report_src(st);
  10149. push_val(st->stack,C_INT,0);
  10150. }
  10151. }
  10152. /*==========================================
  10153. * 単項演算子
  10154. *------------------------------------------
  10155. */
  10156. void op_1num(struct script_state *st,int op)
  10157. {
  10158. int i1;
  10159. i1=pop_val(st);
  10160. switch(op){
  10161. case C_NEG:
  10162. i1=-i1;
  10163. break;
  10164. case C_NOT:
  10165. i1=~i1;
  10166. break;
  10167. case C_LNOT:
  10168. i1=!i1;
  10169. break;
  10170. }
  10171. push_val(st->stack,C_INT,i1);
  10172. }
  10173. /*==========================================
  10174. * 関数の実行
  10175. *------------------------------------------
  10176. */
  10177. int run_func(struct script_state *st)
  10178. {
  10179. int i,start_sp,end_sp,func;
  10180. end_sp=st->stack->sp;
  10181. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  10182. if(i==0){
  10183. if(battle_config.error_log)
  10184. ShowError("function not found\n");
  10185. // st->stack->sp=0;
  10186. st->state=END;
  10187. report_src(st);
  10188. return 1;
  10189. }
  10190. start_sp=i-1;
  10191. st->start=i-1;
  10192. st->end=end_sp;
  10193. func=st->stack->stack_data[st->start].u.num;
  10194. if( st->stack->stack_data[st->start].type!=C_NAME || str_data[func].type!=C_FUNC ){
  10195. ShowMessage ("run_func: '"CL_WHITE"%s"CL_RESET"' (type %d) is not function and command!\n",
  10196. str_buf + str_data[func].str, str_data[func].type);
  10197. // st->stack->sp=0;
  10198. st->state=END;
  10199. report_src(st);
  10200. return 1;
  10201. }
  10202. #ifdef DEBUG_RUN
  10203. if(battle_config.etc_log) {
  10204. 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);
  10205. ShowDebug("stack dump :");
  10206. for(i=0;i<end_sp;i++){
  10207. switch(st->stack->stack_data[i].type){
  10208. case C_INT:
  10209. printf(" int(%d)",st->stack->stack_data[i].u.num);
  10210. break;
  10211. case C_NAME:
  10212. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num].str);
  10213. break;
  10214. case C_ARG:
  10215. printf(" arg");
  10216. break;
  10217. case C_POS:
  10218. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  10219. break;
  10220. case C_STR:
  10221. printf(" str(%s)",st->stack->stack_data[i].u.str);
  10222. break;
  10223. case C_CONSTSTR:
  10224. printf(" cstr(%s)",st->stack->stack_data[i].u.str);
  10225. break;
  10226. default:
  10227. printf(" %d,%d",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  10228. }
  10229. }
  10230. printf("\n");
  10231. }
  10232. #endif
  10233. if(str_data[func].func){
  10234. if (str_data[func].func(st)) //Report error
  10235. report_src(st);
  10236. } else {
  10237. if(battle_config.error_log)
  10238. ShowError("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  10239. push_val(st->stack,C_INT,0);
  10240. report_src(st);
  10241. }
  10242. // Stack's datum are used when re-run functions [Eoe]
  10243. if(st->state != RERUNLINE) {
  10244. pop_stack(st->stack,start_sp,end_sp);
  10245. }
  10246. if(st->state==RETFUNC){
  10247. // ユーザー定義関数からの復帰
  10248. int olddefsp=st->stack->defsp;
  10249. int i;
  10250. pop_stack(st->stack,st->stack->defsp,start_sp); // 復帰に邪魔なスタック削除
  10251. if(st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO){
  10252. ShowWarning("script:run_func(return) return without callfunc or callsub!\n");
  10253. st->state=END;
  10254. report_src(st);
  10255. return 1;
  10256. }
  10257. script_free_vars( st->stack->var_function );
  10258. aFree(st->stack->var_function);
  10259. i = conv_num(st,& (st->stack->stack_data[st->stack->defsp-5])); // 引数の数所得
  10260. st->pos=conv_num(st,& (st->stack->stack_data[st->stack->defsp-1])); // スクリプト位置の復元
  10261. st->script=(struct script_code *)conv_num(st,& (st->stack->stack_data[st->stack->defsp-3])); // スクリプトを復元
  10262. st->stack->var_function = (struct linkdb_node**)st->stack->stack_data[st->stack->defsp-2].u.num; // 関数依存変数
  10263. st->stack->defsp=conv_num(st,& (st->stack->stack_data[st->stack->defsp-4])); // 基準スタックポインタを復元
  10264. pop_stack(st->stack,olddefsp-5-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  10265. st->state=GOTO;
  10266. }
  10267. return 0;
  10268. }
  10269. /*==========================================
  10270. * スクリプトの実行メイン部分
  10271. *------------------------------------------
  10272. */
  10273. void run_script_main(struct script_state *st)
  10274. {
  10275. int c/*,rerun_pos*/;
  10276. int cmdcount=script_config.check_cmdcount;
  10277. int gotocount=script_config.check_gotocount;
  10278. struct script_stack *stack=st->stack;
  10279. TBL_PC *sd = map_id2sd(st->rid);
  10280. struct script_state *bk_st = NULL;
  10281. int bk_npcid = 0;
  10282. if(sd){
  10283. if(sd->st != st){
  10284. bk_st = sd->st;
  10285. bk_npcid = sd->npc_id;
  10286. }
  10287. sd->st = st;
  10288. sd->npc_id = st->oid;
  10289. }
  10290. if(st->state == RERUNLINE) {
  10291. st->state = RUN;
  10292. run_func(st);
  10293. if(st->state == GOTO)
  10294. st->state = RUN;
  10295. } else if(st->state != END)
  10296. st->state = RUN;
  10297. while( st->state == RUN) {
  10298. c= get_com((unsigned char *) st->script->script_buf,&st->pos);
  10299. switch(c){
  10300. case C_EOL:
  10301. if(stack->sp!=stack->defsp){
  10302. if(stack->sp > stack->defsp)
  10303. { //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex]
  10304. //Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded.
  10305. if (battle_config.etc_log)
  10306. ShowWarning("Clearing unused stack stack.sp(%d) -> default(%d)\n",stack->sp,stack->defsp);
  10307. pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section.
  10308. } else if(battle_config.error_log)
  10309. ShowError("stack.sp(%d) != default(%d)\n",stack->sp,stack->defsp);
  10310. stack->sp=stack->defsp;
  10311. }
  10312. // rerun_pos=st->pos;
  10313. break;
  10314. case C_INT:
  10315. push_val(stack,C_INT,get_num((unsigned char *) st->script->script_buf,&st->pos));
  10316. break;
  10317. case C_POS:
  10318. case C_NAME:
  10319. push_val(stack,c,(*(int*)(st->script->script_buf+st->pos))&0xffffff);
  10320. st->pos+=3;
  10321. break;
  10322. case C_ARG:
  10323. push_val(stack,c,0);
  10324. break;
  10325. case C_STR:
  10326. push_str(stack,C_CONSTSTR,(unsigned char *) (st->script->script_buf+st->pos));
  10327. while(st->script->script_buf[st->pos++]);
  10328. break;
  10329. case C_FUNC:
  10330. run_func(st);
  10331. if(st->state==GOTO){
  10332. // rerun_pos=st->pos;
  10333. st->state=RUN;
  10334. if( gotocount>0 && (--gotocount)<=0 ){
  10335. ShowError("run_script: infinity loop !\n");
  10336. st->state=END;
  10337. }
  10338. }
  10339. break;
  10340. case C_ADD:
  10341. op_add(st);
  10342. break;
  10343. case C_SUB:
  10344. case C_MUL:
  10345. case C_DIV:
  10346. case C_MOD:
  10347. case C_EQ:
  10348. case C_NE:
  10349. case C_GT:
  10350. case C_GE:
  10351. case C_LT:
  10352. case C_LE:
  10353. case C_AND:
  10354. case C_OR:
  10355. case C_XOR:
  10356. case C_LAND:
  10357. case C_LOR:
  10358. case C_R_SHIFT:
  10359. case C_L_SHIFT:
  10360. op_2(st,c);
  10361. break;
  10362. case C_NEG:
  10363. case C_NOT:
  10364. case C_LNOT:
  10365. op_1num(st,c);
  10366. break;
  10367. case C_NOP:
  10368. st->state=END;
  10369. break;
  10370. default:
  10371. if(battle_config.error_log)
  10372. ShowError("unknown command : %d @ %d\n",c,pos);
  10373. st->state=END;
  10374. break;
  10375. }
  10376. if( cmdcount>0 && (--cmdcount)<=0 ){
  10377. ShowError("run_script: infinity loop !\n");
  10378. st->state=END;
  10379. }
  10380. }
  10381. switch(st->state){
  10382. case STOP:
  10383. break;
  10384. case END:
  10385. {
  10386. st->pos=-1;
  10387. if(sd){
  10388. if(sd->state.using_fake_npc){
  10389. clif_clearchar_id(sd->npc_id, 0, sd->fd);
  10390. sd->state.using_fake_npc = 0;
  10391. }
  10392. npc_event_dequeue(sd);
  10393. //Restore previous script if any.
  10394. sd->st = bk_st;
  10395. sd->npc_id = bk_npcid;
  10396. bk_st = NULL; //Remove tag for removal.
  10397. if (sd->state.reg_dirty&2)
  10398. intif_saveregistry(sd,2);
  10399. if (sd->state.reg_dirty&1)
  10400. intif_saveregistry(sd,1);
  10401. }
  10402. //Remove unneeded script.
  10403. script_free_stack (st->stack);
  10404. aFree(st);
  10405. }
  10406. break;
  10407. case RERUNLINE:
  10408. if(bk_st && sd->st != bk_st && st->sleep.tick <= 0)
  10409. ShowWarning("Unable to restore stack! Double continuation!\n");
  10410. if(st->sleep.tick > 0)
  10411. { //Delay execution
  10412. if(sd)
  10413. st->sleep.charid = sd->char_id;
  10414. else
  10415. st->sleep.charid = 0;
  10416. st->sleep.timer = add_timer(gettick()+st->sleep.tick,
  10417. run_script_timer, st->sleep.charid, (int)st);
  10418. linkdb_insert(&sleep_db, (void*)st->oid, st);
  10419. //Restore previous script/
  10420. sd->st = bk_st;
  10421. sd->npc_id = bk_npcid;
  10422. bk_st = NULL; //Remove tag for removal.
  10423. }
  10424. // Do not call function of commands two time! [ Eoe / jA 1094 ]
  10425. // For example: select "1", "2", callsub(...);
  10426. // If current script position is changed, callsub will be called two time.
  10427. //
  10428. // {
  10429. // st->pos=rerun_pos;
  10430. // }
  10431. break;
  10432. }
  10433. if (bk_st)
  10434. { //Remove previous script
  10435. script_free_stack(bk_st->stack);
  10436. aFree(bk_st);
  10437. bk_st = NULL;
  10438. }
  10439. //FIXME: Is it correct to NOT free the script when the state is not END AND there's NO PLAYER running it??
  10440. return;
  10441. }
  10442. /*==========================================
  10443. * スクリプトの実行
  10444. *------------------------------------------
  10445. */
  10446. void run_script(struct script_code *rootscript,int pos,int rid,int oid)
  10447. {
  10448. struct script_state *st;
  10449. struct map_session_data *sd=NULL;
  10450. //Variables for backing up the previous script and restore it if needed. [Skotlex]
  10451. //struct script_code *bck_script = NULL;
  10452. //struct script_code *bck_scriptroot = NULL;
  10453. //int bck_scriptstate = 0,bck_npcid = 0;
  10454. //struct script_stack *bck_stack = NULL;
  10455. if (rootscript == NULL || pos < 0)
  10456. return;
  10457. if ((sd = map_id2sd(rid)) && sd->st && sd->st->scriptroot == rootscript && sd->st->pos == pos){
  10458. st = sd->st;
  10459. } else {
  10460. st = aCalloc(sizeof(struct script_state), 1);
  10461. // the script is different, make new script_state and stack
  10462. st->stack = aMalloc (sizeof(struct script_stack));
  10463. st->stack->sp = 0;
  10464. st->stack->sp_max = 64;
  10465. st->stack->stack_data = (struct script_data *) aCalloc (st->stack->sp_max,sizeof(st->stack->stack_data[0]));
  10466. st->stack->defsp = st->stack->sp;
  10467. st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
  10468. st->state = RUN;
  10469. st->script = rootscript;
  10470. /*if (sd){
  10471. if(sd->stack) {
  10472. // if there's a sd and a stack - back it up and restore it if possible.
  10473. bck_script = sd->npc_script;
  10474. bck_scriptroot = sd->npc_scriptroot;
  10475. bck_scriptstate = sd->npc_scriptstate;
  10476. bck_stack = sd->stack;
  10477. sd->stack = NULL;
  10478. }
  10479. bck_npcid = sd->npc_id;
  10480. sd->npc_id = oid;
  10481. }*/
  10482. }
  10483. st->pos = pos;
  10484. st->rid = rid;
  10485. st->oid = oid;
  10486. st->sleep.timer = -1;
  10487. run_script_main(st);
  10488. /* if (st->state != END){
  10489. pos = st->pos;
  10490. if(!st->sleep.tick && sd) {
  10491. // script is not finished, store data in sd.
  10492. sd->npc_script = st->script;
  10493. sd->npc_scriptroot = rootscript;
  10494. sd->npc_scriptstate = st->state;
  10495. sd->stack = st->stack;
  10496. if (bck_stack) //Get rid of the backup as it can't be restored.
  10497. script_free_stack (bck_stack);
  10498. aFree(st);
  10499. }
  10500. return pos;
  10501. } else {
  10502. if(st->stack)
  10503. script_free_stack(st->stack);
  10504. aFree(st);
  10505. }
  10506. } else {
  10507. //Script finished.
  10508. if (sd)
  10509. { //Clear or restore previous script.
  10510. sd->npc_script = bck_script;
  10511. sd->npc_scriptroot = bck_scriptroot;
  10512. sd->npc_scriptstate = bck_scriptstate;
  10513. sd->stack = bck_stack;
  10514. sd->npc_id = bck_npcid;
  10515. //Since the script is done, save any changed account variables [Skotlex]
  10516. if (sd->state.reg_dirty&2)
  10517. intif_saveregistry(sd,2);
  10518. if (sd->state.reg_dirty&1)
  10519. intif_saveregistry(sd,1);
  10520. }
  10521. }*/
  10522. return;
  10523. }
  10524. /*==========================================
  10525. * 指定ノードをsleep_dbから削除
  10526. *------------------------------------------
  10527. */
  10528. struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n)
  10529. {
  10530. struct linkdb_node *retnode;
  10531. if( n == NULL)
  10532. return NULL;
  10533. if( n->prev == NULL )
  10534. sleep_db = n->next;
  10535. else
  10536. n->prev->next = n->next;
  10537. if( n->next )
  10538. n->next->prev = n->prev;
  10539. retnode = n->next;
  10540. aFree( n );
  10541. return retnode; // 次のノードを返す
  10542. }
  10543. /*==========================================
  10544. * sleep用タイマー関数
  10545. *------------------------------------------
  10546. */
  10547. int run_script_timer(int tid, unsigned int tick, int id, int data)
  10548. {
  10549. struct script_state *st = (struct script_state *)data;
  10550. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  10551. struct map_session_data *sd = map_id2sd(st->rid);
  10552. if((sd && sd->char_id != id) || (st->rid && !sd))
  10553. { //Character mismatch. Cancel execution.
  10554. st->rid = 0;
  10555. st->state = END;
  10556. }
  10557. while( node && st->sleep.timer != -1 ) {
  10558. if( (int)node->key == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
  10559. script_erase_sleepdb(node);
  10560. st->sleep.timer = -1;
  10561. break;
  10562. }
  10563. node = node->next;
  10564. }
  10565. run_script_main(st);
  10566. return 0;
  10567. }
  10568. /*==========================================
  10569. * マップ変数の変更
  10570. *------------------------------------------
  10571. */
  10572. int mapreg_setreg(int num,int val)
  10573. {
  10574. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  10575. int i=num>>24;
  10576. char *name=str_buf+str_data[num&0x00ffffff].str;
  10577. char tmp_str[64];
  10578. #endif
  10579. if(val!=0) {
  10580. if(idb_put(mapreg_db,num,(void*)val))
  10581. ;
  10582. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  10583. else if(name[1] != '@') {
  10584. 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);
  10585. if(mysql_query(&mmysql_handle,tmp_sql)){
  10586. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10587. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10588. }
  10589. }
  10590. #endif
  10591. // else
  10592. } else { // [zBuffer]
  10593. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  10594. if(name[1] != '@') { // Remove from database because it is unused.
  10595. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  10596. if(mysql_query(&mmysql_handle,tmp_sql)){
  10597. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10598. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10599. }
  10600. }
  10601. #endif
  10602. idb_remove(mapreg_db,num);
  10603. }
  10604. mapreg_dirty=1;
  10605. return 0;
  10606. }
  10607. /*==========================================
  10608. * 文字列型マップ変数の変更
  10609. *------------------------------------------
  10610. */
  10611. int mapreg_setregstr(int num,const char *str)
  10612. {
  10613. char *p;
  10614. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  10615. char tmp_str[64];
  10616. char tmp_str2[512];
  10617. int i=num>>24; // [zBuffer]
  10618. char *name=str_buf+str_data[num&0x00ffffff].str;
  10619. #endif
  10620. if( str==NULL || *str==0 ){
  10621. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  10622. if(name[1] != '@') {
  10623. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  10624. if(mysql_query(&mmysql_handle,tmp_sql)){
  10625. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10626. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10627. }
  10628. }
  10629. #endif
  10630. idb_remove(mapregstr_db,num);
  10631. mapreg_dirty=1;
  10632. return 0;
  10633. }
  10634. p=(char *)aMallocA((strlen(str)+1)*sizeof(char));
  10635. strcpy(p,str);
  10636. if (idb_put(mapregstr_db,num,p))
  10637. ;
  10638. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  10639. else if(name[1] != '@'){ //put returned null, so we must insert.
  10640. // Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
  10641. 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));
  10642. if(mysql_query(&mmysql_handle,tmp_sql)){
  10643. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10644. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10645. }
  10646. }
  10647. #endif
  10648. mapreg_dirty=1;
  10649. return 0;
  10650. }
  10651. /*==========================================
  10652. * 永続的マップ変数の読み込み
  10653. *------------------------------------------
  10654. */
  10655. static int script_load_mapreg(void)
  10656. {
  10657. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  10658. FILE *fp;
  10659. char line[1024];
  10660. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  10661. return -1;
  10662. while(fgets(line,sizeof(line),fp)){
  10663. char buf1[256],buf2[1024],*p;
  10664. int n,v,s,i;
  10665. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  10666. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  10667. continue;
  10668. if( buf1[strlen(buf1)-1]=='$' ){
  10669. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  10670. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  10671. continue;
  10672. }
  10673. p=(char *)aMallocA((strlen(buf2) + 1)*sizeof(char));
  10674. strcpy(p,buf2);
  10675. s= add_str((unsigned char *) buf1);
  10676. idb_put(mapregstr_db,(i<<24)|s,p);
  10677. }else{
  10678. if( sscanf(line+n,"%d",&v)!=1 ){
  10679. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  10680. continue;
  10681. }
  10682. s= add_str((unsigned char *) buf1);
  10683. idb_put(mapreg_db,(i<<24)|s,(void*)v);
  10684. }
  10685. }
  10686. fclose(fp);
  10687. mapreg_dirty=0;
  10688. return 0;
  10689. #else
  10690. // SQL mapreg code start [zBuffer]
  10691. /*
  10692. 0 1 2
  10693. +-------------------------+
  10694. | varname | index | value |
  10695. +-------------------------+
  10696. */
  10697. unsigned int perfomance = (unsigned int)time(NULL);
  10698. sprintf(tmp_sql,"SELECT * FROM `%s`",mapregsql_db);
  10699. ShowInfo("Querying script_load_mapreg ...\n");
  10700. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  10701. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10702. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10703. return -1;
  10704. }
  10705. ShowInfo("Success! Returning results ...\n");
  10706. sql_res = mysql_store_result(&mmysql_handle);
  10707. if (sql_res) {
  10708. while ((sql_row = mysql_fetch_row(sql_res))) {
  10709. char buf1[33], *p = NULL;
  10710. int i,v,s;
  10711. strcpy(buf1,sql_row[0]);
  10712. if( buf1[strlen(buf1)-1]=='$' ){
  10713. i = atoi(sql_row[1]);
  10714. p=(char *)aMallocA((strlen(sql_row[2]) + 1)*sizeof(char));
  10715. strcpy(p,sql_row[2]);
  10716. s= add_str((unsigned char *) buf1);
  10717. idb_put(mapregstr_db,(i<<24)|s,p);
  10718. }else{
  10719. s= add_str((unsigned char *) buf1);
  10720. v= atoi(sql_row[2]);
  10721. i = atoi(sql_row[1]);
  10722. idb_put(mapreg_db,(i<<24)|s,(void *)v);
  10723. }
  10724. }
  10725. }
  10726. ShowInfo("Freeing results...\n");
  10727. mysql_free_result(sql_res);
  10728. mapreg_dirty=0;
  10729. perfomance = ((unsigned int)time(NULL) - perfomance);
  10730. ShowInfo("SQL Mapreg Loading Completed Under %d Seconds.\n",perfomance);
  10731. return 0;
  10732. #endif /* TXT_ONLY */
  10733. }
  10734. /*==========================================
  10735. * 永続的マップ変数の書き込み
  10736. *------------------------------------------
  10737. */
  10738. static int script_save_mapreg_intsub(DBKey key,void *data,va_list ap)
  10739. {
  10740. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  10741. FILE *fp=va_arg(ap,FILE*);
  10742. int num=key.i&0x00ffffff, i=key.i>>24;
  10743. char *name=str_buf+str_data[num].str;
  10744. if( name[1]!='@' ){
  10745. if(i==0)
  10746. fprintf(fp,"%s\t%d\n", name, (int)data);
  10747. else
  10748. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  10749. }
  10750. return 0;
  10751. #else
  10752. int num=key.i&0x00ffffff, i=key.i>>24; // [zBuffer]
  10753. char *name=str_buf+str_data[num].str;
  10754. if ( name[1] != '@') {
  10755. 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);
  10756. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  10757. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10758. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10759. }
  10760. }
  10761. return 0;
  10762. #endif
  10763. }
  10764. static int script_save_mapreg_strsub(DBKey key,void *data,va_list ap)
  10765. {
  10766. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  10767. FILE *fp=va_arg(ap,FILE*);
  10768. int num=key.i&0x00ffffff, i=key.i>>24;
  10769. char *name=str_buf+str_data[num].str;
  10770. if( name[1]!='@' ){
  10771. if(i==0)
  10772. fprintf(fp,"%s\t%s\n", name, (char *)data);
  10773. else
  10774. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  10775. }
  10776. return 0;
  10777. #else
  10778. char tmp_str2[512];
  10779. int num=key.i&0x00ffffff, i=key.i>>24;
  10780. char *name=str_buf+str_data[num].str;
  10781. if ( name[1] != '@') {
  10782. 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);
  10783. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  10784. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10785. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10786. }
  10787. }
  10788. return 0;
  10789. #endif
  10790. }
  10791. static int script_save_mapreg(void)
  10792. {
  10793. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  10794. FILE *fp;
  10795. int lock;
  10796. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL ) {
  10797. ShowError("script_save_mapreg: Unable to lock-open file [%s]\n",mapreg_txt);
  10798. return -1;
  10799. }
  10800. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub,fp);
  10801. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  10802. lock_fclose(fp,mapreg_txt,&lock);
  10803. #else
  10804. unsigned int perfomance = (unsigned int)time(NULL);
  10805. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub); // [zBuffer]
  10806. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub);
  10807. perfomance = ((unsigned int)time(NULL) - perfomance);
  10808. if(perfomance > 2)
  10809. ShowWarning("Slow Query: MapregSQL Saving @ %d second(s).\n", perfomance);
  10810. #endif
  10811. mapreg_dirty=0;
  10812. return 0;
  10813. }
  10814. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  10815. {
  10816. if(mapreg_dirty)
  10817. if (script_save_mapreg() == -1)
  10818. ShowError("Failed to save the mapreg data!\n");
  10819. return 0;
  10820. }
  10821. /*==========================================
  10822. *
  10823. *------------------------------------------
  10824. */
  10825. static int set_posword(char *p)
  10826. {
  10827. char* np,* str[15];
  10828. int i=0;
  10829. for(i=0;i<11;i++) {
  10830. if((np=strchr(p,','))!=NULL) {
  10831. str[i]=p;
  10832. *np=0;
  10833. p=np+1;
  10834. } else {
  10835. str[i]=p;
  10836. p+=strlen(p);
  10837. }
  10838. if(str[i])
  10839. strcpy(pos[i],str[i]);
  10840. }
  10841. return 0;
  10842. }
  10843. int script_config_read_sub(char *cfgName)
  10844. {
  10845. int i;
  10846. char line[1024],w1[1024],w2[1024];
  10847. FILE *fp;
  10848. fp = fopen(cfgName, "r");
  10849. if (fp == NULL) {
  10850. ShowError("file not found: [%s]\n", cfgName);
  10851. return 1;
  10852. }
  10853. while (fgets(line, sizeof(line) - 1, fp)) {
  10854. if (line[0] == '/' && line[1] == '/')
  10855. continue;
  10856. i = sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  10857. if (i != 2)
  10858. continue;
  10859. if(strcmpi(w1,"refine_posword")==0) {
  10860. set_posword(w2);
  10861. }
  10862. else if(strcmpi(w1,"verbose_mode")==0) {
  10863. script_config.verbose_mode = battle_config_switch(w2);
  10864. }
  10865. else if(strcmpi(w1,"warn_func_no_comma")==0) {
  10866. script_config.warn_func_no_comma = battle_config_switch(w2);
  10867. }
  10868. else if(strcmpi(w1,"warn_cmd_no_comma")==0) {
  10869. script_config.warn_cmd_no_comma = battle_config_switch(w2);
  10870. }
  10871. else if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
  10872. script_config.warn_func_mismatch_paramnum = battle_config_switch(w2);
  10873. }
  10874. else if(strcmpi(w1,"warn_cmd_mismatch_paramnum")==0) {
  10875. script_config.warn_cmd_mismatch_paramnum = battle_config_switch(w2);
  10876. }
  10877. else if(strcmpi(w1,"check_cmdcount")==0) {
  10878. script_config.check_cmdcount = battle_config_switch(w2);
  10879. }
  10880. else if(strcmpi(w1,"check_gotocount")==0) {
  10881. script_config.check_gotocount = battle_config_switch(w2);
  10882. }
  10883. else if(strcmpi(w1,"event_script_type")==0) {
  10884. script_config.event_script_type = battle_config_switch(w2);
  10885. }
  10886. else if(strcmpi(w1,"event_requires_trigger")==0) {
  10887. script_config.event_requires_trigger = battle_config_switch(w2);
  10888. }
  10889. else if(strcmpi(w1,"die_event_name")==0) {
  10890. strncpy(script_config.die_event_name, w2, NAME_LENGTH-1);
  10891. if (strlen(script_config.die_event_name) != strlen(w2))
  10892. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.die_event_name);
  10893. }
  10894. else if(strcmpi(w1,"kill_pc_event_name")==0) {
  10895. strncpy(script_config.kill_pc_event_name, w2, NAME_LENGTH-1);
  10896. if (strlen(script_config.kill_pc_event_name) != strlen(w2))
  10897. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_pc_event_name);
  10898. }
  10899. else if(strcmpi(w1,"kill_mob_event_name")==0) {
  10900. strncpy(script_config.kill_mob_event_name, w2, NAME_LENGTH-1);
  10901. if (strlen(script_config.kill_mob_event_name) != strlen(w2))
  10902. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_mob_event_name);
  10903. }
  10904. else if(strcmpi(w1,"login_event_name")==0) {
  10905. strncpy(script_config.login_event_name, w2, NAME_LENGTH-1);
  10906. if (strlen(script_config.login_event_name) != strlen(w2))
  10907. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.login_event_name);
  10908. }
  10909. else if(strcmpi(w1,"logout_event_name")==0) {
  10910. strncpy(script_config.logout_event_name, w2, NAME_LENGTH-1);
  10911. if (strlen(script_config.logout_event_name) != strlen(w2))
  10912. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.logout_event_name);
  10913. }
  10914. else if(strcmpi(w1,"loadmap_event_name")==0) {
  10915. strncpy(script_config.loadmap_event_name, w2, NAME_LENGTH-1);
  10916. if (strlen(script_config.loadmap_event_name) != strlen(w2))
  10917. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.loadmap_event_name);
  10918. }
  10919. else if(strcmpi(w1,"baselvup_event_name")==0) {
  10920. strncpy(script_config.baselvup_event_name, w2, NAME_LENGTH-1);
  10921. if (strlen(script_config.baselvup_event_name) != strlen(w2))
  10922. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.baselvup_event_name);
  10923. }
  10924. else if(strcmpi(w1,"joblvup_event_name")==0) {
  10925. strncpy(script_config.joblvup_event_name, w2, NAME_LENGTH-1);
  10926. if (strlen(script_config.joblvup_event_name) != strlen(w2))
  10927. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.joblvup_event_name);
  10928. }
  10929. else if(strcmpi(w1,"import")==0){
  10930. script_config_read_sub(w2);
  10931. }
  10932. }
  10933. fclose(fp);
  10934. return 0;
  10935. }
  10936. int script_config_read(char *cfgName)
  10937. { //Script related variables should be initialized once! [Skotlex]
  10938. memset (&script_config, 0, sizeof(script_config));
  10939. script_config.verbose_mode = 0;
  10940. script_config.warn_func_no_comma = 1;
  10941. script_config.warn_cmd_no_comma = 1;
  10942. script_config.warn_func_mismatch_paramnum = 1;
  10943. script_config.warn_cmd_mismatch_paramnum = 1;
  10944. script_config.check_cmdcount = 65535;
  10945. script_config.check_gotocount = 2048;
  10946. script_config.event_script_type = 0;
  10947. script_config.event_requires_trigger = 1;
  10948. return script_config_read_sub(cfgName);
  10949. }
  10950. static int do_final_userfunc_sub (DBKey key,void *data,va_list ap){
  10951. struct script_code *code = (struct script_code *)data;
  10952. if(code){
  10953. script_free_vars( &code->script_vars );
  10954. aFree( code->script_buf );
  10955. }
  10956. return 0;
  10957. }
  10958. /*==========================================
  10959. * 終了
  10960. *------------------------------------------
  10961. */
  10962. int do_final_script()
  10963. {
  10964. if(mapreg_dirty>=0)
  10965. script_save_mapreg();
  10966. mapreg_db->destroy(mapreg_db,NULL);
  10967. mapregstr_db->destroy(mapregstr_db,NULL);
  10968. scriptlabel_db->destroy(scriptlabel_db,NULL);
  10969. userfunc_db->destroy(userfunc_db,do_final_userfunc_sub);
  10970. if(sleep_db) {
  10971. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  10972. while(n) {
  10973. struct script_state *st = (struct script_state *)n->data;
  10974. script_free_stack(st->stack);
  10975. free(st);
  10976. n = n->next;
  10977. }
  10978. linkdb_final(&sleep_db);
  10979. }
  10980. if (str_data)
  10981. aFree(str_data);
  10982. if (str_buf)
  10983. aFree(str_buf);
  10984. return 0;
  10985. }
  10986. /*==========================================
  10987. * 初期化
  10988. *------------------------------------------
  10989. */
  10990. int do_init_script()
  10991. {
  10992. mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
  10993. mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
  10994. userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_RELEASE_BOTH,50);
  10995. scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_ALLOW_NULL_DATA,50);
  10996. script_load_mapreg();
  10997. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  10998. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  10999. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  11000. return 0;
  11001. }
  11002. int script_reload()
  11003. {
  11004. if(mapreg_dirty>=0)
  11005. script_save_mapreg();
  11006. mapreg_db->clear(mapreg_db, NULL);
  11007. mapregstr_db->clear(mapregstr_db, NULL);
  11008. userfunc_db->clear(userfunc_db,do_final_userfunc_sub);
  11009. scriptlabel_db->clear(scriptlabel_db, NULL);
  11010. if(sleep_db) {
  11011. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  11012. while(n) {
  11013. struct script_state *st = (struct script_state *)n->data;
  11014. script_free_stack(st->stack);
  11015. free(st);
  11016. n = n->next;
  11017. }
  11018. linkdb_final(&sleep_db);
  11019. }
  11020. script_load_mapreg();
  11021. return 0;
  11022. }