script.c 190 KB

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