script.c 183 KB

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