pc.c 231 KB

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