pc.c 215 KB

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