pc.c 209 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/core.h" // get_svn_revision()
  5. #include "../common/malloc.h"
  6. #include "../common/nullpo.h"
  7. #include "../common/showmsg.h"
  8. #include "../common/socket.h" // session[]
  9. #include "../common/strlib.h" // safestrncpy()
  10. #include "../common/timer.h"
  11. #include "../common/utils.h"
  12. #include "atcommand.h" // get_atcommand_level()
  13. #include "battle.h" // battle_config
  14. #include "chrif.h"
  15. #include "clif.h"
  16. #include "date.h" // is_day_of_*()
  17. #include "intif.h"
  18. #include "itemdb.h"
  19. #include "log.h"
  20. #include "mail.h"
  21. #include "map.h"
  22. #include "path.h"
  23. #include "homunculus.h"
  24. #include "mercenary.h"
  25. #include "mob.h" // MAX_MOB_RACE_DB
  26. #include "npc.h" // fake_nd
  27. #include "pet.h" // pet_unlocktarget()
  28. #include "party.h" // party_search()
  29. #include "guild.h" // guild_search(), guild_request_info()
  30. #include "script.h" // script_config
  31. #include "skill.h"
  32. #include "status.h" // struct status_data
  33. #include "pc.h"
  34. #include "quest.h"
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <time.h>
  39. #define PVP_CALCRANK_INTERVAL 1000 // PVP順位計算の間隔
  40. static unsigned int exp_table[CLASS_COUNT][2][MAX_LEVEL];
  41. static unsigned int max_level[CLASS_COUNT][2];
  42. static short statp[MAX_LEVEL+1];
  43. // h-files are for declarations, not for implementations... [Shinomori]
  44. struct skill_tree_entry skill_tree[CLASS_COUNT][MAX_SKILL_TREE];
  45. // timer for night.day implementation
  46. int day_timer_tid;
  47. int night_timer_tid;
  48. struct fame_list smith_fame_list[MAX_FAME_LIST];
  49. struct fame_list chemist_fame_list[MAX_FAME_LIST];
  50. struct fame_list taekwon_fame_list[MAX_FAME_LIST];
  51. static unsigned short equip_pos[EQI_MAX]={EQP_ACC_L,EQP_ACC_R,EQP_SHOES,EQP_GARMENT,EQP_HEAD_LOW,EQP_HEAD_MID,EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_AMMO};
  52. #define MOTD_LINE_SIZE 128
  53. char motd_text[MOTD_LINE_SIZE][256]; // Message of the day buffer [Valaris]
  54. struct duel duel_list[MAX_DUEL];
  55. int duel_count = 0;
  56. //Links related info to the sd->hate_mob[]/sd->feel_map[] entries
  57. const struct sg_data sg_info[3] = {
  58. { SG_SUN_ANGER, SG_SUN_BLESS, SG_SUN_COMFORT, "PC_FEEL_SUN", "PC_HATE_MOB_SUN", is_day_of_sun },
  59. { SG_MOON_ANGER, SG_MOON_BLESS, SG_MOON_COMFORT, "PC_FEEL_MOON", "PC_HATE_MOB_MOON", is_day_of_moon },
  60. { SG_STAR_ANGER, SG_STAR_BLESS, SG_STAR_COMFORT, "PC_FEEL_STAR", "PC_HATE_MOB_STAR", is_day_of_star }
  61. };
  62. //Converts a class to its array index for CLASS_COUNT defined arrays.
  63. //Note that it does not do a validity check for speed purposes, where parsing
  64. //player input make sure to use a pcdb_checkid first!
  65. int pc_class2idx(int class_) {
  66. if (class_ >= JOB_NOVICE_HIGH)
  67. return class_- JOB_NOVICE_HIGH+JOB_MAX_BASIC;
  68. return class_;
  69. }
  70. int pc_isGM(struct map_session_data* sd)
  71. {
  72. return sd->gmlevel;
  73. }
  74. static int pc_invincible_timer(int tid, unsigned int tick, int id, intptr data)
  75. {
  76. struct map_session_data *sd;
  77. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  78. return 1;
  79. if(sd->invincible_timer != tid){
  80. ShowError("invincible_timer %d != %d\n",sd->invincible_timer,tid);
  81. return 0;
  82. }
  83. sd->invincible_timer = INVALID_TIMER;
  84. skill_unit_move(&sd->bl,tick,1);
  85. return 0;
  86. }
  87. void pc_setinvincibletimer(struct map_session_data* sd, int val)
  88. {
  89. nullpo_retv(sd);
  90. if( sd->invincible_timer != INVALID_TIMER )
  91. delete_timer(sd->invincible_timer,pc_invincible_timer);
  92. sd->invincible_timer = add_timer(gettick()+val,pc_invincible_timer,sd->bl.id,0);
  93. }
  94. void pc_delinvincibletimer(struct map_session_data* sd)
  95. {
  96. nullpo_retv(sd);
  97. if( sd->invincible_timer != INVALID_TIMER )
  98. {
  99. delete_timer(sd->invincible_timer,pc_invincible_timer);
  100. sd->invincible_timer = INVALID_TIMER;
  101. skill_unit_move(&sd->bl,gettick(),1);
  102. }
  103. }
  104. static int pc_spiritball_timer(int tid, unsigned int tick, int id, intptr data)
  105. {
  106. struct map_session_data *sd;
  107. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  108. return 1;
  109. if(sd->spirit_timer[0] != tid){
  110. ShowError("spirit_timer %d != %d\n",sd->spirit_timer[0],tid);
  111. return 0;
  112. }
  113. if(sd->spiritball <= 0) {
  114. ShowError("Spiritballs are already 0 when pc_spiritball_timer gets called");
  115. sd->spiritball = 0;
  116. return 0;
  117. }
  118. sd->spiritball--;
  119. // I leave this here as bad example [Shinomori]
  120. //memcpy( &sd->spirit_timer[0], &sd->spirit_timer[1], sizeof(sd->spirit_timer[0]) * sd->spiritball );
  121. memmove( sd->spirit_timer+0, sd->spirit_timer+1, (sd->spiritball)*sizeof(int) );
  122. sd->spirit_timer[sd->spiritball]=-1;
  123. clif_spiritball(sd);
  124. return 0;
  125. }
  126. int pc_addspiritball(struct map_session_data *sd,int interval,int max)
  127. {
  128. nullpo_retr(0, sd);
  129. if(max > MAX_SKILL_LEVEL)
  130. max = MAX_SKILL_LEVEL;
  131. if(sd->spiritball < 0)
  132. sd->spiritball = 0;
  133. if(sd->spiritball >= max) {
  134. if(sd->spirit_timer[0] != -1)
  135. delete_timer(sd->spirit_timer[0],pc_spiritball_timer);
  136. // I leave this here as bad example [Shinomori]
  137. //memcpy( &sd->spirit_timer[0], &sd->spirit_timer[1], sizeof(sd->spirit_timer[0]) * (sd->spiritball - 1));
  138. memmove( sd->spirit_timer+0, sd->spirit_timer+1, (sd->spiritball - 1)*sizeof(int) );
  139. //sd->spirit_timer[sd->spiritball-1] = -1; // intentionally, but will be overwritten
  140. } else
  141. sd->spiritball++;
  142. sd->spirit_timer[sd->spiritball-1] = add_timer(gettick()+interval,pc_spiritball_timer,sd->bl.id,0);
  143. clif_spiritball(sd);
  144. return 0;
  145. }
  146. int pc_delspiritball(struct map_session_data *sd,int count,int type)
  147. {
  148. int i;
  149. nullpo_retr(0, sd);
  150. if(sd->spiritball <= 0) {
  151. sd->spiritball = 0;
  152. return 0;
  153. }
  154. if(count > sd->spiritball)
  155. count = sd->spiritball;
  156. sd->spiritball -= count;
  157. if(count > MAX_SKILL_LEVEL)
  158. count = MAX_SKILL_LEVEL;
  159. for(i=0;i<count;i++) {
  160. if(sd->spirit_timer[i] != -1) {
  161. delete_timer(sd->spirit_timer[i],pc_spiritball_timer);
  162. sd->spirit_timer[i] = -1;
  163. }
  164. }
  165. for(i=count;i<MAX_SKILL_LEVEL;i++) {
  166. sd->spirit_timer[i-count] = sd->spirit_timer[i];
  167. sd->spirit_timer[i] = -1;
  168. }
  169. if(!type)
  170. clif_spiritball(sd);
  171. return 0;
  172. }
  173. // Increases a player's fame points and displays a notice to him
  174. void pc_addfame(struct map_session_data *sd,int count)
  175. {
  176. nullpo_retv(sd);
  177. sd->status.fame += count;
  178. if(sd->status.fame > MAX_FAME)
  179. sd->status.fame = MAX_FAME;
  180. switch(sd->class_&MAPID_UPPERMASK){
  181. case MAPID_BLACKSMITH: // Blacksmith
  182. clif_fame_blacksmith(sd,count);
  183. break;
  184. case MAPID_ALCHEMIST: // Alchemist
  185. clif_fame_alchemist(sd,count);
  186. break;
  187. case MAPID_TAEKWON: // Taekwon
  188. clif_fame_taekwon(sd,count);
  189. break;
  190. }
  191. chrif_updatefamelist(sd);
  192. }
  193. // Check whether a player ID is in the fame rankers' list of its job, returns his/her position if so, 0 else
  194. unsigned char pc_famerank(int char_id, int job)
  195. {
  196. int i;
  197. switch(job){
  198. case MAPID_BLACKSMITH: // Blacksmith
  199. for(i = 0; i < MAX_FAME_LIST; i++){
  200. if(smith_fame_list[i].id == char_id)
  201. return i + 1;
  202. }
  203. break;
  204. case MAPID_ALCHEMIST: // Alchemist
  205. for(i = 0; i < MAX_FAME_LIST; i++){
  206. if(chemist_fame_list[i].id == char_id)
  207. return i + 1;
  208. }
  209. break;
  210. case MAPID_TAEKWON: // Taekwon
  211. for(i = 0; i < MAX_FAME_LIST; i++){
  212. if(taekwon_fame_list[i].id == char_id)
  213. return i + 1;
  214. }
  215. break;
  216. }
  217. return 0;
  218. }
  219. int pc_setrestartvalue(struct map_session_data *sd,int type)
  220. {
  221. struct status_data *status, *b_status;
  222. nullpo_retr(0, sd);
  223. b_status = &sd->base_status;
  224. status = &sd->battle_status;
  225. if (type&1)
  226. { //Normal resurrection
  227. status->hp = 1; //Otherwise status_heal may fail if dead.
  228. status_heal(&sd->bl, b_status->hp, b_status->sp>status->sp?b_status->sp-status->sp:0, 1);
  229. } else { //Just for saving on the char-server (with values as if respawned)
  230. sd->status.hp = b_status->hp;
  231. sd->status.sp = (status->sp < b_status->sp)?b_status->sp:status->sp;
  232. }
  233. return 0;
  234. }
  235. /*==========================================
  236. Determines if the GM can give / drop / trade / vend items
  237. Args: GM Level (current player GM level)
  238. *------------------------------------------*/
  239. bool pc_can_give_items(int level)
  240. {
  241. return( level < battle_config.gm_cant_drop_min_lv || level > battle_config.gm_cant_drop_max_lv );
  242. }
  243. /*==========================================
  244. * prepares character for saving.
  245. *------------------------------------------*/
  246. int pc_makesavestatus(struct map_session_data *sd)
  247. {
  248. nullpo_retr(0, sd);
  249. if(!battle_config.save_clothcolor)
  250. sd->status.clothes_color=0;
  251. //Only copy the Cart/Peco/Falcon options, the rest are handled via
  252. //status change load/saving. [Skotlex]
  253. sd->status.option = sd->sc.option&(OPTION_CART|OPTION_FALCON|OPTION_RIDING);
  254. if (sd->sc.data[SC_JAILED])
  255. { //When Jailed, do not move last point.
  256. if(pc_isdead(sd)){
  257. pc_setrestartvalue(sd,0);
  258. } else {
  259. sd->status.hp = sd->battle_status.hp;
  260. sd->status.sp = sd->battle_status.sp;
  261. }
  262. sd->status.last_point.map = sd->mapindex;
  263. sd->status.last_point.x = sd->bl.x;
  264. sd->status.last_point.y = sd->bl.y;
  265. return 0;
  266. }
  267. if(pc_isdead(sd)){
  268. pc_setrestartvalue(sd,0);
  269. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  270. } else {
  271. sd->status.hp = sd->battle_status.hp;
  272. sd->status.sp = sd->battle_status.sp;
  273. sd->status.last_point.map = sd->mapindex;
  274. sd->status.last_point.x = sd->bl.x;
  275. sd->status.last_point.y = sd->bl.y;
  276. }
  277. if(map[sd->bl.m].flag.nosave){
  278. struct map_data *m=&map[sd->bl.m];
  279. if(m->save.map)
  280. memcpy(&sd->status.last_point,&m->save,sizeof(sd->status.last_point));
  281. else
  282. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  283. }
  284. return 0;
  285. }
  286. /*==========================================
  287. * 接?暫フ初期化
  288. *------------------------------------------*/
  289. int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id, int login_id1, unsigned int client_tick, int sex, int fd)
  290. {
  291. nullpo_retr(0, sd);
  292. sd->bl.id = account_id;
  293. sd->status.account_id = account_id;
  294. sd->status.char_id = char_id;
  295. sd->status.sex = sex;
  296. sd->login_id1 = login_id1;
  297. sd->login_id2 = 0; // at this point, we can not know the value :(
  298. sd->client_tick = client_tick;
  299. sd->state.active = 0; //to be set to 1 after player is fully authed and loaded.
  300. sd->bl.type = BL_PC;
  301. sd->canlog_tick = gettick();
  302. //Required to prevent homunculus copuing a base speed of 0.
  303. sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
  304. return 0;
  305. }
  306. int pc_equippoint(struct map_session_data *sd,int n)
  307. {
  308. int ep = 0;
  309. nullpo_retr(0, sd);
  310. if(!sd->inventory_data[n])
  311. return 0;
  312. if (!itemdb_isequip2(sd->inventory_data[n]))
  313. return 0; //Not equippable by players.
  314. ep = sd->inventory_data[n]->equip;
  315. if(sd->inventory_data[n]->look == W_DAGGER ||
  316. sd->inventory_data[n]->look == W_1HSWORD ||
  317. sd->inventory_data[n]->look == W_1HAXE) {
  318. if(ep == EQP_HAND_R && (pc_checkskill(sd,AS_LEFT) > 0 || (sd->class_&MAPID_UPPERMASK) == MAPID_ASSASSIN))
  319. return EQP_ARMS;
  320. }
  321. return ep;
  322. }
  323. int pc_setinventorydata(struct map_session_data *sd)
  324. {
  325. int i,id;
  326. nullpo_retr(0, sd);
  327. for(i=0;i<MAX_INVENTORY;i++) {
  328. id = sd->status.inventory[i].nameid;
  329. sd->inventory_data[i] = id?itemdb_search(id):NULL;
  330. }
  331. return 0;
  332. }
  333. int pc_calcweapontype(struct map_session_data *sd)
  334. {
  335. nullpo_retr(0, sd);
  336. // single-hand
  337. if(sd->weapontype2 == W_FIST) {
  338. sd->status.weapon = sd->weapontype1;
  339. return 1;
  340. }
  341. if(sd->weapontype1 == W_FIST) {
  342. sd->status.weapon = sd->weapontype2;
  343. return 1;
  344. }
  345. // dual-wield
  346. sd->status.weapon = 0;
  347. switch (sd->weapontype1){
  348. case W_DAGGER:
  349. switch (sd->weapontype2) {
  350. case W_DAGGER: sd->status.weapon = W_DOUBLE_DD; break;
  351. case W_1HSWORD: sd->status.weapon = W_DOUBLE_DS; break;
  352. case W_1HAXE: sd->status.weapon = W_DOUBLE_DA; break;
  353. }
  354. break;
  355. case W_1HSWORD:
  356. switch (sd->weapontype2) {
  357. case W_DAGGER: sd->status.weapon = W_DOUBLE_DS; break;
  358. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SS; break;
  359. case W_1HAXE: sd->status.weapon = W_DOUBLE_SA; break;
  360. }
  361. break;
  362. case W_1HAXE:
  363. switch (sd->weapontype2) {
  364. case W_DAGGER: sd->status.weapon = W_DOUBLE_DA; break;
  365. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SA; break;
  366. case W_1HAXE: sd->status.weapon = W_DOUBLE_AA; break;
  367. }
  368. }
  369. // unknown, default to right hand type
  370. if (!sd->status.weapon)
  371. sd->status.weapon = sd->weapontype1;
  372. return 2;
  373. }
  374. int pc_setequipindex(struct map_session_data *sd)
  375. {
  376. int i,j;
  377. nullpo_retr(0, sd);
  378. for(i=0;i<EQI_MAX;i++)
  379. sd->equip_index[i] = -1;
  380. for(i=0;i<MAX_INVENTORY;i++) {
  381. if(sd->status.inventory[i].nameid <= 0)
  382. continue;
  383. if(sd->status.inventory[i].equip) {
  384. for(j=0;j<EQI_MAX;j++)
  385. if(sd->status.inventory[i].equip & equip_pos[j])
  386. sd->equip_index[j] = i;
  387. if(sd->status.inventory[i].equip & EQP_HAND_R)
  388. {
  389. if(sd->inventory_data[i])
  390. sd->weapontype1 = sd->inventory_data[i]->look;
  391. else
  392. sd->weapontype1 = 0;
  393. }
  394. if( sd->status.inventory[i].equip & EQP_HAND_L )
  395. {
  396. if( sd->inventory_data[i] && sd->inventory_data[i]->type == 4 )
  397. sd->weapontype2 = sd->inventory_data[i]->look;
  398. else
  399. sd->weapontype2 = 0;
  400. }
  401. }
  402. }
  403. pc_calcweapontype(sd);
  404. return 0;
  405. }
  406. static int pc_isAllowedCardOn(struct map_session_data *sd,int s,int eqindex,int flag)
  407. {
  408. int i;
  409. struct item *item = &sd->status.inventory[eqindex];
  410. struct item_data *data;
  411. //Crafted/made/hatched items.
  412. if (itemdb_isspecial(item->card[0]))
  413. return 1;
  414. ARR_FIND( 0, s, i, item->card[i] && (data = itemdb_exists(item->card[i])) != NULL && data->flag.no_equip&flag );
  415. return( i < s ) ? 0 : 1;
  416. }
  417. bool pc_isequipped(struct map_session_data *sd, int nameid)
  418. {
  419. int i, j, index;
  420. for( i = 0; i < EQI_MAX; i++ )
  421. {
  422. index = sd->equip_index[i];
  423. if( index < 0 ) continue;
  424. if( i == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue;
  425. if( i == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index ) continue;
  426. if( i == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index) ) continue;
  427. if( !sd->inventory_data[index] ) continue;
  428. if( sd->inventory_data[index]->nameid == nameid )
  429. return true;
  430. for( j = 0; j < sd->inventory_data[index]->slot; j++ )
  431. if( sd->status.inventory[index].card[j] == nameid )
  432. return true;
  433. }
  434. return false;
  435. }
  436. bool pc_can_Adopt(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd )
  437. {
  438. if( !p1_sd || !p2_sd || !b_sd )
  439. return false;
  440. if( b_sd->status.father || b_sd->status.mother || b_sd->adopt_invite )
  441. return false; // already adopted baby / in adopt request
  442. if( !p1_sd->status.partner_id || !p1_sd->status.party_id || p1_sd->status.party_id != b_sd->status.party_id )
  443. return false; // You need to be married and in party with baby to adopt
  444. if( p1_sd->status.partner_id != p2_sd->status.char_id || p2_sd->status.partner_id != p1_sd->status.char_id )
  445. return false; // Not married, wrong married
  446. if( p2_sd->status.party_id != p1_sd->status.party_id )
  447. return false; // Both parents need to be in the same party
  448. // Parents need to have their ring equipped
  449. if( !pc_isequipped(p1_sd, WEDDING_RING_M) && !pc_isequipped(p1_sd, WEDDING_RING_F) )
  450. return false;
  451. if( !pc_isequipped(p2_sd, WEDDING_RING_M) && !pc_isequipped(p2_sd, WEDDING_RING_F) )
  452. return false;
  453. // Already adopted a baby
  454. if( p1_sd->status.child || p2_sd->status.child ) {
  455. clif_Adopt_reply(p1_sd, 0);
  456. return false;
  457. }
  458. // Parents need at least lvl 70 to adopt
  459. if( p1_sd->status.base_level < 70 || p2_sd->status.base_level < 70 ) {
  460. clif_Adopt_reply(p1_sd, 1);
  461. return false;
  462. }
  463. if( b_sd->status.partner_id ) {
  464. clif_Adopt_reply(p1_sd, 2);
  465. return false;
  466. }
  467. if( !(b_sd->status.class_ >= JOB_NOVICE && b_sd->status.class_ <= JOB_THIEF) )
  468. return false;
  469. return true;
  470. }
  471. /*==========================================
  472. * Adoption Process
  473. *------------------------------------------*/
  474. bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
  475. {
  476. int job, joblevel;
  477. unsigned int jobexp;
  478. if( !pc_can_Adopt(p1_sd, p2_sd, b_sd) )
  479. return false;
  480. // Preserve current job levels and progress
  481. joblevel = b_sd->status.job_level;
  482. jobexp = b_sd->status.job_exp;
  483. job = pc_mapid2jobid(b_sd->class_|JOBL_BABY, b_sd->status.sex);
  484. if( job != -1 && !pc_jobchange(b_sd, job, 0) )
  485. { // Success, proceed to configure parents and baby skills
  486. p1_sd->status.child = b_sd->status.char_id;
  487. p2_sd->status.child = b_sd->status.char_id;
  488. b_sd->status.father = p1_sd->status.char_id;
  489. b_sd->status.mother = p2_sd->status.char_id;
  490. // Restore progress
  491. b_sd->status.job_level = joblevel;
  492. clif_updatestatus(b_sd, SP_JOBLEVEL);
  493. b_sd->status.job_exp = jobexp;
  494. clif_updatestatus(b_sd, SP_JOBEXP);
  495. // Baby Skills
  496. pc_skill(b_sd, WE_BABY, 1, 0);
  497. pc_skill(b_sd, WE_CALLPARENT, 1, 0);
  498. // Parents Skills
  499. pc_skill(p1_sd, WE_CALLBABY, 1, 0);
  500. pc_skill(p2_sd, WE_CALLBABY, 1, 0);
  501. return true;
  502. }
  503. return false; // Job Change Fail
  504. }
  505. int pc_isequip(struct map_session_data *sd,int n)
  506. {
  507. struct item_data *item;
  508. //?生や養子の場合の元の職業を算出する
  509. nullpo_retr(0, sd);
  510. item = sd->inventory_data[n];
  511. if( battle_config.gm_allequip>0 && pc_isGM(sd)>=battle_config.gm_allequip )
  512. return 1;
  513. if(item == NULL)
  514. return 0;
  515. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  516. return 0;
  517. if(item->sex != 2 && sd->status.sex != item->sex)
  518. return 0;
  519. if(map[sd->bl.m].flag.pvp && ((item->flag.no_equip&1) || !pc_isAllowedCardOn(sd,item->slot,n,1)))
  520. return 0;
  521. if(map_flag_gvg(sd->bl.m) && ((item->flag.no_equip&2) || !pc_isAllowedCardOn(sd,item->slot,n,2)))
  522. return 0;
  523. if(map[sd->bl.m].flag.restricted)
  524. {
  525. int flag =map[sd->bl.m].zone;
  526. if (item->flag.no_equip&flag || !pc_isAllowedCardOn(sd,item->slot,n,flag))
  527. return 0;
  528. }
  529. if (sd->sc.count) {
  530. if(item->equip & EQP_ARMS && item->type == IT_WEAPON && sd->sc.data[SC_STRIPWEAPON]) // Also works with left-hand weapons [DracoRPG]
  531. return 0;
  532. if(item->equip & EQP_SHIELD && item->type == IT_ARMOR && sd->sc.data[SC_STRIPSHIELD])
  533. return 0;
  534. if(item->equip & EQP_ARMOR && sd->sc.data[SC_STRIPARMOR])
  535. return 0;
  536. if(item->equip & EQP_HELM && sd->sc.data[SC_STRIPHELM])
  537. return 0;
  538. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_SUPERNOVICE) {
  539. //Spirit of Super Novice equip bonuses. [Skotlex]
  540. if (sd->status.base_level > 90 && item->equip & EQP_HELM)
  541. return 1; //Can equip all helms
  542. if (sd->status.base_level > 96 && item->equip & EQP_ARMS && item->type == IT_WEAPON)
  543. switch(item->look) { //In weapons, the look determines type of weapon.
  544. case W_DAGGER: //Level 4 Knives are equippable.. this means all knives, I'd guess?
  545. case W_1HSWORD: //All 1H swords
  546. case W_1HAXE: //All 1H Axes
  547. case W_MACE: //All 1H Maces
  548. case W_STAFF: //All 1H Staves
  549. return 1;
  550. }
  551. }
  552. }
  553. //Not equipable by class. [Skotlex]
  554. if (!(1<<(sd->class_&MAPID_BASEMASK)&item->class_base[(sd->class_&JOBL_2_1)?1:((sd->class_&JOBL_2_2)?2:0)]))
  555. return 0;
  556. //Not equipable by upper class. [Skotlex]
  557. if(!(1<<((sd->class_&JOBL_UPPER)?1:((sd->class_&JOBL_BABY)?2:0))&item->class_upper))
  558. return 0;
  559. return 1;
  560. }
  561. /*==========================================
  562. * session idに問題無し
  563. * char鯖から送られてきたステ?タスを設定
  564. *------------------------------------------*/
  565. bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_time, int gmlevel, struct mmo_charstatus *st)
  566. {
  567. int i;
  568. unsigned long tick = gettick();
  569. uint32 ip = session[sd->fd]->client_addr;
  570. sd->login_id2 = login_id2;
  571. sd->gmlevel = gmlevel;
  572. memcpy(&sd->status, st, sizeof(*st));
  573. if (st->sex != sd->status.sex) {
  574. clif_authfail_fd(sd->fd, 0);
  575. return false;
  576. }
  577. //Set the map-server used job id. [Skotlex]
  578. i = pc_jobid2mapid(sd->status.class_);
  579. if (i == -1) { //Invalid class?
  580. ShowError("pc_authok: Invalid class %d for player %s (%d:%d). Class was changed to novice.\n", sd->status.class_, sd->status.name, sd->status.account_id, sd->status.char_id);
  581. sd->status.class_ = JOB_NOVICE;
  582. sd->class_ = MAPID_NOVICE;
  583. } else
  584. sd->class_ = i;
  585. //Initializations to null/0 unneeded since map_session_data was filled with 0 upon allocation.
  586. if(!sd->status.hp) pc_setdead(sd);
  587. sd->state.connect_new = 1;
  588. sd->followtimer = INVALID_TIMER; // [MouseJstr]
  589. sd->invincible_timer = INVALID_TIMER;
  590. sd->npc_timer_id = -1;
  591. sd->pvp_timer = INVALID_TIMER;
  592. sd->canuseitem_tick = tick;
  593. sd->cantalk_tick = tick;
  594. sd->cansendmail_tick = tick;
  595. for(i = 0; i < MAX_SKILL_LEVEL; i++)
  596. sd->spirit_timer[i] = -1;
  597. if (battle_config.item_auto_get)
  598. sd->state.autoloot = 10000;
  599. if (battle_config.disp_experience)
  600. sd->state.showexp = 1;
  601. if (battle_config.disp_zeny)
  602. sd->state.showzeny = 1;
  603. if (!(battle_config.display_skill_fail&2))
  604. sd->state.showdelay = 1;
  605. // アイテムチェック
  606. pc_setinventorydata(sd);
  607. pc_checkitem(sd);
  608. status_change_init(&sd->bl);
  609. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) && (pc_isGM(sd) >= get_atcommand_level(atcommand_hide)))
  610. sd->status.option &= (OPTION_MASK | OPTION_INVISIBLE);
  611. else
  612. sd->status.option &= OPTION_MASK;
  613. sd->sc.option = sd->status.option; //This is the actual option used in battle.
  614. //Set here because we need the inventory data for weapon sprite parsing.
  615. status_set_viewdata(&sd->bl, sd->status.class_);
  616. unit_dataset(&sd->bl);
  617. sd->guild_x = -1;
  618. sd->guild_y = -1;
  619. // イベント?係の初期化
  620. for(i = 0; i < MAX_EVENTTIMER; i++)
  621. sd->eventtimer[i] = -1;
  622. for (i = 0; i < 3; i++)
  623. sd->hate_mob[i] = -1;
  624. // 位置の設定
  625. if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, 0)) != 0) {
  626. ShowError ("Last_point_map %s - id %d not found (error code %d)\n", mapindex_id2name(sd->status.last_point.map), sd->status.last_point.map, i);
  627. // try warping to a default map instead (church graveyard)
  628. if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, 0) != 0) {
  629. // if we fail again
  630. clif_authfail_fd(sd->fd, 0);
  631. return false;
  632. }
  633. }
  634. clif_authok(sd);
  635. //Prevent S. Novices from getting the no-death bonus just yet. [Skotlex]
  636. sd->die_counter=-1;
  637. //display login notice
  638. if( sd->gmlevel >= battle_config.lowest_gm_level )
  639. ShowInfo("GM '"CL_WHITE"%s"CL_RESET"' logged in."
  640. " (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"',"
  641. " Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%d.%d.%d.%d"CL_RESET"',"
  642. " GM Level '"CL_WHITE"%d"CL_RESET"').\n",
  643. sd->status.name, sd->status.account_id, sd->status.char_id,
  644. sd->packet_ver, CONVIP(ip), sd->gmlevel);
  645. else
  646. ShowInfo("'"CL_WHITE"%s"CL_RESET"' logged in."
  647. " (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"',"
  648. " Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%d.%d.%d.%d"CL_RESET"').\n",
  649. sd->status.name, sd->status.account_id, sd->status.char_id,
  650. sd->packet_ver, CONVIP(ip));
  651. // Send friends list
  652. clif_friendslist_send(sd);
  653. if (battle_config.display_version == 1){
  654. char buf[256];
  655. sprintf(buf, "eAthena SVN version: %s", get_svn_revision());
  656. clif_displaymessage(sd->fd, buf);
  657. }
  658. // Message of the Day [Valaris]
  659. for(i=0; motd_text[i][0] && i < MOTD_LINE_SIZE; i++) {
  660. if (battle_config.motd_type)
  661. clif_disp_onlyself(sd,motd_text[i],strlen(motd_text[i]));
  662. else
  663. clif_displaymessage(sd->fd, motd_text[i]);
  664. }
  665. // message of the limited time of the account
  666. if (expiration_time != 0) { // don't display if it's unlimited or unknow value
  667. char tmpstr[1024];
  668. strftime(tmpstr, sizeof(tmpstr) - 1, msg_txt(501), localtime(&expiration_time)); // "Your account time limit is: %d-%m-%Y %H:%M:%S."
  669. clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
  670. }
  671. //Night message
  672. if (night_flag)
  673. {
  674. char tmpstr[1024];
  675. strcpy(tmpstr, msg_txt(500)); // Actually, it's the night...
  676. clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
  677. }
  678. // Request all registries (auth is considered completed whence they arrive)
  679. intif_request_registry(sd,7);
  680. return true;
  681. }
  682. /*==========================================
  683. * Closes a connection because it failed to be authenticated from the char server.
  684. *------------------------------------------*/
  685. void pc_authfail(struct map_session_data *sd)
  686. {
  687. clif_authfail_fd(sd->fd, 0);
  688. return;
  689. }
  690. //Attempts to set a mob.
  691. int pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl)
  692. {
  693. int class_;
  694. if (!sd || !bl || pos < 0 || pos > 2)
  695. return 0;
  696. if (sd->hate_mob[pos] != -1)
  697. { //Can't change hate targets.
  698. clif_hate_info(sd, pos, sd->hate_mob[pos], 0); //Display current
  699. return 0;
  700. }
  701. class_ = status_get_class(bl);
  702. if (!pcdb_checkid(class_)) {
  703. unsigned int max_hp = status_get_max_hp(bl);
  704. if ((pos == 1 && max_hp < 6000) || (pos == 2 && max_hp < 20000))
  705. return 0;
  706. if (pos != status_get_size(bl))
  707. return 0; //Wrong size
  708. }
  709. sd->hate_mob[pos] = class_;
  710. pc_setglobalreg(sd,sg_info[pos].hate_var,class_+1);
  711. clif_hate_info(sd, pos, class_, 1);
  712. return 1;
  713. }
  714. /*==========================================
  715. * Invoked once after the char/account/account2 registry variables are received. [Skotlex]
  716. *------------------------------------------*/
  717. int pc_reg_received(struct map_session_data *sd)
  718. {
  719. int i,j;
  720. sd->change_level = pc_readglobalreg(sd,"jobchange_level");
  721. sd->die_counter = pc_readglobalreg(sd,"PC_DIE_COUNTER");
  722. // Cash shop
  723. sd->cashPoints = pc_readaccountreg(sd,"#CASHPOINTS");
  724. sd->kafraPoints = pc_readaccountreg(sd,"#KAFRAPOINTS");
  725. if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON )
  726. { //Better check for class rather than skill to prevent "skill resets" from unsetting this
  727. sd->mission_mobid = pc_readglobalreg(sd,"TK_MISSION_ID");
  728. sd->mission_count = pc_readglobalreg(sd,"TK_MISSION_COUNT");
  729. }
  730. //SG map and mob read [Komurka]
  731. for(i=0;i<3;i++) //for now - someone need to make reading from txt/sql
  732. {
  733. if ((j = pc_readglobalreg(sd,sg_info[i].feel_var))!=0) {
  734. sd->feel_map[i].index = j;
  735. sd->feel_map[i].m = map_mapindex2mapid(j);
  736. } else {
  737. sd->feel_map[i].index = 0;
  738. sd->feel_map[i].m = -1;
  739. }
  740. sd->hate_mob[i] = pc_readglobalreg(sd,sg_info[i].hate_var)-1;
  741. }
  742. if ((i = pc_checkskill(sd,RG_PLAGIARISM)) > 0) {
  743. sd->cloneskill_id = pc_readglobalreg(sd,"CLONE_SKILL");
  744. if (sd->cloneskill_id > 0) {
  745. sd->status.skill[sd->cloneskill_id].id = sd->cloneskill_id;
  746. sd->status.skill[sd->cloneskill_id].lv = pc_readglobalreg(sd,"CLONE_SKILL_LV");
  747. if (i < sd->status.skill[sd->cloneskill_id].lv)
  748. sd->status.skill[sd->cloneskill_id].lv = i;
  749. sd->status.skill[sd->cloneskill_id].flag = 13; //cloneskill flag
  750. }
  751. }
  752. //Weird... maybe registries were reloaded?
  753. if (sd->state.active)
  754. return 0;
  755. sd->state.active = 1;
  756. if (sd->status.party_id)
  757. party_member_joined(sd);
  758. if (sd->status.guild_id)
  759. guild_member_joined(sd);
  760. // pet
  761. if (sd->status.pet_id > 0)
  762. intif_request_petdata(sd->status.account_id, sd->status.char_id, sd->status.pet_id);
  763. // Homunculus [albator]
  764. if( sd->status.hom_id > 0 )
  765. intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id);
  766. if( sd->status.mer_id > 0 )
  767. intif_mercenary_request(sd->status.mer_id, sd->status.char_id);
  768. map_addiddb(&sd->bl);
  769. map_delnickdb(sd->status.char_id, sd->status.name);
  770. if (!chrif_auth_finished(sd))
  771. ShowError("pc_reg_received: Failed to properly remove player %d:%d from logging db!\n", sd->status.account_id, sd->status.char_id);
  772. status_calc_pc(sd,1);
  773. chrif_scdata_request(sd->status.account_id, sd->status.char_id);
  774. #ifndef TXT_ONLY
  775. intif_Mail_requestinbox(sd->status.char_id, 0); // MAIL SYSTEM - Request Mail Inbox
  776. intif_request_questlog(sd);
  777. #endif
  778. if (!sd->state.connect_new && sd->fd)
  779. { //Character already loaded map! Gotta trigger LoadEndAck manually.
  780. sd->state.connect_new = 1;
  781. clif_parse_LoadEndAck(sd->fd, sd);
  782. }
  783. return 1;
  784. }
  785. static int pc_calc_skillpoint(struct map_session_data* sd)
  786. {
  787. int i,skill,inf2,skill_point=0;
  788. nullpo_retr(0, sd);
  789. for(i=1;i<MAX_SKILL;i++){
  790. if( (skill = pc_checkskill(sd,i)) > 0) {
  791. inf2 = skill_get_inf2(i);
  792. if((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  793. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) //Do not count wedding/link skills. [Skotlex]
  794. ) {
  795. if(!sd->status.skill[i].flag)
  796. skill_point += skill;
  797. else if(sd->status.skill[i].flag > 2 && sd->status.skill[i].flag != 13) {
  798. skill_point += (sd->status.skill[i].flag - 2);
  799. }
  800. }
  801. }
  802. }
  803. return skill_point;
  804. }
  805. /*==========================================
  806. * ?えられるスキルの計算
  807. *------------------------------------------*/
  808. int pc_calc_skilltree(struct map_session_data *sd)
  809. {
  810. int i,id=0,flag;
  811. int c=0;
  812. nullpo_retr(0, sd);
  813. i = pc_calc_skilltree_normalize_job(sd);
  814. c = pc_mapid2jobid(i, sd->status.sex);
  815. if( c == -1 )
  816. { //Unable to normalize job??
  817. ShowError("pc_calc_skilltree: Unable to normalize job %d for character %s (%d:%d)\n", i, sd->status.name, sd->status.account_id, sd->status.char_id);
  818. return 1;
  819. }
  820. c = pc_class2idx(c);
  821. for( i = 0; i < MAX_SKILL; i++ )
  822. {
  823. if( sd->status.skill[i].flag != 13 ) //Don't touch plagiarized skills
  824. sd->status.skill[i].id = 0; //First clear skills.
  825. }
  826. for( i = 0; i < MAX_SKILL; i++ )
  827. {
  828. if( sd->status.skill[i].flag && sd->status.skill[i].flag != 13 )
  829. { // Restore original level of skills after deleting earned skills.
  830. sd->status.skill[i].lv = (sd->status.skill[i].flag == 1)?0:sd->status.skill[i].flag-2;
  831. sd->status.skill[i].flag = 0;
  832. }
  833. if( sd->sc.count && sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_BARDDANCER && i >= DC_HUMMING && i<= DC_SERVICEFORYOU )
  834. { //Enable Bard/Dancer spirit linked skills.
  835. if( sd->status.sex )
  836. { //Link dancer skills to bard.
  837. sd->status.skill[i].id = i;
  838. sd->status.skill[i].lv = sd->status.skill[i-8].lv; // Set the level to the same as the linking skill
  839. sd->status.skill[i].flag = 1; // Tag it as a non-savable, non-uppable, bonus skill
  840. }
  841. else
  842. { //Link bard skills to dancer.
  843. sd->status.skill[i-8].id = i - 8;
  844. sd->status.skill[i-8].lv = sd->status.skill[i].lv; // Set the level to the same as the linking skill
  845. sd->status.skill[i-8].flag = 1; // Tag it as a non-savable, non-uppable, bonus skill
  846. }
  847. }
  848. }
  849. if( battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill )
  850. {
  851. for( i = 0; i < MAX_SKILL; i++ )
  852. {
  853. if( skill_get_inf2(i)&(INF2_NPC_SKILL|INF2_GUILD_SKILL) )
  854. continue; //Only skills you can't have are npc/guild ones
  855. if( skill_get_max(i) > 0 )
  856. sd->status.skill[i].id = i;
  857. }
  858. return 0;
  859. }
  860. do {
  861. flag = 0;
  862. for( i = 0; i < MAX_SKILL_TREE && (id = skill_tree[c][i].id) > 0; i++ )
  863. {
  864. int j, f, k, inf2;
  865. if( sd->status.skill[id].id )
  866. continue; //Skill already known.
  867. f = 1;
  868. if(!battle_config.skillfree) {
  869. for(j = 0; j < 5; j++) {
  870. if((k=skill_tree[c][i].need[j].id))
  871. {
  872. if (!sd->status.skill[k].id || sd->status.skill[k].flag == 13)
  873. k = 0; //Not learned.
  874. else if (sd->status.skill[k].flag) //Real lerned level
  875. k = sd->status.skill[skill_tree[c][i].need[j].id].flag-2;
  876. else
  877. k = pc_checkskill(sd,k);
  878. if (k < skill_tree[c][i].need[j].lv)
  879. {
  880. f = 0;
  881. break;
  882. }
  883. }
  884. }
  885. if( sd->status.job_level < skill_tree[c][i].joblv )
  886. f = 0; // job level requirement wasn't satisfied
  887. }
  888. if( f )
  889. {
  890. inf2 = skill_get_inf2(id);
  891. if(!sd->status.skill[id].lv && (
  892. (inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  893. inf2&INF2_WEDDING_SKILL ||
  894. (inf2&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
  895. ))
  896. continue; //Cannot be learned via normal means. Note this check DOES allows raising already known skills.
  897. sd->status.skill[id].id = id;
  898. if(inf2&INF2_SPIRIT_SKILL)
  899. { //Spirit skills cannot be learned, they will only show up on your tree when you get buffed.
  900. sd->status.skill[id].lv = 1; // need to manually specify a skill level
  901. sd->status.skill[id].flag = 1; //So it is not saved, and tagged as a "bonus" skill.
  902. }
  903. flag = 1; // skill list has changed, perform another pass
  904. }
  905. }
  906. } while(flag);
  907. //
  908. if( c > 0 && (sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && sd->status.skill_point == 0 && pc_famerank(sd->status.char_id, MAPID_TAEKWON) )
  909. {
  910. /* Taekwon Ranger Bonus Skill Tree
  911. ============================================
  912. - Grant All Taekwon Tree, but only as Bonus Skills in case they drop from ranking.
  913. - (c > 0) to avoid grant Novice Skill Tree in case of Skill Reset (need more logic)
  914. - (sd->status.skill_point == 0) to wait until all skill points are asigned to avoid problems with Job Change quest. */
  915. for( i = 0; i < MAX_SKILL_TREE && (id = skill_tree[c][i].id) > 0; i++ )
  916. {
  917. if( (skill_get_inf2(id)&(INF2_QUEST_SKILL|INF2_WEDDING_SKILL)) )
  918. continue; //Do not include Quest/Wedding skills.
  919. if( sd->status.skill[id].id == 0 )
  920. {
  921. sd->status.skill[id].id = id;
  922. sd->status.skill[id].flag = 1; // So it is not saved, and tagged as a "bonus" skill.
  923. }
  924. else
  925. sd->status.skill[id].flag = sd->status.skill[id].lv+2;
  926. sd->status.skill[id].lv = skill_tree_get_max(id, sd->status.class_);
  927. }
  928. }
  929. return 0;
  930. }
  931. //Checks if you can learn a new skill after having leveled up a skill.
  932. static void pc_check_skilltree(struct map_session_data *sd, int skill)
  933. {
  934. int i,id=0,flag;
  935. int c=0;
  936. if(battle_config.skillfree)
  937. return; //Function serves no purpose if this is set
  938. i = pc_calc_skilltree_normalize_job(sd);
  939. c = pc_mapid2jobid(i, sd->status.sex);
  940. if (c == -1) { //Unable to normalize job??
  941. ShowError("pc_check_skilltree: Unable to normalize job %d for character %s (%d:%d)\n", i, sd->status.name, sd->status.account_id, sd->status.char_id);
  942. return;
  943. }
  944. c = pc_class2idx(c);
  945. do {
  946. flag = 0;
  947. for( i = 0; i < MAX_SKILL_TREE && (id=skill_tree[c][i].id)>0; i++ )
  948. {
  949. int j, f = 1, k;
  950. if( sd->status.skill[id].id ) //Already learned
  951. continue;
  952. for( j = 0; j < 5; j++ )
  953. {
  954. if( (k = skill_tree[c][i].need[j].id) )
  955. {
  956. if( !sd->status.skill[k].id || sd->status.skill[k].flag == 13 )
  957. k = 0; //Not learned.
  958. else if( sd->status.skill[k].flag ) //Real lerned level
  959. k = sd->status.skill[skill_tree[c][i].need[j].id].flag - 2;
  960. else
  961. k = pc_checkskill(sd,k);
  962. if( k < skill_tree[c][i].need[j].lv )
  963. {
  964. f = 0;
  965. break;
  966. }
  967. }
  968. }
  969. if( !f )
  970. continue;
  971. if( sd->status.job_level < skill_tree[c][i].joblv )
  972. continue;
  973. j = skill_get_inf2(id);
  974. if( !sd->status.skill[id].lv && (
  975. (j&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  976. j&INF2_WEDDING_SKILL ||
  977. (j&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
  978. ) )
  979. continue; //Cannot be learned via normal means.
  980. sd->status.skill[id].id = id;
  981. flag = 1;
  982. }
  983. } while(flag);
  984. }
  985. // Make sure all the skills are in the correct condition
  986. // before persisting to the backend.. [MouseJstr]
  987. int pc_clean_skilltree(struct map_session_data *sd)
  988. {
  989. int i;
  990. for (i = 0; i < MAX_SKILL; i++){
  991. if (sd->status.skill[i].flag == 13 || sd->status.skill[i].flag == 1)
  992. {
  993. sd->status.skill[i].id = 0;
  994. sd->status.skill[i].lv = 0;
  995. sd->status.skill[i].flag = 0;
  996. } else if (sd->status.skill[i].flag){
  997. sd->status.skill[i].lv = sd->status.skill[i].flag-2;
  998. sd->status.skill[i].flag = 0;
  999. }
  1000. }
  1001. return 0;
  1002. }
  1003. int pc_calc_skilltree_normalize_job(struct map_session_data *sd)
  1004. {
  1005. int skill_point;
  1006. int c = sd->class_;
  1007. if (!battle_config.skillup_limit)
  1008. return c;
  1009. skill_point = pc_calc_skillpoint(sd);
  1010. if(pc_checkskill(sd, NV_BASIC) < 9) //Consider Novice Tree when you don't have NV_BASIC maxed.
  1011. c = MAPID_NOVICE;
  1012. else
  1013. //Do not send S. Novices to first class (Novice)
  1014. if ((sd->class_&JOBL_2) && (sd->class_&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE &&
  1015. sd->status.skill_point >= (int)sd->status.job_level &&
  1016. ((sd->change_level > 0 && skill_point < sd->change_level+8) || skill_point < 58)) {
  1017. //Send it to first class.
  1018. c &= MAPID_BASEMASK;
  1019. }
  1020. if (sd->class_&JOBL_UPPER) //Convert to Upper
  1021. c |= JOBL_UPPER;
  1022. else if (sd->class_&JOBL_BABY) //Convert to Baby
  1023. c |= JOBL_BABY;
  1024. return c;
  1025. }
  1026. /*==========================================
  1027. * Updates the weight status
  1028. *------------------------------------------
  1029. * 1: overweight 50%
  1030. * 2: overweight 90%
  1031. * It's assumed that SC_WEIGHT50 and SC_WEIGHT90 are only started/stopped here.
  1032. */
  1033. int pc_updateweightstatus(struct map_session_data *sd)
  1034. {
  1035. int old_overweight;
  1036. int new_overweight;
  1037. nullpo_retr(1, sd);
  1038. old_overweight = (sd->sc.data[SC_WEIGHT90]) ? 2 : (sd->sc.data[SC_WEIGHT50]) ? 1 : 0;
  1039. new_overweight = (pc_is90overweight(sd)) ? 2 : (pc_is50overweight(sd)) ? 1 : 0;
  1040. if( old_overweight == new_overweight )
  1041. return 0; // no change
  1042. // stop old status change
  1043. if( old_overweight == 1 )
  1044. status_change_end(&sd->bl, SC_WEIGHT50, -1);
  1045. else if( old_overweight == 2 )
  1046. status_change_end(&sd->bl, SC_WEIGHT90, -1);
  1047. // start new status change
  1048. if( new_overweight == 1 )
  1049. sc_start(&sd->bl, SC_WEIGHT50, 100, 0, 0);
  1050. else if( new_overweight == 2 )
  1051. sc_start(&sd->bl, SC_WEIGHT90, 100, 0, 0);
  1052. // update overweight status
  1053. sd->regen.state.overweight = new_overweight;
  1054. return 0;
  1055. }
  1056. int pc_disguise(struct map_session_data *sd, int class_)
  1057. {
  1058. if (!class_ && !sd->disguise)
  1059. return 0;
  1060. if (class_ && sd->disguise == class_)
  1061. return 0;
  1062. if(sd->sc.option&OPTION_INVISIBLE)
  1063. { //Character is invisible. Stealth class-change. [Skotlex]
  1064. sd->disguise = class_; //viewdata is set on uncloaking.
  1065. return 2;
  1066. }
  1067. if (sd->bl.prev != NULL) {
  1068. pc_stop_walking(sd, 0);
  1069. clif_clearunit_area(&sd->bl, 0);
  1070. }
  1071. if (!class_) {
  1072. sd->disguise = 0;
  1073. class_ = sd->status.class_;
  1074. } else
  1075. sd->disguise=class_;
  1076. status_set_viewdata(&sd->bl, class_);
  1077. clif_changeoption(&sd->bl);
  1078. if (sd->bl.prev != NULL) {
  1079. clif_spawn(&sd->bl);
  1080. if (class_ == sd->status.class_ && pc_iscarton(sd))
  1081. { //It seems the cart info is lost on undisguise.
  1082. clif_cartlist(sd);
  1083. clif_updatestatus(sd,SP_CARTINFO);
  1084. }
  1085. }
  1086. return 1;
  1087. }
  1088. int pc_autoscript_add(struct s_autoscript *scripts, int max, short rate, short flag, struct script_code *script)
  1089. {
  1090. int i;
  1091. ARR_FIND(0, max, i, scripts[i].script == NULL);
  1092. if (i == max) {
  1093. ShowWarning("pc_autoscript_bonus: Reached max (%d) number of autoscripts per character!\n", max);
  1094. return 0;
  1095. }
  1096. scripts[i].script = script;
  1097. scripts[i].rate = rate;
  1098. //Auto-update flag value.
  1099. if (!(flag&BF_RANGEMASK)) flag|=BF_SHORT|BF_LONG; //No range defined? Use both.
  1100. if (!(flag&BF_WEAPONMASK)) flag|=BF_WEAPON; //No attack type defined? Use weapon.
  1101. if (!(flag&BF_SKILLMASK)) {
  1102. if (flag&(BF_MAGIC|BF_MISC)) flag|=BF_SKILL; //These two would never trigger without BF_SKILL
  1103. if (flag&BF_WEAPON) flag|=BF_NORMAL;
  1104. }
  1105. scripts[i].flag = flag;
  1106. return 1;
  1107. }
  1108. void pc_autoscript_clear(struct s_autoscript *scripts, int max)
  1109. {
  1110. int i;
  1111. for (i = 0; i < max && scripts[i].script; i++)
  1112. script_free_code(scripts[i].script);
  1113. memset(scripts, 0, i*sizeof(struct s_autoscript));
  1114. }
  1115. static int pc_bonus_autospell_del(struct s_autospell* spell, int max, short id, short lv, short rate, short card_id)
  1116. {
  1117. int i, j;
  1118. for(i=max-1; i>=0 && !spell[i].id; i--);
  1119. if (i<0) return 0; //Nothing to substract from.
  1120. j = i;
  1121. for(; i>=0 && rate>0; i--)
  1122. {
  1123. if (spell[i].id != id || spell[i].lv != lv) continue;
  1124. if (rate >= spell[i].rate) {
  1125. rate-= spell[i].rate;
  1126. spell[i].rate = 0;
  1127. memmove(&spell[i], &spell[j], sizeof(struct s_autospell));
  1128. memset(&spell[j], 0, sizeof(struct s_autospell));
  1129. j--;
  1130. } else {
  1131. spell[i].rate -= rate;
  1132. rate = 0;
  1133. }
  1134. }
  1135. if (rate > 0 && ++j < max)
  1136. { //Tag this as "pending" autospell to remove.
  1137. spell[j].id = id;
  1138. spell[j].lv = lv;
  1139. spell[j].rate = -rate;
  1140. spell[j].card_id = card_id;
  1141. }
  1142. return rate;
  1143. }
  1144. static int pc_bonus_autospell(struct s_autospell *spell, int max, short id, short lv, short rate, short flag, short card_id)
  1145. {
  1146. int i;
  1147. if (rate < 0) return //Remove the autobonus.
  1148. pc_bonus_autospell_del(spell, max, id, lv, -rate, card_id);
  1149. for (i = 0; i < max && spell[i].id; i++) {
  1150. if ((spell[i].card_id == card_id || spell[i].rate < 0) &&
  1151. spell[i].id == id && spell[i].lv == lv)
  1152. {
  1153. if (!battle_config.autospell_stacking && spell[i].rate > 0)
  1154. return 0;
  1155. rate += spell[i].rate;
  1156. break;
  1157. }
  1158. }
  1159. if (i == max) {
  1160. ShowWarning("pc_bonus: Reached max (%d) number of autospells per character!\n", max);
  1161. return 0;
  1162. }
  1163. spell[i].id = id;
  1164. spell[i].lv = lv;
  1165. spell[i].rate = rate;
  1166. //Auto-update flag value.
  1167. if (!(flag&BF_RANGEMASK)) flag|=BF_SHORT|BF_LONG; //No range defined? Use both.
  1168. if (!(flag&BF_WEAPONMASK)) flag|=BF_WEAPON; //No attack type defined? Use weapon.
  1169. if (!(flag&BF_SKILLMASK)) {
  1170. if (flag&(BF_MAGIC|BF_MISC)) flag|=BF_SKILL; //These two would never trigger without BF_SKILL
  1171. if (flag&BF_WEAPON) flag|=BF_NORMAL; //By default autospells should only trigger on normal weapon attacks.
  1172. }
  1173. spell[i].flag|= flag;
  1174. spell[i].card_id = card_id;
  1175. return 1;
  1176. }
  1177. static int pc_bonus_addeff(struct s_addeffect* effect, int max, enum sc_type id, short rate, short arrow_rate, unsigned char flag)
  1178. {
  1179. int i;
  1180. if (!(flag&(ATF_SHORT|ATF_LONG)))
  1181. flag|=ATF_SHORT|ATF_LONG; //Default range: both
  1182. if (!(flag&(ATF_TARGET|ATF_SELF)))
  1183. flag|=ATF_TARGET; //Default target: enemy.
  1184. for (i = 0; i < max && effect[i].flag; i++) {
  1185. if (effect[i].id == id && effect[i].flag == flag)
  1186. {
  1187. effect[i].rate += rate;
  1188. effect[i].arrow_rate += arrow_rate;
  1189. return 1;
  1190. }
  1191. }
  1192. if (i == max) {
  1193. ShowWarning("pc_bonus: Reached max (%d) number of add effects per character!\n", max);
  1194. return 0;
  1195. }
  1196. effect[i].id = id;
  1197. effect[i].rate = rate;
  1198. effect[i].arrow_rate = arrow_rate;
  1199. effect[i].flag = flag;
  1200. return 1;
  1201. }
  1202. static int pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id, short group, int race, int rate)
  1203. {
  1204. int i;
  1205. //Apply config rate adjustment settings.
  1206. if (rate >= 0) { //Absolute drop.
  1207. if (battle_config.item_rate_adddrop != 100)
  1208. rate = rate*battle_config.item_rate_adddrop/100;
  1209. if (rate < battle_config.item_drop_adddrop_min)
  1210. rate = battle_config.item_drop_adddrop_min;
  1211. else if (rate > battle_config.item_drop_adddrop_max)
  1212. rate = battle_config.item_drop_adddrop_max;
  1213. } else { //Relative drop, max/min limits are applied at drop time.
  1214. if (battle_config.item_rate_adddrop != 100)
  1215. rate = rate*battle_config.item_rate_adddrop/100;
  1216. if (rate > -1)
  1217. rate = -1;
  1218. }
  1219. for(i = 0; i < max && (drop[i].id || drop[i].group); i++) {
  1220. if(
  1221. (id && drop[i].id == id) ||
  1222. (group && drop[i].group == group)
  1223. ) {
  1224. drop[i].race |= race;
  1225. if(drop[i].rate > 0 && rate > 0)
  1226. { //Both are absolute rates.
  1227. if (drop[i].rate < rate)
  1228. drop[i].rate = rate;
  1229. } else
  1230. if(drop[i].rate < 0 && rate < 0) {
  1231. //Both are relative rates.
  1232. if (drop[i].rate > rate)
  1233. drop[i].rate = rate;
  1234. } else if (rate < 0) //Give preference to relative rate.
  1235. drop[i].rate = rate;
  1236. return 1;
  1237. }
  1238. }
  1239. if(i == max) {
  1240. ShowWarning("pc_bonus: Reached max (%d) number of added drops per character!\n", max);
  1241. return 0;
  1242. }
  1243. drop[i].id = id;
  1244. drop[i].group = group;
  1245. drop[i].race |= race;
  1246. drop[i].rate = rate;
  1247. return 1;
  1248. }
  1249. /*==========================================
  1250. * ? 備品による能力等のボ?ナス設定
  1251. *------------------------------------------*/
  1252. int pc_bonus(struct map_session_data *sd,int type,int val)
  1253. {
  1254. struct status_data *status;
  1255. int bonus;
  1256. nullpo_retr(0, sd);
  1257. status = &sd->base_status;
  1258. switch(type){
  1259. case SP_STR:
  1260. case SP_AGI:
  1261. case SP_VIT:
  1262. case SP_INT:
  1263. case SP_DEX:
  1264. case SP_LUK:
  1265. if(sd->state.lr_flag != 2)
  1266. sd->param_bonus[type-SP_STR]+=val;
  1267. break;
  1268. case SP_ATK1:
  1269. if(!sd->state.lr_flag) {
  1270. bonus = status->rhw.atk + val;
  1271. status->rhw.atk = cap_value(bonus, 0, USHRT_MAX);
  1272. }
  1273. else if(sd->state.lr_flag == 1) {
  1274. bonus = status->lhw.atk + val;
  1275. status->lhw.atk = cap_value(bonus, 0, USHRT_MAX);
  1276. }
  1277. break;
  1278. case SP_ATK2:
  1279. if(!sd->state.lr_flag) {
  1280. bonus = status->rhw.atk2 + val;
  1281. status->rhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
  1282. }
  1283. else if(sd->state.lr_flag == 1) {
  1284. bonus = status->lhw.atk2 + val;
  1285. status->lhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
  1286. }
  1287. break;
  1288. case SP_BASE_ATK:
  1289. if(sd->state.lr_flag != 2) {
  1290. bonus = status->batk + val;
  1291. status->batk = cap_value(bonus, 0, USHRT_MAX);
  1292. }
  1293. break;
  1294. case SP_DEF1:
  1295. if(sd->state.lr_flag != 2) {
  1296. bonus = status->def + val;
  1297. status->def = cap_value(bonus, CHAR_MIN, CHAR_MAX);
  1298. }
  1299. break;
  1300. case SP_DEF2:
  1301. if(sd->state.lr_flag != 2) {
  1302. bonus = status->def2 + val;
  1303. status->def2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1304. }
  1305. break;
  1306. case SP_MDEF1:
  1307. if(sd->state.lr_flag != 2) {
  1308. bonus = status->mdef + val;
  1309. status->mdef = cap_value(bonus, CHAR_MIN, CHAR_MAX);
  1310. }
  1311. break;
  1312. case SP_MDEF2:
  1313. if(sd->state.lr_flag != 2) {
  1314. bonus = status->mdef2 + val;
  1315. status->mdef2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1316. }
  1317. break;
  1318. case SP_HIT:
  1319. if(sd->state.lr_flag != 2) {
  1320. bonus = status->hit + val;
  1321. status->hit = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1322. } else
  1323. sd->arrow_hit+=val;
  1324. break;
  1325. case SP_FLEE1:
  1326. if(sd->state.lr_flag != 2) {
  1327. bonus = status->flee + val;
  1328. status->flee = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1329. }
  1330. break;
  1331. case SP_FLEE2:
  1332. if(sd->state.lr_flag != 2) {
  1333. bonus = status->flee2 + val*10;
  1334. status->flee2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1335. }
  1336. break;
  1337. case SP_CRITICAL:
  1338. if(sd->state.lr_flag != 2) {
  1339. bonus = status->cri + val*10;
  1340. status->cri = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1341. } else
  1342. sd->arrow_cri += val*10;
  1343. break;
  1344. case SP_ATKELE:
  1345. if(val >= ELE_MAX) {
  1346. ShowError("pc_bonus: SP_ATKELE: Invalid element %d\n", val);
  1347. break;
  1348. }
  1349. switch (sd->state.lr_flag)
  1350. {
  1351. case 2:
  1352. switch (sd->status.weapon) {
  1353. case W_BOW:
  1354. case W_REVOLVER:
  1355. case W_RIFLE:
  1356. case W_GATLING:
  1357. case W_SHOTGUN:
  1358. case W_GRENADE:
  1359. //Become weapon element.
  1360. status->rhw.ele=val;
  1361. break;
  1362. default: //Become arrow element.
  1363. sd->arrow_ele=val;
  1364. break;
  1365. }
  1366. break;
  1367. case 1:
  1368. status->lhw.ele=val;
  1369. break;
  1370. default:
  1371. status->rhw.ele=val;
  1372. break;
  1373. }
  1374. break;
  1375. case SP_DEFELE:
  1376. if(val >= ELE_MAX) {
  1377. ShowError("pc_bonus: SP_DEFELE: Invalid element %d\n", val);
  1378. break;
  1379. }
  1380. if(sd->state.lr_flag != 2)
  1381. status->def_ele=val;
  1382. break;
  1383. case SP_MAXHP:
  1384. if(sd->state.lr_flag == 2)
  1385. break;
  1386. val += (int)status->max_hp;
  1387. //Negative bonuses will underflow, this will be handled in status_calc_pc through casting
  1388. //If this is called outside of status_calc_pc, you'd better pray they do not underflow and end with UINT_MAX max_hp.
  1389. status->max_hp = (unsigned int)val;
  1390. break;
  1391. case SP_MAXSP:
  1392. if(sd->state.lr_flag == 2)
  1393. break;
  1394. val += (int)status->max_sp;
  1395. status->max_sp = (unsigned int)val;
  1396. break;
  1397. case SP_CASTRATE:
  1398. if(sd->state.lr_flag != 2)
  1399. sd->castrate+=val;
  1400. break;
  1401. case SP_MAXHPRATE:
  1402. if(sd->state.lr_flag != 2)
  1403. sd->hprate+=val;
  1404. break;
  1405. case SP_MAXSPRATE:
  1406. if(sd->state.lr_flag != 2)
  1407. sd->sprate+=val;
  1408. break;
  1409. case SP_SPRATE:
  1410. if(sd->state.lr_flag != 2)
  1411. sd->dsprate+=val;
  1412. break;
  1413. case SP_ATTACKRANGE:
  1414. switch (sd->state.lr_flag) {
  1415. case 2:
  1416. switch (sd->status.weapon) {
  1417. case W_BOW:
  1418. case W_REVOLVER:
  1419. case W_RIFLE:
  1420. case W_GATLING:
  1421. case W_SHOTGUN:
  1422. case W_GRENADE:
  1423. status->rhw.range += val;
  1424. }
  1425. break;
  1426. case 1:
  1427. status->lhw.range += val;
  1428. break;
  1429. default:
  1430. status->rhw.range += val;
  1431. break;
  1432. }
  1433. break;
  1434. case SP_SPEED_RATE: //Non stackable increase
  1435. if(sd->state.lr_flag != 2)
  1436. sd->speed_rate = min(sd->speed_rate, -val);
  1437. break;
  1438. case SP_SPEED_ADDRATE: //Stackable increase
  1439. if(sd->state.lr_flag != 2)
  1440. sd->speed_add_rate -= val;
  1441. break;
  1442. case SP_ASPD: //Raw increase
  1443. if(sd->state.lr_flag != 2)
  1444. sd->aspd_add -= 10*val;
  1445. break;
  1446. case SP_ASPD_RATE: //Stackable increase - Made it linear as per rodatazone
  1447. if(sd->state.lr_flag != 2)
  1448. status->aspd_rate -= 10*val;
  1449. break;
  1450. case SP_HP_RECOV_RATE:
  1451. if(sd->state.lr_flag != 2)
  1452. sd->hprecov_rate += val;
  1453. break;
  1454. case SP_SP_RECOV_RATE:
  1455. if(sd->state.lr_flag != 2)
  1456. sd->sprecov_rate += val;
  1457. break;
  1458. case SP_CRITICAL_DEF:
  1459. if(sd->state.lr_flag != 2)
  1460. sd->critical_def += val;
  1461. break;
  1462. case SP_NEAR_ATK_DEF:
  1463. if(sd->state.lr_flag != 2)
  1464. sd->near_attack_def_rate += val;
  1465. break;
  1466. case SP_LONG_ATK_DEF:
  1467. if(sd->state.lr_flag != 2)
  1468. sd->long_attack_def_rate += val;
  1469. break;
  1470. case SP_DOUBLE_RATE:
  1471. if(sd->state.lr_flag == 0 && sd->double_rate < val)
  1472. sd->double_rate = val;
  1473. break;
  1474. case SP_DOUBLE_ADD_RATE:
  1475. if(sd->state.lr_flag == 0)
  1476. sd->double_add_rate += val;
  1477. break;
  1478. case SP_MATK_RATE:
  1479. if(sd->state.lr_flag != 2)
  1480. sd->matk_rate += val;
  1481. break;
  1482. case SP_IGNORE_DEF_ELE:
  1483. if(val >= ELE_MAX) {
  1484. ShowError("pc_bonus: SP_IGNORE_DEF_ELE: Invalid element %d\n", val);
  1485. break;
  1486. }
  1487. if(!sd->state.lr_flag)
  1488. sd->right_weapon.ignore_def_ele |= 1<<val;
  1489. else if(sd->state.lr_flag == 1)
  1490. sd->left_weapon.ignore_def_ele |= 1<<val;
  1491. break;
  1492. case SP_IGNORE_DEF_RACE:
  1493. if(!sd->state.lr_flag)
  1494. sd->right_weapon.ignore_def_race |= 1<<val;
  1495. else if(sd->state.lr_flag == 1)
  1496. sd->left_weapon.ignore_def_race |= 1<<val;
  1497. break;
  1498. case SP_ATK_RATE:
  1499. if(sd->state.lr_flag != 2)
  1500. sd->atk_rate += val;
  1501. break;
  1502. case SP_MAGIC_ATK_DEF:
  1503. if(sd->state.lr_flag != 2)
  1504. sd->magic_def_rate += val;
  1505. break;
  1506. case SP_MISC_ATK_DEF:
  1507. if(sd->state.lr_flag != 2)
  1508. sd->misc_def_rate += val;
  1509. break;
  1510. case SP_IGNORE_MDEF_RATE:
  1511. if(sd->state.lr_flag != 2) {
  1512. sd->ignore_mdef[RC_NONBOSS] += val;
  1513. sd->ignore_mdef[RC_BOSS] += val;
  1514. }
  1515. break;
  1516. case SP_IGNORE_MDEF_ELE:
  1517. if(val >= ELE_MAX) {
  1518. ShowError("pc_bonus: SP_IGNORE_MDEF_ELE: Invalid element %d\n", val);
  1519. break;
  1520. }
  1521. if(sd->state.lr_flag != 2)
  1522. sd->ignore_mdef_ele |= 1<<val;
  1523. break;
  1524. case SP_IGNORE_MDEF_RACE:
  1525. if(sd->state.lr_flag != 2)
  1526. sd->ignore_mdef_race |= 1<<val;
  1527. break;
  1528. case SP_PERFECT_HIT_RATE:
  1529. if(sd->state.lr_flag != 2 && sd->perfect_hit < val)
  1530. sd->perfect_hit = val;
  1531. break;
  1532. case SP_PERFECT_HIT_ADD_RATE:
  1533. if(sd->state.lr_flag != 2)
  1534. sd->perfect_hit_add += val;
  1535. break;
  1536. case SP_CRITICAL_RATE:
  1537. if(sd->state.lr_flag != 2)
  1538. sd->critical_rate+=val;
  1539. break;
  1540. case SP_DEF_RATIO_ATK_ELE:
  1541. if(val >= ELE_MAX) {
  1542. ShowError("pc_bonus: SP_DEF_RATIO_ATK_ELE: Invalid element %d\n", val);
  1543. break;
  1544. }
  1545. if(!sd->state.lr_flag)
  1546. sd->right_weapon.def_ratio_atk_ele |= 1<<val;
  1547. else if(sd->state.lr_flag == 1)
  1548. sd->left_weapon.def_ratio_atk_ele |= 1<<val;
  1549. break;
  1550. case SP_DEF_RATIO_ATK_RACE:
  1551. if(val >= RC_MAX) {
  1552. ShowError("pc_bonus: SP_DEF_RATIO_ATK_RACE: Invalid race %d\n", val);
  1553. break;
  1554. }
  1555. if(!sd->state.lr_flag)
  1556. sd->right_weapon.def_ratio_atk_race |= 1<<val;
  1557. else if(sd->state.lr_flag == 1)
  1558. sd->left_weapon.def_ratio_atk_race |= 1<<val;
  1559. break;
  1560. case SP_HIT_RATE:
  1561. if(sd->state.lr_flag != 2)
  1562. sd->hit_rate += val;
  1563. break;
  1564. case SP_FLEE_RATE:
  1565. if(sd->state.lr_flag != 2)
  1566. sd->flee_rate += val;
  1567. break;
  1568. case SP_FLEE2_RATE:
  1569. if(sd->state.lr_flag != 2)
  1570. sd->flee2_rate += val;
  1571. break;
  1572. case SP_DEF_RATE:
  1573. if(sd->state.lr_flag != 2)
  1574. sd->def_rate += val;
  1575. break;
  1576. case SP_DEF2_RATE:
  1577. if(sd->state.lr_flag != 2)
  1578. sd->def2_rate += val;
  1579. break;
  1580. case SP_MDEF_RATE:
  1581. if(sd->state.lr_flag != 2)
  1582. sd->mdef_rate += val;
  1583. break;
  1584. case SP_MDEF2_RATE:
  1585. if(sd->state.lr_flag != 2)
  1586. sd->mdef2_rate += val;
  1587. break;
  1588. case SP_RESTART_FULL_RECOVER:
  1589. if(sd->state.lr_flag != 2)
  1590. sd->special_state.restart_full_recover = 1;
  1591. break;
  1592. case SP_NO_CASTCANCEL:
  1593. if(sd->state.lr_flag != 2)
  1594. sd->special_state.no_castcancel = 1;
  1595. break;
  1596. case SP_NO_CASTCANCEL2:
  1597. if(sd->state.lr_flag != 2)
  1598. sd->special_state.no_castcancel2 = 1;
  1599. break;
  1600. case SP_NO_SIZEFIX:
  1601. if(sd->state.lr_flag != 2)
  1602. sd->special_state.no_sizefix = 1;
  1603. break;
  1604. case SP_NO_MAGIC_DAMAGE:
  1605. if(sd->state.lr_flag == 2)
  1606. break;
  1607. val+= sd->special_state.no_magic_damage;
  1608. sd->special_state.no_magic_damage = cap_value(val,0,100);
  1609. break;
  1610. case SP_NO_WEAPON_DAMAGE:
  1611. if(sd->state.lr_flag == 2)
  1612. break;
  1613. val+= sd->special_state.no_weapon_damage;
  1614. sd->special_state.no_weapon_damage = cap_value(val,0,100);
  1615. break;
  1616. case SP_NO_MISC_DAMAGE:
  1617. if(sd->state.lr_flag == 2)
  1618. break;
  1619. val+= sd->special_state.no_misc_damage;
  1620. sd->special_state.no_misc_damage = cap_value(val,0,100);
  1621. break;
  1622. case SP_NO_GEMSTONE:
  1623. if(sd->state.lr_flag != 2)
  1624. sd->special_state.no_gemstone = 1;
  1625. break;
  1626. case SP_INTRAVISION: // Maya Purple Card effect allowing to see Hiding/Cloaking people [DracoRPG]
  1627. if(sd->state.lr_flag != 2) {
  1628. sd->special_state.intravision = 1;
  1629. clif_status_load(&sd->bl, SI_INTRAVISION, 1);
  1630. }
  1631. break;
  1632. case SP_NO_KNOCKBACK:
  1633. if(sd->state.lr_flag != 2)
  1634. sd->special_state.no_knockback = 1;
  1635. break;
  1636. case SP_SPLASH_RANGE:
  1637. if(sd->state.lr_flag != 2 && sd->splash_range < val)
  1638. sd->splash_range = val;
  1639. break;
  1640. case SP_SPLASH_ADD_RANGE:
  1641. if(sd->state.lr_flag != 2)
  1642. sd->splash_add_range += val;
  1643. break;
  1644. case SP_SHORT_WEAPON_DAMAGE_RETURN:
  1645. if(sd->state.lr_flag != 2)
  1646. sd->short_weapon_damage_return += val;
  1647. break;
  1648. case SP_LONG_WEAPON_DAMAGE_RETURN:
  1649. if(sd->state.lr_flag != 2)
  1650. sd->long_weapon_damage_return += val;
  1651. break;
  1652. case SP_MAGIC_DAMAGE_RETURN: //AppleGirl Was Here
  1653. if(sd->state.lr_flag != 2)
  1654. sd->magic_damage_return += val;
  1655. break;
  1656. case SP_ALL_STATS: // [Valaris]
  1657. if(sd->state.lr_flag!=2) {
  1658. sd->param_bonus[SP_STR-SP_STR]+=val;
  1659. sd->param_bonus[SP_AGI-SP_STR]+=val;
  1660. sd->param_bonus[SP_VIT-SP_STR]+=val;
  1661. sd->param_bonus[SP_INT-SP_STR]+=val;
  1662. sd->param_bonus[SP_DEX-SP_STR]+=val;
  1663. sd->param_bonus[SP_LUK-SP_STR]+=val;
  1664. }
  1665. break;
  1666. case SP_AGI_VIT: // [Valaris]
  1667. if(sd->state.lr_flag!=2) {
  1668. sd->param_bonus[SP_AGI-SP_STR]+=val;
  1669. sd->param_bonus[SP_VIT-SP_STR]+=val;
  1670. }
  1671. break;
  1672. case SP_AGI_DEX_STR: // [Valaris]
  1673. if(sd->state.lr_flag!=2) {
  1674. sd->param_bonus[SP_AGI-SP_STR]+=val;
  1675. sd->param_bonus[SP_DEX-SP_STR]+=val;
  1676. sd->param_bonus[SP_STR-SP_STR]+=val;
  1677. }
  1678. break;
  1679. case SP_PERFECT_HIDE: // [Valaris]
  1680. if(sd->state.lr_flag!=2)
  1681. sd->special_state.perfect_hiding=1;
  1682. break;
  1683. case SP_UNBREAKABLE:
  1684. if(sd->state.lr_flag!=2)
  1685. sd->unbreakable += val;
  1686. break;
  1687. case SP_UNBREAKABLE_WEAPON:
  1688. if(sd->state.lr_flag != 2)
  1689. sd->unbreakable_equip |= EQP_WEAPON;
  1690. break;
  1691. case SP_UNBREAKABLE_ARMOR:
  1692. if(sd->state.lr_flag != 2)
  1693. sd->unbreakable_equip |= EQP_ARMOR;
  1694. break;
  1695. case SP_UNBREAKABLE_HELM:
  1696. if(sd->state.lr_flag != 2)
  1697. sd->unbreakable_equip |= EQP_HELM;
  1698. break;
  1699. case SP_UNBREAKABLE_SHIELD:
  1700. if(sd->state.lr_flag != 2)
  1701. sd->unbreakable_equip |= EQP_SHIELD;
  1702. break;
  1703. case SP_CLASSCHANGE: // [Valaris]
  1704. if(sd->state.lr_flag !=2)
  1705. sd->classchange=val;
  1706. break;
  1707. case SP_LONG_ATK_RATE:
  1708. if(sd->state.lr_flag != 2) //[Lupus] it should stack, too. As any other cards rate bonuses
  1709. sd->long_attack_atk_rate+=val;
  1710. break;
  1711. case SP_BREAK_WEAPON_RATE:
  1712. if(sd->state.lr_flag != 2)
  1713. sd->break_weapon_rate+=val;
  1714. break;
  1715. case SP_BREAK_ARMOR_RATE:
  1716. if(sd->state.lr_flag != 2)
  1717. sd->break_armor_rate+=val;
  1718. break;
  1719. case SP_ADD_STEAL_RATE:
  1720. if(sd->state.lr_flag != 2)
  1721. sd->add_steal_rate+=val;
  1722. break;
  1723. case SP_DELAYRATE:
  1724. if(sd->state.lr_flag != 2)
  1725. sd->delayrate+=val;
  1726. break;
  1727. case SP_CRIT_ATK_RATE:
  1728. if(sd->state.lr_flag != 2)
  1729. sd->crit_atk_rate += val;
  1730. break;
  1731. case SP_NO_REGEN:
  1732. if(sd->state.lr_flag != 2)
  1733. sd->regen.state.block|=val;
  1734. break;
  1735. case SP_UNSTRIPABLE_WEAPON:
  1736. if(sd->state.lr_flag != 2)
  1737. sd->unstripable_equip |= EQP_WEAPON;
  1738. break;
  1739. case SP_UNSTRIPABLE:
  1740. case SP_UNSTRIPABLE_ARMOR:
  1741. if(sd->state.lr_flag != 2)
  1742. sd->unstripable_equip |= EQP_ARMOR;
  1743. break;
  1744. case SP_UNSTRIPABLE_HELM:
  1745. if(sd->state.lr_flag != 2)
  1746. sd->unstripable_equip |= EQP_HELM;
  1747. break;
  1748. case SP_UNSTRIPABLE_SHIELD:
  1749. if(sd->state.lr_flag != 2)
  1750. sd->unstripable_equip |= EQP_SHIELD;
  1751. break;
  1752. case SP_HP_DRAIN_VALUE:
  1753. if(!sd->state.lr_flag) {
  1754. sd->right_weapon.hp_drain[RC_NONBOSS].value += val;
  1755. sd->right_weapon.hp_drain[RC_BOSS].value += val;
  1756. }
  1757. else if(sd->state.lr_flag == 1) {
  1758. sd->right_weapon.hp_drain[RC_NONBOSS].value += val;
  1759. sd->right_weapon.hp_drain[RC_BOSS].value += val;
  1760. }
  1761. break;
  1762. case SP_SP_DRAIN_VALUE:
  1763. if(!sd->state.lr_flag) {
  1764. sd->right_weapon.sp_drain[RC_NONBOSS].value += val;
  1765. sd->right_weapon.sp_drain[RC_BOSS].value += val;
  1766. }
  1767. else if(sd->state.lr_flag == 1) {
  1768. sd->left_weapon.sp_drain[RC_NONBOSS].value += val;
  1769. sd->left_weapon.sp_drain[RC_BOSS].value += val;
  1770. }
  1771. break;
  1772. case SP_SP_GAIN_VALUE:
  1773. if(!sd->state.lr_flag)
  1774. sd->sp_gain_value += val;
  1775. break;
  1776. case SP_HP_GAIN_VALUE:
  1777. if(!sd->state.lr_flag)
  1778. sd->hp_gain_value += val;
  1779. break;
  1780. default:
  1781. ShowWarning("pc_bonus: unknown type %d %d !\n",type,val);
  1782. break;
  1783. }
  1784. return 0;
  1785. }
  1786. /*==========================================
  1787. * ? 備品による能力等のボ?ナス設定
  1788. *------------------------------------------*/
  1789. int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
  1790. {
  1791. int i;
  1792. nullpo_retr(0, sd);
  1793. switch(type){
  1794. case SP_ADDELE:
  1795. if(type2 >= ELE_MAX) {
  1796. ShowError("pc_bonus2: SP_ADDELE: Invalid element %d\n", type2);
  1797. break;
  1798. }
  1799. if(!sd->state.lr_flag)
  1800. sd->right_weapon.addele[type2]+=val;
  1801. else if(sd->state.lr_flag == 1)
  1802. sd->left_weapon.addele[type2]+=val;
  1803. else if(sd->state.lr_flag == 2)
  1804. sd->arrow_addele[type2]+=val;
  1805. break;
  1806. case SP_ADDRACE:
  1807. if(!sd->state.lr_flag)
  1808. sd->right_weapon.addrace[type2]+=val;
  1809. else if(sd->state.lr_flag == 1)
  1810. sd->left_weapon.addrace[type2]+=val;
  1811. else if(sd->state.lr_flag == 2)
  1812. sd->arrow_addrace[type2]+=val;
  1813. break;
  1814. case SP_ADDSIZE:
  1815. if(!sd->state.lr_flag)
  1816. sd->right_weapon.addsize[type2]+=val;
  1817. else if(sd->state.lr_flag == 1)
  1818. sd->left_weapon.addsize[type2]+=val;
  1819. else if(sd->state.lr_flag == 2)
  1820. sd->arrow_addsize[type2]+=val;
  1821. break;
  1822. case SP_SUBELE:
  1823. if(type2 >= ELE_MAX) {
  1824. ShowError("pc_bonus2: SP_SUBELE: Invalid element %d\n", type2);
  1825. break;
  1826. }
  1827. if(sd->state.lr_flag != 2)
  1828. sd->subele[type2]+=val;
  1829. break;
  1830. case SP_SUBRACE:
  1831. if(sd->state.lr_flag != 2)
  1832. sd->subrace[type2]+=val;
  1833. break;
  1834. case SP_ADDEFF:
  1835. if (type2 > SC_MAX) {
  1836. ShowWarning("pc_bonus2 (Add Effect): %d is not supported.\n", type2);
  1837. break;
  1838. }
  1839. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  1840. sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, 0);
  1841. break;
  1842. case SP_ADDEFF2:
  1843. if (type2 > SC_MAX) {
  1844. ShowWarning("pc_bonus2 (Add Effect2): %d is not supported.\n", type2);
  1845. break;
  1846. }
  1847. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  1848. sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, ATF_SELF);
  1849. break;
  1850. case SP_RESEFF:
  1851. if (type2 < SC_COMMON_MIN || type2 > SC_COMMON_MAX) {
  1852. ShowWarning("pc_bonus2 (Resist Effect): %d is not supported.\n", type2);
  1853. break;
  1854. }
  1855. if(sd->state.lr_flag == 2)
  1856. break;
  1857. i = sd->reseff[type2-SC_COMMON_MIN]+val;
  1858. sd->reseff[type2-SC_COMMON_MIN]= cap_value(i, 0, 10000);
  1859. break;
  1860. case SP_MAGIC_ADDELE:
  1861. if(type2 >= ELE_MAX) {
  1862. ShowError("pc_bonus2: SP_MAGIC_ADDELE: Invalid element %d\n", type2);
  1863. break;
  1864. }
  1865. if(sd->state.lr_flag != 2)
  1866. sd->magic_addele[type2]+=val;
  1867. break;
  1868. case SP_MAGIC_ADDRACE:
  1869. if(sd->state.lr_flag != 2)
  1870. sd->magic_addrace[type2]+=val;
  1871. break;
  1872. case SP_MAGIC_ADDSIZE:
  1873. if(sd->state.lr_flag != 2)
  1874. sd->magic_addsize[type2]+=val;
  1875. break;
  1876. case SP_ADD_DAMAGE_CLASS:
  1877. switch (sd->state.lr_flag) {
  1878. case 0: //Right hand
  1879. ARR_FIND(0, ARRAYLENGTH(sd->right_weapon.add_dmg), i, sd->right_weapon.add_dmg[i].rate == 0 || sd->right_weapon.add_dmg[i].class_ == type2);
  1880. if (i == ARRAYLENGTH(sd->right_weapon.add_dmg))
  1881. {
  1882. ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->right_weapon.add_dmg));
  1883. break;
  1884. }
  1885. sd->right_weapon.add_dmg[i].class_ = type2;
  1886. sd->right_weapon.add_dmg[i].rate += val;
  1887. if (!sd->right_weapon.add_dmg[i].rate) //Shift the rest of elements up.
  1888. memmove(&sd->right_weapon.add_dmg[i], &sd->right_weapon.add_dmg[i+1], sizeof(sd->right_weapon.add_dmg) - (i+1)*sizeof(sd->right_weapon.add_dmg[0]));
  1889. break;
  1890. case 1: //Left hand
  1891. ARR_FIND(0, ARRAYLENGTH(sd->left_weapon.add_dmg), i, sd->left_weapon.add_dmg[i].rate == 0 || sd->left_weapon.add_dmg[i].class_ == type2);
  1892. if (i == ARRAYLENGTH(sd->left_weapon.add_dmg))
  1893. {
  1894. ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->left_weapon.add_dmg));
  1895. break;
  1896. }
  1897. sd->left_weapon.add_dmg[i].class_ = type2;
  1898. sd->left_weapon.add_dmg[i].rate += val;
  1899. if (!sd->left_weapon.add_dmg[i].rate) //Shift the rest of elements up.
  1900. memmove(&sd->left_weapon.add_dmg[i], &sd->left_weapon.add_dmg[i+1], sizeof(sd->left_weapon.add_dmg) - (i+1)*sizeof(sd->left_weapon.add_dmg[0]));
  1901. break;
  1902. }
  1903. break;
  1904. case SP_ADD_MAGIC_DAMAGE_CLASS:
  1905. if(sd->state.lr_flag == 2)
  1906. break;
  1907. ARR_FIND(0, ARRAYLENGTH(sd->add_mdmg), i, sd->add_mdmg[i].rate == 0 || sd->add_mdmg[i].class_ == type2);
  1908. if (i == ARRAYLENGTH(sd->add_mdmg))
  1909. {
  1910. ShowWarning("pc_bonus2: Reached max (%d) number of add Class magic dmg bonuses per character!\n", ARRAYLENGTH(sd->add_mdmg));
  1911. break;
  1912. }
  1913. sd->add_mdmg[i].class_ = type2;
  1914. sd->add_mdmg[i].rate += val;
  1915. if (!sd->add_mdmg[i].rate) //Shift the rest of elements up.
  1916. memmove(&sd->add_mdmg[i], &sd->add_mdmg[i+1], sizeof(sd->add_mdmg) - (i+1)*sizeof(sd->add_mdmg[0]));
  1917. break;
  1918. case SP_ADD_DEF_CLASS:
  1919. if(sd->state.lr_flag == 2)
  1920. break;
  1921. ARR_FIND(0, ARRAYLENGTH(sd->add_def), i, sd->add_def[i].rate == 0 || sd->add_def[i].class_ == type2);
  1922. if (i == ARRAYLENGTH(sd->add_def))
  1923. {
  1924. ShowWarning("pc_bonus2: Reached max (%d) number of add Class def bonuses per character!\n", ARRAYLENGTH(sd->add_def));
  1925. break;
  1926. }
  1927. sd->add_def[i].class_ = type2;
  1928. sd->add_def[i].rate += val;
  1929. if (!sd->add_def[i].rate) //Shift the rest of elements up.
  1930. memmove(&sd->add_def[i], &sd->add_def[i+1], sizeof(sd->add_def) - (i+1)*sizeof(sd->add_def[0]));
  1931. break;
  1932. case SP_ADD_MDEF_CLASS:
  1933. if(sd->state.lr_flag == 2)
  1934. break;
  1935. ARR_FIND(0, ARRAYLENGTH(sd->add_mdef), i, sd->add_mdef[i].rate == 0 || sd->add_mdef[i].class_ == type2);
  1936. if (i == ARRAYLENGTH(sd->add_mdef))
  1937. {
  1938. ShowWarning("pc_bonus2: Reached max (%d) number of add Class mdef bonuses per character!\n", ARRAYLENGTH(sd->add_mdef));
  1939. break;
  1940. }
  1941. sd->add_mdef[i].class_ = type2;
  1942. sd->add_mdef[i].rate += val;
  1943. if (!sd->add_mdef[i].rate) //Shift the rest of elements up.
  1944. memmove(&sd->add_mdef[i], &sd->add_mdef[i+1], sizeof(sd->add_mdef) - (i+1)*sizeof(sd->add_mdef[0]));
  1945. break;
  1946. case SP_HP_DRAIN_RATE:
  1947. if(!sd->state.lr_flag) {
  1948. sd->right_weapon.hp_drain[RC_NONBOSS].rate += type2;
  1949. sd->right_weapon.hp_drain[RC_NONBOSS].per += val;
  1950. sd->right_weapon.hp_drain[RC_BOSS].rate += type2;
  1951. sd->right_weapon.hp_drain[RC_BOSS].per += val;
  1952. }
  1953. else if(sd->state.lr_flag == 1) {
  1954. sd->left_weapon.hp_drain[RC_NONBOSS].rate += type2;
  1955. sd->left_weapon.hp_drain[RC_NONBOSS].per += val;
  1956. sd->left_weapon.hp_drain[RC_BOSS].rate += type2;
  1957. sd->left_weapon.hp_drain[RC_BOSS].per += val;
  1958. }
  1959. break;
  1960. case SP_HP_DRAIN_VALUE:
  1961. if(!sd->state.lr_flag) {
  1962. sd->right_weapon.hp_drain[RC_NONBOSS].value += type2;
  1963. sd->right_weapon.hp_drain[RC_NONBOSS].type = val;
  1964. sd->right_weapon.hp_drain[RC_BOSS].value += type2;
  1965. sd->right_weapon.hp_drain[RC_BOSS].type = val;
  1966. }
  1967. else if(sd->state.lr_flag == 1) {
  1968. sd->left_weapon.hp_drain[RC_NONBOSS].value += type2;
  1969. sd->left_weapon.hp_drain[RC_NONBOSS].type = val;
  1970. sd->left_weapon.hp_drain[RC_BOSS].value += type2;
  1971. sd->left_weapon.hp_drain[RC_BOSS].type = val;
  1972. }
  1973. break;
  1974. case SP_SP_DRAIN_RATE:
  1975. if(!sd->state.lr_flag) {
  1976. sd->right_weapon.sp_drain[RC_NONBOSS].rate += type2;
  1977. sd->right_weapon.sp_drain[RC_NONBOSS].per += val;
  1978. sd->right_weapon.sp_drain[RC_BOSS].rate += type2;
  1979. sd->right_weapon.sp_drain[RC_BOSS].per += val;
  1980. }
  1981. else if(sd->state.lr_flag == 1) {
  1982. sd->left_weapon.sp_drain[RC_NONBOSS].rate += type2;
  1983. sd->left_weapon.sp_drain[RC_NONBOSS].per += val;
  1984. sd->left_weapon.sp_drain[RC_BOSS].rate += type2;
  1985. sd->left_weapon.sp_drain[RC_BOSS].per += val;
  1986. }
  1987. break;
  1988. case SP_SP_DRAIN_VALUE:
  1989. if(!sd->state.lr_flag) {
  1990. sd->right_weapon.sp_drain[RC_NONBOSS].value += type2;
  1991. sd->right_weapon.sp_drain[RC_NONBOSS].type = val;
  1992. sd->right_weapon.sp_drain[RC_BOSS].value += type2;
  1993. sd->right_weapon.sp_drain[RC_BOSS].type = val;
  1994. }
  1995. else if(sd->state.lr_flag == 1) {
  1996. sd->left_weapon.sp_drain[RC_NONBOSS].value += type2;
  1997. sd->left_weapon.sp_drain[RC_NONBOSS].type = val;
  1998. sd->left_weapon.sp_drain[RC_BOSS].value += type2;
  1999. sd->left_weapon.sp_drain[RC_BOSS].type = val;
  2000. }
  2001. break;
  2002. case SP_SP_VANISH_RATE:
  2003. if(sd->state.lr_flag != 2) {
  2004. sd->sp_vanish_rate += type2;
  2005. sd->sp_vanish_per += val;
  2006. }
  2007. break;
  2008. case SP_GET_ZENY_NUM:
  2009. if(sd->state.lr_flag != 2 && sd->get_zeny_rate < val)
  2010. {
  2011. sd->get_zeny_rate = val;
  2012. sd->get_zeny_num = type2;
  2013. }
  2014. break;
  2015. case SP_ADD_GET_ZENY_NUM:
  2016. if(sd->state.lr_flag != 2)
  2017. {
  2018. sd->get_zeny_rate += val;
  2019. sd->get_zeny_num += type2;
  2020. }
  2021. break;
  2022. case SP_WEAPON_COMA_ELE:
  2023. if(type2 >= ELE_MAX) {
  2024. ShowError("pc_bonus2: SP_WEAPON_COMA_ELE: Invalid element %d\n", type2);
  2025. break;
  2026. }
  2027. if(sd->state.lr_flag == 2)
  2028. break;
  2029. sd->weapon_coma_ele[type2] += val;
  2030. sd->special_state.bonus_coma = 1;
  2031. break;
  2032. case SP_WEAPON_COMA_RACE:
  2033. if(sd->state.lr_flag == 2)
  2034. break;
  2035. sd->weapon_coma_race[type2] += val;
  2036. sd->special_state.bonus_coma = 1;
  2037. break;
  2038. case SP_RANDOM_ATTACK_INCREASE: // [Valaris]
  2039. if(sd->state.lr_flag !=2){
  2040. sd->random_attack_increase_add = type2;
  2041. sd->random_attack_increase_per += val;
  2042. }
  2043. break;
  2044. case SP_WEAPON_ATK:
  2045. if(sd->state.lr_flag != 2)
  2046. sd->weapon_atk[type2]+=val;
  2047. break;
  2048. case SP_WEAPON_ATK_RATE:
  2049. if(sd->state.lr_flag != 2)
  2050. sd->weapon_atk_rate[type2]+=val;
  2051. break;
  2052. case SP_CRITICAL_ADDRACE:
  2053. if(sd->state.lr_flag != 2)
  2054. sd->critaddrace[type2] += val*10;
  2055. break;
  2056. case SP_ADDEFF_WHENHIT:
  2057. if (type2 > SC_MAX) {
  2058. ShowWarning("pc_bonus2 (Add Effect when hit): %d is not supported.\n", type2);
  2059. break;
  2060. }
  2061. if(sd->state.lr_flag != 2)
  2062. pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, val, 0, 0);
  2063. break;
  2064. case SP_SKILL_ATK:
  2065. if(sd->state.lr_flag == 2)
  2066. break;
  2067. ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == 0 || sd->skillatk[i].id == type2);
  2068. if (i == ARRAYLENGTH(sd->skillatk))
  2069. { //Better mention this so the array length can be updated. [Skotlex]
  2070. ShowDebug("run_script: bonus2 bSkillAtk reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillatk), type2, val);
  2071. break;
  2072. }
  2073. if (sd->skillatk[i].id == type2)
  2074. sd->skillatk[i].val += val;
  2075. else {
  2076. sd->skillatk[i].id = type2;
  2077. sd->skillatk[i].val = val;
  2078. }
  2079. break;
  2080. case SP_SKILL_HEAL:
  2081. if(sd->state.lr_flag == 2)
  2082. break;
  2083. ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == 0 || sd->skillheal[i].id == type2);
  2084. if (i == ARRAYLENGTH(sd->skillheal))
  2085. { //Better mention this so the array length can be updated. [Skotlex]
  2086. ShowDebug("run_script: bonus2 bSkillHeal reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal), type2, val);
  2087. break;
  2088. }
  2089. if (sd->skillheal[i].id == type2)
  2090. sd->skillheal[i].val += val;
  2091. else {
  2092. sd->skillheal[i].id = type2;
  2093. sd->skillheal[i].val = val;
  2094. }
  2095. break;
  2096. case SP_ADD_SKILL_BLOW:
  2097. if(sd->state.lr_flag == 2)
  2098. break;
  2099. ARR_FIND(0, ARRAYLENGTH(sd->skillblown), i, sd->skillblown[i].id == 0 || sd->skillblown[i].id == type2);
  2100. if (i == ARRAYLENGTH(sd->skillblown))
  2101. { //Better mention this so the array length can be updated. [Skotlex]
  2102. ShowDebug("run_script: bonus2 bSkillBlown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillblown), type2, val);
  2103. break;
  2104. }
  2105. if(sd->skillblown[i].id == type2)
  2106. sd->skillblown[i].val += val;
  2107. else {
  2108. sd->skillblown[i].id = type2;
  2109. sd->skillblown[i].val = val;
  2110. }
  2111. break;
  2112. case SP_CASTRATE:
  2113. if(sd->state.lr_flag == 2)
  2114. break;
  2115. ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2);
  2116. if (i == ARRAYLENGTH(sd->skillcast))
  2117. { //Better mention this so the array length can be updated. [Skotlex]
  2118. ShowDebug("run_script: bonus2 bCastRate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillcast), type2, val);
  2119. break;
  2120. }
  2121. if(sd->skillcast[i].id == type2)
  2122. sd->skillcast[i].val += val;
  2123. else {
  2124. sd->skillcast[i].id = type2;
  2125. sd->skillcast[i].val = val;
  2126. }
  2127. break;
  2128. case SP_HP_LOSS_RATE:
  2129. if(sd->state.lr_flag != 2) {
  2130. sd->hp_loss.value = type2;
  2131. sd->hp_loss.rate = val;
  2132. }
  2133. break;
  2134. case SP_HP_REGEN_RATE:
  2135. if(sd->state.lr_flag != 2) {
  2136. sd->hp_regen.value = type2;
  2137. sd->hp_regen.rate = val;
  2138. }
  2139. break;
  2140. case SP_ADDRACE2:
  2141. if (!(type2 > 0 && type2 < MAX_MOB_RACE_DB))
  2142. break;
  2143. if(sd->state.lr_flag != 2)
  2144. sd->right_weapon.addrace2[type2] += val;
  2145. else
  2146. sd->left_weapon.addrace2[type2] += val;
  2147. break;
  2148. case SP_SUBSIZE:
  2149. if(sd->state.lr_flag != 2)
  2150. sd->subsize[type2]+=val;
  2151. break;
  2152. case SP_SUBRACE2:
  2153. if(sd->state.lr_flag != 2)
  2154. sd->subrace2[type2]+=val;
  2155. break;
  2156. case SP_ADD_ITEM_HEAL_RATE:
  2157. if(sd->state.lr_flag == 2)
  2158. break;
  2159. if (type2 < MAX_ITEMGROUP) { //Group bonus
  2160. sd->itemgrouphealrate[type2] += val;
  2161. break;
  2162. }
  2163. //Standard item bonus.
  2164. for(i=0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++);
  2165. if(i == ARRAYLENGTH(sd->itemhealrate)) {
  2166. ShowWarning("pc_bonus2: Reached max (%d) number of item heal bonuses per character!\n", ARRAYLENGTH(sd->itemhealrate));
  2167. break;
  2168. }
  2169. sd->itemhealrate[i].nameid = type2;
  2170. sd->itemhealrate[i].rate += val;
  2171. break;
  2172. case SP_EXP_ADDRACE:
  2173. if(sd->state.lr_flag != 2)
  2174. sd->expaddrace[type2]+=val;
  2175. break;
  2176. case SP_SP_GAIN_RACE:
  2177. if(sd->state.lr_flag != 2)
  2178. sd->sp_gain_race[type2]+=val;
  2179. break;
  2180. case SP_ADD_MONSTER_DROP_ITEM:
  2181. if (sd->state.lr_flag != 2)
  2182. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, (1<<RC_BOSS)|(1<<RC_NONBOSS), val);
  2183. break;
  2184. case SP_ADD_MONSTER_DROP_ITEMGROUP:
  2185. if (sd->state.lr_flag != 2)
  2186. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, (1<<RC_BOSS)|(1<<RC_NONBOSS), val);
  2187. break;
  2188. case SP_SP_LOSS_RATE:
  2189. if(sd->state.lr_flag != 2) {
  2190. sd->sp_loss.value = type2;
  2191. sd->sp_loss.rate = val;
  2192. }
  2193. break;
  2194. case SP_SP_REGEN_RATE:
  2195. if(sd->state.lr_flag != 2) {
  2196. sd->sp_regen.value = type2;
  2197. sd->sp_regen.rate = val;
  2198. }
  2199. break;
  2200. case SP_HP_DRAIN_VALUE_RACE:
  2201. if(!sd->state.lr_flag) {
  2202. sd->right_weapon.hp_drain[type2].value += val;
  2203. }
  2204. else if(sd->state.lr_flag == 1) {
  2205. sd->left_weapon.hp_drain[type2].value += val;
  2206. }
  2207. break;
  2208. case SP_SP_DRAIN_VALUE_RACE:
  2209. if(!sd->state.lr_flag) {
  2210. sd->right_weapon.sp_drain[type2].value += val;
  2211. }
  2212. else if(sd->state.lr_flag == 1) {
  2213. sd->left_weapon.sp_drain[type2].value += val;
  2214. }
  2215. break;
  2216. case SP_IGNORE_MDEF_RATE:
  2217. if(sd->state.lr_flag != 2)
  2218. sd->ignore_mdef[type2] += val;
  2219. break;
  2220. default:
  2221. ShowWarning("pc_bonus2: unknown type %d %d %d!\n",type,type2,val);
  2222. break;
  2223. }
  2224. return 0;
  2225. }
  2226. int pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
  2227. {
  2228. nullpo_retr(0, sd);
  2229. switch(type){
  2230. case SP_ADD_MONSTER_DROP_ITEM:
  2231. if(sd->state.lr_flag != 2)
  2232. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, 1<<type3, val);
  2233. break;
  2234. case SP_AUTOSPELL:
  2235. if(sd->state.lr_flag != 2)
  2236. {
  2237. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  2238. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  2239. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell),
  2240. target?-type2:type2, type3, val, 0, current_equip_card_id);
  2241. }
  2242. break;
  2243. case SP_AUTOSPELL_WHENHIT:
  2244. if(sd->state.lr_flag != 2)
  2245. {
  2246. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  2247. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  2248. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2),
  2249. target?-type2:type2, type3, val, 0, current_equip_card_id);
  2250. }
  2251. break;
  2252. case SP_SP_DRAIN_RATE:
  2253. if(!sd->state.lr_flag) {
  2254. sd->right_weapon.sp_drain[RC_NONBOSS].rate += type2;
  2255. sd->right_weapon.sp_drain[RC_NONBOSS].per += type3;
  2256. sd->right_weapon.sp_drain[RC_NONBOSS].type = val;
  2257. sd->right_weapon.sp_drain[RC_BOSS].rate += type2;
  2258. sd->right_weapon.sp_drain[RC_BOSS].per += type3;
  2259. sd->right_weapon.sp_drain[RC_BOSS].type = val;
  2260. }
  2261. else if(sd->state.lr_flag == 1) {
  2262. sd->left_weapon.sp_drain[RC_NONBOSS].rate += type2;
  2263. sd->left_weapon.sp_drain[RC_NONBOSS].per += type3;
  2264. sd->left_weapon.sp_drain[RC_NONBOSS].type = val;
  2265. sd->left_weapon.sp_drain[RC_BOSS].rate += type2;
  2266. sd->left_weapon.sp_drain[RC_BOSS].per += type3;
  2267. sd->left_weapon.sp_drain[RC_BOSS].type = val;
  2268. }
  2269. break;
  2270. case SP_HP_DRAIN_RATE_RACE:
  2271. if(!sd->state.lr_flag) {
  2272. sd->right_weapon.hp_drain[type2].rate += type3;
  2273. sd->right_weapon.hp_drain[type2].per += val;
  2274. }
  2275. else if(sd->state.lr_flag == 1) {
  2276. sd->left_weapon.hp_drain[type2].rate += type3;
  2277. sd->left_weapon.hp_drain[type2].per += val;
  2278. }
  2279. break;
  2280. case SP_SP_DRAIN_RATE_RACE:
  2281. if(!sd->state.lr_flag) {
  2282. sd->right_weapon.sp_drain[type2].rate += type3;
  2283. sd->right_weapon.sp_drain[type2].per += val;
  2284. }
  2285. else if(sd->state.lr_flag == 1) {
  2286. sd->left_weapon.sp_drain[type2].rate += type3;
  2287. sd->left_weapon.sp_drain[type2].per += val;
  2288. }
  2289. break;
  2290. case SP_ADD_MONSTER_DROP_ITEMGROUP:
  2291. if (sd->state.lr_flag != 2)
  2292. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, 1<<type3, val);
  2293. break;
  2294. case SP_ADDEFF:
  2295. if (type2 > SC_MAX) {
  2296. ShowWarning("pc_bonus3 (Add Effect): %d is not supported.\n", type2);
  2297. break;
  2298. }
  2299. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  2300. sd->state.lr_flag!=2?type3:0, sd->state.lr_flag==2?type3:0, val);
  2301. break;
  2302. case SP_ADDEFF_WHENHIT:
  2303. if (type2 > SC_MAX) {
  2304. ShowWarning("pc_bonus3 (Add Effect when hit): %d is not supported.\n", type2);
  2305. break;
  2306. }
  2307. if(sd->state.lr_flag != 2)
  2308. pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, type3, 0, val);
  2309. break;
  2310. default:
  2311. ShowWarning("pc_bonus3: unknown type %d %d %d %d!\n",type,type2,type3,val);
  2312. break;
  2313. }
  2314. return 0;
  2315. }
  2316. int pc_bonus4(struct map_session_data *sd,int type,int type2,int type3,int type4,int val)
  2317. {
  2318. nullpo_retr(0, sd);
  2319. switch(type){
  2320. case SP_AUTOSPELL:
  2321. if(sd->state.lr_flag != 2)
  2322. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
  2323. break;
  2324. case SP_AUTOSPELL_WHENHIT:
  2325. if(sd->state.lr_flag != 2)
  2326. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
  2327. break;
  2328. default:
  2329. ShowWarning("pc_bonus4: unknown type %d %d %d %d %d!\n",type,type2,type3,type4,val);
  2330. break;
  2331. }
  2332. return 0;
  2333. }
  2334. int pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4,int type5,int val)
  2335. {
  2336. nullpo_retr(0, sd);
  2337. switch(type){
  2338. case SP_AUTOSPELL:
  2339. if(sd->state.lr_flag != 2)
  2340. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  2341. break;
  2342. case SP_AUTOSPELL_WHENHIT:
  2343. if(sd->state.lr_flag != 2)
  2344. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  2345. break;
  2346. default:
  2347. ShowWarning("pc_bonus5: unknown type %d %d %d %d %d %d!\n",type,type2,type3,type4,type5,val);
  2348. break;
  2349. }
  2350. return 0;
  2351. }
  2352. /*==========================================
  2353. * Grants a player a given skill. Flag values are:
  2354. * 0 - Grant skill unconditionally and forever (only this one invokes status_calc_pc,
  2355. * as the other two are assumed to be invoked from within it)
  2356. * 1 - Grant an item skill (temporary)
  2357. * 2 - Like 1, except the level granted can stack with previously learned level.
  2358. *------------------------------------------*/
  2359. int pc_skill(TBL_PC* sd, int id, int level, int flag)
  2360. {
  2361. nullpo_retr(0, sd);
  2362. if( id <= 0 || id >= MAX_SKILL || skill_db[id].name == NULL) {
  2363. ShowError("pc_skill: Skill with id %d does not exist in the skill database\n", id);
  2364. return 0;
  2365. }
  2366. if( level > MAX_SKILL_LEVEL ) {
  2367. ShowError("pc_skill: Skill level %d too high. Max lv supported is %d\n", level, MAX_SKILL_LEVEL);
  2368. return 0;
  2369. }
  2370. switch( flag ){
  2371. case 0: //Set skill data overwriting whatever was there before.
  2372. sd->status.skill[id].id = id;
  2373. sd->status.skill[id].lv = level;
  2374. sd->status.skill[id].flag = 0;
  2375. if( !level ) //Remove skill.
  2376. sd->status.skill[id].id = 0;
  2377. if( !skill_get_inf(id) ) //Only recalculate for passive skills.
  2378. status_calc_pc(sd, 0);
  2379. clif_skillinfoblock(sd);
  2380. break;
  2381. case 2: //Add skill bonus on top of what you had.
  2382. if( sd->status.skill[id].id == id ){
  2383. if( !sd->status.skill[id].flag ) // Store previous level.
  2384. sd->status.skill[id].flag = sd->status.skill[id].lv + 2;
  2385. } else {
  2386. sd->status.skill[id].id = id;
  2387. sd->status.skill[id].flag = 1; //Set that this is a bonus skill.
  2388. }
  2389. sd->status.skill[id].lv += level;
  2390. break;
  2391. case 1: //Item bonus skill.
  2392. if( sd->status.skill[id].lv >= level )
  2393. return 0;
  2394. if( sd->status.skill[id].id == id ){
  2395. if( !sd->status.skill[id].flag ) //Non-granted skill, store it's level.
  2396. sd->status.skill[id].flag = sd->status.skill[id].lv + 2;
  2397. } else {
  2398. sd->status.skill[id].id = id;
  2399. sd->status.skill[id].flag = 1;
  2400. }
  2401. sd->status.skill[id].lv = level;
  2402. break;
  2403. default: //Unknown flag?
  2404. return 0;
  2405. }
  2406. return 1;
  2407. }
  2408. /*==========================================
  2409. * カ?ド?入
  2410. *------------------------------------------*/
  2411. int pc_insert_card(struct map_session_data *sd,int idx_card,int idx_equip)
  2412. {
  2413. int i, ep;
  2414. int nameid, cardid;
  2415. nullpo_retr(0, sd);
  2416. if(idx_card < 0 || idx_card >= MAX_INVENTORY || !sd->inventory_data[idx_card])
  2417. return 0; //Invalid card index.
  2418. if(idx_equip < 0 || idx_equip >= MAX_INVENTORY || !sd->inventory_data[idx_equip])
  2419. return 0; //Invalid item index.
  2420. nameid=sd->status.inventory[idx_equip].nameid;
  2421. cardid=sd->status.inventory[idx_card].nameid;
  2422. ep=sd->inventory_data[idx_card]->equip;
  2423. //Check validity
  2424. if( nameid <= 0 || cardid <= 0 ||
  2425. sd->status.inventory[idx_equip].amount < 1 || //These two should never be required due to pc_delitem zero'ing the data.
  2426. sd->status.inventory[idx_card].amount < 1 ||
  2427. (sd->inventory_data[idx_equip]->type!=IT_WEAPON && sd->inventory_data[idx_equip]->type!=IT_ARMOR)||
  2428. sd->inventory_data[idx_card]->type!=IT_CARD || // Prevent Hack [Ancyker]
  2429. sd->status.inventory[idx_equip].identify==0 ||
  2430. itemdb_isspecial(sd->status.inventory[idx_equip].card[0]) ||
  2431. !(sd->inventory_data[idx_equip]->equip&ep) ||
  2432. (sd->inventory_data[idx_equip]->type==IT_WEAPON && ep==EQP_SHIELD) || //Card shield attempted to place on left-hand weapon.
  2433. sd->status.inventory[idx_equip].equip){
  2434. clif_insert_card(sd,idx_equip,idx_card,1);
  2435. return 0;
  2436. }
  2437. for(i=0;i<sd->inventory_data[idx_equip]->slot;i++){
  2438. if( sd->status.inventory[idx_equip].card[i] == 0)
  2439. { //Free slot found.
  2440. sd->status.inventory[idx_equip].card[i]=cardid;
  2441. clif_insert_card(sd,idx_equip,idx_card,0);
  2442. pc_delitem(sd,idx_card,1,1);
  2443. return 0;
  2444. }
  2445. }
  2446. clif_insert_card(sd,idx_equip,idx_card,1);
  2447. return 0;
  2448. }
  2449. //
  2450. // アイテム物
  2451. //
  2452. /*==========================================
  2453. * スキルによる買い値修正
  2454. *------------------------------------------*/
  2455. int pc_modifybuyvalue(struct map_session_data *sd,int orig_value)
  2456. {
  2457. int skill,val = orig_value,rate1 = 0,rate2 = 0;
  2458. if((skill=pc_checkskill(sd,MC_DISCOUNT))>0) // ディスカウント
  2459. rate1 = 5+skill*2-((skill==10)? 1:0);
  2460. if((skill=pc_checkskill(sd,RG_COMPULSION))>0) // コムパルションディスカウント
  2461. rate2 = 5+skill*4;
  2462. if(rate1 < rate2) rate1 = rate2;
  2463. if(rate1)
  2464. val = (int)((double)orig_value*(double)(100-rate1)/100.);
  2465. if(val < 0) val = 0;
  2466. if(orig_value > 0 && val < 1) val = 1;
  2467. return val;
  2468. }
  2469. /*==========================================
  2470. * スキルによる?り値修正
  2471. *------------------------------------------*/
  2472. int pc_modifysellvalue(struct map_session_data *sd,int orig_value)
  2473. {
  2474. int skill,val = orig_value,rate = 0;
  2475. if((skill=pc_checkskill(sd,MC_OVERCHARGE))>0) // オ?バ?チャ?ジ
  2476. rate = 5+skill*2-((skill==10)? 1:0);
  2477. if(rate)
  2478. val = (int)((double)orig_value*(double)(100+rate)/100.);
  2479. if(val < 0) val = 0;
  2480. if(orig_value > 0 && val < 1) val = 1;
  2481. return val;
  2482. }
  2483. /*==========================================
  2484. * アイテムを買った暫ノ、新しいアイテム欄を使うか、
  2485. * 3万個制限にかかるか確認
  2486. *------------------------------------------*/
  2487. int pc_checkadditem(struct map_session_data *sd,int nameid,int amount)
  2488. {
  2489. int i;
  2490. nullpo_retr(0, sd);
  2491. if(!itemdb_isstackable(nameid))
  2492. return ADDITEM_NEW;
  2493. for(i=0;i<MAX_INVENTORY;i++){
  2494. if(sd->status.inventory[i].nameid==nameid){
  2495. if(sd->status.inventory[i].amount+amount > MAX_AMOUNT)
  2496. return ADDITEM_OVERAMOUNT;
  2497. return ADDITEM_EXIST;
  2498. }
  2499. }
  2500. if(amount > MAX_AMOUNT)
  2501. return ADDITEM_OVERAMOUNT;
  2502. return ADDITEM_NEW;
  2503. }
  2504. /*==========================================
  2505. * 空きアイテム欄の個?
  2506. *------------------------------------------*/
  2507. int pc_inventoryblank(struct map_session_data *sd)
  2508. {
  2509. int i,b;
  2510. nullpo_retr(0, sd);
  2511. for(i=0,b=0;i<MAX_INVENTORY;i++){
  2512. if(sd->status.inventory[i].nameid==0)
  2513. b++;
  2514. }
  2515. return b;
  2516. }
  2517. /*==========================================
  2518. * お金を?う
  2519. *------------------------------------------*/
  2520. int pc_payzeny(struct map_session_data *sd,int zeny)
  2521. {
  2522. nullpo_retr(0, sd);
  2523. if( zeny < 0 )
  2524. return pc_getzeny(sd, -zeny);
  2525. if( sd->status.zeny < zeny )
  2526. return 1; //Not enough.
  2527. sd->status.zeny -= zeny;
  2528. clif_updatestatus(sd,SP_ZENY);
  2529. return 0;
  2530. }
  2531. /*==========================================
  2532. * Cash Shop
  2533. *------------------------------------------*/
  2534. void pc_paycash(struct map_session_data *sd, int price, int points)
  2535. {
  2536. char output[128];
  2537. int cash = price - points;
  2538. nullpo_retv(sd);
  2539. pc_setaccountreg(sd,"#CASHPOINTS",sd->cashPoints - cash);
  2540. pc_setaccountreg(sd,"#KAFRAPOINTS",sd->kafraPoints - points);
  2541. sprintf(output, "Used %d kafra points and %d cash points. %d kafra and %d cash points remaining.", points, cash, sd->kafraPoints, sd->cashPoints);
  2542. clif_disp_onlyself(sd, output, strlen(output));
  2543. }
  2544. void pc_getcash(struct map_session_data *sd, int cash, int points)
  2545. {
  2546. char output[128];
  2547. nullpo_retv(sd);
  2548. if( cash > 0 )
  2549. {
  2550. pc_setaccountreg(sd,"#CASHPOINTS",sd->cashPoints + cash);
  2551. sprintf(output, "Gained %d cash points. Total %d points", cash, sd->cashPoints);
  2552. clif_disp_onlyself(sd, output, strlen(output));
  2553. }
  2554. if( points > 0 )
  2555. {
  2556. pc_setaccountreg(sd,"#KAFRAPOINTS",sd->kafraPoints + points);
  2557. sprintf(output, "Gained %d kafra points. Total %d points", points, sd->kafraPoints);
  2558. clif_disp_onlyself(sd, output, strlen(output));
  2559. }
  2560. }
  2561. /*==========================================
  2562. * お金を得る
  2563. *------------------------------------------*/
  2564. int pc_getzeny(struct map_session_data *sd,int zeny)
  2565. {
  2566. nullpo_retr(0, sd);
  2567. if( zeny < 0 )
  2568. return pc_payzeny(sd, -zeny);
  2569. if( zeny > MAX_ZENY - sd->status.zeny )
  2570. zeny = MAX_ZENY - sd->status.zeny;
  2571. sd->status.zeny += zeny;
  2572. clif_updatestatus(sd,SP_ZENY);
  2573. if( zeny > 0 && sd->state.showzeny )
  2574. {
  2575. char output[255];
  2576. sprintf(output, "Gained %dz.", zeny);
  2577. clif_disp_onlyself(sd,output,strlen(output));
  2578. }
  2579. return 0;
  2580. }
  2581. /*==========================================
  2582. * アイテムを探して、インデックスを返す
  2583. *------------------------------------------*/
  2584. int pc_search_inventory(struct map_session_data *sd,int item_id)
  2585. {
  2586. int i;
  2587. nullpo_retr(-1, sd);
  2588. ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == item_id && (sd->status.inventory[i].amount > 0 || item_id == 0) );
  2589. return ( i < MAX_INVENTORY ) ? i : -1;
  2590. }
  2591. /*==========================================
  2592. * アイテム追加。個?のみitem構造?の?字を無視
  2593. *------------------------------------------*/
  2594. int pc_additem(struct map_session_data *sd,struct item *item_data,int amount)
  2595. {
  2596. struct item_data *data;
  2597. int i;
  2598. unsigned int w;
  2599. nullpo_retr(1, sd);
  2600. nullpo_retr(1, item_data);
  2601. if(item_data->nameid <= 0 || amount <= 0)
  2602. return 1;
  2603. if(amount > MAX_AMOUNT)
  2604. return 5;
  2605. data = itemdb_search(item_data->nameid);
  2606. w = data->weight*amount;
  2607. if(sd->weight + w > sd->max_weight)
  2608. return 2;
  2609. i = MAX_INVENTORY;
  2610. if (itemdb_isstackable2(data))
  2611. { //Stackable
  2612. for (i = 0; i < MAX_INVENTORY; i++)
  2613. {
  2614. if(sd->status.inventory[i].nameid == item_data->nameid &&
  2615. memcmp(&sd->status.inventory[i].card,&item_data->card,
  2616. sizeof(item_data->card))==0)
  2617. {
  2618. if (amount > MAX_AMOUNT - sd->status.inventory[i].amount)
  2619. return 5;
  2620. sd->status.inventory[i].amount += amount;
  2621. clif_additem(sd,i,amount,0);
  2622. break;
  2623. }
  2624. }
  2625. }
  2626. if (i >= MAX_INVENTORY){
  2627. i = pc_search_inventory(sd,0);
  2628. if(i<0) return 4;
  2629. memcpy(&sd->status.inventory[i], item_data, sizeof(sd->status.inventory[0]));
  2630. // clear equips field first, just in case
  2631. if (item_data->equip)
  2632. sd->status.inventory[i].equip = 0;
  2633. sd->status.inventory[i].amount = amount;
  2634. sd->inventory_data[i] = data;
  2635. clif_additem(sd,i,amount,0);
  2636. }
  2637. sd->weight += w;
  2638. clif_updatestatus(sd,SP_WEIGHT);
  2639. //Auto-equip
  2640. if(data->flag.autoequip) pc_equipitem(sd, i, data->equip);
  2641. return 0;
  2642. }
  2643. /*==========================================
  2644. * アイテムを減らす
  2645. *------------------------------------------*/
  2646. int pc_delitem(struct map_session_data *sd,int n,int amount,int type)
  2647. {
  2648. nullpo_retr(1, sd);
  2649. if(sd->status.inventory[n].nameid==0 || amount <= 0 || sd->status.inventory[n].amount<amount || sd->inventory_data[n] == NULL)
  2650. return 1;
  2651. sd->status.inventory[n].amount -= amount;
  2652. sd->weight -= sd->inventory_data[n]->weight*amount ;
  2653. if(sd->status.inventory[n].amount<=0){
  2654. if(sd->status.inventory[n].equip)
  2655. pc_unequipitem(sd,n,3);
  2656. memset(&sd->status.inventory[n],0,sizeof(sd->status.inventory[0]));
  2657. sd->inventory_data[n] = NULL;
  2658. }
  2659. if(!(type&1))
  2660. clif_delitem(sd,n,amount);
  2661. if(!(type&2))
  2662. clif_updatestatus(sd,SP_WEIGHT);
  2663. return 0;
  2664. }
  2665. /*==========================================
  2666. * アイテムを落す
  2667. *------------------------------------------*/
  2668. int pc_dropitem(struct map_session_data *sd,int n,int amount)
  2669. {
  2670. nullpo_retr(1, sd);
  2671. if(n < 0 || n >= MAX_INVENTORY)
  2672. return 0;
  2673. if(amount <= 0)
  2674. return 0;
  2675. if(sd->status.inventory[n].nameid <= 0 ||
  2676. sd->status.inventory[n].amount <= 0 ||
  2677. sd->status.inventory[n].amount < amount ||
  2678. sd->state.trading || sd->vender_id != 0 ||
  2679. !sd->inventory_data[n] //pc_delitem would fail on this case.
  2680. )
  2681. return 0;
  2682. if (map[sd->bl.m].flag.nodrop) {
  2683. clif_displaymessage (sd->fd, msg_txt(271));
  2684. return 0; //Can't drop items in nodrop mapflag maps.
  2685. }
  2686. if (!pc_candrop(sd,&sd->status.inventory[n])) {
  2687. clif_displaymessage (sd->fd, msg_txt(263));
  2688. return 0;
  2689. }
  2690. //Logs items, dropped by (P)layers [Lupus]
  2691. if(log_config.enable_logs&0x8)
  2692. log_pick_pc(sd, "P", sd->status.inventory[n].nameid, -amount, (struct item*)&sd->status.inventory[n]);
  2693. //Logs
  2694. if (!map_addflooritem(&sd->status.inventory[n], amount, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 2))
  2695. return 0;
  2696. pc_delitem(sd, n, amount, 0);
  2697. return 1;
  2698. }
  2699. /*==========================================
  2700. * アイテムを拾う
  2701. *------------------------------------------*/
  2702. int pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem)
  2703. {
  2704. int flag=0;
  2705. unsigned int tick = gettick();
  2706. struct map_session_data *first_sd = NULL,*second_sd = NULL,*third_sd = NULL;
  2707. struct party_data *p=NULL;
  2708. nullpo_retr(0, sd);
  2709. nullpo_retr(0, fitem);
  2710. if(!check_distance_bl(&fitem->bl, &sd->bl, 2) && sd->ud.skillid!=BS_GREED)
  2711. return 0; // 距離が遠い
  2712. if (sd->status.party_id)
  2713. p = party_search(sd->status.party_id);
  2714. if(fitem->first_get_charid > 0 && fitem->first_get_charid != sd->status.char_id)
  2715. {
  2716. first_sd = map_charid2sd(fitem->first_get_charid);
  2717. if(DIFF_TICK(tick,fitem->first_get_tick) < 0) {
  2718. if (!(p && p->party.item&1 &&
  2719. first_sd && first_sd->status.party_id == sd->status.party_id
  2720. ))
  2721. return 0;
  2722. }
  2723. else
  2724. if(fitem->second_get_charid > 0 && fitem->second_get_charid != sd->status.char_id)
  2725. {
  2726. second_sd = map_charid2sd(fitem->second_get_charid);
  2727. if(DIFF_TICK(tick, fitem->second_get_tick) < 0) {
  2728. if(!(p && p->party.item&1 &&
  2729. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  2730. (second_sd && second_sd->status.party_id == sd->status.party_id))
  2731. ))
  2732. return 0;
  2733. }
  2734. else
  2735. if(fitem->third_get_charid > 0 && fitem->third_get_charid != sd->status.char_id)
  2736. {
  2737. third_sd = map_charid2sd(fitem->third_get_charid);
  2738. if(DIFF_TICK(tick,fitem->third_get_tick) < 0) {
  2739. if(!(p && p->party.item&1 &&
  2740. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  2741. (second_sd && second_sd->status.party_id == sd->status.party_id) ||
  2742. (third_sd && third_sd->status.party_id == sd->status.party_id))
  2743. ))
  2744. return 0;
  2745. }
  2746. }
  2747. }
  2748. }
  2749. //This function takes care of giving the item to whoever should have it, considering party-share options.
  2750. if ((flag = party_share_loot(p,sd,&fitem->item_data, fitem->first_get_charid))) {
  2751. clif_additem(sd,0,0,flag);
  2752. return 1;
  2753. }
  2754. //Display pickup animation.
  2755. pc_stop_attack(sd);
  2756. clif_takeitem(&sd->bl,&fitem->bl);
  2757. map_clearflooritem(fitem->bl.id);
  2758. return 1;
  2759. }
  2760. int pc_isUseitem(struct map_session_data *sd,int n)
  2761. {
  2762. struct item_data *item;
  2763. int nameid;
  2764. nullpo_retr(0, sd);
  2765. item = sd->inventory_data[n];
  2766. nameid = sd->status.inventory[n].nameid;
  2767. if( item == NULL )
  2768. return 0;
  2769. //Not consumable item
  2770. if( item->type != IT_HEALING && item->type != IT_USABLE )
  2771. return 0;
  2772. if( !item->script ) //if it has no script, you can't really consume it!
  2773. return 0;
  2774. switch( nameid )
  2775. {
  2776. case 605: // Anodyne
  2777. if( map_flag_gvg(sd->bl.m) )
  2778. return 0;
  2779. case 606:
  2780. if( pc_issit(sd) )
  2781. return 0;
  2782. break;
  2783. case 601: // Fly Wing
  2784. case 12212: // Giant Fly Wing
  2785. if( map[sd->bl.m].flag.noteleport || map_flag_gvg(sd->bl.m) )
  2786. {
  2787. clif_skill_teleportmessage(sd,0);
  2788. return 0;
  2789. }
  2790. case 602: // ButterFly Wing
  2791. case 14527: // Dungeon Teleport Scroll
  2792. case 14581: // Dungeon Teleport Scroll
  2793. case 14582: // Yellow Butterfly Wing
  2794. case 14583: // Green Butterfly Wing
  2795. case 14584: // Red Butterfly Wing
  2796. case 14585: // Blue Butterfly Wing
  2797. case 14591: // Siege Teleport Scroll
  2798. if( sd->duel_group && !battle_config.duel_allow_teleport )
  2799. {
  2800. clif_displaymessage(sd->fd, "Duel: Can't use this item in duel.");
  2801. return 0;
  2802. }
  2803. if( nameid != 601 && nameid != 12212 && map[sd->bl.m].flag.noreturn )
  2804. return 0;
  2805. break;
  2806. case 604: // Dead Branch
  2807. case 12024: // Red Pouch
  2808. case 12103: // Bloody Branch
  2809. case 12109: // Poring Box
  2810. if( map[sd->bl.m].flag.nobranch || map_flag_gvg(sd->bl.m) )
  2811. return 0;
  2812. break;
  2813. case 12210: // Bubble Gum
  2814. case 12264: // Comp Bubble Gum
  2815. if( sd->sc.data[SC_ITEMBOOST] )
  2816. return 0;
  2817. break;
  2818. case 12208: // Battle Manual
  2819. case 12263: // Comp Battle Manual
  2820. case 12312: // Thick Battle Manual
  2821. case 12705: // Noble Nameplate
  2822. case 14532: // Battle_Manual25
  2823. case 14533: // Battle_Manual100
  2824. case 14545: // Battle_Manual300
  2825. if( sd->sc.data[SC_EXPBOOST] )
  2826. return 0;
  2827. break;
  2828. // Mercenary Items
  2829. case 12184: // Mercenary's Red Potion
  2830. case 12185: // Mercenary's Blue Potion
  2831. case 12241: // Mercenary's Concentration Potion
  2832. case 12242: // Mercenary's Awakening Potion
  2833. case 12243: // Mercenary's Berserk Potion
  2834. if( sd->md == NULL || sd->md->db == NULL )
  2835. return 0;
  2836. if( sd->md->sc.data[SC_BERSERK] )
  2837. return 0;
  2838. if( nameid == 12242 && sd->md->db->lv < 40 )
  2839. return 0;
  2840. if( nameid == 12243 && sd->md->db->lv < 80 )
  2841. return 0;
  2842. break;
  2843. }
  2844. if( nameid >= 12153 && nameid <= 12182 && sd->md != NULL )
  2845. return 0; // Mercenary Scrolls
  2846. //added item_noequip.txt items check by Maya&[Lupus]
  2847. if (
  2848. (map[sd->bl.m].flag.pvp && item->flag.no_equip&1) || // PVP
  2849. (map_flag_gvg(sd->bl.m) && item->flag.no_equip&2) || // GVG
  2850. (map[sd->bl.m].flag.restricted && item->flag.no_equip&map[sd->bl.m].zone) // Zone restriction
  2851. )
  2852. return 0;
  2853. //Gender check
  2854. if(item->sex != 2 && sd->status.sex != item->sex)
  2855. return 0;
  2856. //Required level check
  2857. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  2858. return 0;
  2859. //Not equipable by class. [Skotlex]
  2860. if (!(
  2861. (1<<(sd->class_&MAPID_BASEMASK)) &
  2862. (item->class_base[sd->class_&JOBL_2_1?1:(sd->class_&JOBL_2_2?2:0)])
  2863. ))
  2864. return 0;
  2865. //Not usable by upper class. [Skotlex]
  2866. if(!(
  2867. (1<<(sd->class_&JOBL_UPPER?1:(sd->class_&JOBL_BABY?2:0))) &
  2868. item->class_upper
  2869. ))
  2870. return 0;
  2871. //Dead Branch & Bloody Branch & Porings Box
  2872. if((log_config.branch > 0) && (nameid == 604 || nameid == 12103 || nameid == 12109))
  2873. log_branch(sd);
  2874. return 1;
  2875. }
  2876. /*==========================================
  2877. * アイテムを使う
  2878. *------------------------------------------*/
  2879. int pc_useitem(struct map_session_data *sd,int n)
  2880. {
  2881. unsigned int tick = gettick();
  2882. int amount;
  2883. struct script_code *script;
  2884. nullpo_retr(0, sd);
  2885. if(sd->status.inventory[n].nameid <= 0 ||
  2886. sd->status.inventory[n].amount <= 0)
  2887. return 0;
  2888. if(!pc_isUseitem(sd,n))
  2889. return 0;
  2890. //Prevent mass item usage. [Skotlex]
  2891. if(DIFF_TICK(sd->canuseitem_tick, tick) > 0)
  2892. return 0;
  2893. if (sd->sc.count && (
  2894. sd->sc.data[SC_BERSERK] ||
  2895. sd->sc.data[SC_MARIONETTE] ||
  2896. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF) ||
  2897. sd->sc.data[SC_TRICKDEAD] ||
  2898. sd->sc.data[SC_BLADESTOP] ||
  2899. sd->sc.data[SC_HIDING] ||
  2900. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  2901. ))
  2902. return 0;
  2903. //Since most delay-consume items involve using a "skill-type" target cursor,
  2904. //perform a skill-use check before going through. [Skotlex]
  2905. //resurrection was picked as testing skill, as a non-offensive, generic skill, it will do.
  2906. if (sd->inventory_data[n]->flag.delay_consume && (
  2907. sd->ud.skilltimer != -1 ||
  2908. DIFF_TICK(tick, sd->ud.canact_tick) < 0 ||
  2909. !status_check_skilluse(&sd->bl, &sd->bl, ALL_RESURRECTION, 0)))
  2910. return 0;
  2911. sd->itemid = sd->status.inventory[n].nameid;
  2912. sd->itemindex = n;
  2913. if(sd->catch_target_class != -1) //Abort pet catching.
  2914. sd->catch_target_class = -1;
  2915. amount = sd->status.inventory[n].amount;
  2916. script = sd->inventory_data[n]->script;
  2917. //Check if the item is to be consumed immediately [Skotlex]
  2918. if (sd->inventory_data[n]->flag.delay_consume)
  2919. clif_useitemack(sd,n,amount,1);
  2920. else {
  2921. clif_useitemack(sd,n,amount-1,1);
  2922. //Logs (C)onsumable items [Lupus]
  2923. if(log_config.enable_logs&0x100)
  2924. log_pick_pc(sd, "C", sd->status.inventory[n].nameid, -1, &sd->status.inventory[n]);
  2925. //Logs
  2926. pc_delitem(sd,n,1,1);
  2927. }
  2928. if(sd->status.inventory[n].card[0]==CARD0_CREATE &&
  2929. pc_famerank(MakeDWord(sd->status.inventory[n].card[2],sd->status.inventory[n].card[3]), MAPID_ALCHEMIST))
  2930. {
  2931. potion_flag = 2; // Famous player's potions have 50% more efficiency
  2932. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_ROGUE)
  2933. potion_flag = 3; //Even more effective potions.
  2934. }
  2935. sd->canuseitem_tick= tick + battle_config.item_use_interval; //Update item use time.
  2936. run_script(script,0,sd->bl.id,fake_nd->bl.id);
  2937. potion_flag = 0;
  2938. return 1;
  2939. }
  2940. /*==========================================
  2941. * カ?トアイテム追加。個?のみitem構造?の?字を無視
  2942. *------------------------------------------*/
  2943. int pc_cart_additem(struct map_session_data *sd,struct item *item_data,int amount)
  2944. {
  2945. struct item_data *data;
  2946. int i,w;
  2947. nullpo_retr(1, sd);
  2948. nullpo_retr(1, item_data);
  2949. if(item_data->nameid <= 0 || amount <= 0)
  2950. return 1;
  2951. data = itemdb_search(item_data->nameid);
  2952. if(!itemdb_cancartstore(item_data, pc_isGM(sd)))
  2953. { //Check item trade restrictions [Skotlex]
  2954. clif_displaymessage (sd->fd, msg_txt(264));
  2955. return 1;
  2956. }
  2957. if((w=data->weight*amount) + sd->cart_weight > battle_config.max_cart_weight)
  2958. return 1;
  2959. i=MAX_CART;
  2960. if(itemdb_isstackable2(data))
  2961. {
  2962. ARR_FIND( 0, MAX_CART, i,
  2963. sd->status.cart[i].nameid == item_data->nameid &&
  2964. sd->status.cart[i].card[0] == item_data->card[0] && sd->status.cart[i].card[1] == item_data->card[1] &&
  2965. sd->status.cart[i].card[2] == item_data->card[2] && sd->status.cart[i].card[3] == item_data->card[3] );
  2966. };
  2967. if( i < MAX_CART )
  2968. {// item already in cart, stack it
  2969. if(sd->status.cart[i].amount+amount > MAX_AMOUNT)
  2970. return 1; // no room
  2971. sd->status.cart[i].amount+=amount;
  2972. clif_cart_additem(sd,i,amount,0);
  2973. }
  2974. else
  2975. {// item not stackable or not present, add it
  2976. ARR_FIND( 0, MAX_CART, i, sd->status.cart[i].nameid == 0 );
  2977. if( i == MAX_CART )
  2978. return 1; // no room
  2979. memcpy(&sd->status.cart[i],item_data,sizeof(sd->status.cart[0]));
  2980. sd->status.cart[i].amount=amount;
  2981. sd->cart_num++;
  2982. clif_cart_additem(sd,i,amount,0);
  2983. }
  2984. sd->cart_weight += w;
  2985. clif_updatestatus(sd,SP_CARTINFO);
  2986. return 0;
  2987. }
  2988. /*==========================================
  2989. * カ?トアイテムを減らす
  2990. *------------------------------------------*/
  2991. int pc_cart_delitem(struct map_session_data *sd,int n,int amount,int type)
  2992. {
  2993. nullpo_retr(1, sd);
  2994. if(sd->status.cart[n].nameid==0 ||
  2995. sd->status.cart[n].amount<amount)
  2996. return 1;
  2997. sd->status.cart[n].amount -= amount;
  2998. sd->cart_weight -= itemdb_weight(sd->status.cart[n].nameid)*amount ;
  2999. if(sd->status.cart[n].amount <= 0){
  3000. memset(&sd->status.cart[n],0,sizeof(sd->status.cart[0]));
  3001. sd->cart_num--;
  3002. }
  3003. if(!type) {
  3004. clif_cart_delitem(sd,n,amount);
  3005. clif_updatestatus(sd,SP_CARTINFO);
  3006. }
  3007. return 0;
  3008. }
  3009. /*==========================================
  3010. * カ?トへアイテム移動
  3011. *------------------------------------------*/
  3012. int pc_putitemtocart(struct map_session_data *sd,int idx,int amount)
  3013. {
  3014. struct item *item_data;
  3015. nullpo_retr(0, sd);
  3016. if (idx < 0 || idx >= MAX_INVENTORY) //Invalid index check [Skotlex]
  3017. return 1;
  3018. item_data = &sd->status.inventory[idx];
  3019. if (item_data->nameid==0 || amount < 1 || item_data->amount<amount || sd->vender_id)
  3020. return 1;
  3021. if (pc_cart_additem(sd,item_data,amount) == 0)
  3022. return pc_delitem(sd,idx,amount,0);
  3023. return 1;
  3024. }
  3025. /*==========================================
  3026. * カ?ト?のアイテム?確認(個?の差分を返す)
  3027. *------------------------------------------*/
  3028. int pc_cartitem_amount(struct map_session_data* sd, int idx, int amount)
  3029. {
  3030. struct item* item_data;
  3031. nullpo_retr(-1, sd);
  3032. item_data = &sd->status.cart[idx];
  3033. if( item_data->nameid == 0 || item_data->amount == 0 )
  3034. return -1;
  3035. return item_data->amount - amount;
  3036. }
  3037. /*==========================================
  3038. * カ?トからアイテム移動
  3039. *------------------------------------------*/
  3040. int pc_getitemfromcart(struct map_session_data *sd,int idx,int amount)
  3041. {
  3042. struct item *item_data;
  3043. int flag;
  3044. nullpo_retr(0, sd);
  3045. if (idx < 0 || idx >= MAX_CART) //Invalid index check [Skotlex]
  3046. return 1;
  3047. item_data=&sd->status.cart[idx];
  3048. if(item_data->nameid==0 || amount < 1 || item_data->amount<amount || sd->vender_id )
  3049. return 1;
  3050. if((flag = pc_additem(sd,item_data,amount)) == 0)
  3051. return pc_cart_delitem(sd,idx,amount,0);
  3052. clif_additem(sd,0,0,flag);
  3053. return 1;
  3054. }
  3055. /*==========================================
  3056. * スティル品公開
  3057. *------------------------------------------*/
  3058. int pc_show_steal(struct block_list *bl,va_list ap)
  3059. {
  3060. struct map_session_data *sd;
  3061. int itemid;
  3062. struct item_data *item=NULL;
  3063. char output[100];
  3064. sd=va_arg(ap,struct map_session_data *);
  3065. itemid=va_arg(ap,int);
  3066. if((item=itemdb_exists(itemid))==NULL)
  3067. sprintf(output,"%s stole an Unknown Item (id: %i).",sd->status.name, itemid);
  3068. else
  3069. sprintf(output,"%s stole %s.",sd->status.name,item->jname);
  3070. clif_displaymessage( ((struct map_session_data *)bl)->fd, output);
  3071. return 0;
  3072. }
  3073. /*==========================================
  3074. *
  3075. *------------------------------------------*/
  3076. int pc_steal_item(struct map_session_data *sd,struct block_list *bl, int lv)
  3077. {
  3078. int i,itemid,flag;
  3079. double rate;
  3080. struct status_data *sd_status, *md_status;
  3081. struct mob_data *md;
  3082. struct item tmp_item;
  3083. if(!sd || !bl || bl->type!=BL_MOB)
  3084. return 0;
  3085. md = (TBL_MOB *)bl;
  3086. if(md->state.steal_flag == UCHAR_MAX || md->sc.opt1) //already stolen from / status change check
  3087. return 0;
  3088. sd_status= status_get_status_data(&sd->bl);
  3089. md_status= status_get_status_data(bl);
  3090. if( md->master_id || md_status->mode&MD_BOSS ||
  3091. (md->class_ >= 1324 && md->class_ < 1364) || // Treasure Boxes WoE
  3092. (md->class_ >= 1938 && md->class_ < 1946) || // Treasure Boxes WoE SE
  3093. map[bl->m].flag.nomobloot || // check noloot map flag [Lorky]
  3094. (battle_config.skill_steal_max_tries && //Reached limit of steal attempts. [Lupus]
  3095. md->state.steal_flag++ >= battle_config.skill_steal_max_tries)
  3096. ) { //Can't steal from
  3097. md->state.steal_flag = UCHAR_MAX;
  3098. return 0;
  3099. }
  3100. // base skill success chance (percentual)
  3101. rate = (sd_status->dex - md_status->dex)/2 + lv*6 + 4;
  3102. rate += sd->add_steal_rate;
  3103. if( rate < 1 )
  3104. return 0;
  3105. // Try dropping one item, in the order from first to last possible slot.
  3106. // Droprate is affected by the skill success rate.
  3107. for( i = 0; i < MAX_STEAL_DROP; i++ )
  3108. if( md->db->dropitem[i].nameid > 0 && itemdb_exists(md->db->dropitem[i].nameid) && rand() % 10000 < md->db->dropitem[i].p * rate/100. )
  3109. break;
  3110. if( i == MAX_STEAL_DROP )
  3111. return 0;
  3112. itemid = md->db->dropitem[i].nameid;
  3113. memset(&tmp_item,0,sizeof(tmp_item));
  3114. tmp_item.nameid = itemid;
  3115. tmp_item.amount = 1;
  3116. tmp_item.identify = itemdb_isidentified(itemid);
  3117. flag = pc_additem(sd,&tmp_item,1);
  3118. //TODO: Should we disable stealing when the item you stole couldn't be added to your inventory? Perhaps players will figure out a way to exploit this behaviour otherwise?
  3119. md->state.steal_flag = UCHAR_MAX; //you can't steal from this mob any more
  3120. if(flag) { //Failed to steal due to overweight
  3121. clif_additem(sd,0,0,flag);
  3122. return 0;
  3123. }
  3124. if(battle_config.show_steal_in_same_party)
  3125. party_foreachsamemap(pc_show_steal,sd,AREA_SIZE,sd,tmp_item.nameid);
  3126. //Logs items, Stolen from mobs [Lupus]
  3127. if(log_config.enable_logs&0x80) {
  3128. log_pick_mob(md, "M", itemid, -1, NULL);
  3129. log_pick_pc(sd, "P", itemid, 1, NULL);
  3130. }
  3131. //A Rare Steal Global Announce by Lupus
  3132. if(md->db->dropitem[i].p<=battle_config.rare_drop_announce) {
  3133. struct item_data *i_data;
  3134. char message[128];
  3135. i_data = itemdb_search(itemid);
  3136. sprintf (message, msg_txt(542), (sd->status.name != NULL)?sd->status.name :"GM", md->db->jname, i_data->jname, (float)md->db->dropitem[i].p/100);
  3137. //MSG: "'%s' stole %s's %s (chance: %0.02f%%)"
  3138. intif_GMmessage(message,strlen(message)+1,0);
  3139. }
  3140. return 1;
  3141. }
  3142. /*==========================================
  3143. *
  3144. *------------------------------------------*/
  3145. int pc_steal_coin(struct map_session_data *sd,struct block_list *target)
  3146. {
  3147. int rate,skill;
  3148. struct mob_data *md;
  3149. if(!sd || !target || target->type != BL_MOB)
  3150. return 0;
  3151. md = (TBL_MOB*)target;
  3152. if( md->state.steal_coin_flag || md->sc.data[SC_STONE] || md->sc.data[SC_FREEZE] )
  3153. return 0;
  3154. if( (md->class_ >= 1324 && md->class_ < 1364) || (md->class_ >= 1938 && md->class_ < 1946) )
  3155. return 0;
  3156. skill = pc_checkskill(sd,RG_STEALCOIN)*10;
  3157. rate = skill + (sd->status.base_level - md->level)*3 + sd->battle_status.dex*2 + sd->battle_status.luk*2;
  3158. if(rand()%1000 < rate) {
  3159. pc_getzeny(sd,md->level*10 + rand()%100);
  3160. md->state.steal_coin_flag = 1;
  3161. return 1;
  3162. }
  3163. return 0;
  3164. }
  3165. /*==========================================
  3166. * Set's a player position.
  3167. * Return values:
  3168. * 0 - Success.
  3169. * 1 - Invalid map index.
  3170. * 2 - Map not in this map-server, and failed to locate alternate map-server.
  3171. *------------------------------------------*/
  3172. int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, uint8 clrtype)
  3173. {
  3174. int m;
  3175. nullpo_retr(0, sd);
  3176. if (!mapindex || !mapindex_id2name(mapindex)) {
  3177. ShowDebug("pc_setpos: Passed mapindex(%d) is invalid!\n", mapindex);
  3178. return 1;
  3179. }
  3180. sd->state.changemap = (sd->mapindex != mapindex);
  3181. if( sd->state.changemap )
  3182. { //Misc map-changing settings
  3183. if (sd->sc.count)
  3184. { //Cancel some map related stuff.
  3185. if (sd->sc.data[SC_JAILED])
  3186. return 1; //You may not get out!
  3187. if (sd->sc.data[SC_BOSSMAPINFO])
  3188. status_change_end(&sd->bl,SC_BOSSMAPINFO,-1);
  3189. if (sd->sc.data[SC_WARM])
  3190. status_change_end(&sd->bl,SC_WARM,-1);
  3191. if (sd->sc.data[SC_SUN_COMFORT])
  3192. status_change_end(&sd->bl,SC_SUN_COMFORT,-1);
  3193. if (sd->sc.data[SC_MOON_COMFORT])
  3194. status_change_end(&sd->bl,SC_MOON_COMFORT,-1);
  3195. if (sd->sc.data[SC_STAR_COMFORT])
  3196. status_change_end(&sd->bl,SC_STAR_COMFORT,-1);
  3197. if (sd->sc.data[SC_KNOWLEDGE]) {
  3198. struct status_change_entry *sce = sd->sc.data[SC_KNOWLEDGE];
  3199. if (sce->timer != -1)
  3200. delete_timer(sce->timer, status_change_timer);
  3201. sce->timer = add_timer(gettick() + skill_get_time(SG_KNOWLEDGE, sce->val1), status_change_timer, sd->bl.id, SC_KNOWLEDGE);
  3202. }
  3203. }
  3204. if (battle_config.clear_unit_onwarp&BL_PC)
  3205. skill_clear_unitgroup(&sd->bl);
  3206. party_send_dot_remove(sd); //minimap dot fix [Kevin]
  3207. guild_send_dot_remove(sd);
  3208. if (sd->regen.state.gc)
  3209. sd->regen.state.gc = 0;
  3210. }
  3211. m=map_mapindex2mapid(mapindex);
  3212. if(m<0) {
  3213. uint32 ip;
  3214. uint16 port;
  3215. //if can't find any map-servers, just abort setting position.
  3216. if(!sd->mapindex || map_mapname2ipport(mapindex,&ip,&port))
  3217. return 2;
  3218. //remove from map, THEN change x/y coordinates
  3219. unit_remove_map_pc(sd,clrtype);
  3220. sd->mapindex = mapindex;
  3221. sd->bl.x=x;
  3222. sd->bl.y=y;
  3223. pc_clean_skilltree(sd);
  3224. chrif_save(sd,2);
  3225. chrif_changemapserver(sd, ip, (short)port);
  3226. //Free session data from this map server [Kevin]
  3227. unit_free_pc(sd);
  3228. return 0;
  3229. }
  3230. if( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys )
  3231. {
  3232. ShowError("pc_setpos: attempt to place player %s (%d:%d) on invalid coordinates (%s-%d,%d)\n", sd->status.name, sd->status.account_id, sd->status.char_id, mapindex_id2name(mapindex),x,y);
  3233. x = y = 0; // make it random
  3234. }
  3235. if( x == 0 && y == 0 )
  3236. {// pick a random walkable cell
  3237. do {
  3238. x=rand()%(map[m].xs-2)+1;
  3239. y=rand()%(map[m].ys-2)+1;
  3240. } while(map_getcell(m,x,y,CELL_CHKNOPASS));
  3241. }
  3242. if(sd->bl.prev != NULL){
  3243. unit_remove_map_pc(sd,clrtype);
  3244. clif_changemap(sd,map[m].index,x,y); // [MouseJstr]
  3245. } else if(sd->state.active)
  3246. //Tag player for rewarping after map-loading is done. [Skotlex]
  3247. sd->state.rewarp = 1;
  3248. sd->mapindex = mapindex;
  3249. sd->bl.m = m;
  3250. sd->bl.x = sd->ud.to_x = x;
  3251. sd->bl.y = sd->ud.to_y = y;
  3252. if( sd->status.guild_id > 0 && map[m].flag.gvg_castle )
  3253. { // Increased guild castle regen [Valaris]
  3254. struct guild_castle *gc = guild_mapindex2gc(sd->mapindex);
  3255. if(gc && gc->guild_id == sd->status.guild_id)
  3256. sd->regen.state.gc = 1;
  3257. }
  3258. if( sd->status.pet_id > 0 && sd->pd && sd->pd->pet.intimate > 0 )
  3259. {
  3260. sd->pd->bl.m = m;
  3261. sd->pd->bl.x = sd->pd->ud.to_x = x;
  3262. sd->pd->bl.y = sd->pd->ud.to_y = y;
  3263. sd->pd->ud.dir = sd->ud.dir;
  3264. }
  3265. if( merc_is_hom_active(sd->hd) )
  3266. {
  3267. sd->hd->bl.m = m;
  3268. sd->hd->bl.x = sd->hd->ud.to_x = x;
  3269. sd->hd->bl.y = sd->hd->ud.to_y = y;
  3270. sd->hd->ud.dir = sd->ud.dir;
  3271. }
  3272. if( sd->md )
  3273. {
  3274. sd->md->bl.m = m;
  3275. sd->md->bl.x = sd->md->ud.to_x = x;
  3276. sd->md->bl.y = sd->md->ud.to_y = y;
  3277. sd->md->ud.dir = sd->ud.dir;
  3278. }
  3279. return 0;
  3280. }
  3281. /*==========================================
  3282. * PCのランダムワ?プ
  3283. *------------------------------------------*/
  3284. int pc_randomwarp(struct map_session_data *sd, int type)
  3285. {
  3286. int x,y,i=0;
  3287. int m;
  3288. nullpo_retr(0, sd);
  3289. m=sd->bl.m;
  3290. if (map[sd->bl.m].flag.noteleport) // テレポ?ト禁止
  3291. return 0;
  3292. do{
  3293. x=rand()%(map[m].xs-2)+1;
  3294. y=rand()%(map[m].ys-2)+1;
  3295. }while(map_getcell(m,x,y,CELL_CHKNOPASS) && (i++)<1000 );
  3296. if (i < 1000)
  3297. return pc_setpos(sd,map[sd->bl.m].index,x,y,type);
  3298. return 0;
  3299. }
  3300. /*==========================================
  3301. * Records a memo point at sd's current position
  3302. * pos - entry to replace, (-1: shift oldest entry out)
  3303. *------------------------------------------*/
  3304. int pc_memo(struct map_session_data* sd, int pos)
  3305. {
  3306. int skill;
  3307. nullpo_retr(0, sd);
  3308. // check mapflags
  3309. if( sd->bl.m >= 0 && (map[sd->bl.m].flag.nomemo || map[sd->bl.m].flag.nowarpto) && battle_config.any_warp_GM_min_level > pc_isGM(sd) ) {
  3310. clif_skill_teleportmessage(sd, 1); // "Saved point cannot be memorized."
  3311. return 0;
  3312. }
  3313. // check inputs
  3314. if( pos < -1 || pos >= MAX_MEMOPOINTS )
  3315. return 0; // invalid input
  3316. // check required skill level
  3317. skill = pc_checkskill(sd, AL_WARP);
  3318. if( skill < 1 ) {
  3319. clif_skill_memomessage(sd,2); // "You haven't learned Warp."
  3320. return 0;
  3321. }
  3322. if( skill < 2 || skill - 2 < pos ) {
  3323. clif_skill_memomessage(sd,1); // "Skill Level is not high enough."
  3324. return 0;
  3325. }
  3326. if( pos == -1 )
  3327. {
  3328. int i;
  3329. // prevent memo-ing the same map multiple times
  3330. ARR_FIND( 0, MAX_MEMOPOINTS, i, sd->status.memo_point[i].map == map_id2index(sd->bl.m) );
  3331. memmove(&sd->status.memo_point[1], &sd->status.memo_point[0], (min(i,MAX_MEMOPOINTS-1))*sizeof(struct point));
  3332. pos = 0;
  3333. }
  3334. sd->status.memo_point[pos].map = map_id2index(sd->bl.m);
  3335. sd->status.memo_point[pos].x = sd->bl.x;
  3336. sd->status.memo_point[pos].y = sd->bl.y;
  3337. clif_skill_memomessage(sd, 0);
  3338. return 1;
  3339. }
  3340. //
  3341. // 武器??
  3342. //
  3343. /*==========================================
  3344. * スキルの?索 所有していた場合Lvが返る
  3345. *------------------------------------------*/
  3346. int pc_checkskill(struct map_session_data *sd,int skill_id)
  3347. {
  3348. if(sd == NULL) return 0;
  3349. if( skill_id>=GD_SKILLBASE){
  3350. struct guild *g;
  3351. if( sd->status.guild_id>0 && (g=guild_search(sd->status.guild_id))!=NULL)
  3352. return guild_checkskill(g,skill_id);
  3353. return 0;
  3354. }
  3355. if(sd->status.skill[skill_id].id == skill_id)
  3356. return (sd->status.skill[skill_id].lv);
  3357. return 0;
  3358. }
  3359. /*==========================================
  3360. * 武器?更によるスキルの??チェック
  3361. * 引?:
  3362. * struct map_session_data *sd セッションデ?タ
  3363. * int nameid ?備品ID
  3364. * 返り値:
  3365. * 0 ?更なし
  3366. * -1 スキルを解除
  3367. *------------------------------------------*/
  3368. int pc_checkallowskill(struct map_session_data *sd)
  3369. {
  3370. const enum sc_type scw_list[] = {
  3371. SC_TWOHANDQUICKEN,
  3372. SC_ONEHAND,
  3373. SC_AURABLADE,
  3374. SC_PARRYING,
  3375. SC_SPEARQUICKEN,
  3376. SC_ADRENALINE,
  3377. SC_ADRENALINE2,
  3378. SC_GATLINGFEVER
  3379. };
  3380. const enum sc_type scs_list[] = {
  3381. SC_AUTOGUARD,
  3382. SC_DEFENDER,
  3383. SC_REFLECTSHIELD
  3384. };
  3385. int i;
  3386. nullpo_retr(0, sd);
  3387. if(!sd->sc.count)
  3388. return 0;
  3389. for (i = 0; i < ARRAYLENGTH(scw_list); i++)
  3390. { // Skills requiring specific weapon types
  3391. if(sd->sc.data[scw_list[i]] &&
  3392. !pc_check_weapontype(sd,skill_get_weapontype(status_sc2skill(scw_list[i]))))
  3393. status_change_end(&sd->bl,scw_list[i],-1);
  3394. }
  3395. if(sd->sc.data[SC_SPURT] && sd->status.weapon)
  3396. // Spurt requires bare hands (feet, in fact xD)
  3397. status_change_end(&sd->bl,SC_SPURT,-1);
  3398. if(sd->status.shield <= 0) { // Skills requiring a shield
  3399. for (i = 0; i < ARRAYLENGTH(scs_list); i++)
  3400. if(sd->sc.data[scs_list[i]])
  3401. status_change_end(&sd->bl,scs_list[i],-1);
  3402. }
  3403. return 0;
  3404. }
  3405. /*==========================================
  3406. * ? 備品のチェック
  3407. *------------------------------------------*/
  3408. int pc_checkequip(struct map_session_data *sd,int pos)
  3409. {
  3410. int i;
  3411. nullpo_retr(-1, sd);
  3412. for(i=0;i<EQI_MAX;i++){
  3413. if(pos & equip_pos[i])
  3414. return sd->equip_index[i];
  3415. }
  3416. return -1;
  3417. }
  3418. /*==========================================
  3419. * Convert's from the client's lame Job ID system
  3420. * to the map server's 'makes sense' system. [Skotlex]
  3421. *------------------------------------------*/
  3422. int pc_jobid2mapid(unsigned short b_class)
  3423. {
  3424. int class_ = 0;
  3425. if (b_class >= JOB_BABY && b_class <= JOB_SUPER_BABY)
  3426. {
  3427. if (b_class == JOB_SUPER_BABY)
  3428. b_class = JOB_SUPER_NOVICE;
  3429. else
  3430. b_class -= JOB_BABY;
  3431. class_|= JOBL_BABY;
  3432. }
  3433. else if (b_class >= JOB_NOVICE_HIGH && b_class <= JOB_PALADIN2)
  3434. {
  3435. b_class -= JOB_NOVICE_HIGH;
  3436. class_|= JOBL_UPPER;
  3437. }
  3438. if (b_class >= JOB_KNIGHT && b_class <= JOB_KNIGHT2)
  3439. class_|= JOBL_2_1;
  3440. else if (b_class >= JOB_CRUSADER && b_class <= JOB_CRUSADER2)
  3441. class_|= JOBL_2_2;
  3442. switch (b_class)
  3443. {
  3444. case JOB_NOVICE:
  3445. case JOB_SWORDMAN:
  3446. case JOB_MAGE:
  3447. case JOB_ARCHER:
  3448. case JOB_ACOLYTE:
  3449. case JOB_MERCHANT:
  3450. case JOB_THIEF:
  3451. class_ |= b_class;
  3452. break;
  3453. case JOB_KNIGHT:
  3454. case JOB_KNIGHT2:
  3455. case JOB_CRUSADER:
  3456. case JOB_CRUSADER2:
  3457. class_ |= MAPID_SWORDMAN;
  3458. break;
  3459. case JOB_PRIEST:
  3460. case JOB_MONK:
  3461. class_ |= MAPID_ACOLYTE;
  3462. break;
  3463. case JOB_WIZARD:
  3464. case JOB_SAGE:
  3465. class_ |= MAPID_MAGE;
  3466. break;
  3467. case JOB_BLACKSMITH:
  3468. case JOB_ALCHEMIST:
  3469. class_ |= MAPID_MERCHANT;
  3470. break;
  3471. case JOB_HUNTER:
  3472. case JOB_BARD:
  3473. case JOB_DANCER:
  3474. class_ |= MAPID_ARCHER;
  3475. break;
  3476. case JOB_ASSASSIN:
  3477. case JOB_ROGUE:
  3478. class_ |= MAPID_THIEF;
  3479. break;
  3480. case JOB_STAR_GLADIATOR:
  3481. case JOB_STAR_GLADIATOR2:
  3482. class_ |= JOBL_2_1;
  3483. class_ |= MAPID_TAEKWON;
  3484. break;
  3485. case JOB_SOUL_LINKER:
  3486. class_ |= JOBL_2_2;
  3487. case JOB_TAEKWON:
  3488. class_ |= MAPID_TAEKWON;
  3489. break;
  3490. case JOB_WEDDING:
  3491. class_ = MAPID_WEDDING;
  3492. break;
  3493. case JOB_SUPER_NOVICE: //Super Novices are considered 2-1 novices. [Skotlex]
  3494. class_ |= JOBL_2_1;
  3495. break;
  3496. case JOB_GUNSLINGER:
  3497. class_ |= MAPID_GUNSLINGER;
  3498. break;
  3499. case JOB_NINJA:
  3500. class_ |= MAPID_NINJA;
  3501. break;
  3502. case JOB_XMAS:
  3503. class_ = MAPID_XMAS;
  3504. break;
  3505. case JOB_SUMMER:
  3506. class_ = MAPID_SUMMER;
  3507. break;
  3508. default:
  3509. return -1;
  3510. }
  3511. return class_;
  3512. }
  3513. //Reverts the map-style class id to the client-style one.
  3514. int pc_mapid2jobid(unsigned short class_, int sex)
  3515. {
  3516. switch(class_) {
  3517. case MAPID_NOVICE: return JOB_NOVICE;
  3518. case MAPID_SWORDMAN: return JOB_SWORDMAN;
  3519. case MAPID_MAGE: return JOB_MAGE;
  3520. case MAPID_ARCHER: return JOB_ARCHER;
  3521. case MAPID_ACOLYTE: return JOB_ACOLYTE;
  3522. case MAPID_MERCHANT: return JOB_MERCHANT;
  3523. case MAPID_THIEF: return JOB_THIEF;
  3524. case MAPID_TAEKWON: return JOB_TAEKWON;
  3525. case MAPID_WEDDING: return JOB_WEDDING;
  3526. case MAPID_GUNSLINGER: return JOB_GUNSLINGER;
  3527. case MAPID_NINJA: return JOB_NINJA;
  3528. case MAPID_XMAS: return JOB_XMAS;
  3529. case MAPID_SUMMER: return JOB_SUMMER;
  3530. //2_1 classes
  3531. case MAPID_SUPER_NOVICE: return JOB_SUPER_NOVICE;
  3532. case MAPID_KNIGHT: return JOB_KNIGHT;
  3533. case MAPID_WIZARD: return JOB_WIZARD;
  3534. case MAPID_HUNTER: return JOB_HUNTER;
  3535. case MAPID_PRIEST: return JOB_PRIEST;
  3536. case MAPID_BLACKSMITH: return JOB_BLACKSMITH;
  3537. case MAPID_ASSASSIN: return JOB_ASSASSIN;
  3538. case MAPID_STAR_GLADIATOR: return JOB_STAR_GLADIATOR;
  3539. //2_2 classes
  3540. case MAPID_CRUSADER: return JOB_CRUSADER;
  3541. case MAPID_SAGE: return JOB_SAGE;
  3542. case MAPID_BARDDANCER: return sex?JOB_BARD:JOB_DANCER;
  3543. case MAPID_MONK: return JOB_MONK;
  3544. case MAPID_ALCHEMIST: return JOB_ALCHEMIST;
  3545. case MAPID_ROGUE: return JOB_ROGUE;
  3546. case MAPID_SOUL_LINKER: return JOB_SOUL_LINKER;
  3547. //1-1: advanced
  3548. case MAPID_NOVICE_HIGH: return JOB_NOVICE_HIGH;
  3549. case MAPID_SWORDMAN_HIGH: return JOB_SWORDMAN_HIGH;
  3550. case MAPID_MAGE_HIGH: return JOB_MAGE_HIGH;
  3551. case MAPID_ARCHER_HIGH: return JOB_ARCHER_HIGH;
  3552. case MAPID_ACOLYTE_HIGH: return JOB_ACOLYTE_HIGH;
  3553. case MAPID_MERCHANT_HIGH: return JOB_MERCHANT_HIGH;
  3554. case MAPID_THIEF_HIGH: return JOB_THIEF_HIGH;
  3555. //2_1 advanced
  3556. case MAPID_LORD_KNIGHT: return JOB_LORD_KNIGHT;
  3557. case MAPID_HIGH_WIZARD: return JOB_HIGH_WIZARD;
  3558. case MAPID_SNIPER: return JOB_SNIPER;
  3559. case MAPID_HIGH_PRIEST: return JOB_HIGH_PRIEST;
  3560. case MAPID_WHITESMITH: return JOB_WHITESMITH;
  3561. case MAPID_ASSASSIN_CROSS: return JOB_ASSASSIN_CROSS;
  3562. //2_2 advanced
  3563. case MAPID_PALADIN: return JOB_PALADIN;
  3564. case MAPID_PROFESSOR: return JOB_PROFESSOR;
  3565. case MAPID_CLOWNGYPSY: return sex?JOB_CLOWN:JOB_GYPSY;
  3566. case MAPID_CHAMPION: return JOB_CHAMPION;
  3567. case MAPID_CREATOR: return JOB_CREATOR;
  3568. case MAPID_STALKER: return JOB_STALKER;
  3569. //1-1 baby
  3570. case MAPID_BABY: return JOB_BABY;
  3571. case MAPID_BABY_SWORDMAN: return JOB_BABY_SWORDMAN;
  3572. case MAPID_BABY_MAGE: return JOB_BABY_MAGE;
  3573. case MAPID_BABY_ARCHER: return JOB_BABY_ARCHER;
  3574. case MAPID_BABY_ACOLYTE: return JOB_BABY_ACOLYTE;
  3575. case MAPID_BABY_MERCHANT: return JOB_BABY_MERCHANT;
  3576. case MAPID_BABY_THIEF: return JOB_BABY_THIEF;
  3577. //2_1 baby
  3578. case MAPID_SUPER_BABY: return JOB_SUPER_BABY;
  3579. case MAPID_BABY_KNIGHT: return JOB_BABY_KNIGHT;
  3580. case MAPID_BABY_WIZARD: return JOB_BABY_WIZARD;
  3581. case MAPID_BABY_HUNTER: return JOB_BABY_HUNTER;
  3582. case MAPID_BABY_PRIEST: return JOB_BABY_PRIEST;
  3583. case MAPID_BABY_BLACKSMITH: return JOB_BABY_BLACKSMITH;
  3584. case MAPID_BABY_ASSASSIN: return JOB_BABY_ASSASSIN;
  3585. //2_2 baby
  3586. case MAPID_BABY_CRUSADER: return JOB_BABY_CRUSADER;
  3587. case MAPID_BABY_SAGE: return JOB_BABY_SAGE;
  3588. case MAPID_BABY_BARDDANCER: return sex?JOB_BABY_BARD:JOB_BABY_DANCER;
  3589. case MAPID_BABY_MONK: return JOB_BABY_MONK;
  3590. case MAPID_BABY_ALCHEMIST: return JOB_BABY_ALCHEMIST;
  3591. case MAPID_BABY_ROGUE: return JOB_BABY_ROGUE;
  3592. default:
  3593. return -1;
  3594. }
  3595. }
  3596. /*====================================================
  3597. * This function return the name of the job (by [Yor])
  3598. *----------------------------------------------------*/
  3599. char* job_name(int class_)
  3600. {
  3601. switch (class_) {
  3602. case JOB_NOVICE:
  3603. case JOB_SWORDMAN:
  3604. case JOB_MAGE:
  3605. case JOB_ARCHER:
  3606. case JOB_ACOLYTE:
  3607. case JOB_MERCHANT:
  3608. case JOB_THIEF:
  3609. return msg_txt(550 - JOB_NOVICE+class_);
  3610. case JOB_KNIGHT:
  3611. case JOB_PRIEST:
  3612. case JOB_WIZARD:
  3613. case JOB_BLACKSMITH:
  3614. case JOB_HUNTER:
  3615. case JOB_ASSASSIN:
  3616. return msg_txt(557 - JOB_KNIGHT+class_);
  3617. case JOB_KNIGHT2:
  3618. return msg_txt(557);
  3619. case JOB_CRUSADER:
  3620. case JOB_MONK:
  3621. case JOB_SAGE:
  3622. case JOB_ROGUE:
  3623. case JOB_ALCHEMIST:
  3624. case JOB_BARD:
  3625. case JOB_DANCER:
  3626. return msg_txt(563 - JOB_CRUSADER+class_);
  3627. case JOB_CRUSADER2:
  3628. return msg_txt(563);
  3629. case JOB_WEDDING:
  3630. case JOB_SUPER_NOVICE:
  3631. case JOB_XMAS:
  3632. return msg_txt(570 - JOB_WEDDING+class_);
  3633. case JOB_SUMMER:
  3634. return msg_txt(621);
  3635. case JOB_NOVICE_HIGH:
  3636. case JOB_SWORDMAN_HIGH:
  3637. case JOB_MAGE_HIGH:
  3638. case JOB_ARCHER_HIGH:
  3639. case JOB_ACOLYTE_HIGH:
  3640. case JOB_MERCHANT_HIGH:
  3641. case JOB_THIEF_HIGH:
  3642. return msg_txt(575 - JOB_NOVICE_HIGH+class_);
  3643. case JOB_LORD_KNIGHT:
  3644. case JOB_HIGH_PRIEST:
  3645. case JOB_HIGH_WIZARD:
  3646. case JOB_WHITESMITH:
  3647. case JOB_SNIPER:
  3648. case JOB_ASSASSIN_CROSS:
  3649. return msg_txt(582 - JOB_LORD_KNIGHT+class_);
  3650. case JOB_LORD_KNIGHT2:
  3651. return msg_txt(582);
  3652. case JOB_PALADIN:
  3653. case JOB_CHAMPION:
  3654. case JOB_PROFESSOR:
  3655. case JOB_STALKER:
  3656. case JOB_CREATOR:
  3657. case JOB_CLOWN:
  3658. case JOB_GYPSY:
  3659. return msg_txt(588 - JOB_PALADIN + class_);
  3660. case JOB_PALADIN2:
  3661. return msg_txt(588);
  3662. case JOB_BABY:
  3663. case JOB_BABY_SWORDMAN:
  3664. case JOB_BABY_MAGE:
  3665. case JOB_BABY_ARCHER:
  3666. case JOB_BABY_ACOLYTE:
  3667. case JOB_BABY_MERCHANT:
  3668. case JOB_BABY_THIEF:
  3669. return msg_txt(595 - JOB_BABY + class_);
  3670. case JOB_BABY_KNIGHT:
  3671. case JOB_BABY_PRIEST:
  3672. case JOB_BABY_WIZARD:
  3673. case JOB_BABY_BLACKSMITH:
  3674. case JOB_BABY_HUNTER:
  3675. case JOB_BABY_ASSASSIN:
  3676. return msg_txt(602 - JOB_BABY_KNIGHT + class_);
  3677. case JOB_BABY_KNIGHT2:
  3678. return msg_txt(602);
  3679. case JOB_BABY_CRUSADER:
  3680. case JOB_BABY_MONK:
  3681. case JOB_BABY_SAGE:
  3682. case JOB_BABY_ROGUE:
  3683. case JOB_BABY_ALCHEMIST:
  3684. case JOB_BABY_BARD:
  3685. case JOB_BABY_DANCER:
  3686. return msg_txt(608 - JOB_BABY_CRUSADER +class_);
  3687. case JOB_BABY_CRUSADER2:
  3688. return msg_txt(608);
  3689. case JOB_SUPER_BABY:
  3690. return msg_txt(615);
  3691. case JOB_TAEKWON:
  3692. return msg_txt(616);
  3693. case JOB_STAR_GLADIATOR:
  3694. case JOB_STAR_GLADIATOR2:
  3695. return msg_txt(617);
  3696. case JOB_SOUL_LINKER:
  3697. return msg_txt(618);
  3698. case JOB_GUNSLINGER:
  3699. return msg_txt(619);
  3700. case JOB_NINJA:
  3701. return msg_txt(620);
  3702. default:
  3703. return msg_txt(650);
  3704. }
  3705. }
  3706. int pc_follow_timer(int tid, unsigned int tick, int id, intptr data)
  3707. {
  3708. struct map_session_data *sd;
  3709. struct block_list *tbl;
  3710. sd = map_id2sd(id);
  3711. nullpo_retr(0, sd);
  3712. if (sd->followtimer != tid){
  3713. ShowError("pc_follow_timer %d != %d\n",sd->followtimer,tid);
  3714. sd->followtimer = INVALID_TIMER;
  3715. return 0;
  3716. }
  3717. sd->followtimer = INVALID_TIMER;
  3718. if (pc_isdead(sd))
  3719. return 0;
  3720. if ((tbl = map_id2bl(sd->followtarget)) == NULL)
  3721. return 0;
  3722. if(status_isdead(tbl))
  3723. return 0;
  3724. // either player or target is currently detached from map blocks (could be teleporting),
  3725. // but still connected to this map, so we'll just increment the timer and check back later
  3726. if (sd->bl.prev != NULL && tbl->prev != NULL &&
  3727. sd->ud.skilltimer == -1 && sd->ud.attacktimer == -1 && sd->ud.walktimer == -1)
  3728. {
  3729. if((sd->bl.m == tbl->m) && unit_can_reach_bl(&sd->bl,tbl, AREA_SIZE, 0, NULL, NULL)) {
  3730. if (!check_distance_bl(&sd->bl, tbl, 5))
  3731. unit_walktobl(&sd->bl, tbl, 5, 0);
  3732. } else
  3733. pc_setpos(sd, map_id2index(tbl->m), tbl->x, tbl->y, 3);
  3734. }
  3735. sd->followtimer = add_timer(
  3736. tick + 1000, // increase time a bit to loosen up map's load
  3737. pc_follow_timer, sd->bl.id, 0);
  3738. return 0;
  3739. }
  3740. int pc_stop_following (struct map_session_data *sd)
  3741. {
  3742. nullpo_retr(0, sd);
  3743. if (sd->followtimer != INVALID_TIMER) {
  3744. delete_timer(sd->followtimer,pc_follow_timer);
  3745. sd->followtimer = INVALID_TIMER;
  3746. }
  3747. sd->followtarget = -1;
  3748. return 0;
  3749. }
  3750. int pc_follow(struct map_session_data *sd,int target_id)
  3751. {
  3752. struct block_list *bl = map_id2bl(target_id);
  3753. if (bl == NULL /*|| bl->type != BL_PC*/)
  3754. return 1;
  3755. if (sd->followtimer != -1)
  3756. pc_stop_following(sd);
  3757. sd->followtarget = target_id;
  3758. pc_follow_timer(-1,gettick(),sd->bl.id,0);
  3759. return 0;
  3760. }
  3761. int pc_checkbaselevelup(struct map_session_data *sd)
  3762. {
  3763. unsigned int next = pc_nextbaseexp(sd);
  3764. if (!next || sd->status.base_exp < next)
  3765. return 0;
  3766. do {
  3767. sd->status.base_exp -= next;
  3768. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  3769. if(!battle_config.multi_level_up && sd->status.base_exp > next-1)
  3770. sd->status.base_exp = next-1;
  3771. sd->status.base_level ++;
  3772. if (battle_config.use_statpoint_table)
  3773. next = statp[sd->status.base_level] - statp[sd->status.base_level-1];
  3774. else //Estimated way.
  3775. next = (sd->status.base_level+14) / 5 ;
  3776. if (sd->status.status_point > USHRT_MAX - next)
  3777. sd->status.status_point = USHRT_MAX;
  3778. else
  3779. sd->status.status_point += next;
  3780. } while ((next=pc_nextbaseexp(sd)) > 0 && sd->status.base_exp >= next);
  3781. if (battle_config.pet_lv_rate && sd->pd) //<Skotlex> update pet's level
  3782. status_calc_pet(sd->pd,0);
  3783. clif_updatestatus(sd,SP_STATUSPOINT);
  3784. clif_updatestatus(sd,SP_BASELEVEL);
  3785. clif_updatestatus(sd,SP_NEXTBASEEXP);
  3786. status_calc_pc(sd,0);
  3787. status_percent_heal(&sd->bl,100,100);
  3788. if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE)
  3789. {
  3790. sc_start(&sd->bl,status_skill2sc(PR_KYRIE),100,1,skill_get_time(PR_KYRIE,1));
  3791. sc_start(&sd->bl,status_skill2sc(PR_IMPOSITIO),100,1,skill_get_time(PR_IMPOSITIO,1));
  3792. sc_start(&sd->bl,status_skill2sc(PR_MAGNIFICAT),100,1,skill_get_time(PR_MAGNIFICAT,1));
  3793. sc_start(&sd->bl,status_skill2sc(PR_GLORIA),100,1,skill_get_time(PR_GLORIA,1));
  3794. sc_start(&sd->bl,status_skill2sc(PR_SUFFRAGIUM),100,1,skill_get_time(PR_SUFFRAGIUM,1));
  3795. if (sd->state.snovice_dead_flag)
  3796. sd->state.snovice_dead_flag = 0; //Reenable steelbody resurrection on dead.
  3797. } else
  3798. if((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON || (sd->class_&MAPID_UPPERMASK) == MAPID_STAR_GLADIATOR)
  3799. {
  3800. sc_start(&sd->bl,status_skill2sc(AL_INCAGI),100,10,600000);
  3801. sc_start(&sd->bl,status_skill2sc(AL_BLESSING),100,10,600000);
  3802. }
  3803. clif_misceffect(&sd->bl,0);
  3804. npc_script_event(sd, NPCE_BASELVUP); //LORDALFA - LVLUPEVENT
  3805. if(sd->status.party_id)
  3806. party_send_levelup(sd);
  3807. return 1;
  3808. }
  3809. int pc_checkjoblevelup(struct map_session_data *sd)
  3810. {
  3811. unsigned int next = pc_nextjobexp(sd);
  3812. nullpo_retr(0, sd);
  3813. if(!next || sd->status.job_exp < next)
  3814. return 0;
  3815. do {
  3816. sd->status.job_exp -= next;
  3817. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  3818. if(!battle_config.multi_level_up && sd->status.job_exp > next-1)
  3819. sd->status.job_exp = next-1;
  3820. sd->status.job_level ++;
  3821. sd->status.skill_point ++;
  3822. } while ((next=pc_nextjobexp(sd)) > 0 && sd->status.job_exp >= next);
  3823. clif_updatestatus(sd,SP_JOBLEVEL);
  3824. clif_updatestatus(sd,SP_NEXTJOBEXP);
  3825. clif_updatestatus(sd,SP_SKILLPOINT);
  3826. status_calc_pc(sd,0);
  3827. clif_misceffect(&sd->bl,1);
  3828. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  3829. clif_status_change(&sd->bl,SI_DEVIL, 1); //Permanent blind effect from SG_DEVIL.
  3830. npc_script_event(sd, NPCE_JOBLVUP);
  3831. return 1;
  3832. }
  3833. /*==========================================
  3834. * Alters experienced based on self bonuses that do not get even shared to the party.
  3835. *------------------------------------------*/
  3836. static void pc_calcexp(struct map_session_data *sd, unsigned int *base_exp, unsigned int *job_exp, struct block_list *src)
  3837. {
  3838. int bonus = 0;
  3839. struct status_data *status = status_get_status_data(src);
  3840. if (sd->expaddrace[status->race])
  3841. bonus += sd->expaddrace[status->race];
  3842. bonus += sd->expaddrace[status->mode&MD_BOSS?RC_BOSS:RC_NONBOSS];
  3843. if (battle_config.pk_mode &&
  3844. (int)(status_get_lv(src) - sd->status.base_level) >= 20)
  3845. bonus += 15; // pk_mode additional exp if monster >20 levels [Valaris]
  3846. if (sd->sc.data[SC_EXPBOOST])
  3847. bonus += sd->sc.data[SC_EXPBOOST]->val1;
  3848. if (!bonus)
  3849. return;
  3850. *base_exp = (unsigned int) cap_value(*base_exp + (double)*base_exp * bonus/100., 1, UINT_MAX);
  3851. *job_exp = (unsigned int) cap_value(*job_exp + (double)*job_exp * bonus/100., 1, UINT_MAX);
  3852. return;
  3853. }
  3854. /*==========================================
  3855. * ??値取得
  3856. *------------------------------------------*/
  3857. int pc_gainexp(struct map_session_data *sd, struct block_list *src, unsigned int base_exp,unsigned int job_exp)
  3858. {
  3859. char output[256];
  3860. float nextbp=0, nextjp=0;
  3861. unsigned int nextb=0, nextj=0;
  3862. nullpo_retr(0, sd);
  3863. if(sd->bl.prev == NULL || pc_isdead(sd))
  3864. return 0;
  3865. if(!battle_config.pvp_exp && map[sd->bl.m].flag.pvp) // [MouseJstr]
  3866. return 0; // no exp on pvp maps
  3867. if(sd->status.guild_id>0)
  3868. base_exp-=guild_payexp(sd,base_exp);
  3869. if(src) pc_calcexp(sd, &base_exp, &job_exp, src);
  3870. nextb = pc_nextbaseexp(sd);
  3871. nextj = pc_nextjobexp(sd);
  3872. if(sd->state.showexp || battle_config.max_exp_gain_rate){
  3873. if (nextb > 0)
  3874. nextbp = (float) base_exp / (float) nextb;
  3875. if (nextj > 0)
  3876. nextjp = (float) job_exp / (float) nextj;
  3877. if(battle_config.max_exp_gain_rate) {
  3878. if (nextbp > battle_config.max_exp_gain_rate/1000.) {
  3879. //Note that this value should never be greater than the original
  3880. //base_exp, therefore no overflow checks are needed. [Skotlex]
  3881. base_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextb);
  3882. if (sd->state.showexp)
  3883. nextbp = (float) base_exp / (float) nextb;
  3884. }
  3885. if (nextjp > battle_config.max_exp_gain_rate/1000.) {
  3886. job_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextj);
  3887. if (sd->state.showexp)
  3888. nextjp = (float) job_exp / (float) nextj;
  3889. }
  3890. }
  3891. }
  3892. //Cap exp to the level up requirement of the previous level when you are at max level, otherwise cap at UINT_MAX (this is required for some S. Novice bonuses). [Skotlex]
  3893. if (base_exp) {
  3894. nextb = nextb?UINT_MAX:pc_thisbaseexp(sd);
  3895. if(sd->status.base_exp > nextb - base_exp)
  3896. sd->status.base_exp = nextb;
  3897. else
  3898. sd->status.base_exp += base_exp;
  3899. pc_checkbaselevelup(sd);
  3900. clif_updatestatus(sd,SP_BASEEXP);
  3901. }
  3902. if (job_exp) {
  3903. nextj = nextj?UINT_MAX:pc_thisjobexp(sd);
  3904. if(sd->status.job_exp > nextj - job_exp)
  3905. sd->status.job_exp = nextj;
  3906. else
  3907. sd->status.job_exp += job_exp;
  3908. pc_checkjoblevelup(sd);
  3909. clif_updatestatus(sd,SP_JOBEXP);
  3910. }
  3911. if(sd->state.showexp){
  3912. sprintf(output,
  3913. "Experience Gained Base:%u (%.2f%%) Job:%u (%.2f%%)",base_exp,nextbp*(float)100,job_exp,nextjp*(float)100);
  3914. clif_disp_onlyself(sd,output,strlen(output));
  3915. }
  3916. return 1;
  3917. }
  3918. /*==========================================
  3919. * Returns max level for this character.
  3920. *------------------------------------------*/
  3921. unsigned int pc_maxbaselv(struct map_session_data *sd)
  3922. {
  3923. return max_level[pc_class2idx(sd->status.class_)][0];
  3924. };
  3925. unsigned int pc_maxjoblv(struct map_session_data *sd)
  3926. {
  3927. return max_level[pc_class2idx(sd->status.class_)][1];
  3928. };
  3929. /*==========================================
  3930. * base level側必要??値計算
  3931. *------------------------------------------*/
  3932. unsigned int pc_nextbaseexp(struct map_session_data *sd)
  3933. {
  3934. nullpo_retr(0, sd);
  3935. if(sd->status.base_level>=pc_maxbaselv(sd) || sd->status.base_level<=0)
  3936. return 0;
  3937. return exp_table[pc_class2idx(sd->status.class_)][0][sd->status.base_level-1];
  3938. }
  3939. unsigned int pc_thisbaseexp(struct map_session_data *sd)
  3940. {
  3941. if(sd->status.base_level>pc_maxbaselv(sd) || sd->status.base_level<=1)
  3942. return 0;
  3943. return exp_table[pc_class2idx(sd->status.class_)][0][sd->status.base_level-2];
  3944. }
  3945. /*==========================================
  3946. * job level側必要??値計算
  3947. *------------------------------------------*/
  3948. unsigned int pc_nextjobexp(struct map_session_data *sd)
  3949. {
  3950. nullpo_retr(0, sd);
  3951. if(sd->status.job_level>=pc_maxjoblv(sd) || sd->status.job_level<=0)
  3952. return 0;
  3953. return exp_table[pc_class2idx(sd->status.class_)][1][sd->status.job_level-1];
  3954. }
  3955. unsigned int pc_thisjobexp(struct map_session_data *sd)
  3956. {
  3957. if(sd->status.job_level>pc_maxjoblv(sd) || sd->status.job_level<=1)
  3958. return 0;
  3959. return exp_table[pc_class2idx(sd->status.class_)][1][sd->status.job_level-2];
  3960. }
  3961. static int pc_getstat(struct map_session_data* sd, int type)
  3962. {
  3963. nullpo_retr(-1, sd);
  3964. switch( type ) {
  3965. case SP_STR: return sd->status.str;
  3966. case SP_AGI: return sd->status.agi;
  3967. case SP_VIT: return sd->status.vit;
  3968. case SP_INT: return sd->status.int_;
  3969. case SP_DEX: return sd->status.dex;
  3970. case SP_LUK: return sd->status.luk;
  3971. default:
  3972. return -1;
  3973. }
  3974. }
  3975. /*==========================================
  3976. * 必要ステ?タスポイント計算
  3977. *------------------------------------------*/
  3978. int pc_need_status_point(struct map_session_data *sd,int type)
  3979. {
  3980. nullpo_retr(-1, sd);
  3981. if( type < SP_STR || type > SP_LUK )
  3982. return -1;
  3983. return ( 1 + (pc_getstat(sd,type) + 9) / 10 );
  3984. }
  3985. /*==========================================
  3986. * 能力値成長
  3987. *------------------------------------------*/
  3988. int pc_statusup(struct map_session_data *sd,int type)
  3989. {
  3990. int max, need,val = 0;
  3991. nullpo_retr(0, sd);
  3992. // check conditions
  3993. need = pc_need_status_point(sd,type);
  3994. if( type < SP_STR || type > SP_LUK || need < 0 || need > sd->status.status_point )
  3995. {
  3996. clif_statusupack(sd,type,0,0);
  3997. return 1;
  3998. }
  3999. // check limits
  4000. max = pc_maxparameter(sd);
  4001. if( pc_getstat(sd,type) >= max )
  4002. {
  4003. clif_statusupack(sd,type,0,0);
  4004. return 1;
  4005. }
  4006. switch(type){
  4007. case SP_STR: val= ++sd->status.str; break;
  4008. case SP_AGI: val= ++sd->status.agi; break;
  4009. case SP_VIT: val= ++sd->status.vit; break;
  4010. case SP_INT: val= ++sd->status.int_; break;
  4011. case SP_DEX: val= ++sd->status.dex; break;
  4012. case SP_LUK: val= ++sd->status.luk; break;
  4013. }
  4014. sd->status.status_point-=need;
  4015. status_calc_pc(sd,0);
  4016. if( need != pc_need_status_point(sd,type) )
  4017. clif_updatestatus(sd,type-SP_STR+SP_USTR);
  4018. clif_updatestatus(sd,SP_STATUSPOINT);
  4019. clif_statusupack(sd,type,1,val);
  4020. clif_updatestatus(sd,type); // send after the 'ack' to override the value
  4021. return 0;
  4022. }
  4023. /*==========================================
  4024. * 能力値成長
  4025. *------------------------------------------*/
  4026. int pc_statusup2(struct map_session_data *sd,int type,int val)
  4027. {
  4028. int max;
  4029. nullpo_retr(0, sd);
  4030. max = pc_maxparameter(sd);
  4031. switch(type){
  4032. case SP_STR: sd->status.str = cap_value(sd->status.str + val, 1, max); break;
  4033. case SP_AGI: sd->status.agi = cap_value(sd->status.agi + val, 1, max); break;
  4034. case SP_VIT: sd->status.vit = cap_value(sd->status.vit + val, 1, max); break;
  4035. case SP_INT: sd->status.int_= cap_value(sd->status.int_+ val, 1, max); break;
  4036. case SP_DEX: sd->status.dex = cap_value(sd->status.dex + val, 1, max); break;
  4037. case SP_LUK: sd->status.luk = cap_value(sd->status.luk + val, 1, max); break;
  4038. default:
  4039. clif_statusupack(sd,type,0,0);
  4040. return 1;
  4041. }
  4042. status_calc_pc(sd,0);
  4043. clif_statusupack(sd,type,1,val);
  4044. return 0;
  4045. }
  4046. /*==========================================
  4047. * スキルポイント割り振り
  4048. *------------------------------------------*/
  4049. int pc_skillup(struct map_session_data *sd,int skill_num)
  4050. {
  4051. nullpo_retr(0, sd);
  4052. if( skill_num >= GD_SKILLBASE && skill_num < GD_SKILLBASE+MAX_GUILDSKILL )
  4053. {
  4054. guild_skillup(sd, skill_num);
  4055. return 0;
  4056. }
  4057. if( skill_num >= HM_SKILLBASE && skill_num < HM_SKILLBASE+MAX_HOMUNSKILL && sd->hd )
  4058. {
  4059. merc_hom_skillup(sd->hd, skill_num);
  4060. return 0;
  4061. }
  4062. if( skill_num < 0 || skill_num >= MAX_SKILL )
  4063. return 0;
  4064. if( sd->status.skill_point > 0 &&
  4065. sd->status.skill[skill_num].id &&
  4066. sd->status.skill[skill_num].flag == 0 && //Don't allow raising while you have granted skills. [Skotlex]
  4067. sd->status.skill[skill_num].lv < skill_tree_get_max(skill_num, sd->status.class_) )
  4068. {
  4069. sd->status.skill[skill_num].lv++;
  4070. sd->status.skill_point--;
  4071. if( !skill_get_inf(skill_num) )
  4072. status_calc_pc(sd,0); // Only recalculate for passive skills.
  4073. else if( sd->status.skill_point == 0 && (sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc_famerank(sd->status.char_id, MAPID_TAEKWON) )
  4074. pc_calc_skilltree(sd); // Required to grant all TK Ranger skills.
  4075. else
  4076. pc_check_skilltree(sd, skill_num); // Check if a new skill can Lvlup
  4077. clif_skillup(sd,skill_num);
  4078. clif_updatestatus(sd,SP_SKILLPOINT);
  4079. clif_skillinfoblock(sd);
  4080. }
  4081. return 0;
  4082. }
  4083. /*==========================================
  4084. * /allskill
  4085. *------------------------------------------*/
  4086. int pc_allskillup(struct map_session_data *sd)
  4087. {
  4088. int i,id;
  4089. nullpo_retr(0, sd);
  4090. for(i=0;i<MAX_SKILL;i++){
  4091. if (sd->status.skill[i].flag && sd->status.skill[i].flag != 13){
  4092. sd->status.skill[i].lv=(sd->status.skill[i].flag==1)?0:sd->status.skill[i].flag-2;
  4093. sd->status.skill[i].flag=0;
  4094. if (!sd->status.skill[i].lv)
  4095. sd->status.skill[i].id=0;
  4096. }
  4097. }
  4098. //pc_calc_skilltree takes care of setting the ID to valid skills. [Skotlex]
  4099. if (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill)
  4100. { //Get ALL skills except npc/guild ones. [Skotlex]
  4101. //and except SG_DEVIL [Komurka] and MO_TRIPLEATTACK and RG_SNATCHER [ultramage]
  4102. for(i=0;i<MAX_SKILL;i++){
  4103. if(!(skill_get_inf2(i)&(INF2_NPC_SKILL|INF2_GUILD_SKILL)) && i!=SG_DEVIL && i!=MO_TRIPLEATTACK && i!=RG_SNATCHER)
  4104. sd->status.skill[i].lv=skill_get_max(i); //Nonexistant skills should return a max of 0 anyway.
  4105. }
  4106. }
  4107. else
  4108. {
  4109. int inf2;
  4110. for(i=0;i < MAX_SKILL_TREE && (id=skill_tree[pc_class2idx(sd->status.class_)][i].id)>0;i++){
  4111. inf2 = skill_get_inf2(id);
  4112. if (
  4113. (inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  4114. (inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) ||
  4115. id==SG_DEVIL
  4116. )
  4117. continue; //Cannot be learned normally.
  4118. sd->status.skill[id].lv = skill_tree_get_max(id, sd->status.class_); // celest
  4119. }
  4120. }
  4121. status_calc_pc(sd,0);
  4122. //Required because if you could level up all skills previously,
  4123. //the update will not be sent as only the lv variable changes.
  4124. clif_skillinfoblock(sd);
  4125. return 0;
  4126. }
  4127. /*==========================================
  4128. * /resetlvl
  4129. *------------------------------------------*/
  4130. int pc_resetlvl(struct map_session_data* sd,int type)
  4131. {
  4132. int i;
  4133. nullpo_retr(0, sd);
  4134. if (type != 3) //Also reset skills
  4135. pc_resetskill(sd, 0);
  4136. if(type == 1){
  4137. sd->status.skill_point=0;
  4138. sd->status.base_level=1;
  4139. sd->status.job_level=1;
  4140. sd->status.base_exp=sd->status.base_exp=0;
  4141. sd->status.job_exp=sd->status.job_exp=0;
  4142. if(sd->sc.option !=0)
  4143. sd->sc.option = 0;
  4144. sd->status.str=1;
  4145. sd->status.agi=1;
  4146. sd->status.vit=1;
  4147. sd->status.int_=1;
  4148. sd->status.dex=1;
  4149. sd->status.luk=1;
  4150. if(sd->status.class_ == JOB_NOVICE_HIGH)
  4151. sd->status.status_point=100; // not 88 [celest]
  4152. // give platinum skills upon changing
  4153. pc_skill(sd,142,1,0);
  4154. pc_skill(sd,143,1,0);
  4155. }
  4156. if(type == 2){
  4157. sd->status.skill_point=0;
  4158. sd->status.base_level=1;
  4159. sd->status.job_level=1;
  4160. sd->status.base_exp=0;
  4161. sd->status.job_exp=0;
  4162. }
  4163. if(type == 3){
  4164. sd->status.base_level=1;
  4165. sd->status.base_exp=0;
  4166. }
  4167. if(type == 4){
  4168. sd->status.job_level=1;
  4169. sd->status.job_exp=0;
  4170. }
  4171. clif_updatestatus(sd,SP_STATUSPOINT);
  4172. clif_updatestatus(sd,SP_STR);
  4173. clif_updatestatus(sd,SP_AGI);
  4174. clif_updatestatus(sd,SP_VIT);
  4175. clif_updatestatus(sd,SP_INT);
  4176. clif_updatestatus(sd,SP_DEX);
  4177. clif_updatestatus(sd,SP_LUK);
  4178. clif_updatestatus(sd,SP_BASELEVEL);
  4179. clif_updatestatus(sd,SP_JOBLEVEL);
  4180. clif_updatestatus(sd,SP_STATUSPOINT);
  4181. clif_updatestatus(sd,SP_NEXTBASEEXP);
  4182. clif_updatestatus(sd,SP_NEXTJOBEXP);
  4183. clif_updatestatus(sd,SP_SKILLPOINT);
  4184. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  4185. clif_updatestatus(sd,SP_UAGI);
  4186. clif_updatestatus(sd,SP_UVIT);
  4187. clif_updatestatus(sd,SP_UINT);
  4188. clif_updatestatus(sd,SP_UDEX);
  4189. clif_updatestatus(sd,SP_ULUK); // End Addition
  4190. for(i=0;i<EQI_MAX;i++) { // unequip items that can't be equipped by base 1 [Valaris]
  4191. if(sd->equip_index[i] >= 0)
  4192. if(!pc_isequip(sd,sd->equip_index[i]))
  4193. pc_unequipitem(sd,sd->equip_index[i],2);
  4194. }
  4195. if ((type == 1 || type == 2 || type == 3) && sd->status.party_id)
  4196. party_send_levelup(sd);
  4197. status_calc_pc(sd,0);
  4198. clif_skillinfoblock(sd);
  4199. return 0;
  4200. }
  4201. /*==========================================
  4202. * /resetstate
  4203. *------------------------------------------*/
  4204. int pc_resetstate(struct map_session_data* sd)
  4205. {
  4206. nullpo_retr(0, sd);
  4207. if (battle_config.use_statpoint_table)
  4208. { // New statpoint table used here - Dexity
  4209. int stat;
  4210. if (sd->status.base_level > MAX_LEVEL)
  4211. { //statp[] goes out of bounds, can't reset!
  4212. ShowError("pc_resetstate: Can't reset stats of %d:%d, the base level (%d) is greater than the max level supported (%d)\n",
  4213. sd->status.account_id, sd->status.char_id, sd->status.base_level, MAX_LEVEL);
  4214. return 0;
  4215. }
  4216. stat = statp[sd->status.base_level];
  4217. if (sd->class_&JOBL_UPPER)
  4218. stat+=52; // extra 52+48=100 stat points
  4219. if (stat > USHRT_MAX)
  4220. sd->status.status_point = USHRT_MAX;
  4221. else
  4222. sd->status.status_point = stat;
  4223. } else { //Use new stat-calculating equation [Skotlex]
  4224. #define sumsp(a) (((a-1)/10 +2)*(5*((a-1)/10 +1) + (a-1)%10) -10)
  4225. int add=0;
  4226. add += sumsp(sd->status.str);
  4227. add += sumsp(sd->status.agi);
  4228. add += sumsp(sd->status.vit);
  4229. add += sumsp(sd->status.int_);
  4230. add += sumsp(sd->status.dex);
  4231. add += sumsp(sd->status.luk);
  4232. if (add > USHRT_MAX - sd->status.status_point)
  4233. sd->status.status_point = USHRT_MAX;
  4234. else
  4235. sd->status.status_point+=add;
  4236. }
  4237. sd->status.str=1;
  4238. sd->status.agi=1;
  4239. sd->status.vit=1;
  4240. sd->status.int_=1;
  4241. sd->status.dex=1;
  4242. sd->status.luk=1;
  4243. clif_updatestatus(sd,SP_STR);
  4244. clif_updatestatus(sd,SP_AGI);
  4245. clif_updatestatus(sd,SP_VIT);
  4246. clif_updatestatus(sd,SP_INT);
  4247. clif_updatestatus(sd,SP_DEX);
  4248. clif_updatestatus(sd,SP_LUK);
  4249. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  4250. clif_updatestatus(sd,SP_UAGI);
  4251. clif_updatestatus(sd,SP_UVIT);
  4252. clif_updatestatus(sd,SP_UINT);
  4253. clif_updatestatus(sd,SP_UDEX);
  4254. clif_updatestatus(sd,SP_ULUK); // End Addition
  4255. clif_updatestatus(sd,SP_STATUSPOINT);
  4256. status_calc_pc(sd,0);
  4257. return 1;
  4258. }
  4259. /*==========================================
  4260. * /resetskill
  4261. * if flag&1, perform block resync and status_calc call.
  4262. * if flag&2, just count total amount of skill points used by player, do not really reset.
  4263. *------------------------------------------*/
  4264. int pc_resetskill(struct map_session_data* sd, int flag)
  4265. {
  4266. int i, lv, inf2, skill_point=0;
  4267. nullpo_retr(0, sd);
  4268. if( !(flag&2) )
  4269. { //Remove stuff lost when resetting skills.
  4270. if( pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd) )
  4271. clif_status_load(&sd->bl, SI_DEVIL, 0); //Remove perma blindness due to skill-reset. [Skotlex]
  4272. i = sd->sc.option;
  4273. if( i&OPTION_RIDING && pc_checkskill(sd, KN_RIDING) )
  4274. i &= ~OPTION_RIDING;
  4275. if( i&OPTION_CART && pc_checkskill(sd, MC_PUSHCART) )
  4276. i &= ~OPTION_CART;
  4277. if( i&OPTION_FALCON && pc_checkskill(sd, HT_FALCON) )
  4278. i &= ~OPTION_FALCON;
  4279. if( i != sd->sc.option )
  4280. pc_setoption(sd, i);
  4281. if( merc_is_hom_active(sd->hd) && pc_checkskill(sd, AM_CALLHOMUN) )
  4282. merc_hom_vaporize(sd, 0);
  4283. }
  4284. for( i = 1; i < MAX_SKILL; i++ )
  4285. {
  4286. lv = sd->status.skill[i].lv;
  4287. if (lv < 1) continue;
  4288. inf2 = skill_get_inf2(i);
  4289. if( inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL) ) //Avoid reseting wedding/linker skills.
  4290. continue;
  4291. if( inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn )
  4292. { //Only handle quest skills in a special way when you can't learn them manually
  4293. if( battle_config.quest_skill_reset && !(flag&2) )
  4294. { //Wipe them
  4295. sd->status.skill[i].lv = 0;
  4296. sd->status.skill[i].flag = 0;
  4297. }
  4298. continue;
  4299. }
  4300. if( !sd->status.skill[i].flag )
  4301. skill_point += lv;
  4302. else if( sd->status.skill[i].flag > 2 && sd->status.skill[i].flag != 13 )
  4303. skill_point += (sd->status.skill[i].flag - 2);
  4304. if( !(flag&2) )
  4305. {
  4306. sd->status.skill[i].lv = 0;
  4307. sd->status.skill[i].flag = 0;
  4308. }
  4309. }
  4310. if( flag&2 || !skill_point ) return skill_point;
  4311. if( sd->status.skill_point > USHRT_MAX - skill_point )
  4312. sd->status.skill_point = USHRT_MAX;
  4313. else
  4314. sd->status.skill_point += skill_point;
  4315. if( flag&1 )
  4316. {
  4317. clif_updatestatus(sd,SP_SKILLPOINT);
  4318. clif_skillinfoblock(sd);
  4319. status_calc_pc(sd,0);
  4320. }
  4321. return skill_point;
  4322. }
  4323. /*==========================================
  4324. * /resetfeel [Komurka]
  4325. *------------------------------------------*/
  4326. int pc_resetfeel(struct map_session_data* sd)
  4327. {
  4328. int i;
  4329. nullpo_retr(0, sd);
  4330. for (i=0; i<3; i++)
  4331. {
  4332. sd->feel_map[i].m = -1;
  4333. sd->feel_map[i].index = 0;
  4334. pc_setglobalreg(sd,sg_info[i].feel_var,0);
  4335. }
  4336. return 0;
  4337. }
  4338. int pc_resethate(struct map_session_data* sd)
  4339. {
  4340. int i;
  4341. nullpo_retr(0, sd);
  4342. for (i=0; i<3; i++)
  4343. {
  4344. sd->hate_mob[i] = -1;
  4345. pc_setglobalreg(sd,sg_info[i].hate_var,0);
  4346. }
  4347. return 0;
  4348. }
  4349. int pc_skillatk_bonus(struct map_session_data *sd, int skill_num)
  4350. {
  4351. int i;
  4352. for (i = 0; i < ARRAYLENGTH(sd->skillatk) && sd->skillatk[i].id; i++)
  4353. {
  4354. if (sd->skillatk[i].id == skill_num)
  4355. return sd->skillatk[i].val;
  4356. }
  4357. return 0;
  4358. }
  4359. int pc_skillheal_bonus(struct map_session_data *sd, int skill_num)
  4360. {
  4361. int i;
  4362. for (i = 0; i < ARRAYLENGTH(sd->skillheal) && sd->skillheal[i].id; i++)
  4363. {
  4364. if (sd->skillheal[i].id == skill_num)
  4365. return sd->skillheal[i].val;
  4366. }
  4367. return 0;
  4368. }
  4369. void pc_respawn(struct map_session_data* sd, uint8 clrtype)
  4370. {
  4371. if( !pc_isdead(sd) )
  4372. return; // not applicable
  4373. pc_setstand(sd);
  4374. pc_setrestartvalue(sd,3);
  4375. if(pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype))
  4376. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  4377. }
  4378. static int pc_respawn_timer(int tid, unsigned int tick, int id, intptr data)
  4379. {
  4380. struct map_session_data *sd = map_id2sd(id);
  4381. if( sd != NULL )
  4382. pc_respawn(sd,0);
  4383. return 0;
  4384. }
  4385. /*==========================================
  4386. * Invoked when a player has received damage
  4387. *------------------------------------------*/
  4388. void pc_damage(struct map_session_data *sd,struct block_list *src,unsigned int hp, unsigned int sp)
  4389. {
  4390. if (sp) clif_updatestatus(sd,SP_SP);
  4391. if (!hp) return;
  4392. if(pc_issit(sd)) {
  4393. pc_setstand(sd);
  4394. skill_sit(sd,0);
  4395. }
  4396. clif_updatestatus(sd,SP_HP);
  4397. if(!src || src == &sd->bl)
  4398. return;
  4399. if(sd->status.pet_id > 0 && sd->pd && battle_config.pet_damage_support)
  4400. pet_target_check(sd,src,1);
  4401. sd->canlog_tick = gettick();
  4402. return;
  4403. }
  4404. int pc_dead(struct map_session_data *sd,struct block_list *src)
  4405. {
  4406. int i=0,j=0,k=0;
  4407. unsigned int tick = gettick();
  4408. for(k = 0; k < 5; k++)
  4409. if (sd->devotion[k]){
  4410. struct map_session_data *devsd = map_id2sd(sd->devotion[k]);
  4411. if (devsd) status_change_end(&devsd->bl,SC_DEVOTION,-1);
  4412. sd->devotion[k] = 0;
  4413. }
  4414. if(sd->status.pet_id > 0 && sd->pd)
  4415. {
  4416. struct s_pet *pet = &sd->pd->pet;
  4417. if(!map[sd->bl.m].flag.noexppenalty){
  4418. pet->intimate -= sd->pd->petDB->die;
  4419. if(pet->intimate < 0)
  4420. pet->intimate = 0;
  4421. clif_send_petdata(sd,sd->pd,1,pet->intimate);
  4422. }
  4423. if(sd->pd->target_id) // Unlock all targets...
  4424. pet_unlocktarget(sd->pd);
  4425. }
  4426. if( sd->status.hom_id > 0 && battle_config.homunculus_auto_vapor )
  4427. merc_hom_vaporize(sd, 0);
  4428. if( sd->md )
  4429. merc_delete(sd->md, 3); // Your mercenary soldier has ran away.
  4430. // Leave duel if you die [LuzZza]
  4431. if(battle_config.duel_autoleave_when_die) {
  4432. if(sd->duel_group > 0)
  4433. duel_leave(sd->duel_group, sd);
  4434. if(sd->duel_invite > 0)
  4435. duel_reject(sd->duel_invite, sd);
  4436. }
  4437. pc_setdead(sd);
  4438. //Reset menu skills/item skills
  4439. if (sd->skillitem)
  4440. sd->skillitem = sd->skillitemlv = 0;
  4441. if (sd->menuskill_id)
  4442. sd->menuskill_id = sd->menuskill_val = 0;
  4443. //Reset ticks.
  4444. sd->hp_loss.tick = sd->sp_loss.tick = sd->hp_regen.tick = sd->sp_regen.tick = 0;
  4445. pc_setglobalreg(sd,"PC_DIE_COUNTER",sd->die_counter+1);
  4446. pc_setglobalreg(sd,"killerrid",src?src->id:0);
  4447. npc_script_event(sd,NPCE_DIE);
  4448. if ( sd && sd->spiritball && (sd->class_&MAPID_BASEMASK)==MAPID_GUNSLINGER ) // maybe also monks' spiritballs ?
  4449. pc_delspiritball(sd,sd->spiritball,0);
  4450. if (src)
  4451. switch (src->type) {
  4452. case BL_MOB:
  4453. {
  4454. struct mob_data *md=(struct mob_data *)src;
  4455. if(md->target_id==sd->bl.id)
  4456. mob_unlocktarget(md,tick);
  4457. if(battle_config.mobs_level_up && md->status.hp &&
  4458. (unsigned int)md->level < pc_maxbaselv(sd) &&
  4459. !md->guardian_data && !md->special_state.ai// Guardians/summons should not level. [Skotlex]
  4460. ) { // monster level up [Valaris]
  4461. clif_misceffect(&md->bl,0);
  4462. md->level++;
  4463. status_calc_mob(md, 0);
  4464. status_percent_heal(src,10,0);
  4465. }
  4466. src = battle_get_master(src); // Maybe Player Summon
  4467. }
  4468. break;
  4469. case BL_PET: //Pass on to master...
  4470. src = &((TBL_PET*)src)->msd->bl;
  4471. break;
  4472. case BL_HOM:
  4473. src = &((TBL_HOM*)src)->master->bl;
  4474. break;
  4475. case BL_MER:
  4476. src = &((TBL_MER*)src)->master->bl;
  4477. break;
  4478. }
  4479. if (src && src->type == BL_PC)
  4480. {
  4481. struct map_session_data *ssd = (struct map_session_data *)src;
  4482. pc_setglobalreg(ssd, "killedrid", sd->bl.id);
  4483. npc_script_event(ssd, NPCE_KILLPC);
  4484. if (battle_config.pk_mode&2) {
  4485. ssd->status.manner -= 5;
  4486. if(ssd->status.manner < 0)
  4487. sc_start(src,SC_NOCHAT,100,0,0);
  4488. #if 0
  4489. // PK/Karma system code (not enabled yet) [celest]
  4490. // originally from Kade Online, so i don't know if any of these is correct ^^;
  4491. // note: karma is measured REVERSE, so more karma = more 'evil' / less honourable,
  4492. // karma going down = more 'good' / more honourable.
  4493. // The Karma System way...
  4494. if (sd->status.karma > ssd->status.karma) { // If player killed was more evil
  4495. sd->status.karma--;
  4496. ssd->status.karma--;
  4497. }
  4498. else if (sd->status.karma < ssd->status.karma) // If player killed was more good
  4499. ssd->status.karma++;
  4500. // or the PK System way...
  4501. if (sd->status.karma > 0) // player killed is dishonourable?
  4502. ssd->status.karma--; // honour points earned
  4503. sd->status.karma++; // honour points lost
  4504. // To-do: Receive exp on certain occasions
  4505. #endif
  4506. }
  4507. }
  4508. if(battle_config.bone_drop==2
  4509. || (battle_config.bone_drop==1 && map[sd->bl.m].flag.pvp))
  4510. {
  4511. struct item item_tmp;
  4512. memset(&item_tmp,0,sizeof(item_tmp));
  4513. item_tmp.nameid=ITEMID_SKULL_;
  4514. item_tmp.identify=1;
  4515. item_tmp.card[0]=CARD0_CREATE;
  4516. item_tmp.card[1]=0;
  4517. item_tmp.card[2]=GetWord(sd->status.char_id,0); // CharId
  4518. item_tmp.card[3]=GetWord(sd->status.char_id,1);
  4519. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
  4520. }
  4521. // activate Steel body if a super novice dies at 99+% exp [celest]
  4522. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && !sd->state.snovice_dead_flag)
  4523. {
  4524. unsigned int next = pc_nextbaseexp(sd);
  4525. if( next == 0 ) next = pc_thisbaseexp(sd);
  4526. if( get_percentage(sd->status.base_exp,next) >= 99 && !map_flag_gvg(sd->bl.m) )
  4527. {
  4528. sd->state.snovice_dead_flag = 1;
  4529. pc_setstand(sd);
  4530. status_percent_heal(&sd->bl, 100, 100);
  4531. clif_resurrection(&sd->bl, 1);
  4532. if(battle_config.pc_invincible_time)
  4533. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  4534. sc_start(&sd->bl,status_skill2sc(MO_STEELBODY),100,1,skill_get_time(MO_STEELBODY,1));
  4535. if(map_flag_gvg(sd->bl.m))
  4536. pc_respawn_timer(-1, gettick(), sd->bl.id, 0);
  4537. return 0;
  4538. }
  4539. }
  4540. // changed penalty options, added death by player if pk_mode [Valaris]
  4541. if(battle_config.death_penalty_type
  4542. && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE // only novices will receive no penalty
  4543. && !map[sd->bl.m].flag.noexppenalty && !map_flag_gvg(sd->bl.m)
  4544. && !sd->sc.data[SC_BABY] && !sd->sc.data[SC_LIFEINSURANCE])
  4545. {
  4546. unsigned int base_penalty =0;
  4547. if (battle_config.death_penalty_base > 0) {
  4548. switch (battle_config.death_penalty_type) {
  4549. case 1:
  4550. base_penalty = (unsigned int) ((double)pc_nextbaseexp(sd) * (double)battle_config.death_penalty_base/10000);
  4551. break;
  4552. case 2:
  4553. base_penalty = (unsigned int) ((double)sd->status.base_exp * (double)battle_config.death_penalty_base/10000);
  4554. break;
  4555. }
  4556. if(base_penalty) {
  4557. if (battle_config.pk_mode && src && src->type==BL_PC)
  4558. base_penalty*=2;
  4559. if(sd->status.base_exp < base_penalty)
  4560. sd->status.base_exp = 0;
  4561. else
  4562. sd->status.base_exp -= base_penalty;
  4563. clif_updatestatus(sd,SP_BASEEXP);
  4564. }
  4565. }
  4566. if(battle_config.death_penalty_job > 0)
  4567. {
  4568. base_penalty = 0;
  4569. switch (battle_config.death_penalty_type) {
  4570. case 1:
  4571. base_penalty = (unsigned int) ((double)pc_nextjobexp(sd) * (double)battle_config.death_penalty_job/10000);
  4572. break;
  4573. case 2:
  4574. base_penalty = (unsigned int) ((double)sd->status.job_exp * (double)battle_config.death_penalty_job/10000);
  4575. break;
  4576. }
  4577. if(base_penalty) {
  4578. if (battle_config.pk_mode && src && src->type==BL_PC)
  4579. base_penalty*=2;
  4580. if(sd->status.job_exp < base_penalty)
  4581. sd->status.job_exp = 0;
  4582. else
  4583. sd->status.job_exp -= base_penalty;
  4584. clif_updatestatus(sd,SP_JOBEXP);
  4585. }
  4586. }
  4587. if(battle_config.zeny_penalty > 0 && !map[sd->bl.m].flag.nozenypenalty)
  4588. {
  4589. base_penalty = (unsigned int)((double)sd->status.zeny * (double)battle_config.zeny_penalty / 10000.);
  4590. if(base_penalty)
  4591. pc_payzeny(sd, base_penalty);
  4592. }
  4593. }
  4594. if(map[sd->bl.m].flag.pvp_nightmaredrop)
  4595. { // Moved this outside so it works when PVP isn't enabled and during pk mode [Ancyker]
  4596. for(j=0;j<MAX_DROP_PER_MAP;j++){
  4597. int id = map[sd->bl.m].drop_list[j].drop_id;
  4598. int type = map[sd->bl.m].drop_list[j].drop_type;
  4599. int per = map[sd->bl.m].drop_list[j].drop_per;
  4600. if(id == 0)
  4601. continue;
  4602. if(id == -1){
  4603. int eq_num=0,eq_n[MAX_INVENTORY];
  4604. memset(eq_n,0,sizeof(eq_n));
  4605. for(i=0;i<MAX_INVENTORY;i++){
  4606. int k;
  4607. if( (type == 1 && !sd->status.inventory[i].equip)
  4608. || (type == 2 && sd->status.inventory[i].equip)
  4609. || type == 3)
  4610. {
  4611. ARR_FIND( 0, MAX_INVENTORY, k, eq_n[k] <= 0 );
  4612. if( k < MAX_INVENTORY )
  4613. eq_n[k] = i;
  4614. eq_num++;
  4615. }
  4616. }
  4617. if(eq_num > 0){
  4618. int n = eq_n[rand()%eq_num];
  4619. if(rand()%10000 < per){
  4620. if(sd->status.inventory[n].equip)
  4621. pc_unequipitem(sd,n,3);
  4622. pc_dropitem(sd,n,1);
  4623. }
  4624. }
  4625. }
  4626. else if(id > 0){
  4627. for(i=0;i<MAX_INVENTORY;i++){
  4628. if(sd->status.inventory[i].nameid == id
  4629. && rand()%10000 < per
  4630. && ((type == 1 && !sd->status.inventory[i].equip)
  4631. || (type == 2 && sd->status.inventory[i].equip)
  4632. || type == 3) ){
  4633. if(sd->status.inventory[i].equip)
  4634. pc_unequipitem(sd,i,3);
  4635. pc_dropitem(sd,i,1);
  4636. break;
  4637. }
  4638. }
  4639. }
  4640. }
  4641. }
  4642. // pvp
  4643. // disable certain pvp functions on pk_mode [Valaris]
  4644. if (map[sd->bl.m].flag.gvg_dungeon ||
  4645. (map[sd->bl.m].flag.pvp && !battle_config.pk_mode && !map[sd->bl.m].flag.pvp_nocalcrank))
  4646. { //Pvp points always take effect on gvg_dungeon maps.
  4647. sd->pvp_point -= 5;
  4648. sd->pvp_lost++;
  4649. if (src && src->type == BL_PC) {
  4650. struct map_session_data *ssd = (struct map_session_data *)src;
  4651. ssd->pvp_point++;
  4652. ssd->pvp_won++;
  4653. }
  4654. if( sd->pvp_point < 0 ){
  4655. sd->pvp_point=0;
  4656. add_timer(tick+1000, pc_respawn_timer,sd->bl.id,0);
  4657. return 1|8;
  4658. }
  4659. }
  4660. //GvG
  4661. if(map_flag_gvg(sd->bl.m)){
  4662. add_timer(tick+1000, pc_respawn_timer,sd->bl.id,0);
  4663. return 1|8;
  4664. }
  4665. //Reset "can log out" tick.
  4666. if (battle_config.prevent_logout)
  4667. sd->canlog_tick = gettick() - battle_config.prevent_logout;
  4668. return 1;
  4669. }
  4670. void pc_revive(struct map_session_data *sd,unsigned int hp, unsigned int sp)
  4671. {
  4672. if(hp) clif_updatestatus(sd,SP_HP);
  4673. if(sp) clif_updatestatus(sd,SP_SP);
  4674. pc_setstand(sd);
  4675. if(battle_config.pc_invincible_time > 0)
  4676. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  4677. }
  4678. // script? 連
  4679. //
  4680. /*==========================================
  4681. * script用PCステ?タス?み出し
  4682. *------------------------------------------*/
  4683. int pc_readparam(struct map_session_data* sd,int type)
  4684. {
  4685. int val = 0;
  4686. nullpo_retr(0, sd);
  4687. switch(type) {
  4688. case SP_SKILLPOINT: val = sd->status.skill_point; break;
  4689. case SP_STATUSPOINT: val = sd->status.status_point; break;
  4690. case SP_ZENY: val = sd->status.zeny; break;
  4691. case SP_BASELEVEL: val = sd->status.base_level; break;
  4692. case SP_JOBLEVEL: val = sd->status.job_level; break;
  4693. case SP_CLASS: val = sd->status.class_; break;
  4694. case SP_BASEJOB: val = pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex); break; //Base job, extracting upper type.
  4695. case SP_UPPER: val = sd->class_&JOBL_UPPER?1:(sd->class_&JOBL_BABY?2:0); break;
  4696. case SP_BASECLASS: val = pc_mapid2jobid(sd->class_&MAPID_BASEMASK, sd->status.sex); break; //Extract base class tree. [Skotlex]
  4697. case SP_SEX: val = sd->status.sex; break;
  4698. case SP_WEIGHT: val = sd->weight; break;
  4699. case SP_MAXWEIGHT: val = sd->max_weight; break;
  4700. case SP_BASEEXP: val = sd->status.base_exp; break;
  4701. case SP_JOBEXP: val = sd->status.job_exp; break;
  4702. case SP_NEXTBASEEXP: val = pc_nextbaseexp(sd); break;
  4703. case SP_NEXTJOBEXP: val = pc_nextjobexp(sd); break;
  4704. case SP_HP: val = sd->battle_status.hp; break;
  4705. case SP_MAXHP: val = sd->battle_status.max_hp; break;
  4706. case SP_SP: val = sd->battle_status.sp; break;
  4707. case SP_MAXSP: val = sd->battle_status.max_sp; break;
  4708. case SP_STR: val = sd->status.str; break;
  4709. case SP_AGI: val = sd->status.agi; break;
  4710. case SP_VIT: val = sd->status.vit; break;
  4711. case SP_INT: val = sd->status.int_; break;
  4712. case SP_DEX: val = sd->status.dex; break;
  4713. case SP_LUK: val = sd->status.luk; break;
  4714. case SP_KARMA: val = sd->status.karma; break;
  4715. case SP_MANNER: val = sd->status.manner; break;
  4716. case SP_FAME: val = sd->status.fame; break;
  4717. }
  4718. return val;
  4719. }
  4720. /*==========================================
  4721. * script用PCステ?タス設定
  4722. *------------------------------------------*/
  4723. int pc_setparam(struct map_session_data *sd,int type,int val)
  4724. {
  4725. int i = 0;
  4726. nullpo_retr(0, sd);
  4727. switch(type){
  4728. case SP_BASELEVEL:
  4729. if ((unsigned int)val > pc_maxbaselv(sd)) //Capping to max
  4730. val = pc_maxbaselv(sd);
  4731. if ((unsigned int)val > sd->status.base_level) {
  4732. int stat=0;
  4733. for (i = 1; i <= (int)((unsigned int)val - sd->status.base_level); i++)
  4734. stat += (sd->status.base_level + i + 14) / 5 ;
  4735. if (sd->status.status_point > USHRT_MAX - stat)
  4736. sd->status.status_point = USHRT_MAX;
  4737. else
  4738. sd->status.status_point += stat;
  4739. }
  4740. sd->status.base_level = (unsigned int)val;
  4741. sd->status.base_exp = 0;
  4742. clif_updatestatus(sd, SP_BASELEVEL);
  4743. clif_updatestatus(sd, SP_NEXTBASEEXP);
  4744. clif_updatestatus(sd, SP_STATUSPOINT);
  4745. clif_updatestatus(sd, SP_BASEEXP);
  4746. status_calc_pc(sd, 0);
  4747. break;
  4748. case SP_JOBLEVEL:
  4749. if ((unsigned int)val >= sd->status.job_level) {
  4750. if ((unsigned int)val > pc_maxjoblv(sd)) val = pc_maxjoblv(sd);
  4751. if (sd->status.skill_point > USHRT_MAX - val + sd->status.job_level)
  4752. sd->status.skill_point = USHRT_MAX;
  4753. else
  4754. sd->status.skill_point += val-sd->status.job_level;
  4755. clif_updatestatus(sd, SP_SKILLPOINT);
  4756. }
  4757. sd->status.job_level = (unsigned int)val;
  4758. sd->status.job_exp = 0;
  4759. clif_updatestatus(sd, SP_JOBLEVEL);
  4760. clif_updatestatus(sd, SP_NEXTJOBEXP);
  4761. clif_updatestatus(sd, SP_JOBEXP);
  4762. status_calc_pc(sd, 0);
  4763. clif_updatestatus(sd,type);
  4764. break;
  4765. case SP_SKILLPOINT:
  4766. sd->status.skill_point = val;
  4767. break;
  4768. case SP_STATUSPOINT:
  4769. sd->status.status_point = val;
  4770. break;
  4771. case SP_ZENY:
  4772. sd->status.zeny = cap_value(val, 0, MAX_ZENY);
  4773. break;
  4774. case SP_BASEEXP:
  4775. if(pc_nextbaseexp(sd) > 0) {
  4776. sd->status.base_exp = val;
  4777. pc_checkbaselevelup(sd);
  4778. }
  4779. break;
  4780. case SP_JOBEXP:
  4781. if(pc_nextjobexp(sd) > 0) {
  4782. sd->status.job_exp = val;
  4783. pc_checkjoblevelup(sd);
  4784. }
  4785. break;
  4786. case SP_SEX:
  4787. sd->status.sex = val;
  4788. break;
  4789. case SP_WEIGHT:
  4790. sd->weight = val;
  4791. break;
  4792. case SP_MAXWEIGHT:
  4793. sd->max_weight = val;
  4794. break;
  4795. case SP_HP:
  4796. sd->battle_status.hp = val;
  4797. break;
  4798. case SP_MAXHP:
  4799. sd->battle_status.max_hp = val;
  4800. break;
  4801. case SP_SP:
  4802. sd->battle_status.sp = val;
  4803. break;
  4804. case SP_MAXSP:
  4805. sd->battle_status.max_sp = val;
  4806. break;
  4807. case SP_STR:
  4808. sd->status.str = val;
  4809. break;
  4810. case SP_AGI:
  4811. sd->status.agi = val;
  4812. break;
  4813. case SP_VIT:
  4814. sd->status.vit = val;
  4815. break;
  4816. case SP_INT:
  4817. sd->status.int_ = val;
  4818. break;
  4819. case SP_DEX:
  4820. sd->status.dex = val;
  4821. break;
  4822. case SP_LUK:
  4823. sd->status.luk = val;
  4824. break;
  4825. case SP_KARMA:
  4826. sd->status.karma = val;
  4827. break;
  4828. case SP_MANNER:
  4829. sd->status.manner = val;
  4830. break;
  4831. case SP_FAME:
  4832. sd->status.fame = val;
  4833. break;
  4834. }
  4835. clif_updatestatus(sd,type);
  4836. return 1;
  4837. }
  4838. /*==========================================
  4839. * HP/SP Healing. If flag is passed, the heal type is through clif_heal, otherwise update status.
  4840. *------------------------------------------*/
  4841. void pc_heal(struct map_session_data *sd,unsigned int hp,unsigned int sp, int type)
  4842. {
  4843. if (type) {
  4844. if (hp)
  4845. clif_heal(sd->fd,SP_HP,hp);
  4846. if (sp)
  4847. clif_heal(sd->fd,SP_SP,sp);
  4848. } else {
  4849. if(hp)
  4850. clif_updatestatus(sd,SP_HP);
  4851. if(sp)
  4852. clif_updatestatus(sd,SP_SP);
  4853. }
  4854. return;
  4855. }
  4856. /*==========================================
  4857. * HP/SP回復
  4858. *------------------------------------------*/
  4859. int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
  4860. {
  4861. int i, bonus;
  4862. if(hp) {
  4863. bonus = 100 + (sd->battle_status.vit<<1)
  4864. + pc_checkskill(sd,SM_RECOVERY)*10
  4865. + pc_checkskill(sd,AM_LEARNINGPOTION)*5;
  4866. // A potion produced by an Alchemist in the Fame Top 10 gets +50% effect [DracoRPG]
  4867. if (potion_flag > 1)
  4868. bonus += bonus*(potion_flag-1)*50/100;
  4869. //Item Group bonuses
  4870. bonus += bonus*itemdb_group_bonus(sd, itemid)/100;
  4871. //Individual item bonuses.
  4872. for(i = 0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid; i++)
  4873. {
  4874. if (sd->itemhealrate[i].nameid == itemid) {
  4875. bonus += bonus*sd->itemhealrate[i].rate/100;
  4876. break;
  4877. }
  4878. }
  4879. if(bonus!=100)
  4880. hp = hp * bonus / 100;
  4881. // Recovery Potion
  4882. if( sd->sc.data[SC_INCHEALRATE] )
  4883. hp += (int)(hp * sd->sc.data[SC_INCHEALRATE]->val1/100.);
  4884. }
  4885. if(sp) {
  4886. bonus = 100 + (sd->battle_status.int_<<1)
  4887. + pc_checkskill(sd,MG_SRECOVERY)*10
  4888. + pc_checkskill(sd,AM_LEARNINGPOTION)*5;
  4889. if (potion_flag > 1)
  4890. bonus += bonus*(potion_flag-1)*50/100;
  4891. if(bonus != 100)
  4892. sp = sp * bonus / 100;
  4893. }
  4894. if (sd->sc.data[SC_CRITICALWOUND])
  4895. {
  4896. hp -= hp * sd->sc.data[SC_CRITICALWOUND]->val2 / 100;
  4897. sp -= sp * sd->sc.data[SC_CRITICALWOUND]->val2 / 100;
  4898. }
  4899. return status_heal(&sd->bl, hp, sp, 1);
  4900. }
  4901. /*==========================================
  4902. * HP/SP回復
  4903. *------------------------------------------*/
  4904. int pc_percentheal(struct map_session_data *sd,int hp,int sp)
  4905. {
  4906. nullpo_retr(0, sd);
  4907. if(hp > 100) hp = 100;
  4908. else
  4909. if(hp <-100) hp =-100;
  4910. if(sp > 100) sp = 100;
  4911. else
  4912. if(sp <-100) sp =-100;
  4913. if(hp >= 0 && sp >= 0) //Heal
  4914. return status_percent_heal(&sd->bl, hp, sp);
  4915. if(hp <= 0 && sp <= 0) //Damage (negative rates indicate % of max rather than current), and only kill target IF the specified amount is 100%
  4916. return status_percent_damage(NULL, &sd->bl, hp, sp, hp==-100);
  4917. //Crossed signs
  4918. if(hp) {
  4919. if(hp > 0)
  4920. status_percent_heal(&sd->bl, hp, 0);
  4921. else
  4922. status_percent_damage(NULL, &sd->bl, hp, 0, hp==-100);
  4923. }
  4924. if(sp) {
  4925. if(sp > 0)
  4926. status_percent_heal(&sd->bl, 0, sp);
  4927. else
  4928. status_percent_damage(NULL, &sd->bl, 0, sp, false);
  4929. }
  4930. return 0;
  4931. }
  4932. /*==========================================
  4933. * 職?更
  4934. * 引? job 職業 0~23
  4935. * upper 通常 0, ?生 1, 養子 2, そのまま -1
  4936. * Rewrote to make it tidider [Celest]
  4937. *------------------------------------------*/
  4938. int pc_jobchange(struct map_session_data *sd,int job, int upper)
  4939. {
  4940. int i, fame_flag=0;
  4941. int b_class;
  4942. nullpo_retr(0, sd);
  4943. if (job < 0)
  4944. return 1;
  4945. //Normalize job.
  4946. b_class = pc_jobid2mapid(job);
  4947. if (b_class == -1)
  4948. return 1;
  4949. switch (upper) {
  4950. case 1:
  4951. b_class|= JOBL_UPPER;
  4952. break;
  4953. case 2:
  4954. b_class|= JOBL_BABY;
  4955. break;
  4956. }
  4957. //This will automatically adjust bard/dancer classes to the correct gender
  4958. //That is, if you try to jobchange into dancer, it will turn you to bard.
  4959. job = pc_mapid2jobid(b_class, sd->status.sex);
  4960. if (job == -1)
  4961. return 1;
  4962. if ((unsigned short)b_class == sd->class_)
  4963. return 1; //Nothing to change.
  4964. // check if we are changing from 1st to 2nd job
  4965. if (b_class&JOBL_2) {
  4966. if (!(sd->class_&JOBL_2))
  4967. sd->change_level = sd->status.job_level;
  4968. else if (!sd->change_level)
  4969. sd->change_level = 40; //Assume 40?
  4970. pc_setglobalreg (sd, "jobchange_level", sd->change_level);
  4971. }
  4972. if(sd->cloneskill_id) {
  4973. sd->cloneskill_id = 0;
  4974. pc_setglobalreg(sd, "CLONE_SKILL", 0);
  4975. pc_setglobalreg(sd, "CLONE_SKILL_LV", 0);
  4976. }
  4977. if ((b_class&&MAPID_UPPERMASK) != (sd->class_&MAPID_UPPERMASK))
  4978. { //Things to remove when changing class tree.
  4979. const int class_ = pc_class2idx(sd->status.class_);
  4980. short id;
  4981. for(i = 0; i < MAX_SKILL_TREE && (id = skill_tree[class_][i].id) > 0; i++) {
  4982. //Remove status specific to your current tree skills.
  4983. enum sc_type sc = status_skill2sc(id);
  4984. if (sc > SC_COMMON_MAX && sd->sc.data[sc])
  4985. status_change_end(&sd->bl, sc, -1);
  4986. }
  4987. }
  4988. sd->status.class_ = job;
  4989. fame_flag = pc_famerank(sd->status.char_id,sd->class_&MAPID_UPPERMASK);
  4990. sd->class_ = (unsigned short)b_class;
  4991. sd->status.job_level=1;
  4992. sd->status.job_exp=0;
  4993. clif_updatestatus(sd,SP_JOBLEVEL);
  4994. clif_updatestatus(sd,SP_JOBEXP);
  4995. clif_updatestatus(sd,SP_NEXTJOBEXP);
  4996. for(i=0;i<EQI_MAX;i++) {
  4997. if(sd->equip_index[i] >= 0)
  4998. if(!pc_isequip(sd,sd->equip_index[i]))
  4999. pc_unequipitem(sd,sd->equip_index[i],2); // ?備外し
  5000. }
  5001. //Change look, if disguised, you need to undisguise
  5002. //to correctly calculate new job sprite without
  5003. if (sd->disguise)
  5004. pc_disguise(sd, 0);
  5005. status_set_viewdata(&sd->bl, job);
  5006. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_); // move sprite update to prevent client crashes with incompatible equipment [Valaris]
  5007. if(sd->vd.cloth_color)
  5008. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  5009. //Update skill tree.
  5010. pc_calc_skilltree(sd);
  5011. clif_skillinfoblock(sd);
  5012. //Remove peco/cart/falcon
  5013. i = sd->sc.option;
  5014. if(i&OPTION_RIDING && !pc_checkskill(sd, KN_RIDING))
  5015. i&=~OPTION_RIDING;
  5016. if(i&OPTION_CART && !pc_checkskill(sd, MC_PUSHCART))
  5017. i&=~OPTION_CART;
  5018. if(i&OPTION_FALCON && !pc_checkskill(sd, HT_FALCON))
  5019. i&=~OPTION_FALCON;
  5020. if(i != sd->sc.option)
  5021. pc_setoption(sd, i);
  5022. if(merc_is_hom_active(sd->hd) && !pc_checkskill(sd, AM_CALLHOMUN))
  5023. merc_hom_vaporize(sd, 0);
  5024. if(sd->status.manner < 0)
  5025. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  5026. status_calc_pc(sd,0);
  5027. pc_checkallowskill(sd);
  5028. pc_equiplookall(sd);
  5029. //if you were previously famous, not anymore.
  5030. if (fame_flag) {
  5031. chrif_save(sd,0);
  5032. chrif_buildfamelist();
  5033. } else if (sd->status.fame > 0) {
  5034. //It may be that now they are famous?
  5035. switch (sd->class_&MAPID_UPPERMASK) {
  5036. case MAPID_BLACKSMITH:
  5037. case MAPID_ALCHEMIST:
  5038. case MAPID_TAEKWON:
  5039. chrif_save(sd,0);
  5040. chrif_buildfamelist();
  5041. break;
  5042. }
  5043. }
  5044. return 0;
  5045. }
  5046. /*==========================================
  5047. * 見た目?更
  5048. *------------------------------------------*/
  5049. int pc_equiplookall(struct map_session_data *sd)
  5050. {
  5051. nullpo_retr(0, sd);
  5052. #if PACKETVER < 4
  5053. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  5054. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  5055. #else
  5056. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  5057. clif_changelook(&sd->bl,LOOK_SHOES,0);
  5058. #endif
  5059. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  5060. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  5061. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  5062. return 0;
  5063. }
  5064. /*==========================================
  5065. * 見た目?更
  5066. *------------------------------------------*/
  5067. int pc_changelook(struct map_session_data *sd,int type,int val)
  5068. {
  5069. nullpo_retr(0, sd);
  5070. switch(type){
  5071. case LOOK_HAIR: //Use the battle_config limits! [Skotlex]
  5072. if (val < battle_config.min_hair_style)
  5073. val = battle_config.min_hair_style;
  5074. else if (val > battle_config.max_hair_style)
  5075. val = battle_config.max_hair_style;
  5076. if (sd->status.hair != val)
  5077. {
  5078. sd->status.hair=val;
  5079. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  5080. intif_guild_change_memberinfo(sd->status.guild_id,sd->status.account_id,sd->status.char_id,
  5081. GMI_HAIR,&sd->status.hair,sizeof(sd->status.hair));
  5082. }
  5083. break;
  5084. case LOOK_WEAPON:
  5085. sd->status.weapon=val;
  5086. break;
  5087. case LOOK_HEAD_BOTTOM:
  5088. sd->status.head_bottom=val;
  5089. break;
  5090. case LOOK_HEAD_TOP:
  5091. sd->status.head_top=val;
  5092. break;
  5093. case LOOK_HEAD_MID:
  5094. sd->status.head_mid=val;
  5095. break;
  5096. case LOOK_HAIR_COLOR: //Use the battle_config limits! [Skotlex]
  5097. if (val < battle_config.min_hair_color)
  5098. val = battle_config.min_hair_color;
  5099. else if (val > battle_config.max_hair_color)
  5100. val = battle_config.max_hair_color;
  5101. if (sd->status.hair_color != val)
  5102. {
  5103. sd->status.hair_color=val;
  5104. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  5105. intif_guild_change_memberinfo(sd->status.guild_id,sd->status.account_id,sd->status.char_id,
  5106. GMI_HAIR_COLOR,&sd->status.hair_color,sizeof(sd->status.hair_color));
  5107. }
  5108. break;
  5109. case LOOK_CLOTHES_COLOR: //Use the battle_config limits! [Skotlex]
  5110. if (val < battle_config.min_cloth_color)
  5111. val = battle_config.min_cloth_color;
  5112. else if (val > battle_config.max_cloth_color)
  5113. val = battle_config.max_cloth_color;
  5114. sd->status.clothes_color=val;
  5115. break;
  5116. case LOOK_SHIELD:
  5117. sd->status.shield=val;
  5118. break;
  5119. case LOOK_SHOES:
  5120. break;
  5121. }
  5122. clif_changelook(&sd->bl,type,val);
  5123. return 0;
  5124. }
  5125. /*==========================================
  5126. * 付?品(鷹,ペコ,カ?ト)設定
  5127. *------------------------------------------*/
  5128. int pc_setoption(struct map_session_data *sd,int type)
  5129. {
  5130. int p_type, new_look=0;
  5131. nullpo_retr(0, sd);
  5132. p_type = sd->sc.option;
  5133. //Option has to be changed client-side before the class sprite or it won't always work (eg: Wedding sprite) [Skotlex]
  5134. sd->sc.option=type;
  5135. clif_changeoption(&sd->bl);
  5136. if (type&OPTION_RIDING && !(p_type&OPTION_RIDING) && (sd->class_&MAPID_BASEMASK) == MAPID_SWORDMAN)
  5137. { //We are going to mount. [Skotlex]
  5138. new_look = -1;
  5139. clif_status_load(&sd->bl,SI_RIDING,1);
  5140. status_calc_pc(sd,0); //Mounting/Umounting affects walk and attack speeds.
  5141. }
  5142. else if (!(type&OPTION_RIDING) && p_type&OPTION_RIDING && (sd->class_&MAPID_BASEMASK) == MAPID_SWORDMAN)
  5143. { //We are going to dismount.
  5144. new_look = -1;
  5145. clif_status_load(&sd->bl,SI_RIDING,0);
  5146. status_calc_pc(sd,0); //Mounting/Umounting affects walk and attack speeds.
  5147. }
  5148. if(type&OPTION_CART && !(p_type&OPTION_CART))
  5149. { //Cart On
  5150. clif_cartlist(sd);
  5151. clif_updatestatus(sd, SP_CARTINFO);
  5152. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  5153. status_calc_pc(sd,0); //Apply speed penalty.
  5154. } else
  5155. if(!(type&OPTION_CART) && p_type&OPTION_CART)
  5156. { //Cart Off
  5157. clif_clearcart(sd->fd);
  5158. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  5159. status_calc_pc(sd,0); //Remove speed penalty.
  5160. }
  5161. if (type&OPTION_FALCON && !(p_type&OPTION_FALCON)) //Falcon ON
  5162. clif_status_load(&sd->bl,SI_FALCON,1);
  5163. else if (!(type&OPTION_FALCON) && p_type&OPTION_FALCON) //Falcon OFF
  5164. clif_status_load(&sd->bl,SI_FALCON,0);
  5165. if (type&OPTION_FLYING && !(p_type&OPTION_FLYING))
  5166. new_look = JOB_STAR_GLADIATOR2;
  5167. else if (!(type&OPTION_FLYING) && p_type&OPTION_FLYING)
  5168. new_look = -1;
  5169. if (type&OPTION_WEDDING && !(p_type&OPTION_WEDDING))
  5170. new_look = JOB_WEDDING;
  5171. else if (!(type&OPTION_WEDDING) && p_type&OPTION_WEDDING)
  5172. new_look = -1;
  5173. if (type&OPTION_XMAS && !(p_type&OPTION_XMAS))
  5174. new_look = JOB_XMAS;
  5175. else if (!(type&OPTION_XMAS) && p_type&OPTION_XMAS)
  5176. new_look = -1;
  5177. if (type&OPTION_SUMMER && !(p_type&OPTION_SUMMER))
  5178. new_look = JOB_SUMMER;
  5179. else if (!(type&OPTION_SUMMER) && p_type&OPTION_SUMMER)
  5180. new_look = -1;
  5181. if (sd->disguise)
  5182. return 0; //Disguises break sprite changes
  5183. if (new_look < 0) { //Restore normal look.
  5184. status_set_viewdata(&sd->bl, sd->status.class_);
  5185. new_look = sd->vd.class_;
  5186. }
  5187. if (new_look) {
  5188. //Stop attacking on new view change (to prevent wedding/santa attacks.
  5189. pc_stop_attack(sd);
  5190. clif_changelook(&sd->bl,LOOK_BASE,new_look);
  5191. if (sd->vd.cloth_color)
  5192. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  5193. }
  5194. return 0;
  5195. }
  5196. /*==========================================
  5197. * カ?ト設定
  5198. *------------------------------------------*/
  5199. int pc_setcart(struct map_session_data *sd,int type)
  5200. {
  5201. int cart[6] = {0x0000,OPTION_CART1,OPTION_CART2,OPTION_CART3,OPTION_CART4,OPTION_CART5};
  5202. int option;
  5203. nullpo_retr(0, sd);
  5204. if( type < 0 || type > 5 )
  5205. return 1;// Never trust the values sent by the client! [Skotlex]
  5206. if( pc_checkskill(sd,MC_PUSHCART) <= 0 )
  5207. return 1;// Push cart is required
  5208. // Update option
  5209. option = sd->sc.option;
  5210. option &= ~OPTION_CART;// clear cart bits
  5211. option |= cart[type]; // set cart
  5212. pc_setoption(sd, option);
  5213. return 0;
  5214. }
  5215. /*==========================================
  5216. * 鷹設定
  5217. *------------------------------------------*/
  5218. int pc_setfalcon(TBL_PC* sd, int flag)
  5219. {
  5220. if( flag ){
  5221. if( pc_checkskill(sd,HT_FALCON)>0 ) // ファルコンマスタリ?スキル所持
  5222. pc_setoption(sd,sd->sc.option|OPTION_FALCON);
  5223. } else if( pc_isfalcon(sd) ){
  5224. pc_setoption(sd,sd->sc.option&~OPTION_FALCON); // remove falcon
  5225. }
  5226. return 0;
  5227. }
  5228. /*==========================================
  5229. * ペコペコ設定
  5230. *------------------------------------------*/
  5231. int pc_setriding(TBL_PC* sd, int flag)
  5232. {
  5233. if( flag ){
  5234. if( pc_checkskill(sd,KN_RIDING) > 0 ) // ライディングスキル所持
  5235. pc_setoption(sd, sd->sc.option|OPTION_RIDING);
  5236. } else if( pc_isriding(sd) ){
  5237. pc_setoption(sd, sd->sc.option&~OPTION_RIDING);
  5238. }
  5239. return 0;
  5240. }
  5241. /*==========================================
  5242. * アイテムドロップ可不可判定
  5243. *------------------------------------------*/
  5244. int pc_candrop(struct map_session_data *sd,struct item *item)
  5245. {
  5246. int level = pc_isGM(sd);
  5247. if ( !pc_can_give_items(level) ) //check if this GM level can drop items
  5248. return 0;
  5249. return (itemdb_isdropable(item, level));
  5250. }
  5251. /*==========================================
  5252. * script用??の値を?む
  5253. *------------------------------------------*/
  5254. int pc_readreg(struct map_session_data* sd, int reg)
  5255. {
  5256. int i;
  5257. nullpo_retr(0, sd);
  5258. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg );
  5259. return ( i < sd->reg_num ) ? sd->reg[i].data : 0;
  5260. }
  5261. /*==========================================
  5262. * script用??の値を設定
  5263. *------------------------------------------*/
  5264. int pc_setreg(struct map_session_data* sd, int reg, int val)
  5265. {
  5266. int i;
  5267. nullpo_retr(0, sd);
  5268. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg );
  5269. if( i < sd->reg_num )
  5270. {// overwrite existing entry
  5271. sd->reg[i].data = val;
  5272. return 1;
  5273. }
  5274. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].data == 0 );
  5275. if( i == sd->reg_num )
  5276. {// nothing free, increase size
  5277. sd->reg_num++;
  5278. RECREATE(sd->reg, struct script_reg, sd->reg_num);
  5279. }
  5280. sd->reg[i].index = reg;
  5281. sd->reg[i].data = val;
  5282. return 1;
  5283. }
  5284. /*==========================================
  5285. * script用文字列??の値を?む
  5286. *------------------------------------------*/
  5287. char* pc_readregstr(struct map_session_data* sd, int reg)
  5288. {
  5289. int i;
  5290. nullpo_retr(0, sd);
  5291. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg );
  5292. return ( i < sd->regstr_num ) ? sd->regstr[i].data : NULL;
  5293. }
  5294. /*==========================================
  5295. * script用文字列??の値を設定
  5296. *------------------------------------------*/
  5297. int pc_setregstr(struct map_session_data* sd, int reg, const char* str)
  5298. {
  5299. int i;
  5300. nullpo_retr(0, sd);
  5301. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg );
  5302. if( i < sd->regstr_num )
  5303. {// found entry, update
  5304. if( str == NULL || *str == '\0' )
  5305. {// empty string
  5306. if( sd->regstr[i].data != NULL )
  5307. aFree(sd->regstr[i].data);
  5308. sd->regstr[i].data = NULL;
  5309. }
  5310. else if( sd->regstr[i].data )
  5311. {// recreate
  5312. size_t len = strlen(str)+1;
  5313. RECREATE(sd->regstr[i].data, char, len);
  5314. memcpy(sd->regstr[i].data, str, len*sizeof(char));
  5315. }
  5316. else
  5317. {// create
  5318. sd->regstr[i].data = aStrdup(str);
  5319. }
  5320. return 1;
  5321. }
  5322. if( str == NULL || *str == '\0' )
  5323. return 1;// nothing to add, empty string
  5324. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].data == NULL );
  5325. if( i == sd->regstr_num )
  5326. {// nothing free, increase size
  5327. sd->regstr_num++;
  5328. RECREATE(sd->regstr, struct script_regstr, sd->regstr_num);
  5329. }
  5330. sd->regstr[i].index = reg;
  5331. sd->regstr[i].data = aStrdup(str);
  5332. return 1;
  5333. }
  5334. int pc_readregistry(struct map_session_data *sd,const char *reg,int type)
  5335. {
  5336. struct global_reg *sd_reg;
  5337. int i,max;
  5338. nullpo_retr(0, sd);
  5339. switch (type) {
  5340. case 3: //Char reg
  5341. sd_reg = sd->save_reg.global;
  5342. max = sd->save_reg.global_num;
  5343. break;
  5344. case 2: //Account reg
  5345. sd_reg = sd->save_reg.account;
  5346. max = sd->save_reg.account_num;
  5347. break;
  5348. case 1: //Account2 reg
  5349. sd_reg = sd->save_reg.account2;
  5350. max = sd->save_reg.account2_num;
  5351. break;
  5352. default:
  5353. return 0;
  5354. }
  5355. if (max == -1) {
  5356. ShowError("pc_readregistry: Trying to read reg value %s (type %d) before it's been loaded!\n", reg, type);
  5357. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  5358. intif_request_registry(sd,type==3?4:type);
  5359. return 0;
  5360. }
  5361. ARR_FIND( 0, max, i, strcmp(sd_reg[i].str,reg) == 0 );
  5362. return ( i < max ) ? atoi(sd_reg[i].value) : 0;
  5363. }
  5364. char* pc_readregistry_str(struct map_session_data *sd,const char *reg,int type)
  5365. {
  5366. struct global_reg *sd_reg;
  5367. int i,max;
  5368. nullpo_retr(0, sd);
  5369. switch (type) {
  5370. case 3: //Char reg
  5371. sd_reg = sd->save_reg.global;
  5372. max = sd->save_reg.global_num;
  5373. break;
  5374. case 2: //Account reg
  5375. sd_reg = sd->save_reg.account;
  5376. max = sd->save_reg.account_num;
  5377. break;
  5378. case 1: //Account2 reg
  5379. sd_reg = sd->save_reg.account2;
  5380. max = sd->save_reg.account2_num;
  5381. break;
  5382. default:
  5383. return NULL;
  5384. }
  5385. if (max == -1) {
  5386. ShowError("pc_readregistry: Trying to read reg value %s (type %d) before it's been loaded!\n", reg, type);
  5387. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  5388. intif_request_registry(sd,type==3?4:type);
  5389. return NULL;
  5390. }
  5391. ARR_FIND( 0, max, i, strcmp(sd_reg[i].str,reg) == 0 );
  5392. return ( i < max ) ? sd_reg[i].value : NULL;
  5393. }
  5394. int pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type)
  5395. {
  5396. struct global_reg *sd_reg;
  5397. int i,*max, regmax;
  5398. nullpo_retr(0, sd);
  5399. switch( type )
  5400. {
  5401. case 3: //Char reg
  5402. if( !strcmp(reg,"PC_DIE_COUNTER") && sd->die_counter != val )
  5403. {
  5404. i = (!sd->die_counter && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE);
  5405. sd->die_counter = val;
  5406. if( i )
  5407. status_calc_pc(sd,0); // Lost the bonus.
  5408. }
  5409. sd_reg = sd->save_reg.global;
  5410. max = &sd->save_reg.global_num;
  5411. regmax = GLOBAL_REG_NUM;
  5412. break;
  5413. case 2: //Account reg
  5414. if( !strcmp(reg,"#CASHPOINTS") && sd->cashPoints != val )
  5415. {
  5416. val = cap_value(val, 0, MAX_ZENY);
  5417. sd->cashPoints = val;
  5418. }
  5419. else if( !strcmp(reg,"#KAFRAPOINTS") && sd->kafraPoints != val )
  5420. {
  5421. val = cap_value(val, 0, MAX_ZENY);
  5422. sd->kafraPoints = val;
  5423. }
  5424. sd_reg = sd->save_reg.account;
  5425. max = &sd->save_reg.account_num;
  5426. regmax = ACCOUNT_REG_NUM;
  5427. break;
  5428. case 1: //Account2 reg
  5429. sd_reg = sd->save_reg.account2;
  5430. max = &sd->save_reg.account2_num;
  5431. regmax = ACCOUNT_REG2_NUM;
  5432. break;
  5433. default:
  5434. return 0;
  5435. }
  5436. if (*max == -1) {
  5437. ShowError("pc_setregistry : refusing to set %s (type %d) until vars are received.\n", reg, type);
  5438. return 1;
  5439. }
  5440. // delete reg
  5441. if (val == 0) {
  5442. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  5443. if( i < *max )
  5444. {
  5445. if (i != *max - 1)
  5446. memcpy(&sd_reg[i], &sd_reg[*max - 1], sizeof(struct global_reg));
  5447. memset(&sd_reg[*max - 1], 0, sizeof(struct global_reg));
  5448. (*max)--;
  5449. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  5450. }
  5451. return 1;
  5452. }
  5453. // change value if found
  5454. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  5455. if( i < *max )
  5456. {
  5457. safesnprintf(sd_reg[i].value, sizeof(sd_reg[i].value), "%d", val);
  5458. sd->state.reg_dirty |= 1<<(type-1);
  5459. return 1;
  5460. }
  5461. // add value if not found
  5462. if (i < regmax) {
  5463. memset(&sd_reg[i], 0, sizeof(struct global_reg));
  5464. safestrncpy(sd_reg[i].str, reg, sizeof(sd_reg[i].str));
  5465. safesnprintf(sd_reg[i].value, sizeof(sd_reg[i].value), "%d", val);
  5466. (*max)++;
  5467. sd->state.reg_dirty |= 1<<(type-1);
  5468. return 1;
  5469. }
  5470. ShowError("pc_setregistry : couldn't set %s, limit of registries reached (%d)\n", reg, regmax);
  5471. return 0;
  5472. }
  5473. int pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *val,int type)
  5474. {
  5475. struct global_reg *sd_reg;
  5476. int i,*max, regmax;
  5477. nullpo_retr(0, sd);
  5478. if (reg[strlen(reg)-1] != '$') {
  5479. ShowError("pc_setregistry_str : reg %s must be string (end in '$') to use this!\n", reg);
  5480. return 0;
  5481. }
  5482. switch (type) {
  5483. case 3: //Char reg
  5484. sd_reg = sd->save_reg.global;
  5485. max = &sd->save_reg.global_num;
  5486. regmax = GLOBAL_REG_NUM;
  5487. break;
  5488. case 2: //Account reg
  5489. sd_reg = sd->save_reg.account;
  5490. max = &sd->save_reg.account_num;
  5491. regmax = ACCOUNT_REG_NUM;
  5492. break;
  5493. case 1: //Account2 reg
  5494. sd_reg = sd->save_reg.account2;
  5495. max = &sd->save_reg.account2_num;
  5496. regmax = ACCOUNT_REG2_NUM;
  5497. break;
  5498. default:
  5499. return 0;
  5500. }
  5501. if (*max == -1) {
  5502. ShowError("pc_setregistry_str : refusing to set %s (type %d) until vars are received.\n", reg, type);
  5503. return 0;
  5504. }
  5505. // delete reg
  5506. if (!val || strcmp(val,"")==0)
  5507. {
  5508. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  5509. if( i < *max )
  5510. {
  5511. if (i != *max - 1)
  5512. memcpy(&sd_reg[i], &sd_reg[*max - 1], sizeof(struct global_reg));
  5513. memset(&sd_reg[*max - 1], 0, sizeof(struct global_reg));
  5514. (*max)--;
  5515. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  5516. if (type!=3) intif_saveregistry(sd,type);
  5517. }
  5518. return 1;
  5519. }
  5520. // change value if found
  5521. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  5522. if( i < *max )
  5523. {
  5524. safestrncpy(sd_reg[i].value, val, sizeof(sd_reg[i].value));
  5525. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  5526. if (type!=3) intif_saveregistry(sd,type);
  5527. return 1;
  5528. }
  5529. // add value if not found
  5530. if (i < regmax) {
  5531. memset(&sd_reg[i], 0, sizeof(struct global_reg));
  5532. safestrncpy(sd_reg[i].str, reg, sizeof(sd_reg[i].str));
  5533. safestrncpy(sd_reg[i].value, val, sizeof(sd_reg[i].value));
  5534. (*max)++;
  5535. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  5536. if (type!=3) intif_saveregistry(sd,type);
  5537. return 1;
  5538. }
  5539. ShowError("pc_setregistry : couldn't set %s, limit of registries reached (%d)\n", reg, regmax);
  5540. return 0;
  5541. }
  5542. /*==========================================
  5543. * イベントタイマ??理
  5544. *------------------------------------------*/
  5545. static int pc_eventtimer(int tid, unsigned int tick, int id, intptr data)
  5546. {
  5547. struct map_session_data *sd=map_id2sd(id);
  5548. char *p = (char *)data;
  5549. int i;
  5550. if(sd==NULL)
  5551. return 0;
  5552. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == tid );
  5553. if( i < MAX_EVENTTIMER )
  5554. {
  5555. sd->eventtimer[i] = -1;
  5556. sd->eventcount--;
  5557. npc_event(sd,p,0);
  5558. }
  5559. else
  5560. ShowError("pc_eventtimer: no such event timer\n");
  5561. if (p) aFree(p);
  5562. return 0;
  5563. }
  5564. /*==========================================
  5565. * イベントタイマ?追加
  5566. *------------------------------------------*/
  5567. int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
  5568. {
  5569. int i;
  5570. nullpo_retr(0, sd);
  5571. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == -1 );
  5572. if( i == MAX_EVENTTIMER )
  5573. return 0;
  5574. sd->eventtimer[i] = add_timer(gettick()+tick, pc_eventtimer, sd->bl.id, (int)aStrdup(name));
  5575. sd->eventcount++;
  5576. return 1;
  5577. }
  5578. /*==========================================
  5579. * イベントタイマ?削除
  5580. *------------------------------------------*/
  5581. int pc_deleventtimer(struct map_session_data *sd,const char *name)
  5582. {
  5583. char* p = NULL;
  5584. int i;
  5585. nullpo_retr(0, sd);
  5586. if (sd->eventcount <= 0)
  5587. return 0;
  5588. // find the named event timer
  5589. ARR_FIND( 0, MAX_EVENTTIMER, i,
  5590. sd->eventtimer[i] != -1 &&
  5591. (p = (char *)(get_timer(sd->eventtimer[i])->data)) != NULL &&
  5592. strcmp(p, name) == 0
  5593. );
  5594. if( i == MAX_EVENTTIMER )
  5595. return 0; // not found
  5596. delete_timer(sd->eventtimer[i],pc_eventtimer);
  5597. sd->eventtimer[i]=-1;
  5598. sd->eventcount--;
  5599. aFree(p);
  5600. return 1;
  5601. }
  5602. /*==========================================
  5603. * イベントタイマ?カウント値追加
  5604. *------------------------------------------*/
  5605. int pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick)
  5606. {
  5607. int i;
  5608. nullpo_retr(0, sd);
  5609. for(i=0;i<MAX_EVENTTIMER;i++)
  5610. if( sd->eventtimer[i]!=-1 && strcmp(
  5611. (char *)(get_timer(sd->eventtimer[i])->data), name)==0 ){
  5612. addtick_timer(sd->eventtimer[i],tick);
  5613. break;
  5614. }
  5615. return 0;
  5616. }
  5617. /*==========================================
  5618. * イベントタイマ?全削除
  5619. *------------------------------------------*/
  5620. int pc_cleareventtimer(struct map_session_data *sd)
  5621. {
  5622. int i;
  5623. nullpo_retr(0, sd);
  5624. if (sd->eventcount <= 0)
  5625. return 0;
  5626. for(i=0;i<MAX_EVENTTIMER;i++)
  5627. if( sd->eventtimer[i]!=-1 ){
  5628. char *p = (char *)(get_timer(sd->eventtimer[i])->data);
  5629. delete_timer(sd->eventtimer[i],pc_eventtimer);
  5630. sd->eventtimer[i]=-1;
  5631. sd->eventcount--;
  5632. if (p) aFree(p);
  5633. }
  5634. return 0;
  5635. }
  5636. //
  5637. // ? 備物
  5638. //
  5639. /*==========================================
  5640. * アイテムを?備する
  5641. *------------------------------------------*/
  5642. int pc_equipitem(struct map_session_data *sd,int n,int req_pos)
  5643. {
  5644. int i,pos,flag=0;
  5645. struct item_data *id;
  5646. nullpo_retr(0, sd);
  5647. if( n < 0 || n >= MAX_INVENTORY ) {
  5648. clif_equipitemack(sd,0,0,0);
  5649. return 0;
  5650. }
  5651. id = sd->inventory_data[n];
  5652. pos = pc_equippoint(sd,n); //With a few exceptions, item should go in all specified slots.
  5653. if(battle_config.battle_log)
  5654. ShowInfo("equip %d(%d) %x:%x\n",sd->status.inventory[n].nameid,n,id->equip,req_pos);
  5655. if(!pc_isequip(sd,n) || !(pos&req_pos) || sd->status.inventory[n].attribute==1 ) { // [Valaris]
  5656. clif_equipitemack(sd,n,0,0); // fail
  5657. return 0;
  5658. }
  5659. if(sd->sc.data[SC_BERSERK] || sd->sc.data[SC_BLADESTOP])
  5660. {
  5661. clif_equipitemack(sd,n,0,0); // fail
  5662. return 0;
  5663. }
  5664. if(pos == EQP_ACC) { //Accesories should only go in one of the two,
  5665. pos = req_pos&EQP_ACC;
  5666. if (pos == EQP_ACC) //User specified both slots..
  5667. pos = sd->equip_index[EQI_ACC_R] >= 0 ? EQP_ACC_L : EQP_ACC_R;
  5668. }
  5669. if(pos == EQP_ARMS && id->equip == EQP_HAND_R)
  5670. { //Dual wield capable weapon.
  5671. pos = (req_pos&EQP_ARMS);
  5672. if (pos == EQP_ARMS) //User specified both slots, pick one for them.
  5673. pos = sd->equip_index[EQI_HAND_R] >= 0 ? EQP_HAND_L : EQP_HAND_R;
  5674. }
  5675. if (pos&EQP_HAND_R && battle_config.use_weapon_skill_range&BL_PC)
  5676. { //Update skill-block range database when weapon range changes. [Skotlex]
  5677. i = sd->equip_index[EQI_HAND_R];
  5678. if (i < 0 || !sd->inventory_data[i]) //No data, or no weapon equipped
  5679. flag = 1;
  5680. else
  5681. flag = id->range != sd->inventory_data[i]->range;
  5682. }
  5683. for(i=0;i<EQI_MAX;i++) {
  5684. if(pos & equip_pos[i]) {
  5685. if(sd->equip_index[i] >= 0) //Slot taken, remove item from there.
  5686. pc_unequipitem(sd,sd->equip_index[i],2);
  5687. sd->equip_index[i] = n;
  5688. }
  5689. }
  5690. if(pos==EQP_AMMO){
  5691. clif_arrowequip(sd,n);
  5692. clif_arrow_fail(sd,3);
  5693. }
  5694. else
  5695. clif_equipitemack(sd,n,pos,1);
  5696. sd->status.inventory[n].equip=pos;
  5697. if(pos & EQP_HAND_R) {
  5698. if(id)
  5699. sd->weapontype1 = id->look;
  5700. else
  5701. sd->weapontype1 = 0;
  5702. pc_calcweapontype(sd);
  5703. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  5704. }
  5705. if(pos & EQP_HAND_L) {
  5706. if(id) {
  5707. if(id->type == IT_WEAPON) {
  5708. sd->status.shield = 0;
  5709. if(sd->status.inventory[n].equip == EQP_HAND_L)
  5710. sd->weapontype2 = id->look;
  5711. else
  5712. sd->weapontype2 = 0;
  5713. }
  5714. else
  5715. if(id->type == IT_ARMOR) {
  5716. sd->status.shield = id->look;
  5717. sd->weapontype2 = 0;
  5718. }
  5719. }
  5720. else
  5721. sd->status.shield = sd->weapontype2 = 0;
  5722. pc_calcweapontype(sd);
  5723. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  5724. }
  5725. //Added check to prevent sending the same look on multiple slots ->
  5726. //causes client to redraw item on top of itself. (suggested by Lupus)
  5727. if(pos & EQP_HEAD_LOW) {
  5728. if(id && !(pos&(EQP_HEAD_TOP|EQP_HEAD_MID)))
  5729. sd->status.head_bottom = id->look;
  5730. else
  5731. sd->status.head_bottom = 0;
  5732. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  5733. }
  5734. if(pos & EQP_HEAD_TOP) {
  5735. if(id)
  5736. sd->status.head_top = id->look;
  5737. else
  5738. sd->status.head_top = 0;
  5739. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  5740. }
  5741. if(pos & EQP_HEAD_MID) {
  5742. if(id && !(pos&EQP_HEAD_TOP))
  5743. sd->status.head_mid = id->look;
  5744. else
  5745. sd->status.head_mid = 0;
  5746. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  5747. }
  5748. if(pos & EQP_SHOES)
  5749. clif_changelook(&sd->bl,LOOK_SHOES,0);
  5750. pc_checkallowskill(sd); //Check if status changes should be halted.
  5751. status_calc_pc(sd,0);
  5752. if (flag) //Update skill data
  5753. clif_skillinfoblock(sd);
  5754. //OnEquip script [Skotlex]
  5755. if (id) {
  5756. int i;
  5757. struct item_data *data;
  5758. if (id->equip_script)
  5759. run_script(id->equip_script,0,sd->bl.id,fake_nd->bl.id);
  5760. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  5761. ; //No cards
  5762. else
  5763. for(i=0;i<id->slot; i++)
  5764. {
  5765. if (!sd->status.inventory[n].card[i])
  5766. continue;
  5767. data = itemdb_exists(sd->status.inventory[n].card[i]);
  5768. if (data && data->equip_script)
  5769. run_script(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
  5770. }
  5771. }
  5772. return 0;
  5773. }
  5774. /*==========================================
  5775. * ? 備した物を外す
  5776. * type:
  5777. * 0 - only unequip
  5778. * 1 - calculate status after unequipping
  5779. * 2 - force unequip
  5780. *------------------------------------------*/
  5781. int pc_unequipitem(struct map_session_data *sd,int n,int flag)
  5782. {
  5783. int i;
  5784. nullpo_retr(0, sd);
  5785. if( n < 0 || n >= MAX_INVENTORY ) {
  5786. clif_unequipitemack(sd,0,0,0);
  5787. return 0;
  5788. }
  5789. // if player is berserk then cannot unequip
  5790. if(!(flag&2) && sd->sc.count && (sd->sc.data[SC_BLADESTOP] || sd->sc.data[SC_BERSERK])){
  5791. clif_unequipitemack(sd,n,0,0);
  5792. return 0;
  5793. }
  5794. if(battle_config.battle_log)
  5795. ShowInfo("unequip %d %x:%x\n",n,pc_equippoint(sd,n),sd->status.inventory[n].equip);
  5796. if(!sd->status.inventory[n].equip){ //Nothing to unequip
  5797. clif_unequipitemack(sd,n,0,0);
  5798. return 0;
  5799. }
  5800. for(i=0;i<EQI_MAX;i++) {
  5801. if(sd->status.inventory[n].equip & equip_pos[i])
  5802. sd->equip_index[i] = -1;
  5803. }
  5804. if(sd->status.inventory[n].equip & EQP_HAND_R) {
  5805. sd->weapontype1 = 0;
  5806. sd->status.weapon = sd->weapontype2;
  5807. pc_calcweapontype(sd);
  5808. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  5809. if(sd->sc.data[SC_DANCING]) //When unequipping, stop dancing. [Skotlex]
  5810. skill_stop_dancing(&sd->bl);
  5811. }
  5812. if(sd->status.inventory[n].equip & EQP_HAND_L) {
  5813. sd->status.shield = sd->weapontype2 = 0;
  5814. pc_calcweapontype(sd);
  5815. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  5816. }
  5817. if(sd->status.inventory[n].equip & EQP_HEAD_LOW) {
  5818. sd->status.head_bottom = 0;
  5819. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  5820. }
  5821. if(sd->status.inventory[n].equip & EQP_HEAD_TOP) {
  5822. sd->status.head_top = 0;
  5823. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  5824. }
  5825. if(sd->status.inventory[n].equip & EQP_HEAD_MID) {
  5826. sd->status.head_mid = 0;
  5827. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  5828. }
  5829. if(sd->status.inventory[n].equip & EQP_SHOES)
  5830. clif_changelook(&sd->bl,LOOK_SHOES,0);
  5831. clif_unequipitemack(sd,n,sd->status.inventory[n].equip,1);
  5832. if((sd->status.inventory[n].equip & EQP_ARMS) &&
  5833. sd->weapontype1 == 0 && sd->weapontype2 == 0 && (!sd->sc.data[SC_SEVENWIND] || sd->sc.data[SC_ASPERSIO])) //Check for seven wind (but not level seven!)
  5834. skill_enchant_elemental_end(&sd->bl,-1);
  5835. if(sd->status.inventory[n].equip & EQP_ARMOR) {
  5836. // On Armor Change...
  5837. if( sd->sc.data[SC_BENEDICTIO] )
  5838. status_change_end(&sd->bl, SC_BENEDICTIO, -1);
  5839. if( sd->sc.data[SC_ARMOR_RESIST] )
  5840. status_change_end(&sd->bl, SC_ARMOR_RESIST, -1);
  5841. }
  5842. sd->status.inventory[n].equip=0;
  5843. if(flag&1) {
  5844. pc_checkallowskill(sd);
  5845. status_calc_pc(sd,0);
  5846. }
  5847. if(sd->sc.data[SC_SIGNUMCRUCIS] && !battle_check_undead(sd->battle_status.race,sd->battle_status.def_ele))
  5848. status_change_end(&sd->bl,SC_SIGNUMCRUCIS,-1);
  5849. //OnUnEquip script [Skotlex]
  5850. if (sd->inventory_data[n]) {
  5851. struct item_data *data;
  5852. if (sd->inventory_data[n]->unequip_script)
  5853. run_script(sd->inventory_data[n]->unequip_script,0,sd->bl.id,fake_nd->bl.id);
  5854. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  5855. ; //No cards
  5856. else
  5857. for(i=0;i<sd->inventory_data[n]->slot; i++)
  5858. {
  5859. if (!sd->status.inventory[n].card[i])
  5860. continue;
  5861. data = itemdb_exists(sd->status.inventory[n].card[i]);
  5862. if (data && data->unequip_script)
  5863. run_script(data->unequip_script,0,sd->bl.id,fake_nd->bl.id);
  5864. }
  5865. }
  5866. return 0;
  5867. }
  5868. /*==========================================
  5869. * アイテムのindex番?を詰めたり
  5870. * ? 備品の?備可能チェックを行なう
  5871. *------------------------------------------*/
  5872. int pc_checkitem(struct map_session_data *sd)
  5873. {
  5874. int i,j,k,id,calc_flag = 0;
  5875. struct item_data *it=NULL;
  5876. nullpo_retr(0, sd);
  5877. if (sd->vender_id) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
  5878. return 0;
  5879. // 所持品空き詰め
  5880. for(i=j=0;i<MAX_INVENTORY;i++){
  5881. if( (id=sd->status.inventory[i].nameid)==0)
  5882. continue;
  5883. if( battle_config.item_check && !itemdb_available(id) ){
  5884. ShowWarning("illegal item id %d in %d[%s] inventory.\n",id,sd->bl.id,sd->status.name);
  5885. pc_delitem(sd,i,sd->status.inventory[i].amount,3);
  5886. continue;
  5887. }
  5888. if(i>j){
  5889. memcpy(&sd->status.inventory[j],&sd->status.inventory[i],sizeof(struct item));
  5890. sd->inventory_data[j] = sd->inventory_data[i];
  5891. }
  5892. j++;
  5893. }
  5894. if(j < MAX_INVENTORY)
  5895. memset(&sd->status.inventory[j],0,sizeof(struct item)*(MAX_INVENTORY-j));
  5896. for(k=j;k<MAX_INVENTORY;k++)
  5897. sd->inventory_data[k] = NULL;
  5898. // カ?ト?空き詰め
  5899. for(i=j=0;i<MAX_CART;i++){
  5900. if( (id=sd->status.cart[i].nameid)==0 )
  5901. continue;
  5902. if( battle_config.item_check && !itemdb_available(id) ){
  5903. ShowWarning("illegal item id %d in %d[%s] cart.\n",id,sd->bl.id,sd->status.name);
  5904. pc_cart_delitem(sd,i,sd->status.cart[i].amount,1);
  5905. continue;
  5906. }
  5907. if(i>j){
  5908. memcpy(&sd->status.cart[j],&sd->status.cart[i],sizeof(struct item));
  5909. }
  5910. j++;
  5911. }
  5912. if(j < MAX_CART)
  5913. memset(&sd->status.cart[j],0,sizeof(struct item)*(MAX_CART-j));
  5914. // ? 備位置チェック
  5915. for(i=0;i<MAX_INVENTORY;i++){
  5916. it=sd->inventory_data[i];
  5917. if(sd->status.inventory[i].nameid==0)
  5918. continue;
  5919. if(!sd->status.inventory[i].equip)
  5920. continue;
  5921. if(sd->status.inventory[i].equip&~pc_equippoint(sd,i)) {
  5922. sd->status.inventory[i].equip=0;
  5923. calc_flag = 1;
  5924. continue;
  5925. }
  5926. if(it) {
  5927. //check for forbiden items.
  5928. int flag =
  5929. (map[sd->bl.m].flag.restricted?map[sd->bl.m].zone:0)
  5930. | (map[sd->bl.m].flag.pvp?1:0)
  5931. | (map_flag_gvg(sd->bl.m)?2:0);
  5932. if (flag && (it->flag.no_equip&flag || !pc_isAllowedCardOn(sd,it->slot,i,flag)))
  5933. {
  5934. sd->status.inventory[i].equip=0;
  5935. calc_flag = 1;
  5936. }
  5937. }
  5938. }
  5939. pc_setequipindex(sd);
  5940. if(calc_flag && sd->state.active)
  5941. {
  5942. status_calc_pc(sd,0);
  5943. pc_equiplookall(sd);
  5944. }
  5945. return 0;
  5946. }
  5947. /*==========================================
  5948. * PVP順位計算用(foreachinarea)
  5949. *------------------------------------------*/
  5950. int pc_calc_pvprank_sub(struct block_list *bl,va_list ap)
  5951. {
  5952. struct map_session_data *sd1,*sd2=NULL;
  5953. sd1=(struct map_session_data *)bl;
  5954. sd2=va_arg(ap,struct map_session_data *);
  5955. if( sd1->pvp_point > sd2->pvp_point )
  5956. sd2->pvp_rank++;
  5957. return 0;
  5958. }
  5959. /*==========================================
  5960. * PVP順位計算
  5961. *------------------------------------------*/
  5962. int pc_calc_pvprank(struct map_session_data *sd)
  5963. {
  5964. int old;
  5965. struct map_data *m;
  5966. m=&map[sd->bl.m];
  5967. old=sd->pvp_rank;
  5968. sd->pvp_rank=1;
  5969. map_foreachinmap(pc_calc_pvprank_sub,sd->bl.m,BL_PC,sd);
  5970. if(old!=sd->pvp_rank || sd->pvp_lastusers!=m->users)
  5971. clif_pvpset(sd,sd->pvp_rank,sd->pvp_lastusers=m->users,0);
  5972. return sd->pvp_rank;
  5973. }
  5974. /*==========================================
  5975. * PVP順位計算(timer)
  5976. *------------------------------------------*/
  5977. int pc_calc_pvprank_timer(int tid, unsigned int tick, int id, intptr data)
  5978. {
  5979. struct map_session_data *sd=NULL;
  5980. sd=map_id2sd(id);
  5981. if(sd==NULL)
  5982. return 0;
  5983. sd->pvp_timer = INVALID_TIMER;
  5984. if( pc_calc_pvprank(sd) > 0 )
  5985. sd->pvp_timer = add_timer(gettick()+PVP_CALCRANK_INTERVAL,pc_calc_pvprank_timer,id,data);
  5986. return 0;
  5987. }
  5988. /*==========================================
  5989. * sdは結婚しているか(?婚の場合は相方のchar_idを返す)
  5990. *------------------------------------------*/
  5991. int pc_ismarried(struct map_session_data *sd)
  5992. {
  5993. if(sd == NULL)
  5994. return -1;
  5995. if(sd->status.partner_id > 0)
  5996. return sd->status.partner_id;
  5997. else
  5998. return 0;
  5999. }
  6000. /*==========================================
  6001. * sdがdstsdと結婚(dstsd→sdの結婚?理も同暫ノ行う)
  6002. *------------------------------------------*/
  6003. int pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd)
  6004. {
  6005. if(sd == NULL || dstsd == NULL ||
  6006. sd->status.partner_id > 0 || dstsd->status.partner_id > 0 ||
  6007. sd->class_&JOBL_BABY)
  6008. return -1;
  6009. sd->status.partner_id = dstsd->status.char_id;
  6010. dstsd->status.partner_id = sd->status.char_id;
  6011. return 0;
  6012. }
  6013. /*==========================================
  6014. * Divorce sd from its partner
  6015. *------------------------------------------*/
  6016. int pc_divorce(struct map_session_data *sd)
  6017. {
  6018. struct map_session_data *p_sd;
  6019. int i;
  6020. if( sd == NULL || !pc_ismarried(sd) )
  6021. return -1;
  6022. if( !sd->status.partner_id )
  6023. return -1; // Char is not married
  6024. if( (p_sd = map_charid2sd(sd->status.partner_id)) == NULL )
  6025. { // Lets char server do the divorce
  6026. #ifndef TXT_ONLY
  6027. if( chrif_divorce(sd->status.char_id, sd->status.partner_id) )
  6028. return -1; // No char server connected
  6029. return 0;
  6030. #else
  6031. ShowError("pc_divorce: p_sd nullpo\n");
  6032. return -1;
  6033. #endif
  6034. }
  6035. // Both players online, lets do the divorce manually
  6036. sd->status.partner_id = 0;
  6037. p_sd->status.partner_id = 0;
  6038. for( i = 0; i < MAX_INVENTORY; i++ )
  6039. {
  6040. if( sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F )
  6041. pc_delitem(sd, i, 1, 0);
  6042. if( p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F )
  6043. pc_delitem(p_sd, i, 1, 0);
  6044. }
  6045. clif_divorced(sd, p_sd->status.name);
  6046. clif_divorced(p_sd, sd->status.name);
  6047. return 0;
  6048. }
  6049. /*==========================================
  6050. * sdの相方のmap_session_dataを返す
  6051. *------------------------------------------*/
  6052. struct map_session_data *pc_get_partner(struct map_session_data *sd)
  6053. {
  6054. if (sd && pc_ismarried(sd))
  6055. // charid2sd returns NULL if not found
  6056. return map_charid2sd(sd->status.partner_id);
  6057. return NULL;
  6058. }
  6059. struct map_session_data *pc_get_father (struct map_session_data *sd)
  6060. {
  6061. if (sd && sd->class_&JOBL_BABY && sd->status.father > 0)
  6062. // charid2sd returns NULL if not found
  6063. return map_charid2sd(sd->status.father);
  6064. return NULL;
  6065. }
  6066. struct map_session_data *pc_get_mother (struct map_session_data *sd)
  6067. {
  6068. if (sd && sd->class_&JOBL_BABY && sd->status.mother > 0)
  6069. // charid2sd returns NULL if not found
  6070. return map_charid2sd(sd->status.mother);
  6071. return NULL;
  6072. }
  6073. struct map_session_data *pc_get_child (struct map_session_data *sd)
  6074. {
  6075. if (sd && pc_ismarried(sd) && sd->status.child > 0)
  6076. // charid2sd returns NULL if not found
  6077. return map_charid2sd(sd->status.child);
  6078. return NULL;
  6079. }
  6080. void pc_bleeding (struct map_session_data *sd, unsigned int diff_tick)
  6081. {
  6082. int hp = 0, sp = 0;
  6083. if (sd->hp_loss.value) {
  6084. sd->hp_loss.tick += diff_tick;
  6085. while (sd->hp_loss.tick >= sd->hp_loss.rate) {
  6086. hp += sd->hp_loss.value;
  6087. sd->hp_loss.tick -= sd->hp_loss.rate;
  6088. }
  6089. if(hp >= sd->battle_status.hp)
  6090. hp = sd->battle_status.hp-1; //Script drains cannot kill you.
  6091. }
  6092. if (sd->sp_loss.value) {
  6093. sd->sp_loss.tick += diff_tick;
  6094. while (sd->sp_loss.tick >= sd->sp_loss.rate) {
  6095. sp += sd->sp_loss.value;
  6096. sd->sp_loss.tick -= sd->sp_loss.rate;
  6097. }
  6098. }
  6099. if (hp > 0 || sp > 0)
  6100. status_zap(&sd->bl, hp, sp);
  6101. return;
  6102. }
  6103. //Character regen. Flag is used to know which types of regen can take place.
  6104. //&1: HP regen
  6105. //&2: SP regen
  6106. void pc_regen (struct map_session_data *sd, unsigned int diff_tick)
  6107. {
  6108. int hp = 0, sp = 0;
  6109. if (sd->hp_regen.value) {
  6110. sd->hp_regen.tick += diff_tick;
  6111. while (sd->hp_regen.tick >= sd->hp_regen.rate) {
  6112. hp += sd->hp_regen.value;
  6113. sd->hp_regen.tick -= sd->hp_regen.rate;
  6114. }
  6115. }
  6116. if (sd->sp_regen.value) {
  6117. sd->sp_regen.tick += diff_tick;
  6118. while (sd->sp_regen.tick >= sd->sp_regen.rate) {
  6119. sp += sd->sp_regen.value;
  6120. sd->sp_regen.tick -= sd->sp_regen.rate;
  6121. }
  6122. }
  6123. if (hp > 0 || sp > 0)
  6124. status_heal(&sd->bl, hp, sp, 0);
  6125. return;
  6126. }
  6127. /*==========================================
  6128. * セ?ブポイントの保存
  6129. *------------------------------------------*/
  6130. int pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y)
  6131. {
  6132. nullpo_retr(0, sd);
  6133. sd->status.save_point.map = mapindex;
  6134. sd->status.save_point.x = x;
  6135. sd->status.save_point.y = y;
  6136. return 0;
  6137. }
  6138. /*==========================================
  6139. * 自動セ?ブ (timer??)
  6140. *------------------------------------------*/
  6141. int pc_autosave(int tid, unsigned int tick, int id, intptr data)
  6142. {
  6143. int interval;
  6144. struct s_mapiterator* iter;
  6145. struct map_session_data* sd;
  6146. static int last_save_id = 0, save_flag = 0;
  6147. if(save_flag == 2) //Someone was saved on last call, normal cycle
  6148. save_flag = 0;
  6149. else
  6150. save_flag = 1; //Noone was saved, so save first found char.
  6151. iter = mapit_getallusers();
  6152. for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
  6153. {
  6154. if(sd->bl.id == last_save_id && save_flag != 1) {
  6155. save_flag = 1;
  6156. continue;
  6157. }
  6158. if(save_flag != 1) //Not our turn to save yet.
  6159. continue;
  6160. //Save char.
  6161. last_save_id = sd->bl.id;
  6162. save_flag = 2;
  6163. chrif_save(sd,0);
  6164. }
  6165. mapit_free(iter);
  6166. interval = autosave_interval/(map_usercount()+1);
  6167. if(interval < minsave_interval)
  6168. interval = minsave_interval;
  6169. add_timer(gettick()+interval,pc_autosave,0,0);
  6170. return 0;
  6171. }
  6172. static int pc_daynight_timer_sub(struct map_session_data *sd,va_list ap)
  6173. {
  6174. if (sd->state.night != night_flag && map[sd->bl.m].flag.nightenabled)
  6175. { //Night/day state does not match.
  6176. clif_status_load(&sd->bl, SI_NIGHT, night_flag); //New night effect by dynamix [Skotlex]
  6177. sd->state.night = night_flag;
  6178. return 1;
  6179. }
  6180. return 0;
  6181. }
  6182. /*================================================
  6183. * timer to do the day [Yor]
  6184. * data: 0 = called by timer, 1 = gmcommand/script
  6185. *------------------------------------------------*/
  6186. int map_day_timer(int tid, unsigned int tick, int id, intptr data)
  6187. {
  6188. char tmp_soutput[1024];
  6189. if (data == 0 && battle_config.day_duration <= 0) // if we want a day
  6190. return 0;
  6191. if (!night_flag)
  6192. return 0; //Already day.
  6193. night_flag = 0; // 0=day, 1=night [Yor]
  6194. map_foreachpc(pc_daynight_timer_sub);
  6195. strcpy(tmp_soutput, (data == 0) ? msg_txt(502) : msg_txt(60)); // The day has arrived!
  6196. intif_GMmessage(tmp_soutput, strlen(tmp_soutput) + 1, 0);
  6197. return 0;
  6198. }
  6199. /*================================================
  6200. * timer to do the night [Yor]
  6201. * data: 0 = called by timer, 1 = gmcommand/script
  6202. *------------------------------------------------*/
  6203. int map_night_timer(int tid, unsigned int tick, int id, intptr data)
  6204. {
  6205. char tmp_soutput[1024];
  6206. if (data == 0 && battle_config.night_duration <= 0) // if we want a night
  6207. return 0;
  6208. if (night_flag)
  6209. return 0; //Already nigth.
  6210. night_flag = 1; // 0=day, 1=night [Yor]
  6211. map_foreachpc(pc_daynight_timer_sub);
  6212. strcpy(tmp_soutput, (data == 0) ? msg_txt(503) : msg_txt(59)); // The night has fallen...
  6213. intif_GMmessage(tmp_soutput, strlen(tmp_soutput) + 1, 0);
  6214. return 0;
  6215. }
  6216. void pc_setstand(struct map_session_data *sd){
  6217. nullpo_retv(sd);
  6218. if(sd->sc.data[SC_TENSIONRELAX])
  6219. status_change_end(&sd->bl,SC_TENSIONRELAX,-1);
  6220. //Reset sitting tick.
  6221. sd->ssregen.tick.hp = sd->ssregen.tick.sp = 0;
  6222. sd->state.dead_sit = sd->vd.dead_sit = 0;
  6223. }
  6224. /*==========================================
  6225. * Duel organizing functions [LuzZza]
  6226. *------------------------------------------*/
  6227. void duel_savetime(struct map_session_data* sd)
  6228. {
  6229. time_t timer;
  6230. struct tm *t;
  6231. time(&timer);
  6232. t = localtime(&timer);
  6233. pc_setglobalreg(sd, "PC_LAST_DUEL_TIME", t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min);
  6234. return;
  6235. }
  6236. int duel_checktime(struct map_session_data* sd)
  6237. {
  6238. int diff;
  6239. time_t timer;
  6240. struct tm *t;
  6241. time(&timer);
  6242. t = localtime(&timer);
  6243. diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, "PC_LAST_DUEL_TIME");
  6244. return !(diff >= 0 && diff < battle_config.duel_time_interval);
  6245. }
  6246. static int duel_showinfo_sub(struct map_session_data* sd, va_list va)
  6247. {
  6248. struct map_session_data *ssd = va_arg(va, struct map_session_data*);
  6249. int *p = va_arg(va, int*);
  6250. char output[256];
  6251. if (sd->duel_group != ssd->duel_group) return 0;
  6252. sprintf(output, " %d. %s", ++(*p), sd->status.name);
  6253. clif_disp_onlyself(ssd, output, strlen(output));
  6254. return 1;
  6255. }
  6256. int duel_showinfo(const unsigned int did, struct map_session_data* sd)
  6257. {
  6258. int p=0;
  6259. char output[256];
  6260. if(duel_list[did].max_players_limit > 0)
  6261. sprintf(output, msg_txt(370), //" -- Duels: %d/%d, Members: %d/%d, Max players: %d --"
  6262. did, duel_count,
  6263. duel_list[did].members_count,
  6264. duel_list[did].members_count + duel_list[did].invites_count,
  6265. duel_list[did].max_players_limit);
  6266. else
  6267. sprintf(output, msg_txt(371), //" -- Duels: %d/%d, Members: %d/%d --"
  6268. did, duel_count,
  6269. duel_list[did].members_count,
  6270. duel_list[did].members_count + duel_list[did].invites_count);
  6271. clif_disp_onlyself(sd, output, strlen(output));
  6272. map_foreachpc(duel_showinfo_sub, sd, &p);
  6273. return 0;
  6274. }
  6275. int duel_create(struct map_session_data* sd, const unsigned int maxpl)
  6276. {
  6277. int i=1;
  6278. char output[256];
  6279. while(duel_list[i].members_count > 0 && i < MAX_DUEL) i++;
  6280. if(i == MAX_DUEL) return 0;
  6281. duel_count++;
  6282. sd->duel_group = i;
  6283. duel_list[i].members_count++;
  6284. duel_list[i].invites_count = 0;
  6285. duel_list[i].max_players_limit = maxpl;
  6286. strcpy(output, msg_txt(372)); // " -- Duel has been created (@invite/@leave) --"
  6287. clif_disp_onlyself(sd, output, strlen(output));
  6288. clif_set0199(sd, 1);
  6289. //clif_misceffect2(&sd->bl, 159);
  6290. return i;
  6291. }
  6292. int duel_invite(const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd)
  6293. {
  6294. char output[256];
  6295. // " -- Player %s invites %s to duel --"
  6296. sprintf(output, msg_txt(373), sd->status.name, target_sd->status.name);
  6297. clif_disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
  6298. target_sd->duel_invite = did;
  6299. duel_list[did].invites_count++;
  6300. // "Blue -- Player %s invites you to PVP duel (@accept/@reject) --"
  6301. sprintf(output, msg_txt(374), sd->status.name);
  6302. clif_GMmessage((struct block_list *)target_sd, output, strlen(output)+1, 3);
  6303. return 0;
  6304. }
  6305. static int duel_leave_sub(struct map_session_data* sd, va_list va)
  6306. {
  6307. int did = va_arg(va, int);
  6308. if (sd->duel_invite == did)
  6309. sd->duel_invite = 0;
  6310. return 0;
  6311. }
  6312. int duel_leave(const unsigned int did, struct map_session_data* sd)
  6313. {
  6314. char output[256];
  6315. // " <- Player %s has left duel --"
  6316. sprintf(output, msg_txt(375), sd->status.name);
  6317. clif_disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
  6318. duel_list[did].members_count--;
  6319. if(duel_list[did].members_count == 0) {
  6320. map_foreachpc(duel_leave_sub, did);
  6321. duel_count--;
  6322. }
  6323. sd->duel_group = 0;
  6324. duel_savetime(sd);
  6325. clif_set0199(sd, 0);
  6326. return 0;
  6327. }
  6328. int duel_accept(const unsigned int did, struct map_session_data* sd)
  6329. {
  6330. char output[256];
  6331. duel_list[did].members_count++;
  6332. sd->duel_group = sd->duel_invite;
  6333. duel_list[did].invites_count--;
  6334. sd->duel_invite = 0;
  6335. // " -> Player %s has accepted duel --"
  6336. sprintf(output, msg_txt(376), sd->status.name);
  6337. clif_disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
  6338. clif_set0199(sd, 1);
  6339. //clif_misceffect2(&sd->bl, 159);
  6340. return 0;
  6341. }
  6342. int duel_reject(const unsigned int did, struct map_session_data* sd)
  6343. {
  6344. char output[256];
  6345. // " -- Player %s has rejected duel --"
  6346. sprintf(output, msg_txt(377), sd->status.name);
  6347. clif_disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
  6348. duel_list[did].invites_count--;
  6349. sd->duel_invite = 0;
  6350. return 0;
  6351. }
  6352. int pc_split_str(char *str,char **val,int num)
  6353. {
  6354. int i;
  6355. for (i=0; i<num && str; i++){
  6356. val[i] = str;
  6357. str = strchr(str,',');
  6358. if (str && i<num-1) //Do not remove a trailing comma.
  6359. *str++=0;
  6360. }
  6361. return i;
  6362. }
  6363. int pc_split_atoi(char* str, int* val, char sep, int max)
  6364. {
  6365. int i,j;
  6366. for (i=0; i<max; i++) {
  6367. if (!str) break;
  6368. val[i] = atoi(str);
  6369. str = strchr(str,sep);
  6370. if (str)
  6371. *str++=0;
  6372. }
  6373. //Zero up the remaining.
  6374. for(j=i; j < max; j++)
  6375. val[j] = 0;
  6376. return i;
  6377. }
  6378. int pc_split_atoui(char* str, unsigned int* val, char sep, int max)
  6379. {
  6380. static int warning=0;
  6381. int i,j;
  6382. double f;
  6383. for (i=0; i<max; i++) {
  6384. if (!str) break;
  6385. f = atof(str);
  6386. if (f < 0)
  6387. val[i] = 0;
  6388. else if (f > UINT_MAX) {
  6389. val[i] = UINT_MAX;
  6390. if (!warning) {
  6391. warning = 1;
  6392. ShowWarning("pc_readdb (exp.txt): Required exp per level is capped to %u\n", UINT_MAX);
  6393. }
  6394. } else
  6395. val[i] = (unsigned int)f;
  6396. str = strchr(str,sep);
  6397. if (str)
  6398. *str++=0;
  6399. }
  6400. //Zero up the remaining.
  6401. for(j=i; j < max; j++)
  6402. val[j] = 0;
  6403. return i;
  6404. }
  6405. /*==========================================
  6406. * DB reading.
  6407. * exp.txt - required experience values
  6408. * job_db1.txt - weight, hp, sp, aspd
  6409. * job_db2.txt - job level stat bonuses
  6410. * skill_tree.txt - skill tree for every class
  6411. * attr_fix.txt - elemental adjustment table
  6412. * size_fix.txt - size adjustment table for weapons
  6413. * refine_db.txt - refining data table
  6414. *------------------------------------------*/
  6415. int pc_readdb(void)
  6416. {
  6417. int i,j,k;
  6418. FILE *fp;
  6419. char line[24000],*p;
  6420. // 必要??値?み?み
  6421. memset(exp_table,0,sizeof(exp_table));
  6422. memset(max_level,0,sizeof(max_level));
  6423. sprintf(line, "%s/exp.txt", db_path);
  6424. fp=fopen(line, "r");
  6425. if(fp==NULL){
  6426. ShowError("can't read %s\n", line);
  6427. return 1;
  6428. }
  6429. while(fgets(line, sizeof(line), fp))
  6430. {
  6431. int jobs[CLASS_COUNT], job_count, job, job_id;
  6432. int type;
  6433. unsigned int ui,maxlv;
  6434. char *split[4];
  6435. if(line[0]=='/' && line[1]=='/')
  6436. continue;
  6437. if (pc_split_str(line,split,4) < 4)
  6438. continue;
  6439. job_count = pc_split_atoi(split[1],jobs,':',CLASS_COUNT);
  6440. if (job_count < 1)
  6441. continue;
  6442. job_id = jobs[0];
  6443. if (!pcdb_checkid(job_id)) {
  6444. ShowError("pc_readdb: Invalid job ID %d.\n", job_id);
  6445. continue;
  6446. }
  6447. type = atoi(split[2]);
  6448. if (type < 0 || type > 1) {
  6449. ShowError("pc_readdb: Invalid type %d (must be 0 for base levels, 1 for job levels).\n", type);
  6450. continue;
  6451. }
  6452. maxlv = atoi(split[0]);
  6453. if (maxlv > MAX_LEVEL) {
  6454. ShowWarning("pc_readdb: Specified max level %u for job %d is beyond server's limit (%u).\n ", maxlv, job_id, MAX_LEVEL);
  6455. maxlv = MAX_LEVEL;
  6456. }
  6457. job = jobs[0] = pc_class2idx(job_id);
  6458. //We send one less and then one more because the last entry in the exp array should hold 0.
  6459. max_level[job][type] = pc_split_atoui(split[3], exp_table[job][type],',',maxlv-1)+1;
  6460. //Reverse check in case the array has a bunch of trailing zeros... [Skotlex]
  6461. //The reasoning behind the -2 is this... if the max level is 5, then the array
  6462. //should look like this:
  6463. //0: x, 1: x, 2: x: 3: x 4: 0 <- last valid value is at 3.
  6464. while ((ui = max_level[job][type]) >= 2 && exp_table[job][type][ui-2] <= 0)
  6465. max_level[job][type]--;
  6466. if (max_level[job][type] < maxlv) {
  6467. ShowWarning("pc_readdb: Specified max %u for job %d, but that job's exp table only goes up to level %u.\n", maxlv, job_id, max_level[job][type]);
  6468. ShowInfo("Filling the missing values with the last exp entry.\n");
  6469. //Fill the requested values with the last entry.
  6470. ui = (max_level[job][type] <= 2? 0: max_level[job][type]-2);
  6471. for (; ui+2 < maxlv; ui++)
  6472. exp_table[job][type][ui] = exp_table[job][type][ui-1];
  6473. max_level[job][type] = maxlv;
  6474. }
  6475. // ShowDebug("%s - Class %d: %d\n", type?"Job":"Base", job_id, max_level[job][type]);
  6476. for (i = 1; i < job_count; i++) {
  6477. job_id = jobs[i];
  6478. if (!pcdb_checkid(job_id)) {
  6479. ShowError("pc_readdb: Invalid job ID %d.\n", job_id);
  6480. continue;
  6481. }
  6482. job = pc_class2idx(job_id);
  6483. memcpy(exp_table[job][type], exp_table[jobs[0]][type], sizeof(exp_table[0][0]));
  6484. max_level[job][type] = maxlv;
  6485. // ShowDebug("%s - Class %d: %u\n", type?"Job":"Base", job_id, max_level[job][type]);
  6486. }
  6487. }
  6488. fclose(fp);
  6489. for (i = 0; i < JOB_MAX; i++) {
  6490. if (!pcdb_checkid(i)) continue;
  6491. if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER)
  6492. continue; //Classes that do not need exp tables.
  6493. j = pc_class2idx(i);
  6494. if (!max_level[j][0])
  6495. ShowWarning("Class %s (%d) does not has a base exp table.\n", job_name(i), i);
  6496. if (!max_level[j][1])
  6497. ShowWarning("Class %s (%d) does not has a job exp table.\n", job_name(i), i);
  6498. }
  6499. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","exp.txt");
  6500. // スキルツリ?
  6501. memset(skill_tree,0,sizeof(skill_tree));
  6502. sprintf(line, "%s/skill_tree.txt", db_path);
  6503. fp=fopen(line,"r");
  6504. if(fp==NULL){
  6505. ShowError("can't read %s\n", line);
  6506. return 1;
  6507. }
  6508. while(fgets(line, sizeof(line), fp))
  6509. {
  6510. char *split[50];
  6511. int f=0, m=3, idx;
  6512. if(line[0]=='/' && line[1]=='/')
  6513. continue;
  6514. for(j=0,p=line;j<14 && p;j++){
  6515. split[j]=p;
  6516. p=strchr(p,',');
  6517. if(p) *p++=0;
  6518. }
  6519. if(j<13)
  6520. continue;
  6521. if (j == 14) {
  6522. f=1; // MinJobLvl has been added
  6523. m++;
  6524. }
  6525. // check for bounds [celest]
  6526. idx = atoi(split[0]);
  6527. if(!pcdb_checkid(idx))
  6528. continue;
  6529. idx = pc_class2idx(idx);
  6530. k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex]
  6531. ARR_FIND( 0, MAX_SKILL_TREE, j, skill_tree[idx][j].id == 0 || skill_tree[idx][j].id == k );
  6532. if( j == MAX_SKILL_TREE )
  6533. {
  6534. ShowWarning("Unable to load skill %d into job %d's tree. Maximum number of skills per class has been reached.\n", k, atoi(split[0]));
  6535. continue;
  6536. }
  6537. skill_tree[idx][j].id=k;
  6538. skill_tree[idx][j].max=atoi(split[2]);
  6539. if (f) skill_tree[idx][j].joblv=atoi(split[3]);
  6540. for(k=0;k<5;k++){
  6541. skill_tree[idx][j].need[k].id=atoi(split[k*2+m]);
  6542. skill_tree[idx][j].need[k].lv=atoi(split[k*2+m+1]);
  6543. }
  6544. }
  6545. fclose(fp);
  6546. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","skill_tree.txt");
  6547. // ?性修正テ?ブル
  6548. for(i=0;i<4;i++)
  6549. for(j=0;j<ELE_MAX;j++)
  6550. for(k=0;k<ELE_MAX;k++)
  6551. attr_fix_table[i][j][k]=100;
  6552. sprintf(line, "%s/attr_fix.txt", db_path);
  6553. fp=fopen(line,"r");
  6554. if(fp==NULL){
  6555. ShowError("can't read %s\n", line);
  6556. return 1;
  6557. }
  6558. while(fgets(line, sizeof(line), fp))
  6559. {
  6560. char *split[10];
  6561. int lv,n;
  6562. if(line[0]=='/' && line[1]=='/')
  6563. continue;
  6564. for(j=0,p=line;j<3 && p;j++){
  6565. split[j]=p;
  6566. p=strchr(p,',');
  6567. if(p) *p++=0;
  6568. }
  6569. lv=atoi(split[0]);
  6570. n=atoi(split[1]);
  6571. for(i=0;i<n && i<ELE_MAX;){
  6572. if( !fgets(line, sizeof(line), fp) )
  6573. break;
  6574. if(line[0]=='/' && line[1]=='/')
  6575. continue;
  6576. for(j=0,p=line;j<n && j<ELE_MAX && p;j++){
  6577. while(*p==32 && *p>0)
  6578. p++;
  6579. attr_fix_table[lv-1][i][j]=atoi(p);
  6580. if(battle_config.attr_recover == 0 && attr_fix_table[lv-1][i][j] < 0)
  6581. attr_fix_table[lv-1][i][j] = 0;
  6582. p=strchr(p,',');
  6583. if(p) *p++=0;
  6584. }
  6585. i++;
  6586. }
  6587. }
  6588. fclose(fp);
  6589. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","attr_fix.txt");
  6590. // スキルツリ?
  6591. memset(statp,0,sizeof(statp));
  6592. i=1;
  6593. j=45; // base points
  6594. sprintf(line, "%s/statpoint.txt", db_path);
  6595. fp=fopen(line,"r");
  6596. if(fp == NULL){
  6597. ShowStatus("Can't read '"CL_WHITE"%s"CL_RESET"'... Generating DB.\n",line);
  6598. //return 1;
  6599. } else {
  6600. while(fgets(line, sizeof(line), fp))
  6601. {
  6602. if(line[0]=='/' && line[1]=='/')
  6603. continue;
  6604. if ((j=atoi(line))<0)
  6605. j=0;
  6606. if (i > MAX_LEVEL)
  6607. break;
  6608. statp[i]=j;
  6609. i++;
  6610. }
  6611. fclose(fp);
  6612. ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","statpoint.txt");
  6613. }
  6614. // generate the remaining parts of the db if necessary
  6615. for (; i <= MAX_LEVEL; i++) {
  6616. j += (i+15)/5;
  6617. statp[i] = j;
  6618. }
  6619. return 0;
  6620. }
  6621. // Read MOTD on startup. [Valaris]
  6622. int pc_read_motd(void)
  6623. {
  6624. FILE *fp;
  6625. int ln=0,i=0;
  6626. memset(motd_text,0,sizeof(motd_text));
  6627. if ((fp = fopen(motd_txt, "r")) != NULL) {
  6628. while ((ln < MOTD_LINE_SIZE) && fgets(motd_text[ln], sizeof(motd_text[ln])-1, fp) != NULL) {
  6629. if(motd_text[ln][0] == '/' && motd_text[ln][1] == '/')
  6630. continue;
  6631. for(i=0; motd_text[ln][i]; i++) {
  6632. if (motd_text[ln][i] == '\r' || motd_text[ln][i]== '\n') {
  6633. if(i)
  6634. motd_text[ln][i]=0;
  6635. else
  6636. motd_text[ln][0]=' ';
  6637. ln++;
  6638. break;
  6639. }
  6640. }
  6641. }
  6642. fclose(fp);
  6643. }
  6644. else
  6645. ShowWarning("In function pc_read_motd() -> File '"CL_WHITE"%s"CL_RESET"' not found.\n", motd_txt);
  6646. return 0;
  6647. }
  6648. /*==========================================
  6649. * pc? 係初期化
  6650. *------------------------------------------*/
  6651. void do_final_pc(void)
  6652. {
  6653. return;
  6654. }
  6655. int do_init_pc(void)
  6656. {
  6657. pc_readdb();
  6658. pc_read_motd(); // Read MOTD [Valaris]
  6659. memset(&duel_list[0], 0, sizeof(duel_list));
  6660. add_timer_func_list(pc_invincible_timer, "pc_invincible_timer");
  6661. add_timer_func_list(pc_eventtimer, "pc_eventtimer");
  6662. add_timer_func_list(pc_calc_pvprank_timer, "pc_calc_pvprank_timer");
  6663. add_timer_func_list(pc_autosave, "pc_autosave");
  6664. add_timer_func_list(pc_spiritball_timer, "pc_spiritball_timer");
  6665. add_timer_func_list(pc_follow_timer, "pc_follow_timer");
  6666. add_timer(gettick() + autosave_interval, pc_autosave, 0, 0);
  6667. if (battle_config.day_duration > 0 && battle_config.night_duration > 0) {
  6668. int day_duration = battle_config.day_duration;
  6669. int night_duration = battle_config.night_duration;
  6670. // add night/day timer (by [yor])
  6671. add_timer_func_list(map_day_timer, "map_day_timer"); // by [yor]
  6672. add_timer_func_list(map_night_timer, "map_night_timer"); // by [yor]
  6673. if (!battle_config.night_at_start) {
  6674. night_flag = 0; // 0=day, 1=night [Yor]
  6675. day_timer_tid = add_timer_interval(gettick() + day_duration + night_duration, map_day_timer, 0, 0, day_duration + night_duration);
  6676. night_timer_tid = add_timer_interval(gettick() + day_duration, map_night_timer, 0, 0, day_duration + night_duration);
  6677. } else {
  6678. night_flag = 1; // 0=day, 1=night [Yor]
  6679. day_timer_tid = add_timer_interval(gettick() + night_duration, map_day_timer, 0, 0, day_duration + night_duration);
  6680. night_timer_tid = add_timer_interval(gettick() + day_duration + night_duration, map_night_timer, 0, 0, day_duration + night_duration);
  6681. }
  6682. }
  6683. return 0;
  6684. }