pc.c 321 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675
  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/random.h"
  8. #include "../common/showmsg.h"
  9. #include "../common/socket.h" // session[]
  10. #include "../common/strlib.h" // safestrncpy()
  11. #include "../common/timer.h"
  12. #include "../common/utils.h"
  13. #include "../common/mmo.h" //NAME_LENGTH
  14. #include "atcommand.h" // get_atcommand_level()
  15. #include "map.h"
  16. #include "battle.h" // battle_config
  17. #include "battleground.h"
  18. #include "channel.h"
  19. #include "chat.h"
  20. #include "chrif.h"
  21. #include "clif.h"
  22. #include "date.h" // is_day_of_*()
  23. #include "duel.h"
  24. #include "intif.h"
  25. #include "itemdb.h"
  26. #include "log.h"
  27. #include "mail.h"
  28. #include "path.h"
  29. #include "homunculus.h"
  30. #include "instance.h"
  31. #include "mercenary.h"
  32. #include "elemental.h"
  33. #include "npc.h" // fake_nd
  34. #include "pet.h" // pet_unlocktarget()
  35. #include "party.h" // party_search()
  36. #include "guild.h" // guild_search(), guild_request_info()
  37. #include "script.h" // script_config
  38. #include "skill.h"
  39. #include "status.h" // struct status_data
  40. #include "storage.h"
  41. #include "pc.h"
  42. #include "pc_groups.h"
  43. #include "quest.h"
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <time.h>
  48. #include <math.h>
  49. int pc_split_atoui(char* str, unsigned int* val, char sep, int max);
  50. #define PVP_CALCRANK_INTERVAL 1000 // PVP calculation interval
  51. static unsigned int statp[MAX_LEVEL+1];
  52. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  53. static unsigned int level_penalty[3][CLASS_MAX][MAX_LEVEL*2+1];
  54. #endif
  55. // h-files are for declarations, not for implementations... [Shinomori]
  56. struct skill_tree_entry skill_tree[CLASS_COUNT][MAX_SKILL_TREE];
  57. // timer for night.day implementation
  58. int day_timer_tid;
  59. int night_timer_tid;
  60. struct fame_list smith_fame_list[MAX_FAME_LIST];
  61. struct fame_list chemist_fame_list[MAX_FAME_LIST];
  62. struct fame_list taekwon_fame_list[MAX_FAME_LIST];
  63. static unsigned int 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_COSTUME_HEAD_TOP,EQP_COSTUME_HEAD_MID,EQP_COSTUME_HEAD_LOW,EQP_COSTUME_GARMENT,EQP_AMMO,EQP_SHADOW_ARMOR,EQP_SHADOW_WEAPON,EQP_SHADOW_SHIELD,EQP_SHADOW_SHOES,EQP_SHADOW_ACC_R,EQP_SHADOW_ACC_L};
  64. #define MOTD_LINE_SIZE 128
  65. static char motd_text[MOTD_LINE_SIZE][CHAT_SIZE_MAX]; // Message of the day buffer [Valaris]
  66. //Links related info to the sd->hate_mob[]/sd->feel_map[] entries
  67. const struct sg_data sg_info[MAX_PC_FEELHATE] = {
  68. { SG_SUN_ANGER, SG_SUN_BLESS, SG_SUN_COMFORT, "PC_FEEL_SUN", "PC_HATE_MOB_SUN", is_day_of_sun },
  69. { SG_MOON_ANGER, SG_MOON_BLESS, SG_MOON_COMFORT, "PC_FEEL_MOON", "PC_HATE_MOB_MOON", is_day_of_moon },
  70. { SG_STAR_ANGER, SG_STAR_BLESS, SG_STAR_COMFORT, "PC_FEEL_STAR", "PC_HATE_MOB_STAR", is_day_of_star }
  71. };
  72. /**
  73. * Item Cool Down Delay Saving
  74. * Struct item_cd is not a member of struct map_session_data
  75. * to keep cooldowns in memory between player log-ins.
  76. * All cooldowns are reset when server is restarted.
  77. **/
  78. DBMap* itemcd_db = NULL; // char_id -> struct skill_cd
  79. struct item_cd {
  80. unsigned int tick[MAX_ITEMDELAYS];//tick
  81. short nameid[MAX_ITEMDELAYS];//skill id
  82. };
  83. //Converts a class to its array index for CLASS_COUNT defined arrays.
  84. //Note that it does not do a validity check for speed purposes, where parsing
  85. //player input make sure to use a pcdb_checkid first!
  86. int pc_class2idx(int class_) {
  87. if (class_ >= JOB_NOVICE_HIGH)
  88. return class_- JOB_NOVICE_HIGH+JOB_MAX_BASIC;
  89. return class_;
  90. }
  91. inline int pc_get_group_id(struct map_session_data *sd) {
  92. return sd->group_id;
  93. }
  94. inline int pc_get_group_level(struct map_session_data *sd) {
  95. return sd->group_level;
  96. }
  97. static int pc_invincible_timer(int tid, unsigned int tick, int id, intptr_t data)
  98. {
  99. struct map_session_data *sd;
  100. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  101. return 1;
  102. if(sd->invincible_timer != tid){
  103. ShowError("invincible_timer %d != %d\n",sd->invincible_timer,tid);
  104. return 0;
  105. }
  106. sd->invincible_timer = INVALID_TIMER;
  107. skill_unit_move(&sd->bl,tick,1);
  108. return 0;
  109. }
  110. void pc_setinvincibletimer(struct map_session_data* sd, int val) {
  111. nullpo_retv(sd);
  112. if( sd->invincible_timer != INVALID_TIMER )
  113. delete_timer(sd->invincible_timer,pc_invincible_timer);
  114. sd->invincible_timer = add_timer(gettick()+val,pc_invincible_timer,sd->bl.id,0);
  115. }
  116. void pc_delinvincibletimer(struct map_session_data* sd)
  117. {
  118. nullpo_retv(sd);
  119. if( sd->invincible_timer != INVALID_TIMER )
  120. {
  121. delete_timer(sd->invincible_timer,pc_invincible_timer);
  122. sd->invincible_timer = INVALID_TIMER;
  123. skill_unit_move(&sd->bl,gettick(),1);
  124. }
  125. }
  126. static int pc_spiritball_timer(int tid, unsigned int tick, int id, intptr_t data)
  127. {
  128. struct map_session_data *sd;
  129. int i;
  130. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  131. return 1;
  132. if( sd->spiritball <= 0 )
  133. {
  134. 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);
  135. sd->spiritball = 0;
  136. return 0;
  137. }
  138. ARR_FIND(0, sd->spiritball, i, sd->spirit_timer[i] == tid);
  139. if( i == sd->spiritball )
  140. {
  141. ShowError("pc_spiritball_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
  142. return 0;
  143. }
  144. sd->spiritball--;
  145. if( i != sd->spiritball )
  146. memmove(sd->spirit_timer+i, sd->spirit_timer+i+1, (sd->spiritball-i)*sizeof(int));
  147. sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
  148. clif_spiritball(&sd->bl);
  149. return 0;
  150. }
  151. int pc_addspiritball(struct map_session_data *sd,int interval,int max)
  152. {
  153. int tid, i;
  154. nullpo_ret(sd);
  155. if(max > MAX_SKILL_LEVEL)
  156. max = MAX_SKILL_LEVEL;
  157. if(sd->spiritball < 0)
  158. sd->spiritball = 0;
  159. if( sd->spiritball && sd->spiritball >= max )
  160. {
  161. if(sd->spirit_timer[0] != INVALID_TIMER)
  162. delete_timer(sd->spirit_timer[0],pc_spiritball_timer);
  163. sd->spiritball--;
  164. if( sd->spiritball != 0 )
  165. memmove(sd->spirit_timer+0, sd->spirit_timer+1, (sd->spiritball)*sizeof(int));
  166. sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
  167. }
  168. tid = add_timer(gettick()+interval, pc_spiritball_timer, sd->bl.id, 0);
  169. 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);
  170. if( i != sd->spiritball )
  171. memmove(sd->spirit_timer+i+1, sd->spirit_timer+i, (sd->spiritball-i)*sizeof(int));
  172. sd->spirit_timer[i] = tid;
  173. sd->spiritball++;
  174. if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
  175. clif_millenniumshield(sd,sd->spiritball);
  176. else
  177. clif_spiritball(&sd->bl);
  178. return 0;
  179. }
  180. int pc_delspiritball(struct map_session_data *sd,int count,int type)
  181. {
  182. int i;
  183. nullpo_ret(sd);
  184. if(sd->spiritball <= 0) {
  185. sd->spiritball = 0;
  186. return 0;
  187. }
  188. if(count <= 0)
  189. return 0;
  190. if(count > sd->spiritball)
  191. count = sd->spiritball;
  192. sd->spiritball -= count;
  193. if(count > MAX_SKILL_LEVEL)
  194. count = MAX_SKILL_LEVEL;
  195. for(i=0;i<count;i++) {
  196. if(sd->spirit_timer[i] != INVALID_TIMER) {
  197. delete_timer(sd->spirit_timer[i],pc_spiritball_timer);
  198. sd->spirit_timer[i] = INVALID_TIMER;
  199. }
  200. }
  201. for(i=count;i<MAX_SKILL_LEVEL;i++) {
  202. sd->spirit_timer[i-count] = sd->spirit_timer[i];
  203. sd->spirit_timer[i] = INVALID_TIMER;
  204. }
  205. if(!type) {
  206. if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
  207. clif_millenniumshield(sd,sd->spiritball);
  208. else
  209. clif_spiritball(&sd->bl);
  210. }
  211. return 0;
  212. }
  213. static int pc_check_banding( struct block_list *bl, va_list ap ) {
  214. int *c, *b_sd;
  215. struct block_list *src;
  216. struct map_session_data *tsd;
  217. struct status_change *sc;
  218. nullpo_ret(bl);
  219. nullpo_ret(tsd = (struct map_session_data*)bl);
  220. nullpo_ret(src = va_arg(ap,struct block_list *));
  221. c = va_arg(ap,int *);
  222. b_sd = va_arg(ap, int *);
  223. if(pc_isdead(tsd))
  224. return 0;
  225. sc = status_get_sc(bl);
  226. if( bl == src )
  227. return 0;
  228. if( sc && sc->data[SC_BANDING] )
  229. {
  230. b_sd[(*c)++] = tsd->bl.id;
  231. return 1;
  232. }
  233. return 0;
  234. }
  235. int pc_banding(struct map_session_data *sd, uint16 skill_lv) {
  236. int c;
  237. int b_sd[MAX_PARTY]; // In case of a full Royal Guard party.
  238. int i, j, hp, extra_hp = 0, tmp_qty = 0;
  239. int range = skill_get_splash(LG_BANDING,skill_lv);
  240. nullpo_ret(sd);
  241. c = 0;
  242. memset(b_sd, 0, sizeof(b_sd));
  243. i = party_foreachsamemap(pc_check_banding,sd,range,&sd->bl,&c,&b_sd);
  244. if( c < 1 ) //just recalc status no need to recalc hp
  245. { // No more Royal Guards in Banding found.
  246. struct status_change *sc;
  247. if( (sc = status_get_sc(&sd->bl)) != NULL && sc->data[SC_BANDING] )
  248. {
  249. sc->data[SC_BANDING]->val2 = 0; // Reset the counter
  250. status_calc_bl(&sd->bl, status_sc2scb_flag(SC_BANDING));
  251. }
  252. return 0;
  253. }
  254. //Add yourself
  255. hp = status_get_hp(&sd->bl);
  256. i++;
  257. // Get total HP of all Royal Guards in party.
  258. for( j = 0; j < i; j++ ){
  259. struct map_session_data *bsd = map_id2sd(b_sd[j]);
  260. if( bsd != NULL )
  261. hp += status_get_hp(&bsd->bl);
  262. }
  263. // Set average HP.
  264. hp = hp / i;
  265. // If a Royal Guard have full HP, give more HP to others that haven't full HP.
  266. for( j = 0; j < i; j++ )
  267. {
  268. int tmp_hp=0;
  269. struct map_session_data *bsd = map_id2sd(b_sd[j]);
  270. if( bsd != NULL && (tmp_hp = hp - status_get_max_hp(&bsd->bl)) > 0 ){
  271. extra_hp += tmp_hp;
  272. tmp_qty++;
  273. }
  274. }
  275. if( extra_hp > 0 && tmp_qty > 0 )
  276. hp += extra_hp / tmp_qty;
  277. for( j = 0; j < i; j++ ){
  278. struct map_session_data *bsd = map_id2sd(b_sd[j]);
  279. if( bsd != NULL )
  280. {
  281. struct status_change *sc;
  282. status_set_hp(&bsd->bl,hp,0); // Set hp
  283. if( (sc = status_get_sc(&bsd->bl)) != NULL && sc->data[SC_BANDING] )
  284. {
  285. sc->data[SC_BANDING]->val2 = c; // Set the counter. It doesn't count your self.
  286. status_calc_bl(&bsd->bl, status_sc2scb_flag(SC_BANDING)); // Set atk and def.
  287. }
  288. }
  289. }
  290. return c;
  291. }
  292. // Increases a player's fame points and displays a notice to him
  293. void pc_addfame(struct map_session_data *sd,int count)
  294. {
  295. int ranktype=-1;
  296. nullpo_retv(sd);
  297. sd->status.fame += count;
  298. if(sd->status.fame > MAX_FAME)
  299. sd->status.fame = MAX_FAME;
  300. switch(sd->class_&MAPID_UPPERMASK){
  301. case MAPID_BLACKSMITH: ranktype=0; break;
  302. case MAPID_ALCHEMIST: ranktype=1; break;
  303. case MAPID_TAEKWON: ranktype=2; break;
  304. }
  305. clif_update_rankingpoint(sd,ranktype,count);
  306. chrif_updatefamelist(sd);
  307. }
  308. // Check whether a player ID is in the fame rankers' list of its job, returns his/her position if so, 0 else
  309. unsigned char pc_famerank(int char_id, int job)
  310. {
  311. int i;
  312. switch(job){
  313. case MAPID_BLACKSMITH: // Blacksmith
  314. for(i = 0; i < MAX_FAME_LIST; i++){
  315. if(smith_fame_list[i].id == char_id)
  316. return i + 1;
  317. }
  318. break;
  319. case MAPID_ALCHEMIST: // Alchemist
  320. for(i = 0; i < MAX_FAME_LIST; i++){
  321. if(chemist_fame_list[i].id == char_id)
  322. return i + 1;
  323. }
  324. break;
  325. case MAPID_TAEKWON: // Taekwon
  326. for(i = 0; i < MAX_FAME_LIST; i++){
  327. if(taekwon_fame_list[i].id == char_id)
  328. return i + 1;
  329. }
  330. break;
  331. }
  332. return 0;
  333. }
  334. int pc_setrestartvalue(struct map_session_data *sd,int type) {
  335. struct status_data *status, *b_status;
  336. nullpo_ret(sd);
  337. b_status = &sd->base_status;
  338. status = &sd->battle_status;
  339. if (type&1) { //Normal resurrection
  340. status->hp = 1; //Otherwise status_heal may fail if dead.
  341. status_heal(&sd->bl, b_status->hp, 0, 1);
  342. if( status->sp < b_status->sp )
  343. status_set_sp(&sd->bl, b_status->sp, 1);
  344. } else { //Just for saving on the char-server (with values as if respawned)
  345. sd->status.hp = b_status->hp;
  346. sd->status.sp = (status->sp < b_status->sp)?b_status->sp:status->sp;
  347. }
  348. return 0;
  349. }
  350. /*==========================================
  351. Rental System
  352. *------------------------------------------*/
  353. static int pc_inventory_rental_end(int tid, unsigned int tick, int id, intptr_t data)
  354. {
  355. struct map_session_data *sd = map_id2sd(id);
  356. if( sd == NULL )
  357. return 0;
  358. if( tid != sd->rental_timer )
  359. {
  360. ShowError("pc_inventory_rental_end: invalid timer id.\n");
  361. return 0;
  362. }
  363. pc_inventory_rentals(sd);
  364. return 1;
  365. }
  366. int pc_inventory_rental_clear(struct map_session_data *sd)
  367. {
  368. if( sd->rental_timer != INVALID_TIMER )
  369. {
  370. delete_timer(sd->rental_timer, pc_inventory_rental_end);
  371. sd->rental_timer = INVALID_TIMER;
  372. }
  373. return 1;
  374. }
  375. void pc_inventory_rentals(struct map_session_data *sd)
  376. {
  377. int i, c = 0;
  378. unsigned int expire_tick, next_tick = UINT_MAX;
  379. for( i = 0; i < MAX_INVENTORY; i++ )
  380. { // Check for Rentals on Inventory
  381. if( sd->status.inventory[i].nameid == 0 )
  382. continue; // Nothing here
  383. if( sd->status.inventory[i].expire_time == 0 )
  384. continue;
  385. if( sd->status.inventory[i].expire_time <= time(NULL) ) {
  386. if( sd->status.inventory[i].nameid == ITEMID_REINS_OF_MOUNT && sd->sc.data[SC_ALL_RIDING] )
  387. status_change_end(&sd->bl, SC_ALL_RIDING, INVALID_TIMER);
  388. clif_rental_expired(sd->fd, i, sd->status.inventory[i].nameid);
  389. pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
  390. } else {
  391. expire_tick = (unsigned int)(sd->status.inventory[i].expire_time - time(NULL)) * 1000;
  392. clif_rental_time(sd->fd, sd->status.inventory[i].nameid, (int)(expire_tick / 1000));
  393. next_tick = min(expire_tick, next_tick);
  394. c++;
  395. }
  396. }
  397. 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
  398. sd->rental_timer = add_timer(gettick() + min(next_tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
  399. else
  400. sd->rental_timer = INVALID_TIMER;
  401. }
  402. void pc_inventory_rental_add(struct map_session_data *sd, int seconds)
  403. {
  404. int tick = seconds * 1000;
  405. if( sd == NULL )
  406. return;
  407. if( sd->rental_timer != INVALID_TIMER )
  408. {
  409. const struct TimerData * td;
  410. td = get_timer(sd->rental_timer);
  411. if( DIFF_TICK(td->tick, gettick()) > tick )
  412. { // Update Timer as this one ends first than the current one
  413. pc_inventory_rental_clear(sd);
  414. sd->rental_timer = add_timer(gettick() + tick, pc_inventory_rental_end, sd->bl.id, 0);
  415. }
  416. }
  417. else
  418. sd->rental_timer = add_timer(gettick() + min(tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
  419. }
  420. /**
  421. * Determines if player can give / drop / trade / vend items
  422. */
  423. bool pc_can_give_items(struct map_session_data *sd)
  424. {
  425. return pc_has_permission(sd, PC_PERM_TRADE);
  426. }
  427. /**
  428. * Determines if player can give / drop / trade / vend bounded items
  429. */
  430. bool pc_can_give_bounded_items(struct map_session_data *sd)
  431. {
  432. return pc_has_permission(sd, PC_PERM_TRADE_BOUNDED);
  433. }
  434. /*==========================================
  435. * prepares character for saving.
  436. *------------------------------------------*/
  437. int pc_makesavestatus(struct map_session_data *sd)
  438. {
  439. nullpo_ret(sd);
  440. if(!battle_config.save_clothcolor)
  441. sd->status.clothes_color=0;
  442. //Only copy the Cart/Peco/Falcon options, the rest are handled via
  443. //status change load/saving. [Skotlex]
  444. #ifdef NEW_CARTS
  445. sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
  446. #else
  447. sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_CART|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
  448. #endif
  449. if (sd->sc.data[SC_JAILED])
  450. { //When Jailed, do not move last point.
  451. if(pc_isdead(sd)){
  452. pc_setrestartvalue(sd,0);
  453. } else {
  454. sd->status.hp = sd->battle_status.hp;
  455. sd->status.sp = sd->battle_status.sp;
  456. }
  457. sd->status.last_point.map = sd->mapindex;
  458. sd->status.last_point.x = sd->bl.x;
  459. sd->status.last_point.y = sd->bl.y;
  460. return 0;
  461. }
  462. if(pc_isdead(sd)){
  463. pc_setrestartvalue(sd,0);
  464. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  465. } else {
  466. sd->status.hp = sd->battle_status.hp;
  467. sd->status.sp = sd->battle_status.sp;
  468. sd->status.last_point.map = sd->mapindex;
  469. sd->status.last_point.x = sd->bl.x;
  470. sd->status.last_point.y = sd->bl.y;
  471. }
  472. if(map[sd->bl.m].flag.nosave){
  473. struct map_data *m=&map[sd->bl.m];
  474. if(m->save.map)
  475. memcpy(&sd->status.last_point,&m->save,sizeof(sd->status.last_point));
  476. else
  477. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  478. }
  479. return 0;
  480. }
  481. /*==========================================
  482. * Off init ? Connection?
  483. *------------------------------------------*/
  484. 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)
  485. {
  486. nullpo_ret(sd);
  487. sd->bl.id = account_id;
  488. sd->status.account_id = account_id;
  489. sd->status.char_id = char_id;
  490. sd->status.sex = sex;
  491. sd->login_id1 = login_id1;
  492. sd->login_id2 = 0; // at this point, we can not know the value :(
  493. sd->client_tick = client_tick;
  494. sd->state.active = 0; //to be set to 1 after player is fully authed and loaded.
  495. sd->bl.type = BL_PC;
  496. sd->canlog_tick = gettick();
  497. //Required to prevent homunculus copuing a base speed of 0.
  498. sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
  499. return 0;
  500. }
  501. int pc_equippoint(struct map_session_data *sd,int n){
  502. int ep = 0;
  503. nullpo_ret(sd);
  504. if(!sd->inventory_data[n])
  505. return 0;
  506. if (!itemdb_isequip2(sd->inventory_data[n]))
  507. return 0; //Not equippable by players.
  508. ep = sd->inventory_data[n]->equip;
  509. if(sd->inventory_data[n]->look == W_DAGGER ||
  510. sd->inventory_data[n]->look == W_1HSWORD ||
  511. sd->inventory_data[n]->look == W_1HAXE) {
  512. if(ep == EQP_HAND_R && (pc_checkskill(sd,AS_LEFT) > 0 || (sd->class_&MAPID_UPPERMASK) == MAPID_ASSASSIN ||
  513. (sd->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO))//Kagerou and Oboro can dual wield daggers. [Rytech]
  514. return EQP_ARMS;
  515. }
  516. return ep;
  517. }
  518. /**
  519. * Fill inventory_data with struct *item_data through inventory (fill with struct *item)
  520. * @param sd : player session
  521. * @return 0 sucess, 1:invalid sd
  522. */
  523. int pc_setinventorydata(struct map_session_data *sd)
  524. {
  525. uint8 i;
  526. nullpo_retr(1,sd);
  527. for(i=0;i<MAX_INVENTORY;i++) {
  528. uint16 id = sd->status.inventory[i].nameid;
  529. sd->inventory_data[i] = id?itemdb_search(id):NULL;
  530. }
  531. return 0;
  532. }
  533. int pc_calcweapontype(struct map_session_data *sd)
  534. {
  535. nullpo_ret(sd);
  536. // single-hand
  537. if(sd->weapontype2 == W_FIST) {
  538. sd->status.weapon = sd->weapontype1;
  539. return 1;
  540. }
  541. if(sd->weapontype1 == W_FIST) {
  542. sd->status.weapon = sd->weapontype2;
  543. return 1;
  544. }
  545. // dual-wield
  546. sd->status.weapon = 0;
  547. switch (sd->weapontype1){
  548. case W_DAGGER:
  549. switch (sd->weapontype2) {
  550. case W_DAGGER: sd->status.weapon = W_DOUBLE_DD; break;
  551. case W_1HSWORD: sd->status.weapon = W_DOUBLE_DS; break;
  552. case W_1HAXE: sd->status.weapon = W_DOUBLE_DA; break;
  553. }
  554. break;
  555. case W_1HSWORD:
  556. switch (sd->weapontype2) {
  557. case W_DAGGER: sd->status.weapon = W_DOUBLE_DS; break;
  558. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SS; break;
  559. case W_1HAXE: sd->status.weapon = W_DOUBLE_SA; break;
  560. }
  561. break;
  562. case W_1HAXE:
  563. switch (sd->weapontype2) {
  564. case W_DAGGER: sd->status.weapon = W_DOUBLE_DA; break;
  565. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SA; break;
  566. case W_1HAXE: sd->status.weapon = W_DOUBLE_AA; break;
  567. }
  568. }
  569. // unknown, default to right hand type
  570. if (!sd->status.weapon)
  571. sd->status.weapon = sd->weapontype1;
  572. return 2;
  573. }
  574. int pc_setequipindex(struct map_session_data *sd)
  575. {
  576. int i,j;
  577. nullpo_ret(sd);
  578. for(i=0;i<EQI_MAX;i++)
  579. sd->equip_index[i] = -1;
  580. for(i=0;i<MAX_INVENTORY;i++) {
  581. if(sd->status.inventory[i].nameid <= 0)
  582. continue;
  583. if(sd->status.inventory[i].equip) {
  584. for(j=0;j<EQI_MAX;j++)
  585. if(sd->status.inventory[i].equip & equip_pos[j])
  586. sd->equip_index[j] = i;
  587. if(sd->status.inventory[i].equip & EQP_HAND_R)
  588. {
  589. if(sd->inventory_data[i])
  590. sd->weapontype1 = sd->inventory_data[i]->look;
  591. else
  592. sd->weapontype1 = 0;
  593. }
  594. if( sd->status.inventory[i].equip & EQP_HAND_L )
  595. {
  596. if( sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON )
  597. sd->weapontype2 = sd->inventory_data[i]->look;
  598. else
  599. sd->weapontype2 = 0;
  600. }
  601. }
  602. }
  603. pc_calcweapontype(sd);
  604. return 0;
  605. }
  606. //static int pc_isAllowedCardOn(struct map_session_data *sd,int s,int eqindex,int flag)
  607. //{
  608. // int i;
  609. // struct item *item = &sd->status.inventory[eqindex];
  610. // struct item_data *data;
  611. //
  612. // //Crafted/made/hatched items.
  613. // if (itemdb_isspecial(item->card[0]))
  614. // return 1;
  615. //
  616. // /* scan for enchant armor gems */
  617. // if( item->card[MAX_SLOTS - 1] && s < MAX_SLOTS - 1 )
  618. // s = MAX_SLOTS - 1;
  619. //
  620. // ARR_FIND( 0, s, i, item->card[i] && (data = itemdb_exists(item->card[i])) != NULL && data->flag.no_equip&flag );
  621. // return( i < s ) ? 0 : 1;
  622. //}
  623. /**
  624. * Check if an item is equiped by player
  625. * (Check if the itemid is equiped then search if that match the index in inventory (should be))
  626. * @param sd : player session
  627. * @param nameid : itemid
  628. * @return 1:yes, 0:no
  629. */
  630. bool pc_isequipped(struct map_session_data *sd, int nameid)
  631. {
  632. uint8 i;
  633. for( i = 0; i < EQI_MAX; i++ )
  634. {
  635. uint8 index = sd->equip_index[i], j;
  636. if( index < 0 ) continue;
  637. if( i == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue;
  638. if( i == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index ) continue;
  639. if( i == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index) ) continue;
  640. if( !sd->inventory_data[index] )
  641. continue;
  642. if( sd->inventory_data[index]->nameid == nameid )
  643. return true;
  644. for( j = 0; j < sd->inventory_data[index]->slot; j++ ){
  645. if( sd->status.inventory[index].card[j] == nameid )
  646. return true;
  647. }
  648. }
  649. return false;
  650. }
  651. bool pc_can_Adopt(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd )
  652. {
  653. if( !p1_sd || !p2_sd || !b_sd )
  654. return false;
  655. if( b_sd->status.father || b_sd->status.mother || b_sd->adopt_invite )
  656. return false; // already adopted baby / in adopt request
  657. if( !p1_sd->status.partner_id || !p1_sd->status.party_id || p1_sd->status.party_id != b_sd->status.party_id )
  658. return false; // You need to be married and in party with baby to adopt
  659. if( p1_sd->status.partner_id != p2_sd->status.char_id || p2_sd->status.partner_id != p1_sd->status.char_id )
  660. return false; // Not married, wrong married
  661. if( p2_sd->status.party_id != p1_sd->status.party_id )
  662. return false; // Both parents need to be in the same party
  663. // Parents need to have their ring equipped
  664. if( !pc_isequipped(p1_sd, WEDDING_RING_M) && !pc_isequipped(p1_sd, WEDDING_RING_F) )
  665. return false;
  666. if( !pc_isequipped(p2_sd, WEDDING_RING_M) && !pc_isequipped(p2_sd, WEDDING_RING_F) )
  667. return false;
  668. // Already adopted a baby
  669. if( p1_sd->status.child || p2_sd->status.child ) {
  670. clif_Adopt_reply(p1_sd, 0);
  671. return false;
  672. }
  673. // Parents need at least lvl 70 to adopt
  674. if( p1_sd->status.base_level < 70 || p2_sd->status.base_level < 70 ) {
  675. clif_Adopt_reply(p1_sd, 1);
  676. return false;
  677. }
  678. if( b_sd->status.partner_id ) {
  679. clif_Adopt_reply(p1_sd, 2);
  680. return false;
  681. }
  682. if( !( ( b_sd->status.class_ >= JOB_NOVICE && b_sd->status.class_ <= JOB_THIEF ) || b_sd->status.class_ == JOB_SUPER_NOVICE ) )
  683. return false;
  684. return true;
  685. }
  686. /*==========================================
  687. * Adoption Process
  688. *------------------------------------------*/
  689. bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
  690. {
  691. int job, joblevel;
  692. unsigned int jobexp;
  693. if( !pc_can_Adopt(p1_sd, p2_sd, b_sd) )
  694. return false;
  695. // Preserve current job levels and progress
  696. joblevel = b_sd->status.job_level;
  697. jobexp = b_sd->status.job_exp;
  698. job = pc_mapid2jobid(b_sd->class_|JOBL_BABY, b_sd->status.sex);
  699. if( job != -1 && !pc_jobchange(b_sd, job, 0) )
  700. { // Success, proceed to configure parents and baby skills
  701. p1_sd->status.child = b_sd->status.char_id;
  702. p2_sd->status.child = b_sd->status.char_id;
  703. b_sd->status.father = p1_sd->status.char_id;
  704. b_sd->status.mother = p2_sd->status.char_id;
  705. // Restore progress
  706. b_sd->status.job_level = joblevel;
  707. clif_updatestatus(b_sd, SP_JOBLEVEL);
  708. b_sd->status.job_exp = jobexp;
  709. clif_updatestatus(b_sd, SP_JOBEXP);
  710. // Baby Skills
  711. pc_skill(b_sd, WE_BABY, 1, 0);
  712. pc_skill(b_sd, WE_CALLPARENT, 1, 0);
  713. // Parents Skills
  714. pc_skill(p1_sd, WE_CALLBABY, 1, 0);
  715. pc_skill(p2_sd, WE_CALLBABY, 1, 0);
  716. return true;
  717. }
  718. return false; // Job Change Fail
  719. }
  720. /*==========================================
  721. * Check if player can use/equip selected item. Used by pc_isUseitem and pc_isequip
  722. Returns:
  723. false : Cannot use/equip
  724. true : Can use/equip
  725. * Credits:
  726. [Inkfish] for first idea
  727. [Haru] for third-classes extension
  728. [Cydh] finishing :D
  729. *------------------------------------------*/
  730. static bool pc_isItemClass (struct map_session_data *sd, struct item_data* item) {
  731. while (1) {
  732. if (item->class_upper&ITEMJ_NORMAL && !(sd->class_&(JOBL_UPPER|JOBL_THIRD|JOBL_BABY))) //normal classes (no upper, no baby, no third)
  733. break;
  734. #ifndef RENEWAL
  735. //allow third classes to use trans. class items
  736. if (item->class_upper&ITEMJ_UPPER && sd->class_&(JOBL_UPPER|JOBL_THIRD)) //trans. classes
  737. break;
  738. //third-baby classes can use same item too
  739. if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY) //baby classes
  740. break;
  741. //don't need to decide specific rules for third-classes?
  742. //items for third classes can be used for all third classes
  743. if (item->class_upper&(ITEMJ_THIRD|ITEMJ_THIRD_TRANS|ITEMJ_THIRD_BABY) && sd->class_&JOBL_THIRD)
  744. break;
  745. #else
  746. //trans. classes (exl. third-trans.)
  747. if (item->class_upper&ITEMJ_UPPER && sd->class_&JOBL_UPPER && !(sd->class_&JOBL_THIRD))
  748. break;
  749. //baby classes (exl. third-baby)
  750. if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY && !(sd->class_&JOBL_THIRD))
  751. break;
  752. //third classes (exl. third-trans. and baby-third)
  753. if (item->class_upper&ITEMJ_THIRD && sd->class_&JOBL_THIRD && !(sd->class_&(JOBL_UPPER|JOBL_BABY)))
  754. break;
  755. //trans-third classes
  756. if (item->class_upper&ITEMJ_THIRD_TRANS && sd->class_&JOBL_THIRD && sd->class_&JOBL_UPPER)
  757. break;
  758. //third-baby classes
  759. if (item->class_upper&ITEMJ_THIRD_BABY && sd->class_&JOBL_THIRD && sd->class_&JOBL_BABY)
  760. break;
  761. #endif
  762. return false;
  763. }
  764. return true;
  765. }
  766. /*=================================================
  767. * Checks if the player can equip the item at index n in inventory.
  768. * Returns 0 (no) or 1 (yes).
  769. *------------------------------------------------*/
  770. int pc_isequip(struct map_session_data *sd,int n)
  771. {
  772. struct item_data *item;
  773. nullpo_ret(sd);
  774. item = sd->inventory_data[n];
  775. if(pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT))
  776. return 1;
  777. if(item == NULL)
  778. return 0;
  779. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  780. return 0;
  781. #ifdef RENEWAL
  782. if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
  783. return 0;
  784. #endif
  785. if(item->sex != 2 && sd->status.sex != item->sex)
  786. return 0;
  787. if (sd->sc.count) {
  788. if(item->equip & EQP_ARMS && item->type == IT_WEAPON && sd->sc.data[SC_STRIPWEAPON]) // Also works with left-hand weapons [DracoRPG]
  789. return 0;
  790. if(item->equip & EQP_SHIELD && item->type == IT_ARMOR && sd->sc.data[SC_STRIPSHIELD])
  791. return 0;
  792. if(item->equip & EQP_ARMOR && sd->sc.data[SC_STRIPARMOR])
  793. return 0;
  794. if(item->equip & EQP_HEAD_TOP && sd->sc.data[SC_STRIPHELM])
  795. return 0;
  796. if(item->equip & EQP_ACC && sd->sc.data[SC__STRIPACCESSORY])
  797. return 0;
  798. if(item->equip && sd->sc.data[SC_KYOUGAKU])
  799. return 0;
  800. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_SUPERNOVICE) {
  801. //Spirit of Super Novice equip bonuses. [Skotlex]
  802. if (sd->status.base_level > 90 && item->equip & EQP_HELM)
  803. return 1; //Can equip all helms
  804. if (sd->status.base_level > 96 && item->equip & EQP_ARMS && item->type == IT_WEAPON)
  805. switch(item->look) { //In weapons, the look determines type of weapon.
  806. case W_DAGGER: //Level 4 Knives are equippable.. this means all knives, I'd guess?
  807. case W_1HSWORD: //All 1H swords
  808. case W_1HAXE: //All 1H Axes
  809. case W_MACE: //All 1H Maces
  810. case W_STAFF: //All 1H Staves
  811. return 1;
  812. }
  813. }
  814. }
  815. //fail to equip if item is restricted
  816. if (!battle_config.allow_equip_restricted_item && itemdb_isNoEquip(item, sd->bl.m))
  817. return 0;
  818. //Not equipable by class. [Skotlex]
  819. if (!(1<<(sd->class_&MAPID_BASEMASK)&item->class_base[(sd->class_&JOBL_2_1)?1:((sd->class_&JOBL_2_2)?2:0)]))
  820. return 0;
  821. if (!pc_isItemClass(sd,item))
  822. return 0;
  823. return 1;
  824. }
  825. /*==========================================
  826. * No problem with the session id
  827. * set the status that has been sent from char server
  828. *------------------------------------------*/
  829. bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers)
  830. {
  831. int i;
  832. #ifdef BOUND_ITEMS
  833. int j;
  834. int idxlist[MAX_INVENTORY];
  835. #endif
  836. unsigned long tick = gettick();
  837. uint32 ip = session[sd->fd]->client_addr;
  838. sd->login_id2 = login_id2;
  839. sd->group_id = group_id;
  840. /* load user permissions */
  841. pc_group_pc_load(sd);
  842. memcpy(&sd->status, st, sizeof(*st));
  843. if (st->sex != sd->status.sex) {
  844. clif_authfail_fd(sd->fd, 0);
  845. return false;
  846. }
  847. //Set the map-server used job id. [Skotlex]
  848. i = pc_jobid2mapid(sd->status.class_);
  849. if (i == -1) { //Invalid class?
  850. 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);
  851. sd->status.class_ = JOB_NOVICE;
  852. sd->class_ = MAPID_NOVICE;
  853. } else
  854. sd->class_ = i;
  855. // Checks and fixes to character status data, that are required
  856. // in case of configuration change or stuff, which cannot be
  857. // checked on char-server.
  858. sd->status.hair = cap_value(sd->status.hair,MIN_HAIR_STYLE,MAX_HAIR_STYLE);
  859. sd->status.hair_color = cap_value(sd->status.hair_color,MIN_HAIR_COLOR,MAX_HAIR_COLOR);
  860. sd->status.clothes_color = cap_value(sd->status.clothes_color,MIN_CLOTH_COLOR,MAX_CLOTH_COLOR);
  861. //Initializations to null/0 unneeded since map_session_data was filled with 0 upon allocation.
  862. if(!sd->status.hp) pc_setdead(sd);
  863. sd->state.connect_new = 1;
  864. sd->followtimer = INVALID_TIMER; // [MouseJstr]
  865. sd->invincible_timer = INVALID_TIMER;
  866. sd->npc_timer_id = INVALID_TIMER;
  867. sd->pvp_timer = INVALID_TIMER;
  868. #ifdef SECURE_NPCTIMEOUT
  869. // Initialize to defaults/expected
  870. sd->npc_idle_timer = INVALID_TIMER;
  871. sd->npc_idle_tick = tick;
  872. sd->npc_idle_type = NPCT_INPUT;
  873. #endif
  874. sd->canuseitem_tick = tick;
  875. sd->canusecashfood_tick = tick;
  876. sd->canequip_tick = tick;
  877. sd->cantalk_tick = tick;
  878. sd->canskill_tick = tick;
  879. sd->cansendmail_tick = tick;
  880. for(i = 0; i < MAX_SKILL_LEVEL; i++)
  881. sd->spirit_timer[i] = INVALID_TIMER;
  882. for(i = 0; i < ARRAYLENGTH(sd->autobonus); i++)
  883. sd->autobonus[i].active = INVALID_TIMER;
  884. for(i = 0; i < ARRAYLENGTH(sd->autobonus2); i++)
  885. sd->autobonus2[i].active = INVALID_TIMER;
  886. for(i = 0; i < ARRAYLENGTH(sd->autobonus3); i++)
  887. sd->autobonus3[i].active = INVALID_TIMER;
  888. if (battle_config.item_auto_get)
  889. sd->state.autoloot = 10000;
  890. if (battle_config.disp_experience)
  891. sd->state.showexp = 1;
  892. if (battle_config.disp_zeny)
  893. sd->state.showzeny = 1;
  894. #ifdef VIP_ENABLE
  895. if (!battle_config.vip_disp_rate)
  896. sd->disableshowrate = 1;
  897. #endif
  898. if (!(battle_config.display_skill_fail&2))
  899. sd->state.showdelay = 1;
  900. pc_setinventorydata(sd);
  901. pc_setequipindex(sd);
  902. if( sd->status.option&OPTION_INVISIBLE && !pc_can_use_command( sd, "hide", COMMAND_ATCOMMAND ) ){
  903. sd->status.option &= ~OPTION_INVISIBLE;
  904. }
  905. status_change_init(&sd->bl);
  906. sd->sc.option = sd->status.option; //This is the actual option used in battle.
  907. //Set here because we need the inventory data for weapon sprite parsing.
  908. status_set_viewdata(&sd->bl, sd->status.class_);
  909. unit_dataset(&sd->bl);
  910. sd->guild_x = -1;
  911. sd->guild_y = -1;
  912. // Event Timers
  913. for( i = 0; i < MAX_EVENTTIMER; i++ )
  914. sd->eventtimer[i] = INVALID_TIMER;
  915. // Rental Timer
  916. sd->rental_timer = INVALID_TIMER;
  917. for( i = 0; i < 3; i++ )
  918. sd->hate_mob[i] = -1;
  919. //warp player
  920. if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != 0) {
  921. 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);
  922. // try warping to a default map instead (church graveyard)
  923. if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != 0) {
  924. // if we fail again
  925. clif_authfail_fd(sd->fd, 0);
  926. return false;
  927. }
  928. }
  929. clif_authok(sd);
  930. //Prevent S. Novices from getting the no-death bonus just yet. [Skotlex]
  931. sd->die_counter=-1;
  932. //display login notice
  933. ShowInfo("'"CL_WHITE"%s"CL_RESET"' logged in."
  934. " (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"',"
  935. " Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%d.%d.%d.%d"CL_RESET"',"
  936. " Group '"CL_WHITE"%d"CL_RESET"').\n",
  937. sd->status.name, sd->status.account_id, sd->status.char_id,
  938. sd->packet_ver, CONVIP(ip), sd->group_id);
  939. // Send friends list
  940. clif_friendslist_send(sd);
  941. if( !changing_mapservers ) {
  942. if (battle_config.display_version == 1)
  943. pc_show_version(sd);
  944. // Message of the Day [Valaris]
  945. for(i=0; i < MOTD_LINE_SIZE && motd_text[i][0]; i++) {
  946. if (battle_config.motd_type)
  947. clif_disp_onlyself(sd,motd_text[i],strlen(motd_text[i]));
  948. else
  949. clif_displaymessage(sd->fd, motd_text[i]);
  950. }
  951. // message of the limited time of the account
  952. if (expiration_time != 0) { // don't display if it's unlimited or unknow value
  953. char tmpstr[1024];
  954. strftime(tmpstr, sizeof(tmpstr) - 1, msg_txt(sd,501), localtime(&expiration_time)); // "Your account time limit is: %d-%m-%Y %H:%M:%S."
  955. clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
  956. }
  957. /**
  958. * Fixes login-without-aura glitch (the screen won't blink at this point, don't worry :P)
  959. **/
  960. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  961. }
  962. /**
  963. * Check if player have any item cooldowns on
  964. **/
  965. pc_itemcd_do(sd,true);
  966. #ifdef BOUND_ITEMS
  967. // Party bound item check
  968. if(sd->status.party_id == 0 && (j = pc_bound_chk(sd,3,idxlist))) { // Party was deleted while character offline
  969. for(i=0;i<j;i++)
  970. pc_delitem(sd,idxlist[i],sd->status.inventory[idxlist[i]].amount,0,1,LOG_TYPE_OTHER);
  971. }
  972. #endif
  973. // Player has not yet received the CashShop list
  974. sd->status.cashshop_sent = false;
  975. // Request all registries (auth is considered completed whence they arrive)
  976. intif_request_registry(sd,7);
  977. return true;
  978. }
  979. /*==========================================
  980. * Closes a connection because it failed to be authenticated from the char server.
  981. *------------------------------------------*/
  982. void pc_authfail(struct map_session_data *sd)
  983. {
  984. clif_authfail_fd(sd->fd, 0);
  985. return;
  986. }
  987. /**
  988. * Player register a bl as hatred
  989. * @param sd : player session
  990. * @param pos : hate position [0;2]
  991. * @param bl : target bl
  992. * @return false:failed, true:success
  993. */
  994. bool pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl)
  995. {
  996. int class_;
  997. if (!sd || !bl || pos < 0 || pos > 2)
  998. return false;
  999. if (sd->hate_mob[pos] != -1)
  1000. { //Can't change hate targets.
  1001. clif_hate_info(sd, pos, sd->hate_mob[pos], 0); //Display current
  1002. return false;
  1003. }
  1004. class_ = status_get_class(bl);
  1005. if (!pcdb_checkid(class_)) {
  1006. unsigned int max_hp = status_get_max_hp(bl);
  1007. if ((pos == 1 && max_hp < 6000) || (pos == 2 && max_hp < 20000))
  1008. return false;
  1009. if (pos != status_get_size(bl))
  1010. return false; //Wrong size
  1011. }
  1012. sd->hate_mob[pos] = class_;
  1013. pc_setglobalreg(sd,sg_info[pos].hate_var,class_+1);
  1014. clif_hate_info(sd, pos, class_, 1);
  1015. return true;
  1016. }
  1017. /*==========================================
  1018. * Invoked once after the char/account/account2 registry variables are received. [Skotlex]
  1019. *------------------------------------------*/
  1020. int pc_reg_received(struct map_session_data *sd)
  1021. {
  1022. uint8 i;
  1023. sd->change_level_2nd = pc_readglobalreg(sd,"jobchange_level");
  1024. sd->change_level_3rd = pc_readglobalreg(sd,"jobchange_level_3rd");
  1025. sd->die_counter = pc_readglobalreg(sd,"PC_DIE_COUNTER");
  1026. sd->langtype = pc_readaccountreg(sd,"#langtype");
  1027. if(msg_checklangtype(sd->langtype,true)<0) sd->langtype=0; //invalid langtype reset to default
  1028. // Cash shop
  1029. sd->cashPoints = pc_readaccountreg(sd,"#CASHPOINTS");
  1030. sd->kafraPoints = pc_readaccountreg(sd,"#KAFRAPOINTS");
  1031. // Cooking Exp
  1032. sd->cook_mastery = pc_readglobalreg(sd,"COOK_MASTERY");
  1033. if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON )
  1034. { // Better check for class rather than skill to prevent "skill resets" from unsetting this
  1035. sd->mission_mobid = pc_readglobalreg(sd,"TK_MISSION_ID");
  1036. sd->mission_count = pc_readglobalreg(sd,"TK_MISSION_COUNT");
  1037. }
  1038. //SG map and mob read [Komurka]
  1039. for(i=0;i<MAX_PC_FEELHATE;i++) //for now - someone need to make reading from txt/sql
  1040. {
  1041. uint16 j;
  1042. if ((j = pc_readglobalreg(sd,sg_info[i].feel_var))!=0) {
  1043. sd->feel_map[i].index = j;
  1044. sd->feel_map[i].m = map_mapindex2mapid(j);
  1045. } else {
  1046. sd->feel_map[i].index = 0;
  1047. sd->feel_map[i].m = -1;
  1048. }
  1049. sd->hate_mob[i] = pc_readglobalreg(sd,sg_info[i].hate_var)-1;
  1050. }
  1051. if ((i = pc_checkskill(sd,RG_PLAGIARISM)) > 0) {
  1052. sd->cloneskill_idx = skill_get_index(pc_readglobalreg(sd,SKILL_VAR_PLAGIARISM));
  1053. if (sd->cloneskill_idx >= 0) {
  1054. sd->status.skill[sd->cloneskill_idx].id = pc_readglobalreg(sd,SKILL_VAR_PLAGIARISM);
  1055. sd->status.skill[sd->cloneskill_idx].lv = pc_readglobalreg(sd,SKILL_VAR_PLAGIARISM_LV);
  1056. if (sd->status.skill[sd->cloneskill_idx].lv > i)
  1057. sd->status.skill[sd->cloneskill_idx].lv = i;
  1058. sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
  1059. }
  1060. }
  1061. if ((i = pc_checkskill(sd,SC_REPRODUCE)) > 0) {
  1062. sd->reproduceskill_idx = skill_get_index(pc_readglobalreg(sd,SKILL_VAR_REPRODUCE));
  1063. if (sd->reproduceskill_idx >= 0) {
  1064. sd->status.skill[sd->reproduceskill_idx].id = pc_readglobalreg(sd,SKILL_VAR_REPRODUCE);
  1065. sd->status.skill[sd->reproduceskill_idx].lv = pc_readglobalreg(sd,SKILL_VAR_REPRODUCE_LV);
  1066. if (i < sd->status.skill[sd->reproduceskill_idx].lv)
  1067. sd->status.skill[sd->reproduceskill_idx].lv = i;
  1068. sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
  1069. }
  1070. }
  1071. //Weird... maybe registries were reloaded?
  1072. if (sd->state.active)
  1073. return 0;
  1074. sd->state.active = 1;
  1075. if (sd->status.party_id)
  1076. party_member_joined(sd);
  1077. if (sd->status.guild_id)
  1078. guild_member_joined(sd);
  1079. // pet
  1080. if (sd->status.pet_id > 0)
  1081. intif_request_petdata(sd->status.account_id, sd->status.char_id, sd->status.pet_id);
  1082. // Homunculus [albator]
  1083. if( sd->status.hom_id > 0 )
  1084. intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id);
  1085. if( sd->status.mer_id > 0 )
  1086. intif_mercenary_request(sd->status.mer_id, sd->status.char_id);
  1087. if( sd->status.ele_id > 0 )
  1088. intif_elemental_request(sd->status.ele_id, sd->status.char_id);
  1089. map_addiddb(&sd->bl);
  1090. map_delnickdb(sd->status.char_id, sd->status.name);
  1091. if (!chrif_auth_finished(sd))
  1092. ShowError("pc_reg_received: Failed to properly remove player %d:%d from logging db!\n", sd->status.account_id, sd->status.char_id);
  1093. pc_check_available_item(sd); // Check for invalid(ated) items.
  1094. pc_load_combo(sd);
  1095. status_calc_pc(sd,1);
  1096. chrif_scdata_request(sd->status.account_id, sd->status.char_id);
  1097. chrif_skillcooldown_request(sd->status.account_id, sd->status.char_id);
  1098. chrif_bsdata_request(sd->status.char_id);
  1099. sd->storage_size = MIN_STORAGE; //default to min
  1100. if(battle_config.feature_banking)
  1101. chrif_req_login_operation(sd->status.account_id, sd->status.name, 7, 0, 1, 0); //request Bank data
  1102. #ifdef VIP_ENABLE
  1103. sd->vip.time = 0;
  1104. sd->vip.enabled = 0;
  1105. chrif_req_login_operation(sd->status.account_id, sd->status.name, 6, 0, 1, 0); // request VIP informations
  1106. #endif
  1107. intif_Mail_requestinbox(sd->status.char_id, 0); // MAIL SYSTEM - Request Mail Inbox
  1108. intif_request_questlog(sd);
  1109. if (sd->state.connect_new == 0 && sd->fd) { //Character already loaded map! Gotta trigger LoadEndAck manually.
  1110. sd->state.connect_new = 1;
  1111. clif_parse_LoadEndAck(sd->fd, sd);
  1112. }
  1113. pc_inventory_rentals(sd);
  1114. if( sd->sc.option&OPTION_INVISIBLE ) {
  1115. sd->vd.class_ = INVISIBLE_CLASS;
  1116. clif_displaymessage( sd->fd, msg_txt( sd, 11 ) ); // Invisible: On
  1117. // decrement the number of pvp players on the map
  1118. map[sd->bl.m].users_pvp--;
  1119. if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER ){
  1120. // unregister the player for ranking
  1121. delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  1122. sd->pvp_timer = INVALID_TIMER;
  1123. }
  1124. clif_changeoption( &sd->bl );
  1125. }
  1126. if( sd->state.autotrade ){
  1127. clif_parse_LoadEndAck(sd->fd, sd);
  1128. }
  1129. return 1;
  1130. }
  1131. static int pc_calc_skillpoint(struct map_session_data* sd)
  1132. {
  1133. uint16 i, skill_point=0;
  1134. nullpo_ret(sd);
  1135. for(i=1;i<MAX_SKILL;i++){
  1136. uint8 skill_lv;
  1137. if( (skill_lv = pc_checkskill(sd,i)) > 0) {
  1138. uint16 inf2 = skill_get_inf2(i);
  1139. if((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  1140. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) //Do not count wedding/link skills. [Skotlex]
  1141. ) {
  1142. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  1143. skill_point += skill_lv;
  1144. else
  1145. if(sd->status.skill[i].flag == SKILL_FLAG_REPLACED_LV_0)
  1146. skill_point += (sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0);
  1147. }
  1148. }
  1149. }
  1150. return skill_point;
  1151. }
  1152. /*==========================================
  1153. * Calculation of skill level.
  1154. *------------------------------------------*/
  1155. int pc_calc_skilltree(struct map_session_data *sd)
  1156. {
  1157. int i,id=0,flag;
  1158. int c=0;
  1159. nullpo_ret(sd);
  1160. i = pc_calc_skilltree_normalize_job(sd);
  1161. c = pc_mapid2jobid(i, sd->status.sex);
  1162. if( c == -1 )
  1163. { //Unable to normalize job??
  1164. 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);
  1165. return 1;
  1166. }
  1167. c = pc_class2idx(c);
  1168. for( i = 0; i < MAX_SKILL; i++ ) {
  1169. if( sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED ) //Don't touch these
  1170. sd->status.skill[i].id = 0; //First clear skills.
  1171. /* permanent skills that must be re-checked */
  1172. if( sd->status.skill[i].flag == SKILL_FLAG_PERM_GRANTED ) {
  1173. switch( i ) {
  1174. case NV_TRICKDEAD:
  1175. if( (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ) {
  1176. sd->status.skill[i].id = 0;
  1177. sd->status.skill[i].lv = 0;
  1178. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1179. }
  1180. break;
  1181. }
  1182. }
  1183. }
  1184. for( i = 0; i < MAX_SKILL; i++ )
  1185. {
  1186. if( sd->status.skill[i].flag != SKILL_FLAG_PERMANENT && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED && sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED )
  1187. { // Restore original level of skills after deleting earned skills.
  1188. sd->status.skill[i].lv = (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  1189. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1190. }
  1191. if( sd->sc.count && sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_BARDDANCER && i >= DC_HUMMING && i<= DC_SERVICEFORYOU )
  1192. { //Enable Bard/Dancer spirit linked skills.
  1193. if( sd->status.sex )
  1194. { //Link dancer skills to bard.
  1195. if( sd->status.skill[i-8].lv < 10 )
  1196. continue;
  1197. sd->status.skill[i].id = i;
  1198. sd->status.skill[i].lv = sd->status.skill[i-8].lv; // Set the level to the same as the linking skill
  1199. sd->status.skill[i].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
  1200. }
  1201. else
  1202. { //Link bard skills to dancer.
  1203. if( sd->status.skill[i].lv < 10 )
  1204. continue;
  1205. sd->status.skill[i-8].id = i - 8;
  1206. sd->status.skill[i-8].lv = sd->status.skill[i].lv; // Set the level to the same as the linking skill
  1207. sd->status.skill[i-8].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
  1208. }
  1209. }
  1210. }
  1211. if( pc_has_permission(sd, PC_PERM_ALL_SKILL) ) {
  1212. for( i = 0; i < MAX_SKILL; i++ ) {
  1213. switch(i) {
  1214. /**
  1215. * Dummy skills must be added here otherwise they'll be displayed in the,
  1216. * skill tree and since they have no icons they'll give resource errors
  1217. **/
  1218. case SM_SELFPROVOKE:
  1219. case AB_DUPLELIGHT_MELEE:
  1220. case AB_DUPLELIGHT_MAGIC:
  1221. case WL_CHAINLIGHTNING_ATK:
  1222. case WL_TETRAVORTEX_FIRE:
  1223. case WL_TETRAVORTEX_WATER:
  1224. case WL_TETRAVORTEX_WIND:
  1225. case WL_TETRAVORTEX_GROUND:
  1226. case WL_SUMMON_ATK_FIRE:
  1227. case WL_SUMMON_ATK_WIND:
  1228. case WL_SUMMON_ATK_WATER:
  1229. case WL_SUMMON_ATK_GROUND:
  1230. case LG_OVERBRAND_BRANDISH:
  1231. case LG_OVERBRAND_PLUSATK:
  1232. case WM_SEVERE_RAINSTORM_MELEE:
  1233. continue;
  1234. default:
  1235. break;
  1236. }
  1237. if( skill_get_inf2(i)&(INF2_NPC_SKILL|INF2_GUILD_SKILL) )
  1238. continue; //Only skills you can't have are npc/guild ones
  1239. if( skill_get_max(i) > 0 )
  1240. sd->status.skill[i].id = i;
  1241. }
  1242. return 0;
  1243. }
  1244. do {
  1245. flag = 0;
  1246. for( i = 0; i < MAX_SKILL_TREE && (id = skill_tree[c][i].id) > 0; i++ )
  1247. {
  1248. int f;
  1249. if( sd->status.skill[id].id )
  1250. continue; //Skill already known.
  1251. f = 1;
  1252. if(!battle_config.skillfree) {
  1253. int j;
  1254. for(j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
  1255. int k;
  1256. if((k=skill_tree[c][i].need[j].id))
  1257. {
  1258. if (sd->status.skill[k].id == 0 || sd->status.skill[k].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[k].flag == SKILL_FLAG_PLAGIARIZED)
  1259. k = 0; //Not learned.
  1260. else
  1261. if (sd->status.skill[k].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
  1262. k = sd->status.skill[skill_tree[c][i].need[j].id].flag - SKILL_FLAG_REPLACED_LV_0;
  1263. else
  1264. k = pc_checkskill(sd,k);
  1265. if (k < skill_tree[c][i].need[j].lv)
  1266. {
  1267. f = 0;
  1268. break;
  1269. }
  1270. }
  1271. }
  1272. if( sd->status.job_level < skill_tree[c][i].joblv ) { //We need to get the actual class in this case
  1273. int class_ = pc_mapid2jobid(sd->class_, sd->status.sex);
  1274. class_ = pc_class2idx(class_);
  1275. if (class_ == c || (class_ != c && sd->status.job_level < skill_tree[class_][i].joblv))
  1276. f = 0; // job level requirement wasn't satisfied
  1277. }
  1278. }
  1279. if( f ) {
  1280. int inf2;
  1281. inf2 = skill_get_inf2(id);
  1282. if(!sd->status.skill[id].lv && (
  1283. (inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  1284. inf2&INF2_WEDDING_SKILL ||
  1285. (inf2&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
  1286. ))
  1287. continue; //Cannot be learned via normal means. Note this check DOES allows raising already known skills.
  1288. sd->status.skill[id].id = id;
  1289. if(inf2&INF2_SPIRIT_SKILL) { //Spirit skills cannot be learned, they will only show up on your tree when you get buffed.
  1290. sd->status.skill[id].lv = 1; // need to manually specify a skill level
  1291. sd->status.skill[id].flag = SKILL_FLAG_TEMPORARY; //So it is not saved, and tagged as a "bonus" skill.
  1292. }
  1293. flag = 1; // skill list has changed, perform another pass
  1294. }
  1295. }
  1296. } while(flag);
  1297. //
  1298. 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) )
  1299. {
  1300. /* Taekwon Ranger Bonus Skill Tree
  1301. ============================================
  1302. - Grant All Taekwon Tree, but only as Bonus Skills in case they drop from ranking.
  1303. - (c > 0) to avoid grant Novice Skill Tree in case of Skill Reset (need more logic)
  1304. - (sd->status.skill_point == 0) to wait until all skill points are asigned to avoid problems with Job Change quest. */
  1305. for( i = 0; i < MAX_SKILL_TREE && (id = skill_tree[c][i].id) > 0; i++ )
  1306. {
  1307. if( (skill_get_inf2(id)&(INF2_QUEST_SKILL|INF2_WEDDING_SKILL)) )
  1308. continue; //Do not include Quest/Wedding skills.
  1309. if( sd->status.skill[id].id == 0 )
  1310. {
  1311. sd->status.skill[id].id = id;
  1312. sd->status.skill[id].flag = SKILL_FLAG_TEMPORARY; // So it is not saved, and tagged as a "bonus" skill.
  1313. }
  1314. else if( id != NV_BASIC )
  1315. {
  1316. sd->status.skill[id].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[id].lv; // Remember original level
  1317. }
  1318. sd->status.skill[id].lv = skill_tree_get_max(id, sd->status.class_);
  1319. }
  1320. }
  1321. return 0;
  1322. }
  1323. //Checks if you can learn a new skill after having leveled up a skill.
  1324. static void pc_check_skilltree(struct map_session_data *sd, int skill)
  1325. {
  1326. int i,id=0,flag;
  1327. int c=0;
  1328. if(battle_config.skillfree)
  1329. return; //Function serves no purpose if this is set
  1330. i = pc_calc_skilltree_normalize_job(sd);
  1331. c = pc_mapid2jobid(i, sd->status.sex);
  1332. if (c == -1) { //Unable to normalize job??
  1333. 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);
  1334. return;
  1335. }
  1336. c = pc_class2idx(c);
  1337. do {
  1338. flag = 0;
  1339. for( i = 0; i < MAX_SKILL_TREE && (id=skill_tree[c][i].id)>0; i++ )
  1340. {
  1341. int j, f = 1;
  1342. if( sd->status.skill[id].id ) //Already learned
  1343. continue;
  1344. for( j = 0; j < MAX_PC_SKILL_REQUIRE; j++ ){
  1345. int k = skill_tree[c][i].need[j].id;
  1346. if( k != 0 ){
  1347. if( sd->status.skill[k].id == 0 || sd->status.skill[k].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[k].flag == SKILL_FLAG_PLAGIARIZED )
  1348. k = 0; //Not learned.
  1349. else
  1350. if( sd->status.skill[k].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
  1351. k = sd->status.skill[skill_tree[c][i].need[j].id].flag - SKILL_FLAG_REPLACED_LV_0;
  1352. else
  1353. k = pc_checkskill(sd,k);
  1354. if( k < skill_tree[c][i].need[j].lv )
  1355. {
  1356. f = 0;
  1357. break;
  1358. }
  1359. }
  1360. }
  1361. if( !f )
  1362. continue;
  1363. if( sd->status.job_level < skill_tree[c][i].joblv )
  1364. continue;
  1365. j = skill_get_inf2(id);
  1366. if( !sd->status.skill[id].lv && (
  1367. (j&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  1368. j&INF2_WEDDING_SKILL ||
  1369. (j&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
  1370. ) )
  1371. continue; //Cannot be learned via normal means.
  1372. sd->status.skill[id].id = id;
  1373. flag = 1;
  1374. }
  1375. } while(flag);
  1376. }
  1377. // Make sure all the skills are in the correct condition
  1378. // before persisting to the backend.. [MouseJstr]
  1379. void pc_clean_skilltree(struct map_session_data *sd)
  1380. {
  1381. uint16 i;
  1382. for (i = 0; i < MAX_SKILL; i++){
  1383. if (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED)
  1384. {
  1385. sd->status.skill[i].id = 0;
  1386. sd->status.skill[i].lv = 0;
  1387. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1388. }
  1389. else
  1390. if (sd->status.skill[i].flag == SKILL_FLAG_REPLACED_LV_0){
  1391. sd->status.skill[i].lv = sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  1392. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1393. }
  1394. }
  1395. }
  1396. int pc_calc_skilltree_normalize_job(struct map_session_data *sd)
  1397. {
  1398. int skill_point, novice_skills;
  1399. int c = sd->class_;
  1400. if (!battle_config.skillup_limit || pc_has_permission(sd, PC_PERM_ALL_SKILL))
  1401. return c;
  1402. skill_point = pc_calc_skillpoint(sd);
  1403. novice_skills = job_info[pc_class2idx(JOB_NOVICE)].max_level[1] - 1;
  1404. // limit 1st class and above to novice job levels
  1405. if(skill_point < novice_skills)
  1406. {
  1407. c = MAPID_NOVICE;
  1408. }
  1409. // limit 2nd class and above to first class job levels (super novices are exempt)
  1410. else if ((sd->class_&JOBL_2) && (sd->class_&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE)
  1411. {
  1412. // regenerate change_level_2nd
  1413. if (!sd->change_level_2nd)
  1414. {
  1415. if (sd->class_&JOBL_THIRD)
  1416. {
  1417. // if neither 2nd nor 3rd jobchange levels are known, we have to assume a default for 2nd
  1418. if (!sd->change_level_3rd)
  1419. sd->change_level_2nd = job_info[pc_class2idx(pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex))].max_level[1];
  1420. else
  1421. sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
  1422. - (sd->status.job_level - 1)
  1423. - (sd->change_level_3rd - 1)
  1424. - novice_skills;
  1425. }
  1426. else
  1427. {
  1428. sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
  1429. - (sd->status.job_level - 1)
  1430. - novice_skills;
  1431. }
  1432. pc_setglobalreg (sd, "jobchange_level", sd->change_level_2nd);
  1433. }
  1434. if (skill_point < novice_skills + (sd->change_level_2nd - 1))
  1435. {
  1436. c &= MAPID_BASEMASK;
  1437. }
  1438. // limit 3rd class to 2nd class/trans job levels
  1439. else if(sd->class_&JOBL_THIRD)
  1440. {
  1441. // regenerate change_level_3rd
  1442. if (!sd->change_level_3rd)
  1443. {
  1444. sd->change_level_3rd = 1 + skill_point + sd->status.skill_point
  1445. - (sd->status.job_level - 1)
  1446. - (sd->change_level_2nd - 1)
  1447. - novice_skills;
  1448. pc_setglobalreg (sd, "jobchange_level_3rd", sd->change_level_3rd);
  1449. }
  1450. if (skill_point < novice_skills + (sd->change_level_2nd - 1) + (sd->change_level_3rd - 1))
  1451. c &= MAPID_UPPERMASK;
  1452. }
  1453. }
  1454. // restore non-limiting flags
  1455. c |= sd->class_&(JOBL_UPPER|JOBL_BABY);
  1456. return c;
  1457. }
  1458. /*==========================================
  1459. * Updates the weight status
  1460. *------------------------------------------
  1461. * 1: overweight 50%
  1462. * 2: overweight 90%
  1463. * It's assumed that SC_WEIGHT50 and SC_WEIGHT90 are only started/stopped here.
  1464. */
  1465. int pc_updateweightstatus(struct map_session_data *sd)
  1466. {
  1467. int old_overweight;
  1468. int new_overweight;
  1469. nullpo_retr(1, sd);
  1470. old_overweight = (sd->sc.data[SC_WEIGHT90]) ? 2 : (sd->sc.data[SC_WEIGHT50]) ? 1 : 0;
  1471. new_overweight = (pc_is90overweight(sd)) ? 2 : (pc_is50overweight(sd)) ? 1 : 0;
  1472. if( old_overweight == new_overweight )
  1473. return 0; // no change
  1474. // stop old status change
  1475. if( old_overweight == 1 )
  1476. status_change_end(&sd->bl, SC_WEIGHT50, INVALID_TIMER);
  1477. else if( old_overweight == 2 )
  1478. status_change_end(&sd->bl, SC_WEIGHT90, INVALID_TIMER);
  1479. // start new status change
  1480. if( new_overweight == 1 )
  1481. sc_start(&sd->bl,&sd->bl, SC_WEIGHT50, 100, 0, 0);
  1482. else if( new_overweight == 2 )
  1483. sc_start(&sd->bl,&sd->bl, SC_WEIGHT90, 100, 0, 0);
  1484. // update overweight status
  1485. sd->regen.state.overweight = new_overweight;
  1486. return 0;
  1487. }
  1488. int pc_disguise(struct map_session_data *sd, int class_)
  1489. {
  1490. if (!class_ && !sd->disguise)
  1491. return 0;
  1492. if (class_ && sd->disguise == class_)
  1493. return 0;
  1494. if(sd->sc.option&OPTION_INVISIBLE)
  1495. { //Character is invisible. Stealth class-change. [Skotlex]
  1496. sd->disguise = class_; //viewdata is set on uncloaking.
  1497. return 2;
  1498. }
  1499. if (sd->bl.prev != NULL) {
  1500. pc_stop_walking(sd, 0);
  1501. clif_clearunit_area(&sd->bl, CLR_OUTSIGHT);
  1502. }
  1503. if (!class_) {
  1504. sd->disguise = 0;
  1505. class_ = sd->status.class_;
  1506. } else
  1507. sd->disguise=class_;
  1508. status_set_viewdata(&sd->bl, class_);
  1509. clif_changeoption(&sd->bl);
  1510. if (sd->bl.prev != NULL) {
  1511. clif_spawn(&sd->bl);
  1512. if (class_ == sd->status.class_ && pc_iscarton(sd))
  1513. { //It seems the cart info is lost on undisguise.
  1514. clif_cartlist(sd);
  1515. clif_updatestatus(sd,SP_CARTINFO);
  1516. }
  1517. if (sd->chatID) {
  1518. struct chat_data* cd;
  1519. nullpo_retr(1, sd);
  1520. cd = (struct chat_data*)map_id2bl(sd->chatID);
  1521. if( cd != NULL || (struct block_list*)sd == cd->owner )
  1522. clif_dispchat(cd,0);
  1523. }
  1524. }
  1525. return 1;
  1526. }
  1527. static int pc_bonus_autospell(struct s_autospell *spell, int max, short id, short lv, short rate, short flag, short card_id)
  1528. {
  1529. int i;
  1530. if( !rate )
  1531. return 0;
  1532. for( i = 0; i < max && spell[i].id; i++ )
  1533. {
  1534. if( (spell[i].card_id == card_id || spell[i].rate < 0 || rate < 0) && spell[i].id == id && spell[i].lv == lv )
  1535. {
  1536. if( !battle_config.autospell_stacking && spell[i].rate > 0 && rate > 0 )
  1537. return 0;
  1538. rate += spell[i].rate;
  1539. break;
  1540. }
  1541. }
  1542. if (i == max) {
  1543. ShowWarning("pc_bonus: Reached max (%d) number of autospells per character!\n", max);
  1544. return 0;
  1545. }
  1546. spell[i].id = id;
  1547. spell[i].lv = lv;
  1548. spell[i].rate = rate;
  1549. //Auto-update flag value.
  1550. if (!(flag&BF_RANGEMASK)) flag|=BF_SHORT|BF_LONG; //No range defined? Use both.
  1551. if (!(flag&BF_WEAPONMASK)) flag|=BF_WEAPON; //No attack type defined? Use weapon.
  1552. if (!(flag&BF_SKILLMASK)) {
  1553. if (flag&(BF_MAGIC|BF_MISC)) flag|=BF_SKILL; //These two would never trigger without BF_SKILL
  1554. if (flag&BF_WEAPON) flag|=BF_NORMAL; //By default autospells should only trigger on normal weapon attacks.
  1555. }
  1556. spell[i].flag|= flag;
  1557. spell[i].card_id = card_id;
  1558. return 1;
  1559. }
  1560. static int pc_bonus_autospell_onskill(struct s_autospell *spell, int max, short src_skill, short id, short lv, short rate, short card_id)
  1561. {
  1562. int i;
  1563. if( !rate )
  1564. return 0;
  1565. for( i = 0; i < max && spell[i].id; i++ )
  1566. {
  1567. ; // each autospell works independently
  1568. }
  1569. if( i == max )
  1570. {
  1571. ShowWarning("pc_bonus: Reached max (%d) number of autospells per character!\n", max);
  1572. return 0;
  1573. }
  1574. spell[i].flag = src_skill;
  1575. spell[i].id = id;
  1576. spell[i].lv = lv;
  1577. spell[i].rate = rate;
  1578. spell[i].card_id = card_id;
  1579. return 1;
  1580. }
  1581. static int pc_bonus_addeff(struct s_addeffect* effect, int max, enum sc_type id, short rate, short arrow_rate, unsigned char flag)
  1582. {
  1583. int i;
  1584. if (!(flag&(ATF_SHORT|ATF_LONG)))
  1585. flag|=ATF_SHORT|ATF_LONG; //Default range: both
  1586. if (!(flag&(ATF_TARGET|ATF_SELF)))
  1587. flag|=ATF_TARGET; //Default target: enemy.
  1588. if (!(flag&(ATF_WEAPON|ATF_MAGIC|ATF_MISC)))
  1589. flag|=ATF_WEAPON; //Default type: weapon.
  1590. for (i = 0; i < max && effect[i].flag; i++) {
  1591. if (effect[i].id == id && effect[i].flag == flag)
  1592. {
  1593. effect[i].rate += rate;
  1594. effect[i].arrow_rate += arrow_rate;
  1595. return 1;
  1596. }
  1597. }
  1598. if (i == max) {
  1599. ShowWarning("pc_bonus: Reached max (%d) number of add effects per character!\n", max);
  1600. return 0;
  1601. }
  1602. effect[i].id = id;
  1603. effect[i].rate = rate;
  1604. effect[i].arrow_rate = arrow_rate;
  1605. effect[i].flag = flag;
  1606. return 1;
  1607. }
  1608. static int pc_bonus_addeff_onskill(struct s_addeffectonskill* effect, int max, enum sc_type id, short rate, short skill, unsigned char target)
  1609. {
  1610. int i;
  1611. for( i = 0; i < max && effect[i].skill; i++ )
  1612. {
  1613. if( effect[i].id == id && effect[i].skill == skill && effect[i].target == target )
  1614. {
  1615. effect[i].rate += rate;
  1616. return 1;
  1617. }
  1618. }
  1619. if( i == max ) {
  1620. ShowWarning("pc_bonus: Reached max (%d) number of add effects on skill per character!\n", max);
  1621. return 0;
  1622. }
  1623. effect[i].id = id;
  1624. effect[i].rate = rate;
  1625. effect[i].skill = skill;
  1626. effect[i].target = target;
  1627. return 1;
  1628. }
  1629. /** Adjust/add drop rate modifier for player
  1630. * @param drop: Player's sd->add_drop (struct s_add_drop)
  1631. * @param max: Max bonus can be received
  1632. * @param nameid: item id that will be dropped
  1633. * @param group: group id
  1634. * @param class_: target class
  1635. * @param race: target race. if < 0, means monster_id
  1636. * @param rate: rate value: 1 ~ 10000. If < 0, it will be multiplied with mob level/10
  1637. */
  1638. static void pc_bonus_item_drop(struct s_add_drop *drop, const short max, uint16 nameid, uint16 group, int class_, int race, int rate)
  1639. {
  1640. uint8 i;
  1641. if (nameid && !group && !itemdb_exists(nameid)) {
  1642. ShowWarning("pc_bonus_item_drop: Invalid item id\n",nameid);
  1643. return;
  1644. }
  1645. //Apply config rate adjustment settings.
  1646. if (rate >= 0) { //Absolute drop.
  1647. if (battle_config.item_rate_adddrop != 100)
  1648. rate = rate*battle_config.item_rate_adddrop/100;
  1649. if (rate < battle_config.item_drop_adddrop_min)
  1650. rate = battle_config.item_drop_adddrop_min;
  1651. else if (rate > battle_config.item_drop_adddrop_max)
  1652. rate = battle_config.item_drop_adddrop_max;
  1653. } else { //Relative drop, max/min limits are applied at drop time.
  1654. if (battle_config.item_rate_adddrop != 100)
  1655. rate = rate*battle_config.item_rate_adddrop/100;
  1656. if (rate > -1)
  1657. rate = -1;
  1658. }
  1659. //Find match entry, and adjust the rate only
  1660. for (i = 0; i < max; i++) {
  1661. if (!&drop[i] || (!drop[i].nameid && !drop[i].group))
  1662. continue;
  1663. if (drop[i].nameid == nameid &&
  1664. drop[i].group == group &&
  1665. drop[i].race == race &&
  1666. drop[i].class_ == class_
  1667. )
  1668. {
  1669. //Adjust the rate if it has same classification
  1670. if ((rate < 0 && drop[i].rate < 0) ||
  1671. (rate > 0 && drop[i].rate > 0))
  1672. {
  1673. drop[i].rate += rate;
  1674. return;
  1675. }
  1676. }
  1677. }
  1678. ARR_FIND(0,max,i,!&drop[i] || (drop[i].nameid == 0 && drop[i].group == 0));
  1679. if (i >= max) {
  1680. ShowWarning("pc_bonus_item_drop: Reached max (%d) number of added drops per character! (nameid:%d group:%d class_:%d race:%d rate:%d)\n",max,nameid,group,class_,race,rate);
  1681. return;
  1682. }
  1683. drop[i].nameid = nameid;
  1684. drop[i].group = group;
  1685. drop[i].race = race;
  1686. drop[i].class_ = class_;
  1687. drop[i].rate = rate;
  1688. }
  1689. bool 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)
  1690. {
  1691. int i;
  1692. ARR_FIND(0, max, i, bonus[i].rate == 0);
  1693. if( i == max )
  1694. {
  1695. ShowWarning("pc_addautobonus: Reached max (%d) number of autobonus per character!\n", max);
  1696. return false;
  1697. }
  1698. if( !onskill )
  1699. {
  1700. if( !(flag&BF_RANGEMASK) )
  1701. flag|=BF_SHORT|BF_LONG; //No range defined? Use both.
  1702. if( !(flag&BF_WEAPONMASK) )
  1703. flag|=BF_WEAPON; //No attack type defined? Use weapon.
  1704. if( !(flag&BF_SKILLMASK) )
  1705. {
  1706. if( flag&(BF_MAGIC|BF_MISC) )
  1707. flag|=BF_SKILL; //These two would never trigger without BF_SKILL
  1708. if( flag&BF_WEAPON )
  1709. flag|=BF_NORMAL|BF_SKILL;
  1710. }
  1711. }
  1712. bonus[i].rate = rate;
  1713. bonus[i].duration = dur;
  1714. bonus[i].active = INVALID_TIMER;
  1715. bonus[i].atk_type = flag;
  1716. bonus[i].pos = pos;
  1717. bonus[i].bonus_script = aStrdup(script);
  1718. bonus[i].other_script = other_script?aStrdup(other_script):NULL;
  1719. return true;
  1720. }
  1721. void pc_delautobonus(struct map_session_data* sd, struct s_autobonus *autobonus,char max,bool restore)
  1722. {
  1723. int i;
  1724. if (!sd)
  1725. return;
  1726. for( i = 0; i < max; i++ )
  1727. {
  1728. if( autobonus[i].active != INVALID_TIMER )
  1729. {
  1730. if( restore && sd->state.autobonus&autobonus[i].pos )
  1731. {
  1732. if( autobonus[i].bonus_script )
  1733. {
  1734. int j;
  1735. ARR_FIND( 0, EQI_MAX, j, sd->equip_index[j] >= 0 && sd->status.inventory[sd->equip_index[j]].equip == autobonus[i].pos );
  1736. if( j < EQI_MAX )
  1737. script_run_autobonus(autobonus[i].bonus_script,sd->bl.id,sd->equip_index[j]);
  1738. }
  1739. continue;
  1740. }
  1741. else
  1742. { // Logout / Unequipped an item with an activated bonus
  1743. delete_timer(autobonus[i].active,pc_endautobonus);
  1744. autobonus[i].active = INVALID_TIMER;
  1745. }
  1746. }
  1747. if( autobonus[i].bonus_script ) aFree(autobonus[i].bonus_script);
  1748. if( autobonus[i].other_script ) aFree(autobonus[i].other_script);
  1749. autobonus[i].bonus_script = autobonus[i].other_script = NULL;
  1750. autobonus[i].rate = autobonus[i].atk_type = autobonus[i].duration = autobonus[i].pos = 0;
  1751. autobonus[i].active = INVALID_TIMER;
  1752. }
  1753. }
  1754. void pc_exeautobonus(struct map_session_data *sd,struct s_autobonus *autobonus)
  1755. {
  1756. if (!sd || !autobonus)
  1757. return;
  1758. if( autobonus->other_script )
  1759. {
  1760. int j;
  1761. ARR_FIND( 0, EQI_MAX, j, sd->equip_index[j] >= 0 && sd->status.inventory[sd->equip_index[j]].equip == autobonus->pos );
  1762. if( j < EQI_MAX )
  1763. script_run_autobonus(autobonus->other_script,sd->bl.id,sd->equip_index[j]);
  1764. }
  1765. autobonus->active = add_timer(gettick()+autobonus->duration, pc_endautobonus, sd->bl.id, (intptr_t)autobonus);
  1766. sd->state.autobonus |= autobonus->pos;
  1767. status_calc_pc(sd,0);
  1768. }
  1769. int pc_endautobonus(int tid, unsigned int tick, int id, intptr_t data)
  1770. {
  1771. struct map_session_data *sd = map_id2sd(id);
  1772. struct s_autobonus *autobonus = (struct s_autobonus *)data;
  1773. nullpo_ret(sd);
  1774. nullpo_ret(autobonus);
  1775. autobonus->active = INVALID_TIMER;
  1776. sd->state.autobonus &= ~autobonus->pos;
  1777. status_calc_pc(sd,0);
  1778. return 0;
  1779. }
  1780. int pc_bonus_addele(struct map_session_data* sd, unsigned char ele, short rate, short flag)
  1781. {
  1782. int i;
  1783. struct weapon_data* wd;
  1784. wd = (sd->state.lr_flag ? &sd->left_weapon : &sd->right_weapon);
  1785. ARR_FIND(0, MAX_PC_BONUS, i, wd->addele2[i].rate == 0);
  1786. if (i == MAX_PC_BONUS)
  1787. {
  1788. ShowWarning("pc_addele: Reached max (%d) possible bonuses for this player.\n", MAX_PC_BONUS);
  1789. return 0;
  1790. }
  1791. if (!(flag&BF_RANGEMASK))
  1792. flag |= BF_SHORT|BF_LONG;
  1793. if (!(flag&BF_WEAPONMASK))
  1794. flag |= BF_WEAPON;
  1795. if (!(flag&BF_SKILLMASK))
  1796. {
  1797. if (flag&(BF_MAGIC|BF_MISC))
  1798. flag |= BF_SKILL;
  1799. if (flag&BF_WEAPON)
  1800. flag |= BF_NORMAL|BF_SKILL;
  1801. }
  1802. wd->addele2[i].ele = ele;
  1803. wd->addele2[i].rate = rate;
  1804. wd->addele2[i].flag = flag;
  1805. return 0;
  1806. }
  1807. int pc_bonus_subele(struct map_session_data* sd, unsigned char ele, short rate, short flag)
  1808. {
  1809. int i;
  1810. ARR_FIND(0, MAX_PC_BONUS, i, sd->subele2[i].rate == 0);
  1811. if (i == MAX_PC_BONUS)
  1812. {
  1813. ShowWarning("pc_subele: Reached max (%d) possible bonuses for this player.\n", MAX_PC_BONUS);
  1814. return 0;
  1815. }
  1816. if (!(flag&BF_RANGEMASK))
  1817. flag |= BF_SHORT|BF_LONG;
  1818. if (!(flag&BF_WEAPONMASK))
  1819. flag |= BF_WEAPON;
  1820. if (!(flag&BF_SKILLMASK))
  1821. {
  1822. if (flag&(BF_MAGIC|BF_MISC))
  1823. flag |= BF_SKILL;
  1824. if (flag&BF_WEAPON)
  1825. flag |= BF_NORMAL|BF_SKILL;
  1826. }
  1827. sd->subele2[i].ele = ele;
  1828. sd->subele2[i].rate = rate;
  1829. sd->subele2[i].flag = flag;
  1830. return 0;
  1831. }
  1832. /*==========================================
  1833. * Add a bonus(type) to player sd
  1834. *------------------------------------------*/
  1835. int pc_bonus(struct map_session_data *sd,int type,int val)
  1836. {
  1837. struct status_data *status;
  1838. int bonus;
  1839. nullpo_ret(sd);
  1840. status = &sd->base_status;
  1841. switch(type){
  1842. case SP_STR:
  1843. case SP_AGI:
  1844. case SP_VIT:
  1845. case SP_INT:
  1846. case SP_DEX:
  1847. case SP_LUK:
  1848. if(sd->state.lr_flag != 2)
  1849. sd->param_bonus[type-SP_STR]+=val;
  1850. break;
  1851. case SP_ATK1:
  1852. if(!sd->state.lr_flag) {
  1853. bonus = status->rhw.atk + val;
  1854. status->rhw.atk = cap_value(bonus, 0, USHRT_MAX);
  1855. }
  1856. else if(sd->state.lr_flag == 1) {
  1857. bonus = status->lhw.atk + val;
  1858. status->lhw.atk = cap_value(bonus, 0, USHRT_MAX);
  1859. }
  1860. break;
  1861. case SP_ATK2:
  1862. if(!sd->state.lr_flag) {
  1863. bonus = status->rhw.atk2 + val;
  1864. status->rhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
  1865. }
  1866. else if(sd->state.lr_flag == 1) {
  1867. bonus = status->lhw.atk2 + val;
  1868. status->lhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
  1869. }
  1870. break;
  1871. case SP_BASE_ATK:
  1872. if(sd->state.lr_flag != 2) {
  1873. #ifdef RENEWAL
  1874. sd->bonus.eatk += val;
  1875. #else
  1876. bonus = status->batk + val;
  1877. status->batk = cap_value(bonus, 0, USHRT_MAX);
  1878. #endif
  1879. }
  1880. break;
  1881. case SP_DEF1:
  1882. if(sd->state.lr_flag != 2) {
  1883. bonus = status->def + val;
  1884. #ifdef RENEWAL
  1885. status->def = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1886. #else
  1887. status->def = cap_value(bonus, CHAR_MIN, CHAR_MAX);
  1888. #endif
  1889. }
  1890. break;
  1891. case SP_DEF2:
  1892. if(sd->state.lr_flag != 2) {
  1893. bonus = status->def2 + val;
  1894. status->def2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1895. }
  1896. break;
  1897. case SP_MDEF1:
  1898. if(sd->state.lr_flag != 2) {
  1899. bonus = status->mdef + val;
  1900. #ifdef RENEWAL
  1901. status->mdef = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1902. #else
  1903. status->mdef = cap_value(bonus, CHAR_MIN, CHAR_MAX);
  1904. #endif
  1905. if( sd->state.lr_flag == 3 ) {//Shield, used for royal guard
  1906. sd->bonus.shieldmdef += bonus;
  1907. }
  1908. }
  1909. break;
  1910. case SP_MDEF2:
  1911. if(sd->state.lr_flag != 2) {
  1912. bonus = status->mdef2 + val;
  1913. status->mdef2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1914. }
  1915. break;
  1916. case SP_HIT:
  1917. if(sd->state.lr_flag != 2) {
  1918. bonus = status->hit + val;
  1919. status->hit = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1920. } else
  1921. sd->bonus.arrow_hit+=val;
  1922. break;
  1923. case SP_FLEE1:
  1924. if(sd->state.lr_flag != 2) {
  1925. bonus = status->flee + val;
  1926. status->flee = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1927. }
  1928. break;
  1929. case SP_FLEE2:
  1930. if(sd->state.lr_flag != 2) {
  1931. bonus = status->flee2 + val*10;
  1932. status->flee2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1933. }
  1934. break;
  1935. case SP_CRITICAL:
  1936. if(sd->state.lr_flag != 2) {
  1937. bonus = status->cri + val*10;
  1938. status->cri = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  1939. } else
  1940. sd->bonus.arrow_cri += val*10;
  1941. break;
  1942. case SP_ATKELE:
  1943. if(val > ELE_ALL) {
  1944. ShowError("pc_bonus: SP_ATKELE: Invalid element %d\n", val);
  1945. break;
  1946. }
  1947. switch (sd->state.lr_flag)
  1948. {
  1949. case 2:
  1950. switch (sd->status.weapon) {
  1951. case W_BOW:
  1952. case W_REVOLVER:
  1953. case W_RIFLE:
  1954. case W_GATLING:
  1955. case W_SHOTGUN:
  1956. case W_GRENADE:
  1957. //Become weapon element.
  1958. status->rhw.ele=val;
  1959. break;
  1960. default: //Become arrow element.
  1961. sd->bonus.arrow_ele=val;
  1962. break;
  1963. }
  1964. break;
  1965. case 1:
  1966. status->lhw.ele=val;
  1967. break;
  1968. default:
  1969. status->rhw.ele=val;
  1970. break;
  1971. }
  1972. break;
  1973. case SP_DEFELE:
  1974. if(val > ELE_ALL) {
  1975. ShowError("pc_bonus: SP_DEFELE: Invalid element %d\n", val);
  1976. break;
  1977. }
  1978. if(sd->state.lr_flag != 2)
  1979. status->def_ele=val;
  1980. break;
  1981. case SP_MAXHP:
  1982. if(sd->state.lr_flag == 2)
  1983. break;
  1984. sd->bonus.hp += val;
  1985. break;
  1986. case SP_MAXSP:
  1987. if(sd->state.lr_flag == 2)
  1988. break;
  1989. sd->bonus.sp += val;
  1990. break;
  1991. #ifndef RENEWAL_CAST
  1992. case SP_VARCASTRATE:
  1993. #endif
  1994. case SP_CASTRATE:
  1995. if(sd->state.lr_flag != 2)
  1996. sd->castrate+=val;
  1997. break;
  1998. case SP_MAXHPRATE:
  1999. if(sd->state.lr_flag != 2)
  2000. sd->hprate+=val;
  2001. break;
  2002. case SP_MAXSPRATE:
  2003. if(sd->state.lr_flag != 2)
  2004. sd->sprate+=val;
  2005. break;
  2006. case SP_SPRATE:
  2007. if(sd->state.lr_flag != 2)
  2008. sd->dsprate+=val;
  2009. break;
  2010. case SP_ATTACKRANGE:
  2011. switch (sd->state.lr_flag) {
  2012. case 2:
  2013. switch (sd->status.weapon) {
  2014. case W_BOW:
  2015. case W_REVOLVER:
  2016. case W_RIFLE:
  2017. case W_GATLING:
  2018. case W_SHOTGUN:
  2019. case W_GRENADE:
  2020. status->rhw.range += val;
  2021. }
  2022. break;
  2023. case 1:
  2024. status->lhw.range += val;
  2025. break;
  2026. default:
  2027. status->rhw.range += val;
  2028. break;
  2029. }
  2030. break;
  2031. case SP_SPEED_RATE: //Non stackable increase
  2032. if(sd->state.lr_flag != 2)
  2033. sd->bonus.speed_rate = min(sd->bonus.speed_rate, -val);
  2034. break;
  2035. case SP_SPEED_ADDRATE: //Stackable increase
  2036. if(sd->state.lr_flag != 2)
  2037. sd->bonus.speed_add_rate -= val;
  2038. break;
  2039. case SP_ASPD: //Raw increase
  2040. if(sd->state.lr_flag != 2)
  2041. sd->bonus.aspd_add -= 10*val;
  2042. break;
  2043. case SP_ASPD_RATE: //Stackable increase - Made it linear as per rodatazone
  2044. if(sd->state.lr_flag != 2)
  2045. #ifndef RENEWAL_ASPD
  2046. status->aspd_rate -= 10*val;
  2047. #else
  2048. status->aspd_rate2 += val;
  2049. #endif
  2050. break;
  2051. case SP_HP_RECOV_RATE:
  2052. if(sd->state.lr_flag != 2)
  2053. sd->hprecov_rate += val;
  2054. break;
  2055. case SP_SP_RECOV_RATE:
  2056. if(sd->state.lr_flag != 2)
  2057. sd->sprecov_rate += val;
  2058. break;
  2059. case SP_CRITICAL_DEF:
  2060. if(sd->state.lr_flag != 2)
  2061. sd->bonus.critical_def += val;
  2062. break;
  2063. case SP_NEAR_ATK_DEF:
  2064. if(sd->state.lr_flag != 2)
  2065. sd->bonus.near_attack_def_rate += val;
  2066. break;
  2067. case SP_LONG_ATK_DEF:
  2068. if(sd->state.lr_flag != 2)
  2069. sd->bonus.long_attack_def_rate += val;
  2070. break;
  2071. case SP_DOUBLE_RATE:
  2072. if(sd->state.lr_flag == 0 && sd->bonus.double_rate < val)
  2073. sd->bonus.double_rate = val;
  2074. break;
  2075. case SP_DOUBLE_ADD_RATE:
  2076. if(sd->state.lr_flag == 0)
  2077. sd->bonus.double_add_rate += val;
  2078. break;
  2079. case SP_MATK_RATE:
  2080. if(sd->state.lr_flag != 2)
  2081. sd->matk_rate += val;
  2082. break;
  2083. case SP_IGNORE_DEF_ELE:
  2084. if(val > ELE_ALL) {
  2085. ShowError("pc_bonus: SP_IGNORE_DEF_ELE: Invalid element %d\n", val);
  2086. break;
  2087. }
  2088. if(!sd->state.lr_flag)
  2089. sd->right_weapon.ignore_def_ele |= 1<<val;
  2090. else if(sd->state.lr_flag == 1)
  2091. sd->left_weapon.ignore_def_ele |= 1<<val;
  2092. break;
  2093. case SP_IGNORE_DEF_RACE:
  2094. if(!sd->state.lr_flag)
  2095. sd->right_weapon.ignore_def_race |= 1<<val;
  2096. else if(sd->state.lr_flag == 1)
  2097. sd->left_weapon.ignore_def_race |= 1<<val;
  2098. break;
  2099. case SP_IGNORE_DEF_CLASS:
  2100. if(!sd->state.lr_flag)
  2101. sd->right_weapon.ignore_def_class |= 1<<val;
  2102. else if(sd->state.lr_flag == 1)
  2103. sd->left_weapon.ignore_def_class |= 1<<val;
  2104. break;
  2105. case SP_ATK_RATE:
  2106. if(sd->state.lr_flag != 2)
  2107. sd->bonus.atk_rate += val;
  2108. break;
  2109. case SP_MAGIC_ATK_DEF:
  2110. if(sd->state.lr_flag != 2)
  2111. sd->bonus.magic_def_rate += val;
  2112. break;
  2113. case SP_MISC_ATK_DEF:
  2114. if(sd->state.lr_flag != 2)
  2115. sd->bonus.misc_def_rate += val;
  2116. break;
  2117. case SP_IGNORE_MDEF_ELE:
  2118. if(val > ELE_ALL) {
  2119. ShowError("pc_bonus: SP_IGNORE_MDEF_ELE: Invalid element %d\n", val);
  2120. break;
  2121. }
  2122. if(sd->state.lr_flag != 2)
  2123. sd->bonus.ignore_mdef_ele |= 1<<val;
  2124. break;
  2125. case SP_IGNORE_MDEF_RACE:
  2126. if(sd->state.lr_flag != 2)
  2127. sd->bonus.ignore_mdef_race |= 1<<val;
  2128. break;
  2129. case SP_PERFECT_HIT_RATE:
  2130. if(sd->state.lr_flag != 2 && sd->bonus.perfect_hit < val)
  2131. sd->bonus.perfect_hit = val;
  2132. break;
  2133. case SP_PERFECT_HIT_ADD_RATE:
  2134. if(sd->state.lr_flag != 2)
  2135. sd->bonus.perfect_hit_add += val;
  2136. break;
  2137. case SP_CRITICAL_RATE:
  2138. if(sd->state.lr_flag != 2)
  2139. sd->critical_rate+=val;
  2140. break;
  2141. case SP_DEF_RATIO_ATK_ELE:
  2142. if(val > ELE_ALL) {
  2143. ShowError("pc_bonus: SP_DEF_RATIO_ATK_ELE: Invalid element %d\n", val);
  2144. break;
  2145. }
  2146. if(!sd->state.lr_flag)
  2147. sd->right_weapon.def_ratio_atk_ele |= 1<<val;
  2148. else if(sd->state.lr_flag == 1)
  2149. sd->left_weapon.def_ratio_atk_ele |= 1<<val;
  2150. break;
  2151. case SP_DEF_RATIO_ATK_RACE:
  2152. if(val > RC_ALL) {
  2153. ShowError("pc_bonus: SP_DEF_RATIO_ATK_RACE: Invalid race %d\n", val);
  2154. break;
  2155. }
  2156. if(!sd->state.lr_flag)
  2157. sd->right_weapon.def_ratio_atk_race |= 1<<val;
  2158. else if(sd->state.lr_flag == 1)
  2159. sd->left_weapon.def_ratio_atk_race |= 1<<val;
  2160. break;
  2161. case SP_DEF_RATIO_ATK_CLASS:
  2162. if(val > CLASS_ALL) {
  2163. ShowError("pc_bonus: SP_DEF_RATIO_ATK_CLASS: Invalid class %d\n", val);
  2164. break;
  2165. }
  2166. if(!sd->state.lr_flag)
  2167. sd->right_weapon.def_ratio_atk_class |= 1<<val;
  2168. else if(sd->state.lr_flag == 1)
  2169. sd->left_weapon.def_ratio_atk_class |= 1<<val;
  2170. break;
  2171. case SP_HIT_RATE:
  2172. if(sd->state.lr_flag != 2)
  2173. sd->hit_rate += val;
  2174. break;
  2175. case SP_FLEE_RATE:
  2176. if(sd->state.lr_flag != 2)
  2177. sd->flee_rate += val;
  2178. break;
  2179. case SP_FLEE2_RATE:
  2180. if(sd->state.lr_flag != 2)
  2181. sd->flee2_rate += val;
  2182. break;
  2183. case SP_DEF_RATE:
  2184. if(sd->state.lr_flag != 2)
  2185. sd->def_rate += val;
  2186. break;
  2187. case SP_DEF2_RATE:
  2188. if(sd->state.lr_flag != 2)
  2189. sd->def2_rate += val;
  2190. break;
  2191. case SP_MDEF_RATE:
  2192. if(sd->state.lr_flag != 2)
  2193. sd->mdef_rate += val;
  2194. break;
  2195. case SP_MDEF2_RATE:
  2196. if(sd->state.lr_flag != 2)
  2197. sd->mdef2_rate += val;
  2198. break;
  2199. case SP_RESTART_FULL_RECOVER:
  2200. if(sd->state.lr_flag != 2)
  2201. sd->special_state.restart_full_recover = 1;
  2202. break;
  2203. case SP_NO_CASTCANCEL:
  2204. if(sd->state.lr_flag != 2)
  2205. sd->special_state.no_castcancel = 1;
  2206. break;
  2207. case SP_NO_CASTCANCEL2:
  2208. if(sd->state.lr_flag != 2)
  2209. sd->special_state.no_castcancel2 = 1;
  2210. break;
  2211. case SP_NO_SIZEFIX:
  2212. if(sd->state.lr_flag != 2)
  2213. sd->special_state.no_sizefix = 1;
  2214. break;
  2215. case SP_NO_MAGIC_DAMAGE:
  2216. if(sd->state.lr_flag == 2)
  2217. break;
  2218. val+= sd->special_state.no_magic_damage;
  2219. sd->special_state.no_magic_damage = cap_value(val,0,100);
  2220. break;
  2221. case SP_NO_WEAPON_DAMAGE:
  2222. if(sd->state.lr_flag == 2)
  2223. break;
  2224. val+= sd->special_state.no_weapon_damage;
  2225. sd->special_state.no_weapon_damage = cap_value(val,0,100);
  2226. break;
  2227. case SP_NO_MISC_DAMAGE:
  2228. if(sd->state.lr_flag == 2)
  2229. break;
  2230. val+= sd->special_state.no_misc_damage;
  2231. sd->special_state.no_misc_damage = cap_value(val,0,100);
  2232. break;
  2233. case SP_NO_GEMSTONE:
  2234. if(sd->state.lr_flag != 2 && sd->special_state.no_gemstone != 2)
  2235. sd->special_state.no_gemstone = 1;
  2236. break;
  2237. case SP_INTRAVISION: // Maya Purple Card effect allowing to see Hiding/Cloaking people [DracoRPG]
  2238. if(sd->state.lr_flag != 2) {
  2239. sd->special_state.intravision = 1;
  2240. clif_status_load(&sd->bl, SI_INTRAVISION, 1);
  2241. }
  2242. break;
  2243. case SP_NO_KNOCKBACK:
  2244. if(sd->state.lr_flag != 2)
  2245. sd->special_state.no_knockback = 1;
  2246. break;
  2247. case SP_SPLASH_RANGE:
  2248. if(sd->bonus.splash_range < val)
  2249. sd->bonus.splash_range = val;
  2250. break;
  2251. case SP_SPLASH_ADD_RANGE:
  2252. sd->bonus.splash_add_range += val;
  2253. break;
  2254. case SP_SHORT_WEAPON_DAMAGE_RETURN:
  2255. if(sd->state.lr_flag != 2)
  2256. sd->bonus.short_weapon_damage_return += val;
  2257. break;
  2258. case SP_LONG_WEAPON_DAMAGE_RETURN:
  2259. if(sd->state.lr_flag != 2)
  2260. sd->bonus.long_weapon_damage_return += val;
  2261. break;
  2262. case SP_MAGIC_DAMAGE_RETURN: //AppleGirl Was Here
  2263. if(sd->state.lr_flag != 2)
  2264. sd->bonus.magic_damage_return += val;
  2265. break;
  2266. case SP_ALL_STATS: // [Valaris]
  2267. if(sd->state.lr_flag!=2) {
  2268. sd->param_bonus[SP_STR-SP_STR]+=val;
  2269. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2270. sd->param_bonus[SP_VIT-SP_STR]+=val;
  2271. sd->param_bonus[SP_INT-SP_STR]+=val;
  2272. sd->param_bonus[SP_DEX-SP_STR]+=val;
  2273. sd->param_bonus[SP_LUK-SP_STR]+=val;
  2274. }
  2275. break;
  2276. case SP_AGI_VIT: // [Valaris]
  2277. if(sd->state.lr_flag!=2) {
  2278. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2279. sd->param_bonus[SP_VIT-SP_STR]+=val;
  2280. }
  2281. break;
  2282. case SP_AGI_DEX_STR: // [Valaris]
  2283. if(sd->state.lr_flag!=2) {
  2284. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2285. sd->param_bonus[SP_DEX-SP_STR]+=val;
  2286. sd->param_bonus[SP_STR-SP_STR]+=val;
  2287. }
  2288. break;
  2289. case SP_PERFECT_HIDE: // [Valaris]
  2290. if(sd->state.lr_flag!=2)
  2291. sd->special_state.perfect_hiding=1;
  2292. break;
  2293. case SP_UNBREAKABLE:
  2294. if(sd->state.lr_flag!=2)
  2295. sd->bonus.unbreakable += val;
  2296. break;
  2297. case SP_UNBREAKABLE_WEAPON:
  2298. if(sd->state.lr_flag != 2)
  2299. sd->bonus.unbreakable_equip |= EQP_WEAPON;
  2300. break;
  2301. case SP_UNBREAKABLE_ARMOR:
  2302. if(sd->state.lr_flag != 2)
  2303. sd->bonus.unbreakable_equip |= EQP_ARMOR;
  2304. break;
  2305. case SP_UNBREAKABLE_HELM:
  2306. if(sd->state.lr_flag != 2)
  2307. sd->bonus.unbreakable_equip |= EQP_HELM;
  2308. break;
  2309. case SP_UNBREAKABLE_SHIELD:
  2310. if(sd->state.lr_flag != 2)
  2311. sd->bonus.unbreakable_equip |= EQP_SHIELD;
  2312. break;
  2313. case SP_UNBREAKABLE_GARMENT:
  2314. if(sd->state.lr_flag != 2)
  2315. sd->bonus.unbreakable_equip |= EQP_GARMENT;
  2316. break;
  2317. case SP_UNBREAKABLE_SHOES:
  2318. if(sd->state.lr_flag != 2)
  2319. sd->bonus.unbreakable_equip |= EQP_SHOES;
  2320. break;
  2321. case SP_CLASSCHANGE: // [Valaris]
  2322. if(sd->state.lr_flag !=2)
  2323. sd->bonus.classchange=val;
  2324. break;
  2325. case SP_LONG_ATK_RATE:
  2326. if(sd->state.lr_flag != 2) //[Lupus] it should stack, too. As any other cards rate bonuses
  2327. sd->bonus.long_attack_atk_rate+=val;
  2328. break;
  2329. case SP_BREAK_WEAPON_RATE:
  2330. if(sd->state.lr_flag != 2)
  2331. sd->bonus.break_weapon_rate+=val;
  2332. break;
  2333. case SP_BREAK_ARMOR_RATE:
  2334. if(sd->state.lr_flag != 2)
  2335. sd->bonus.break_armor_rate+=val;
  2336. break;
  2337. case SP_ADD_STEAL_RATE:
  2338. if(sd->state.lr_flag != 2)
  2339. sd->bonus.add_steal_rate+=val;
  2340. break;
  2341. case SP_DELAYRATE:
  2342. if(sd->state.lr_flag != 2)
  2343. sd->delayrate+=val;
  2344. break;
  2345. case SP_CRIT_ATK_RATE:
  2346. if(sd->state.lr_flag != 2)
  2347. sd->bonus.crit_atk_rate += val;
  2348. break;
  2349. case SP_NO_REGEN:
  2350. if(sd->state.lr_flag != 2)
  2351. sd->regen.state.block|=val;
  2352. break;
  2353. case SP_UNSTRIPABLE_WEAPON:
  2354. if(sd->state.lr_flag != 2)
  2355. sd->bonus.unstripable_equip |= EQP_WEAPON;
  2356. break;
  2357. case SP_UNSTRIPABLE:
  2358. case SP_UNSTRIPABLE_ARMOR:
  2359. if(sd->state.lr_flag != 2)
  2360. sd->bonus.unstripable_equip |= EQP_ARMOR;
  2361. break;
  2362. case SP_UNSTRIPABLE_HELM:
  2363. if(sd->state.lr_flag != 2)
  2364. sd->bonus.unstripable_equip |= EQP_HELM;
  2365. break;
  2366. case SP_UNSTRIPABLE_SHIELD:
  2367. if(sd->state.lr_flag != 2)
  2368. sd->bonus.unstripable_equip |= EQP_SHIELD;
  2369. break;
  2370. case SP_HP_DRAIN_VALUE:
  2371. if(!sd->state.lr_flag) {
  2372. sd->right_weapon.hp_drain_class[CLASS_NORMAL].value += val;
  2373. sd->right_weapon.hp_drain_class[CLASS_BOSS].value += val;
  2374. } else if(sd->state.lr_flag == 1) {
  2375. sd->left_weapon.hp_drain_class[CLASS_NORMAL].value += val;
  2376. sd->left_weapon.hp_drain_class[CLASS_BOSS].value += val;
  2377. }
  2378. break;
  2379. case SP_SP_DRAIN_VALUE:
  2380. if(!sd->state.lr_flag) {
  2381. sd->right_weapon.sp_drain_class[CLASS_NORMAL].value += val;
  2382. sd->right_weapon.sp_drain_class[CLASS_BOSS].value += val;
  2383. } else if(sd->state.lr_flag == 1) {
  2384. sd->left_weapon.sp_drain_class[CLASS_NORMAL].value += val;
  2385. sd->left_weapon.sp_drain_class[CLASS_BOSS].value += val;
  2386. }
  2387. break;
  2388. case SP_SP_GAIN_VALUE:
  2389. if(!sd->state.lr_flag)
  2390. sd->bonus.sp_gain_value += val;
  2391. break;
  2392. case SP_HP_GAIN_VALUE:
  2393. if(!sd->state.lr_flag)
  2394. sd->bonus.hp_gain_value += val;
  2395. break;
  2396. case SP_MAGIC_SP_GAIN_VALUE:
  2397. if(!sd->state.lr_flag)
  2398. sd->bonus.magic_sp_gain_value += val;
  2399. break;
  2400. case SP_MAGIC_HP_GAIN_VALUE:
  2401. if(!sd->state.lr_flag)
  2402. sd->bonus.magic_hp_gain_value += val;
  2403. break;
  2404. case SP_ADD_HEAL_RATE:
  2405. if(sd->state.lr_flag != 2)
  2406. sd->bonus.add_heal_rate += val;
  2407. break;
  2408. case SP_ADD_HEAL2_RATE:
  2409. if(sd->state.lr_flag != 2)
  2410. sd->bonus.add_heal2_rate += val;
  2411. break;
  2412. case SP_ADD_ITEM_HEAL_RATE:
  2413. if(sd->state.lr_flag != 2)
  2414. sd->bonus.itemhealrate2 += val;
  2415. break;
  2416. case SP_EMATK:
  2417. if(sd->state.lr_flag != 2)
  2418. sd->bonus.ematk += val;
  2419. break;
  2420. case SP_FIXCASTRATE:
  2421. if(sd->state.lr_flag != 2)
  2422. sd->bonus.fixcastrate -= val;
  2423. break;
  2424. case SP_ADD_FIXEDCAST:
  2425. if(sd->state.lr_flag != 2)
  2426. sd->bonus.add_fixcast += val;
  2427. break;
  2428. #ifdef RENEWAL_CAST
  2429. case SP_VARCASTRATE:
  2430. if(sd->state.lr_flag != 2)
  2431. sd->bonus.varcastrate -= val;
  2432. break;
  2433. case SP_ADD_VARIABLECAST:
  2434. if(sd->state.lr_flag != 2)
  2435. sd->bonus.add_varcast += val;
  2436. break;
  2437. #endif
  2438. case SP_ADDMAXWEIGHT:
  2439. if (sd->state.lr_flag != 2)
  2440. sd->max_weight += val;
  2441. break;
  2442. default:
  2443. ShowWarning("pc_bonus: unknown type %d %d !\n",type,val);
  2444. break;
  2445. }
  2446. return 0;
  2447. }
  2448. /*==========================================
  2449. * Player bonus (type) with args type2 and val, called trough bonus2 (npc)
  2450. *------------------------------------------*/
  2451. int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
  2452. {
  2453. int i;
  2454. nullpo_ret(sd);
  2455. switch(type){
  2456. case SP_ADDELE:
  2457. if(type2 > ELE_ALL) {
  2458. ShowError("pc_bonus2: SP_ADDELE: Invalid element %d\n", type2);
  2459. break;
  2460. }
  2461. if(!sd->state.lr_flag)
  2462. sd->right_weapon.addele[type2]+=val;
  2463. else if(sd->state.lr_flag == 1)
  2464. sd->left_weapon.addele[type2]+=val;
  2465. else if(sd->state.lr_flag == 2)
  2466. sd->arrow_addele[type2]+=val;
  2467. break;
  2468. case SP_ADDRACE:
  2469. if(!sd->state.lr_flag)
  2470. sd->right_weapon.addrace[type2]+=val;
  2471. else if(sd->state.lr_flag == 1)
  2472. sd->left_weapon.addrace[type2]+=val;
  2473. else if(sd->state.lr_flag == 2)
  2474. sd->arrow_addrace[type2]+=val;
  2475. break;
  2476. case SP_ADDCLASS:
  2477. if(!sd->state.lr_flag)
  2478. sd->right_weapon.addclass[type2]+=val;
  2479. else if(sd->state.lr_flag == 1)
  2480. sd->left_weapon.addclass[type2]+=val;
  2481. else if(sd->state.lr_flag == 2)
  2482. sd->arrow_addclass[type2]+=val;
  2483. break;
  2484. case SP_ADDSIZE:
  2485. if(!sd->state.lr_flag)
  2486. sd->right_weapon.addsize[type2]+=val;
  2487. else if(sd->state.lr_flag == 1)
  2488. sd->left_weapon.addsize[type2]+=val;
  2489. else if(sd->state.lr_flag == 2)
  2490. sd->arrow_addsize[type2]+=val;
  2491. break;
  2492. case SP_SUBELE:
  2493. if(type2 > ELE_ALL) {
  2494. ShowError("pc_bonus2: SP_SUBELE: Invalid element %d\n", type2);
  2495. break;
  2496. }
  2497. if(sd->state.lr_flag != 2)
  2498. sd->subele[type2]+=val;
  2499. break;
  2500. case SP_SUBRACE:
  2501. if(sd->state.lr_flag != 2)
  2502. sd->subrace[type2]+=val;
  2503. break;
  2504. case SP_SUBCLASS:
  2505. if(sd->state.lr_flag != 2)
  2506. sd->subclass[type2]+=val;
  2507. break;
  2508. case SP_ADDEFF:
  2509. if (type2 > SC_MAX) {
  2510. ShowWarning("pc_bonus2 (Add Effect): %d is not supported.\n", type2);
  2511. break;
  2512. }
  2513. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  2514. sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, 0);
  2515. break;
  2516. case SP_ADDEFF2:
  2517. if (type2 > SC_MAX) {
  2518. ShowWarning("pc_bonus2 (Add Effect2): %d is not supported.\n", type2);
  2519. break;
  2520. }
  2521. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  2522. sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, ATF_SELF);
  2523. break;
  2524. case SP_RESEFF:
  2525. if (type2 < SC_COMMON_MIN || type2 > SC_COMMON_MAX) {
  2526. ShowWarning("pc_bonus2 (Resist Effect): %d is not supported.\n", type2);
  2527. break;
  2528. }
  2529. if(sd->state.lr_flag == 2)
  2530. break;
  2531. i = sd->reseff[type2-SC_COMMON_MIN]+val;
  2532. sd->reseff[type2-SC_COMMON_MIN]= cap_value(i, 0, 10000);
  2533. break;
  2534. case SP_MAGIC_ADDELE:
  2535. if(type2 > ELE_ALL) {
  2536. ShowError("pc_bonus2: SP_MAGIC_ADDELE: Invalid element %d\n", type2);
  2537. break;
  2538. }
  2539. if(sd->state.lr_flag != 2)
  2540. sd->magic_addele[type2]+=val;
  2541. break;
  2542. case SP_MAGIC_ADDRACE:
  2543. if(sd->state.lr_flag != 2)
  2544. sd->magic_addrace[type2]+=val;
  2545. break;
  2546. case SP_MAGIC_ADDCLASS:
  2547. if(sd->state.lr_flag != 2)
  2548. sd->magic_addclass[type2]+=val;
  2549. break;
  2550. case SP_MAGIC_ADDSIZE:
  2551. if(sd->state.lr_flag != 2)
  2552. sd->magic_addsize[type2]+=val;
  2553. break;
  2554. case SP_MAGIC_ATK_ELE:
  2555. if(sd->state.lr_flag != 2)
  2556. sd->magic_atk_ele[type2]+=val;
  2557. break;
  2558. case SP_ADD_DAMAGE_CLASS:
  2559. switch (sd->state.lr_flag) {
  2560. case 0: //Right hand
  2561. 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);
  2562. if (i == ARRAYLENGTH(sd->right_weapon.add_dmg))
  2563. {
  2564. ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->right_weapon.add_dmg));
  2565. break;
  2566. }
  2567. sd->right_weapon.add_dmg[i].class_ = type2;
  2568. sd->right_weapon.add_dmg[i].rate += val;
  2569. if (!sd->right_weapon.add_dmg[i].rate) //Shift the rest of elements up.
  2570. 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]));
  2571. break;
  2572. case 1: //Left hand
  2573. 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);
  2574. if (i == ARRAYLENGTH(sd->left_weapon.add_dmg))
  2575. {
  2576. ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->left_weapon.add_dmg));
  2577. break;
  2578. }
  2579. sd->left_weapon.add_dmg[i].class_ = type2;
  2580. sd->left_weapon.add_dmg[i].rate += val;
  2581. if (!sd->left_weapon.add_dmg[i].rate) //Shift the rest of elements up.
  2582. 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]));
  2583. break;
  2584. }
  2585. break;
  2586. case SP_ADD_MAGIC_DAMAGE_CLASS:
  2587. if(sd->state.lr_flag == 2)
  2588. break;
  2589. ARR_FIND(0, ARRAYLENGTH(sd->add_mdmg), i, sd->add_mdmg[i].rate == 0 || sd->add_mdmg[i].class_ == type2);
  2590. if (i == ARRAYLENGTH(sd->add_mdmg))
  2591. {
  2592. ShowWarning("pc_bonus2: Reached max (%d) number of add Class magic dmg bonuses per character!\n", ARRAYLENGTH(sd->add_mdmg));
  2593. break;
  2594. }
  2595. sd->add_mdmg[i].class_ = type2;
  2596. sd->add_mdmg[i].rate += val;
  2597. if (!sd->add_mdmg[i].rate) //Shift the rest of elements up.
  2598. memmove(&sd->add_mdmg[i], &sd->add_mdmg[i+1], sizeof(sd->add_mdmg) - (i+1)*sizeof(sd->add_mdmg[0]));
  2599. break;
  2600. case SP_ADD_DEF_MONSTER:
  2601. if(sd->state.lr_flag == 2)
  2602. break;
  2603. ARR_FIND(0, ARRAYLENGTH(sd->add_def), i, sd->add_def[i].rate == 0 || sd->add_def[i].class_ == type2);
  2604. if (i == ARRAYLENGTH(sd->add_def))
  2605. {
  2606. ShowWarning("pc_bonus2: Reached max (%d) number of add Class def bonuses per character!\n", ARRAYLENGTH(sd->add_def));
  2607. break;
  2608. }
  2609. sd->add_def[i].class_ = type2;
  2610. sd->add_def[i].rate += val;
  2611. if (!sd->add_def[i].rate) //Shift the rest of elements up.
  2612. memmove(&sd->add_def[i], &sd->add_def[i+1], sizeof(sd->add_def) - (i+1)*sizeof(sd->add_def[0]));
  2613. break;
  2614. case SP_ADD_MDEF_MONSTER:
  2615. if(sd->state.lr_flag == 2)
  2616. break;
  2617. ARR_FIND(0, ARRAYLENGTH(sd->add_mdef), i, sd->add_mdef[i].rate == 0 || sd->add_mdef[i].class_ == type2);
  2618. if (i == ARRAYLENGTH(sd->add_mdef))
  2619. {
  2620. ShowWarning("pc_bonus2: Reached max (%d) number of add Class mdef bonuses per character!\n", ARRAYLENGTH(sd->add_mdef));
  2621. break;
  2622. }
  2623. sd->add_mdef[i].class_ = type2;
  2624. sd->add_mdef[i].rate += val;
  2625. if (!sd->add_mdef[i].rate) //Shift the rest of elements up.
  2626. memmove(&sd->add_mdef[i], &sd->add_mdef[i+1], sizeof(sd->add_mdef) - (i+1)*sizeof(sd->add_mdef[0]));
  2627. break;
  2628. case SP_HP_DRAIN_RATE:
  2629. if(!sd->state.lr_flag) {
  2630. sd->right_weapon.hp_drain_class[CLASS_NORMAL].rate += type2;
  2631. sd->right_weapon.hp_drain_class[CLASS_NORMAL].per += val;
  2632. sd->right_weapon.hp_drain_class[CLASS_BOSS].rate += type2;
  2633. sd->right_weapon.hp_drain_class[CLASS_BOSS].per += val;
  2634. }
  2635. else if(sd->state.lr_flag == 1) {
  2636. sd->left_weapon.hp_drain_class[CLASS_NORMAL].rate += type2;
  2637. sd->left_weapon.hp_drain_class[CLASS_NORMAL].per += val;
  2638. sd->left_weapon.hp_drain_class[CLASS_BOSS].rate += type2;
  2639. sd->left_weapon.hp_drain_class[CLASS_BOSS].per += val;
  2640. }
  2641. break;
  2642. case SP_HP_DRAIN_VALUE:
  2643. if(!sd->state.lr_flag) {
  2644. sd->right_weapon.hp_drain_class[CLASS_NORMAL].value += type2;
  2645. sd->right_weapon.hp_drain_class[CLASS_NORMAL].type = val;
  2646. sd->right_weapon.hp_drain_class[CLASS_BOSS].value += type2;
  2647. sd->right_weapon.hp_drain_class[CLASS_BOSS].type = val;
  2648. }
  2649. else if(sd->state.lr_flag == 1) {
  2650. sd->left_weapon.hp_drain_class[CLASS_NORMAL].value += type2;
  2651. sd->left_weapon.hp_drain_class[CLASS_NORMAL].type = val;
  2652. sd->left_weapon.hp_drain_class[CLASS_BOSS].value += type2;
  2653. sd->left_weapon.hp_drain_class[CLASS_BOSS].type = val;
  2654. }
  2655. break;
  2656. case SP_SP_DRAIN_RATE:
  2657. if(!sd->state.lr_flag) {
  2658. sd->right_weapon.sp_drain_class[CLASS_NORMAL].rate += type2;
  2659. sd->right_weapon.sp_drain_class[CLASS_NORMAL].per += val;
  2660. sd->right_weapon.sp_drain_class[CLASS_BOSS].rate += type2;
  2661. sd->right_weapon.sp_drain_class[CLASS_BOSS].per += val;
  2662. }
  2663. else if(sd->state.lr_flag == 1) {
  2664. sd->left_weapon.sp_drain_class[CLASS_NORMAL].rate += type2;
  2665. sd->left_weapon.sp_drain_class[CLASS_NORMAL].per += val;
  2666. sd->left_weapon.sp_drain_class[CLASS_BOSS].rate += type2;
  2667. sd->left_weapon.sp_drain_class[CLASS_BOSS].per += val;
  2668. }
  2669. break;
  2670. case SP_SP_DRAIN_VALUE:
  2671. if(!sd->state.lr_flag) {
  2672. sd->right_weapon.sp_drain_class[CLASS_NORMAL].value += type2;
  2673. sd->right_weapon.sp_drain_class[CLASS_NORMAL].type = val;
  2674. sd->right_weapon.sp_drain_class[CLASS_BOSS].value += type2;
  2675. sd->right_weapon.sp_drain_class[CLASS_BOSS].type = val;
  2676. }
  2677. else if(sd->state.lr_flag == 1) {
  2678. sd->left_weapon.sp_drain_class[CLASS_NORMAL].value += type2;
  2679. sd->left_weapon.sp_drain_class[CLASS_NORMAL].type = val;
  2680. sd->left_weapon.sp_drain_class[CLASS_BOSS].value += type2;
  2681. sd->left_weapon.sp_drain_class[CLASS_BOSS].type = val;
  2682. }
  2683. break;
  2684. case SP_SP_VANISH_RATE:
  2685. if(sd->state.lr_flag != 2) {
  2686. sd->bonus.sp_vanish_rate += type2;
  2687. sd->bonus.sp_vanish_per += val;
  2688. }
  2689. break;
  2690. case SP_HP_VANISH_RATE:
  2691. if(sd->state.lr_flag != 2) {
  2692. sd->bonus.hp_vanish_rate += type2;
  2693. sd->bonus.hp_vanish_per += val;
  2694. }
  2695. break;
  2696. case SP_GET_ZENY_NUM:
  2697. if(sd->state.lr_flag != 2 && sd->bonus.get_zeny_rate < val) {
  2698. sd->bonus.get_zeny_rate = val;
  2699. sd->bonus.get_zeny_num = type2;
  2700. }
  2701. break;
  2702. case SP_ADD_GET_ZENY_NUM:
  2703. if(sd->state.lr_flag != 2) {
  2704. sd->bonus.get_zeny_rate += val;
  2705. sd->bonus.get_zeny_num += type2;
  2706. }
  2707. break;
  2708. case SP_WEAPON_COMA_ELE:
  2709. if(type2 > ELE_ALL) {
  2710. ShowError("pc_bonus2: SP_WEAPON_COMA_ELE: Invalid element %d\n", type2);
  2711. break;
  2712. }
  2713. if(sd->state.lr_flag == 2)
  2714. break;
  2715. sd->weapon_coma_ele[type2] += val;
  2716. sd->special_state.bonus_coma = 1;
  2717. break;
  2718. case SP_WEAPON_COMA_RACE:
  2719. if(sd->state.lr_flag == 2)
  2720. break;
  2721. sd->weapon_coma_race[type2] += val;
  2722. sd->special_state.bonus_coma = 1;
  2723. break;
  2724. case SP_WEAPON_COMA_CLASS:
  2725. if(sd->state.lr_flag == 2)
  2726. break;
  2727. sd->weapon_coma_class[type2] += val;
  2728. sd->special_state.bonus_coma = 1;
  2729. break;
  2730. case SP_WEAPON_ATK:
  2731. if(sd->state.lr_flag != 2)
  2732. sd->weapon_atk[type2]+=val;
  2733. break;
  2734. case SP_WEAPON_ATK_RATE:
  2735. if(sd->state.lr_flag != 2)
  2736. sd->weapon_atk_rate[type2]+=val;
  2737. break;
  2738. case SP_CRITICAL_ADDRACE:
  2739. if(sd->state.lr_flag != 2)
  2740. sd->critaddrace[type2] += val*10;
  2741. break;
  2742. case SP_ADDEFF_WHENHIT:
  2743. if (type2 > SC_MAX) {
  2744. ShowWarning("pc_bonus2 (Add Effect when hit): %d is not supported.\n", type2);
  2745. break;
  2746. }
  2747. if(sd->state.lr_flag != 2)
  2748. pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, val, 0, 0);
  2749. break;
  2750. case SP_SKILL_ATK:
  2751. if(sd->state.lr_flag == 2)
  2752. break;
  2753. ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == 0 || sd->skillatk[i].id == type2);
  2754. if (i == ARRAYLENGTH(sd->skillatk))
  2755. { //Better mention this so the array length can be updated. [Skotlex]
  2756. ShowDebug("run_script: bonus2 bSkillAtk reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillatk), type2, val);
  2757. break;
  2758. }
  2759. if (sd->skillatk[i].id == type2)
  2760. sd->skillatk[i].val += val;
  2761. else {
  2762. sd->skillatk[i].id = type2;
  2763. sd->skillatk[i].val = val;
  2764. }
  2765. break;
  2766. case SP_SKILL_HEAL:
  2767. if(sd->state.lr_flag == 2)
  2768. break;
  2769. ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == 0 || sd->skillheal[i].id == type2);
  2770. if (i == ARRAYLENGTH(sd->skillheal))
  2771. { // Better mention this so the array length can be updated. [Skotlex]
  2772. ShowDebug("run_script: bonus2 bSkillHeal reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal), type2, val);
  2773. break;
  2774. }
  2775. if (sd->skillheal[i].id == type2)
  2776. sd->skillheal[i].val += val;
  2777. else {
  2778. sd->skillheal[i].id = type2;
  2779. sd->skillheal[i].val = val;
  2780. }
  2781. break;
  2782. case SP_SKILL_HEAL2:
  2783. if(sd->state.lr_flag == 2)
  2784. break;
  2785. ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == 0 || sd->skillheal2[i].id == type2);
  2786. if (i == ARRAYLENGTH(sd->skillheal2))
  2787. { // Better mention this so the array length can be updated. [Skotlex]
  2788. ShowDebug("run_script: bonus2 bSkillHeal2 reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal2), type2, val);
  2789. break;
  2790. }
  2791. if (sd->skillheal2[i].id == type2)
  2792. sd->skillheal2[i].val += val;
  2793. else {
  2794. sd->skillheal2[i].id = type2;
  2795. sd->skillheal2[i].val = val;
  2796. }
  2797. break;
  2798. case SP_ADD_SKILL_BLOW:
  2799. if(sd->state.lr_flag == 2)
  2800. break;
  2801. ARR_FIND(0, ARRAYLENGTH(sd->skillblown), i, sd->skillblown[i].id == 0 || sd->skillblown[i].id == type2);
  2802. if (i == ARRAYLENGTH(sd->skillblown))
  2803. { //Better mention this so the array length can be updated. [Skotlex]
  2804. ShowDebug("run_script: bonus2 bSkillBlown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillblown), type2, val);
  2805. break;
  2806. }
  2807. if(sd->skillblown[i].id == type2)
  2808. sd->skillblown[i].val += val;
  2809. else {
  2810. sd->skillblown[i].id = type2;
  2811. sd->skillblown[i].val = val;
  2812. }
  2813. break;
  2814. #ifndef RENEWAL_CAST
  2815. case SP_VARCASTRATE:
  2816. #endif
  2817. case SP_CASTRATE:
  2818. if(sd->state.lr_flag == 2)
  2819. break;
  2820. ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2);
  2821. if (i == ARRAYLENGTH(sd->skillcast))
  2822. { //Better mention this so the array length can be updated. [Skotlex]
  2823. ShowDebug("run_script: bonus2 %s reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",
  2824. #ifndef RENEWAL_CAST
  2825. "bCastRate",
  2826. #else
  2827. "bVariableCastrate",
  2828. #endif
  2829. ARRAYLENGTH(sd->skillcast), type2, val);
  2830. break;
  2831. }
  2832. if(sd->skillcast[i].id == type2)
  2833. sd->skillcast[i].val += val;
  2834. else {
  2835. sd->skillcast[i].id = type2;
  2836. sd->skillcast[i].val = val;
  2837. }
  2838. break;
  2839. case SP_FIXCASTRATE:
  2840. if(sd->state.lr_flag == 2)
  2841. break;
  2842. ARR_FIND(0, ARRAYLENGTH(sd->skillfixcastrate), i, sd->skillfixcastrate[i].id == 0 || sd->skillfixcastrate[i].id == type2);
  2843. if (i == ARRAYLENGTH(sd->skillfixcastrate))
  2844. {
  2845. ShowDebug("run_script: bonus2 bFixedCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcastrate), type2, val);
  2846. break;
  2847. }
  2848. if(sd->skillfixcastrate[i].id == type2)
  2849. sd->skillfixcastrate[i].val += val;
  2850. else {
  2851. sd->skillfixcastrate[i].id = type2;
  2852. sd->skillfixcastrate[i].val = val;
  2853. }
  2854. break;
  2855. case SP_HP_LOSS_RATE:
  2856. if(sd->state.lr_flag != 2) {
  2857. sd->hp_loss.value = type2;
  2858. sd->hp_loss.rate = val;
  2859. }
  2860. break;
  2861. case SP_HP_REGEN_RATE:
  2862. if(sd->state.lr_flag != 2) {
  2863. sd->hp_regen.value = type2;
  2864. sd->hp_regen.rate = val;
  2865. }
  2866. break;
  2867. case SP_ADDRACE2:
  2868. if (!(type2 > RC2_NONE && type2 < RC2_MAX))
  2869. break;
  2870. if(sd->state.lr_flag != 2)
  2871. sd->right_weapon.addrace2[type2] += val;
  2872. else
  2873. sd->left_weapon.addrace2[type2] += val;
  2874. break;
  2875. case SP_SUBSIZE:
  2876. if(sd->state.lr_flag != 2)
  2877. sd->subsize[type2]+=val;
  2878. break;
  2879. case SP_SUBRACE2:
  2880. if (!(type2 > RC2_NONE && type2 < RC2_MAX))
  2881. break;
  2882. if(sd->state.lr_flag != 2)
  2883. sd->subrace2[type2]+=val;
  2884. break;
  2885. case SP_ADD_ITEM_HEAL_RATE:
  2886. if(sd->state.lr_flag == 2)
  2887. break;
  2888. if (type2 < MAX_ITEMGROUP) { //Group bonus
  2889. sd->itemgrouphealrate[type2] += val;
  2890. break;
  2891. }
  2892. //Standard item bonus.
  2893. for(i=0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++);
  2894. if(i == ARRAYLENGTH(sd->itemhealrate)) {
  2895. ShowWarning("pc_bonus2: Reached max (%d) number of item heal bonuses per character!\n", ARRAYLENGTH(sd->itemhealrate));
  2896. break;
  2897. }
  2898. sd->itemhealrate[i].nameid = type2;
  2899. sd->itemhealrate[i].rate += val;
  2900. break;
  2901. case SP_EXP_ADDRACE:
  2902. if(sd->state.lr_flag != 2)
  2903. sd->expaddrace[type2]+=val;
  2904. break;
  2905. case SP_EXP_ADDCLASS:
  2906. if(sd->state.lr_flag != 2)
  2907. sd->expaddclass[type2]+=val;
  2908. break;
  2909. case SP_SP_GAIN_RACE:
  2910. if(sd->state.lr_flag != 2)
  2911. sd->sp_gain_race[type2]+=val;
  2912. break;
  2913. case SP_ADD_MONSTER_DROP_ITEM:
  2914. if (sd->state.lr_flag != 2)
  2915. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, CLASS_ALL, RC_NONE_, val);
  2916. break;
  2917. case SP_ADD_MONSTER_DROP_ITEMGROUP:
  2918. if (sd->state.lr_flag != 2)
  2919. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, CLASS_ALL, RC_NONE_, val);
  2920. break;
  2921. case SP_SP_LOSS_RATE:
  2922. if(sd->state.lr_flag != 2) {
  2923. sd->sp_loss.value = type2;
  2924. sd->sp_loss.rate = val;
  2925. }
  2926. break;
  2927. case SP_SP_REGEN_RATE:
  2928. if(sd->state.lr_flag != 2) {
  2929. sd->sp_regen.value = type2;
  2930. sd->sp_regen.rate = val;
  2931. }
  2932. break;
  2933. case SP_HP_DRAIN_VALUE_RACE:
  2934. if(!sd->state.lr_flag) {
  2935. sd->right_weapon.hp_drain_race[type2].value += val;
  2936. }
  2937. else if(sd->state.lr_flag == 1) {
  2938. sd->left_weapon.hp_drain_race[type2].value += val;
  2939. }
  2940. break;
  2941. case SP_SP_DRAIN_VALUE_RACE:
  2942. if(!sd->state.lr_flag) {
  2943. sd->right_weapon.sp_drain_race[type2].value += val;
  2944. }
  2945. else if(sd->state.lr_flag == 1) {
  2946. sd->left_weapon.sp_drain_race[type2].value += val;
  2947. }
  2948. break;
  2949. case SP_HP_DRAIN_VALUE_CLASS:
  2950. if(!sd->state.lr_flag) {
  2951. sd->right_weapon.hp_drain_class[type2].value += val;
  2952. }
  2953. else if(sd->state.lr_flag == 1) {
  2954. sd->left_weapon.hp_drain_class[type2].value += val;
  2955. }
  2956. break;
  2957. case SP_SP_DRAIN_VALUE_CLASS:
  2958. if(!sd->state.lr_flag) {
  2959. sd->right_weapon.sp_drain_class[type2].value += val;
  2960. }
  2961. else if(sd->state.lr_flag == 1) {
  2962. sd->left_weapon.sp_drain_class[type2].value += val;
  2963. }
  2964. break;
  2965. case SP_IGNORE_MDEF_RACE_RATE:
  2966. if(sd->state.lr_flag != 2)
  2967. sd->ignore_mdef_by_race[type2] += val;
  2968. break;
  2969. case SP_IGNORE_MDEF_CLASS_RATE:
  2970. if(sd->state.lr_flag != 2)
  2971. sd->ignore_mdef_by_class[type2] += val;
  2972. break;
  2973. case SP_IGNORE_DEF_RACE_RATE:
  2974. if(sd->state.lr_flag != 2)
  2975. sd->ignore_def_by_race[type2] += val;
  2976. break;
  2977. case SP_SP_GAIN_RACE_ATTACK:
  2978. if(sd->state.lr_flag != 2)
  2979. sd->sp_gain_race_attack[type2] = cap_value(sd->sp_gain_race_attack[type2] + val, 0, INT16_MAX);
  2980. break;
  2981. case SP_HP_GAIN_RACE_ATTACK:
  2982. if(sd->state.lr_flag != 2)
  2983. sd->hp_gain_race_attack[type2] = cap_value(sd->hp_gain_race_attack[type2] + val, 0, INT16_MAX);
  2984. break;
  2985. case SP_SKILL_USE_SP_RATE: //bonus2 bSkillUseSPrate,n,x;
  2986. if(sd->state.lr_flag == 2)
  2987. break;
  2988. ARR_FIND(0, ARRAYLENGTH(sd->skillusesprate), i, sd->skillusesprate[i].id == 0 || sd->skillusesprate[i].id == type2);
  2989. if (i == ARRAYLENGTH(sd->skillusesprate)) {
  2990. ShowDebug("run_script: bonus2 bSkillUseSPrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesprate), type2, val);
  2991. break;
  2992. }
  2993. if (sd->skillusesprate[i].id == type2)
  2994. sd->skillusesprate[i].val += val;
  2995. else {
  2996. sd->skillusesprate[i].id = type2;
  2997. sd->skillusesprate[i].val = val;
  2998. }
  2999. break;
  3000. case SP_SKILL_COOLDOWN:
  3001. if(sd->state.lr_flag == 2)
  3002. break;
  3003. ARR_FIND(0, ARRAYLENGTH(sd->skillcooldown), i, sd->skillcooldown[i].id == 0 || sd->skillcooldown[i].id == type2);
  3004. if (i == ARRAYLENGTH(sd->skillcooldown))
  3005. {
  3006. ShowDebug("run_script: bonus2 bSkillCoolDown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillcooldown), type2, val);
  3007. break;
  3008. }
  3009. if (sd->skillcooldown[i].id == type2)
  3010. sd->skillcooldown[i].val += val;
  3011. else {
  3012. sd->skillcooldown[i].id = type2;
  3013. sd->skillcooldown[i].val = val;
  3014. }
  3015. break;
  3016. case SP_SKILL_FIXEDCAST:
  3017. if(sd->state.lr_flag == 2)
  3018. break;
  3019. ARR_FIND(0, ARRAYLENGTH(sd->skillfixcast), i, sd->skillfixcast[i].id == 0 || sd->skillfixcast[i].id == type2);
  3020. if (i == ARRAYLENGTH(sd->skillfixcast))
  3021. {
  3022. ShowDebug("run_script: bonus2 bSkillFixedCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcast), type2, val);
  3023. break;
  3024. }
  3025. if (sd->skillfixcast[i].id == type2)
  3026. sd->skillfixcast[i].val += val;
  3027. else {
  3028. sd->skillfixcast[i].id = type2;
  3029. sd->skillfixcast[i].val = val;
  3030. }
  3031. break;
  3032. case SP_SKILL_VARIABLECAST:
  3033. if(sd->state.lr_flag == 2)
  3034. break;
  3035. ARR_FIND(0, ARRAYLENGTH(sd->skillvarcast), i, sd->skillvarcast[i].id == 0 || sd->skillvarcast[i].id == type2);
  3036. if (i == ARRAYLENGTH(sd->skillvarcast))
  3037. {
  3038. ShowDebug("run_script: bonus2 bSkillVariableCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillvarcast), type2, val);
  3039. break;
  3040. }
  3041. if (sd->skillvarcast[i].id == type2)
  3042. sd->skillvarcast[i].val += val;
  3043. else {
  3044. sd->skillvarcast[i].id = type2;
  3045. sd->skillvarcast[i].val = val;
  3046. }
  3047. break;
  3048. #ifdef RENEWAL_CAST
  3049. case SP_VARCASTRATE:
  3050. if(sd->state.lr_flag == 2)
  3051. break;
  3052. ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2);
  3053. if (i == ARRAYLENGTH(sd->skillcast))
  3054. {
  3055. ShowDebug("run_script: bonus2 bVariableCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",ARRAYLENGTH(sd->skillcast), type2, val);
  3056. break;
  3057. }
  3058. if(sd->skillcast[i].id == type2)
  3059. sd->skillcast[i].val -= val;
  3060. else {
  3061. sd->skillcast[i].id = type2;
  3062. sd->skillcast[i].val -= val;
  3063. }
  3064. break;
  3065. #endif
  3066. case SP_SKILL_USE_SP: //bonus2 bSkillUseSP,n,x;
  3067. if(sd->state.lr_flag == 2)
  3068. break;
  3069. ARR_FIND(0, ARRAYLENGTH(sd->skillusesp), i, sd->skillusesp[i].id == 0 || sd->skillusesp[i].id == type2);
  3070. if (i == ARRAYLENGTH(sd->skillusesp)) {
  3071. ShowDebug("run_script: bonus2 bSkillUseSP reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesp), type2, val);
  3072. break;
  3073. }
  3074. if (sd->skillusesp[i].id == type2)
  3075. sd->skillusesp[i].val += val;
  3076. else {
  3077. sd->skillusesp[i].id = type2;
  3078. sd->skillusesp[i].val = val;
  3079. }
  3080. break;
  3081. default:
  3082. ShowWarning("pc_bonus2: unknown type %d %d %d!\n",type,type2,val);
  3083. break;
  3084. }
  3085. return 0;
  3086. }
  3087. int pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
  3088. {
  3089. nullpo_ret(sd);
  3090. switch(type){
  3091. case SP_ADD_MONSTER_DROP_ITEM:
  3092. if(sd->state.lr_flag != 2)
  3093. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, CLASS_NONE, type3, val);
  3094. break;
  3095. case SP_ADD_MONSTER_ID_DROP_ITEM:
  3096. if(sd->state.lr_flag != 2)
  3097. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, CLASS_NONE, -type3, val);
  3098. break;
  3099. case SP_ADD_CLASS_DROP_ITEM:
  3100. if(sd->state.lr_flag != 2)
  3101. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, type3, RC_NONE_, val);
  3102. break;
  3103. case SP_AUTOSPELL:
  3104. if(sd->state.lr_flag != 2)
  3105. {
  3106. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3107. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3108. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell),
  3109. target?-type2:type2, type3, val, 0, current_equip_card_id);
  3110. }
  3111. break;
  3112. case SP_AUTOSPELL_WHENHIT:
  3113. if(sd->state.lr_flag != 2)
  3114. {
  3115. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3116. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3117. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2),
  3118. target?-type2:type2, type3, val, BF_NORMAL|BF_SKILL, current_equip_card_id);
  3119. }
  3120. break;
  3121. case SP_SP_DRAIN_RATE:
  3122. if(!sd->state.lr_flag) {
  3123. sd->right_weapon.sp_drain_class[CLASS_NORMAL].rate += type2;
  3124. sd->right_weapon.sp_drain_class[CLASS_NORMAL].per += type3;
  3125. sd->right_weapon.sp_drain_class[CLASS_NORMAL].type = val;
  3126. sd->right_weapon.sp_drain_class[CLASS_BOSS].rate += type2;
  3127. sd->right_weapon.sp_drain_class[CLASS_BOSS].per += type3;
  3128. sd->right_weapon.sp_drain_class[CLASS_BOSS].type = val;
  3129. }
  3130. else if(sd->state.lr_flag == 1) {
  3131. sd->left_weapon.sp_drain_class[CLASS_NORMAL].rate += type2;
  3132. sd->left_weapon.sp_drain_class[CLASS_NORMAL].per += type3;
  3133. sd->left_weapon.sp_drain_class[CLASS_NORMAL].type = val;
  3134. sd->left_weapon.sp_drain_class[CLASS_BOSS].rate += type2;
  3135. sd->left_weapon.sp_drain_class[CLASS_BOSS].per += type3;
  3136. sd->left_weapon.sp_drain_class[CLASS_BOSS].type = val;
  3137. }
  3138. break;
  3139. case SP_ADD_MONSTER_DROP_ITEMGROUP:
  3140. if (sd->state.lr_flag != 2)
  3141. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, CLASS_NONE, type3, val);
  3142. break;
  3143. case SP_ADD_CLASS_DROP_ITEMGROUP:
  3144. if (sd->state.lr_flag != 2)
  3145. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, type3, RC_NONE_, val);
  3146. break;
  3147. case SP_ADDEFF:
  3148. if (type2 > SC_MAX) {
  3149. ShowWarning("pc_bonus3 (Add Effect): %d is not supported.\n", type2);
  3150. break;
  3151. }
  3152. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  3153. sd->state.lr_flag!=2?type3:0, sd->state.lr_flag==2?type3:0, val);
  3154. break;
  3155. case SP_ADDEFF_WHENHIT:
  3156. if (type2 > SC_MAX) {
  3157. ShowWarning("pc_bonus3 (Add Effect when hit): %d is not supported.\n", type2);
  3158. break;
  3159. }
  3160. if(sd->state.lr_flag != 2)
  3161. pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, type3, 0, val);
  3162. break;
  3163. case SP_ADDEFF_ONSKILL:
  3164. if( type3 > SC_MAX ) {
  3165. ShowWarning("pc_bonus3 (Add Effect on skill): %d is not supported.\n", type3);
  3166. break;
  3167. }
  3168. if( sd->state.lr_flag != 2 )
  3169. pc_bonus_addeff_onskill(sd->addeff3, ARRAYLENGTH(sd->addeff3), (sc_type)type3, val, type2, ATF_TARGET);
  3170. break;
  3171. case SP_ADDELE:
  3172. if (type2 > ELE_ALL) {
  3173. ShowWarning("pc_bonus3 (SP_ADDELE): element %d is out of range.\n", type2);
  3174. break;
  3175. }
  3176. if (sd->state.lr_flag != 2)
  3177. pc_bonus_addele(sd, (unsigned char)type2, type3, val);
  3178. break;
  3179. case SP_SUBELE:
  3180. if (type2 > ELE_ALL) {
  3181. ShowWarning("pc_bonus3 (SP_SUBELE): element %d is out of range.\n", type2);
  3182. break;
  3183. }
  3184. if (sd->state.lr_flag != 2)
  3185. pc_bonus_subele(sd, (unsigned char)type2, type3, val);
  3186. break;
  3187. default:
  3188. ShowWarning("pc_bonus3: unknown type %d %d %d %d!\n",type,type2,type3,val);
  3189. break;
  3190. }
  3191. return 0;
  3192. }
  3193. int pc_bonus4(struct map_session_data *sd,int type,int type2,int type3,int type4,int val)
  3194. {
  3195. nullpo_ret(sd);
  3196. switch(type){
  3197. case SP_AUTOSPELL:
  3198. if(sd->state.lr_flag != 2)
  3199. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
  3200. break;
  3201. case SP_AUTOSPELL_WHENHIT:
  3202. if(sd->state.lr_flag != 2)
  3203. 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);
  3204. break;
  3205. case SP_AUTOSPELL_ONSKILL:
  3206. if(sd->state.lr_flag != 2)
  3207. {
  3208. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3209. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3210. pc_bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, target?-type3:type3, type4, val, current_equip_card_id);
  3211. }
  3212. break;
  3213. case SP_ADDEFF_ONSKILL:
  3214. if( type2 > SC_MAX ) {
  3215. ShowWarning("pc_bonus4 (Add Effect on skill): %d is not supported.\n", type2);
  3216. break;
  3217. }
  3218. if( sd->state.lr_flag != 2 )
  3219. pc_bonus_addeff_onskill(sd->addeff3, ARRAYLENGTH(sd->addeff3), (sc_type)type3, type4, type2, val);
  3220. break;
  3221. case SP_DEF_SET: //bonus4 bSetDefRace,n,x,r,y;
  3222. if( type2 > RC_ALL ) {
  3223. ShowWarning("pc_bonus4 (DEF_SET): %d is not supported.\n", type2);
  3224. break;
  3225. }
  3226. if(sd->state.lr_flag == 2)
  3227. break;
  3228. sd->def_set_race[type2].rate = type3;
  3229. sd->def_set_race[type2].tick = type4;
  3230. sd->def_set_race[type2].value = val;
  3231. break;
  3232. case SP_MDEF_SET: //bonus4 bSetMDefRace,n,x,r,y;
  3233. if( type2 > RC_ALL ) {
  3234. ShowWarning("pc_bonus4 (MDEF_SET): %d is not supported.\n", type2);
  3235. break;
  3236. }
  3237. if(sd->state.lr_flag == 2)
  3238. break;
  3239. sd->mdef_set_race[type2].rate = type3;
  3240. sd->mdef_set_race[type2].tick = type4;
  3241. sd->mdef_set_race[type2].value = val;
  3242. break;
  3243. default:
  3244. ShowWarning("pc_bonus4: unknown type %d %d %d %d %d!\n",type,type2,type3,type4,val);
  3245. break;
  3246. }
  3247. return 0;
  3248. }
  3249. int pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4,int type5,int val)
  3250. {
  3251. nullpo_ret(sd);
  3252. switch(type){
  3253. case SP_AUTOSPELL:
  3254. if(sd->state.lr_flag != 2)
  3255. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  3256. break;
  3257. case SP_AUTOSPELL_WHENHIT:
  3258. if(sd->state.lr_flag != 2)
  3259. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  3260. break;
  3261. case SP_AUTOSPELL_ONSKILL:
  3262. if(sd->state.lr_flag != 2)
  3263. pc_bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, (val&1?-type3:type3), (val&2?-type4:type4), type5, current_equip_card_id);
  3264. break;
  3265. default:
  3266. ShowWarning("pc_bonus5: unknown type %d %d %d %d %d %d!\n",type,type2,type3,type4,type5,val);
  3267. break;
  3268. }
  3269. return 0;
  3270. }
  3271. /*==========================================
  3272. * Grants a player a given skill. Flag values are:
  3273. * 0 - Grant permanent skill to be bound to skill tree
  3274. * 1 - Grant an item skill (temporary)
  3275. * 2 - Like 1, except the level granted can stack with previously learned level.
  3276. * 4 - Like 0, except the skill will ignore skill tree (saves through job changes and resets).
  3277. *------------------------------------------*/
  3278. int pc_skill(TBL_PC* sd, int id, int level, int flag)
  3279. {
  3280. nullpo_ret(sd);
  3281. if( id <= 0 || id >= MAX_SKILL || skill_db[id].name == NULL) {
  3282. ShowError("pc_skill: Skill with id %d does not exist in the skill database\n", id);
  3283. return 0;
  3284. }
  3285. if( level > MAX_SKILL_LEVEL ) {
  3286. ShowError("pc_skill: Skill level %d too high. Max lv supported is %d\n", level, MAX_SKILL_LEVEL);
  3287. return 0;
  3288. }
  3289. if( flag == 2 && sd->status.skill[id].lv + level > MAX_SKILL_LEVEL ) {
  3290. 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);
  3291. return 0;
  3292. }
  3293. switch( flag ){
  3294. case 0: //Set skill data overwriting whatever was there before.
  3295. sd->status.skill[id].id = id;
  3296. sd->status.skill[id].lv = level;
  3297. sd->status.skill[id].flag = SKILL_FLAG_PERMANENT;
  3298. if( level == 0 ) { //Remove skill.
  3299. sd->status.skill[id].id = 0;
  3300. clif_deleteskill(sd,id);
  3301. } else
  3302. clif_addskill(sd,id);
  3303. if( !skill_get_inf(id) ) //Only recalculate for passive skills.
  3304. status_calc_pc(sd, 0);
  3305. break;
  3306. case 1: //Item bonus skill.
  3307. if( sd->status.skill[id].id == id ){
  3308. if( sd->status.skill[id].lv >= level )
  3309. return 0;
  3310. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT ) //Non-granted skill, store it's level.
  3311. sd->status.skill[id].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[id].lv;
  3312. } else {
  3313. sd->status.skill[id].id = id;
  3314. sd->status.skill[id].flag = SKILL_FLAG_TEMPORARY;
  3315. }
  3316. sd->status.skill[id].lv = level;
  3317. break;
  3318. case 2: //Add skill bonus on top of what you had.
  3319. if( sd->status.skill[id].id == id ){
  3320. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  3321. sd->status.skill[id].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[id].lv; // Store previous level.
  3322. } else {
  3323. sd->status.skill[id].id = id;
  3324. sd->status.skill[id].flag = SKILL_FLAG_TEMPORARY; //Set that this is a bonus skill.
  3325. }
  3326. sd->status.skill[id].lv += level;
  3327. break;
  3328. case 4: //Permanent granted skills ignore the skill tree
  3329. sd->status.skill[id].id = id;
  3330. sd->status.skill[id].lv = level;
  3331. sd->status.skill[id].flag = SKILL_FLAG_PERM_GRANTED;
  3332. if( level == 0 ) { //Remove skill.
  3333. sd->status.skill[id].id = 0;
  3334. clif_deleteskill(sd,id);
  3335. } else
  3336. clif_addskill(sd,id);
  3337. if( !skill_get_inf(id) ) //Only recalculate for passive skills.
  3338. status_calc_pc(sd, 0);
  3339. break;
  3340. default: //Unknown flag?
  3341. return 0;
  3342. }
  3343. return 1;
  3344. }
  3345. /*==========================================
  3346. * Append a card to an item ?
  3347. *------------------------------------------*/
  3348. int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip)
  3349. {
  3350. int i;
  3351. int nameid;
  3352. nullpo_ret(sd);
  3353. if( idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL )
  3354. return 0; //Invalid item index.
  3355. if( idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL )
  3356. return 0; //Invalid card index.
  3357. if( sd->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1 )
  3358. return 0; // target item missing
  3359. if( sd->status.inventory[idx_card].nameid <= 0 || sd->status.inventory[idx_card].amount < 1 )
  3360. return 0; // target card missing
  3361. if( sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR )
  3362. return 0; // only weapons and armor are allowed
  3363. if( sd->inventory_data[idx_card]->type != IT_CARD )
  3364. return 0; // must be a card
  3365. if( sd->status.inventory[idx_equip].identify == 0 )
  3366. return 0; // target must be identified
  3367. if( itemdb_isspecial(sd->status.inventory[idx_equip].card[0]) )
  3368. return 0; // card slots reserved for other purposes
  3369. if( (sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0 )
  3370. return 0; // card cannot be compounded on this item type
  3371. if( sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD )
  3372. return 0; // attempted to place shield card on left-hand weapon.
  3373. if( sd->status.inventory[idx_equip].equip != 0 )
  3374. return 0; // item must be unequipped
  3375. ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0 );
  3376. if( i == sd->inventory_data[idx_equip]->slot )
  3377. return 0; // no free slots
  3378. // remember the card id to insert
  3379. nameid = sd->status.inventory[idx_card].nameid;
  3380. if( pc_delitem(sd,idx_card,1,1,0,LOG_TYPE_OTHER) == 1 )
  3381. {// failed
  3382. clif_insert_card(sd,idx_equip,idx_card,1);
  3383. }
  3384. else
  3385. {// success
  3386. log_pick_pc(sd, LOG_TYPE_OTHER, -1, &sd->status.inventory[idx_equip]);
  3387. sd->status.inventory[idx_equip].card[i] = nameid;
  3388. log_pick_pc(sd, LOG_TYPE_OTHER, 1, &sd->status.inventory[idx_equip]);
  3389. clif_insert_card(sd,idx_equip,idx_card,0);
  3390. }
  3391. return 0;
  3392. }
  3393. //
  3394. // Items
  3395. //
  3396. /*==========================================
  3397. * Update buying value by skills
  3398. *------------------------------------------*/
  3399. int pc_modifybuyvalue(struct map_session_data *sd,int orig_value)
  3400. {
  3401. int skill,val = orig_value,rate1 = 0,rate2 = 0;
  3402. if((skill=pc_checkskill(sd,MC_DISCOUNT))>0) // merchant discount
  3403. rate1 = 5+skill*2-((skill==10)? 1:0);
  3404. if((skill=pc_checkskill(sd,RG_COMPULSION))>0) // rogue discount
  3405. rate2 = 5+skill*4;
  3406. if(rate1 < rate2) rate1 = rate2;
  3407. if(rate1)
  3408. val = (int)((double)orig_value*(double)(100-rate1)/100.);
  3409. if(val < 0) val = 0;
  3410. if(orig_value > 0 && val < 1) val = 1;
  3411. return val;
  3412. }
  3413. /*==========================================
  3414. * Update selling value by skills
  3415. *------------------------------------------*/
  3416. int pc_modifysellvalue(struct map_session_data *sd,int orig_value)
  3417. {
  3418. int skill,val = orig_value,rate = 0;
  3419. if((skill=pc_checkskill(sd,MC_OVERCHARGE))>0) //OverCharge
  3420. rate = 5+skill*2-((skill==10)? 1:0);
  3421. if(rate)
  3422. val = (int)((double)orig_value*(double)(100+rate)/100.);
  3423. if(val < 0) val = 0;
  3424. if(orig_value > 0 && val < 1) val = 1;
  3425. return val;
  3426. }
  3427. /*==========================================
  3428. * Checking if we have enough place on inventory for new item
  3429. * Make sure to take 30k as limit (for client I guess)
  3430. *------------------------------------------*/
  3431. int pc_checkadditem(struct map_session_data *sd,int nameid,int amount)
  3432. {
  3433. int i;
  3434. struct item_data* data;
  3435. nullpo_ret(sd);
  3436. if(amount > MAX_AMOUNT)
  3437. return CHKADDITEM_OVERAMOUNT;
  3438. data = itemdb_search(nameid);
  3439. if(!itemdb_isstackable2(data))
  3440. return CHKADDITEM_NEW;
  3441. if( data->stack.inventory && amount > data->stack.amount )
  3442. return CHKADDITEM_OVERAMOUNT;
  3443. for(i=0;i<MAX_INVENTORY;i++){
  3444. // FIXME: This does not consider the checked item's cards, thus could check a wrong slot for stackability.
  3445. if(sd->status.inventory[i].nameid==nameid){
  3446. if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) )
  3447. return CHKADDITEM_OVERAMOUNT;
  3448. return CHKADDITEM_EXIST;
  3449. }
  3450. }
  3451. return CHKADDITEM_NEW;
  3452. }
  3453. /*==========================================
  3454. * Return number of available place in inventory
  3455. * Each non stackable item will reduce place by 1
  3456. *------------------------------------------*/
  3457. int pc_inventoryblank(struct map_session_data *sd)
  3458. {
  3459. int i,b;
  3460. nullpo_ret(sd);
  3461. for(i=0,b=0;i<MAX_INVENTORY;i++){
  3462. if(sd->status.inventory[i].nameid==0)
  3463. b++;
  3464. }
  3465. return b;
  3466. }
  3467. /*==========================================
  3468. * attempts to remove zeny from player (sd)
  3469. *------------------------------------------*/
  3470. int pc_payzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type, struct map_session_data *tsd)
  3471. {
  3472. nullpo_retr(-1,sd);
  3473. zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3474. if( zeny < 0 )
  3475. {
  3476. ShowError("pc_payzeny: Paying negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
  3477. return 1;
  3478. }
  3479. if( sd->status.zeny < zeny )
  3480. return 1; //Not enough.
  3481. sd->status.zeny -= zeny;
  3482. clif_updatestatus(sd,SP_ZENY);
  3483. if(!tsd) tsd = sd;
  3484. log_zeny(sd, type, tsd, -zeny);
  3485. if( zeny > 0 && sd->state.showzeny ) {
  3486. char output[255];
  3487. sprintf(output, "Removed %dz.", zeny);
  3488. clif_disp_onlyself(sd,output,strlen(output));
  3489. }
  3490. return 0;
  3491. }
  3492. /** Makes player pays by using cash points
  3493. * @param sd Player who pays
  3494. * @param price How many point player has to pay
  3495. * @param points
  3496. * @param type e_log_pick_type
  3497. * @return -2: Paying negative points, -1: Not enough points, otherwise is succes (cash+points)
  3498. */
  3499. int pc_paycash(struct map_session_data *sd, int price, int points, e_log_pick_type type ){
  3500. int cash;
  3501. nullpo_retr(-1,sd);
  3502. points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3503. if( price < 0 || points < 0 )
  3504. {
  3505. 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);
  3506. return -2;
  3507. }
  3508. if( points > price )
  3509. {
  3510. 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);
  3511. points = price;
  3512. }
  3513. cash = price-points;
  3514. if( sd->cashPoints < cash || sd->kafraPoints < points )
  3515. {
  3516. 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);
  3517. return -1;
  3518. }
  3519. pc_setaccountreg(sd, "#CASHPOINTS", sd->cashPoints-cash);
  3520. if( cash ){
  3521. log_cash( sd, type, LOG_CASH_TYPE_CASH, -cash );
  3522. }
  3523. pc_setaccountreg(sd, "#KAFRAPOINTS", sd->kafraPoints-points);
  3524. if( points ){
  3525. log_cash( sd, type, LOG_CASH_TYPE_KAFRA, -points );
  3526. }
  3527. if( battle_config.cashshop_show_points )
  3528. {
  3529. char output[128];
  3530. sprintf(output, msg_txt(sd,504), points, cash, sd->kafraPoints, sd->cashPoints);
  3531. clif_disp_onlyself(sd, output, strlen(output));
  3532. }
  3533. return cash+points;
  3534. }
  3535. int pc_getcash( struct map_session_data *sd, int cash, int points, e_log_pick_type type ){
  3536. char output[128];
  3537. nullpo_retr(-1,sd);
  3538. cash = cap_value(cash,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3539. points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3540. if( cash > 0 )
  3541. {
  3542. if( cash > MAX_ZENY-sd->cashPoints )
  3543. {
  3544. 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);
  3545. cash = MAX_ZENY-sd->cashPoints;
  3546. }
  3547. pc_setaccountreg(sd, "#CASHPOINTS", sd->cashPoints+cash);
  3548. if( cash ){
  3549. log_cash( sd, type, LOG_CASH_TYPE_CASH, cash );
  3550. }
  3551. if( battle_config.cashshop_show_points )
  3552. {
  3553. sprintf(output, msg_txt(sd,505), cash, sd->cashPoints);
  3554. clif_disp_onlyself(sd, output, strlen(output));
  3555. }
  3556. return cash;
  3557. }
  3558. else if( cash < 0 )
  3559. {
  3560. 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);
  3561. return -1;
  3562. }
  3563. if( points > 0 )
  3564. {
  3565. if( points > MAX_ZENY-sd->kafraPoints )
  3566. {
  3567. 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);
  3568. points = MAX_ZENY-sd->kafraPoints;
  3569. }
  3570. pc_setaccountreg(sd, "#KAFRAPOINTS", sd->kafraPoints+points);
  3571. if( points ){
  3572. log_cash( sd, type, LOG_CASH_TYPE_KAFRA, points );
  3573. }
  3574. if( battle_config.cashshop_show_points )
  3575. {
  3576. sprintf(output, msg_txt(sd,506), points, sd->kafraPoints);
  3577. clif_disp_onlyself(sd, output, strlen(output));
  3578. }
  3579. return points;
  3580. }
  3581. else if( points < 0 )
  3582. {
  3583. 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);
  3584. return -1;
  3585. }
  3586. return -2; //shouldn't happen but jsut in case
  3587. }
  3588. /*==========================================
  3589. * Attempts to give zeny to player (sd)
  3590. * tsd (optional) from who for log (if null take sd)
  3591. *------------------------------------------*/
  3592. int pc_getzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type, struct map_session_data *tsd)
  3593. {
  3594. nullpo_retr(-1,sd);
  3595. zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3596. if( zeny < 0 )
  3597. {
  3598. ShowError("pc_getzeny: Obtaining negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
  3599. return 1;
  3600. }
  3601. if( zeny > MAX_ZENY - sd->status.zeny )
  3602. zeny = MAX_ZENY - sd->status.zeny;
  3603. sd->status.zeny += zeny;
  3604. clif_updatestatus(sd,SP_ZENY);
  3605. if(!tsd) tsd = sd;
  3606. log_zeny(sd, type, tsd, zeny);
  3607. if( zeny > 0 && sd->state.showzeny ) {
  3608. char output[255];
  3609. sprintf(output, "Gained %dz.", zeny);
  3610. clif_disp_onlyself(sd,output,strlen(output));
  3611. }
  3612. return 0;
  3613. }
  3614. /*==========================================
  3615. * Searching a specified itemid in inventory and return his stored index
  3616. *------------------------------------------*/
  3617. int pc_search_inventory(struct map_session_data *sd,int item_id)
  3618. {
  3619. int i;
  3620. nullpo_retr(-1, sd);
  3621. ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == item_id && (sd->status.inventory[i].amount > 0 || item_id == 0) );
  3622. return ( i < MAX_INVENTORY ) ? i : -1;
  3623. }
  3624. /*==========================================
  3625. * Attempt to add a new item to inventory.
  3626. * Return:
  3627. 0 = success
  3628. 1 = invalid itemid not found or negative amount
  3629. 2 = overweight
  3630. 3 = ?
  3631. 4 = no free place found
  3632. 5 = max amount reached
  3633. 6 = ?
  3634. 7 = stack limitation
  3635. *------------------------------------------*/
  3636. int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type)
  3637. {
  3638. struct item_data *data;
  3639. int i;
  3640. unsigned int w;
  3641. nullpo_retr(1, sd);
  3642. nullpo_retr(1, item_data);
  3643. if( item_data->nameid <= 0 || amount <= 0 )
  3644. return ADDITEM_INVALID;
  3645. if( amount > MAX_AMOUNT )
  3646. return ADDITEM_OVERAMOUNT;
  3647. data = itemdb_search(item_data->nameid);
  3648. if( data->stack.inventory && amount > data->stack.amount )
  3649. {// item stack limitation
  3650. return ADDITEM_STACKLIMIT;
  3651. }
  3652. w = data->weight*amount;
  3653. if(sd->weight + w > sd->max_weight)
  3654. return ADDITEM_OVERWEIGHT;
  3655. i = MAX_INVENTORY;
  3656. if( itemdb_isstackable2(data) && item_data->expire_time == 0 )
  3657. { // Stackable | Non Rental
  3658. for( i = 0; i < MAX_INVENTORY; i++ )
  3659. {
  3660. if( sd->status.inventory[i].nameid == item_data->nameid && sd->status.inventory[i].bound == item_data->bound && memcmp(&sd->status.inventory[i].card, &item_data->card, sizeof(item_data->card)) == 0 )
  3661. {
  3662. if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) )
  3663. return 5;
  3664. sd->status.inventory[i].amount += amount;
  3665. clif_additem(sd,i,amount,0);
  3666. break;
  3667. }
  3668. }
  3669. }
  3670. if( i >= MAX_INVENTORY )
  3671. {
  3672. i = pc_search_inventory(sd,0);
  3673. if( i < 0 )
  3674. return ADDITEM_OVERITEM;
  3675. memcpy(&sd->status.inventory[i], item_data, sizeof(sd->status.inventory[0]));
  3676. // clear equips field first, just in case
  3677. if( item_data->equip )
  3678. sd->status.inventory[i].equip = 0;
  3679. sd->status.inventory[i].amount = amount;
  3680. sd->inventory_data[i] = data;
  3681. clif_additem(sd,i,amount,0);
  3682. }
  3683. #ifdef NSI_UNIQUE_ID
  3684. if( !itemdb_isstackable2(data) && !item_data->unique_id )
  3685. sd->status.inventory[i].unique_id = itemdb_unique_id(0,0);
  3686. #endif
  3687. log_pick_pc(sd, log_type, amount, &sd->status.inventory[i]);
  3688. sd->weight += w;
  3689. clif_updatestatus(sd,SP_WEIGHT);
  3690. //Auto-equip
  3691. if(data->flag.autoequip)
  3692. pc_equipitem(sd, i, data->equip);
  3693. /* rental item check */
  3694. if( item_data->expire_time ) {
  3695. if( time(NULL) > item_data->expire_time ) {
  3696. clif_rental_expired(sd->fd, i, sd->status.inventory[i].nameid);
  3697. pc_delitem(sd, i, sd->status.inventory[i].amount, 1, 0, LOG_TYPE_OTHER);
  3698. } else {
  3699. int seconds = (int)( item_data->expire_time - time(NULL) );
  3700. clif_rental_time(sd->fd, sd->status.inventory[i].nameid, seconds);
  3701. pc_inventory_rental_add(sd, seconds);
  3702. }
  3703. }
  3704. return ADDITEM_SUCCESS;
  3705. }
  3706. /*==========================================
  3707. * Remove an item at index n from inventory by amount.
  3708. * Parameters :
  3709. * @type
  3710. * 1 : don't notify deletion
  3711. * 2 : don't notify weight change
  3712. * Return:
  3713. * 0 = success
  3714. * 1 = invalid itemid or negative amount
  3715. *------------------------------------------*/
  3716. int pc_delitem(struct map_session_data *sd,int n,int amount,int type, short reason, e_log_pick_type log_type)
  3717. {
  3718. nullpo_retr(1, sd);
  3719. if(n < 0 || sd->status.inventory[n].nameid==0 || amount <= 0 || sd->status.inventory[n].amount<amount || sd->inventory_data[n] == NULL)
  3720. return 1;
  3721. log_pick_pc(sd, log_type, -amount, &sd->status.inventory[n]);
  3722. sd->status.inventory[n].amount -= amount;
  3723. sd->weight -= sd->inventory_data[n]->weight*amount ;
  3724. if( sd->status.inventory[n].amount <= 0 ){
  3725. if(sd->status.inventory[n].equip)
  3726. pc_unequipitem(sd,n,3);
  3727. memset(&sd->status.inventory[n],0,sizeof(sd->status.inventory[0]));
  3728. sd->inventory_data[n] = NULL;
  3729. }
  3730. if(!(type&1))
  3731. clif_delitem(sd,n,amount,reason);
  3732. if(!(type&2))
  3733. clif_updatestatus(sd,SP_WEIGHT);
  3734. return 0;
  3735. }
  3736. /*==========================================
  3737. * Attempt to drop an item.
  3738. * Return:
  3739. * 0 = fail
  3740. * 1 = success
  3741. *------------------------------------------*/
  3742. int pc_dropitem(struct map_session_data *sd,int n,int amount)
  3743. {
  3744. nullpo_retr(1, sd);
  3745. if(n < 0 || n >= MAX_INVENTORY)
  3746. return 0;
  3747. if(amount <= 0)
  3748. return 0;
  3749. if(sd->status.inventory[n].nameid <= 0 ||
  3750. sd->status.inventory[n].amount <= 0 ||
  3751. sd->status.inventory[n].amount < amount ||
  3752. sd->state.trading || sd->state.vending ||
  3753. !sd->inventory_data[n] //pc_delitem would fail on this case.
  3754. )
  3755. return 0;
  3756. if( map[sd->bl.m].flag.nodrop )
  3757. {
  3758. clif_displaymessage (sd->fd, msg_txt(sd,271));
  3759. return 0; //Can't drop items in nodrop mapflag maps.
  3760. }
  3761. if( !pc_candrop(sd,&sd->status.inventory[n]) )
  3762. {
  3763. clif_displaymessage (sd->fd, msg_txt(sd,263));
  3764. return 0;
  3765. }
  3766. if (!map_addflooritem(&sd->status.inventory[n], amount, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 2))
  3767. return 0;
  3768. pc_delitem(sd, n, amount, 1, 0, LOG_TYPE_PICKDROP_PLAYER);
  3769. clif_dropitem(sd, n, amount);
  3770. return 1;
  3771. }
  3772. /*==========================================
  3773. * Attempt to pick up an item.
  3774. * Return:
  3775. * 0 = fail
  3776. * 1 = success
  3777. *------------------------------------------*/
  3778. int pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem)
  3779. {
  3780. int flag=0;
  3781. unsigned int tick = gettick();
  3782. struct party_data *p=NULL;
  3783. nullpo_ret(sd);
  3784. nullpo_ret(fitem);
  3785. if(!check_distance_bl(&fitem->bl, &sd->bl, 2) && sd->ud.skill_id!=BS_GREED)
  3786. return 0; // Distance is too far
  3787. if( sd->sc.cant.pickup )
  3788. return 0;
  3789. if (sd->status.party_id)
  3790. p = party_search(sd->status.party_id);
  3791. if(fitem->first_get_charid > 0 && fitem->first_get_charid != sd->status.char_id) {
  3792. struct map_session_data *first_sd = map_charid2sd(fitem->first_get_charid);
  3793. if(DIFF_TICK(tick,fitem->first_get_tick) < 0) {
  3794. if (!(p && p->party.item&1 &&
  3795. first_sd && first_sd->status.party_id == sd->status.party_id
  3796. ))
  3797. return 0;
  3798. }
  3799. else if(fitem->second_get_charid > 0 && fitem->second_get_charid != sd->status.char_id) {
  3800. struct map_session_data *second_sd = map_charid2sd(fitem->second_get_charid);
  3801. if(DIFF_TICK(tick, fitem->second_get_tick) < 0) {
  3802. if(!(p && p->party.item&1 &&
  3803. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  3804. (second_sd && second_sd->status.party_id == sd->status.party_id))
  3805. ))
  3806. return 0;
  3807. }
  3808. else if(fitem->third_get_charid > 0 && fitem->third_get_charid != sd->status.char_id){
  3809. struct map_session_data *third_sd = map_charid2sd(fitem->third_get_charid);
  3810. if(DIFF_TICK(tick,fitem->third_get_tick) < 0) {
  3811. if(!(p && p->party.item&1 &&
  3812. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  3813. (second_sd && second_sd->status.party_id == sd->status.party_id) ||
  3814. (third_sd && third_sd->status.party_id == sd->status.party_id))
  3815. ))
  3816. return 0;
  3817. }
  3818. }
  3819. }
  3820. }
  3821. //This function takes care of giving the item to whoever should have it, considering party-share options.
  3822. if ((flag = party_share_loot(p,sd,&fitem->item_data, fitem->first_get_charid))) {
  3823. clif_additem(sd,0,0,flag);
  3824. return 1;
  3825. }
  3826. //Display pickup animation.
  3827. pc_stop_attack(sd);
  3828. clif_takeitem(&sd->bl,&fitem->bl);
  3829. map_clearflooritem(&fitem->bl);
  3830. return 1;
  3831. }
  3832. /*==========================================
  3833. * Check if item is usable.
  3834. * Return:
  3835. * 0 = no
  3836. * 1 = yes
  3837. *------------------------------------------*/
  3838. int pc_isUseitem(struct map_session_data *sd,int n)
  3839. {
  3840. struct item_data *item;
  3841. int nameid;
  3842. nullpo_ret(sd);
  3843. item = sd->inventory_data[n];
  3844. nameid = sd->status.inventory[n].nameid;
  3845. if( item == NULL )
  3846. return 0;
  3847. //Not consumable item
  3848. if( item->type != IT_HEALING && item->type != IT_USABLE && item->type != IT_CASH )
  3849. return 0;
  3850. if( !item->script ) //if it has no script, you can't really consume it!
  3851. return 0;
  3852. if (pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL))
  3853. return 1;
  3854. if(map[sd->bl.m].flag.noitemconsumption) //consumable but mapflag prevent it
  3855. return 0;
  3856. //Prevent mass item usage. [Skotlex]
  3857. if( DIFF_TICK(sd->canuseitem_tick,gettick()) > 0 ||
  3858. (itemdb_iscashfood(nameid) && DIFF_TICK(sd->canusecashfood_tick,gettick()) > 0)
  3859. )
  3860. return 0;
  3861. if( (item->item_usage.flag&NOUSE_SITTING) && (pc_issit(sd) == 1) && (pc_get_group_level(sd) < item->item_usage.override) ) {
  3862. return 0; // You cannot use this item while sitting.
  3863. }
  3864. if (sd->state.storage_flag && item->type != IT_CASH) {
  3865. clif_colormes(sd, color_table[COLOR_RED], msg_txt(sd,388));
  3866. return 0; // You cannot use this item while storage is open.
  3867. }
  3868. switch( nameid ) {
  3869. case ITEMID_ANODYNE:
  3870. if( map_flag_gvg(sd->bl.m) )
  3871. return 0;
  3872. case ITEMID_ALOEBERA:
  3873. if( pc_issit(sd) )
  3874. return 0;
  3875. break;
  3876. case ITEMID_WING_OF_FLY:
  3877. case ITEMID_GIANT_FLY_WING:
  3878. if( map[sd->bl.m].flag.noteleport || map_flag_gvg(sd->bl.m) ) {
  3879. clif_skill_teleportmessage(sd,0);
  3880. return 0;
  3881. }
  3882. case ITEMID_WING_OF_BUTTERFLY:
  3883. case ITEMID_DUN_TELE_SCROLL1:
  3884. case ITEMID_DUN_TELE_SCROLL2:
  3885. case ITEMID_DUN_TELE_SCROLL3:
  3886. case ITEMID_WOB_RUNE:
  3887. case ITEMID_WOB_SCHWALTZ:
  3888. case ITEMID_WOB_RACHEL:
  3889. case ITEMID_WOB_LOCAL:
  3890. case ITEMID_SIEGE_TELEPORT_SCROLL:
  3891. if( sd->duel_group && !battle_config.duel_allow_teleport ) {
  3892. clif_displaymessage(sd->fd, msg_txt(sd,663));
  3893. return 0;
  3894. }
  3895. if( nameid != 601 && nameid != 12212 && map[sd->bl.m].flag.noreturn )
  3896. return 0;
  3897. break;
  3898. case ITEMID_BRANCH_OF_DEAD_TREE:
  3899. case ITEMID_RED_POUCH_OF_SURPRISE:
  3900. case ITEMID_BLOODY_DEAD_BRANCH:
  3901. case ITEMID_PORING_BOX:
  3902. case ITEMID_TREASURE_CHEST_SUMMONED_II:
  3903. if( map[sd->bl.m].flag.nobranch || map_flag_gvg(sd->bl.m) )
  3904. return 0;
  3905. break;
  3906. case ITEMID_BUBBLE_GUM:
  3907. case ITEMID_COMP_BUBBLE_GUM:
  3908. if( sd->sc.data[SC_ITEMBOOST] )
  3909. return 0;
  3910. break;
  3911. case ITEMID_BATTLE_MANUAL:
  3912. case ITEMID_COMP_BATTLE_MANUAL:
  3913. case ITEMID_THICK_BATTLE_MANUAL:
  3914. case ITEMID_NOBLE_NAMEPLATE:
  3915. case ITEMID_BATTLE_MANUAL25:
  3916. case ITEMID_BATTLE_MANUAL100:
  3917. case ITEMID_BATTLE_MANUAL300:
  3918. if( sd->sc.data[SC_EXPBOOST] )
  3919. return 0;
  3920. break;
  3921. case ITEMID_JOB_MANUAL50:
  3922. if( sd->sc.data[SC_JEXPBOOST] )
  3923. return 0;
  3924. break;
  3925. case ITEMID_MERCENARY_RED_POTION:
  3926. case ITEMID_MERCENARY_BLUE_POTION:
  3927. case ITEMID_M_CENTER_POTION:
  3928. case ITEMID_M_AWAKENING_POTION:
  3929. case ITEMID_M_BERSERK_POTION:
  3930. if( sd->md == NULL || sd->md->db == NULL )
  3931. return 0;
  3932. if (sd->md->sc.data[SC_BERSERK] || sd->md->sc.data[SC_SATURDAYNIGHTFEVER])
  3933. return 0;
  3934. if( nameid == ITEMID_M_AWAKENING_POTION && sd->md->db->lv < 40 )
  3935. return 0;
  3936. if( nameid == ITEMID_M_BERSERK_POTION && sd->md->db->lv < 80 )
  3937. return 0;
  3938. break;
  3939. case ITEMID_NEURALIZER:
  3940. if( !map[sd->bl.m].flag.reset )
  3941. return 0;
  3942. break;
  3943. }
  3944. if( nameid >= ITEMID_BOW_MERCENARY_SCROLL1 && nameid <= ITEMID_SPEARMERCENARY_SCROLL10 && sd->md != NULL )
  3945. return 0; // Mercenary Scrolls
  3946. /**
  3947. * Only Rune Knights may use runes
  3948. **/
  3949. if( itemdb_is_rune(nameid) && (sd->class_&MAPID_THIRDMASK) != MAPID_RUNE_KNIGHT )
  3950. return 0;
  3951. /**
  3952. * Only GCross may use poisons
  3953. **/
  3954. else if( itemdb_is_poison(nameid) && (sd->class_&MAPID_THIRDMASK) != MAPID_GUILLOTINE_CROSS )
  3955. return 0;
  3956. //Gender check
  3957. if(item->sex != 2 && sd->status.sex != item->sex)
  3958. return 0;
  3959. //Required level check
  3960. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  3961. return 0;
  3962. #ifdef RENEWAL
  3963. if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
  3964. return 0;
  3965. #endif
  3966. //Not equipable by class. [Skotlex]
  3967. if (!(
  3968. (1<<(sd->class_&MAPID_BASEMASK)) &
  3969. (item->class_base[sd->class_&JOBL_2_1?1:(sd->class_&JOBL_2_2?2:0)])
  3970. ))
  3971. return 0;
  3972. if (sd->sc.count && (
  3973. sd->sc.data[SC_BERSERK] || sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  3974. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF) ||
  3975. sd->sc.data[SC_TRICKDEAD] ||
  3976. sd->sc.data[SC_HIDING] ||
  3977. sd->sc.data[SC__SHADOWFORM] ||
  3978. sd->sc.data[SC__INVISIBILITY] ||
  3979. sd->sc.data[SC__MANHOLE] ||
  3980. sd->sc.data[SC_KAGEHUMI] ||
  3981. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM) ||
  3982. sd->sc.data[SC_HEAT_BARREL_AFTER]))
  3983. return 0;
  3984. if (!pc_isItemClass(sd,item))
  3985. return 0;
  3986. //Dead Branch & Bloody Branch & Porings Box
  3987. if( nameid == ITEMID_BRANCH_OF_DEAD_TREE || nameid == ITEMID_BLOODY_DEAD_BRANCH || nameid == ITEMID_PORING_BOX || nameid == ITEMID_TREASURE_CHEST_SUMMONED_II )
  3988. log_branch(sd);
  3989. return 1;
  3990. }
  3991. /*==========================================
  3992. * Last checks to use an item.
  3993. * Return:
  3994. * 0 = fail
  3995. * 1 = success
  3996. *------------------------------------------*/
  3997. int pc_useitem(struct map_session_data *sd,int n)
  3998. {
  3999. unsigned int tick = gettick();
  4000. int amount, nameid;
  4001. struct script_code *script;
  4002. struct item item;
  4003. struct item_data *id;
  4004. nullpo_ret(sd);
  4005. if( sd->npc_id ){
  4006. #ifdef RENEWAL
  4007. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  4008. return 0;
  4009. #else
  4010. if( !sd->npc_item_flag )
  4011. return 0;
  4012. #endif
  4013. }
  4014. item = sd->status.inventory[n];
  4015. id = sd->inventory_data[n];
  4016. if (item.nameid <= 0 || item.amount <= 0)
  4017. return 0;
  4018. if( !pc_isUseitem(sd,n) )
  4019. return 0;
  4020. // Store information for later use before it is lost (via pc_delitem) [Paradox924X]
  4021. nameid = id->nameid;
  4022. if (nameid != ITEMID_NAUTHIZ && sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  4023. return 0;
  4024. /* Items with delayed consume are not meant to work while in mounts except reins of mount(12622) */
  4025. if( id->flag.delay_consume ) {
  4026. if( nameid != ITEMID_REINS_OF_MOUNT && sd->sc.data[SC_ALL_RIDING] )
  4027. return 0;
  4028. else if( pc_issit(sd) )
  4029. return 0;
  4030. }
  4031. //Since most delay-consume items involve using a "skill-type" target cursor,
  4032. //perform a skill-use check before going through. [Skotlex]
  4033. //resurrection was picked as testing skill, as a non-offensive, generic skill, it will do.
  4034. //FIXME: Is this really needed here? It'll be checked in unit.c after all and this prevents skill items using when silenced [Inkfish]
  4035. if( id->flag.delay_consume && ( sd->ud.skilltimer != INVALID_TIMER /*|| !status_check_skilluse(&sd->bl, &sd->bl, ALL_RESURRECTION, 0)*/ ) )
  4036. return 0;
  4037. if( id->delay > 0 && !pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL) ) {
  4038. int i;
  4039. ARR_FIND(0, MAX_ITEMDELAYS, i, sd->item_delay[i].nameid == nameid );
  4040. if( i == MAX_ITEMDELAYS ) /* item not found. try first empty now */
  4041. ARR_FIND(0, MAX_ITEMDELAYS, i, !sd->item_delay[i].nameid );
  4042. if( i < MAX_ITEMDELAYS ) {
  4043. if( sd->item_delay[i].nameid ) {// found
  4044. if( DIFF_TICK(sd->item_delay[i].tick, tick) > 0 ) {
  4045. int e_tick = DIFF_TICK(sd->item_delay[i].tick, tick)/1000;
  4046. char e_msg[100];
  4047. if( e_tick > 99 )
  4048. sprintf(e_msg,msg_txt(sd,379), //Item Failed. [%s] is cooling down. Wait %.1f minutes.
  4049. itemdb_jname(item.nameid),
  4050. (double)e_tick / 60);
  4051. else
  4052. sprintf(e_msg,msg_txt(sd,380), //Item Failed. [%s] is cooling down. Wait %d seconds.
  4053. itemdb_jname(item.nameid),
  4054. e_tick+1);
  4055. clif_colormes(sd,color_table[COLOR_RED],e_msg);
  4056. return 0; // Delay has not expired yet
  4057. }
  4058. } else {// not yet used item (all slots are initially empty)
  4059. sd->item_delay[i].nameid = nameid;
  4060. }
  4061. if( !(nameid == ITEMID_REINS_OF_MOUNT && sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR)) )
  4062. sd->item_delay[i].tick = tick + sd->inventory_data[n]->delay;
  4063. } else {// should not happen
  4064. ShowError("pc_useitem: Exceeded item delay array capacity! (nameid=%d, char_id=%d)\n", nameid, sd->status.char_id);
  4065. }
  4066. //clean up used delays so we can give room for more
  4067. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  4068. if( DIFF_TICK(sd->item_delay[i].tick, tick) <= 0 ) {
  4069. sd->item_delay[i].tick = 0;
  4070. sd->item_delay[i].nameid = 0;
  4071. }
  4072. }
  4073. }
  4074. /* on restricted maps the item is consumed but the effect is not used */
  4075. if (!pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL) && itemdb_isNoEquip(id,sd->bl.m)) {
  4076. if( battle_config.allow_consume_restricted_item && !id->flag.delay_consume ) { //need confirmation for delayed consumption items
  4077. clif_useitemack(sd,n,item.amount-1,true);
  4078. pc_delitem(sd,n,1,1,0,LOG_TYPE_CONSUME);
  4079. }
  4080. return 0;/* regardless, effect is not run */
  4081. }
  4082. sd->itemid = item.nameid;
  4083. sd->itemindex = n;
  4084. if(sd->catch_target_class != -1) //Abort pet catching.
  4085. sd->catch_target_class = -1;
  4086. amount = item.amount;
  4087. script = id->script;
  4088. //Check if the item is to be consumed immediately [Skotlex]
  4089. if (id->flag.delay_consume)
  4090. clif_useitemack(sd, n, amount, true);
  4091. else
  4092. {
  4093. if( item.expire_time == 0 && nameid != ITEMID_REINS_OF_MOUNT )
  4094. {
  4095. clif_useitemack(sd, n, amount - 1, true);
  4096. pc_delitem(sd, n, 1, 1, 0, LOG_TYPE_CONSUME); // Rental Usable Items are not deleted until expiration
  4097. }
  4098. else
  4099. clif_useitemack(sd, n, 0, false);
  4100. }
  4101. if(item.card[0]==CARD0_CREATE &&
  4102. pc_famerank(MakeDWord(item.card[2],item.card[3]), MAPID_ALCHEMIST))
  4103. {
  4104. potion_flag = 2; // Famous player's potions have 50% more efficiency
  4105. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_ROGUE)
  4106. potion_flag = 3; //Even more effective potions.
  4107. }
  4108. //Update item use time.
  4109. sd->canuseitem_tick = tick + battle_config.item_use_interval;
  4110. if( itemdb_iscashfood(nameid) )
  4111. sd->canusecashfood_tick = tick + battle_config.cashfood_use_interval;
  4112. run_script(script,0,sd->bl.id,fake_nd->bl.id);
  4113. potion_flag = 0;
  4114. return 1;
  4115. }
  4116. /*==========================================
  4117. * Add item on cart for given index.
  4118. * Return:
  4119. * 0 = success
  4120. * 1 = fail
  4121. *------------------------------------------*/
  4122. int pc_cart_additem(struct map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type)
  4123. {
  4124. struct item_data *data;
  4125. int i,w;
  4126. nullpo_retr(1, sd);
  4127. nullpo_retr(1, item_data);
  4128. if(item_data->nameid <= 0 || amount <= 0)
  4129. return 1;
  4130. data = itemdb_search(item_data->nameid);
  4131. if( data->stack.cart && amount > data->stack.amount )
  4132. {// item stack limitation
  4133. return 1;
  4134. }
  4135. if( !itemdb_cancartstore(item_data, pc_get_group_level(sd)) || (item_data->bound > 1 && !pc_can_give_bounded_items(sd)))
  4136. { // Check item trade restrictions [Skotlex]
  4137. clif_displaymessage (sd->fd, msg_txt(sd,264));
  4138. return 1;
  4139. }
  4140. if( (w = data->weight*amount) + sd->cart_weight > sd->cart_weight_max )
  4141. return 1;
  4142. i = MAX_CART;
  4143. if( itemdb_isstackable2(data) && !item_data->expire_time )
  4144. {
  4145. ARR_FIND( 0, MAX_CART, i,
  4146. sd->status.cart[i].nameid == item_data->nameid && sd->status.cart[i].bound == item_data->bound &&
  4147. sd->status.cart[i].card[0] == item_data->card[0] && sd->status.cart[i].card[1] == item_data->card[1] &&
  4148. sd->status.cart[i].card[2] == item_data->card[2] && sd->status.cart[i].card[3] == item_data->card[3] );
  4149. };
  4150. if( i < MAX_CART )
  4151. {// item already in cart, stack it
  4152. if( amount > MAX_AMOUNT - sd->status.cart[i].amount || ( data->stack.cart && amount > data->stack.amount - sd->status.cart[i].amount ) )
  4153. return 2; // no slot
  4154. sd->status.cart[i].amount+=amount;
  4155. clif_cart_additem(sd,i,amount,0);
  4156. }
  4157. else
  4158. {// item not stackable or not present, add it
  4159. ARR_FIND( 0, MAX_CART, i, sd->status.cart[i].nameid == 0 );
  4160. if( i == MAX_CART )
  4161. return 2; // no slot
  4162. memcpy(&sd->status.cart[i],item_data,sizeof(sd->status.cart[0]));
  4163. sd->status.cart[i].amount=amount;
  4164. sd->cart_num++;
  4165. clif_cart_additem(sd,i,amount,0);
  4166. }
  4167. sd->status.cart[i].favorite = 0;/* clear */
  4168. log_pick_pc(sd, log_type, amount, &sd->status.cart[i]);
  4169. sd->cart_weight += w;
  4170. clif_updatestatus(sd,SP_CARTINFO);
  4171. return 0;
  4172. }
  4173. /*==========================================
  4174. * Delete item on cart for given index.
  4175. * Return:
  4176. * 0 = success
  4177. * 1 = fail
  4178. *------------------------------------------*/
  4179. int pc_cart_delitem(struct map_session_data *sd,int n,int amount,int type,e_log_pick_type log_type)
  4180. {
  4181. nullpo_retr(1, sd);
  4182. if(sd->status.cart[n].nameid==0 ||
  4183. sd->status.cart[n].amount<amount)
  4184. return 1;
  4185. log_pick_pc(sd, log_type, -amount, &sd->status.cart[n]);
  4186. sd->status.cart[n].amount -= amount;
  4187. sd->cart_weight -= itemdb_weight(sd->status.cart[n].nameid)*amount ;
  4188. if(sd->status.cart[n].amount <= 0){
  4189. memset(&sd->status.cart[n],0,sizeof(sd->status.cart[0]));
  4190. sd->cart_num--;
  4191. }
  4192. if(!type) {
  4193. clif_cart_delitem(sd,n,amount);
  4194. clif_updatestatus(sd,SP_CARTINFO);
  4195. }
  4196. return 0;
  4197. }
  4198. /*==========================================
  4199. * Transfer item from inventory to cart.
  4200. * Return:
  4201. * 0 = fail
  4202. * 1 = succes
  4203. *------------------------------------------*/
  4204. int pc_putitemtocart(struct map_session_data *sd,int idx,int amount)
  4205. {
  4206. struct item *item_data;
  4207. short flag;
  4208. nullpo_ret(sd);
  4209. if (idx < 0 || idx >= MAX_INVENTORY) //Invalid index check [Skotlex]
  4210. return 1;
  4211. item_data = &sd->status.inventory[idx];
  4212. if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
  4213. return 1;
  4214. if( (flag = pc_cart_additem(sd,item_data,amount,LOG_TYPE_NONE)) == 0 )
  4215. return pc_delitem(sd,idx,amount,0,5,LOG_TYPE_NONE);
  4216. return flag;
  4217. }
  4218. /*==========================================
  4219. * Get number of item in cart.
  4220. * Return:
  4221. -1 = itemid not found or no amount found
  4222. x = remaining itemid on cart after get
  4223. *------------------------------------------*/
  4224. int pc_cartitem_amount(struct map_session_data* sd, int idx, int amount)
  4225. {
  4226. struct item* item_data;
  4227. nullpo_retr(-1, sd);
  4228. item_data = &sd->status.cart[idx];
  4229. if( item_data->nameid == 0 || item_data->amount == 0 )
  4230. return -1;
  4231. return item_data->amount - amount;
  4232. }
  4233. /*==========================================
  4234. * Retrieve an item at index idx from cart.
  4235. * Return:
  4236. * 0 = player not found or (FIXME) succes (from pc_cart_delitem)
  4237. * 1 = failure
  4238. *------------------------------------------*/
  4239. int pc_getitemfromcart(struct map_session_data *sd,int idx,int amount)
  4240. {
  4241. struct item *item_data;
  4242. int flag;
  4243. nullpo_ret(sd);
  4244. if (idx < 0 || idx >= MAX_CART) //Invalid index check [Skotlex]
  4245. return 1;
  4246. item_data=&sd->status.cart[idx];
  4247. if(item_data->nameid==0 || amount < 1 || item_data->amount<amount || sd->state.vending )
  4248. return 1;
  4249. if((flag = pc_additem(sd,item_data,amount,LOG_TYPE_NONE)) == 0)
  4250. return pc_cart_delitem(sd,idx,amount,0,LOG_TYPE_NONE);
  4251. clif_additem(sd,0,0,flag);
  4252. return 1;
  4253. }
  4254. /*==========================================
  4255. * Bound Item Check
  4256. * Type:
  4257. * 1 Account Bound
  4258. * 2 Guild Bound
  4259. * 3 Party Bound
  4260. * 4 Character Bound
  4261. *------------------------------------------*/
  4262. int pc_bound_chk(TBL_PC *sd,int type,int *idxlist)
  4263. {
  4264. int i=0, j=0;
  4265. for(i=0;i<MAX_INVENTORY;i++){
  4266. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0 && sd->status.inventory[i].bound == type) {
  4267. idxlist[j] = i;
  4268. j++;
  4269. }
  4270. }
  4271. return j;
  4272. }
  4273. /*==========================================
  4274. * Display item stolen msg to player sd
  4275. *------------------------------------------*/
  4276. int pc_show_steal(struct block_list *bl,va_list ap)
  4277. {
  4278. struct map_session_data *sd;
  4279. int itemid;
  4280. struct item_data *item=NULL;
  4281. char output[100];
  4282. sd=va_arg(ap,struct map_session_data *);
  4283. itemid=va_arg(ap,int);
  4284. if((item=itemdb_exists(itemid))==NULL)
  4285. sprintf(output,"%s stole an Unknown Item (id: %i).",sd->status.name, itemid);
  4286. else
  4287. sprintf(output,"%s stole %s.",sd->status.name,item->jname);
  4288. clif_displaymessage( ((struct map_session_data *)bl)->fd, output);
  4289. return 0;
  4290. }
  4291. /*==========================================
  4292. * Steal an item from bl (mob).
  4293. * Return:
  4294. * 0 = fail
  4295. * 1 = succes
  4296. *------------------------------------------*/
  4297. int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv)
  4298. {
  4299. int i,itemid,flag;
  4300. double rate;
  4301. struct status_data *sd_status, *md_status;
  4302. struct mob_data *md;
  4303. struct item tmp_item;
  4304. if(!sd || !bl || bl->type!=BL_MOB)
  4305. return 0;
  4306. md = (TBL_MOB *)bl;
  4307. if(md->state.steal_flag == UCHAR_MAX || ( md->sc.opt1 && md->sc.opt1 != OPT1_BURNING && md->sc.opt1 != OPT1_CRYSTALIZE ) ) //already stolen from / status change check
  4308. return 0;
  4309. sd_status= status_get_status_data(&sd->bl);
  4310. md_status= status_get_status_data(bl);
  4311. if( md->master_id || md_status->mode&MD_BOSS || mob_is_treasure(md) ||
  4312. map[bl->m].flag.nomobloot || // check noloot map flag [Lorky]
  4313. (battle_config.skill_steal_max_tries && //Reached limit of steal attempts. [Lupus]
  4314. md->state.steal_flag++ >= battle_config.skill_steal_max_tries)
  4315. ) { //Can't steal from
  4316. md->state.steal_flag = UCHAR_MAX;
  4317. return 0;
  4318. }
  4319. // base skill success chance (percentual)
  4320. rate = (sd_status->dex - md_status->dex)/2 + skill_lv*6 + 4;
  4321. rate += sd->bonus.add_steal_rate;
  4322. if( rate < 1 )
  4323. return 0;
  4324. // Try dropping one item, in the order from first to last possible slot.
  4325. // Droprate is affected by the skill success rate.
  4326. for( i = 0; i < MAX_STEAL_DROP; i++ )
  4327. if( md->db->dropitem[i].nameid > 0 && itemdb_exists(md->db->dropitem[i].nameid) && rnd() % 10000 < md->db->dropitem[i].p * rate/100. )
  4328. break;
  4329. if( i == MAX_STEAL_DROP )
  4330. return 0;
  4331. itemid = md->db->dropitem[i].nameid;
  4332. memset(&tmp_item,0,sizeof(tmp_item));
  4333. tmp_item.nameid = itemid;
  4334. tmp_item.amount = 1;
  4335. tmp_item.identify = itemdb_isidentified(itemid);
  4336. flag = pc_additem(sd,&tmp_item,1,LOG_TYPE_PICKDROP_PLAYER);
  4337. //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?
  4338. md->state.steal_flag = UCHAR_MAX; //you can't steal from this mob any more
  4339. if(flag) { //Failed to steal due to overweight
  4340. clif_additem(sd,0,0,flag);
  4341. return 0;
  4342. }
  4343. if(battle_config.show_steal_in_same_party)
  4344. party_foreachsamemap(pc_show_steal,sd,AREA_SIZE,sd,tmp_item.nameid);
  4345. //Logs items, Stolen from mobs [Lupus]
  4346. log_pick_mob(md, LOG_TYPE_STEAL, -1, &tmp_item);
  4347. //A Rare Steal Global Announce by Lupus
  4348. if(md->db->dropitem[i].p<=battle_config.rare_drop_announce) {
  4349. struct item_data *i_data;
  4350. char message[128];
  4351. i_data = itemdb_search(itemid);
  4352. sprintf (message, msg_txt(sd,542), (sd->status.name != NULL)?sd->status.name :"GM", md->db->jname, i_data->jname, (float)md->db->dropitem[i].p/100);
  4353. //MSG: "'%s' stole %s's %s (chance: %0.02f%%)"
  4354. intif_broadcast(message,strlen(message)+1,0);
  4355. }
  4356. return 1;
  4357. }
  4358. /*==========================================
  4359. * Stole zeny from bl (mob)
  4360. * return
  4361. * 0 = fail
  4362. * 1 = success
  4363. *------------------------------------------*/
  4364. int pc_steal_coin(struct map_session_data *sd,struct block_list *target)
  4365. {
  4366. int rate,skill;
  4367. struct mob_data *md;
  4368. if(!sd || !target || target->type != BL_MOB)
  4369. return 0;
  4370. md = (TBL_MOB*)target;
  4371. if( md->state.steal_coin_flag || md->sc.data[SC_STONE] || md->sc.data[SC_FREEZE] || md->status.mode&MD_BOSS )
  4372. return 0;
  4373. if( mob_is_treasure(md) )
  4374. return 0;
  4375. // FIXME: This formula is either custom or outdated.
  4376. skill = pc_checkskill(sd,RG_STEALCOIN)*10;
  4377. rate = skill + (sd->status.base_level - md->level)*3 + sd->battle_status.dex*2 + sd->battle_status.luk*2;
  4378. if(rnd()%1000 < rate)
  4379. {
  4380. int amount = md->level*10 + rnd()%100;
  4381. pc_getzeny(sd, amount, LOG_TYPE_STEAL, NULL);
  4382. md->state.steal_coin_flag = 1;
  4383. return 1;
  4384. }
  4385. return 0;
  4386. }
  4387. /*==========================================
  4388. * Set's a player position.
  4389. * Return values:
  4390. * 0 - Success.
  4391. * 1 - Invalid map index.
  4392. * 2 - Map not in this map-server, and failed to locate alternate map-server.
  4393. *------------------------------------------*/
  4394. int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype)
  4395. {
  4396. int16 m;
  4397. nullpo_ret(sd);
  4398. if( !mapindex || !mapindex_id2name(mapindex) ) {
  4399. ShowDebug("pc_setpos: Passed mapindex(%d) is invalid!\n", mapindex);
  4400. return 1;
  4401. }
  4402. if( pc_isdead(sd) ) { //Revive dead people before warping them
  4403. pc_setstand(sd);
  4404. pc_setrestartvalue(sd,1);
  4405. }
  4406. m = map_mapindex2mapid(mapindex);
  4407. sd->state.changemap = (sd->mapindex != mapindex);
  4408. sd->state.warping = 1;
  4409. if(sd->status.party_id && map[sd->bl.m].instance_id && sd->state.changemap && !map[m].instance_id) {
  4410. struct party_data *p;
  4411. if((p = party_search(sd->status.party_id)) != NULL && p->instance_id )
  4412. instance_delusers(p->instance_id);
  4413. }
  4414. if( sd->state.changemap ) { // Misc map-changing settings
  4415. int i;
  4416. sd->state.pmap = sd->bl.m;
  4417. if (sd->sc.count) { // Cancel some map related stuff.
  4418. if (sd->sc.data[SC_JAILED])
  4419. return 1; //You may not get out!
  4420. status_change_end(&sd->bl, SC_BOSSMAPINFO, INVALID_TIMER);
  4421. status_change_end(&sd->bl, SC_WARM, INVALID_TIMER);
  4422. status_change_end(&sd->bl, SC_SUN_COMFORT, INVALID_TIMER);
  4423. status_change_end(&sd->bl, SC_MOON_COMFORT, INVALID_TIMER);
  4424. status_change_end(&sd->bl, SC_STAR_COMFORT, INVALID_TIMER);
  4425. status_change_end(&sd->bl, SC_MIRACLE, INVALID_TIMER);
  4426. if (sd->sc.data[SC_KNOWLEDGE]) {
  4427. struct status_change_entry *sce = sd->sc.data[SC_KNOWLEDGE];
  4428. if (sce->timer != INVALID_TIMER)
  4429. delete_timer(sce->timer, status_change_timer);
  4430. sce->timer = add_timer(gettick() + skill_get_time(SG_KNOWLEDGE, sce->val1), status_change_timer, sd->bl.id, SC_KNOWLEDGE);
  4431. }
  4432. status_change_end(&sd->bl, SC_PROPERTYWALK, INVALID_TIMER);
  4433. status_change_end(&sd->bl, SC_CLOAKING, INVALID_TIMER);
  4434. status_change_end(&sd->bl, SC_CLOAKINGEXCEED, INVALID_TIMER);
  4435. }
  4436. for( i = 0; i < EQI_MAX; i++ ) {
  4437. if( sd->equip_index[ i ] >= 0 )
  4438. if( !pc_isequip( sd , sd->equip_index[ i ] ) )
  4439. pc_unequipitem( sd , sd->equip_index[ i ] , 2 );
  4440. }
  4441. if (battle_config.clear_unit_onwarp&BL_PC)
  4442. skill_clear_unitgroup(&sd->bl);
  4443. party_send_dot_remove(sd); //minimap dot fix [Kevin]
  4444. guild_send_dot_remove(sd);
  4445. bg_send_dot_remove(sd);
  4446. if (sd->regen.state.gc)
  4447. sd->regen.state.gc = 0;
  4448. // make sure vending is allowed here
  4449. if (sd->state.vending && map[m].flag.novending) {
  4450. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  4451. vending_closevending(sd);
  4452. }
  4453. channel_pcquit(sd,4); //quit map chan
  4454. }
  4455. if( m < 0 )
  4456. {
  4457. uint32 ip;
  4458. uint16 port;
  4459. //if can't find any map-servers, just abort setting position.
  4460. if(!sd->mapindex || map_mapname2ipport(mapindex,&ip,&port))
  4461. return 2;
  4462. if (sd->npc_id)
  4463. npc_event_dequeue(sd);
  4464. npc_script_event(sd, NPCE_LOGOUT);
  4465. //remove from map, THEN change x/y coordinates
  4466. unit_remove_map_pc(sd,clrtype);
  4467. sd->mapindex = mapindex;
  4468. sd->bl.x=x;
  4469. sd->bl.y=y;
  4470. pc_clean_skilltree(sd);
  4471. chrif_save(sd,2);
  4472. chrif_changemapserver(sd, ip, (short)port);
  4473. //Free session data from this map server [Kevin]
  4474. unit_free_pc(sd);
  4475. return 0;
  4476. }
  4477. if( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys )
  4478. {
  4479. 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);
  4480. x = y = 0; // make it random
  4481. }
  4482. if( x == 0 && y == 0 )
  4483. {// pick a random walkable cell
  4484. do {
  4485. x=rnd()%(map[m].xs-2)+1;
  4486. y=rnd()%(map[m].ys-2)+1;
  4487. } while(map_getcell(m,x,y,CELL_CHKNOPASS));
  4488. }
  4489. if (sd->state.vending && map_getcell(m,x,y,CELL_CHKNOVENDING)) {
  4490. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  4491. vending_closevending(sd);
  4492. }
  4493. if(sd->bl.prev != NULL){
  4494. unit_remove_map_pc(sd,clrtype);
  4495. clif_changemap(sd,m,x,y); // [MouseJstr]
  4496. } else if(sd->state.active) //Tag player for rewarping after map-loading is done. [Skotlex]
  4497. sd->state.rewarp = 1;
  4498. sd->mapindex = mapindex;
  4499. sd->bl.m = m;
  4500. sd->bl.x = sd->ud.to_x = x;
  4501. sd->bl.y = sd->ud.to_y = y;
  4502. if( sd->status.guild_id > 0 && map[m].flag.gvg_castle )
  4503. { // Increased guild castle regen [Valaris]
  4504. struct guild_castle *gc = guild_mapindex2gc(sd->mapindex);
  4505. if(gc && gc->guild_id == sd->status.guild_id)
  4506. sd->regen.state.gc = 1;
  4507. }
  4508. if( sd->status.pet_id > 0 && sd->pd && sd->pd->pet.intimate > 0 )
  4509. {
  4510. sd->pd->bl.m = m;
  4511. sd->pd->bl.x = sd->pd->ud.to_x = x;
  4512. sd->pd->bl.y = sd->pd->ud.to_y = y;
  4513. sd->pd->ud.dir = sd->ud.dir;
  4514. }
  4515. if( merc_is_hom_active(sd->hd) )
  4516. {
  4517. sd->hd->bl.m = m;
  4518. sd->hd->bl.x = sd->hd->ud.to_x = x;
  4519. sd->hd->bl.y = sd->hd->ud.to_y = y;
  4520. sd->hd->ud.dir = sd->ud.dir;
  4521. }
  4522. if( sd->md )
  4523. {
  4524. sd->md->bl.m = m;
  4525. sd->md->bl.x = sd->md->ud.to_x = x;
  4526. sd->md->bl.y = sd->md->ud.to_y = y;
  4527. sd->md->ud.dir = sd->ud.dir;
  4528. }
  4529. pc_cell_basilica(sd);
  4530. return 0;
  4531. }
  4532. /*==========================================
  4533. * Warp player sd to random location on current map.
  4534. * May fail if no walkable cell found (1000 attempts).
  4535. * Return:
  4536. * 0 = fail or FIXME success (from pc_setpos)
  4537. * x(1|2) = fail
  4538. *------------------------------------------*/
  4539. int pc_randomwarp(struct map_session_data *sd, clr_type type)
  4540. {
  4541. int x,y,i=0;
  4542. int16 m;
  4543. nullpo_ret(sd);
  4544. m=sd->bl.m;
  4545. if (map[sd->bl.m].flag.noteleport) //Teleport forbidden
  4546. return 0;
  4547. do{
  4548. x=rnd()%(map[m].xs-2)+1;
  4549. y=rnd()%(map[m].ys-2)+1;
  4550. }while(map_getcell(m,x,y,CELL_CHKNOPASS) && (i++)<1000 );
  4551. if (i < 1000)
  4552. return pc_setpos(sd,map[sd->bl.m].index,x,y,type);
  4553. return 0;
  4554. }
  4555. /*==========================================
  4556. * Records a memo point at sd's current position
  4557. * pos - entry to replace, (-1: shift oldest entry out)
  4558. *------------------------------------------*/
  4559. int pc_memo(struct map_session_data* sd, int pos)
  4560. {
  4561. int skill;
  4562. nullpo_ret(sd);
  4563. // check mapflags
  4564. if( sd->bl.m >= 0 && (map[sd->bl.m].flag.nomemo || map[sd->bl.m].flag.nowarpto) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE) ) {
  4565. clif_skill_teleportmessage(sd, 1); // "Saved point cannot be memorized."
  4566. return 0;
  4567. }
  4568. // check inputs
  4569. if( pos < -1 || pos >= MAX_MEMOPOINTS )
  4570. return 0; // invalid input
  4571. // check required skill level
  4572. skill = pc_checkskill(sd, AL_WARP);
  4573. if( skill < 1 ) {
  4574. clif_skill_memomessage(sd,2); // "You haven't learned Warp."
  4575. return 0;
  4576. }
  4577. if( skill < 2 || skill - 2 < pos ) {
  4578. clif_skill_memomessage(sd,1); // "Skill Level is not high enough."
  4579. return 0;
  4580. }
  4581. if( pos == -1 )
  4582. {
  4583. int i;
  4584. // prevent memo-ing the same map multiple times
  4585. ARR_FIND( 0, MAX_MEMOPOINTS, i, sd->status.memo_point[i].map == map_id2index(sd->bl.m) );
  4586. memmove(&sd->status.memo_point[1], &sd->status.memo_point[0], (min(i,MAX_MEMOPOINTS-1))*sizeof(struct point));
  4587. pos = 0;
  4588. }
  4589. if( map[sd->bl.m].instance_id ) {
  4590. clif_displaymessage( sd->fd, msg_txt(sd,384) ); // You cannot create a memo in an instance.
  4591. return 0;
  4592. }
  4593. sd->status.memo_point[pos].map = map_id2index(sd->bl.m);
  4594. sd->status.memo_point[pos].x = sd->bl.x;
  4595. sd->status.memo_point[pos].y = sd->bl.y;
  4596. clif_skill_memomessage(sd, 0);
  4597. return 1;
  4598. }
  4599. //
  4600. // Skills
  4601. //
  4602. /*==========================================
  4603. * Return player sd skill_lv learned for given skill
  4604. *------------------------------------------*/
  4605. int pc_checkskill(struct map_session_data *sd,uint16 skill_id)
  4606. {
  4607. if(sd == NULL) return 0;
  4608. if( skill_id >= GD_SKILLBASE && skill_id < GD_MAX ) {
  4609. struct guild *g;
  4610. if( sd->status.guild_id>0 && (g=sd->guild)!=NULL)
  4611. return guild_checkskill(g,skill_id);
  4612. return 0;
  4613. } else if(skill_id >= ARRAYLENGTH(sd->status.skill) ) {
  4614. ShowError("pc_checkskill: Invalid skill id %d (char_id=%d).\n", skill_id, sd->status.char_id);
  4615. return 0;
  4616. }
  4617. if(sd->status.skill[skill_id].id == skill_id)
  4618. return (sd->status.skill[skill_id].lv);
  4619. return 0;
  4620. }
  4621. /**
  4622. * Chk if we still have the correct weapon to continue the skill (actually status)
  4623. * If not ending it
  4624. * @param sd
  4625. * @return 0:error, 1:check done
  4626. */
  4627. static void pc_checkallowskill(struct map_session_data *sd)
  4628. {
  4629. const enum sc_type scw_list[] = {
  4630. SC_TWOHANDQUICKEN,
  4631. SC_ONEHAND,
  4632. SC_AURABLADE,
  4633. SC_PARRYING,
  4634. SC_SPEARQUICKEN,
  4635. SC_ADRENALINE,
  4636. SC_ADRENALINE2,
  4637. SC_DANCING,
  4638. SC_GATLINGFEVER,
  4639. SC_FEARBREEZE
  4640. };
  4641. uint8 i;
  4642. nullpo_retv(sd);
  4643. if(!sd->sc.count)
  4644. return;
  4645. for (i = 0; i < ARRAYLENGTH(scw_list); i++)
  4646. { // Skills requiring specific weapon types
  4647. if( scw_list[i] == SC_DANCING && !battle_config.dancing_weaponswitch_fix )
  4648. continue;
  4649. if(sd->sc.data[scw_list[i]] &&
  4650. !pc_check_weapontype(sd,skill_get_weapontype(status_sc2skill(scw_list[i]))))
  4651. status_change_end(&sd->bl, scw_list[i], INVALID_TIMER);
  4652. }
  4653. if(sd->sc.data[SC_SPURT] && sd->status.weapon)
  4654. // Spurt requires bare hands (feet, in fact xD)
  4655. status_change_end(&sd->bl, SC_SPURT, INVALID_TIMER);
  4656. if(sd->status.shield <= 0) { // Skills requiring a shield
  4657. const enum sc_type scs_list[] = {
  4658. SC_AUTOGUARD,
  4659. SC_DEFENDER,
  4660. SC_REFLECTSHIELD,
  4661. SC_REFLECTDAMAGE
  4662. };
  4663. for (i = 0; i < ARRAYLENGTH(scs_list); i++)
  4664. if(sd->sc.data[scs_list[i]])
  4665. status_change_end(&sd->bl, scs_list[i], INVALID_TIMER);
  4666. }
  4667. }
  4668. /*==========================================
  4669. * Return equiped itemid? on player sd at pos
  4670. * Return
  4671. * -1 : mean nothing equiped
  4672. * idx : (this index could be used in inventory to found item_data)
  4673. *------------------------------------------*/
  4674. short pc_checkequip(struct map_session_data *sd,int pos)
  4675. {
  4676. uint8 i;
  4677. nullpo_retr(-1, sd);
  4678. for(i=0;i<EQI_MAX;i++){
  4679. if(pos & equip_pos[i])
  4680. return sd->equip_index[i];
  4681. }
  4682. return -1;
  4683. }
  4684. /*==========================================
  4685. * Check if sd as nameid equiped somewhere
  4686. * @sd : the player session
  4687. * @nameid : id of the item to check
  4688. * @min : : see pc.h enum equip_index from ? to @max
  4689. * @max : see pc.h enum equip_index for @min to ?
  4690. * -return true,false
  4691. *------------------------------------------*/
  4692. bool pc_checkequip2(struct map_session_data *sd,int nameid, int min, int max){
  4693. int i;
  4694. for(i=min;i<max;i++){
  4695. if(equip_pos[i]){
  4696. int idx = sd->equip_index[i];
  4697. if (sd->status.inventory[idx].nameid == nameid)
  4698. return true;
  4699. }
  4700. }
  4701. return false;
  4702. }
  4703. /*==========================================
  4704. * Convert's from the client's lame Job ID system
  4705. * to the map server's 'makes sense' system. [Skotlex]
  4706. *------------------------------------------*/
  4707. int pc_jobid2mapid(unsigned short b_class)
  4708. {
  4709. switch(b_class)
  4710. {
  4711. //Novice And 1-1 Jobs
  4712. case JOB_NOVICE: return MAPID_NOVICE;
  4713. case JOB_SWORDMAN: return MAPID_SWORDMAN;
  4714. case JOB_MAGE: return MAPID_MAGE;
  4715. case JOB_ARCHER: return MAPID_ARCHER;
  4716. case JOB_ACOLYTE: return MAPID_ACOLYTE;
  4717. case JOB_MERCHANT: return MAPID_MERCHANT;
  4718. case JOB_THIEF: return MAPID_THIEF;
  4719. case JOB_TAEKWON: return MAPID_TAEKWON;
  4720. case JOB_WEDDING: return MAPID_WEDDING;
  4721. case JOB_GUNSLINGER: return MAPID_GUNSLINGER;
  4722. case JOB_NINJA: return MAPID_NINJA;
  4723. case JOB_XMAS: return MAPID_XMAS;
  4724. case JOB_SUMMER: return MAPID_SUMMER;
  4725. case JOB_HANBOK: return MAPID_HANBOK;
  4726. case JOB_OKTOBERFEST: return MAPID_OKTOBERFEST;
  4727. case JOB_GANGSI: return MAPID_GANGSI;
  4728. //2-1 Jobs
  4729. case JOB_SUPER_NOVICE: return MAPID_SUPER_NOVICE;
  4730. case JOB_KNIGHT: return MAPID_KNIGHT;
  4731. case JOB_WIZARD: return MAPID_WIZARD;
  4732. case JOB_HUNTER: return MAPID_HUNTER;
  4733. case JOB_PRIEST: return MAPID_PRIEST;
  4734. case JOB_BLACKSMITH: return MAPID_BLACKSMITH;
  4735. case JOB_ASSASSIN: return MAPID_ASSASSIN;
  4736. case JOB_STAR_GLADIATOR: return MAPID_STAR_GLADIATOR;
  4737. case JOB_KAGEROU:
  4738. case JOB_OBORO: return MAPID_KAGEROUOBORO;
  4739. case JOB_REBELLION: return MAPID_REBELLION;
  4740. case JOB_DEATH_KNIGHT: return MAPID_DEATH_KNIGHT;
  4741. //2-2 Jobs
  4742. case JOB_CRUSADER: return MAPID_CRUSADER;
  4743. case JOB_SAGE: return MAPID_SAGE;
  4744. case JOB_BARD:
  4745. case JOB_DANCER: return MAPID_BARDDANCER;
  4746. case JOB_MONK: return MAPID_MONK;
  4747. case JOB_ALCHEMIST: return MAPID_ALCHEMIST;
  4748. case JOB_ROGUE: return MAPID_ROGUE;
  4749. case JOB_SOUL_LINKER: return MAPID_SOUL_LINKER;
  4750. case JOB_DARK_COLLECTOR: return MAPID_DARK_COLLECTOR;
  4751. //Trans Novice And Trans 1-1 Jobs
  4752. case JOB_NOVICE_HIGH: return MAPID_NOVICE_HIGH;
  4753. case JOB_SWORDMAN_HIGH: return MAPID_SWORDMAN_HIGH;
  4754. case JOB_MAGE_HIGH: return MAPID_MAGE_HIGH;
  4755. case JOB_ARCHER_HIGH: return MAPID_ARCHER_HIGH;
  4756. case JOB_ACOLYTE_HIGH: return MAPID_ACOLYTE_HIGH;
  4757. case JOB_MERCHANT_HIGH: return MAPID_MERCHANT_HIGH;
  4758. case JOB_THIEF_HIGH: return MAPID_THIEF_HIGH;
  4759. //Trans 2-1 Jobs
  4760. case JOB_LORD_KNIGHT: return MAPID_LORD_KNIGHT;
  4761. case JOB_HIGH_WIZARD: return MAPID_HIGH_WIZARD;
  4762. case JOB_SNIPER: return MAPID_SNIPER;
  4763. case JOB_HIGH_PRIEST: return MAPID_HIGH_PRIEST;
  4764. case JOB_WHITESMITH: return MAPID_WHITESMITH;
  4765. case JOB_ASSASSIN_CROSS: return MAPID_ASSASSIN_CROSS;
  4766. //Trans 2-2 Jobs
  4767. case JOB_PALADIN: return MAPID_PALADIN;
  4768. case JOB_PROFESSOR: return MAPID_PROFESSOR;
  4769. case JOB_CLOWN:
  4770. case JOB_GYPSY: return MAPID_CLOWNGYPSY;
  4771. case JOB_CHAMPION: return MAPID_CHAMPION;
  4772. case JOB_CREATOR: return MAPID_CREATOR;
  4773. case JOB_STALKER: return MAPID_STALKER;
  4774. //Baby Novice And Baby 1-1 Jobs
  4775. case JOB_BABY: return MAPID_BABY;
  4776. case JOB_BABY_SWORDMAN: return MAPID_BABY_SWORDMAN;
  4777. case JOB_BABY_MAGE: return MAPID_BABY_MAGE;
  4778. case JOB_BABY_ARCHER: return MAPID_BABY_ARCHER;
  4779. case JOB_BABY_ACOLYTE: return MAPID_BABY_ACOLYTE;
  4780. case JOB_BABY_MERCHANT: return MAPID_BABY_MERCHANT;
  4781. case JOB_BABY_THIEF: return MAPID_BABY_THIEF;
  4782. //Baby 2-1 Jobs
  4783. case JOB_SUPER_BABY: return MAPID_SUPER_BABY;
  4784. case JOB_BABY_KNIGHT: return MAPID_BABY_KNIGHT;
  4785. case JOB_BABY_WIZARD: return MAPID_BABY_WIZARD;
  4786. case JOB_BABY_HUNTER: return MAPID_BABY_HUNTER;
  4787. case JOB_BABY_PRIEST: return MAPID_BABY_PRIEST;
  4788. case JOB_BABY_BLACKSMITH: return MAPID_BABY_BLACKSMITH;
  4789. case JOB_BABY_ASSASSIN: return MAPID_BABY_ASSASSIN;
  4790. //Baby 2-2 Jobs
  4791. case JOB_BABY_CRUSADER: return MAPID_BABY_CRUSADER;
  4792. case JOB_BABY_SAGE: return MAPID_BABY_SAGE;
  4793. case JOB_BABY_BARD:
  4794. case JOB_BABY_DANCER: return MAPID_BABY_BARDDANCER;
  4795. case JOB_BABY_MONK: return MAPID_BABY_MONK;
  4796. case JOB_BABY_ALCHEMIST: return MAPID_BABY_ALCHEMIST;
  4797. case JOB_BABY_ROGUE: return MAPID_BABY_ROGUE;
  4798. //3-1 Jobs
  4799. case JOB_SUPER_NOVICE_E: return MAPID_SUPER_NOVICE_E;
  4800. case JOB_RUNE_KNIGHT: return MAPID_RUNE_KNIGHT;
  4801. case JOB_WARLOCK: return MAPID_WARLOCK;
  4802. case JOB_RANGER: return MAPID_RANGER;
  4803. case JOB_ARCH_BISHOP: return MAPID_ARCH_BISHOP;
  4804. case JOB_MECHANIC: return MAPID_MECHANIC;
  4805. case JOB_GUILLOTINE_CROSS: return MAPID_GUILLOTINE_CROSS;
  4806. //3-2 Jobs
  4807. case JOB_ROYAL_GUARD: return MAPID_ROYAL_GUARD;
  4808. case JOB_SORCERER: return MAPID_SORCERER;
  4809. case JOB_MINSTREL:
  4810. case JOB_WANDERER: return MAPID_MINSTRELWANDERER;
  4811. case JOB_SURA: return MAPID_SURA;
  4812. case JOB_GENETIC: return MAPID_GENETIC;
  4813. case JOB_SHADOW_CHASER: return MAPID_SHADOW_CHASER;
  4814. //Trans 3-1 Jobs
  4815. case JOB_RUNE_KNIGHT_T: return MAPID_RUNE_KNIGHT_T;
  4816. case JOB_WARLOCK_T: return MAPID_WARLOCK_T;
  4817. case JOB_RANGER_T: return MAPID_RANGER_T;
  4818. case JOB_ARCH_BISHOP_T: return MAPID_ARCH_BISHOP_T;
  4819. case JOB_MECHANIC_T: return MAPID_MECHANIC_T;
  4820. case JOB_GUILLOTINE_CROSS_T: return MAPID_GUILLOTINE_CROSS_T;
  4821. //Trans 3-2 Jobs
  4822. case JOB_ROYAL_GUARD_T: return MAPID_ROYAL_GUARD_T;
  4823. case JOB_SORCERER_T: return MAPID_SORCERER_T;
  4824. case JOB_MINSTREL_T:
  4825. case JOB_WANDERER_T: return MAPID_MINSTRELWANDERER_T;
  4826. case JOB_SURA_T: return MAPID_SURA_T;
  4827. case JOB_GENETIC_T: return MAPID_GENETIC_T;
  4828. case JOB_SHADOW_CHASER_T: return MAPID_SHADOW_CHASER_T;
  4829. //Baby 3-1 Jobs
  4830. case JOB_SUPER_BABY_E: return MAPID_SUPER_BABY_E;
  4831. case JOB_BABY_RUNE: return MAPID_BABY_RUNE;
  4832. case JOB_BABY_WARLOCK: return MAPID_BABY_WARLOCK;
  4833. case JOB_BABY_RANGER: return MAPID_BABY_RANGER;
  4834. case JOB_BABY_BISHOP: return MAPID_BABY_BISHOP;
  4835. case JOB_BABY_MECHANIC: return MAPID_BABY_MECHANIC;
  4836. case JOB_BABY_CROSS: return MAPID_BABY_CROSS;
  4837. //Baby 3-2 Jobs
  4838. case JOB_BABY_GUARD: return MAPID_BABY_GUARD;
  4839. case JOB_BABY_SORCERER: return MAPID_BABY_SORCERER;
  4840. case JOB_BABY_MINSTREL:
  4841. case JOB_BABY_WANDERER: return MAPID_BABY_MINSTRELWANDERER;
  4842. case JOB_BABY_SURA: return MAPID_BABY_SURA;
  4843. case JOB_BABY_GENETIC: return MAPID_BABY_GENETIC;
  4844. case JOB_BABY_CHASER: return MAPID_BABY_CHASER;
  4845. default:
  4846. return -1;
  4847. }
  4848. }
  4849. //Reverts the map-style class id to the client-style one.
  4850. int pc_mapid2jobid(unsigned short class_, int sex)
  4851. {
  4852. switch(class_)
  4853. {
  4854. //Novice And 1-1 Jobs
  4855. case MAPID_NOVICE: return JOB_NOVICE;
  4856. case MAPID_SWORDMAN: return JOB_SWORDMAN;
  4857. case MAPID_MAGE: return JOB_MAGE;
  4858. case MAPID_ARCHER: return JOB_ARCHER;
  4859. case MAPID_ACOLYTE: return JOB_ACOLYTE;
  4860. case MAPID_MERCHANT: return JOB_MERCHANT;
  4861. case MAPID_THIEF: return JOB_THIEF;
  4862. case MAPID_TAEKWON: return JOB_TAEKWON;
  4863. case MAPID_WEDDING: return JOB_WEDDING;
  4864. case MAPID_GUNSLINGER: return JOB_GUNSLINGER;
  4865. case MAPID_NINJA: return JOB_NINJA;
  4866. case MAPID_XMAS: return JOB_XMAS;
  4867. case MAPID_SUMMER: return JOB_SUMMER;
  4868. case MAPID_HANBOK: return JOB_HANBOK;
  4869. case MAPID_OKTOBERFEST: return JOB_OKTOBERFEST;
  4870. case MAPID_GANGSI: return JOB_GANGSI;
  4871. //2-1 Jobs
  4872. case MAPID_SUPER_NOVICE: return JOB_SUPER_NOVICE;
  4873. case MAPID_KNIGHT: return JOB_KNIGHT;
  4874. case MAPID_WIZARD: return JOB_WIZARD;
  4875. case MAPID_HUNTER: return JOB_HUNTER;
  4876. case MAPID_PRIEST: return JOB_PRIEST;
  4877. case MAPID_BLACKSMITH: return JOB_BLACKSMITH;
  4878. case MAPID_ASSASSIN: return JOB_ASSASSIN;
  4879. case MAPID_STAR_GLADIATOR: return JOB_STAR_GLADIATOR;
  4880. case MAPID_KAGEROUOBORO: return sex?JOB_KAGEROU:JOB_OBORO;
  4881. case MAPID_REBELLION: return JOB_REBELLION;
  4882. case MAPID_DEATH_KNIGHT: return JOB_DEATH_KNIGHT;
  4883. //2-2 Jobs
  4884. case MAPID_CRUSADER: return JOB_CRUSADER;
  4885. case MAPID_SAGE: return JOB_SAGE;
  4886. case MAPID_BARDDANCER: return sex?JOB_BARD:JOB_DANCER;
  4887. case MAPID_MONK: return JOB_MONK;
  4888. case MAPID_ALCHEMIST: return JOB_ALCHEMIST;
  4889. case MAPID_ROGUE: return JOB_ROGUE;
  4890. case MAPID_SOUL_LINKER: return JOB_SOUL_LINKER;
  4891. case MAPID_DARK_COLLECTOR: return JOB_DARK_COLLECTOR;
  4892. //Trans Novice And Trans 2-1 Jobs
  4893. case MAPID_NOVICE_HIGH: return JOB_NOVICE_HIGH;
  4894. case MAPID_SWORDMAN_HIGH: return JOB_SWORDMAN_HIGH;
  4895. case MAPID_MAGE_HIGH: return JOB_MAGE_HIGH;
  4896. case MAPID_ARCHER_HIGH: return JOB_ARCHER_HIGH;
  4897. case MAPID_ACOLYTE_HIGH: return JOB_ACOLYTE_HIGH;
  4898. case MAPID_MERCHANT_HIGH: return JOB_MERCHANT_HIGH;
  4899. case MAPID_THIEF_HIGH: return JOB_THIEF_HIGH;
  4900. //Trans 2-1 Jobs
  4901. case MAPID_LORD_KNIGHT: return JOB_LORD_KNIGHT;
  4902. case MAPID_HIGH_WIZARD: return JOB_HIGH_WIZARD;
  4903. case MAPID_SNIPER: return JOB_SNIPER;
  4904. case MAPID_HIGH_PRIEST: return JOB_HIGH_PRIEST;
  4905. case MAPID_WHITESMITH: return JOB_WHITESMITH;
  4906. case MAPID_ASSASSIN_CROSS: return JOB_ASSASSIN_CROSS;
  4907. //Trans 2-2 Jobs
  4908. case MAPID_PALADIN: return JOB_PALADIN;
  4909. case MAPID_PROFESSOR: return JOB_PROFESSOR;
  4910. case MAPID_CLOWNGYPSY: return sex?JOB_CLOWN:JOB_GYPSY;
  4911. case MAPID_CHAMPION: return JOB_CHAMPION;
  4912. case MAPID_CREATOR: return JOB_CREATOR;
  4913. case MAPID_STALKER: return JOB_STALKER;
  4914. //Baby Novice And Baby 1-1 Jobs
  4915. case MAPID_BABY: return JOB_BABY;
  4916. case MAPID_BABY_SWORDMAN: return JOB_BABY_SWORDMAN;
  4917. case MAPID_BABY_MAGE: return JOB_BABY_MAGE;
  4918. case MAPID_BABY_ARCHER: return JOB_BABY_ARCHER;
  4919. case MAPID_BABY_ACOLYTE: return JOB_BABY_ACOLYTE;
  4920. case MAPID_BABY_MERCHANT: return JOB_BABY_MERCHANT;
  4921. case MAPID_BABY_THIEF: return JOB_BABY_THIEF;
  4922. //Baby 2-1 Jobs
  4923. case MAPID_SUPER_BABY: return JOB_SUPER_BABY;
  4924. case MAPID_BABY_KNIGHT: return JOB_BABY_KNIGHT;
  4925. case MAPID_BABY_WIZARD: return JOB_BABY_WIZARD;
  4926. case MAPID_BABY_HUNTER: return JOB_BABY_HUNTER;
  4927. case MAPID_BABY_PRIEST: return JOB_BABY_PRIEST;
  4928. case MAPID_BABY_BLACKSMITH: return JOB_BABY_BLACKSMITH;
  4929. case MAPID_BABY_ASSASSIN: return JOB_BABY_ASSASSIN;
  4930. //Baby 2-2 Jobs
  4931. case MAPID_BABY_CRUSADER: return JOB_BABY_CRUSADER;
  4932. case MAPID_BABY_SAGE: return JOB_BABY_SAGE;
  4933. case MAPID_BABY_BARDDANCER: return sex?JOB_BABY_BARD:JOB_BABY_DANCER;
  4934. case MAPID_BABY_MONK: return JOB_BABY_MONK;
  4935. case MAPID_BABY_ALCHEMIST: return JOB_BABY_ALCHEMIST;
  4936. case MAPID_BABY_ROGUE: return JOB_BABY_ROGUE;
  4937. //3-1 Jobs
  4938. case MAPID_SUPER_NOVICE_E: return JOB_SUPER_NOVICE_E;
  4939. case MAPID_RUNE_KNIGHT: return JOB_RUNE_KNIGHT;
  4940. case MAPID_WARLOCK: return JOB_WARLOCK;
  4941. case MAPID_RANGER: return JOB_RANGER;
  4942. case MAPID_ARCH_BISHOP: return JOB_ARCH_BISHOP;
  4943. case MAPID_MECHANIC: return JOB_MECHANIC;
  4944. case MAPID_GUILLOTINE_CROSS: return JOB_GUILLOTINE_CROSS;
  4945. //3-2 Jobs
  4946. case MAPID_ROYAL_GUARD: return JOB_ROYAL_GUARD;
  4947. case MAPID_SORCERER: return JOB_SORCERER;
  4948. case MAPID_MINSTRELWANDERER: return sex?JOB_MINSTREL:JOB_WANDERER;
  4949. case MAPID_SURA: return JOB_SURA;
  4950. case MAPID_GENETIC: return JOB_GENETIC;
  4951. case MAPID_SHADOW_CHASER: return JOB_SHADOW_CHASER;
  4952. //Trans 3-1 Jobs
  4953. case MAPID_RUNE_KNIGHT_T: return JOB_RUNE_KNIGHT_T;
  4954. case MAPID_WARLOCK_T: return JOB_WARLOCK_T;
  4955. case MAPID_RANGER_T: return JOB_RANGER_T;
  4956. case MAPID_ARCH_BISHOP_T: return JOB_ARCH_BISHOP_T;
  4957. case MAPID_MECHANIC_T: return JOB_MECHANIC_T;
  4958. case MAPID_GUILLOTINE_CROSS_T: return JOB_GUILLOTINE_CROSS_T;
  4959. //Trans 3-2 Jobs
  4960. case MAPID_ROYAL_GUARD_T: return JOB_ROYAL_GUARD_T;
  4961. case MAPID_SORCERER_T: return JOB_SORCERER_T;
  4962. case MAPID_MINSTRELWANDERER_T: return sex?JOB_MINSTREL_T:JOB_WANDERER_T;
  4963. case MAPID_SURA_T: return JOB_SURA_T;
  4964. case MAPID_GENETIC_T: return JOB_GENETIC_T;
  4965. case MAPID_SHADOW_CHASER_T: return JOB_SHADOW_CHASER_T;
  4966. //Baby 3-1 Jobs
  4967. case MAPID_SUPER_BABY_E: return JOB_SUPER_BABY_E;
  4968. case MAPID_BABY_RUNE: return JOB_BABY_RUNE;
  4969. case MAPID_BABY_WARLOCK: return JOB_BABY_WARLOCK;
  4970. case MAPID_BABY_RANGER: return JOB_BABY_RANGER;
  4971. case MAPID_BABY_BISHOP: return JOB_BABY_BISHOP;
  4972. case MAPID_BABY_MECHANIC: return JOB_BABY_MECHANIC;
  4973. case MAPID_BABY_CROSS: return JOB_BABY_CROSS;
  4974. //Baby 3-2 Jobs
  4975. case MAPID_BABY_GUARD: return JOB_BABY_GUARD;
  4976. case MAPID_BABY_SORCERER: return JOB_BABY_SORCERER;
  4977. case MAPID_BABY_MINSTRELWANDERER: return sex?JOB_BABY_MINSTREL:JOB_BABY_WANDERER;
  4978. case MAPID_BABY_SURA: return JOB_BABY_SURA;
  4979. case MAPID_BABY_GENETIC: return JOB_BABY_GENETIC;
  4980. case MAPID_BABY_CHASER: return JOB_BABY_CHASER;
  4981. default:
  4982. return -1;
  4983. }
  4984. }
  4985. /*====================================================
  4986. * This function return the name of the job (by [Yor])
  4987. *----------------------------------------------------*/
  4988. const char* job_name(int class_)
  4989. {
  4990. switch (class_) {
  4991. case JOB_NOVICE:
  4992. case JOB_SWORDMAN:
  4993. case JOB_MAGE:
  4994. case JOB_ARCHER:
  4995. case JOB_ACOLYTE:
  4996. case JOB_MERCHANT:
  4997. case JOB_THIEF:
  4998. return msg_txt(NULL,550 - JOB_NOVICE+class_);
  4999. case JOB_KNIGHT:
  5000. case JOB_PRIEST:
  5001. case JOB_WIZARD:
  5002. case JOB_BLACKSMITH:
  5003. case JOB_HUNTER:
  5004. case JOB_ASSASSIN:
  5005. return msg_txt(NULL,557 - JOB_KNIGHT+class_);
  5006. case JOB_KNIGHT2:
  5007. return msg_txt(NULL,557);
  5008. case JOB_CRUSADER:
  5009. case JOB_MONK:
  5010. case JOB_SAGE:
  5011. case JOB_ROGUE:
  5012. case JOB_ALCHEMIST:
  5013. case JOB_BARD:
  5014. case JOB_DANCER:
  5015. return msg_txt(NULL,563 - JOB_CRUSADER+class_);
  5016. case JOB_CRUSADER2:
  5017. return msg_txt(NULL,563);
  5018. case JOB_WEDDING:
  5019. case JOB_SUPER_NOVICE:
  5020. case JOB_GUNSLINGER:
  5021. case JOB_NINJA:
  5022. case JOB_XMAS:
  5023. return msg_txt(NULL,570 - JOB_WEDDING+class_);
  5024. case JOB_SUMMER:
  5025. return msg_txt(NULL,621);
  5026. case JOB_HANBOK:
  5027. return msg_txt(NULL,694);
  5028. case JOB_OKTOBERFEST:
  5029. return msg_txt(NULL,696);
  5030. case JOB_NOVICE_HIGH:
  5031. case JOB_SWORDMAN_HIGH:
  5032. case JOB_MAGE_HIGH:
  5033. case JOB_ARCHER_HIGH:
  5034. case JOB_ACOLYTE_HIGH:
  5035. case JOB_MERCHANT_HIGH:
  5036. case JOB_THIEF_HIGH:
  5037. return msg_txt(NULL,575 - JOB_NOVICE_HIGH+class_);
  5038. case JOB_LORD_KNIGHT:
  5039. case JOB_HIGH_PRIEST:
  5040. case JOB_HIGH_WIZARD:
  5041. case JOB_WHITESMITH:
  5042. case JOB_SNIPER:
  5043. case JOB_ASSASSIN_CROSS:
  5044. return msg_txt(NULL,582 - JOB_LORD_KNIGHT+class_);
  5045. case JOB_LORD_KNIGHT2:
  5046. return msg_txt(NULL,582);
  5047. case JOB_PALADIN:
  5048. case JOB_CHAMPION:
  5049. case JOB_PROFESSOR:
  5050. case JOB_STALKER:
  5051. case JOB_CREATOR:
  5052. case JOB_CLOWN:
  5053. case JOB_GYPSY:
  5054. return msg_txt(NULL,588 - JOB_PALADIN + class_);
  5055. case JOB_PALADIN2:
  5056. return msg_txt(NULL,588);
  5057. case JOB_BABY:
  5058. case JOB_BABY_SWORDMAN:
  5059. case JOB_BABY_MAGE:
  5060. case JOB_BABY_ARCHER:
  5061. case JOB_BABY_ACOLYTE:
  5062. case JOB_BABY_MERCHANT:
  5063. case JOB_BABY_THIEF:
  5064. return msg_txt(NULL,595 - JOB_BABY + class_);
  5065. case JOB_BABY_KNIGHT:
  5066. case JOB_BABY_PRIEST:
  5067. case JOB_BABY_WIZARD:
  5068. case JOB_BABY_BLACKSMITH:
  5069. case JOB_BABY_HUNTER:
  5070. case JOB_BABY_ASSASSIN:
  5071. return msg_txt(NULL,602 - JOB_BABY_KNIGHT + class_);
  5072. case JOB_BABY_KNIGHT2:
  5073. return msg_txt(NULL,602);
  5074. case JOB_BABY_CRUSADER:
  5075. case JOB_BABY_MONK:
  5076. case JOB_BABY_SAGE:
  5077. case JOB_BABY_ROGUE:
  5078. case JOB_BABY_ALCHEMIST:
  5079. case JOB_BABY_BARD:
  5080. case JOB_BABY_DANCER:
  5081. return msg_txt(NULL,608 - JOB_BABY_CRUSADER + class_);
  5082. case JOB_BABY_CRUSADER2:
  5083. return msg_txt(NULL,608);
  5084. case JOB_SUPER_BABY:
  5085. return msg_txt(NULL,615);
  5086. case JOB_TAEKWON:
  5087. return msg_txt(NULL,616);
  5088. case JOB_STAR_GLADIATOR:
  5089. case JOB_STAR_GLADIATOR2:
  5090. return msg_txt(NULL,617);
  5091. case JOB_SOUL_LINKER:
  5092. return msg_txt(NULL,618);
  5093. case JOB_GANGSI:
  5094. case JOB_DEATH_KNIGHT:
  5095. case JOB_DARK_COLLECTOR:
  5096. return msg_txt(NULL,622 - JOB_GANGSI+class_);
  5097. case JOB_RUNE_KNIGHT:
  5098. case JOB_WARLOCK:
  5099. case JOB_RANGER:
  5100. case JOB_ARCH_BISHOP:
  5101. case JOB_MECHANIC:
  5102. case JOB_GUILLOTINE_CROSS:
  5103. return msg_txt(NULL,625 - JOB_RUNE_KNIGHT+class_);
  5104. case JOB_RUNE_KNIGHT_T:
  5105. case JOB_WARLOCK_T:
  5106. case JOB_RANGER_T:
  5107. case JOB_ARCH_BISHOP_T:
  5108. case JOB_MECHANIC_T:
  5109. case JOB_GUILLOTINE_CROSS_T:
  5110. return msg_txt(NULL,681 - JOB_RUNE_KNIGHT_T+class_);
  5111. case JOB_ROYAL_GUARD:
  5112. case JOB_SORCERER:
  5113. case JOB_MINSTREL:
  5114. case JOB_WANDERER:
  5115. case JOB_SURA:
  5116. case JOB_GENETIC:
  5117. case JOB_SHADOW_CHASER:
  5118. return msg_txt(NULL,631 - JOB_ROYAL_GUARD+class_);
  5119. case JOB_ROYAL_GUARD_T:
  5120. case JOB_SORCERER_T:
  5121. case JOB_MINSTREL_T:
  5122. case JOB_WANDERER_T:
  5123. case JOB_SURA_T:
  5124. case JOB_GENETIC_T:
  5125. case JOB_SHADOW_CHASER_T:
  5126. return msg_txt(NULL,687 - JOB_ROYAL_GUARD_T+class_);
  5127. case JOB_RUNE_KNIGHT2:
  5128. case JOB_RUNE_KNIGHT_T2:
  5129. return msg_txt(NULL,625);
  5130. case JOB_ROYAL_GUARD2:
  5131. case JOB_ROYAL_GUARD_T2:
  5132. return msg_txt(NULL,631);
  5133. case JOB_RANGER2:
  5134. case JOB_RANGER_T2:
  5135. return msg_txt(NULL,627);
  5136. case JOB_MECHANIC2:
  5137. case JOB_MECHANIC_T2:
  5138. return msg_txt(NULL,629);
  5139. case JOB_BABY_RUNE:
  5140. case JOB_BABY_WARLOCK:
  5141. case JOB_BABY_RANGER:
  5142. case JOB_BABY_BISHOP:
  5143. case JOB_BABY_MECHANIC:
  5144. case JOB_BABY_CROSS:
  5145. case JOB_BABY_GUARD:
  5146. case JOB_BABY_SORCERER:
  5147. case JOB_BABY_MINSTREL:
  5148. case JOB_BABY_WANDERER:
  5149. case JOB_BABY_SURA:
  5150. case JOB_BABY_GENETIC:
  5151. case JOB_BABY_CHASER:
  5152. return msg_txt(NULL,638 - JOB_BABY_RUNE+class_);
  5153. case JOB_BABY_RUNE2:
  5154. return msg_txt(NULL,638);
  5155. case JOB_BABY_GUARD2:
  5156. return msg_txt(NULL,644);
  5157. case JOB_BABY_RANGER2:
  5158. return msg_txt(NULL,640);
  5159. case JOB_BABY_MECHANIC2:
  5160. return msg_txt(NULL,642);
  5161. case JOB_SUPER_NOVICE_E:
  5162. case JOB_SUPER_BABY_E:
  5163. return msg_txt(NULL,651 - JOB_SUPER_NOVICE_E+class_);
  5164. case JOB_KAGEROU:
  5165. case JOB_OBORO:
  5166. return msg_txt(NULL,653 - JOB_KAGEROU+class_);
  5167. case JOB_REBELLION:
  5168. return msg_txt(NULL,695);
  5169. default:
  5170. return msg_txt(NULL,655);
  5171. }
  5172. }
  5173. /*====================================================
  5174. * Timered function to make id follow a target.
  5175. * @id = bl.id (player only atm)
  5176. * target is define in sd->followtarget (bl.id)
  5177. * used by pc_follow
  5178. *----------------------------------------------------*/
  5179. int pc_follow_timer(int tid, unsigned int tick, int id, intptr_t data)
  5180. {
  5181. struct map_session_data *sd;
  5182. struct block_list *tbl;
  5183. sd = map_id2sd(id);
  5184. nullpo_ret(sd);
  5185. if (sd->followtimer != tid){
  5186. ShowError("pc_follow_timer %d != %d\n",sd->followtimer,tid);
  5187. sd->followtimer = INVALID_TIMER;
  5188. return 0;
  5189. }
  5190. sd->followtimer = INVALID_TIMER;
  5191. tbl = map_id2bl(sd->followtarget);
  5192. if (tbl == NULL || pc_isdead(sd) || status_isdead(tbl))
  5193. {
  5194. pc_stop_following(sd);
  5195. return 0;
  5196. }
  5197. // either player or target is currently detached from map blocks (could be teleporting),
  5198. // but still connected to this map, so we'll just increment the timer and check back later
  5199. if (sd->bl.prev != NULL && tbl->prev != NULL &&
  5200. sd->ud.skilltimer == INVALID_TIMER && sd->ud.attacktimer == INVALID_TIMER && sd->ud.walktimer == INVALID_TIMER)
  5201. {
  5202. if((sd->bl.m == tbl->m) && unit_can_reach_bl(&sd->bl,tbl, AREA_SIZE, 0, NULL, NULL)) {
  5203. if (!check_distance_bl(&sd->bl, tbl, 5))
  5204. unit_walktobl(&sd->bl, tbl, 5, 0);
  5205. } else
  5206. pc_setpos(sd, map_id2index(tbl->m), tbl->x, tbl->y, CLR_TELEPORT);
  5207. }
  5208. sd->followtimer = add_timer(
  5209. tick + 1000, // increase time a bit to loosen up map's load
  5210. pc_follow_timer, sd->bl.id, 0);
  5211. return 0;
  5212. }
  5213. int pc_stop_following (struct map_session_data *sd)
  5214. {
  5215. nullpo_ret(sd);
  5216. if (sd->followtimer != INVALID_TIMER) {
  5217. delete_timer(sd->followtimer,pc_follow_timer);
  5218. sd->followtimer = INVALID_TIMER;
  5219. }
  5220. sd->followtarget = -1;
  5221. sd->ud.target_to = 0;
  5222. unit_stop_walking(&sd->bl, 1);
  5223. return 0;
  5224. }
  5225. int pc_follow(struct map_session_data *sd,int target_id)
  5226. {
  5227. struct block_list *bl = map_id2bl(target_id);
  5228. if (bl == NULL /*|| bl->type != BL_PC*/)
  5229. return 1;
  5230. if (sd->followtimer != INVALID_TIMER)
  5231. pc_stop_following(sd);
  5232. sd->followtarget = target_id;
  5233. pc_follow_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
  5234. return 0;
  5235. }
  5236. int pc_checkbaselevelup(struct map_session_data *sd) {
  5237. unsigned int next = pc_nextbaseexp(sd);
  5238. if (!next || sd->status.base_exp < next)
  5239. return 0;
  5240. do {
  5241. sd->status.base_exp -= next;
  5242. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  5243. if(!battle_config.multi_level_up && sd->status.base_exp > next-1)
  5244. sd->status.base_exp = next-1;
  5245. next = pc_gets_status_point(sd->status.base_level);
  5246. sd->status.base_level ++;
  5247. sd->status.status_point += next;
  5248. } while ((next=pc_nextbaseexp(sd)) > 0 && sd->status.base_exp >= next);
  5249. if (battle_config.pet_lv_rate && sd->pd) //<Skotlex> update pet's level
  5250. status_calc_pet(sd->pd,0);
  5251. clif_updatestatus(sd,SP_STATUSPOINT);
  5252. clif_updatestatus(sd,SP_BASELEVEL);
  5253. clif_updatestatus(sd,SP_BASEEXP);
  5254. clif_updatestatus(sd,SP_NEXTBASEEXP);
  5255. status_calc_pc(sd,0);
  5256. status_percent_heal(&sd->bl,100,100);
  5257. if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) {
  5258. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_KYRIE),100,1,skill_get_time(PR_KYRIE,1));
  5259. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_IMPOSITIO),100,1,skill_get_time(PR_IMPOSITIO,1));
  5260. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_MAGNIFICAT),100,1,skill_get_time(PR_MAGNIFICAT,1));
  5261. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_GLORIA),100,1,skill_get_time(PR_GLORIA,1));
  5262. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_SUFFRAGIUM),100,1,skill_get_time(PR_SUFFRAGIUM,1));
  5263. if (sd->state.snovice_dead_flag)
  5264. sd->state.snovice_dead_flag = 0; //Reenable steelbody resurrection on dead.
  5265. } else if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON ) {
  5266. sc_start(&sd->bl,&sd->bl,status_skill2sc(AL_INCAGI),100,10,600000);
  5267. sc_start(&sd->bl,&sd->bl,status_skill2sc(AL_BLESSING),100,10,600000);
  5268. }
  5269. clif_misceffect(&sd->bl,0);
  5270. npc_script_event(sd, NPCE_BASELVUP); //LORDALFA - LVLUPEVENT
  5271. if(sd->status.party_id)
  5272. party_send_levelup(sd);
  5273. pc_baselevelchanged(sd);
  5274. return 1;
  5275. }
  5276. void pc_baselevelchanged(struct map_session_data *sd) {
  5277. #ifdef RENEWAL
  5278. int i;
  5279. for( i = 0; i < EQI_MAX; i++ ) {
  5280. if( sd->equip_index[i] >= 0 ) {
  5281. if( sd->inventory_data[ sd->equip_index[i] ]->elvmax && sd->status.base_level > (unsigned int)sd->inventory_data[ sd->equip_index[i] ]->elvmax )
  5282. pc_unequipitem(sd, sd->equip_index[i], 3);
  5283. }
  5284. }
  5285. #endif
  5286. }
  5287. int pc_checkjoblevelup(struct map_session_data *sd)
  5288. {
  5289. unsigned int next = pc_nextjobexp(sd);
  5290. nullpo_ret(sd);
  5291. if(!next || sd->status.job_exp < next)
  5292. return 0;
  5293. do {
  5294. sd->status.job_exp -= next;
  5295. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  5296. if(!battle_config.multi_level_up && sd->status.job_exp > next-1)
  5297. sd->status.job_exp = next-1;
  5298. sd->status.job_level ++;
  5299. sd->status.skill_point ++;
  5300. } while ((next=pc_nextjobexp(sd)) > 0 && sd->status.job_exp >= next);
  5301. clif_updatestatus(sd,SP_JOBLEVEL);
  5302. clif_updatestatus(sd,SP_JOBEXP);
  5303. clif_updatestatus(sd,SP_NEXTJOBEXP);
  5304. clif_updatestatus(sd,SP_SKILLPOINT);
  5305. status_calc_pc(sd,0);
  5306. clif_misceffect(&sd->bl,1);
  5307. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  5308. clif_status_change(&sd->bl,SI_DEVIL, 1, 0, 0, 0, 1); //Permanent blind effect from SG_DEVIL.
  5309. npc_script_event(sd, NPCE_JOBLVUP);
  5310. return 1;
  5311. }
  5312. /*==========================================
  5313. * Alters experienced based on self bonuses that do not get even shared to the party.
  5314. *------------------------------------------*/
  5315. static void pc_calcexp(struct map_session_data *sd, unsigned int *base_exp, unsigned int *job_exp, struct block_list *src)
  5316. {
  5317. int bonus = 0;
  5318. struct status_data *status = status_get_status_data(src);
  5319. if( sd->expaddrace[status->race] )
  5320. bonus += sd->expaddrace[status->race];
  5321. if( sd->expaddrace[RC_ALL] )
  5322. bonus += sd->expaddrace[RC_ALL];
  5323. if( sd->expaddclass[status->class_] )
  5324. bonus += sd->expaddclass[status->class_];
  5325. if( sd->expaddclass[CLASS_ALL] )
  5326. bonus += sd->expaddclass[CLASS_ALL];
  5327. if (battle_config.pk_mode &&
  5328. (int)(status_get_lv(src) - sd->status.base_level) >= 20)
  5329. bonus += 15; // pk_mode additional exp if monster >20 levels [Valaris]
  5330. if (sd->sc.data[SC_EXPBOOST]) {
  5331. bonus += sd->sc.data[SC_EXPBOOST]->val1;
  5332. if( battle_config.vip_bm_increase && pc_isvip(sd) ) // Increase Battle Manual EXP rate for VIP.
  5333. bonus += ( sd->sc.data[SC_EXPBOOST]->val1 / battle_config.vip_bm_increase );
  5334. }
  5335. *base_exp = (unsigned int) cap_value(*base_exp + (double)*base_exp * bonus/100., 1, UINT_MAX);
  5336. if (sd->sc.data[SC_JEXPBOOST])
  5337. bonus += sd->sc.data[SC_JEXPBOOST]->val1;
  5338. *job_exp = (unsigned int) cap_value(*job_exp + (double)*job_exp * bonus/100., 1, UINT_MAX);
  5339. return;
  5340. }
  5341. /*==========================================
  5342. * Give x exp at sd player and calculate remaining exp for next lvl
  5343. *------------------------------------------*/
  5344. int pc_gainexp(struct map_session_data *sd, struct block_list *src, unsigned int base_exp,unsigned int job_exp,bool quest)
  5345. {
  5346. float nextbp=0, nextjp=0;
  5347. unsigned int nextb=0, nextj=0;
  5348. nullpo_ret(sd);
  5349. if(sd->bl.prev == NULL || pc_isdead(sd))
  5350. return 0;
  5351. if(!battle_config.pvp_exp && map[sd->bl.m].flag.pvp) // [MouseJstr]
  5352. return 0; // no exp on pvp maps
  5353. // Increase base EXP rate for VIP.
  5354. if (src && src->type&BL_MOB && (battle_config.vip_base_exp_increase && (sd && pc_isvip(sd))))
  5355. base_exp = (unsigned int)cap_value(base_exp * (battle_config.vip_base_exp_increase)/100., 1, UINT_MAX);
  5356. if(sd->status.guild_id>0)
  5357. base_exp-=guild_payexp(sd,base_exp);
  5358. if(src) pc_calcexp(sd, &base_exp, &job_exp, src);
  5359. nextb = pc_nextbaseexp(sd);
  5360. nextj = pc_nextjobexp(sd);
  5361. if(sd->state.showexp || battle_config.max_exp_gain_rate){
  5362. if (nextb > 0)
  5363. nextbp = (float) base_exp / (float) nextb;
  5364. if (nextj > 0)
  5365. nextjp = (float) job_exp / (float) nextj;
  5366. if(battle_config.max_exp_gain_rate) {
  5367. if (nextbp > battle_config.max_exp_gain_rate/1000.) {
  5368. //Note that this value should never be greater than the original
  5369. //base_exp, therefore no overflow checks are needed. [Skotlex]
  5370. base_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextb);
  5371. if (sd->state.showexp)
  5372. nextbp = (float) base_exp / (float) nextb;
  5373. }
  5374. if (nextjp > battle_config.max_exp_gain_rate/1000.) {
  5375. job_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextj);
  5376. if (sd->state.showexp)
  5377. nextjp = (float) job_exp / (float) nextj;
  5378. }
  5379. }
  5380. }
  5381. //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]
  5382. if (base_exp) {
  5383. nextb = nextb?UINT_MAX:pc_thisbaseexp(sd);
  5384. if(sd->status.base_exp > nextb - base_exp)
  5385. sd->status.base_exp = nextb;
  5386. else
  5387. sd->status.base_exp += base_exp;
  5388. pc_checkbaselevelup(sd);
  5389. clif_updatestatus(sd,SP_BASEEXP);
  5390. }
  5391. if (job_exp) {
  5392. nextj = nextj?UINT_MAX:pc_thisjobexp(sd);
  5393. if(sd->status.job_exp > nextj - job_exp)
  5394. sd->status.job_exp = nextj;
  5395. else
  5396. sd->status.job_exp += job_exp;
  5397. pc_checkjoblevelup(sd);
  5398. clif_updatestatus(sd,SP_JOBEXP);
  5399. }
  5400. if(base_exp)
  5401. clif_displayexp(sd, base_exp, SP_BASEEXP, quest);
  5402. if(job_exp)
  5403. clif_displayexp(sd, job_exp, SP_JOBEXP, quest);
  5404. if(sd->state.showexp) {
  5405. char output[256];
  5406. sprintf(output,
  5407. "Experience Gained Base:%u (%.2f%%) Job:%u (%.2f%%)",base_exp,nextbp*(float)100,job_exp,nextjp*(float)100);
  5408. clif_disp_onlyself(sd,output,strlen(output));
  5409. }
  5410. return 1;
  5411. }
  5412. /*==========================================
  5413. * Returns max level for this character.
  5414. *------------------------------------------*/
  5415. unsigned int pc_maxbaselv(struct map_session_data *sd){
  5416. return job_info[pc_class2idx(sd->status.class_)].max_level[0];
  5417. }
  5418. unsigned int pc_maxjoblv(struct map_session_data *sd){
  5419. return job_info[pc_class2idx(sd->status.class_)].max_level[1];
  5420. }
  5421. /*==========================================
  5422. * base level exp lookup.
  5423. *------------------------------------------*/
  5424. //Base exp needed for next level.
  5425. unsigned int pc_nextbaseexp(struct map_session_data *sd){
  5426. nullpo_ret(sd);
  5427. if(sd->status.base_level>=pc_maxbaselv(sd) || sd->status.base_level==0)
  5428. return 0;
  5429. return job_info[pc_class2idx(sd->status.class_)].exp_table[0][sd->status.base_level-1];
  5430. }
  5431. //Base exp needed for this level.
  5432. unsigned int pc_thisbaseexp(struct map_session_data *sd){
  5433. if(sd->status.base_level>pc_maxbaselv(sd) || sd->status.base_level<=1)
  5434. return 0;
  5435. return job_info[pc_class2idx(sd->status.class_)].exp_table[0][sd->status.base_level-2];
  5436. }
  5437. /*==========================================
  5438. * job level exp lookup
  5439. * Return:
  5440. * 0 = not found
  5441. * x = exp for level
  5442. *------------------------------------------*/
  5443. //Job exp needed for next level.
  5444. unsigned int pc_nextjobexp(struct map_session_data *sd){
  5445. nullpo_ret(sd);
  5446. if(sd->status.job_level>=pc_maxjoblv(sd) || sd->status.job_level==0)
  5447. return 0;
  5448. return job_info[pc_class2idx(sd->status.class_)].exp_table[1][sd->status.job_level-1];
  5449. }
  5450. //Job exp needed for this level.
  5451. unsigned int pc_thisjobexp(struct map_session_data *sd){
  5452. if(sd->status.job_level>pc_maxjoblv(sd) || sd->status.job_level<=1)
  5453. return 0;
  5454. return job_info[pc_class2idx(sd->status.class_)].exp_table[1][sd->status.job_level-2];
  5455. }
  5456. /// Returns the value of the specified stat.
  5457. static int pc_getstat(struct map_session_data* sd, int type)
  5458. {
  5459. nullpo_retr(-1, sd);
  5460. switch( type ) {
  5461. case SP_STR: return sd->status.str;
  5462. case SP_AGI: return sd->status.agi;
  5463. case SP_VIT: return sd->status.vit;
  5464. case SP_INT: return sd->status.int_;
  5465. case SP_DEX: return sd->status.dex;
  5466. case SP_LUK: return sd->status.luk;
  5467. default:
  5468. return -1;
  5469. }
  5470. }
  5471. /// Sets the specified stat to the specified value.
  5472. /// Returns the new value.
  5473. static int pc_setstat(struct map_session_data* sd, int type, int val)
  5474. {
  5475. nullpo_retr(-1, sd);
  5476. switch( type ) {
  5477. case SP_STR: sd->status.str = val; break;
  5478. case SP_AGI: sd->status.agi = val; break;
  5479. case SP_VIT: sd->status.vit = val; break;
  5480. case SP_INT: sd->status.int_ = val; break;
  5481. case SP_DEX: sd->status.dex = val; break;
  5482. case SP_LUK: sd->status.luk = val; break;
  5483. default:
  5484. return -1;
  5485. }
  5486. return val;
  5487. }
  5488. // Calculates the number of status points PC gets when leveling up (from level to level+1)
  5489. int pc_gets_status_point(int level)
  5490. {
  5491. if (battle_config.use_statpoint_table) //Use values from "db/statpoint.txt"
  5492. return (statp[level+1] - statp[level]);
  5493. else //Default increase
  5494. return ((level+15) / 5);
  5495. }
  5496. /// Returns the number of stat points needed to change the specified stat by val.
  5497. /// If val is negative, returns the number of stat points that would be needed to
  5498. /// raise the specified stat from (current value - val) to current value.
  5499. int pc_need_status_point(struct map_session_data* sd, int type, int val)
  5500. {
  5501. int low, high, sp = 0, max = 0;
  5502. if ( val == 0 )
  5503. return 0;
  5504. low = pc_getstat(sd,type);
  5505. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR));
  5506. if ( low >= max && val > 0 )
  5507. return 0; // Official servers show '0' when max is reached
  5508. high = low + val;
  5509. if ( val < 0 )
  5510. swap(low, high);
  5511. for ( ; low < high; low++ )
  5512. #ifdef RENEWAL // renewal status point cost formula
  5513. sp += (low < 100) ? (2 + (low - 1) / 10) : (16 + 4 * ((low - 100) / 5));
  5514. #else
  5515. sp += ( 1 + (low + 9) / 10 );
  5516. #endif
  5517. return sp;
  5518. }
  5519. /// Raises a stat by 1.
  5520. /// Obeys max_parameter limits.
  5521. /// Subtracts stat points.
  5522. ///
  5523. /// @param type The stat to change (see enum _sp)
  5524. int pc_statusup(struct map_session_data* sd, int type)
  5525. {
  5526. int max, need, val;
  5527. nullpo_ret(sd);
  5528. // check conditions
  5529. need = pc_need_status_point(sd,type,1);
  5530. if( type < SP_STR || type > SP_LUK || need < 0 || need > sd->status.status_point )
  5531. {
  5532. clif_statusupack(sd,type,0,0);
  5533. return 1;
  5534. }
  5535. // check limits
  5536. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR));
  5537. if( pc_getstat(sd,type) >= max )
  5538. {
  5539. clif_statusupack(sd,type,0,0);
  5540. return 1;
  5541. }
  5542. // set new values
  5543. val = pc_setstat(sd, type, pc_getstat(sd,type) + 1);
  5544. sd->status.status_point -= need;
  5545. status_calc_pc(sd,0);
  5546. // update increase cost indicator
  5547. if( need != pc_need_status_point(sd,type,1) )
  5548. clif_updatestatus(sd, SP_USTR + type-SP_STR);
  5549. // update statpoint count
  5550. clif_updatestatus(sd,SP_STATUSPOINT);
  5551. // update stat value
  5552. clif_statusupack(sd,type,1,val); // required
  5553. if( val > 255 )
  5554. clif_updatestatus(sd,type); // send after the 'ack' to override the truncated value
  5555. return 0;
  5556. }
  5557. /// Raises a stat by the specified amount.
  5558. /// Obeys max_parameter limits.
  5559. /// Does not subtract stat points.
  5560. ///
  5561. /// @param type The stat to change (see enum _sp)
  5562. /// @param val The stat increase amount.
  5563. int pc_statusup2(struct map_session_data* sd, int type, int val)
  5564. {
  5565. int max, need;
  5566. nullpo_ret(sd);
  5567. if( type < SP_STR || type > SP_LUK )
  5568. {
  5569. clif_statusupack(sd,type,0,0);
  5570. return 1;
  5571. }
  5572. need = pc_need_status_point(sd,type,1);
  5573. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR)); // set new value
  5574. val = pc_setstat(sd, type, cap_value(pc_getstat(sd,type) + val, 1, max));
  5575. status_calc_pc(sd,0);
  5576. // update increase cost indicator
  5577. if( need != pc_need_status_point(sd,type,1) )
  5578. clif_updatestatus(sd, SP_USTR + type-SP_STR);
  5579. // update stat value
  5580. clif_statusupack(sd,type,1,val); // required
  5581. if( val > 255 )
  5582. clif_updatestatus(sd,type); // send after the 'ack' to override the truncated value
  5583. return 0;
  5584. }
  5585. /*==========================================
  5586. * Update skill_lv for player sd
  5587. * Skill point allocation
  5588. *------------------------------------------*/
  5589. int pc_skillup(struct map_session_data *sd,uint16 skill_id)
  5590. {
  5591. nullpo_ret(sd);
  5592. if( skill_id >= GD_SKILLBASE && skill_id < GD_SKILLBASE+MAX_GUILDSKILL )
  5593. {
  5594. guild_skillup(sd, skill_id);
  5595. return 0;
  5596. }
  5597. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE+MAX_HOMUNSKILL && sd->hd )
  5598. {
  5599. merc_hom_skillup(sd->hd, skill_id);
  5600. return 0;
  5601. }
  5602. if(skill_id >= MAX_SKILL )
  5603. return 0;
  5604. if( sd->status.skill_point > 0 &&
  5605. sd->status.skill[skill_id].id &&
  5606. sd->status.skill[skill_id].flag == SKILL_FLAG_PERMANENT && //Don't allow raising while you have granted skills. [Skotlex]
  5607. sd->status.skill[skill_id].lv < skill_tree_get_max(skill_id, sd->status.class_) )
  5608. {
  5609. int lv,range, upgradable;
  5610. sd->status.skill[skill_id].lv++;
  5611. sd->status.skill_point--;
  5612. if( !skill_get_inf(skill_id) )
  5613. status_calc_pc(sd,0); // Only recalculate for passive skills.
  5614. 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) )
  5615. pc_calc_skilltree(sd); // Required to grant all TK Ranger skills.
  5616. else
  5617. pc_check_skilltree(sd, skill_id); // Check if a new skill can Lvlup
  5618. lv = sd->status.skill[skill_id].lv;
  5619. range = skill_get_range2(&sd->bl, skill_id, lv);
  5620. upgradable = (lv < skill_tree_get_max(sd->status.skill[skill_id].id, sd->status.class_)) ? 1 : 0;
  5621. clif_skillup(sd,skill_id,lv,range,upgradable);
  5622. clif_updatestatus(sd,SP_SKILLPOINT);
  5623. if( skill_id == GN_REMODELING_CART ) /* cart weight info was updated by status_calc_pc */
  5624. clif_updatestatus(sd,SP_CARTINFO);
  5625. if (!pc_has_permission(sd, PC_PERM_ALL_SKILL)) // may skill everything at any time anyways, and this would cause a huge slowdown
  5626. clif_skillinfoblock(sd);
  5627. }
  5628. return 0;
  5629. }
  5630. /*==========================================
  5631. * /allskill
  5632. *------------------------------------------*/
  5633. int pc_allskillup(struct map_session_data *sd)
  5634. {
  5635. int i;
  5636. nullpo_ret(sd);
  5637. for(i=0;i<MAX_SKILL;i++){
  5638. if (sd->status.skill[i].flag != SKILL_FLAG_PERMANENT && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED && sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED) {
  5639. sd->status.skill[i].lv = (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  5640. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  5641. if (sd->status.skill[i].lv == 0)
  5642. sd->status.skill[i].id = 0;
  5643. }
  5644. }
  5645. if (pc_has_permission(sd, PC_PERM_ALL_SKILL))
  5646. { //Get ALL skills except npc/guild ones. [Skotlex]
  5647. //and except SG_DEVIL [Komurka] and MO_TRIPLEATTACK and RG_SNATCHER [ultramage]
  5648. for(i=0;i<MAX_SKILL;i++){
  5649. switch( i ) {
  5650. case SG_DEVIL:
  5651. case MO_TRIPLEATTACK:
  5652. case RG_SNATCHER:
  5653. continue;
  5654. default:
  5655. if( !(skill_get_inf2(i)&(INF2_NPC_SKILL|INF2_GUILD_SKILL)) )
  5656. if ( ( sd->status.skill[i].lv = skill_get_max(i) ) )//Nonexistant skills should return a max of 0 anyway.
  5657. sd->status.skill[i].id = i;
  5658. }
  5659. }
  5660. } else {
  5661. int id;
  5662. for(i=0;i < MAX_SKILL_TREE && (id=skill_tree[pc_class2idx(sd->status.class_)][i].id)>0;i++){
  5663. int inf2 = skill_get_inf2(id);
  5664. if (
  5665. (inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  5666. (inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) ||
  5667. id==SG_DEVIL
  5668. )
  5669. continue; //Cannot be learned normally.
  5670. sd->status.skill[id].id = id;
  5671. sd->status.skill[id].lv = skill_tree_get_max(id, sd->status.class_); // celest
  5672. }
  5673. }
  5674. status_calc_pc(sd,0);
  5675. //Required because if you could level up all skills previously,
  5676. //the update will not be sent as only the lv variable changes.
  5677. clif_skillinfoblock(sd);
  5678. return 0;
  5679. }
  5680. /*==========================================
  5681. * /resetlvl
  5682. *------------------------------------------*/
  5683. int pc_resetlvl(struct map_session_data* sd,int type)
  5684. {
  5685. int i;
  5686. nullpo_ret(sd);
  5687. if (type != 3) //Also reset skills
  5688. pc_resetskill(sd, 0);
  5689. if(type == 1){
  5690. sd->status.skill_point=0;
  5691. sd->status.base_level=1;
  5692. sd->status.job_level=1;
  5693. sd->status.base_exp=0;
  5694. sd->status.job_exp=0;
  5695. if(sd->sc.option !=0)
  5696. sd->sc.option = 0;
  5697. sd->status.str=1;
  5698. sd->status.agi=1;
  5699. sd->status.vit=1;
  5700. sd->status.int_=1;
  5701. sd->status.dex=1;
  5702. sd->status.luk=1;
  5703. if(sd->status.class_ == JOB_NOVICE_HIGH) {
  5704. sd->status.status_point=100; // not 88 [celest]
  5705. // give platinum skills upon changing
  5706. pc_skill(sd,142,1,0);
  5707. pc_skill(sd,143,1,0);
  5708. }
  5709. }
  5710. if(type == 2){
  5711. sd->status.skill_point=0;
  5712. sd->status.base_level=1;
  5713. sd->status.job_level=1;
  5714. sd->status.base_exp=0;
  5715. sd->status.job_exp=0;
  5716. }
  5717. if(type == 3){
  5718. sd->status.base_level=1;
  5719. sd->status.base_exp=0;
  5720. }
  5721. if(type == 4){
  5722. sd->status.job_level=1;
  5723. sd->status.job_exp=0;
  5724. }
  5725. clif_updatestatus(sd,SP_STATUSPOINT);
  5726. clif_updatestatus(sd,SP_STR);
  5727. clif_updatestatus(sd,SP_AGI);
  5728. clif_updatestatus(sd,SP_VIT);
  5729. clif_updatestatus(sd,SP_INT);
  5730. clif_updatestatus(sd,SP_DEX);
  5731. clif_updatestatus(sd,SP_LUK);
  5732. clif_updatestatus(sd,SP_BASELEVEL);
  5733. clif_updatestatus(sd,SP_JOBLEVEL);
  5734. clif_updatestatus(sd,SP_STATUSPOINT);
  5735. clif_updatestatus(sd,SP_BASEEXP);
  5736. clif_updatestatus(sd,SP_JOBEXP);
  5737. clif_updatestatus(sd,SP_NEXTBASEEXP);
  5738. clif_updatestatus(sd,SP_NEXTJOBEXP);
  5739. clif_updatestatus(sd,SP_SKILLPOINT);
  5740. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  5741. clif_updatestatus(sd,SP_UAGI);
  5742. clif_updatestatus(sd,SP_UVIT);
  5743. clif_updatestatus(sd,SP_UINT);
  5744. clif_updatestatus(sd,SP_UDEX);
  5745. clif_updatestatus(sd,SP_ULUK); // End Addition
  5746. for(i=0;i<EQI_MAX;i++) { // unequip items that can't be equipped by base 1 [Valaris]
  5747. if(sd->equip_index[i] >= 0)
  5748. if(!pc_isequip(sd,sd->equip_index[i]))
  5749. pc_unequipitem(sd,sd->equip_index[i],2);
  5750. }
  5751. if ((type == 1 || type == 2 || type == 3) && sd->status.party_id)
  5752. party_send_levelup(sd);
  5753. status_calc_pc(sd,0);
  5754. clif_skillinfoblock(sd);
  5755. return 0;
  5756. }
  5757. /*==========================================
  5758. * /resetstate
  5759. *------------------------------------------*/
  5760. int pc_resetstate(struct map_session_data* sd)
  5761. {
  5762. nullpo_ret(sd);
  5763. if (battle_config.use_statpoint_table)
  5764. { // New statpoint table used here - Dexity
  5765. if (sd->status.base_level > MAX_LEVEL)
  5766. { //statp[] goes out of bounds, can't reset!
  5767. ShowError("pc_resetstate: Can't reset stats of %d:%d, the base level (%d) is greater than the max level supported (%d)\n",
  5768. sd->status.account_id, sd->status.char_id, sd->status.base_level, MAX_LEVEL);
  5769. return 0;
  5770. }
  5771. sd->status.status_point = statp[sd->status.base_level] + ( sd->class_&JOBL_UPPER ? 52 : 0 ); // extra 52+48=100 stat points
  5772. }
  5773. else
  5774. {
  5775. int add=0;
  5776. add += pc_need_status_point(sd, SP_STR, 1-pc_getstat(sd, SP_STR));
  5777. add += pc_need_status_point(sd, SP_AGI, 1-pc_getstat(sd, SP_AGI));
  5778. add += pc_need_status_point(sd, SP_VIT, 1-pc_getstat(sd, SP_VIT));
  5779. add += pc_need_status_point(sd, SP_INT, 1-pc_getstat(sd, SP_INT));
  5780. add += pc_need_status_point(sd, SP_DEX, 1-pc_getstat(sd, SP_DEX));
  5781. add += pc_need_status_point(sd, SP_LUK, 1-pc_getstat(sd, SP_LUK));
  5782. sd->status.status_point+=add;
  5783. }
  5784. pc_setstat(sd, SP_STR, 1);
  5785. pc_setstat(sd, SP_AGI, 1);
  5786. pc_setstat(sd, SP_VIT, 1);
  5787. pc_setstat(sd, SP_INT, 1);
  5788. pc_setstat(sd, SP_DEX, 1);
  5789. pc_setstat(sd, SP_LUK, 1);
  5790. clif_updatestatus(sd,SP_STR);
  5791. clif_updatestatus(sd,SP_AGI);
  5792. clif_updatestatus(sd,SP_VIT);
  5793. clif_updatestatus(sd,SP_INT);
  5794. clif_updatestatus(sd,SP_DEX);
  5795. clif_updatestatus(sd,SP_LUK);
  5796. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  5797. clif_updatestatus(sd,SP_UAGI);
  5798. clif_updatestatus(sd,SP_UVIT);
  5799. clif_updatestatus(sd,SP_UINT);
  5800. clif_updatestatus(sd,SP_UDEX);
  5801. clif_updatestatus(sd,SP_ULUK); // End Addition
  5802. clif_updatestatus(sd,SP_STATUSPOINT);
  5803. if( sd->mission_mobid ) { //bugreport:2200
  5804. sd->mission_mobid = 0;
  5805. sd->mission_count = 0;
  5806. pc_setglobalreg(sd,"TK_MISSION_ID", 0);
  5807. }
  5808. status_calc_pc(sd,0);
  5809. return 1;
  5810. }
  5811. /*==========================================
  5812. * /resetskill
  5813. * if flag&1, perform block resync and status_calc call.
  5814. * if flag&2, just count total amount of skill points used by player, do not really reset.
  5815. * if flag&4, just reset the skills if the player class is a bard/dancer type (for changesex.)
  5816. *------------------------------------------*/
  5817. int pc_resetskill(struct map_session_data* sd, int flag)
  5818. {
  5819. int i, skill_point=0;
  5820. nullpo_ret(sd);
  5821. if( flag&4 && (sd->class_&MAPID_UPPERMASK) != MAPID_BARDDANCER )
  5822. return 0;
  5823. if( !(flag&2) ) { //Remove stuff lost when resetting skills.
  5824. /**
  5825. * It has been confirmed on official server that when you reset skills with a ranked tweakwon your skills are not reset (because you have all of them anyway)
  5826. **/
  5827. if( (sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc_famerank(sd->status.char_id, MAPID_TAEKWON) )
  5828. return 0;
  5829. if( pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd) )
  5830. clif_status_load(&sd->bl, SI_DEVIL, 0); //Remove perma blindness due to skill-reset. [Skotlex]
  5831. i = sd->sc.option;
  5832. if( i&OPTION_RIDING && pc_checkskill(sd, KN_RIDING) )
  5833. i &= ~OPTION_RIDING;
  5834. if( i&OPTION_FALCON && pc_checkskill(sd, HT_FALCON) )
  5835. i &= ~OPTION_FALCON;
  5836. if( i&OPTION_DRAGON && pc_checkskill(sd, RK_DRAGONTRAINING) )
  5837. i &= ~OPTION_DRAGON;
  5838. if( i&OPTION_WUG && pc_checkskill(sd, RA_WUGMASTERY) )
  5839. i &= ~OPTION_WUG;
  5840. if( i&OPTION_WUGRIDER && pc_checkskill(sd, RA_WUGRIDER) )
  5841. i &= ~OPTION_WUGRIDER;
  5842. if( i&OPTION_MADOGEAR && ( sd->class_&MAPID_THIRDMASK ) == MAPID_MECHANIC )
  5843. i &= ~OPTION_MADOGEAR;
  5844. #ifndef NEW_CARTS
  5845. if( i&OPTION_CART && pc_checkskill(sd, MC_PUSHCART) )
  5846. i &= ~OPTION_CART;
  5847. #else
  5848. if( sd->sc.data[SC_PUSH_CART] )
  5849. pc_setcart(sd, 0);
  5850. #endif
  5851. if( i != sd->sc.option )
  5852. pc_setoption(sd, i);
  5853. if( merc_is_hom_active(sd->hd) && pc_checkskill(sd, AM_CALLHOMUN) )
  5854. merc_hom_vaporize(sd, HOM_ST_ACTIVE);
  5855. }
  5856. for( i = 1; i < MAX_SKILL; i++ )
  5857. {
  5858. int lv = sd->status.skill[i].lv;
  5859. int inf2;
  5860. if (lv < 1) continue;
  5861. inf2 = skill_get_inf2(i);
  5862. if( inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL) ) //Avoid reseting wedding/linker skills.
  5863. continue;
  5864. // Don't reset trick dead if not a novice/baby
  5865. if( i == NV_TRICKDEAD && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE )
  5866. {
  5867. sd->status.skill[i].lv = 0;
  5868. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  5869. continue;
  5870. }
  5871. // do not reset basic skill
  5872. if( i == NV_BASIC && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE )
  5873. continue;
  5874. if( sd->status.skill[i].flag == SKILL_FLAG_PERM_GRANTED )
  5875. continue;
  5876. if( flag&4 && !skill_ischangesex(i) )
  5877. continue;
  5878. if( inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn )
  5879. { //Only handle quest skills in a special way when you can't learn them manually
  5880. if( battle_config.quest_skill_reset && !(flag&2) )
  5881. { //Wipe them
  5882. sd->status.skill[i].lv = 0;
  5883. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  5884. }
  5885. continue;
  5886. }
  5887. if( sd->status.skill[i].flag == SKILL_FLAG_PERMANENT )
  5888. skill_point += lv;
  5889. else
  5890. if( sd->status.skill[i].flag == SKILL_FLAG_REPLACED_LV_0 )
  5891. skill_point += (sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0);
  5892. if( !(flag&2) )
  5893. {// reset
  5894. sd->status.skill[i].lv = 0;
  5895. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  5896. }
  5897. }
  5898. if( flag&2 || !skill_point ) return skill_point;
  5899. sd->status.skill_point += skill_point;
  5900. if( flag&1 )
  5901. {
  5902. clif_updatestatus(sd,SP_SKILLPOINT);
  5903. clif_skillinfoblock(sd);
  5904. status_calc_pc(sd,0);
  5905. }
  5906. return skill_point;
  5907. }
  5908. /*==========================================
  5909. * /resetfeel [Komurka]
  5910. *------------------------------------------*/
  5911. int pc_resetfeel(struct map_session_data* sd)
  5912. {
  5913. int i;
  5914. nullpo_ret(sd);
  5915. for (i=0; i<MAX_PC_FEELHATE; i++)
  5916. {
  5917. sd->feel_map[i].m = -1;
  5918. sd->feel_map[i].index = 0;
  5919. pc_setglobalreg(sd,sg_info[i].feel_var,0);
  5920. }
  5921. return 0;
  5922. }
  5923. int pc_resethate(struct map_session_data* sd)
  5924. {
  5925. int i;
  5926. nullpo_ret(sd);
  5927. for (i=0; i<3; i++)
  5928. {
  5929. sd->hate_mob[i] = -1;
  5930. pc_setglobalreg(sd,sg_info[i].hate_var,0);
  5931. }
  5932. return 0;
  5933. }
  5934. int pc_skillatk_bonus(struct map_session_data *sd, uint16 skill_id)
  5935. {
  5936. int i, bonus = 0;
  5937. nullpo_ret(sd);
  5938. ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == skill_id);
  5939. if( i < ARRAYLENGTH(sd->skillatk) ) bonus = sd->skillatk[i].val;
  5940. if(sd->sc.data[SC_PYROTECHNIC_OPTION] || sd->sc.data[SC_AQUAPLAY_OPTION])
  5941. bonus += 10;
  5942. return bonus;
  5943. }
  5944. int pc_skillheal_bonus(struct map_session_data *sd, uint16 skill_id) {
  5945. int i, bonus = sd->bonus.add_heal_rate;
  5946. if( bonus ) {
  5947. switch( skill_id ) {
  5948. case AL_HEAL: if( !(battle_config.skill_add_heal_rate&1) ) bonus = 0; break;
  5949. case PR_SANCTUARY: if( !(battle_config.skill_add_heal_rate&2) ) bonus = 0; break;
  5950. case AM_POTIONPITCHER: if( !(battle_config.skill_add_heal_rate&4) ) bonus = 0; break;
  5951. case CR_SLIMPITCHER: if( !(battle_config.skill_add_heal_rate&8) ) bonus = 0; break;
  5952. case BA_APPLEIDUN: if( !(battle_config.skill_add_heal_rate&16)) bonus = 0; break;
  5953. }
  5954. }
  5955. ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == skill_id);
  5956. if( i < ARRAYLENGTH(sd->skillheal) )
  5957. bonus += sd->skillheal[i].val;
  5958. return bonus;
  5959. }
  5960. int pc_skillheal2_bonus(struct map_session_data *sd, uint16 skill_id) {
  5961. int i, bonus = sd->bonus.add_heal2_rate;
  5962. ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == skill_id);
  5963. if( i < ARRAYLENGTH(sd->skillheal2) )
  5964. bonus += sd->skillheal2[i].val;
  5965. return bonus;
  5966. }
  5967. void pc_respawn(struct map_session_data* sd, clr_type clrtype)
  5968. {
  5969. if( !pc_isdead(sd) )
  5970. return; // not applicable
  5971. if( sd->bg_id && bg_member_respawn(sd) )
  5972. return; // member revived by battleground
  5973. pc_setstand(sd);
  5974. pc_setrestartvalue(sd,3);
  5975. if( pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype) )
  5976. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  5977. }
  5978. static int pc_respawn_timer(int tid, unsigned int tick, int id, intptr_t data)
  5979. {
  5980. struct map_session_data *sd = map_id2sd(id);
  5981. if( sd != NULL )
  5982. {
  5983. sd->pvp_point=0;
  5984. pc_respawn(sd,CLR_OUTSIGHT);
  5985. }
  5986. return 0;
  5987. }
  5988. /*==========================================
  5989. * Invoked when a player has received damage
  5990. *------------------------------------------*/
  5991. void pc_damage(struct map_session_data *sd,struct block_list *src,unsigned int hp, unsigned int sp)
  5992. {
  5993. if (sp) clif_updatestatus(sd,SP_SP);
  5994. if (hp) clif_updatestatus(sd,SP_HP);
  5995. else return;
  5996. if( !src || src == &sd->bl )
  5997. return;
  5998. if( pc_issit(sd) ) {
  5999. pc_setstand(sd);
  6000. skill_sit(sd,0);
  6001. }
  6002. if( sd->progressbar.npc_id )
  6003. clif_progressbar_abort(sd);
  6004. if( sd->status.pet_id > 0 && sd->pd && battle_config.pet_damage_support )
  6005. pet_target_check(sd,src,1);
  6006. if( sd->status.ele_id > 0 )
  6007. elemental_set_target(sd,src);
  6008. sd->canlog_tick = gettick();
  6009. }
  6010. int pc_close_npc_timer(int tid, unsigned int tick, int id, intptr_t data)
  6011. {
  6012. TBL_PC *sd = map_id2sd(id);
  6013. if(sd) pc_close_npc(sd,data);
  6014. return 0;
  6015. }
  6016. /*
  6017. * Method to properly close npc for player and clear anything related
  6018. * @flag == 1 : produce close button
  6019. * @flag == 2 : directly close it
  6020. */
  6021. void pc_close_npc(struct map_session_data *sd,int flag)
  6022. {
  6023. nullpo_retv(sd);
  6024. if (sd->npc_id || sd->npc_shopid) {
  6025. if (sd->state.using_fake_npc) {
  6026. clif_clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd);
  6027. sd->state.using_fake_npc = 0;
  6028. }
  6029. if (sd->st) {
  6030. if(sd->st->state == RUN){ //wait ending code execution
  6031. add_timer(gettick()+500,pc_close_npc_timer,sd->bl.id,flag);
  6032. return;
  6033. }
  6034. sd->st->state = ((flag==1 && sd->st->mes_active)?CLOSE:END);
  6035. sd->st->mes_active = 0;
  6036. }
  6037. sd->state.menu_or_input = 0;
  6038. sd->npc_menu = 0;
  6039. sd->npc_shopid = 0;
  6040. #ifdef SECURE_NPCTIMEOUT
  6041. sd->npc_idle_timer = INVALID_TIMER;
  6042. #endif
  6043. clif_scriptclose(sd,sd->npc_id);
  6044. clif_scriptclear(sd,sd->npc_id); // [Ind/Hercules]
  6045. if(sd->st && sd->st->state == END ) {// free attached scripts that are waiting
  6046. script_free_state(sd->st);
  6047. sd->st = NULL;
  6048. sd->npc_id = 0;
  6049. }
  6050. }
  6051. }
  6052. /*==========================================
  6053. * Invoked when a player has negative current hp
  6054. *------------------------------------------*/
  6055. int pc_dead(struct map_session_data *sd,struct block_list *src)
  6056. {
  6057. int i=0,k=0;
  6058. unsigned int tick = gettick();
  6059. // Activate Steel body if a super novice dies at 99+% exp [celest]
  6060. // Super Novices have no kill or die functions attached when saved by their angel
  6061. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && !sd->state.snovice_dead_flag) {
  6062. unsigned int next = pc_nextbaseexp(sd);
  6063. if( next == 0 ) next = pc_thisbaseexp(sd);
  6064. if( get_percentage(sd->status.base_exp,next) >= 99 ) {
  6065. sd->state.snovice_dead_flag = 1;
  6066. pc_setrestartvalue(sd,1);
  6067. status_percent_heal(&sd->bl, 100, 100);
  6068. clif_resurrection(&sd->bl, 1);
  6069. if(battle_config.pc_invincible_time)
  6070. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  6071. sc_start(&sd->bl,&sd->bl,status_skill2sc(MO_STEELBODY),100,5,skill_get_time(MO_STEELBODY,5));
  6072. if(map_flag_gvg(sd->bl.m))
  6073. pc_respawn_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
  6074. return 0;
  6075. }
  6076. }
  6077. for(k = 0; k < 5; k++)
  6078. if (sd->devotion[k]){
  6079. struct map_session_data *devsd = map_id2sd(sd->devotion[k]);
  6080. if (devsd)
  6081. status_change_end(&devsd->bl, SC_DEVOTION, INVALID_TIMER);
  6082. sd->devotion[k] = 0;
  6083. }
  6084. if(sd->shadowform_id) { //if we were target of shadowform
  6085. status_change_end(map_id2bl(sd->shadowform_id), SC__SHADOWFORM, INVALID_TIMER);
  6086. sd->shadowform_id = 0; //should be remove on status end anyway
  6087. }
  6088. if(sd->status.pet_id > 0 && sd->pd) {
  6089. struct pet_data *pd = sd->pd;
  6090. if( !map[sd->bl.m].flag.noexppenalty ) {
  6091. pet_set_intimate(pd, pd->pet.intimate - pd->petDB->die);
  6092. if( pd->pet.intimate < 0 )
  6093. pd->pet.intimate = 0;
  6094. clif_send_petdata(sd,sd->pd,1,pd->pet.intimate);
  6095. }
  6096. if( sd->pd->target_id ) // Unlock all targets...
  6097. pet_unlocktarget(sd->pd);
  6098. }
  6099. if (sd->status.hom_id > 0) {
  6100. if(battle_config.homunculus_auto_vapor && sd->hd && !sd->hd->sc.data[SC_LIGHT_OF_REGENE])
  6101. merc_hom_vaporize(sd, HOM_ST_ACTIVE);
  6102. }
  6103. if( sd->md )
  6104. merc_delete(sd->md, 3); // Your mercenary soldier has ran away.
  6105. if( sd->ed )
  6106. elemental_delete(sd->ed, 0);
  6107. // Leave duel if you die [LuzZza]
  6108. if(battle_config.duel_autoleave_when_die) {
  6109. if(sd->duel_group > 0)
  6110. duel_leave(sd->duel_group, sd);
  6111. if(sd->duel_invite > 0)
  6112. duel_reject(sd->duel_invite, sd);
  6113. }
  6114. pc_close_npc(sd,2); //close npc if we were using one
  6115. /* e.g. not killed thru pc_damage */
  6116. if( pc_issit(sd) ) {
  6117. clif_status_load(&sd->bl,SI_SIT,0);
  6118. }
  6119. pc_setdead(sd);
  6120. pc_setglobalreg(sd,"PC_DIE_COUNTER",sd->die_counter+1);
  6121. pc_setparam(sd, SP_KILLERRID, src?src->id:0);
  6122. //Reset menu skills/item skills
  6123. if ((sd->skillitem) != 0)
  6124. sd->skillitem = sd->skillitemlv = 0;
  6125. if ((sd->menuskill_id) != 0)
  6126. sd->menuskill_id = sd->menuskill_val = 0;
  6127. //Reset ticks.
  6128. sd->hp_loss.tick = sd->sp_loss.tick = sd->hp_regen.tick = sd->sp_regen.tick = 0;
  6129. if ( sd->spiritball !=0 )
  6130. pc_delspiritball(sd,sd->spiritball,0);
  6131. for(i = 1; i < 5; i++)
  6132. pc_del_talisman(sd, sd->talisman[i], i);
  6133. if (src)
  6134. switch (src->type) {
  6135. case BL_MOB:
  6136. {
  6137. struct mob_data *md=(struct mob_data *)src;
  6138. if(md->target_id==sd->bl.id)
  6139. mob_unlocktarget(md,tick);
  6140. if(battle_config.mobs_level_up && md->status.hp &&
  6141. (unsigned int)md->level < pc_maxbaselv(sd) &&
  6142. !md->guardian_data && !md->special_state.ai// Guardians/summons should not level. [Skotlex]
  6143. ) { // monster level up [Valaris]
  6144. clif_misceffect(&md->bl,0);
  6145. md->level++;
  6146. status_calc_mob(md, 0);
  6147. status_percent_heal(src,10,0);
  6148. if( battle_config.show_mob_info&4 )
  6149. {// update name with new level
  6150. clif_charnameack(0, &md->bl);
  6151. }
  6152. }
  6153. src = battle_get_master(src); // Maybe Player Summon
  6154. }
  6155. break;
  6156. case BL_PET: //Pass on to master...
  6157. case BL_HOM:
  6158. case BL_MER:
  6159. src = battle_get_master(src);
  6160. break;
  6161. }
  6162. if (src && src->type == BL_PC) {
  6163. struct map_session_data *ssd = (struct map_session_data *)src;
  6164. pc_setparam(ssd, SP_KILLEDRID, sd->bl.id);
  6165. npc_script_event(ssd, NPCE_KILLPC);
  6166. if (battle_config.pk_mode&2) {
  6167. ssd->status.manner -= 5;
  6168. if(ssd->status.manner < 0)
  6169. sc_start(&sd->bl,src,SC_NOCHAT,100,0,0);
  6170. #if 0
  6171. // PK/Karma system code (not enabled yet) [celest]
  6172. // originally from Kade Online, so i don't know if any of these is correct ^^;
  6173. // note: karma is measured REVERSE, so more karma = more 'evil' / less honourable,
  6174. // karma going down = more 'good' / more honourable.
  6175. // The Karma System way...
  6176. if (sd->status.karma > ssd->status.karma) { // If player killed was more evil
  6177. sd->status.karma--;
  6178. ssd->status.karma--;
  6179. }
  6180. else if (sd->status.karma < ssd->status.karma) // If player killed was more good
  6181. ssd->status.karma++;
  6182. // or the PK System way...
  6183. if (sd->status.karma > 0) // player killed is dishonourable?
  6184. ssd->status.karma--; // honour points earned
  6185. sd->status.karma++; // honour points lost
  6186. // To-do: Receive exp on certain occasions
  6187. #endif
  6188. }
  6189. }
  6190. if(battle_config.bone_drop==2
  6191. || (battle_config.bone_drop==1 && map[sd->bl.m].flag.pvp))
  6192. {
  6193. struct item item_tmp;
  6194. memset(&item_tmp,0,sizeof(item_tmp));
  6195. item_tmp.nameid=ITEMID_SKULL_;
  6196. item_tmp.identify=1;
  6197. item_tmp.card[0]=CARD0_CREATE;
  6198. item_tmp.card[1]=0;
  6199. item_tmp.card[2]=GetWord(sd->status.char_id,0); // CharId
  6200. item_tmp.card[3]=GetWord(sd->status.char_id,1);
  6201. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
  6202. }
  6203. //Remove bonus_script when dead
  6204. pc_bonus_script_clear(sd,BONUS_FLAG_REM_ON_DEAD);
  6205. // changed penalty options, added death by player if pk_mode [Valaris]
  6206. if(battle_config.death_penalty_type
  6207. && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE // only novices will receive no penalty
  6208. && !map[sd->bl.m].flag.noexppenalty && !map_flag_gvg(sd->bl.m)
  6209. && !sd->sc.data[SC_BABY] && !sd->sc.data[SC_LIFEINSURANCE])
  6210. {
  6211. uint32 base_penalty = battle_config.death_penalty_base;
  6212. uint32 job_penalty = battle_config.death_penalty_job;
  6213. uint32 zeny_penalty = battle_config.zeny_penalty;
  6214. #ifdef VIP_ENABLE
  6215. if(pc_isvip(sd)){
  6216. base_penalty *= battle_config.vip_exp_penalty_base;
  6217. job_penalty *= battle_config.vip_exp_penalty_job;
  6218. }
  6219. else {
  6220. base_penalty *= battle_config.vip_exp_penalty_base_normal;
  6221. job_penalty *= battle_config.vip_exp_penalty_job_normal;
  6222. }
  6223. #endif
  6224. if (base_penalty > 0) {
  6225. switch (battle_config.death_penalty_type) {
  6226. case 1: base_penalty = (uint32) ( pc_nextbaseexp(sd) * ( base_penalty / 10000. ) ); break;
  6227. case 2: base_penalty = (uint32) ( sd->status.base_exp * ( base_penalty / 10000. ) ); break;
  6228. }
  6229. if (base_penalty > 0){ //recheck after altering to speedup
  6230. if (battle_config.pk_mode && src && src->type==BL_PC)
  6231. base_penalty*=2;
  6232. sd->status.base_exp -= min(sd->status.base_exp, base_penalty);
  6233. clif_updatestatus(sd,SP_BASEEXP);
  6234. }
  6235. }
  6236. if(job_penalty > 0) {
  6237. switch (battle_config.death_penalty_type) {
  6238. case 1: job_penalty = (uint32) ( pc_nextjobexp(sd) * ( job_penalty / 10000. ) ); break;
  6239. case 2: job_penalty = (uint32) ( sd->status.job_exp * ( job_penalty /10000. ) ); break;
  6240. }
  6241. if(job_penalty) {
  6242. if (battle_config.pk_mode && src && src->type==BL_PC)
  6243. job_penalty*=2;
  6244. sd->status.job_exp -= min(sd->status.job_exp, job_penalty);
  6245. clif_updatestatus(sd,SP_JOBEXP);
  6246. }
  6247. }
  6248. if( zeny_penalty > 0 && !map[sd->bl.m].flag.nozenypenalty) {
  6249. zeny_penalty = (uint32)( sd->status.zeny * ( zeny_penalty / 10000. ) );
  6250. if(zeny_penalty)
  6251. pc_payzeny(sd, zeny_penalty, LOG_TYPE_PICKDROP_PLAYER, NULL);
  6252. }
  6253. }
  6254. if(map[sd->bl.m].flag.pvp_nightmaredrop) { // Moved this outside so it works when PVP isn't enabled and during pk mode [Ancyker]
  6255. int j;
  6256. for(j=0;j<MAX_DROP_PER_MAP;j++){
  6257. int id = map[sd->bl.m].drop_list[j].drop_id;
  6258. int type = map[sd->bl.m].drop_list[j].drop_type;
  6259. int per = map[sd->bl.m].drop_list[j].drop_per;
  6260. if(id == 0)
  6261. continue;
  6262. if(id == -1){
  6263. int eq_num=0,eq_n[MAX_INVENTORY];
  6264. memset(eq_n,0,sizeof(eq_n));
  6265. for(i=0;i<MAX_INVENTORY;i++) {
  6266. if( (type == 1 && !sd->status.inventory[i].equip)
  6267. || (type == 2 && sd->status.inventory[i].equip)
  6268. || type == 3)
  6269. {
  6270. int k;
  6271. ARR_FIND( 0, MAX_INVENTORY, k, eq_n[k] <= 0 );
  6272. if( k < MAX_INVENTORY )
  6273. eq_n[k] = i;
  6274. eq_num++;
  6275. }
  6276. }
  6277. if(eq_num > 0){
  6278. int n = eq_n[rnd()%eq_num];
  6279. if(rnd()%10000 < per) {
  6280. if(sd->status.inventory[n].equip)
  6281. pc_unequipitem(sd,n,3);
  6282. pc_dropitem(sd,n,1);
  6283. }
  6284. }
  6285. }
  6286. else if(id > 0) {
  6287. for(i=0;i<MAX_INVENTORY;i++){
  6288. if(sd->status.inventory[i].nameid == id
  6289. && rnd()%10000 < per
  6290. && ((type == 1 && !sd->status.inventory[i].equip)
  6291. || (type == 2 && sd->status.inventory[i].equip)
  6292. || type == 3) ){
  6293. if(sd->status.inventory[i].equip)
  6294. pc_unequipitem(sd,i,3);
  6295. pc_dropitem(sd,i,1);
  6296. break;
  6297. }
  6298. }
  6299. }
  6300. }
  6301. }
  6302. // pvp
  6303. // disable certain pvp functions on pk_mode [Valaris]
  6304. if( map[sd->bl.m].flag.pvp && !battle_config.pk_mode && !map[sd->bl.m].flag.pvp_nocalcrank ) {
  6305. sd->pvp_point -= 5;
  6306. sd->pvp_lost++;
  6307. if( src && src->type == BL_PC ) {
  6308. struct map_session_data *ssd = (struct map_session_data *)src;
  6309. ssd->pvp_point++;
  6310. ssd->pvp_won++;
  6311. }
  6312. if( sd->pvp_point < 0 ) {
  6313. add_timer(tick+1000, pc_respawn_timer,sd->bl.id,0);
  6314. return 1|8;
  6315. }
  6316. }
  6317. //GvG
  6318. if( map_flag_gvg(sd->bl.m) ) {
  6319. add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
  6320. return 1|8;
  6321. }
  6322. else if( sd->bg_id ) {
  6323. struct battleground_data *bg = bg_team_search(sd->bg_id);
  6324. if( bg && bg->mapindex > 0 ) { // Respawn by BG
  6325. add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
  6326. return 1|8;
  6327. }
  6328. }
  6329. //Reset "can log out" tick.
  6330. if( battle_config.prevent_logout )
  6331. sd->canlog_tick = gettick() - battle_config.prevent_logout;
  6332. return 1;
  6333. }
  6334. void pc_revive(struct map_session_data *sd,unsigned int hp, unsigned int sp) {
  6335. if(hp) clif_updatestatus(sd,SP_HP);
  6336. if(sp) clif_updatestatus(sd,SP_SP);
  6337. pc_setstand(sd);
  6338. if(battle_config.pc_invincible_time > 0)
  6339. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  6340. if( sd->state.gmaster_flag ) {
  6341. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  6342. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  6343. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  6344. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  6345. }
  6346. }
  6347. // script
  6348. //
  6349. /*==========================================
  6350. * script reading pc status registry
  6351. *------------------------------------------*/
  6352. int pc_readparam(struct map_session_data* sd,int type)
  6353. {
  6354. int val = 0;
  6355. nullpo_ret(sd);
  6356. switch(type) {
  6357. case SP_SKILLPOINT: val = sd->status.skill_point; break;
  6358. case SP_STATUSPOINT: val = sd->status.status_point; break;
  6359. case SP_ZENY: val = sd->status.zeny; break;
  6360. case SP_BASELEVEL: val = sd->status.base_level; break;
  6361. case SP_JOBLEVEL: val = sd->status.job_level; break;
  6362. case SP_CLASS: val = sd->status.class_; break;
  6363. case SP_BASEJOB: val = pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex); break; //Base job, extracting upper type.
  6364. case SP_UPPER: val = sd->class_&JOBL_UPPER?1:(sd->class_&JOBL_BABY?2:0); break;
  6365. case SP_BASECLASS: val = pc_mapid2jobid(sd->class_&MAPID_BASEMASK, sd->status.sex); break; //Extract base class tree. [Skotlex]
  6366. case SP_SEX: val = sd->status.sex; break;
  6367. case SP_WEIGHT: val = sd->weight; break;
  6368. case SP_MAXWEIGHT: val = sd->max_weight; break;
  6369. case SP_BASEEXP: val = sd->status.base_exp; break;
  6370. case SP_JOBEXP: val = sd->status.job_exp; break;
  6371. case SP_NEXTBASEEXP: val = pc_nextbaseexp(sd); break;
  6372. case SP_NEXTJOBEXP: val = pc_nextjobexp(sd); break;
  6373. case SP_HP: val = sd->battle_status.hp; break;
  6374. case SP_MAXHP: val = sd->battle_status.max_hp; break;
  6375. case SP_SP: val = sd->battle_status.sp; break;
  6376. case SP_MAXSP: val = sd->battle_status.max_sp; break;
  6377. case SP_STR: val = sd->status.str; break;
  6378. case SP_AGI: val = sd->status.agi; break;
  6379. case SP_VIT: val = sd->status.vit; break;
  6380. case SP_INT: val = sd->status.int_; break;
  6381. case SP_DEX: val = sd->status.dex; break;
  6382. case SP_LUK: val = sd->status.luk; break;
  6383. case SP_KARMA: val = sd->status.karma; break;
  6384. case SP_MANNER: val = sd->status.manner; break;
  6385. case SP_FAME: val = sd->status.fame; break;
  6386. case SP_KILLERRID: val = sd->killerrid; break;
  6387. case SP_KILLEDRID: val = sd->killedrid; break;
  6388. case SP_SITTING: val = pc_issit(sd)?1:0; break;
  6389. case SP_CHARMOVE: val = sd->status.character_moves; break;
  6390. case SP_CRITICAL: val = sd->battle_status.cri/10; break;
  6391. case SP_ASPD: val = (2000-sd->battle_status.amotion)/10; break;
  6392. case SP_BASE_ATK: val = sd->battle_status.batk; break;
  6393. case SP_DEF1: val = sd->battle_status.def; break;
  6394. case SP_DEF2: val = sd->battle_status.def2; break;
  6395. case SP_MDEF1: val = sd->battle_status.mdef; break;
  6396. case SP_MDEF2: val = sd->battle_status.mdef2; break;
  6397. case SP_HIT: val = sd->battle_status.hit; break;
  6398. case SP_FLEE1: val = sd->battle_status.flee; break;
  6399. case SP_FLEE2: val = sd->battle_status.flee2; break;
  6400. case SP_DEFELE: val = sd->battle_status.def_ele; break;
  6401. #ifndef RENEWAL_CAST
  6402. case SP_VARCASTRATE:
  6403. #endif
  6404. case SP_CASTRATE:
  6405. val = sd->castrate+=val;
  6406. break;
  6407. case SP_MAXHPRATE: val = sd->hprate; break;
  6408. case SP_MAXSPRATE: val = sd->sprate; break;
  6409. case SP_SPRATE: val = sd->dsprate; break;
  6410. case SP_SPEED_RATE: val = sd->bonus.speed_rate; break;
  6411. case SP_SPEED_ADDRATE: val = sd->bonus.speed_add_rate; break;
  6412. case SP_ASPD_RATE:
  6413. #ifndef RENEWAL_ASPD
  6414. val = sd->battle_status.aspd_rate;
  6415. #else
  6416. val = sd->battle_status.aspd_rate2;
  6417. #endif
  6418. break;
  6419. case SP_HP_RECOV_RATE: val = sd->hprecov_rate; break;
  6420. case SP_SP_RECOV_RATE: val = sd->sprecov_rate; break;
  6421. case SP_CRITICAL_DEF: val = sd->bonus.critical_def; break;
  6422. case SP_NEAR_ATK_DEF: val = sd->bonus.near_attack_def_rate; break;
  6423. case SP_LONG_ATK_DEF: val = sd->bonus.long_attack_def_rate; break;
  6424. case SP_DOUBLE_RATE: val = sd->bonus.double_rate; break;
  6425. case SP_DOUBLE_ADD_RATE: val = sd->bonus.double_add_rate; break;
  6426. case SP_MATK_RATE: val = sd->matk_rate; break;
  6427. case SP_ATK_RATE: val = sd->bonus.atk_rate; break;
  6428. case SP_MAGIC_ATK_DEF: val = sd->bonus.magic_def_rate; break;
  6429. case SP_MISC_ATK_DEF: val = sd->bonus.misc_def_rate; break;
  6430. case SP_PERFECT_HIT_RATE:val = sd->bonus.perfect_hit; break;
  6431. case SP_PERFECT_HIT_ADD_RATE: val = sd->bonus.perfect_hit_add; break;
  6432. case SP_CRITICAL_RATE: val = sd->critical_rate; break;
  6433. case SP_HIT_RATE: val = sd->hit_rate; break;
  6434. case SP_FLEE_RATE: val = sd->flee_rate; break;
  6435. case SP_FLEE2_RATE: val = sd->flee2_rate; break;
  6436. case SP_DEF_RATE: val = sd->def_rate; break;
  6437. case SP_DEF2_RATE: val = sd->def2_rate; break;
  6438. case SP_MDEF_RATE: val = sd->mdef_rate; break;
  6439. case SP_MDEF2_RATE: val = sd->mdef2_rate; break;
  6440. case SP_RESTART_FULL_RECOVER: val = sd->special_state.restart_full_recover?1:0; break;
  6441. case SP_NO_CASTCANCEL: val = sd->special_state.no_castcancel?1:0; break;
  6442. case SP_NO_CASTCANCEL2: val = sd->special_state.no_castcancel2?1:0; break;
  6443. case SP_NO_SIZEFIX: val = sd->special_state.no_sizefix?1:0; break;
  6444. case SP_NO_MAGIC_DAMAGE: val = sd->special_state.no_magic_damage; break;
  6445. case SP_NO_WEAPON_DAMAGE:val = sd->special_state.no_weapon_damage; break;
  6446. case SP_NO_MISC_DAMAGE: val = sd->special_state.no_misc_damage; break;
  6447. case SP_NO_GEMSTONE: val = sd->special_state.no_gemstone?1:0; break;
  6448. case SP_INTRAVISION: val = sd->special_state.intravision?1:0; break;
  6449. case SP_NO_KNOCKBACK: val = sd->special_state.no_knockback?1:0; break;
  6450. case SP_SPLASH_RANGE: val = sd->bonus.splash_range; break;
  6451. case SP_SPLASH_ADD_RANGE:val = sd->bonus.splash_add_range; break;
  6452. case SP_SHORT_WEAPON_DAMAGE_RETURN: val = sd->bonus.short_weapon_damage_return; break;
  6453. case SP_LONG_WEAPON_DAMAGE_RETURN: val = sd->bonus.long_weapon_damage_return; break;
  6454. case SP_MAGIC_DAMAGE_RETURN: val = sd->bonus.magic_damage_return; break;
  6455. case SP_PERFECT_HIDE: val = sd->special_state.perfect_hiding?1:0; break;
  6456. case SP_UNBREAKABLE: val = sd->bonus.unbreakable; break;
  6457. case SP_UNBREAKABLE_WEAPON: val = (sd->bonus.unbreakable_equip&EQP_WEAPON)?1:0; break;
  6458. case SP_UNBREAKABLE_ARMOR: val = (sd->bonus.unbreakable_equip&EQP_ARMOR)?1:0; break;
  6459. case SP_UNBREAKABLE_HELM: val = (sd->bonus.unbreakable_equip&EQP_HELM)?1:0; break;
  6460. case SP_UNBREAKABLE_SHIELD: val = (sd->bonus.unbreakable_equip&EQP_SHIELD)?1:0; break;
  6461. case SP_UNBREAKABLE_GARMENT: val = (sd->bonus.unbreakable_equip&EQP_GARMENT)?1:0; break;
  6462. case SP_UNBREAKABLE_SHOES: val = (sd->bonus.unbreakable_equip&EQP_SHOES)?1:0; break;
  6463. case SP_CLASSCHANGE: val = sd->bonus.classchange; break;
  6464. case SP_LONG_ATK_RATE: val = sd->bonus.long_attack_atk_rate; break;
  6465. case SP_BREAK_WEAPON_RATE: val = sd->bonus.break_weapon_rate; break;
  6466. case SP_BREAK_ARMOR_RATE: val = sd->bonus.break_armor_rate; break;
  6467. case SP_ADD_STEAL_RATE: val = sd->bonus.add_steal_rate; break;
  6468. case SP_DELAYRATE: val = sd->delayrate; break;
  6469. case SP_CRIT_ATK_RATE: val = sd->bonus.crit_atk_rate; break;
  6470. case SP_UNSTRIPABLE_WEAPON: val = (sd->bonus.unstripable_equip&EQP_WEAPON)?1:0; break;
  6471. case SP_UNSTRIPABLE:
  6472. case SP_UNSTRIPABLE_ARMOR:
  6473. val = (sd->bonus.unstripable_equip&EQP_ARMOR)?1:0;
  6474. break;
  6475. case SP_UNSTRIPABLE_HELM: val = (sd->bonus.unstripable_equip&EQP_HELM)?1:0; break;
  6476. case SP_UNSTRIPABLE_SHIELD: val = (sd->bonus.unstripable_equip&EQP_SHIELD)?1:0; break;
  6477. case SP_SP_GAIN_VALUE: val = sd->bonus.sp_gain_value; break;
  6478. case SP_HP_GAIN_VALUE: val = sd->bonus.hp_gain_value; break;
  6479. case SP_MAGIC_SP_GAIN_VALUE: val = sd->bonus.magic_sp_gain_value; break;
  6480. case SP_MAGIC_HP_GAIN_VALUE: val = sd->bonus.magic_hp_gain_value; break;
  6481. case SP_ADD_HEAL_RATE: val = sd->bonus.add_heal_rate; break;
  6482. case SP_ADD_HEAL2_RATE: val = sd->bonus.add_heal2_rate; break;
  6483. case SP_ADD_ITEM_HEAL_RATE: val = sd->bonus.itemhealrate2; break;
  6484. case SP_EMATK: val = sd->bonus.ematk; break;
  6485. case SP_FIXCASTRATE: val = sd->bonus.fixcastrate; break;
  6486. case SP_ADD_FIXEDCAST: val = sd->bonus.add_fixcast; break;
  6487. #ifdef RENEWAL_CAST
  6488. case SP_VARCASTRATE: val = sd->bonus.varcastrate; break;
  6489. case SP_ADD_VARIABLECAST:val = sd->bonus.add_varcast; break;
  6490. #endif
  6491. }
  6492. return val;
  6493. }
  6494. /*==========================================
  6495. * script set pc status registry
  6496. *------------------------------------------*/
  6497. bool pc_setparam(struct map_session_data *sd,int type,int val)
  6498. {
  6499. nullpo_retr(false,sd);
  6500. switch(type){
  6501. case SP_BASELEVEL:
  6502. if ((unsigned int)val > pc_maxbaselv(sd)) //Capping to max
  6503. val = pc_maxbaselv(sd);
  6504. if ((unsigned int)val > sd->status.base_level) {
  6505. int i = 0;
  6506. int stat=0;
  6507. for (i = 0; i < (int)((unsigned int)val - sd->status.base_level); i++)
  6508. stat += pc_gets_status_point(sd->status.base_level + i);
  6509. sd->status.status_point += stat;
  6510. }
  6511. sd->status.base_level = (unsigned int)val;
  6512. sd->status.base_exp = 0;
  6513. // clif_updatestatus(sd, SP_BASELEVEL); // Gets updated at the bottom
  6514. clif_updatestatus(sd, SP_NEXTBASEEXP);
  6515. clif_updatestatus(sd, SP_STATUSPOINT);
  6516. clif_updatestatus(sd, SP_BASEEXP);
  6517. status_calc_pc(sd, 0);
  6518. if(sd->status.party_id)
  6519. {
  6520. party_send_levelup(sd);
  6521. }
  6522. break;
  6523. case SP_JOBLEVEL:
  6524. if ((unsigned int)val >= sd->status.job_level) {
  6525. if ((unsigned int)val > pc_maxjoblv(sd)) val = pc_maxjoblv(sd);
  6526. sd->status.skill_point += val - sd->status.job_level;
  6527. clif_updatestatus(sd, SP_SKILLPOINT);
  6528. }
  6529. sd->status.job_level = (unsigned int)val;
  6530. sd->status.job_exp = 0;
  6531. // clif_updatestatus(sd, SP_JOBLEVEL); // Gets updated at the bottom
  6532. clif_updatestatus(sd, SP_NEXTJOBEXP);
  6533. clif_updatestatus(sd, SP_JOBEXP);
  6534. status_calc_pc(sd, 0);
  6535. break;
  6536. case SP_SKILLPOINT:
  6537. sd->status.skill_point = val;
  6538. break;
  6539. case SP_STATUSPOINT:
  6540. sd->status.status_point = val;
  6541. break;
  6542. case SP_ZENY:
  6543. if( val < 0 )
  6544. return false;// can't set negative zeny
  6545. log_zeny(sd, LOG_TYPE_SCRIPT, sd, -(sd->status.zeny - cap_value(val, 0, MAX_ZENY)));
  6546. sd->status.zeny = cap_value(val, 0, MAX_ZENY);
  6547. break;
  6548. case SP_BASEEXP:
  6549. if(pc_nextbaseexp(sd) > 0) {
  6550. sd->status.base_exp = val;
  6551. pc_checkbaselevelup(sd);
  6552. }
  6553. break;
  6554. case SP_JOBEXP:
  6555. if(pc_nextjobexp(sd) > 0) {
  6556. sd->status.job_exp = val;
  6557. pc_checkjoblevelup(sd);
  6558. }
  6559. break;
  6560. case SP_SEX:
  6561. sd->status.sex = val ? SEX_MALE : SEX_FEMALE;
  6562. break;
  6563. case SP_WEIGHT:
  6564. sd->weight = val;
  6565. break;
  6566. case SP_MAXWEIGHT:
  6567. sd->max_weight = val;
  6568. break;
  6569. case SP_HP:
  6570. sd->battle_status.hp = cap_value(val, 1, (int)sd->battle_status.max_hp);
  6571. break;
  6572. case SP_MAXHP:
  6573. sd->battle_status.max_hp = cap_value(val, 1, battle_config.max_hp);
  6574. if( sd->battle_status.max_hp < sd->battle_status.hp )
  6575. {
  6576. sd->battle_status.hp = sd->battle_status.max_hp;
  6577. clif_updatestatus(sd, SP_HP);
  6578. }
  6579. break;
  6580. case SP_SP:
  6581. sd->battle_status.sp = cap_value(val, 0, (int)sd->battle_status.max_sp);
  6582. break;
  6583. case SP_MAXSP:
  6584. sd->battle_status.max_sp = cap_value(val, 1, battle_config.max_sp);
  6585. if( sd->battle_status.max_sp < sd->battle_status.sp )
  6586. {
  6587. sd->battle_status.sp = sd->battle_status.max_sp;
  6588. clif_updatestatus(sd, SP_SP);
  6589. }
  6590. break;
  6591. case SP_STR:
  6592. sd->status.str = cap_value(val, 1, pc_maxparameter(sd,PARAM_STR));
  6593. break;
  6594. case SP_AGI:
  6595. sd->status.agi = cap_value(val, 1, pc_maxparameter(sd,PARAM_AGI));
  6596. break;
  6597. case SP_VIT:
  6598. sd->status.vit = cap_value(val, 1, pc_maxparameter(sd,PARAM_VIT));
  6599. break;
  6600. case SP_INT:
  6601. sd->status.int_ = cap_value(val, 1, pc_maxparameter(sd,PARAM_INT));
  6602. break;
  6603. case SP_DEX:
  6604. sd->status.dex = cap_value(val, 1, pc_maxparameter(sd,PARAM_DEX));
  6605. break;
  6606. case SP_LUK:
  6607. sd->status.luk = cap_value(val, 1, pc_maxparameter(sd,PARAM_LUK));
  6608. break;
  6609. case SP_KARMA:
  6610. sd->status.karma = val;
  6611. break;
  6612. case SP_MANNER:
  6613. sd->status.manner = val;
  6614. break;
  6615. case SP_FAME:
  6616. sd->status.fame = val;
  6617. break;
  6618. case SP_KILLERRID:
  6619. sd->killerrid = val;
  6620. return true;
  6621. case SP_KILLEDRID:
  6622. sd->killedrid = val;
  6623. return true;
  6624. case SP_CHARMOVE:
  6625. sd->status.character_moves = val;
  6626. return true;
  6627. default:
  6628. ShowError("pc_setparam: Attempted to set unknown parameter '%d'.\n", type);
  6629. return false;
  6630. }
  6631. clif_updatestatus(sd,type);
  6632. return true;
  6633. }
  6634. /*==========================================
  6635. * HP/SP Healing. If flag is passed, the heal type is through clif_heal, otherwise update status.
  6636. *------------------------------------------*/
  6637. void pc_heal(struct map_session_data *sd,unsigned int hp,unsigned int sp, int type)
  6638. {
  6639. if (type) {
  6640. if (hp)
  6641. clif_heal(sd->fd,SP_HP,hp);
  6642. if (sp)
  6643. clif_heal(sd->fd,SP_SP,sp);
  6644. } else {
  6645. if(hp)
  6646. clif_updatestatus(sd,SP_HP);
  6647. if(sp)
  6648. clif_updatestatus(sd,SP_SP);
  6649. }
  6650. return;
  6651. }
  6652. /*==========================================
  6653. * HP/SP Recovery
  6654. * Heal player hp and/or sp linearly.
  6655. * Calculate bonus by status.
  6656. *------------------------------------------*/
  6657. int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
  6658. {
  6659. int bonus;
  6660. if(hp) {
  6661. int i;
  6662. bonus = 100 + (sd->battle_status.vit<<1)
  6663. + pc_checkskill(sd,SM_RECOVERY)*10
  6664. + pc_checkskill(sd,AM_LEARNINGPOTION)*5;
  6665. // A potion produced by an Alchemist in the Fame Top 10 gets +50% effect [DracoRPG]
  6666. if (potion_flag > 1)
  6667. bonus += bonus*(potion_flag-1)*50/100;
  6668. //All item bonuses.
  6669. bonus += sd->bonus.itemhealrate2;
  6670. //Item Group bonuses
  6671. bonus += bonus*itemdb_group_bonus(sd, itemid)/100;
  6672. //Individual item bonuses.
  6673. for(i = 0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid; i++)
  6674. {
  6675. if (sd->itemhealrate[i].nameid == itemid) {
  6676. bonus += bonus*sd->itemhealrate[i].rate/100;
  6677. break;
  6678. }
  6679. }
  6680. if(bonus!=100)
  6681. hp = hp * bonus / 100;
  6682. // Recovery Potion
  6683. if( sd->sc.data[SC_INCHEALRATE] )
  6684. hp += (int)(hp * sd->sc.data[SC_INCHEALRATE]->val1/100.);
  6685. }
  6686. if(sp) {
  6687. bonus = 100 + (sd->battle_status.int_<<1)
  6688. + pc_checkskill(sd,MG_SRECOVERY)*10
  6689. + pc_checkskill(sd,AM_LEARNINGPOTION)*5;
  6690. if (potion_flag > 1)
  6691. bonus += bonus*(potion_flag-1)*50/100;
  6692. if(bonus != 100)
  6693. sp = sp * bonus / 100;
  6694. }
  6695. if( sd->sc.count ) {
  6696. if ( sd->sc.data[SC_CRITICALWOUND] ) {
  6697. hp -= hp * sd->sc.data[SC_CRITICALWOUND]->val2 / 100;
  6698. sp -= sp * sd->sc.data[SC_CRITICALWOUND]->val2 / 100;
  6699. }
  6700. if ( sd->sc.data[SC_DEATHHURT] ) {
  6701. hp -= hp * 20 / 100;
  6702. sp -= sp * 20 / 100;
  6703. }
  6704. if( sd->sc.data[SC_VITALITYACTIVATION] ){
  6705. hp += hp / 2; // 1.5 times
  6706. sp -= sp / 2;
  6707. }
  6708. if( sd->sc.data[SC_WATER_INSIGNIA] && sd->sc.data[SC_WATER_INSIGNIA]->val1 == 2 ) {
  6709. hp += hp / 10;
  6710. sp += sp / 10;
  6711. }
  6712. #ifdef RENEWAL
  6713. if( sd->sc.data[SC_EXTREMITYFIST2] )
  6714. sp = 0;
  6715. #endif
  6716. }
  6717. return status_heal(&sd->bl, hp, sp, 1);
  6718. }
  6719. /*==========================================
  6720. * HP/SP Recovery
  6721. * Heal player hp nad/or sp by rate
  6722. *------------------------------------------*/
  6723. int pc_percentheal(struct map_session_data *sd,int hp,int sp)
  6724. {
  6725. nullpo_ret(sd);
  6726. if (hp > 100) hp = 100;
  6727. else if (hp <-100) hp = -100;
  6728. if (sp > 100) sp = 100;
  6729. else if (sp <-100) sp = -100;
  6730. if(hp >= 0 && sp >= 0) //Heal
  6731. return status_percent_heal(&sd->bl, hp, sp);
  6732. if(hp <= 0 && sp <= 0) //Damage (negative rates indicate % of max rather than current), and only kill target IF the specified amount is 100%
  6733. return status_percent_damage(NULL, &sd->bl, hp, sp, hp==-100);
  6734. //Crossed signs
  6735. if(hp) {
  6736. if(hp > 0)
  6737. status_percent_heal(&sd->bl, hp, 0);
  6738. else
  6739. status_percent_damage(NULL, &sd->bl, hp, 0, hp==-100);
  6740. }
  6741. if(sp) {
  6742. if(sp > 0)
  6743. status_percent_heal(&sd->bl, 0, sp);
  6744. else
  6745. status_percent_damage(NULL, &sd->bl, 0, sp, false);
  6746. }
  6747. return 0;
  6748. }
  6749. static int jobchange_killclone(struct block_list *bl, va_list ap)
  6750. {
  6751. struct mob_data *md;
  6752. int flag;
  6753. md = (struct mob_data *)bl;
  6754. nullpo_ret(md);
  6755. flag = va_arg(ap, int);
  6756. if (md->master_id && md->special_state.clone && md->master_id == flag)
  6757. status_kill(&md->bl);
  6758. return 1;
  6759. }
  6760. /*==========================================
  6761. * Called when player changes job
  6762. * Rewrote to make it tidider [Celest]
  6763. *------------------------------------------*/
  6764. int pc_jobchange(struct map_session_data *sd,int job, int upper)
  6765. {
  6766. int i, fame_flag=0;
  6767. int b_class;
  6768. nullpo_ret(sd);
  6769. if (job < 0)
  6770. return 1;
  6771. //Normalize job.
  6772. b_class = pc_jobid2mapid(job);
  6773. if (b_class == -1)
  6774. return 1;
  6775. switch (upper) {
  6776. case 1:
  6777. b_class|= JOBL_UPPER;
  6778. break;
  6779. case 2:
  6780. b_class|= JOBL_BABY;
  6781. break;
  6782. }
  6783. //This will automatically adjust bard/dancer classes to the correct gender
  6784. //That is, if you try to jobchange into dancer, it will turn you to bard.
  6785. job = pc_mapid2jobid(b_class, sd->status.sex);
  6786. if (job == -1)
  6787. return 1;
  6788. if ((unsigned short)b_class == sd->class_)
  6789. return 1; //Nothing to change.
  6790. // changing from 1st to 2nd job
  6791. if ((b_class&JOBL_2) && !(sd->class_&JOBL_2) && (b_class&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE) {
  6792. sd->change_level_2nd = sd->status.job_level;
  6793. pc_setglobalreg (sd, "jobchange_level", sd->change_level_2nd);
  6794. }
  6795. // changing from 2nd to 3rd job
  6796. else if((b_class&JOBL_THIRD) && !(sd->class_&JOBL_THIRD)) {
  6797. sd->change_level_3rd = sd->status.job_level;
  6798. pc_setglobalreg (sd, "jobchange_level_3rd", sd->change_level_3rd);
  6799. }
  6800. if(sd->cloneskill_idx >= 0) {
  6801. if( sd->status.skill[sd->cloneskill_idx].flag == SKILL_FLAG_PLAGIARIZED ) {
  6802. sd->status.skill[sd->cloneskill_idx].id = 0;
  6803. sd->status.skill[sd->cloneskill_idx].lv = 0;
  6804. sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PERMANENT;
  6805. clif_deleteskill(sd,pc_readglobalreg(sd,SKILL_VAR_PLAGIARISM));
  6806. }
  6807. sd->cloneskill_idx = -1;
  6808. pc_setglobalreg(sd,SKILL_VAR_PLAGIARISM, 0);
  6809. pc_setglobalreg(sd,SKILL_VAR_PLAGIARISM_LV, 0);
  6810. }
  6811. if(sd->reproduceskill_idx >= 0) {
  6812. if( sd->status.skill[sd->reproduceskill_idx].flag == SKILL_FLAG_PLAGIARIZED ) {
  6813. sd->status.skill[sd->reproduceskill_idx].id = 0;
  6814. sd->status.skill[sd->reproduceskill_idx].lv = 0;
  6815. sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PERMANENT;
  6816. clif_deleteskill(sd,pc_readglobalreg(sd,SKILL_VAR_REPRODUCE));
  6817. }
  6818. sd->reproduceskill_idx = -1;
  6819. pc_setglobalreg(sd,SKILL_VAR_REPRODUCE,0);
  6820. pc_setglobalreg(sd,SKILL_VAR_REPRODUCE_LV,0);
  6821. }
  6822. // Give or reduce transcendent status points
  6823. if( (b_class&JOBL_UPPER) && !(sd->class_&JOBL_UPPER) ){ // Change from a non t class to a t class -> give points
  6824. sd->status.status_point += 52;
  6825. clif_updatestatus(sd,SP_STATUSPOINT);
  6826. }else if( !(b_class&JOBL_UPPER) && (sd->class_&JOBL_UPPER) ){ // Change from a t class to a non t class -> remove points
  6827. if( sd->status.status_point < 52 ){
  6828. // The player already used his bonus points, so we have to reset his status points
  6829. pc_resetstate(sd);
  6830. }
  6831. sd->status.status_point -= 52;
  6832. clif_updatestatus(sd,SP_STATUSPOINT);
  6833. }
  6834. if ( (b_class&MAPID_UPPERMASK) != (sd->class_&MAPID_UPPERMASK) ) { //Things to remove when changing class tree.
  6835. const int class_ = pc_class2idx(sd->status.class_);
  6836. short id;
  6837. for(i = 0; i < MAX_SKILL_TREE && (id = skill_tree[class_][i].id) > 0; i++) {
  6838. //Remove status specific to your current tree skills.
  6839. enum sc_type sc = status_skill2sc(id);
  6840. if (sc > SC_COMMON_MAX && sd->sc.data[sc])
  6841. status_change_end(&sd->bl, sc, INVALID_TIMER);
  6842. }
  6843. }
  6844. if( (sd->class_&MAPID_UPPERMASK) == MAPID_STAR_GLADIATOR && (b_class&MAPID_UPPERMASK) != MAPID_STAR_GLADIATOR) {
  6845. /* going off star glad lineage, reset feel to not store no-longer-used vars in the database */
  6846. pc_resetfeel(sd);
  6847. }
  6848. sd->status.class_ = job;
  6849. fame_flag = pc_famerank(sd->status.char_id,sd->class_&MAPID_UPPERMASK);
  6850. sd->class_ = (unsigned short)b_class;
  6851. sd->status.job_level=1;
  6852. sd->status.job_exp=0;
  6853. if (sd->status.base_level > pc_maxbaselv(sd)) {
  6854. sd->status.base_level = pc_maxbaselv(sd);
  6855. sd->status.base_exp=0;
  6856. pc_resetstate(sd);
  6857. clif_updatestatus(sd,SP_STATUSPOINT);
  6858. clif_updatestatus(sd,SP_BASELEVEL);
  6859. clif_updatestatus(sd,SP_BASEEXP);
  6860. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6861. }
  6862. clif_updatestatus(sd,SP_JOBLEVEL);
  6863. clif_updatestatus(sd,SP_JOBEXP);
  6864. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6865. for(i=0;i<EQI_MAX;i++) {
  6866. if(sd->equip_index[i] >= 0)
  6867. if(!pc_isequip(sd,sd->equip_index[i]))
  6868. pc_unequipitem(sd,sd->equip_index[i],2); // unequip invalid item for class
  6869. }
  6870. //Change look, if disguised, you need to undisguise
  6871. //to correctly calculate new job sprite without
  6872. if (sd->disguise)
  6873. pc_disguise(sd, 0);
  6874. status_set_viewdata(&sd->bl, job);
  6875. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_); // move sprite update to prevent client crashes with incompatible equipment [Valaris]
  6876. if(sd->vd.cloth_color)
  6877. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  6878. //Update skill tree.
  6879. pc_calc_skilltree(sd);
  6880. clif_skillinfoblock(sd);
  6881. if (sd->ed)
  6882. elemental_delete(sd->ed, 0);
  6883. if (sd->state.vending)
  6884. vending_closevending(sd);
  6885. map_foreachinmap(jobchange_killclone, sd->bl.m, BL_MOB, sd->bl.id);
  6886. //Remove peco/cart/falcon
  6887. i = sd->sc.option;
  6888. if( i&OPTION_RIDING && !pc_checkskill(sd, KN_RIDING) )
  6889. i&=~OPTION_RIDING;
  6890. if( i&OPTION_FALCON && !pc_checkskill(sd, HT_FALCON) )
  6891. i&=~OPTION_FALCON;
  6892. if( i&OPTION_DRAGON && !pc_checkskill(sd,RK_DRAGONTRAINING) )
  6893. i&=~OPTION_DRAGON;
  6894. if( i&OPTION_WUGRIDER && !pc_checkskill(sd,RA_WUGMASTERY) )
  6895. i&=~OPTION_WUGRIDER;
  6896. if( i&OPTION_WUG && !pc_checkskill(sd,RA_WUGMASTERY) )
  6897. i&=~OPTION_WUG;
  6898. if( i&OPTION_MADOGEAR ) //You do not need a skill for this.
  6899. i&=~OPTION_MADOGEAR;
  6900. #ifndef NEW_CARTS
  6901. if( i&OPTION_CART && !pc_checkskill(sd, MC_PUSHCART) )
  6902. i&=~OPTION_CART;
  6903. #else
  6904. if( sd->sc.data[SC_PUSH_CART] && !pc_checkskill(sd, MC_PUSHCART) )
  6905. pc_setcart(sd, 0);
  6906. #endif
  6907. if(i != sd->sc.option)
  6908. pc_setoption(sd, i);
  6909. if(merc_is_hom_active(sd->hd) && !pc_checkskill(sd, AM_CALLHOMUN))
  6910. merc_hom_vaporize(sd, HOM_ST_ACTIVE);
  6911. if(sd->status.manner < 0)
  6912. clif_changestatus(sd,SP_MANNER,sd->status.manner);
  6913. status_calc_pc(sd,0);
  6914. pc_checkallowskill(sd);
  6915. pc_equiplookall(sd);
  6916. //if you were previously famous, not anymore.
  6917. if (fame_flag) {
  6918. chrif_save(sd,0);
  6919. chrif_buildfamelist();
  6920. } else if (sd->status.fame > 0) {
  6921. //It may be that now they are famous?
  6922. switch (sd->class_&MAPID_UPPERMASK) {
  6923. case MAPID_BLACKSMITH:
  6924. case MAPID_ALCHEMIST:
  6925. case MAPID_TAEKWON:
  6926. chrif_save(sd,0);
  6927. chrif_buildfamelist();
  6928. break;
  6929. }
  6930. }
  6931. return 0;
  6932. }
  6933. /*==========================================
  6934. * Tell client player sd has change equipement
  6935. *------------------------------------------*/
  6936. void pc_equiplookall(struct map_session_data *sd)
  6937. {
  6938. nullpo_retv(sd);
  6939. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6940. clif_changelook(&sd->bl,LOOK_SHOES,0);
  6941. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  6942. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  6943. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  6944. clif_changelook(&sd->bl,LOOK_ROBE, sd->status.robe);
  6945. }
  6946. /*==========================================
  6947. * Tell client player sd has change look (hair,equip...)
  6948. *------------------------------------------*/
  6949. void pc_changelook(struct map_session_data *sd,int type,int val)
  6950. {
  6951. nullpo_retv(sd);
  6952. switch(type){
  6953. case LOOK_HAIR: //Use the battle_config limits! [Skotlex]
  6954. val = cap_value(val, MIN_HAIR_STYLE, MAX_HAIR_STYLE);
  6955. if (sd->status.hair != val)
  6956. {
  6957. sd->status.hair=val;
  6958. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  6959. intif_guild_change_memberinfo(sd->status.guild_id,sd->status.account_id,sd->status.char_id,
  6960. GMI_HAIR,&sd->status.hair,sizeof(sd->status.hair));
  6961. }
  6962. break;
  6963. case LOOK_WEAPON:
  6964. sd->status.weapon=val;
  6965. break;
  6966. case LOOK_HEAD_BOTTOM:
  6967. sd->status.head_bottom=val;
  6968. break;
  6969. case LOOK_HEAD_TOP:
  6970. sd->status.head_top=val;
  6971. break;
  6972. case LOOK_HEAD_MID:
  6973. sd->status.head_mid=val;
  6974. break;
  6975. case LOOK_HAIR_COLOR: //Use the battle_config limits! [Skotlex]
  6976. val = cap_value(val, MIN_HAIR_COLOR, MAX_HAIR_COLOR);
  6977. if (sd->status.hair_color != val) {
  6978. sd->status.hair_color=val;
  6979. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  6980. intif_guild_change_memberinfo(sd->status.guild_id,sd->status.account_id,sd->status.char_id,
  6981. GMI_HAIR_COLOR,&sd->status.hair_color,sizeof(sd->status.hair_color));
  6982. }
  6983. break;
  6984. case LOOK_CLOTHES_COLOR: //Use the battle_config limits! [Skotlex]
  6985. val = cap_value(val, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  6986. sd->status.clothes_color=val;
  6987. break;
  6988. case LOOK_SHIELD:
  6989. sd->status.shield=val;
  6990. break;
  6991. case LOOK_SHOES:
  6992. break;
  6993. case LOOK_ROBE:
  6994. sd->status.robe = val;
  6995. break;
  6996. }
  6997. clif_changelook(&sd->bl,type,val);
  6998. }
  6999. /*==========================================
  7000. * Give an option (type) to player (sd) and display it to client
  7001. *------------------------------------------*/
  7002. void pc_setoption(struct map_session_data *sd,int type)
  7003. {
  7004. int p_type, new_look=0;
  7005. nullpo_retv(sd);
  7006. p_type = sd->sc.option;
  7007. //Option has to be changed client-side before the class sprite or it won't always work (eg: Wedding sprite) [Skotlex]
  7008. sd->sc.option=type;
  7009. clif_changeoption(&sd->bl);
  7010. if( (type&OPTION_RIDING && !(p_type&OPTION_RIDING)) || (type&OPTION_DRAGON && !(p_type&OPTION_DRAGON) && pc_checkskill(sd,RK_DRAGONTRAINING) > 0) )
  7011. { // Mounting
  7012. clif_status_load(&sd->bl,SI_RIDING,1);
  7013. status_calc_pc(sd,0);
  7014. }
  7015. else if( (!(type&OPTION_RIDING) && p_type&OPTION_RIDING) || (!(type&OPTION_DRAGON) && p_type&OPTION_DRAGON && pc_checkskill(sd,RK_DRAGONTRAINING) > 0) )
  7016. { // Dismount
  7017. clif_status_load(&sd->bl,SI_RIDING,0);
  7018. status_calc_pc(sd,0);
  7019. }
  7020. #ifndef NEW_CARTS
  7021. if( type&OPTION_CART && !( p_type&OPTION_CART ) ) { //Cart On
  7022. clif_cartlist(sd);
  7023. clif_updatestatus(sd, SP_CARTINFO);
  7024. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7025. status_calc_pc(sd,0); //Apply speed penalty.
  7026. } else if( !( type&OPTION_CART ) && p_type&OPTION_CART ){ //Cart Off
  7027. clif_clearcart(sd->fd);
  7028. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7029. status_calc_pc(sd,0); //Remove speed penalty.
  7030. }
  7031. #endif
  7032. if (type&OPTION_FALCON && !(p_type&OPTION_FALCON)) //Falcon ON
  7033. clif_status_load(&sd->bl,SI_FALCON,1);
  7034. else if (!(type&OPTION_FALCON) && p_type&OPTION_FALCON) //Falcon OFF
  7035. clif_status_load(&sd->bl,SI_FALCON,0);
  7036. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER ) {
  7037. if( type&OPTION_WUGRIDER && !(p_type&OPTION_WUGRIDER) ) { // Mounting
  7038. clif_status_load(&sd->bl,SI_WUGRIDER,1);
  7039. status_calc_pc(sd,0);
  7040. } else if( !(type&OPTION_WUGRIDER) && p_type&OPTION_WUGRIDER ) { // Dismount
  7041. clif_status_load(&sd->bl,SI_WUGRIDER,0);
  7042. status_calc_pc(sd,0);
  7043. }
  7044. }
  7045. if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  7046. if( type&OPTION_MADOGEAR && !(p_type&OPTION_MADOGEAR) ) {
  7047. status_calc_pc(sd, 0);
  7048. status_change_end(&sd->bl,SC_MAXIMIZEPOWER,INVALID_TIMER);
  7049. status_change_end(&sd->bl,SC_OVERTHRUST,INVALID_TIMER);
  7050. status_change_end(&sd->bl,SC_WEAPONPERFECTION,INVALID_TIMER);
  7051. status_change_end(&sd->bl,SC_ADRENALINE,INVALID_TIMER);
  7052. status_change_end(&sd->bl,SC_CARTBOOST,INVALID_TIMER);
  7053. status_change_end(&sd->bl,SC_MELTDOWN,INVALID_TIMER);
  7054. status_change_end(&sd->bl,SC_MAXOVERTHRUST,INVALID_TIMER);
  7055. } else if( !(type&OPTION_MADOGEAR) && p_type&OPTION_MADOGEAR ) {
  7056. status_calc_pc(sd, 0);
  7057. status_change_end(&sd->bl,SC_SHAPESHIFT,INVALID_TIMER);
  7058. status_change_end(&sd->bl,SC_HOVERING,INVALID_TIMER);
  7059. status_change_end(&sd->bl,SC_ACCELERATION,INVALID_TIMER);
  7060. status_change_end(&sd->bl,SC_OVERHEAT_LIMITPOINT,INVALID_TIMER);
  7061. status_change_end(&sd->bl,SC_OVERHEAT,INVALID_TIMER);
  7062. }
  7063. }
  7064. if (type&OPTION_FLYING && !(p_type&OPTION_FLYING))
  7065. new_look = JOB_STAR_GLADIATOR2;
  7066. else if (!(type&OPTION_FLYING) && p_type&OPTION_FLYING)
  7067. new_look = -1;
  7068. if (type&OPTION_WEDDING && !(p_type&OPTION_WEDDING))
  7069. new_look = JOB_WEDDING;
  7070. else if (!(type&OPTION_WEDDING) && p_type&OPTION_WEDDING)
  7071. new_look = -1;
  7072. if (type&OPTION_XMAS && !(p_type&OPTION_XMAS))
  7073. new_look = JOB_XMAS;
  7074. else if (!(type&OPTION_XMAS) && p_type&OPTION_XMAS)
  7075. new_look = -1;
  7076. if (type&OPTION_SUMMER && !(p_type&OPTION_SUMMER))
  7077. new_look = JOB_SUMMER;
  7078. else if (!(type&OPTION_SUMMER) && p_type&OPTION_SUMMER)
  7079. new_look = -1;
  7080. if (type&OPTION_HANBOK && !(p_type&OPTION_HANBOK))
  7081. new_look = JOB_HANBOK;
  7082. else if (!(type&OPTION_HANBOK) && p_type&OPTION_HANBOK)
  7083. new_look = -1;
  7084. if (type&OPTION_OKTOBERFEST && !(p_type&OPTION_OKTOBERFEST))
  7085. new_look = JOB_OKTOBERFEST;
  7086. else if (!(type&OPTION_OKTOBERFEST) && p_type&OPTION_OKTOBERFEST)
  7087. new_look = -1;
  7088. if (sd->disguise || !new_look)
  7089. return; //Disguises break sprite changes
  7090. if (new_look < 0) { //Restore normal look.
  7091. status_set_viewdata(&sd->bl, sd->status.class_);
  7092. new_look = sd->vd.class_;
  7093. }
  7094. pc_stop_attack(sd); //Stop attacking on new view change (to prevent wedding/santa attacks.
  7095. clif_changelook(&sd->bl,LOOK_BASE,new_look);
  7096. if (sd->vd.cloth_color)
  7097. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7098. clif_skillinfoblock(sd); // Skill list needs to be updated after base change.
  7099. }
  7100. /*==========================================
  7101. * Give player a cart
  7102. *------------------------------------------*/
  7103. bool pc_setcart(struct map_session_data *sd,int type) {
  7104. #ifndef NEW_CARTS
  7105. int cart[6] = {0x0000,OPTION_CART1,OPTION_CART2,OPTION_CART3,OPTION_CART4,OPTION_CART5};
  7106. int option;
  7107. #endif
  7108. nullpo_retr(false,sd);
  7109. if( type < 0 || type > MAX_CARTS )
  7110. return false;// Never trust the values sent by the client! [Skotlex]
  7111. if( pc_checkskill(sd,MC_PUSHCART) <= 0 && type != 0 )
  7112. return false;// Push cart is required
  7113. #ifdef NEW_CARTS
  7114. switch( type ) {
  7115. case 0:
  7116. if( !sd->sc.data[SC_PUSH_CART] )
  7117. return 0;
  7118. status_change_end(&sd->bl,SC_PUSH_CART,INVALID_TIMER);
  7119. clif_clearcart(sd->fd);
  7120. break;
  7121. default:/* everything else is an allowed ID so we can move on */
  7122. if( !sd->sc.data[SC_PUSH_CART] ) /* first time, so fill cart data */
  7123. clif_cartlist(sd);
  7124. clif_updatestatus(sd, SP_CARTINFO);
  7125. sc_start(&sd->bl,&sd->bl, SC_PUSH_CART, 100, type, 0);
  7126. clif_status_load_notick(&sd->bl, SI_ON_PUSH_CART, 2 , type, 0, 0);
  7127. if( sd->sc.data[SC_PUSH_CART] )/* forcefully update */
  7128. sd->sc.data[SC_PUSH_CART]->val1 = type;
  7129. break;
  7130. }
  7131. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7132. status_calc_pc(sd,0); //Recalc speed penalty.
  7133. #else
  7134. // Update option
  7135. option = sd->sc.option;
  7136. option &= ~OPTION_CART;// clear cart bits
  7137. option |= cart[type]; // set cart
  7138. pc_setoption(sd, option);
  7139. #endif
  7140. return true;
  7141. }
  7142. /*==========================================
  7143. * Give player a falcon
  7144. *------------------------------------------*/
  7145. void pc_setfalcon(TBL_PC* sd, int flag)
  7146. {
  7147. if( flag ){
  7148. if( pc_checkskill(sd,HT_FALCON)>0 ) // add falcon if he have the skill
  7149. pc_setoption(sd,sd->sc.option|OPTION_FALCON);
  7150. } else if( pc_isfalcon(sd) ){
  7151. pc_setoption(sd,sd->sc.option&~OPTION_FALCON); // remove falcon
  7152. }
  7153. }
  7154. /*==========================================
  7155. * Set player riding
  7156. *------------------------------------------*/
  7157. void pc_setriding(TBL_PC* sd, int flag)
  7158. {
  7159. if( sd->sc.data[SC_ALL_RIDING] )
  7160. return;
  7161. if( flag ){
  7162. if( pc_checkskill(sd,KN_RIDING) > 0 ) // add peco
  7163. pc_setoption(sd, sd->sc.option|OPTION_RIDING);
  7164. } else if( pc_isriding(sd) ){
  7165. pc_setoption(sd, sd->sc.option&~OPTION_RIDING);
  7166. }
  7167. }
  7168. /*==========================================
  7169. * Give player a mado
  7170. *------------------------------------------*/
  7171. void pc_setmadogear(TBL_PC* sd, int flag)
  7172. {
  7173. if( flag ){
  7174. if( pc_checkskill(sd,NC_MADOLICENCE) > 0 )
  7175. pc_setoption(sd, sd->sc.option|OPTION_MADOGEAR);
  7176. } else if( pc_ismadogear(sd) ){
  7177. pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR);
  7178. }
  7179. }
  7180. /*==========================================
  7181. * Check if player can drop an item
  7182. *------------------------------------------*/
  7183. bool pc_candrop(struct map_session_data *sd, struct item *item)
  7184. {
  7185. if( item && (item->expire_time || (item->bound && !pc_can_give_bounded_items(sd))) )
  7186. return false;
  7187. if( !pc_can_give_items(sd) || sd->sc.cant.drop) //check if this GM level can drop items
  7188. return false;
  7189. return (itemdb_isdropable(item, pc_get_group_level(sd)));
  7190. }
  7191. /*==========================================
  7192. * Read ram register for player sd
  7193. * get val (int) from reg for player sd
  7194. *------------------------------------------*/
  7195. int pc_readreg(struct map_session_data* sd, int reg)
  7196. {
  7197. int i;
  7198. nullpo_ret(sd);
  7199. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg );
  7200. return ( i < sd->reg_num ) ? sd->reg[i].data : 0;
  7201. }
  7202. /*==========================================
  7203. * Set ram register for player sd
  7204. * memo val(int) at reg for player sd
  7205. *------------------------------------------*/
  7206. bool pc_setreg(struct map_session_data* sd, int reg, int val)
  7207. {
  7208. int i;
  7209. nullpo_retr(false,sd);
  7210. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg );
  7211. if( i < sd->reg_num )
  7212. {// overwrite existing entry
  7213. sd->reg[i].data = val;
  7214. return true;
  7215. }
  7216. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].data == 0 );
  7217. if( i == sd->reg_num )
  7218. {// nothing free, increase size
  7219. sd->reg_num++;
  7220. RECREATE(sd->reg, struct script_reg, sd->reg_num);
  7221. }
  7222. sd->reg[i].index = reg;
  7223. sd->reg[i].data = val;
  7224. return true;
  7225. }
  7226. /*==========================================
  7227. * Read ram register for player sd
  7228. * get val (str) from reg for player sd
  7229. *------------------------------------------*/
  7230. char* pc_readregstr(struct map_session_data* sd, int reg)
  7231. {
  7232. int i;
  7233. nullpo_ret(sd);
  7234. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg );
  7235. return ( i < sd->regstr_num ) ? sd->regstr[i].data : NULL;
  7236. }
  7237. /*==========================================
  7238. * Set ram register for player sd
  7239. * memo val(str) at reg for player sd
  7240. *------------------------------------------*/
  7241. bool pc_setregstr(struct map_session_data* sd, int reg, const char* str)
  7242. {
  7243. int i;
  7244. nullpo_retr(false,sd);
  7245. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg );
  7246. if( i < sd->regstr_num )
  7247. {// found entry, update
  7248. if( str == NULL || *str == '\0' )
  7249. {// empty string
  7250. if( sd->regstr[i].data != NULL )
  7251. aFree(sd->regstr[i].data);
  7252. sd->regstr[i].data = NULL;
  7253. }
  7254. else if( sd->regstr[i].data )
  7255. {// recreate
  7256. size_t len = strlen(str)+1;
  7257. RECREATE(sd->regstr[i].data, char, len);
  7258. memcpy(sd->regstr[i].data, str, len*sizeof(char));
  7259. }
  7260. else
  7261. {// create
  7262. sd->regstr[i].data = aStrdup(str);
  7263. }
  7264. return true;
  7265. }
  7266. if( str == NULL || *str == '\0' )
  7267. return true;// nothing to add, empty string
  7268. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].data == NULL );
  7269. if( i == sd->regstr_num )
  7270. {// nothing free, increase size
  7271. sd->regstr_num++;
  7272. RECREATE(sd->regstr, struct script_regstr, sd->regstr_num);
  7273. }
  7274. sd->regstr[i].index = reg;
  7275. sd->regstr[i].data = aStrdup(str);
  7276. return true;
  7277. }
  7278. int pc_readregistry(struct map_session_data *sd,const char *reg,int type)
  7279. {
  7280. struct global_reg *sd_reg;
  7281. int i,max;
  7282. nullpo_ret(sd);
  7283. switch (type) {
  7284. case 3: //Char reg
  7285. sd_reg = sd->save_reg.global;
  7286. max = sd->save_reg.global_num;
  7287. break;
  7288. case 2: //Account reg
  7289. sd_reg = sd->save_reg.account;
  7290. max = sd->save_reg.account_num;
  7291. break;
  7292. case 1: //Account2 reg
  7293. sd_reg = sd->save_reg.account2;
  7294. max = sd->save_reg.account2_num;
  7295. break;
  7296. default:
  7297. return 0;
  7298. }
  7299. if (max == -1) {
  7300. ShowError("pc_readregistry: Trying to read reg value %s (type %d) before it's been loaded!\n", reg, type);
  7301. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  7302. intif_request_registry(sd,type==3?4:type);
  7303. return 0;
  7304. }
  7305. ARR_FIND( 0, max, i, strcmp(sd_reg[i].str,reg) == 0 );
  7306. return ( i < max ) ? atoi(sd_reg[i].value) : 0;
  7307. }
  7308. char* pc_readregistry_str(struct map_session_data *sd,const char *reg,int type)
  7309. {
  7310. struct global_reg *sd_reg;
  7311. int i,max;
  7312. nullpo_ret(sd);
  7313. switch (type) {
  7314. case 3: //Char reg
  7315. sd_reg = sd->save_reg.global;
  7316. max = sd->save_reg.global_num;
  7317. break;
  7318. case 2: //Account reg
  7319. sd_reg = sd->save_reg.account;
  7320. max = sd->save_reg.account_num;
  7321. break;
  7322. case 1: //Account2 reg
  7323. sd_reg = sd->save_reg.account2;
  7324. max = sd->save_reg.account2_num;
  7325. break;
  7326. default:
  7327. return NULL;
  7328. }
  7329. if (max == -1) {
  7330. ShowError("pc_readregistry: Trying to read reg value %s (type %d) before it's been loaded!\n", reg, type);
  7331. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  7332. intif_request_registry(sd,type==3?4:type);
  7333. return NULL;
  7334. }
  7335. ARR_FIND( 0, max, i, strcmp(sd_reg[i].str,reg) == 0 );
  7336. return ( i < max ) ? sd_reg[i].value : NULL;
  7337. }
  7338. bool pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type)
  7339. {
  7340. struct global_reg *sd_reg;
  7341. int i,*max, regmax;
  7342. nullpo_retr(false,sd);
  7343. switch( type )
  7344. {
  7345. case 3: //Char reg
  7346. if( !strcmp(reg,"PC_DIE_COUNTER") && sd->die_counter != val )
  7347. {
  7348. i = (!sd->die_counter && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE);
  7349. sd->die_counter = val;
  7350. if( i )
  7351. status_calc_pc(sd,0); // Lost the bonus.
  7352. }
  7353. else if( !strcmp(reg,"COOK_MASTERY") && sd->cook_mastery != val )
  7354. {
  7355. val = cap_value(val, 0, 1999);
  7356. sd->cook_mastery = val;
  7357. }
  7358. sd_reg = sd->save_reg.global;
  7359. max = &sd->save_reg.global_num;
  7360. regmax = GLOBAL_REG_NUM;
  7361. break;
  7362. case 2: //Account reg
  7363. if( !strcmp(reg,"#CASHPOINTS") && sd->cashPoints != val )
  7364. {
  7365. val = cap_value(val, 0, MAX_ZENY);
  7366. sd->cashPoints = val;
  7367. }
  7368. else if( !strcmp(reg,"#KAFRAPOINTS") && sd->kafraPoints != val )
  7369. {
  7370. val = cap_value(val, 0, MAX_ZENY);
  7371. sd->kafraPoints = val;
  7372. }
  7373. sd_reg = sd->save_reg.account;
  7374. max = &sd->save_reg.account_num;
  7375. regmax = ACCOUNT_REG_NUM;
  7376. break;
  7377. case 1: //Account2 reg
  7378. sd_reg = sd->save_reg.account2;
  7379. max = &sd->save_reg.account2_num;
  7380. regmax = ACCOUNT_REG2_NUM;
  7381. break;
  7382. default:
  7383. return false;
  7384. }
  7385. if (*max == -1) {
  7386. ShowError("pc_setregistry : refusing to set %s (type %d) until vars are received.\n", reg, type);
  7387. return true;
  7388. }
  7389. // delete reg
  7390. if (val == 0) {
  7391. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  7392. if( i < *max )
  7393. {
  7394. if (i != *max - 1)
  7395. memcpy(&sd_reg[i], &sd_reg[*max - 1], sizeof(struct global_reg));
  7396. memset(&sd_reg[*max - 1], 0, sizeof(struct global_reg));
  7397. (*max)--;
  7398. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  7399. }
  7400. return true;
  7401. }
  7402. // change value if found
  7403. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  7404. if( i < *max )
  7405. {
  7406. safesnprintf(sd_reg[i].value, sizeof(sd_reg[i].value), "%d", val);
  7407. sd->state.reg_dirty |= 1<<(type-1);
  7408. return true;
  7409. }
  7410. // add value if not found
  7411. if (i < regmax) {
  7412. memset(&sd_reg[i], 0, sizeof(struct global_reg));
  7413. safestrncpy(sd_reg[i].str, reg, sizeof(sd_reg[i].str));
  7414. safesnprintf(sd_reg[i].value, sizeof(sd_reg[i].value), "%d", val);
  7415. (*max)++;
  7416. sd->state.reg_dirty |= 1<<(type-1);
  7417. return true;
  7418. }
  7419. ShowError("pc_setregistry : couldn't set %s, limit of registries reached (%d)\n", reg, regmax);
  7420. return false;
  7421. }
  7422. bool pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *val,int type)
  7423. {
  7424. struct global_reg *sd_reg;
  7425. int i,*max, regmax;
  7426. nullpo_retr(false,sd);
  7427. if (reg[strlen(reg)-1] != '$') {
  7428. ShowError("pc_setregistry_str : reg %s must be string (end in '$') to use this!\n", reg);
  7429. return false;
  7430. }
  7431. switch (type) {
  7432. case 3: //Char reg
  7433. sd_reg = sd->save_reg.global;
  7434. max = &sd->save_reg.global_num;
  7435. regmax = GLOBAL_REG_NUM;
  7436. break;
  7437. case 2: //Account reg
  7438. sd_reg = sd->save_reg.account;
  7439. max = &sd->save_reg.account_num;
  7440. regmax = ACCOUNT_REG_NUM;
  7441. break;
  7442. case 1: //Account2 reg
  7443. sd_reg = sd->save_reg.account2;
  7444. max = &sd->save_reg.account2_num;
  7445. regmax = ACCOUNT_REG2_NUM;
  7446. break;
  7447. default:
  7448. return false;
  7449. }
  7450. if (*max == -1) {
  7451. ShowError("pc_setregistry_str : refusing to set %s (type %d) until vars are received.\n", reg, type);
  7452. return false;
  7453. }
  7454. // delete reg
  7455. if (!val || strcmp(val,"")==0)
  7456. {
  7457. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  7458. if( i < *max )
  7459. {
  7460. if (i != *max - 1)
  7461. memcpy(&sd_reg[i], &sd_reg[*max - 1], sizeof(struct global_reg));
  7462. memset(&sd_reg[*max - 1], 0, sizeof(struct global_reg));
  7463. (*max)--;
  7464. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  7465. if (type!=3) intif_saveregistry(sd,type);
  7466. }
  7467. return true;
  7468. }
  7469. // change value if found
  7470. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  7471. if( i < *max )
  7472. {
  7473. safestrncpy(sd_reg[i].value, val, sizeof(sd_reg[i].value));
  7474. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  7475. if (type!=3) intif_saveregistry(sd,type);
  7476. return true;
  7477. }
  7478. // add value if not found
  7479. if (i < regmax) {
  7480. memset(&sd_reg[i], 0, sizeof(struct global_reg));
  7481. safestrncpy(sd_reg[i].str, reg, sizeof(sd_reg[i].str));
  7482. safestrncpy(sd_reg[i].value, val, sizeof(sd_reg[i].value));
  7483. (*max)++;
  7484. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  7485. if (type!=3) intif_saveregistry(sd,type);
  7486. return true;
  7487. }
  7488. ShowError("pc_setregistry : couldn't set %s, limit of registries reached (%d)\n", reg, regmax);
  7489. return false;
  7490. }
  7491. /*==========================================
  7492. * Exec eventtimer for player sd (retrieved from map_session (id))
  7493. *------------------------------------------*/
  7494. static int pc_eventtimer(int tid, unsigned int tick, int id, intptr_t data)
  7495. {
  7496. struct map_session_data *sd=map_id2sd(id);
  7497. char *p = (char *)data;
  7498. int i;
  7499. if(sd==NULL)
  7500. return 0;
  7501. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == tid );
  7502. if( i < MAX_EVENTTIMER )
  7503. {
  7504. sd->eventtimer[i] = INVALID_TIMER;
  7505. sd->eventcount--;
  7506. npc_event(sd,p,0);
  7507. }
  7508. else
  7509. ShowError("pc_eventtimer: no such event timer\n");
  7510. if (p) aFree(p);
  7511. return 0;
  7512. }
  7513. /*==========================================
  7514. * Add eventtimer for player sd ?
  7515. *------------------------------------------*/
  7516. bool pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
  7517. {
  7518. int i;
  7519. nullpo_retr(false,sd);
  7520. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == INVALID_TIMER );
  7521. if( i == MAX_EVENTTIMER )
  7522. return false;
  7523. sd->eventtimer[i] = add_timer(gettick()+tick, pc_eventtimer, sd->bl.id, (intptr_t)aStrdup(name));
  7524. sd->eventcount++;
  7525. return true;
  7526. }
  7527. /*==========================================
  7528. * Del eventtimer for player sd ?
  7529. *------------------------------------------*/
  7530. bool pc_deleventtimer(struct map_session_data *sd,const char *name)
  7531. {
  7532. char* p = NULL;
  7533. int i;
  7534. nullpo_retr(false,sd);
  7535. if (sd->eventcount == 0)
  7536. return false;
  7537. // find the named event timer
  7538. ARR_FIND( 0, MAX_EVENTTIMER, i,
  7539. sd->eventtimer[i] != INVALID_TIMER &&
  7540. (p = (char *)(get_timer(sd->eventtimer[i])->data)) != NULL &&
  7541. strcmp(p, name) == 0
  7542. );
  7543. if( i == MAX_EVENTTIMER )
  7544. return false; // not found
  7545. delete_timer(sd->eventtimer[i],pc_eventtimer);
  7546. sd->eventtimer[i] = INVALID_TIMER;
  7547. if(sd->eventcount > 0)
  7548. sd->eventcount--;
  7549. aFree(p);
  7550. return true;
  7551. }
  7552. /*==========================================
  7553. * Update eventtimer count for player sd
  7554. *------------------------------------------*/
  7555. void pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick)
  7556. {
  7557. int i;
  7558. nullpo_retv(sd);
  7559. for(i=0;i<MAX_EVENTTIMER;i++)
  7560. if( sd->eventtimer[i] != INVALID_TIMER && strcmp(
  7561. (char *)(get_timer(sd->eventtimer[i])->data), name)==0 ){
  7562. addtick_timer(sd->eventtimer[i],tick);
  7563. break;
  7564. }
  7565. }
  7566. /*==========================================
  7567. * Remove all eventtimer for player sd
  7568. *------------------------------------------*/
  7569. void pc_cleareventtimer(struct map_session_data *sd)
  7570. {
  7571. int i;
  7572. nullpo_retv(sd);
  7573. if (sd->eventcount == 0)
  7574. return;
  7575. for(i=0;i<MAX_EVENTTIMER;i++){
  7576. if( sd->eventtimer[i] != INVALID_TIMER ){
  7577. char *p = (char *)(get_timer(sd->eventtimer[i])->data);
  7578. delete_timer(sd->eventtimer[i],pc_eventtimer);
  7579. sd->eventtimer[i] = INVALID_TIMER;
  7580. if(sd->eventcount > 0) //avoid looping to max val
  7581. sd->eventcount--;
  7582. if (p) aFree(p);
  7583. }
  7584. }
  7585. }
  7586. /**
  7587. * Called when an item with combo is worn
  7588. * @param *sd
  7589. * @param *data struct item_data
  7590. * @return success numbers of succeed combo
  7591. */
  7592. static int pc_checkcombo(struct map_session_data *sd, struct item_data *data) {
  7593. uint16 i;
  7594. int success = 0;
  7595. for( i = 0; i < data->combos_count; i++ ) {
  7596. int16 *combo_idx = NULL, idx, j;
  7597. /* ensure this isn't a duplicate combo */
  7598. if( sd->combos.bonus != NULL ) {
  7599. int x;
  7600. ARR_FIND( 0, sd->combos.count, x, sd->combos.id[x] == data->combos[i]->id );
  7601. /* found a match, skip this combo */
  7602. if( x < sd->combos.count )
  7603. continue;
  7604. }
  7605. CREATE(combo_idx,int16,data->combos[i]->count);
  7606. memset(combo_idx,-1,data->combos[i]->count * sizeof(int16));
  7607. for( j = 0; j < data->combos[i]->count; j++ ) {
  7608. uint16 id = data->combos[i]->nameid[j], k;
  7609. bool found = false;
  7610. for( k = 0; k < EQI_MAX; k++ ) {
  7611. bool do_continue = false; //used to continue that specific loop with some check that also use some loop
  7612. int16 index;
  7613. index = sd->equip_index[k];
  7614. if( index < 0 ) continue;
  7615. if( k == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue;
  7616. if( k == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index ) continue;
  7617. if( k == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index) ) continue;
  7618. if(!sd->inventory_data[index])
  7619. continue;
  7620. if(j>0){
  7621. uint8 z;
  7622. for (z = 0; z < data->combos[i]->count; z++)
  7623. if(combo_idx[z] == index) //we already have that index recorded
  7624. do_continue=true;
  7625. if(do_continue)
  7626. continue;
  7627. }
  7628. if ( itemdb_type(id) != IT_CARD ) {
  7629. if ( sd->inventory_data[index]->nameid != id )
  7630. continue;
  7631. combo_idx[j] = index;
  7632. found = true;
  7633. break;
  7634. } else { //Cards
  7635. uint16 z;
  7636. if ( sd->inventory_data[index]->slot == 0 || itemdb_isspecial(sd->status.inventory[index].card[0]) )
  7637. continue;
  7638. for (z = 0; z < sd->inventory_data[index]->slot; z++) {
  7639. if (sd->status.inventory[index].card[z] != id)
  7640. continue;
  7641. combo_idx[j] = index;
  7642. found = true;
  7643. break;
  7644. }
  7645. }
  7646. }
  7647. if( !found )
  7648. break;/* we haven't found all the ids for this combo, so we can return */
  7649. }
  7650. aFree(combo_idx);
  7651. /* means we broke out of the count loop w/o finding all ids, we can move to the next combo */
  7652. if( j < data->combos[i]->count )
  7653. continue;
  7654. /* we got here, means all items in the combo are matching */
  7655. idx = sd->combos.count;
  7656. if( sd->combos.bonus == NULL ) {
  7657. CREATE(sd->combos.bonus, struct script_code *, 1);
  7658. CREATE(sd->combos.id, unsigned short, 1);
  7659. sd->combos.count = 1;
  7660. } else {
  7661. RECREATE(sd->combos.bonus, struct script_code *, ++sd->combos.count);
  7662. RECREATE(sd->combos.id, unsigned short, sd->combos.count);
  7663. }
  7664. /* we simply copy the pointer */
  7665. sd->combos.bonus[idx] = data->combos[i]->script;
  7666. /* save this combo's id */
  7667. sd->combos.id[idx] = data->combos[i]->id;
  7668. success++;
  7669. }
  7670. return success;
  7671. }
  7672. /**
  7673. * Called when an item with combo is removed
  7674. * @param *sd
  7675. * @param *data struct item_data
  7676. * @return retval numbers of removed combo
  7677. */
  7678. static int pc_removecombo(struct map_session_data *sd, struct item_data *data ) {
  7679. int i, retval = 0;
  7680. if( sd->combos.bonus == NULL )
  7681. return 0;/* nothing to do here, player has no combos */
  7682. for( i = 0; i < data->combos_count; i++ ) {
  7683. /* check if this combo exists in this user */
  7684. int x = 0, cursor = 0, j;
  7685. ARR_FIND( 0, sd->combos.count, x, sd->combos.id[x] == data->combos[i]->id );
  7686. /* no match, skip this combo */
  7687. if( !(x < sd->combos.count) )
  7688. continue;
  7689. sd->combos.bonus[x] = NULL;
  7690. sd->combos.id[x] = 0;
  7691. retval++;
  7692. /* check if combo requirements still fit */
  7693. if( pc_checkcombo( sd, data ) )
  7694. continue;
  7695. /* move next value to empty slot */
  7696. for( j = 0, cursor = 0; j < sd->combos.count; j++ ) {
  7697. if( sd->combos.bonus[j] == NULL )
  7698. continue;
  7699. if( cursor != j ) {
  7700. sd->combos.bonus[cursor] = sd->combos.bonus[j];
  7701. sd->combos.id[cursor] = sd->combos.id[j];
  7702. }
  7703. cursor++;
  7704. }
  7705. /* it's empty, we can clear all the memory */
  7706. if( (sd->combos.count = cursor) == 0 ) {
  7707. aFree(sd->combos.bonus);
  7708. aFree(sd->combos.id);
  7709. sd->combos.bonus = NULL;
  7710. sd->combos.id = NULL;
  7711. return retval; /* we also can return at this point for we have no more combos to check */
  7712. }
  7713. }
  7714. return retval;
  7715. }
  7716. /**
  7717. * Load combo data(s) of player
  7718. * @param *sd
  7719. * @return ret numbers of succeed combo
  7720. */
  7721. int pc_load_combo(struct map_session_data *sd) {
  7722. int i, ret = 0;
  7723. for( i = 0; i < EQI_MAX; i++ ) {
  7724. struct item_data *id = NULL;
  7725. int idx = sd->equip_index[i];
  7726. if( sd->equip_index[i] < 0 || !(id = sd->inventory_data[idx] ) )
  7727. continue;
  7728. if( id->combos_count )
  7729. ret += pc_checkcombo(sd,id);
  7730. if(!itemdb_isspecial(sd->status.inventory[idx].card[0])) {
  7731. struct item_data *data;
  7732. int j;
  7733. for( j = 0; j < id->slot; j++ ) {
  7734. if (!sd->status.inventory[idx].card[j])
  7735. continue;
  7736. if ( ( data = itemdb_exists(sd->status.inventory[idx].card[j]) ) != NULL ) {
  7737. if( data->combos_count )
  7738. ret += pc_checkcombo(sd,data);
  7739. }
  7740. }
  7741. }
  7742. }
  7743. return ret;
  7744. }
  7745. /*==========================================
  7746. * Equip item on player sd at req_pos from inventory index n
  7747. * return: false - fail; true - success
  7748. *------------------------------------------*/
  7749. bool pc_equipitem(struct map_session_data *sd,int n,int req_pos)
  7750. {
  7751. int i,pos,flag=0,iflag;
  7752. struct item_data *id;
  7753. nullpo_retr(false,sd);
  7754. if( n < 0 || n >= MAX_INVENTORY ) {
  7755. clif_equipitemack(sd,0,0,0);
  7756. return false;
  7757. }
  7758. if( sd->sc.count && (
  7759. (sd->sc.data[SC_PYROCLASTIC] && sd->inventory_data[n]->type == IT_WEAPON) ||
  7760. sd->sc.data[SC_BERSERK] ||
  7761. sd->sc.data[SC_SATURDAYNIGHTFEVER]) )
  7762. {
  7763. clif_equipitemack(sd,0,0,0);
  7764. return false;
  7765. }
  7766. if( DIFF_TICK(sd->canequip_tick,gettick()) > 0 ) {
  7767. clif_equipitemack(sd,n,0,0);
  7768. return false;
  7769. }
  7770. if (!(id = sd->inventory_data[n]))
  7771. return false;
  7772. pos = pc_equippoint(sd,n); //With a few exceptions, item should go in all specified slots.
  7773. if(battle_config.battle_log)
  7774. ShowInfo("equip %d(%d) %x:%x\n",sd->status.inventory[n].nameid,n,id?id->equip:0,req_pos);
  7775. if(!pc_isequip(sd,n) || !(pos&req_pos) || sd->status.inventory[n].equip != 0 || sd->status.inventory[n].attribute==1 ) { // [Valaris]
  7776. // FIXME: pc_isequip: equip level failure uses 2 instead of 0
  7777. clif_equipitemack(sd,n,0,0); // fail
  7778. return false;
  7779. }
  7780. if(pos == EQP_ACC) { //Accesories should only go in one of the two,
  7781. pos = req_pos&EQP_ACC;
  7782. if (pos == EQP_ACC) //User specified both slots..
  7783. pos = sd->equip_index[EQI_ACC_R] >= 0 ? EQP_ACC_L : EQP_ACC_R;
  7784. }
  7785. if(pos == EQP_SHADOW_ACC) { // Shadow System
  7786. pos = req_pos&EQP_SHADOW_ACC;
  7787. if (pos == EQP_SHADOW_ACC)
  7788. pos = sd->equip_index[EQI_SHADOW_ACC_L] >= 0 ? EQP_SHADOW_ACC_R : EQP_SHADOW_ACC_L;
  7789. }
  7790. if(pos == EQP_ARMS && id->equip == EQP_HAND_R) { //Dual wield capable weapon.
  7791. pos = (req_pos&EQP_ARMS);
  7792. if (pos == EQP_ARMS) //User specified both slots, pick one for them.
  7793. pos = sd->equip_index[EQI_HAND_R] >= 0 ? EQP_HAND_L : EQP_HAND_R;
  7794. }
  7795. if (pos&EQP_HAND_R && battle_config.use_weapon_skill_range&BL_PC) {
  7796. //Update skill-block range database when weapon range changes. [Skotlex]
  7797. i = sd->equip_index[EQI_HAND_R];
  7798. if (i < 0 || !sd->inventory_data[i]) //No data, or no weapon equipped
  7799. flag = 1;
  7800. else
  7801. flag = id->range != sd->inventory_data[i]->range;
  7802. }
  7803. for(i=0;i<EQI_MAX;i++) {
  7804. if(pos & equip_pos[i]) {
  7805. if(sd->equip_index[i] >= 0) //Slot taken, remove item from there.
  7806. pc_unequipitem(sd,sd->equip_index[i],2);
  7807. sd->equip_index[i] = n;
  7808. }
  7809. }
  7810. if(pos==EQP_AMMO) {
  7811. clif_arrowequip(sd,n);
  7812. clif_arrow_fail(sd,3);
  7813. }
  7814. else
  7815. clif_equipitemack(sd,n,pos,1);
  7816. sd->status.inventory[n].equip=pos;
  7817. if(pos & EQP_HAND_R) {
  7818. if(id)
  7819. sd->weapontype1 = id->look;
  7820. else
  7821. sd->weapontype1 = 0;
  7822. pc_calcweapontype(sd);
  7823. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7824. }
  7825. if(pos & EQP_HAND_L) {
  7826. if(id) {
  7827. if(id->type == IT_WEAPON) {
  7828. sd->status.shield = 0;
  7829. sd->weapontype2 = id->look;
  7830. }
  7831. else
  7832. if(id->type == IT_ARMOR) {
  7833. sd->status.shield = id->look;
  7834. sd->weapontype2 = 0;
  7835. }
  7836. }
  7837. else
  7838. sd->status.shield = sd->weapontype2 = 0;
  7839. pc_calcweapontype(sd);
  7840. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7841. }
  7842. //Added check to prevent sending the same look on multiple slots ->
  7843. //causes client to redraw item on top of itself. (suggested by Lupus)
  7844. if(pos & EQP_HEAD_LOW && pc_checkequip(sd,EQP_COSTUME_HEAD_LOW) == -1) {
  7845. if(id && !(pos&(EQP_HEAD_TOP|EQP_HEAD_MID)))
  7846. sd->status.head_bottom = id->look;
  7847. else
  7848. sd->status.head_bottom = 0;
  7849. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  7850. }
  7851. if(pos & EQP_HEAD_TOP && pc_checkequip(sd,EQP_COSTUME_HEAD_TOP) == -1) {
  7852. if(id)
  7853. sd->status.head_top = id->look;
  7854. else
  7855. sd->status.head_top = 0;
  7856. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  7857. }
  7858. if(pos & EQP_HEAD_MID && pc_checkequip(sd,EQP_COSTUME_HEAD_MID) == -1) {
  7859. if(id && !(pos&EQP_HEAD_TOP))
  7860. sd->status.head_mid = id->look;
  7861. else
  7862. sd->status.head_mid = 0;
  7863. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  7864. }
  7865. if(pos & EQP_COSTUME_HEAD_TOP) {
  7866. if(id){
  7867. sd->status.head_top = id->look;
  7868. } else
  7869. sd->status.head_top = 0;
  7870. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  7871. }
  7872. if(pos & EQP_COSTUME_HEAD_MID) {
  7873. if(id && !(pos&EQP_HEAD_TOP)){
  7874. sd->status.head_mid = id->look;
  7875. } else
  7876. sd->status.head_mid = 0;
  7877. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  7878. }
  7879. if(pos & EQP_COSTUME_HEAD_LOW) {
  7880. if(id && !(pos&(EQP_HEAD_TOP|EQP_HEAD_MID))){
  7881. sd->status.head_bottom = id->look;
  7882. } else
  7883. sd->status.head_bottom = 0;
  7884. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  7885. }
  7886. if(pos & EQP_SHOES)
  7887. clif_changelook(&sd->bl,LOOK_SHOES,0);
  7888. if(pos&EQP_GARMENT && pc_checkequip(sd,EQP_COSTUME_GARMENT) == -1) {
  7889. sd->status.robe = id ? id->look : 0;
  7890. clif_changelook(&sd->bl, LOOK_ROBE, sd->status.robe);
  7891. }
  7892. if(pos & EQP_COSTUME_GARMENT) {
  7893. sd->status.robe = id ? id->look : 0;
  7894. clif_changelook(&sd->bl,LOOK_ROBE,sd->status.robe);
  7895. }
  7896. pc_checkallowskill(sd); //Check if status changes should be halted.
  7897. iflag = sd->npc_item_flag;
  7898. /* check for combos (MUST be before status_calc_pc) */
  7899. if( id->combos_count )
  7900. pc_checkcombo(sd,id);
  7901. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  7902. ; //No cards
  7903. else {
  7904. for( i = 0; i < id->slot; i++ ) {
  7905. struct item_data *data;
  7906. if (!sd->status.inventory[n].card[i])
  7907. continue;
  7908. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  7909. if( data->combos_count )
  7910. pc_checkcombo(sd,data);
  7911. }
  7912. }
  7913. }
  7914. status_calc_pc(sd,0);
  7915. if (flag) //Update skill data
  7916. clif_skillinfoblock(sd);
  7917. //OnEquip script [Skotlex]
  7918. if (id) {
  7919. //only run the script if item isn't restricted
  7920. if (id->equip_script && (pc_has_permission(sd,PC_PERM_USE_ALL_EQUIPMENT) || !itemdb_isNoEquip(id,sd->bl.m)))
  7921. run_script(id->equip_script,0,sd->bl.id,fake_nd->bl.id);
  7922. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  7923. ; //No cards
  7924. else {
  7925. for( i = 0; i < id->slot; i++ ) {
  7926. struct item_data *data;
  7927. if (!sd->status.inventory[n].card[i])
  7928. continue;
  7929. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  7930. if (data->equip_script && (pc_has_permission(sd,PC_PERM_USE_ALL_EQUIPMENT) || !itemdb_isNoEquip(data,sd->bl.m)))
  7931. run_script(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
  7932. }
  7933. }
  7934. }
  7935. }
  7936. sd->npc_item_flag = iflag;
  7937. return true;
  7938. }
  7939. /*==========================================
  7940. * Called when attemting to unequip an item from player
  7941. * type:
  7942. * 0 - only unequip
  7943. * 1 - calculate status after unequipping
  7944. * 2 - force unequip
  7945. * return: false - fail; true - success
  7946. *------------------------------------------*/
  7947. bool pc_unequipitem(struct map_session_data *sd,int n,int flag) {
  7948. int i,iflag;
  7949. bool status_cacl = false;
  7950. nullpo_retr(false,sd);
  7951. if( n < 0 || n >= MAX_INVENTORY ) {
  7952. clif_unequipitemack(sd,0,0,0);
  7953. return false;
  7954. }
  7955. // status change that makes player cannot unequip equipment
  7956. if( !(flag&2) && sd->sc.count && (
  7957. sd->sc.data[SC_BERSERK] ||
  7958. sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  7959. sd->sc.data[SC__BLOODYLUST] ||
  7960. sd->sc.data[SC_KYOUGAKU] ||
  7961. (sd->sc.data[SC_PYROCLASTIC] && sd->inventory_data[n]->type == IT_WEAPON)) ) // can't switch weapon
  7962. {
  7963. clif_unequipitemack(sd,n,0,0);
  7964. return false;
  7965. }
  7966. if (&sd->sc) {
  7967. if (sd->sc.data[SC_HEAT_BARREL])
  7968. status_change_end(&sd->bl,SC_HEAT_BARREL,INVALID_TIMER);
  7969. if (sd->sc.data[SC_P_ALTER] && (sd->inventory_data[n]->type == IT_WEAPON || sd->inventory_data[n]->type == IT_AMMO))
  7970. status_change_end(&sd->bl,SC_P_ALTER,INVALID_TIMER);
  7971. }
  7972. if(battle_config.battle_log)
  7973. ShowInfo("unequip %d %x:%x\n",n,pc_equippoint(sd,n),sd->status.inventory[n].equip);
  7974. if(!sd->status.inventory[n].equip){ //Nothing to unequip
  7975. clif_unequipitemack(sd,n,0,0);
  7976. return false;
  7977. }
  7978. for(i=0;i<EQI_MAX;i++) {
  7979. if(sd->status.inventory[n].equip & equip_pos[i])
  7980. sd->equip_index[i] = -1;
  7981. }
  7982. if(sd->status.inventory[n].equip & EQP_HAND_R) {
  7983. sd->weapontype1 = 0;
  7984. sd->status.weapon = sd->weapontype2;
  7985. pc_calcweapontype(sd);
  7986. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7987. if( !battle_config.dancing_weaponswitch_fix )
  7988. status_change_end(&sd->bl, SC_DANCING, INVALID_TIMER); // Unequipping => stop dancing.
  7989. }
  7990. if(sd->status.inventory[n].equip & EQP_HAND_L) {
  7991. sd->status.shield = sd->weapontype2 = 0;
  7992. pc_calcweapontype(sd);
  7993. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7994. }
  7995. if(sd->status.inventory[n].equip & EQP_HEAD_LOW && pc_checkequip(sd,EQP_COSTUME_HEAD_LOW) == -1 ) {
  7996. sd->status.head_bottom = 0;
  7997. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  7998. }
  7999. if(sd->status.inventory[n].equip & EQP_HEAD_TOP && pc_checkequip(sd,EQP_COSTUME_HEAD_TOP) == -1 ) {
  8000. sd->status.head_top = 0;
  8001. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  8002. }
  8003. if(sd->status.inventory[n].equip & EQP_HEAD_MID && pc_checkequip(sd,EQP_COSTUME_HEAD_MID) == -1 ) {
  8004. sd->status.head_mid = 0;
  8005. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8006. }
  8007. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_TOP) {
  8008. sd->status.head_top = ( pc_checkequip(sd,EQP_HEAD_TOP) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_TOP)]->look : 0;
  8009. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  8010. }
  8011. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_MID) {
  8012. sd->status.head_mid = ( pc_checkequip(sd,EQP_HEAD_MID) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_MID)]->look : 0;
  8013. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8014. }
  8015. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_LOW) {
  8016. sd->status.head_bottom = ( pc_checkequip(sd,EQP_HEAD_LOW) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_LOW)]->look : 0;
  8017. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  8018. }
  8019. if(sd->status.inventory[n].equip & EQP_SHOES)
  8020. clif_changelook(&sd->bl,LOOK_SHOES,0);
  8021. if(sd->status.inventory[n].equip&EQP_GARMENT && pc_checkequip(sd,EQP_COSTUME_GARMENT) == -1) {
  8022. sd->status.robe = 0;
  8023. clif_changelook(&sd->bl, LOOK_ROBE, 0);
  8024. }
  8025. if(sd->status.inventory[n].equip & EQP_COSTUME_GARMENT) {
  8026. sd->status.robe = ( pc_checkequip(sd,EQP_GARMENT) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_GARMENT)]->look : 0;
  8027. clif_changelook(&sd->bl,LOOK_ROBE,sd->status.robe);
  8028. }
  8029. clif_unequipitemack(sd,n,sd->status.inventory[n].equip,1);
  8030. if((sd->status.inventory[n].equip & EQP_ARMS) &&
  8031. sd->weapontype1 == 0 && sd->weapontype2 == 0 && (!sd->sc.data[SC_SEVENWIND] || sd->sc.data[SC_ASPERSIO])) //Check for seven wind (but not level seven!)
  8032. skill_enchant_elemental_end(&sd->bl,-1);
  8033. if(sd->status.inventory[n].equip & EQP_ARMOR) {
  8034. // On Armor Change...
  8035. status_change_end(&sd->bl, SC_BENEDICTIO, INVALID_TIMER);
  8036. status_change_end(&sd->bl, SC_ARMOR_RESIST, INVALID_TIMER);
  8037. }
  8038. if( sd->state.autobonus&sd->status.inventory[n].equip )
  8039. sd->state.autobonus &= ~sd->status.inventory[n].equip; //Check for activated autobonus [Inkfish]
  8040. sd->status.inventory[n].equip=0;
  8041. iflag = sd->npc_item_flag;
  8042. /* check for combos (MUST be before status_calc_pc) */
  8043. if ( sd->inventory_data[n] ) {
  8044. if( sd->inventory_data[n]->combos_count ) {
  8045. if( pc_removecombo(sd,sd->inventory_data[n]) )
  8046. status_cacl = true;
  8047. } if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  8048. ; //No cards
  8049. else {
  8050. for( i = 0; i < sd->inventory_data[n]->slot; i++ ) {
  8051. struct item_data *data;
  8052. if (!sd->status.inventory[n].card[i])
  8053. continue;
  8054. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  8055. if( data->combos_count ) {
  8056. if( pc_removecombo(sd,data) )
  8057. status_cacl = true;
  8058. }
  8059. }
  8060. }
  8061. }
  8062. }
  8063. if(flag&1 || status_cacl) {
  8064. pc_checkallowskill(sd);
  8065. status_calc_pc(sd,0);
  8066. }
  8067. if(sd->sc.data[SC_SIGNUMCRUCIS] && !battle_check_undead(sd->battle_status.race,sd->battle_status.def_ele))
  8068. status_change_end(&sd->bl, SC_SIGNUMCRUCIS, INVALID_TIMER);
  8069. //OnUnEquip script [Skotlex]
  8070. if (sd->inventory_data[n]) {
  8071. if (sd->inventory_data[n]->unequip_script)
  8072. run_script(sd->inventory_data[n]->unequip_script,0,sd->bl.id,fake_nd->bl.id);
  8073. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  8074. ; //No cards
  8075. else {
  8076. for( i = 0; i < sd->inventory_data[n]->slot; i++ ) {
  8077. struct item_data *data;
  8078. if (!sd->status.inventory[n].card[i])
  8079. continue;
  8080. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  8081. if( data->unequip_script )
  8082. run_script(data->unequip_script,0,sd->bl.id,fake_nd->bl.id);
  8083. }
  8084. }
  8085. }
  8086. }
  8087. sd->npc_item_flag = iflag;
  8088. return true;
  8089. }
  8090. /*==========================================
  8091. * Checking if player (sd) has an invalid item
  8092. * and is unequiped on map load (item_noequip)
  8093. *------------------------------------------*/
  8094. void pc_checkitem(struct map_session_data *sd) {
  8095. int i, calc_flag = 0;
  8096. struct item it;
  8097. nullpo_retv(sd);
  8098. if( sd->state.vending ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
  8099. return;
  8100. for( i = 0; i < MAX_INVENTORY; i++ ) {
  8101. it = sd->status.inventory[i];
  8102. if( it.nameid == 0 )
  8103. continue;
  8104. if( !it.equip )
  8105. continue;
  8106. if( it.equip&~pc_equippoint(sd,i) ) {
  8107. pc_unequipitem(sd, i, 2);
  8108. calc_flag = 1;
  8109. continue;
  8110. }
  8111. if( !pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT) && !battle_config.allow_equip_restricted_item && itemdb_isNoEquip(sd->inventory_data[i], sd->bl.m) ) {
  8112. pc_unequipitem(sd, i, 2);
  8113. calc_flag = 1;
  8114. continue;
  8115. }
  8116. }
  8117. if( calc_flag && sd->state.active ) {
  8118. pc_checkallowskill(sd);
  8119. status_calc_pc(sd,0);
  8120. }
  8121. return;
  8122. }
  8123. /*==========================================
  8124. * Checks for unavailable items and removes them.
  8125. *------------------------------------------*/
  8126. void pc_check_available_item(struct map_session_data *sd) {
  8127. int i, it;
  8128. char output[256];
  8129. nullpo_retv(sd);
  8130. if( battle_config.item_check&1 ) { // Check for invalid(ated) items in inventory.
  8131. for( i = 0; i < MAX_INVENTORY; i++ ) {
  8132. it = sd->status.inventory[i].nameid;
  8133. if( it && !itemdb_available(it) ) {
  8134. sprintf(output, msg_txt(sd, 709), it); // Item %d has been removed from your inventory.
  8135. clif_displaymessage(sd->fd, output);
  8136. ShowWarning("Removed invalid/disabled item id %d from inventory (amount=%d, char_id=%d).\n", it, sd->status.inventory[i].amount, sd->status.char_id);
  8137. pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
  8138. }
  8139. }
  8140. }
  8141. if( battle_config.item_check&2 ) { // Check for invalid(ated) items in cart.
  8142. for( i = 0; i < MAX_CART; i++ ) {
  8143. it = sd->status.cart[i].nameid;
  8144. if( it && !itemdb_available(it) ) {
  8145. sprintf(output, msg_txt(sd, 710), it); // Item %d has been removed from your cart.
  8146. clif_displaymessage(sd->fd, output);
  8147. ShowWarning("Removed invalid/disabled item id %d from cart (amount=%d, char_id=%d).\n", it, sd->status.cart[i].amount, sd->status.char_id);
  8148. pc_cart_delitem(sd, i, sd->status.cart[i].amount, 0, LOG_TYPE_OTHER);
  8149. }
  8150. }
  8151. }
  8152. if( battle_config.item_check&4 ) { // Check for invalid(ated) items in storage.
  8153. for( i = 0; i < sd->storage_size; i++ ) {
  8154. it = sd->status.storage.items[i].nameid;
  8155. if( it && !itemdb_available(it) ) {
  8156. sprintf(output, msg_txt(sd, 711), it); // Item %d has been removed from your storage.
  8157. clif_displaymessage(sd->fd, output);
  8158. ShowWarning("Removed invalid/disabled item id %d from storage (amount=%d, char_id=%d).\n", it, sd->status.storage.items[i].amount, sd->status.char_id);
  8159. storage_delitem(sd, i, sd->status.storage.items[i].amount);
  8160. }
  8161. }
  8162. }
  8163. }
  8164. /*==========================================
  8165. * Update PVP rank for sd1 in cmp to sd2
  8166. *------------------------------------------*/
  8167. static int pc_calc_pvprank_sub(struct block_list *bl,va_list ap)
  8168. {
  8169. struct map_session_data *sd1,*sd2;
  8170. sd1=(struct map_session_data *)bl;
  8171. sd2=va_arg(ap,struct map_session_data *);
  8172. if( sd1->sc.option&OPTION_INVISIBLE || sd2->sc.option&OPTION_INVISIBLE )
  8173. {// cannot register pvp rank for hidden GMs
  8174. return 0;
  8175. }
  8176. if( sd1->pvp_point > sd2->pvp_point )
  8177. sd2->pvp_rank++;
  8178. return 0;
  8179. }
  8180. /*==========================================
  8181. * Calculate new rank beetween all present players (map_foreachinarea)
  8182. * and display result
  8183. *------------------------------------------*/
  8184. int pc_calc_pvprank(struct map_session_data *sd)
  8185. {
  8186. int old = sd->pvp_rank;
  8187. struct map_data *m = &map[sd->bl.m];
  8188. sd->pvp_rank=1;
  8189. map_foreachinmap(pc_calc_pvprank_sub,sd->bl.m,BL_PC,sd);
  8190. if(old!=sd->pvp_rank || sd->pvp_lastusers!=m->users_pvp)
  8191. clif_pvpset(sd,sd->pvp_rank,sd->pvp_lastusers=m->users_pvp,0);
  8192. return sd->pvp_rank;
  8193. }
  8194. /*==========================================
  8195. * Calculate next sd ranking calculation from config
  8196. *------------------------------------------*/
  8197. int pc_calc_pvprank_timer(int tid, unsigned int tick, int id, intptr_t data)
  8198. {
  8199. struct map_session_data *sd;
  8200. sd=map_id2sd(id);
  8201. if(sd==NULL)
  8202. return 0;
  8203. sd->pvp_timer = INVALID_TIMER;
  8204. if( sd->sc.option&OPTION_INVISIBLE )
  8205. {// do not calculate the pvp rank for a hidden GM
  8206. return 0;
  8207. }
  8208. if( pc_calc_pvprank(sd) > 0 )
  8209. sd->pvp_timer = add_timer(gettick()+PVP_CALCRANK_INTERVAL,pc_calc_pvprank_timer,id,data);
  8210. return 0;
  8211. }
  8212. /*==========================================
  8213. * Checking if sd is married
  8214. * Return:
  8215. * partner_id = yes
  8216. * 0 = no
  8217. *------------------------------------------*/
  8218. int pc_ismarried(struct map_session_data *sd)
  8219. {
  8220. if(sd == NULL)
  8221. return -1;
  8222. if(sd->status.partner_id > 0)
  8223. return sd->status.partner_id;
  8224. else
  8225. return 0;
  8226. }
  8227. /*==========================================
  8228. * Marry player sd to player dstsd
  8229. * Return:
  8230. * false = fail
  8231. * true = success
  8232. *------------------------------------------*/
  8233. bool pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd)
  8234. {
  8235. if(sd == NULL || dstsd == NULL ||
  8236. sd->status.partner_id > 0 || dstsd->status.partner_id > 0 ||
  8237. (sd->class_&JOBL_BABY) || (dstsd->class_&JOBL_BABY))
  8238. return false;
  8239. sd->status.partner_id = dstsd->status.char_id;
  8240. dstsd->status.partner_id = sd->status.char_id;
  8241. return true;
  8242. }
  8243. /*==========================================
  8244. * Divorce sd from its partner
  8245. * Return:
  8246. * false = fail
  8247. * true = success
  8248. *------------------------------------------*/
  8249. bool pc_divorce(struct map_session_data *sd)
  8250. {
  8251. struct map_session_data *p_sd;
  8252. int i;
  8253. if( sd == NULL || !pc_ismarried(sd) )
  8254. return false;
  8255. if( !sd->status.partner_id )
  8256. return false; // Char is not married
  8257. if( (p_sd = map_charid2sd(sd->status.partner_id)) == NULL )
  8258. { // Lets char server do the divorce
  8259. if( chrif_divorce(sd->status.char_id, sd->status.partner_id) )
  8260. return false; // No char server connected
  8261. return true;
  8262. }
  8263. // Both players online, lets do the divorce manually
  8264. sd->status.partner_id = 0;
  8265. p_sd->status.partner_id = 0;
  8266. for( i = 0; i < MAX_INVENTORY; i++ )
  8267. {
  8268. if( sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F )
  8269. pc_delitem(sd, i, 1, 0, 0, LOG_TYPE_OTHER);
  8270. if( p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F )
  8271. pc_delitem(p_sd, i, 1, 0, 0, LOG_TYPE_OTHER);
  8272. }
  8273. clif_divorced(sd, p_sd->status.name);
  8274. clif_divorced(p_sd, sd->status.name);
  8275. return true;
  8276. }
  8277. /**
  8278. * Get the partner map_session_data of a player
  8279. * @param sd : the husband|wife session
  8280. * @return partner session or NULL
  8281. */
  8282. struct map_session_data *pc_get_partner(struct map_session_data *sd){
  8283. if (!sd || !pc_ismarried(sd))
  8284. return NULL;
  8285. return map_charid2sd(sd->status.partner_id);
  8286. }
  8287. /**
  8288. * Get the father map_session_data of a player
  8289. * @param sd : the baby session
  8290. * @return father session or NULL
  8291. */
  8292. struct map_session_data *pc_get_father (struct map_session_data *sd){
  8293. if (!sd || !(sd->class_&JOBL_BABY) || !sd->status.father)
  8294. return NULL;
  8295. return map_charid2sd(sd->status.father);
  8296. }
  8297. /**
  8298. * Get the mother map_session_data of a player
  8299. * @param sd : the baby session
  8300. * @return mother session or NULL
  8301. */
  8302. struct map_session_data *pc_get_mother (struct map_session_data *sd){
  8303. if (!sd || !(sd->class_&JOBL_BABY) || !sd->status.mother)
  8304. return NULL;
  8305. return map_charid2sd(sd->status.mother);
  8306. }
  8307. /*==========================================
  8308. * Get sd children charid. (Need to be married)
  8309. *------------------------------------------*/
  8310. struct map_session_data *pc_get_child (struct map_session_data *sd)
  8311. {
  8312. if (!sd || !pc_ismarried(sd) || !sd->status.child)
  8313. // charid2sd returns NULL if not found
  8314. return NULL;
  8315. return map_charid2sd(sd->status.child);
  8316. }
  8317. /*==========================================
  8318. * Set player sd to bleed. (losing hp and/or sp each diff_tick)
  8319. *------------------------------------------*/
  8320. void pc_bleeding (struct map_session_data *sd, unsigned int diff_tick)
  8321. {
  8322. int hp = 0, sp = 0;
  8323. if( pc_isdead(sd) )
  8324. return;
  8325. if (sd->hp_loss.value) {
  8326. sd->hp_loss.tick += diff_tick;
  8327. while (sd->hp_loss.tick >= sd->hp_loss.rate) {
  8328. hp += sd->hp_loss.value;
  8329. sd->hp_loss.tick -= sd->hp_loss.rate;
  8330. }
  8331. if(hp >= sd->battle_status.hp)
  8332. hp = sd->battle_status.hp-1; //Script drains cannot kill you.
  8333. }
  8334. if (sd->sp_loss.value) {
  8335. sd->sp_loss.tick += diff_tick;
  8336. while (sd->sp_loss.tick >= sd->sp_loss.rate) {
  8337. sp += sd->sp_loss.value;
  8338. sd->sp_loss.tick -= sd->sp_loss.rate;
  8339. }
  8340. }
  8341. if (hp > 0 || sp > 0)
  8342. status_zap(&sd->bl, hp, sp);
  8343. }
  8344. //Character regen. Flag is used to know which types of regen can take place.
  8345. //&1: HP regen
  8346. //&2: SP regen
  8347. void pc_regen (struct map_session_data *sd, unsigned int diff_tick)
  8348. {
  8349. int hp = 0, sp = 0;
  8350. if (sd->hp_regen.value) {
  8351. sd->hp_regen.tick += diff_tick;
  8352. while (sd->hp_regen.tick >= sd->hp_regen.rate) {
  8353. hp += sd->hp_regen.value;
  8354. sd->hp_regen.tick -= sd->hp_regen.rate;
  8355. }
  8356. }
  8357. if (sd->sp_regen.value) {
  8358. sd->sp_regen.tick += diff_tick;
  8359. while (sd->sp_regen.tick >= sd->sp_regen.rate) {
  8360. sp += sd->sp_regen.value;
  8361. sd->sp_regen.tick -= sd->sp_regen.rate;
  8362. }
  8363. }
  8364. if (hp > 0 || sp > 0)
  8365. status_heal(&sd->bl, hp, sp, 0);
  8366. }
  8367. /*==========================================
  8368. * Memo player sd savepoint. (map,x,y)
  8369. *------------------------------------------*/
  8370. void pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y)
  8371. {
  8372. nullpo_retv(sd);
  8373. sd->status.save_point.map = mapindex;
  8374. sd->status.save_point.x = x;
  8375. sd->status.save_point.y = y;
  8376. }
  8377. /*==========================================
  8378. * Save 1 player data at autosave intervalle
  8379. *------------------------------------------*/
  8380. static int pc_autosave(int tid, unsigned int tick, int id, intptr_t data)
  8381. {
  8382. int interval;
  8383. struct s_mapiterator* iter;
  8384. struct map_session_data* sd;
  8385. static int last_save_id = 0, save_flag = 0;
  8386. if(save_flag == 2) //Someone was saved on last call, normal cycle
  8387. save_flag = 0;
  8388. else
  8389. save_flag = 1; //Noone was saved, so save first found char.
  8390. iter = mapit_getallusers();
  8391. for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
  8392. {
  8393. if(sd->bl.id == last_save_id && save_flag != 1) {
  8394. save_flag = 1;
  8395. continue;
  8396. }
  8397. if(save_flag != 1) //Not our turn to save yet.
  8398. continue;
  8399. //Save char.
  8400. last_save_id = sd->bl.id;
  8401. save_flag = 2;
  8402. #ifdef VIP_ENABLE
  8403. if(sd->vip.enabled) //check if we're still vip
  8404. chrif_req_login_operation(1, sd->status.name, 6, 0, 1, 0);
  8405. #endif
  8406. chrif_save(sd,0);
  8407. break;
  8408. }
  8409. mapit_free(iter);
  8410. interval = autosave_interval/(map_usercount()+1);
  8411. if(interval < minsave_interval)
  8412. interval = minsave_interval;
  8413. add_timer(gettick()+interval,pc_autosave,0,0);
  8414. return 0;
  8415. }
  8416. static int pc_daynight_timer_sub(struct map_session_data *sd,va_list ap)
  8417. {
  8418. if (sd->state.night != night_flag && map[sd->bl.m].flag.nightenabled)
  8419. { //Night/day state does not match.
  8420. clif_status_load(&sd->bl, SI_NIGHT, night_flag); //New night effect by dynamix [Skotlex]
  8421. sd->state.night = night_flag;
  8422. return 1;
  8423. }
  8424. return 0;
  8425. }
  8426. /*================================================
  8427. * timer to do the day [Yor]
  8428. * data: 0 = called by timer, 1 = gmcommand/script
  8429. *------------------------------------------------*/
  8430. int map_day_timer(int tid, unsigned int tick, int id, intptr_t data)
  8431. {
  8432. char tmp_soutput[1024];
  8433. if (data == 0 && battle_config.day_duration <= 0) // if we want a day
  8434. return 0;
  8435. if (!night_flag)
  8436. return 0; //Already day.
  8437. night_flag = 0; // 0=day, 1=night [Yor]
  8438. map_foreachpc(pc_daynight_timer_sub);
  8439. strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,502) : msg_txt(NULL,60)); // The day has arrived!
  8440. intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, 0);
  8441. return 0;
  8442. }
  8443. /*================================================
  8444. * timer to do the night [Yor]
  8445. * data: 0 = called by timer, 1 = gmcommand/script
  8446. *------------------------------------------------*/
  8447. int map_night_timer(int tid, unsigned int tick, int id, intptr_t data)
  8448. {
  8449. char tmp_soutput[1024];
  8450. if (data == 0 && battle_config.night_duration <= 0) // if we want a night
  8451. return 0;
  8452. if (night_flag)
  8453. return 0; //Already nigth.
  8454. night_flag = 1; // 0=day, 1=night [Yor]
  8455. map_foreachpc(pc_daynight_timer_sub);
  8456. strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,503) : msg_txt(NULL,59)); // The night has fallen...
  8457. intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, 0);
  8458. return 0;
  8459. }
  8460. void pc_setstand(struct map_session_data *sd){
  8461. nullpo_retv(sd);
  8462. status_change_end(&sd->bl, SC_TENSIONRELAX, INVALID_TIMER);
  8463. clif_status_load(&sd->bl,SI_SIT,0);
  8464. clif_standing(&sd->bl); //Inform area PC is standing
  8465. //Reset sitting tick.
  8466. sd->ssregen.tick.hp = sd->ssregen.tick.sp = 0;
  8467. sd->state.dead_sit = sd->vd.dead_sit = 0;
  8468. }
  8469. /**
  8470. * Mechanic (MADO GEAR)
  8471. **/
  8472. void pc_overheat(struct map_session_data *sd, int val) {
  8473. int heat = val, skill,
  8474. limit[] = { 10, 20, 28, 46, 66 };
  8475. if( !pc_ismadogear(sd) || sd->sc.data[SC_OVERHEAT] )
  8476. return; // already burning
  8477. skill = cap_value(pc_checkskill(sd,NC_MAINFRAME),0,4);
  8478. if( sd->sc.data[SC_OVERHEAT_LIMITPOINT] ) {
  8479. heat += sd->sc.data[SC_OVERHEAT_LIMITPOINT]->val1;
  8480. status_change_end(&sd->bl,SC_OVERHEAT_LIMITPOINT,INVALID_TIMER);
  8481. }
  8482. heat = max(0,heat); // Avoid negative HEAT
  8483. if( heat >= limit[skill] )
  8484. sc_start(&sd->bl,&sd->bl,SC_OVERHEAT,100,0,1000);
  8485. else
  8486. sc_start(&sd->bl,&sd->bl,SC_OVERHEAT_LIMITPOINT,100,heat,30000);
  8487. return;
  8488. }
  8489. /**
  8490. * Check if player is autolooting given itemID.
  8491. */
  8492. bool pc_isautolooting(struct map_session_data *sd, int nameid)
  8493. {
  8494. uint8 i = 0;
  8495. bool j = false;
  8496. if (!sd->state.autolooting && !sd->state.autolootingtype)
  8497. return false;
  8498. if (sd->state.autolooting)
  8499. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == nameid);
  8500. if (sd->state.autolootingtype && sd->state.autoloottype&(1<<itemdb_type(nameid)))
  8501. j = true;
  8502. return (i != AUTOLOOTITEM_SIZE || j );
  8503. }
  8504. /**
  8505. * Checks if player can use @/#command
  8506. * @param sd Player map session data
  8507. * @param command Command name without @/# and params
  8508. * @param type is it atcommand or charcommand
  8509. */
  8510. bool pc_can_use_command(struct map_session_data *sd, const char *command, AtCommandType type)
  8511. {
  8512. return pc_group_can_use_command(pc_get_group_id(sd), command, type);
  8513. }
  8514. /**
  8515. * Checks if commands used by a player should be logged
  8516. * according to their group setting.
  8517. * @param sd Player map session data
  8518. */
  8519. bool pc_should_log_commands(struct map_session_data *sd)
  8520. {
  8521. return pc_group_should_log_commands(pc_get_group_id(sd));
  8522. }
  8523. static int pc_talisman_timer(int tid, unsigned int tick, int id, intptr_t data)
  8524. {
  8525. struct map_session_data *sd;
  8526. int i, type;
  8527. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  8528. return 1;
  8529. ARR_FIND(1, 5, type, sd->talisman[type] > 0);
  8530. if( sd->talisman[type] <= 0 )
  8531. {
  8532. ShowError("pc_talisman_timer: %d talisman's available. (aid=%d cid=%d tid=%d)\n", sd->talisman[type], sd->status.account_id, sd->status.char_id, tid);
  8533. sd->talisman[type] = 0;
  8534. return 0;
  8535. }
  8536. ARR_FIND(0, sd->talisman[type], i, sd->talisman_timer[type][i] == tid);
  8537. if( i == sd->talisman[type] )
  8538. {
  8539. ShowError("pc_talisman_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
  8540. return 0;
  8541. }
  8542. sd->talisman[type]--;
  8543. if( i != sd->talisman[type] )
  8544. memmove(sd->talisman_timer[type]+i, sd->talisman_timer[type]+i+1, (sd->talisman[type]-i)*sizeof(int));
  8545. sd->talisman_timer[type][sd->talisman[type]] = INVALID_TIMER;
  8546. clif_talisman(sd, type);
  8547. return 0;
  8548. }
  8549. int pc_add_talisman(struct map_session_data *sd,int interval,int max,int type)
  8550. {
  8551. int tid, i;
  8552. nullpo_ret(sd);
  8553. if(max > 10)
  8554. max = 10;
  8555. if(sd->talisman[type] < 0)
  8556. sd->talisman[type] = 0;
  8557. if( sd->talisman[type] && sd->talisman[type] >= max )
  8558. {
  8559. if(sd->talisman_timer[type][0] != INVALID_TIMER)
  8560. delete_timer(sd->talisman_timer[type][0],pc_talisman_timer);
  8561. sd->talisman[type]--;
  8562. if( sd->talisman[type] != 0 )
  8563. memmove(sd->talisman_timer[type]+0, sd->talisman_timer[type]+1, (sd->talisman[type])*sizeof(int));
  8564. sd->talisman_timer[type][sd->talisman[type]] = INVALID_TIMER;
  8565. }
  8566. tid = add_timer(gettick()+interval, pc_talisman_timer, sd->bl.id, 0);
  8567. ARR_FIND(0, sd->talisman[type], i, sd->talisman_timer[type][i] == INVALID_TIMER || DIFF_TICK(get_timer(tid)->tick, get_timer(sd->talisman_timer[type][i])->tick) < 0);
  8568. if( i != sd->talisman[type] )
  8569. memmove(sd->talisman_timer[type]+i+1, sd->talisman_timer[type]+i, (sd->talisman[type]-i)*sizeof(int));
  8570. sd->talisman_timer[type][i] = tid;
  8571. sd->talisman[type]++;
  8572. clif_talisman(sd, type);
  8573. return 0;
  8574. }
  8575. int pc_del_talisman(struct map_session_data *sd,int count,int type)
  8576. {
  8577. int i;
  8578. nullpo_ret(sd);
  8579. if( sd->talisman[type] <= 0 ) {
  8580. sd->talisman[type] = 0;
  8581. return 0;
  8582. }
  8583. if( count <= 0 )
  8584. return 0;
  8585. if( count > sd->talisman[type] )
  8586. count = sd->talisman[type];
  8587. sd->talisman[type] -= count;
  8588. if( count > 10 )
  8589. count = 10;
  8590. for(i = 0; i < count; i++) {
  8591. if(sd->talisman_timer[type][i] != INVALID_TIMER) {
  8592. delete_timer(sd->talisman_timer[type][i],pc_talisman_timer);
  8593. sd->talisman_timer[type][i] = INVALID_TIMER;
  8594. }
  8595. }
  8596. for(i = count; i < 10; i++) {
  8597. sd->talisman_timer[type][i-count] = sd->talisman_timer[type][i];
  8598. sd->talisman_timer[type][i] = INVALID_TIMER;
  8599. }
  8600. clif_talisman(sd, type);
  8601. return 0;
  8602. }
  8603. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  8604. /*==========================================
  8605. * Renewal EXP/Itemdrop rate modifier base on level penalty
  8606. * 1=exp 2=itemdrop
  8607. *------------------------------------------*/
  8608. int pc_level_penalty_mod(struct map_session_data *sd, int mob_level, uint32 mob_class, int type)
  8609. {
  8610. int diff, rate = 100, i;
  8611. nullpo_ret(sd);
  8612. diff = mob_level - sd->status.base_level;
  8613. if( diff < 0 )
  8614. diff = MAX_LEVEL + ( ~diff + 1 );
  8615. for( i = 0; i < CLASS_ALL; i++ ) {
  8616. int tmp;
  8617. if( ( tmp = level_penalty[type][i][diff] ) > 0 ) {
  8618. rate = tmp;
  8619. break;
  8620. }
  8621. }
  8622. return rate;
  8623. }
  8624. #endif
  8625. int pc_split_str(char *str,char **val,int num)
  8626. {
  8627. int i;
  8628. for (i=0; i<num && str; i++){
  8629. val[i] = str;
  8630. str = strchr(str,',');
  8631. if (str && i<num-1) //Do not remove a trailing comma.
  8632. *str++=0;
  8633. }
  8634. return i;
  8635. }
  8636. int pc_split_atoi(char* str, int* val, char sep, int max)
  8637. {
  8638. int i,j;
  8639. for (i=0; i<max; i++) {
  8640. if (!str) break;
  8641. val[i] = atoi(str);
  8642. str = strchr(str,sep);
  8643. if (str)
  8644. *str++=0;
  8645. }
  8646. //Zero up the remaining.
  8647. for(j=i; j < max; j++)
  8648. val[j] = 0;
  8649. return i;
  8650. }
  8651. int pc_split_atoui(char* str, unsigned int* val, char sep, int max)
  8652. {
  8653. static int warning=0;
  8654. int i,j;
  8655. for (i=0; i<max; i++) {
  8656. double f;
  8657. if (!str) break;
  8658. f = atof(str);
  8659. if (f < 0)
  8660. val[i] = 0;
  8661. else if (f > UINT_MAX) {
  8662. val[i] = UINT_MAX;
  8663. if (!warning) {
  8664. warning = 1;
  8665. ShowWarning("pc_readdb (exp.txt): Required exp per level is capped to %u\n", UINT_MAX);
  8666. }
  8667. } else
  8668. val[i] = (unsigned int)f;
  8669. str = strchr(str,sep);
  8670. if (str)
  8671. *str++=0;
  8672. }
  8673. //Zero up the remaining.
  8674. for(j=i; j < max; j++)
  8675. val[j] = 0;
  8676. return i;
  8677. }
  8678. /*==========================================
  8679. * sub DB reading.
  8680. * Function used to read skill_tree.txt
  8681. *------------------------------------------*/
  8682. static bool pc_readdb_skilltree(char* fields[], int columns, int current)
  8683. {
  8684. unsigned char joblv = 0, skill_lv;
  8685. uint16 skill_id;
  8686. int idx, class_;
  8687. unsigned int i, offset = 3, skill_idx;
  8688. class_ = atoi(fields[0]);
  8689. skill_id = (uint16)atoi(fields[1]);
  8690. skill_lv = (unsigned char)atoi(fields[2]);
  8691. if(columns==4+MAX_PC_SKILL_REQUIRE*2)
  8692. {// job level requirement extra column
  8693. joblv = (unsigned char)atoi(fields[3]);
  8694. offset++;
  8695. }
  8696. if(!pcdb_checkid(class_))
  8697. {
  8698. ShowWarning("pc_readdb_skilltree: Invalid job class %d specified.\n", class_);
  8699. return false;
  8700. }
  8701. idx = pc_class2idx(class_);
  8702. //This is to avoid adding two lines for the same skill. [Skotlex]
  8703. ARR_FIND( 0, MAX_SKILL_TREE, skill_idx, skill_tree[idx][skill_idx].id == 0 || skill_tree[idx][skill_idx].id == skill_id );
  8704. if( skill_idx == MAX_SKILL_TREE )
  8705. {
  8706. ShowWarning("pc_readdb_skilltree: Unable to load skill %hu into job %d's tree. Maximum number of skills per class has been reached.\n", skill_id, class_);
  8707. return false;
  8708. }
  8709. else if(skill_tree[idx][skill_idx].id)
  8710. {
  8711. ShowNotice("pc_readdb_skilltree: Overwriting skill %hu for job class %d.\n", skill_id, class_);
  8712. }
  8713. skill_tree[idx][skill_idx].id = skill_id;
  8714. skill_tree[idx][skill_idx].max = skill_lv;
  8715. skill_tree[idx][skill_idx].joblv = joblv;
  8716. for(i = 0; i < MAX_PC_SKILL_REQUIRE; i++)
  8717. {
  8718. skill_tree[idx][skill_idx].need[i].id = atoi(fields[i*2+offset]);
  8719. skill_tree[idx][skill_idx].need[i].lv = atoi(fields[i*2+offset+1]);
  8720. }
  8721. return true;
  8722. }
  8723. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  8724. static bool pc_readdb_levelpenalty(char* fields[], int columns, int current)
  8725. {
  8726. int type, class_, diff;
  8727. type = atoi(fields[0]); //1=experience, 2=item drop
  8728. class_ = atoi(fields[1]);
  8729. diff = atoi(fields[2]);
  8730. if( type != 1 && type != 2 ){
  8731. ShowWarning("pc_readdb_levelpenalty: Invalid type %d specified.\n", type);
  8732. return false;
  8733. }
  8734. if( class_ < 0 || class_ > CLASS_ALL ){
  8735. ShowWarning("pc_readdb_levelpenalty: Invalid class %d specified.\n", class_);
  8736. return false;
  8737. }
  8738. diff = min(diff, MAX_LEVEL);
  8739. if( diff < 0 )
  8740. diff = min(MAX_LEVEL + ( ~(diff) + 1 ), MAX_LEVEL*2);
  8741. level_penalty[type][class_][diff] = atoi(fields[3]);
  8742. return true;
  8743. }
  8744. #endif
  8745. /** [Cydh]
  8746. * Calculates base hp of player. Reference: http://irowiki.org/wiki/Max_HP
  8747. * @param level Base level of player
  8748. * @param idx Index of class
  8749. * @return base_hp
  8750. */
  8751. static unsigned int pc_calc_basehp(uint16 level, uint16 class_idx) {
  8752. double base_hp;
  8753. uint16 i;
  8754. base_hp = 35 + level * (job_info[class_idx].hp_multiplicator/100.);
  8755. for (i = 2; i <= level; i++)
  8756. base_hp += floor(((job_info[class_idx].hp_factor/100.) * i) + 0.5); //Don't have round()
  8757. return (unsigned int)base_hp;
  8758. }
  8759. //Reading job_db1.txt line, (class,weight,HPFactor,HPMultiplicator,SPFactor,aspd/lvl...)
  8760. static bool pc_readdb_job1(char* fields[], int columns, int current){
  8761. int idx, class_;
  8762. unsigned int i;
  8763. class_ = atoi(fields[0]);
  8764. if (!pcdb_checkid(class_)) {
  8765. ShowWarning("status_readdb_job1: Invalid job class %d specified.\n", class_);
  8766. return false;
  8767. }
  8768. idx = pc_class2idx(class_);
  8769. job_info[idx].max_weight_base = atoi(fields[1]);
  8770. job_info[idx].hp_factor = atoi(fields[2]);
  8771. job_info[idx].hp_multiplicator = atoi(fields[3]);
  8772. job_info[idx].sp_factor = atoi(fields[4]);
  8773. #ifdef RENEWAL_ASPD
  8774. for(i = 0; i <= MAX_WEAPON_TYPE; i++)
  8775. #else
  8776. for(i = 0; i < MAX_WEAPON_TYPE; i++)
  8777. #endif
  8778. {
  8779. job_info[idx].aspd_base[i] = atoi(fields[i+5]);
  8780. }
  8781. return true;
  8782. }
  8783. //Reading job_db2.txt line (class,JobLv1,JobLv2,JobLv3,...)
  8784. static bool pc_readdb_job2(char* fields[], int columns, int current)
  8785. {
  8786. int idx, class_, i;
  8787. class_ = atoi(fields[0]);
  8788. if(!pcdb_checkid(class_))
  8789. {
  8790. ShowWarning("status_readdb_job2: Invalid job class %d specified.\n", class_);
  8791. return false;
  8792. }
  8793. idx = pc_class2idx(class_);
  8794. for(i = 1; i < columns; i++)
  8795. {
  8796. job_info[idx].job_bonus[i-1] = atoi(fields[i]);
  8797. }
  8798. return true;
  8799. }
  8800. //Reading job_exp.txt line
  8801. //Max Level,Class list,Type (0 - Base Exp; 1 - Job Exp),Exp/lvl...
  8802. static bool pc_readdb_job_exp(char* fields[], int columns, int current)
  8803. {
  8804. int idx, i, type;
  8805. int job_id,job_count,jobs[CLASS_COUNT];
  8806. unsigned int ui, maxlvl;
  8807. maxlvl = atoi(fields[0]);
  8808. if(maxlvl > MAX_LEVEL || maxlvl<1){
  8809. ShowError("pc_readdb_job_exp: Invalid maxlevel %d specified.\n", maxlvl);
  8810. return false;
  8811. }
  8812. if((maxlvl+3) > columns){ //nb values = (maxlvl-startlvl)+1-index1stvalue
  8813. ShowError("pc_readdb_job_exp: Number of columns %d defined is too low for max level %d.\n",columns,maxlvl);
  8814. return false;
  8815. }
  8816. type = atoi(fields[2]);
  8817. if(type < 0 || type > 1){
  8818. ShowError("pc_readdb_job_exp: Invalid type %d specified.\n", type);
  8819. return false;
  8820. }
  8821. job_count = pc_split_atoi(fields[1],jobs,':',CLASS_COUNT);
  8822. if (job_count < 1)
  8823. return false;
  8824. job_id = jobs[0];
  8825. if(!pcdb_checkid(job_id)){
  8826. ShowError("pc_readdb_job_exp: Invalid job class %d specified.\n", job_id);
  8827. return false;
  8828. }
  8829. idx = pc_class2idx(job_id);
  8830. job_info[idx].max_level[type] = maxlvl;
  8831. for(i=0; i<maxlvl; i++) {
  8832. job_info[idx].exp_table[type][i] = ((uint32) atoi(fields[3+i]));
  8833. //Place the BaseHP/SP calculation here, so we can use the maxlevel from job_exp
  8834. if (type != 0)
  8835. continue;
  8836. job_info[idx].base_hp[i] = pc_calc_basehp(i+1,idx);
  8837. job_info[idx].base_sp[i] = 10 + ((i+1) * (job_info[idx].sp_factor/100));
  8838. }
  8839. //Reverse check in case the array has a bunch of trailing zeros... [Skotlex]
  8840. //The reasoning behind the -2 is this... if the max level is 5, then the array
  8841. //should look like this:
  8842. //0: x, 1: x, 2: x: 3: x 4: 0 <- last valid value is at 3.
  8843. while ((ui = job_info[idx].max_level[type]) >= 2 && job_info[idx].exp_table[type][ui-2] <= 0)
  8844. job_info[idx].max_level[type]--;
  8845. if (job_info[idx].max_level[type] < maxlvl) {
  8846. ShowWarning("pc_readdb_job_exp: Specified max %u for job %d, but that job's exp table only goes up to level %u.\n", maxlvl, job_id, job_info[idx].max_level[type]);
  8847. ShowInfo("Filling the missing values with the last exp entry.\n");
  8848. //Fill the requested values with the last entry.
  8849. ui = (job_info[idx].max_level[type] <= 2? 0: job_info[idx].max_level[type]-2);
  8850. for (; ui+2 < maxlvl; ui++)
  8851. job_info[idx].exp_table[type][ui] = job_info[idx].exp_table[type][ui-1];
  8852. job_info[idx].max_level[type] = maxlvl;
  8853. }
  8854. // ShowInfo("%s - Class %d: %d\n", type?"Job":"Base", job_id, job_info[idx].max_level[type]);
  8855. for (i = 1; i < job_count; i++) {
  8856. uint16 j;
  8857. job_id = jobs[i];
  8858. if (!pcdb_checkid(job_id)) {
  8859. ShowError("pc_readdb_job_exp: Invalid job ID %d.\n", job_id);
  8860. continue;
  8861. }
  8862. idx = pc_class2idx(job_id);
  8863. memcpy(job_info[idx].exp_table[type], job_info[pc_class2idx(jobs[0])].exp_table[type], sizeof(job_info[pc_class2idx(jobs[0])].exp_table[type]));
  8864. job_info[idx].max_level[type] = maxlvl;
  8865. // ShowInfo("%s - Class %d: %u\n", type?"Job":"Base", job_id, job_info[idx].max_level[type]);
  8866. //Place the BaseHP/SP calculation here, so we can use the maxlevel from job_exp
  8867. if (type != 0)
  8868. continue;
  8869. for (j = 0; j < maxlvl; j++) {
  8870. job_info[idx].base_hp[j] = pc_calc_basehp(j+1,idx);
  8871. job_info[idx].base_sp[j] = 10 + ((j+1) * (job_info[idx].sp_factor/100));
  8872. }
  8873. }
  8874. return true;
  8875. }
  8876. /**
  8877. * #ifdef HP_SP_TABLES, reads 'job_basehpsp_db.txt to replace hp/sp results from formula
  8878. * startlvl,endlvl,class,type,values...
  8879. */
  8880. #ifdef HP_SP_TABLES
  8881. static bool pc_readdb_job_basehpsp(char* fields[], int columns, int current)
  8882. {
  8883. int i, startlvl, endlvl;
  8884. int job_count,jobs[CLASS_COUNT];
  8885. short type;
  8886. startlvl = atoi(fields[0]);
  8887. if(startlvl<1){
  8888. ShowError("pc_readdb_job_basehpsp: Invalid start level %d specified.\n", startlvl);
  8889. return false;
  8890. }
  8891. endlvl = atoi(fields[1]);
  8892. if(endlvl<1 || endlvl<startlvl){
  8893. ShowError("pc_readdb_job_basehpsp: Invalid end level %d specified.\n", endlvl);
  8894. return false;
  8895. }
  8896. if((endlvl-startlvl+1+4) > columns){ //nb values = (maxlvl-startlvl)+1-index1stvalue
  8897. ShowError("pc_readdb_job_basehpsp: Number of columns %d (needs %d) defined is too low for start level %d, max level %d.\n",columns,(endlvl-startlvl+1+4),startlvl,endlvl);
  8898. return false;
  8899. }
  8900. type = atoi(fields[3]);
  8901. if(type < 0 || type > 1){
  8902. ShowError("pc_readdb_job_basehpsp: Invalid type %d specified.\n", type);
  8903. return false;
  8904. }
  8905. job_count = pc_split_atoi(fields[2],jobs,':',CLASS_COUNT);
  8906. if (job_count < 1)
  8907. return false;
  8908. for (i = 0; i < job_count; i++) {
  8909. int idx, job_id = jobs[i], use_endlvl;
  8910. if (!pcdb_checkid(job_id)) {
  8911. ShowError("pc_readdb_job_basehpsp: Invalid job class %d specified.\n", job_id);
  8912. return false;
  8913. }
  8914. idx = pc_class2idx(job_id);
  8915. if (startlvl > job_info[idx].max_level[0]) {
  8916. ShowError("pc_readdb_job_basehpsp: Invalid start level %d specified.\n", startlvl);
  8917. return false;
  8918. }
  8919. //Just read until available max level for this job, don't use MAX_LEVEL!
  8920. use_endlvl = endlvl;
  8921. if (use_endlvl > job_info[idx].max_level[0])
  8922. use_endlvl = job_info[idx].max_level[0];
  8923. if(type == 0) { //hp type
  8924. uint16 j;
  8925. for(j = 0; j < use_endlvl; j++) {
  8926. if (atoi(fields[j+4])) {
  8927. uint16 lvl_idx = startlvl-1+j;
  8928. job_info[idx].base_hp[lvl_idx] = atoi(fields[j+4]);
  8929. //Tells if this HP is lower than previous level
  8930. if (lvl_idx-1 >= 0 && job_info[idx].base_hp[lvl_idx] < job_info[idx].base_hp[lvl_idx-1])
  8931. ShowWarning("pc_readdb_job_basehpsp: HP value at line %d col %d is lower than previous level (job=%d,lvl=%d,oldval=%d,val=%d).\n",
  8932. current,j+4,job_id,lvl_idx+1,job_info[idx].base_hp[lvl_idx-1],job_info[idx].base_hp[lvl_idx]);
  8933. }
  8934. }
  8935. }
  8936. else { //sp type
  8937. uint16 j;
  8938. for(j = 0; j < use_endlvl; j++) {
  8939. if (atoi(fields[j+4])) {
  8940. uint16 lvl_idx = startlvl-1+j;
  8941. job_info[idx].base_sp[lvl_idx] = atoi(fields[j+4]);
  8942. //Tells if this SP is lower than previous level
  8943. if (lvl_idx-1 >= 0 && job_info[idx].base_sp[lvl_idx] < job_info[idx].base_sp[lvl_idx-1])
  8944. ShowWarning("pc_readdb_job_basehpsp: SP value at line %d col %d is lower than previous level (job=%d,lvl=%d,oldval=%d,val=%d).\n",
  8945. current,j+4,job_id,lvl_idx+1,job_info[idx].base_sp[lvl_idx-1],job_info[idx].base_sp[lvl_idx]);
  8946. }
  8947. }
  8948. }
  8949. }
  8950. return true;
  8951. }
  8952. #endif
  8953. /** [Cydh]
  8954. * Reads 'job_param_db.txt' to check max. param each job and store them to job_info[].max_param.*
  8955. */
  8956. static bool pc_readdb_job_param(char* fields[], int columns, int current)
  8957. {
  8958. int idx, class_;
  8959. uint16 str, agi, vit, int_, dex, luk;
  8960. script_get_constant(trim(fields[0]),&class_);
  8961. if ((idx = pc_class2idx(class_)) < 0) {
  8962. ShowError("pc_readdb_job_param: Invalid job '%s'. Skipping!",fields[0]);
  8963. return false;
  8964. }
  8965. str = cap_value(atoi(fields[1]),10,SHRT_MAX);
  8966. agi = atoi(fields[2]) ? cap_value(atoi(fields[2]),10,SHRT_MAX) : str;
  8967. vit = atoi(fields[3]) ? cap_value(atoi(fields[3]),10,SHRT_MAX) : str;
  8968. int_ = atoi(fields[4]) ? cap_value(atoi(fields[4]),10,SHRT_MAX) : str;
  8969. dex = atoi(fields[5]) ? cap_value(atoi(fields[5]),10,SHRT_MAX) : str;
  8970. luk = atoi(fields[6]) ? cap_value(atoi(fields[6]),10,SHRT_MAX) : str;
  8971. job_info[idx].max_param.str = str;
  8972. job_info[idx].max_param.agi = agi;
  8973. job_info[idx].max_param.vit = vit;
  8974. job_info[idx].max_param.int_ = int_;
  8975. job_info[idx].max_param.dex = dex;
  8976. job_info[idx].max_param.luk = luk;
  8977. return true;
  8978. }
  8979. static int pc_read_statsdb(const char *basedir, int last_s, bool silent){
  8980. int i=1;
  8981. char line[24000]; //FIXME this seem too big
  8982. FILE *fp;
  8983. sprintf(line, "%s/statpoint.txt", basedir);
  8984. fp=fopen(line,"r");
  8985. if(fp == NULL){
  8986. if(silent==0) ShowWarning("Can't read '"CL_WHITE"%s"CL_RESET"'... Generating DB.\n",line);
  8987. return -1;
  8988. } else {
  8989. int entries=0;
  8990. while(fgets(line, sizeof(line), fp))
  8991. {
  8992. int stat;
  8993. trim(line);
  8994. if(line[0] == '\0' || (line[0]=='/' && line[1]=='/'))
  8995. continue;
  8996. if ((stat=strtoul(line,NULL,10))<0)
  8997. stat=0;
  8998. if (i > MAX_LEVEL)
  8999. break;
  9000. statp[i]=stat;
  9001. i++;
  9002. entries++;
  9003. }
  9004. fclose(fp);
  9005. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s/%s"CL_RESET"'.\n", entries, basedir,"statpoint.txt");
  9006. }
  9007. return max(last_s,i);
  9008. }
  9009. /*==========================================
  9010. * pc DB reading.
  9011. * job_exp.txt - required experience values
  9012. * skill_tree.txt - skill tree for every class
  9013. * attr_fix.txt - elemental adjustment table
  9014. * job_db1.txt - job,weight,hp_factor,hp_multiplicator,sp_factor,aspds/lvl
  9015. * job_db2.txt - job,stats bonuses/lvl
  9016. * job_maxhpsp_db.txt - strtlvl,maxlvl,job,type,values/lvl (values=hp|sp)
  9017. *------------------------------------------*/
  9018. int pc_readdb(void)
  9019. {
  9020. int i, k, s = 1;
  9021. const char* dbsubpath[] = {
  9022. "",
  9023. "import"
  9024. //add other path here
  9025. };
  9026. //reset
  9027. memset(job_info,0,sizeof(job_info)); // job_info table
  9028. // Reset and read skilltree
  9029. memset(skill_tree,0,sizeof(skill_tree));
  9030. sv_readdb(db_path, DBPATH"skill_tree.txt", ',', 3+MAX_PC_SKILL_REQUIRE*2, 4+MAX_PC_SKILL_REQUIRE*2, -1, &pc_readdb_skilltree, 0);
  9031. sv_readdb(db_path, "import/skill_tree.txt", ',', 3+MAX_PC_SKILL_REQUIRE*2, 4+MAX_PC_SKILL_REQUIRE*2, -1, &pc_readdb_skilltree, 1);
  9032. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  9033. sv_readdb(db_path, "re/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty, 0);
  9034. sv_readdb(db_path, "import/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty, 1);
  9035. for( k=1; k < 3; k++ ){ // fill in the blanks
  9036. int j;
  9037. for( j = 0; j < CLASS_ALL; j++ ){
  9038. int tmp = 0;
  9039. for( i = 0; i < MAX_LEVEL*2; i++ ){
  9040. if( i == MAX_LEVEL+1 )
  9041. tmp = level_penalty[k][j][0];// reset
  9042. if( level_penalty[k][j][i] > 0 )
  9043. tmp = level_penalty[k][j][i];
  9044. else
  9045. level_penalty[k][j][i] = tmp;
  9046. }
  9047. }
  9048. }
  9049. #endif
  9050. // reset then read statspoint
  9051. memset(statp,0,sizeof(statp));
  9052. for(i=0; i<ARRAYLENGTH(dbsubpath); i++){
  9053. int n1 = strlen(db_path)+strlen(dbsubpath[i])+1;
  9054. int n2 = strlen(db_path)+strlen(DBPATH)+strlen(dbsubpath[i])+1;
  9055. char* dbsubpath1 = aMalloc(n1+1);
  9056. char* dbsubpath2 = aMalloc(n2+1);
  9057. safesnprintf(dbsubpath1,n1+1,"%s%s",db_path,dbsubpath[i]);
  9058. if(i==0) safesnprintf(dbsubpath2,n2,"%s/%s%s",db_path,DBPATH,dbsubpath[i]);
  9059. else safesnprintf(dbsubpath2,n2,"%s%s",db_path,dbsubpath[i]);
  9060. s = pc_read_statsdb(dbsubpath2,s,i);
  9061. #ifdef RENEWAL_ASPD
  9062. sv_readdb(dbsubpath1, "re/job_db1.txt",',',6+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
  9063. #else
  9064. sv_readdb(dbsubpath1, "pre-re/job_db1.txt",',',5+MAX_WEAPON_TYPE,5+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
  9065. #endif
  9066. sv_readdb(dbsubpath1, "job_db2.txt",',',1,1+MAX_LEVEL,CLASS_COUNT,&pc_readdb_job2, i);
  9067. sv_readdb(dbsubpath2, "job_exp.txt",',',4,1000+3,CLASS_COUNT*2,&pc_readdb_job_exp, i); //support till 1000lvl
  9068. #ifdef HP_SP_TABLES
  9069. sv_readdb(dbsubpath2, "job_basehpsp_db.txt", ',', 4, 4+500, CLASS_COUNT*2, &pc_readdb_job_basehpsp, i); //Make it support until lvl 500!
  9070. #endif
  9071. sv_readdb(dbsubpath2, "job_param_db.txt", ',', 2, PARAM_MAX+1, CLASS_COUNT, &pc_readdb_job_param, i);
  9072. aFree(dbsubpath1);
  9073. aFree(dbsubpath2);
  9074. }
  9075. // generate the remaining parts of the db if necessary
  9076. k = battle_config.use_statpoint_table; //save setting
  9077. battle_config.use_statpoint_table = 0; //temporarily disable to force pc_gets_status_point use default values
  9078. statp[0] = 45; // seed value
  9079. for (; s <= MAX_LEVEL; s++)
  9080. statp[s] = statp[s-1] + pc_gets_status_point(s-1);
  9081. battle_config.use_statpoint_table = k; //restore setting
  9082. //Checking if all class have their data
  9083. for (i = 0; i < JOB_MAX; i++) {
  9084. int idx;
  9085. if (!pcdb_checkid(i)) continue;
  9086. if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER || i == JOB_HANBOK || i == JOB_OKTOBERFEST)
  9087. continue; //Classes that do not need exp tables.
  9088. idx = pc_class2idx(i);
  9089. if (!job_info[idx].max_level[0])
  9090. ShowWarning("Class %s (%d) does not have a base exp table.\n", job_name(i), i);
  9091. if (!job_info[idx].max_level[1])
  9092. ShowWarning("Class %s (%d) does not have a job exp table.\n", job_name(i), i);
  9093. }
  9094. return 0;
  9095. }
  9096. // Read MOTD on startup. [Valaris]
  9097. int pc_read_motd(void)
  9098. {
  9099. FILE* fp;
  9100. // clear old MOTD
  9101. memset(motd_text, 0, sizeof(motd_text));
  9102. // read current MOTD
  9103. if( ( fp = fopen(motd_txt, "r") ) != NULL )
  9104. {
  9105. unsigned int entries = 0;
  9106. while( entries < MOTD_LINE_SIZE && fgets(motd_text[entries], sizeof(motd_text[entries]), fp) )
  9107. {
  9108. char* buf = motd_text[entries];
  9109. unsigned int lines = 0;
  9110. size_t len;
  9111. lines++;
  9112. if( buf[0] == '/' && buf[1] == '/' )
  9113. continue;
  9114. len = strlen(buf);
  9115. while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) ) // strip trailing EOL characters
  9116. len--;
  9117. if( len ) {
  9118. char * ptr;
  9119. buf[len] = 0;
  9120. if( ( ptr = strstr(buf, " :") ) != NULL && ptr-buf >= NAME_LENGTH ) // crashes newer clients
  9121. 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);
  9122. }
  9123. else {// empty line
  9124. buf[0] = ' ';
  9125. buf[1] = 0;
  9126. }
  9127. entries++;
  9128. }
  9129. fclose(fp);
  9130. ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, motd_txt);
  9131. }
  9132. else
  9133. ShowWarning("File '"CL_WHITE"%s"CL_RESET"' not found.\n", motd_txt);
  9134. return 0;
  9135. }
  9136. void pc_itemcd_do(struct map_session_data *sd, bool load) {
  9137. int i,cursor = 0;
  9138. struct item_cd* cd = NULL;
  9139. if( load ) {
  9140. if( !(cd = idb_get(itemcd_db, sd->status.char_id)) ) {
  9141. // no skill cooldown is associated with this character
  9142. return;
  9143. }
  9144. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  9145. if( cd->nameid[i] && DIFF_TICK(gettick(),cd->tick[i]) < 0 ) {
  9146. sd->item_delay[cursor].tick = cd->tick[i];
  9147. sd->item_delay[cursor].nameid = cd->nameid[i];
  9148. cursor++;
  9149. }
  9150. }
  9151. idb_remove(itemcd_db,sd->status.char_id);
  9152. } else {
  9153. if( !(cd = idb_get(itemcd_db,sd->status.char_id)) ) {
  9154. // create a new skill cooldown object for map storage
  9155. CREATE( cd, struct item_cd, 1 );
  9156. idb_put( itemcd_db, sd->status.char_id, cd );
  9157. }
  9158. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  9159. if( sd->item_delay[i].nameid && DIFF_TICK(gettick(),sd->item_delay[i].tick) < 0 ) {
  9160. cd->tick[cursor] = sd->item_delay[i].tick;
  9161. cd->nameid[cursor] = sd->item_delay[i].nameid;
  9162. cursor++;
  9163. }
  9164. }
  9165. }
  9166. return;
  9167. }
  9168. /**
  9169. * Clear the dmglog data from player
  9170. * @param sd
  9171. * @param md
  9172. **/
  9173. static void pc_clear_log_damage_sub(int char_id, struct mob_data *md)
  9174. {
  9175. uint8 i;
  9176. ARR_FIND(0,DAMAGELOG_SIZE,i,md->dmglog[i].id == char_id);
  9177. if (i < DAMAGELOG_SIZE) {
  9178. md->dmglog[i].id=0;
  9179. md->dmglog[i].dmg=0;
  9180. md->dmglog[i].flag=0;
  9181. }
  9182. }
  9183. /**
  9184. * Add log to player's dmglog
  9185. * @param sd
  9186. * @param id Monster's GID
  9187. **/
  9188. void pc_damage_log_add(struct map_session_data *sd, int id)
  9189. {
  9190. uint8 i = 0;
  9191. if (!sd)
  9192. return;
  9193. //Only store new data, don't need to renew the old one with same id
  9194. for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
  9195. if (sd->dmglog[i] == id)
  9196. return;
  9197. sd->dmglog[i] = id;
  9198. return;
  9199. }
  9200. }
  9201. /**
  9202. * Clear dmglog data from player
  9203. * @param sd
  9204. * @param id Monster's id
  9205. **/
  9206. void pc_damage_log_clear(struct map_session_data *sd, int id)
  9207. {
  9208. uint8 i;
  9209. struct mob_data *md = NULL;
  9210. if (!sd)
  9211. return;
  9212. if (!id) {
  9213. for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
  9214. if( !sd->dmglog[i] ) //skip the empty value
  9215. continue;
  9216. if ((md = map_id2md(sd->dmglog[i])))
  9217. pc_clear_log_damage_sub(sd->status.char_id,md);
  9218. sd->dmglog[i] = 0;
  9219. }
  9220. }
  9221. else {
  9222. if ((md = map_id2md(id)))
  9223. pc_clear_log_damage_sub(sd->status.char_id,md);
  9224. ARR_FIND(0,DAMAGELOG_SIZE_PC,i,sd->dmglog[i] == id); // find the id position
  9225. if (i < DAMAGELOG_SIZE_PC)
  9226. sd->dmglog[i] = 0;
  9227. }
  9228. }
  9229. /**
  9230. * Deposit some money to bank
  9231. * @param sd
  9232. * @param money Amount of money to deposit
  9233. **/
  9234. enum e_BANKING_DEPOSIT_ACK pc_bank_deposit(struct map_session_data *sd, int money) {
  9235. unsigned int limit_check = money+sd->status.bank_vault;
  9236. if( money <= 0 || limit_check > MAX_BANK_ZENY ) {
  9237. return BDA_OVERFLOW;
  9238. } else if ( money > sd->status.zeny ) {
  9239. return BDA_NO_MONEY;
  9240. }
  9241. if( pc_payzeny(sd,money, LOG_TYPE_BANK, NULL) )
  9242. return BDA_NO_MONEY;
  9243. sd->status.bank_vault += money;
  9244. if( save_settings&256 )
  9245. chrif_save(sd,0);
  9246. return BDA_SUCCESS;
  9247. }
  9248. /**
  9249. * Withdraw money from bank
  9250. * @param sd
  9251. * @param money Amount of money that will be withdrawn
  9252. **/
  9253. enum e_BANKING_WITHDRAW_ACK pc_bank_withdraw(struct map_session_data *sd, int money) {
  9254. unsigned int limit_check = money+sd->status.zeny;
  9255. if( money <= 0 ) {
  9256. return BWA_UNKNOWN_ERROR;
  9257. } else if ( money > sd->status.bank_vault ) {
  9258. return BWA_NO_MONEY;
  9259. } else if ( limit_check > MAX_ZENY ) {
  9260. /* no official response for this scenario exists. */
  9261. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1495)); //You can't withdraw that much money
  9262. return BWA_UNKNOWN_ERROR;
  9263. }
  9264. if( pc_getzeny(sd,money, LOG_TYPE_BANK, NULL) )
  9265. return BWA_NO_MONEY;
  9266. sd->status.bank_vault -= money;
  9267. if( save_settings&256 )
  9268. chrif_save(sd,0);
  9269. return BWA_SUCCESS;
  9270. }
  9271. /**
  9272. * Clear Cirmson Marker data from caster
  9273. * @param sd: Player
  9274. **/
  9275. void pc_crimson_marker_clear(struct map_session_data *sd) {
  9276. uint8 i;
  9277. if (!sd || !(&sd->c_marker) || !sd->c_marker.target)
  9278. return;
  9279. for (i = 0; i < MAX_SKILL_CRIMSON_MARKER; i++) {
  9280. struct block_list *bl = NULL;
  9281. if (sd->c_marker.target[i] && (bl = map_id2bl(sd->c_marker.target[i])))
  9282. status_change_end(bl,SC_C_MARKER,INVALID_TIMER);
  9283. }
  9284. }
  9285. /**
  9286. * Show version to player
  9287. * @param sd: Player
  9288. **/
  9289. void pc_show_version(struct map_session_data *sd) {
  9290. const char* svn = get_svn_revision();
  9291. char buf[CHAT_SIZE_MAX];
  9292. if( svn[0] != UNKNOWN_VERSION )
  9293. sprintf(buf,msg_txt(sd,1295),"SVN: r",svn); //rAthena Version SVN: r%s
  9294. else {
  9295. const char* git = get_git_hash();
  9296. if( git[0] != UNKNOWN_VERSION )
  9297. sprintf(buf,msg_txt(sd,1295),"Git Hash: ",git); //rAthena Version Git Hash: %s
  9298. else
  9299. sprintf(buf,"%s",msg_txt(sd,1296)); //Cannot determine SVN/Git version.
  9300. }
  9301. clif_displaymessage(sd->fd,buf);
  9302. }
  9303. /** [Cydh]
  9304. * Timer for bonus_script
  9305. * @param tid
  9306. * @param tick
  9307. * @param id
  9308. * @param data
  9309. **/
  9310. int pc_bonus_script_timer(int tid, unsigned int tick, int id, intptr_t data) {
  9311. uint8 i = (uint8)data;
  9312. struct map_session_data *sd;
  9313. sd = map_id2sd(id);
  9314. if (!sd) {
  9315. ShowDebug("pc_bonus_script_timer: Null pointer id: %d data: %d\n",id,data);
  9316. return 0;
  9317. }
  9318. if (i > MAX_PC_BONUS_SCRIPT|| !(&sd->bonus_script[i]) || !sd->bonus_script[i].script) {
  9319. ShowDebug("pc_bonus_script_timer: Invalid index %d\n",i);
  9320. return 0;
  9321. }
  9322. pc_bonus_script_remove(sd,i);
  9323. status_calc_pc(sd,false);
  9324. return 0;
  9325. }
  9326. /** [Cydh]
  9327. * Remove bonus_script data from sd (not deleting timer)
  9328. * @param sd: Target player
  9329. * @param i: Bonus script index
  9330. **/
  9331. void pc_bonus_script_remove(struct map_session_data *sd, uint8 i) {
  9332. if (!sd || i >= MAX_PC_BONUS_SCRIPT)
  9333. return;
  9334. script_free_code(sd->bonus_script[i].script);
  9335. memset(&sd->bonus_script[i].script,0,sizeof(sd->bonus_script[i].script));
  9336. sd->bonus_script[i].script_str[0] = '\0';
  9337. sd->bonus_script[i].tick = 0;
  9338. sd->bonus_script[i].tid = 0;
  9339. sd->bonus_script[i].flag = 0;
  9340. clif_status_change(&sd->bl,sd->bonus_script[i].icon,0,0,0,0,0);
  9341. sd->bonus_script[i].icon = SI_BLANK;
  9342. }
  9343. /** [Cydh]
  9344. * Check then clear all active timer(s) of bonus_script data from player based on reason
  9345. * @param sd: Target player
  9346. * @param flag: Reason to remove the bonus_script. e_bonus_script_flags or e_bonus_script_types
  9347. **/
  9348. void pc_bonus_script_clear(struct map_session_data *sd, uint16 flag) {
  9349. uint8 i, count = 0;
  9350. if (!sd)
  9351. return;
  9352. for (i = 0; i < MAX_PC_BONUS_SCRIPT; i++) {
  9353. if (&sd->bonus_script[i] && sd->bonus_script[i].script &&
  9354. (sd->bonus_script[i].flag&flag || //Remove bonus script based on e_bonus_script_flags
  9355. (sd->bonus_script[i].type && (
  9356. (flag&BONUS_FLAG_REM_BUFF && sd->bonus_script[i].type == 1) || //Remove bonus script based on buff type
  9357. (flag&BONUS_FLAG_REM_DEBUFF && sd->bonus_script[i].type == 2)) //Remove bonus script based on debuff type
  9358. )))
  9359. {
  9360. delete_timer(sd->bonus_script[i].tid,pc_bonus_script_timer);
  9361. pc_bonus_script_remove(sd,i);
  9362. count++;
  9363. }
  9364. }
  9365. if (count && !(flag&BONUS_FLAG_REM_ON_LOGOUT)) //Don't need to do this if log out
  9366. status_calc_pc(sd,false);
  9367. }
  9368. /** [Cydh]
  9369. * Gives/removes SC_BASILICA when player steps in/out the cell with 'cell_basilica'
  9370. * @param sd: Target player
  9371. */
  9372. void pc_cell_basilica(struct map_session_data *sd) {
  9373. nullpo_retv(sd);
  9374. if (!map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKBASILICA)) {
  9375. if (&sd->sc && sd->sc.data[SC_BASILICA])
  9376. status_change_end(&sd->bl,SC_BASILICA,INVALID_TIMER);
  9377. }
  9378. else if (!(&sd->sc) || !sd->sc.data[SC_BASILICA])
  9379. sc_start(&sd->bl,&sd->bl,SC_BASILICA,100,0,-1);
  9380. }
  9381. /** [Cydh]
  9382. * Get maximum specified parameter for specified class
  9383. * @param class_: sd->class
  9384. * @param sex: sd->status.sex
  9385. * @param flag: parameter will be checked
  9386. * @return max_param
  9387. */
  9388. short pc_maxparameter(struct map_session_data *sd, enum e_params param) {
  9389. int idx = -1, class_ = sd->class_;
  9390. if ((idx = pc_class2idx(pc_mapid2jobid(class_,sd->status.sex))) >= 0) {
  9391. short max_param = 0;
  9392. switch (param) {
  9393. case PARAM_STR: max_param = job_info[idx].max_param.str; break;
  9394. case PARAM_AGI: max_param = job_info[idx].max_param.agi; break;
  9395. case PARAM_VIT: max_param = job_info[idx].max_param.vit; break;
  9396. case PARAM_INT: max_param = job_info[idx].max_param.int_; break;
  9397. case PARAM_DEX: max_param = job_info[idx].max_param.dex; break;
  9398. case PARAM_LUK: max_param = job_info[idx].max_param.luk; break;
  9399. }
  9400. if (max_param > 0)
  9401. return max_param;
  9402. }
  9403. return ((class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO || (class_&MAPID_UPPERMASK) == MAPID_REBELLION) ? battle_config.max_extended_parameter :
  9404. ((class_&JOBL_THIRD) ? ((class_&JOBL_UPPER) ? battle_config.max_third_trans_parameter : ((class_&JOBL_BABY) ? battle_config.max_baby_third_parameter : battle_config.max_third_parameter)) :
  9405. ((class_&JOBL_BABY) ? battle_config.max_baby_parameter :
  9406. ((class_&JOBL_UPPER) ? battle_config.max_trans_parameter : battle_config.max_parameter)));
  9407. }
  9408. /*==========================================
  9409. * pc Init/Terminate
  9410. *------------------------------------------*/
  9411. void do_final_pc(void) {
  9412. db_destroy(itemcd_db);
  9413. do_final_pc_groups();
  9414. return;
  9415. }
  9416. int do_init_pc(void) {
  9417. itemcd_db = idb_alloc(DB_OPT_RELEASE_DATA);
  9418. pc_readdb();
  9419. pc_read_motd(); // Read MOTD [Valaris]
  9420. add_timer_func_list(pc_invincible_timer, "pc_invincible_timer");
  9421. add_timer_func_list(pc_eventtimer, "pc_eventtimer");
  9422. add_timer_func_list(pc_inventory_rental_end, "pc_inventory_rental_end");
  9423. add_timer_func_list(pc_calc_pvprank_timer, "pc_calc_pvprank_timer");
  9424. add_timer_func_list(pc_autosave, "pc_autosave");
  9425. add_timer_func_list(pc_spiritball_timer, "pc_spiritball_timer");
  9426. add_timer_func_list(pc_follow_timer, "pc_follow_timer");
  9427. add_timer_func_list(pc_endautobonus, "pc_endautobonus");
  9428. add_timer_func_list(pc_talisman_timer, "pc_talisman_timer");
  9429. add_timer(gettick() + autosave_interval, pc_autosave, 0, 0);
  9430. // 0=day, 1=night [Yor]
  9431. night_flag = battle_config.night_at_start ? 1 : 0;
  9432. if (battle_config.day_duration > 0 && battle_config.night_duration > 0) {
  9433. int day_duration = battle_config.day_duration;
  9434. int night_duration = battle_config.night_duration;
  9435. // add night/day timer [Yor]
  9436. add_timer_func_list(map_day_timer, "map_day_timer");
  9437. add_timer_func_list(map_night_timer, "map_night_timer");
  9438. day_timer_tid = add_timer_interval(gettick() + (night_flag ? 0 : day_duration) + night_duration, map_day_timer, 0, 0, day_duration + night_duration);
  9439. night_timer_tid = add_timer_interval(gettick() + day_duration + (night_flag ? night_duration : 0), map_night_timer, 0, 0, day_duration + night_duration);
  9440. }
  9441. do_init_pc_groups();
  9442. return 0;
  9443. }