pc.c 320 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669
  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
  387. && sd->sc.option&OPTION_MOUNTING ) {
  388. pc_setoption(sd, sd->sc.option&~OPTION_MOUNTING);
  389. }
  390. clif_rental_expired(sd->fd, i, sd->status.inventory[i].nameid);
  391. pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
  392. } else {
  393. expire_tick = (unsigned int)(sd->status.inventory[i].expire_time - time(NULL)) * 1000;
  394. clif_rental_time(sd->fd, sd->status.inventory[i].nameid, (int)(expire_tick / 1000));
  395. next_tick = min(expire_tick, next_tick);
  396. c++;
  397. }
  398. }
  399. 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
  400. sd->rental_timer = add_timer(gettick() + min(next_tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
  401. else
  402. sd->rental_timer = INVALID_TIMER;
  403. }
  404. void pc_inventory_rental_add(struct map_session_data *sd, int seconds)
  405. {
  406. int tick = seconds * 1000;
  407. if( sd == NULL )
  408. return;
  409. if( sd->rental_timer != INVALID_TIMER )
  410. {
  411. const struct TimerData * td;
  412. td = get_timer(sd->rental_timer);
  413. if( DIFF_TICK(td->tick, gettick()) > tick )
  414. { // Update Timer as this one ends first than the current one
  415. pc_inventory_rental_clear(sd);
  416. sd->rental_timer = add_timer(gettick() + tick, pc_inventory_rental_end, sd->bl.id, 0);
  417. }
  418. }
  419. else
  420. sd->rental_timer = add_timer(gettick() + min(tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
  421. }
  422. /**
  423. * Determines if player can give / drop / trade / vend items
  424. */
  425. bool pc_can_give_items(struct map_session_data *sd)
  426. {
  427. return pc_has_permission(sd, PC_PERM_TRADE);
  428. }
  429. /**
  430. * Determines if player can give / drop / trade / vend bounded items
  431. */
  432. bool pc_can_give_bounded_items(struct map_session_data *sd)
  433. {
  434. return pc_has_permission(sd, PC_PERM_TRADE_BOUNDED);
  435. }
  436. /*==========================================
  437. * prepares character for saving.
  438. *------------------------------------------*/
  439. int pc_makesavestatus(struct map_session_data *sd)
  440. {
  441. nullpo_ret(sd);
  442. if(!battle_config.save_clothcolor)
  443. sd->status.clothes_color=0;
  444. //Only copy the Cart/Peco/Falcon options, the rest are handled via
  445. //status change load/saving. [Skotlex]
  446. #ifdef NEW_CARTS
  447. sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR|OPTION_MOUNTING);
  448. #else
  449. sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_CART|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR|OPTION_MOUNTING);
  450. #endif
  451. if (sd->sc.data[SC_JAILED])
  452. { //When Jailed, do not move last point.
  453. if(pc_isdead(sd)){
  454. pc_setrestartvalue(sd,0);
  455. } else {
  456. sd->status.hp = sd->battle_status.hp;
  457. sd->status.sp = sd->battle_status.sp;
  458. }
  459. sd->status.last_point.map = sd->mapindex;
  460. sd->status.last_point.x = sd->bl.x;
  461. sd->status.last_point.y = sd->bl.y;
  462. return 0;
  463. }
  464. if(pc_isdead(sd)){
  465. pc_setrestartvalue(sd,0);
  466. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  467. } else {
  468. sd->status.hp = sd->battle_status.hp;
  469. sd->status.sp = sd->battle_status.sp;
  470. sd->status.last_point.map = sd->mapindex;
  471. sd->status.last_point.x = sd->bl.x;
  472. sd->status.last_point.y = sd->bl.y;
  473. }
  474. if(map[sd->bl.m].flag.nosave){
  475. struct map_data *m=&map[sd->bl.m];
  476. if(m->save.map)
  477. memcpy(&sd->status.last_point,&m->save,sizeof(sd->status.last_point));
  478. else
  479. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  480. }
  481. return 0;
  482. }
  483. /*==========================================
  484. * Off init ? Connection?
  485. *------------------------------------------*/
  486. 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)
  487. {
  488. nullpo_ret(sd);
  489. sd->bl.id = account_id;
  490. sd->status.account_id = account_id;
  491. sd->status.char_id = char_id;
  492. sd->status.sex = sex;
  493. sd->login_id1 = login_id1;
  494. sd->login_id2 = 0; // at this point, we can not know the value :(
  495. sd->client_tick = client_tick;
  496. sd->state.active = 0; //to be set to 1 after player is fully authed and loaded.
  497. sd->bl.type = BL_PC;
  498. sd->canlog_tick = gettick();
  499. //Required to prevent homunculus copuing a base speed of 0.
  500. sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
  501. return 0;
  502. }
  503. int pc_equippoint(struct map_session_data *sd,int n){
  504. int ep = 0;
  505. nullpo_ret(sd);
  506. if(!sd->inventory_data[n])
  507. return 0;
  508. if (!itemdb_isequip2(sd->inventory_data[n]))
  509. return 0; //Not equippable by players.
  510. ep = sd->inventory_data[n]->equip;
  511. if(sd->inventory_data[n]->look == W_DAGGER ||
  512. sd->inventory_data[n]->look == W_1HSWORD ||
  513. sd->inventory_data[n]->look == W_1HAXE) {
  514. if(ep == EQP_HAND_R && (pc_checkskill(sd,AS_LEFT) > 0 || (sd->class_&MAPID_UPPERMASK) == MAPID_ASSASSIN ||
  515. (sd->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO))//Kagerou and Oboro can dual wield daggers. [Rytech]
  516. return EQP_ARMS;
  517. }
  518. return ep;
  519. }
  520. /**
  521. * Fill inventory_data with struct *item_data trough inventory (fill with struct *item)
  522. * @param sd : player session
  523. * @return 0 sucess, 1:invalid sd
  524. */
  525. int pc_setinventorydata(struct map_session_data *sd)
  526. {
  527. uint8 i;
  528. nullpo_retr(1,sd);
  529. for(i=0;i<MAX_INVENTORY;i++) {
  530. uint16 id = sd->status.inventory[i].nameid;
  531. sd->inventory_data[i] = id?itemdb_search(id):NULL;
  532. }
  533. return 0;
  534. }
  535. int pc_calcweapontype(struct map_session_data *sd)
  536. {
  537. nullpo_ret(sd);
  538. // single-hand
  539. if(sd->weapontype2 == W_FIST) {
  540. sd->status.weapon = sd->weapontype1;
  541. return 1;
  542. }
  543. if(sd->weapontype1 == W_FIST) {
  544. sd->status.weapon = sd->weapontype2;
  545. return 1;
  546. }
  547. // dual-wield
  548. sd->status.weapon = 0;
  549. switch (sd->weapontype1){
  550. case W_DAGGER:
  551. switch (sd->weapontype2) {
  552. case W_DAGGER: sd->status.weapon = W_DOUBLE_DD; break;
  553. case W_1HSWORD: sd->status.weapon = W_DOUBLE_DS; break;
  554. case W_1HAXE: sd->status.weapon = W_DOUBLE_DA; break;
  555. }
  556. break;
  557. case W_1HSWORD:
  558. switch (sd->weapontype2) {
  559. case W_DAGGER: sd->status.weapon = W_DOUBLE_DS; break;
  560. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SS; break;
  561. case W_1HAXE: sd->status.weapon = W_DOUBLE_SA; break;
  562. }
  563. break;
  564. case W_1HAXE:
  565. switch (sd->weapontype2) {
  566. case W_DAGGER: sd->status.weapon = W_DOUBLE_DA; break;
  567. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SA; break;
  568. case W_1HAXE: sd->status.weapon = W_DOUBLE_AA; break;
  569. }
  570. }
  571. // unknown, default to right hand type
  572. if (!sd->status.weapon)
  573. sd->status.weapon = sd->weapontype1;
  574. return 2;
  575. }
  576. int pc_setequipindex(struct map_session_data *sd)
  577. {
  578. int i,j;
  579. nullpo_ret(sd);
  580. for(i=0;i<EQI_MAX;i++)
  581. sd->equip_index[i] = -1;
  582. for(i=0;i<MAX_INVENTORY;i++) {
  583. if(sd->status.inventory[i].nameid <= 0)
  584. continue;
  585. if(sd->status.inventory[i].equip) {
  586. for(j=0;j<EQI_MAX;j++)
  587. if(sd->status.inventory[i].equip & equip_pos[j])
  588. sd->equip_index[j] = i;
  589. if(sd->status.inventory[i].equip & EQP_HAND_R)
  590. {
  591. if(sd->inventory_data[i])
  592. sd->weapontype1 = sd->inventory_data[i]->look;
  593. else
  594. sd->weapontype1 = 0;
  595. }
  596. if( sd->status.inventory[i].equip & EQP_HAND_L )
  597. {
  598. if( sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON )
  599. sd->weapontype2 = sd->inventory_data[i]->look;
  600. else
  601. sd->weapontype2 = 0;
  602. }
  603. }
  604. }
  605. pc_calcweapontype(sd);
  606. return 0;
  607. }
  608. //static int pc_isAllowedCardOn(struct map_session_data *sd,int s,int eqindex,int flag)
  609. //{
  610. // int i;
  611. // struct item *item = &sd->status.inventory[eqindex];
  612. // struct item_data *data;
  613. //
  614. // //Crafted/made/hatched items.
  615. // if (itemdb_isspecial(item->card[0]))
  616. // return 1;
  617. //
  618. // /* scan for enchant armor gems */
  619. // if( item->card[MAX_SLOTS - 1] && s < MAX_SLOTS - 1 )
  620. // s = MAX_SLOTS - 1;
  621. //
  622. // ARR_FIND( 0, s, i, item->card[i] && (data = itemdb_exists(item->card[i])) != NULL && data->flag.no_equip&flag );
  623. // return( i < s ) ? 0 : 1;
  624. //}
  625. /**
  626. * Check if an item is equiped by player
  627. * (Check if the itemid is equiped then search if that match the index in inventory (should be))
  628. * @param sd : player session
  629. * @param nameid : itemid
  630. * @return 1:yes, 0:no
  631. */
  632. bool pc_isequipped(struct map_session_data *sd, int nameid)
  633. {
  634. uint8 i;
  635. for( i = 0; i < EQI_MAX; i++ )
  636. {
  637. uint8 index = sd->equip_index[i], j;
  638. if( index < 0 ) continue;
  639. if( i == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue;
  640. if( i == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index ) continue;
  641. if( i == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index) ) continue;
  642. if( !sd->inventory_data[index] )
  643. continue;
  644. if( sd->inventory_data[index]->nameid == nameid )
  645. return true;
  646. for( j = 0; j < sd->inventory_data[index]->slot; j++ ){
  647. if( sd->status.inventory[index].card[j] == nameid )
  648. return true;
  649. }
  650. }
  651. return false;
  652. }
  653. bool pc_can_Adopt(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd )
  654. {
  655. if( !p1_sd || !p2_sd || !b_sd )
  656. return false;
  657. if( b_sd->status.father || b_sd->status.mother || b_sd->adopt_invite )
  658. return false; // already adopted baby / in adopt request
  659. if( !p1_sd->status.partner_id || !p1_sd->status.party_id || p1_sd->status.party_id != b_sd->status.party_id )
  660. return false; // You need to be married and in party with baby to adopt
  661. if( p1_sd->status.partner_id != p2_sd->status.char_id || p2_sd->status.partner_id != p1_sd->status.char_id )
  662. return false; // Not married, wrong married
  663. if( p2_sd->status.party_id != p1_sd->status.party_id )
  664. return false; // Both parents need to be in the same party
  665. // Parents need to have their ring equipped
  666. if( !pc_isequipped(p1_sd, WEDDING_RING_M) && !pc_isequipped(p1_sd, WEDDING_RING_F) )
  667. return false;
  668. if( !pc_isequipped(p2_sd, WEDDING_RING_M) && !pc_isequipped(p2_sd, WEDDING_RING_F) )
  669. return false;
  670. // Already adopted a baby
  671. if( p1_sd->status.child || p2_sd->status.child ) {
  672. clif_Adopt_reply(p1_sd, 0);
  673. return false;
  674. }
  675. // Parents need at least lvl 70 to adopt
  676. if( p1_sd->status.base_level < 70 || p2_sd->status.base_level < 70 ) {
  677. clif_Adopt_reply(p1_sd, 1);
  678. return false;
  679. }
  680. if( b_sd->status.partner_id ) {
  681. clif_Adopt_reply(p1_sd, 2);
  682. return false;
  683. }
  684. if( !( ( b_sd->status.class_ >= JOB_NOVICE && b_sd->status.class_ <= JOB_THIEF ) || b_sd->status.class_ == JOB_SUPER_NOVICE ) )
  685. return false;
  686. return true;
  687. }
  688. /*==========================================
  689. * Adoption Process
  690. *------------------------------------------*/
  691. bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
  692. {
  693. int job, joblevel;
  694. unsigned int jobexp;
  695. if( !pc_can_Adopt(p1_sd, p2_sd, b_sd) )
  696. return false;
  697. // Preserve current job levels and progress
  698. joblevel = b_sd->status.job_level;
  699. jobexp = b_sd->status.job_exp;
  700. job = pc_mapid2jobid(b_sd->class_|JOBL_BABY, b_sd->status.sex);
  701. if( job != -1 && !pc_jobchange(b_sd, job, 0) )
  702. { // Success, proceed to configure parents and baby skills
  703. p1_sd->status.child = b_sd->status.char_id;
  704. p2_sd->status.child = b_sd->status.char_id;
  705. b_sd->status.father = p1_sd->status.char_id;
  706. b_sd->status.mother = p2_sd->status.char_id;
  707. // Restore progress
  708. b_sd->status.job_level = joblevel;
  709. clif_updatestatus(b_sd, SP_JOBLEVEL);
  710. b_sd->status.job_exp = jobexp;
  711. clif_updatestatus(b_sd, SP_JOBEXP);
  712. // Baby Skills
  713. pc_skill(b_sd, WE_BABY, 1, 0);
  714. pc_skill(b_sd, WE_CALLPARENT, 1, 0);
  715. // Parents Skills
  716. pc_skill(p1_sd, WE_CALLBABY, 1, 0);
  717. pc_skill(p2_sd, WE_CALLBABY, 1, 0);
  718. return true;
  719. }
  720. return false; // Job Change Fail
  721. }
  722. /*==========================================
  723. * Check if player can use/equip selected item. Used by pc_isUseitem and pc_isequip
  724. Returns:
  725. false : Cannot use/equip
  726. true : Can use/equip
  727. * Credits:
  728. [Inkfish] for first idea
  729. [Haru] for third-classes extension
  730. [Cydh] finishing :D
  731. *------------------------------------------*/
  732. static bool pc_isItemClass (struct map_session_data *sd, struct item_data* item) {
  733. while (1) {
  734. if (item->class_upper&ITEMJ_NORMAL && !(sd->class_&(JOBL_UPPER|JOBL_THIRD|JOBL_BABY))) //normal classes (no upper, no baby, no third)
  735. break;
  736. #ifndef RENEWAL
  737. //allow third classes to use trans. class items
  738. if (item->class_upper&ITEMJ_UPPER && sd->class_&(JOBL_UPPER|JOBL_THIRD)) //trans. classes
  739. break;
  740. //third-baby classes can use same item too
  741. if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY) //baby classes
  742. break;
  743. //don't need to decide specific rules for third-classes?
  744. //items for third classes can be used for all third classes
  745. if (item->class_upper&(ITEMJ_THIRD|ITEMJ_THIRD_TRANS|ITEMJ_THIRD_BABY) && sd->class_&JOBL_THIRD)
  746. break;
  747. #else
  748. //trans. classes (exl. third-trans.)
  749. if (item->class_upper&ITEMJ_UPPER && sd->class_&JOBL_UPPER && !(sd->class_&JOBL_THIRD))
  750. break;
  751. //baby classes (exl. third-baby)
  752. if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY && !(sd->class_&JOBL_THIRD))
  753. break;
  754. //third classes (exl. third-trans. and baby-third)
  755. if (item->class_upper&ITEMJ_THIRD && sd->class_&JOBL_THIRD && !(sd->class_&(JOBL_UPPER|JOBL_BABY)))
  756. break;
  757. //trans-third classes
  758. if (item->class_upper&ITEMJ_THIRD_TRANS && sd->class_&JOBL_THIRD && sd->class_&JOBL_UPPER)
  759. break;
  760. //third-baby classes
  761. if (item->class_upper&ITEMJ_THIRD_BABY && sd->class_&JOBL_THIRD && sd->class_&JOBL_BABY)
  762. break;
  763. #endif
  764. return false;
  765. }
  766. return true;
  767. }
  768. /*=================================================
  769. * Checks if the player can equip the item at index n in inventory.
  770. * Returns 0 (no) or 1 (yes).
  771. *------------------------------------------------*/
  772. int pc_isequip(struct map_session_data *sd,int n)
  773. {
  774. struct item_data *item;
  775. nullpo_ret(sd);
  776. item = sd->inventory_data[n];
  777. if(pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT))
  778. return 1;
  779. if(item == NULL)
  780. return 0;
  781. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  782. return 0;
  783. #ifdef RENEWAL
  784. if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
  785. return 0;
  786. #endif
  787. if(item->sex != 2 && sd->status.sex != item->sex)
  788. return 0;
  789. if (sd->sc.count) {
  790. if(item->equip & EQP_ARMS && item->type == IT_WEAPON && sd->sc.data[SC_STRIPWEAPON]) // Also works with left-hand weapons [DracoRPG]
  791. return 0;
  792. if(item->equip & EQP_SHIELD && item->type == IT_ARMOR && sd->sc.data[SC_STRIPSHIELD])
  793. return 0;
  794. if(item->equip & EQP_ARMOR && sd->sc.data[SC_STRIPARMOR])
  795. return 0;
  796. if(item->equip & EQP_HEAD_TOP && sd->sc.data[SC_STRIPHELM])
  797. return 0;
  798. if(item->equip & EQP_ACC && sd->sc.data[SC__STRIPACCESSORY])
  799. return 0;
  800. if(item->equip && sd->sc.data[SC_KYOUGAKU])
  801. return 0;
  802. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_SUPERNOVICE) {
  803. //Spirit of Super Novice equip bonuses. [Skotlex]
  804. if (sd->status.base_level > 90 && item->equip & EQP_HELM)
  805. return 1; //Can equip all helms
  806. if (sd->status.base_level > 96 && item->equip & EQP_ARMS && item->type == IT_WEAPON)
  807. switch(item->look) { //In weapons, the look determines type of weapon.
  808. case W_DAGGER: //Level 4 Knives are equippable.. this means all knives, I'd guess?
  809. case W_1HSWORD: //All 1H swords
  810. case W_1HAXE: //All 1H Axes
  811. case W_MACE: //All 1H Maces
  812. case W_STAFF: //All 1H Staves
  813. return 1;
  814. }
  815. }
  816. }
  817. //fail to equip if item is restricted
  818. if (!battle_config.allow_equip_restricted_item && itemdb_isNoEquip(item, sd->bl.m))
  819. return 0;
  820. //Not equipable by class. [Skotlex]
  821. if (!(1<<(sd->class_&MAPID_BASEMASK)&item->class_base[(sd->class_&JOBL_2_1)?1:((sd->class_&JOBL_2_2)?2:0)]))
  822. return 0;
  823. if (!pc_isItemClass(sd,item))
  824. return 0;
  825. return 1;
  826. }
  827. /*==========================================
  828. * No problem with the session id
  829. * set the status that has been sent from char server
  830. *------------------------------------------*/
  831. 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)
  832. {
  833. int i;
  834. #ifdef BOUND_ITEMS
  835. int j;
  836. int idxlist[MAX_INVENTORY];
  837. #endif
  838. unsigned long tick = gettick();
  839. uint32 ip = session[sd->fd]->client_addr;
  840. sd->login_id2 = login_id2;
  841. sd->group_id = group_id;
  842. /* load user permissions */
  843. pc_group_pc_load(sd);
  844. memcpy(&sd->status, st, sizeof(*st));
  845. if (st->sex != sd->status.sex) {
  846. clif_authfail_fd(sd->fd, 0);
  847. return false;
  848. }
  849. //Set the map-server used job id. [Skotlex]
  850. i = pc_jobid2mapid(sd->status.class_);
  851. if (i == -1) { //Invalid class?
  852. 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);
  853. sd->status.class_ = JOB_NOVICE;
  854. sd->class_ = MAPID_NOVICE;
  855. } else
  856. sd->class_ = i;
  857. // Checks and fixes to character status data, that are required
  858. // in case of configuration change or stuff, which cannot be
  859. // checked on char-server.
  860. sd->status.hair = cap_value(sd->status.hair,MIN_HAIR_STYLE,MAX_HAIR_STYLE);
  861. sd->status.hair_color = cap_value(sd->status.hair_color,MIN_HAIR_COLOR,MAX_HAIR_COLOR);
  862. sd->status.clothes_color = cap_value(sd->status.clothes_color,MIN_CLOTH_COLOR,MAX_CLOTH_COLOR);
  863. //Initializations to null/0 unneeded since map_session_data was filled with 0 upon allocation.
  864. if(!sd->status.hp) pc_setdead(sd);
  865. sd->state.connect_new = 1;
  866. sd->followtimer = INVALID_TIMER; // [MouseJstr]
  867. sd->invincible_timer = INVALID_TIMER;
  868. sd->npc_timer_id = INVALID_TIMER;
  869. sd->pvp_timer = INVALID_TIMER;
  870. #ifdef SECURE_NPCTIMEOUT
  871. // Initialize to defaults/expected
  872. sd->npc_idle_timer = INVALID_TIMER;
  873. sd->npc_idle_tick = tick;
  874. sd->npc_idle_type = NPCT_INPUT;
  875. #endif
  876. sd->canuseitem_tick = tick;
  877. sd->canusecashfood_tick = tick;
  878. sd->canequip_tick = tick;
  879. sd->cantalk_tick = tick;
  880. sd->canskill_tick = tick;
  881. sd->cansendmail_tick = tick;
  882. for(i = 0; i < MAX_SKILL_LEVEL; i++)
  883. sd->spirit_timer[i] = INVALID_TIMER;
  884. for(i = 0; i < ARRAYLENGTH(sd->autobonus); i++)
  885. sd->autobonus[i].active = INVALID_TIMER;
  886. for(i = 0; i < ARRAYLENGTH(sd->autobonus2); i++)
  887. sd->autobonus2[i].active = INVALID_TIMER;
  888. for(i = 0; i < ARRAYLENGTH(sd->autobonus3); i++)
  889. sd->autobonus3[i].active = INVALID_TIMER;
  890. if (battle_config.item_auto_get)
  891. sd->state.autoloot = 10000;
  892. if (battle_config.disp_experience)
  893. sd->state.showexp = 1;
  894. if (battle_config.disp_zeny)
  895. sd->state.showzeny = 1;
  896. if (!(battle_config.display_skill_fail&2))
  897. sd->state.showdelay = 1;
  898. pc_setinventorydata(sd);
  899. pc_setequipindex(sd);
  900. if( sd->status.option&OPTION_INVISIBLE && !pc_can_use_command( sd, "hide", COMMAND_ATCOMMAND ) ){
  901. sd->status.option &= ~OPTION_INVISIBLE;
  902. }
  903. status_change_init(&sd->bl);
  904. sd->sc.option = sd->status.option; //This is the actual option used in battle.
  905. //Set here because we need the inventory data for weapon sprite parsing.
  906. status_set_viewdata(&sd->bl, sd->status.class_);
  907. unit_dataset(&sd->bl);
  908. sd->guild_x = -1;
  909. sd->guild_y = -1;
  910. // Event Timers
  911. for( i = 0; i < MAX_EVENTTIMER; i++ )
  912. sd->eventtimer[i] = INVALID_TIMER;
  913. // Rental Timer
  914. sd->rental_timer = INVALID_TIMER;
  915. for( i = 0; i < 3; i++ )
  916. sd->hate_mob[i] = -1;
  917. //warp player
  918. if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != 0) {
  919. 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);
  920. // try warping to a default map instead (church graveyard)
  921. if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != 0) {
  922. // if we fail again
  923. clif_authfail_fd(sd->fd, 0);
  924. return false;
  925. }
  926. }
  927. clif_authok(sd);
  928. //Prevent S. Novices from getting the no-death bonus just yet. [Skotlex]
  929. sd->die_counter=-1;
  930. //display login notice
  931. ShowInfo("'"CL_WHITE"%s"CL_RESET"' logged in."
  932. " (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"',"
  933. " Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%d.%d.%d.%d"CL_RESET"',"
  934. " Group '"CL_WHITE"%d"CL_RESET"').\n",
  935. sd->status.name, sd->status.account_id, sd->status.char_id,
  936. sd->packet_ver, CONVIP(ip), sd->group_id);
  937. // Send friends list
  938. clif_friendslist_send(sd);
  939. if( !changing_mapservers ) {
  940. if (battle_config.display_version == 1)
  941. pc_show_version(sd);
  942. // Message of the Day [Valaris]
  943. for(i=0; i < MOTD_LINE_SIZE && motd_text[i][0]; i++) {
  944. if (battle_config.motd_type)
  945. clif_disp_onlyself(sd,motd_text[i],strlen(motd_text[i]));
  946. else
  947. clif_displaymessage(sd->fd, motd_text[i]);
  948. }
  949. // message of the limited time of the account
  950. if (expiration_time != 0) { // don't display if it's unlimited or unknow value
  951. char tmpstr[1024];
  952. strftime(tmpstr, sizeof(tmpstr) - 1, msg_txt(sd,501), localtime(&expiration_time)); // "Your account time limit is: %d-%m-%Y %H:%M:%S."
  953. clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
  954. }
  955. /**
  956. * Fixes login-without-aura glitch (the screen won't blink at this point, don't worry :P)
  957. **/
  958. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  959. }
  960. /**
  961. * Check if player have any item cooldowns on
  962. **/
  963. pc_itemcd_do(sd,true);
  964. #ifdef BOUND_ITEMS
  965. // Party bound item check
  966. if(sd->status.party_id == 0 && (j = pc_bound_chk(sd,3,idxlist))) { // Party was deleted while character offline
  967. for(i=0;i<j;i++)
  968. pc_delitem(sd,idxlist[i],sd->status.inventory[idxlist[i]].amount,0,1,LOG_TYPE_OTHER);
  969. }
  970. #endif
  971. // Player has not yet received the CashShop list
  972. sd->status.cashshop_sent = false;
  973. // Request all registries (auth is considered completed whence they arrive)
  974. intif_request_registry(sd,7);
  975. return true;
  976. }
  977. /*==========================================
  978. * Closes a connection because it failed to be authenticated from the char server.
  979. *------------------------------------------*/
  980. void pc_authfail(struct map_session_data *sd)
  981. {
  982. clif_authfail_fd(sd->fd, 0);
  983. return;
  984. }
  985. /**
  986. * Player register a bl as hatred
  987. * @param sd : player session
  988. * @param pos : hate position [0;2]
  989. * @param bl : target bl
  990. * @return false:failed, true:success
  991. */
  992. bool pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl)
  993. {
  994. int class_;
  995. if (!sd || !bl || pos < 0 || pos > 2)
  996. return false;
  997. if (sd->hate_mob[pos] != -1)
  998. { //Can't change hate targets.
  999. clif_hate_info(sd, pos, sd->hate_mob[pos], 0); //Display current
  1000. return false;
  1001. }
  1002. class_ = status_get_class(bl);
  1003. if (!pcdb_checkid(class_)) {
  1004. unsigned int max_hp = status_get_max_hp(bl);
  1005. if ((pos == 1 && max_hp < 6000) || (pos == 2 && max_hp < 20000))
  1006. return false;
  1007. if (pos != status_get_size(bl))
  1008. return false; //Wrong size
  1009. }
  1010. sd->hate_mob[pos] = class_;
  1011. pc_setglobalreg(sd,sg_info[pos].hate_var,class_+1);
  1012. clif_hate_info(sd, pos, class_, 1);
  1013. return true;
  1014. }
  1015. /*==========================================
  1016. * Invoked once after the char/account/account2 registry variables are received. [Skotlex]
  1017. *------------------------------------------*/
  1018. int pc_reg_received(struct map_session_data *sd)
  1019. {
  1020. uint8 i;
  1021. sd->change_level_2nd = pc_readglobalreg(sd,"jobchange_level");
  1022. sd->change_level_3rd = pc_readglobalreg(sd,"jobchange_level_3rd");
  1023. sd->die_counter = pc_readglobalreg(sd,"PC_DIE_COUNTER");
  1024. sd->langtype = pc_readaccountreg(sd,"#langtype");
  1025. if(msg_checklangtype(sd->langtype,true)<0) sd->langtype=0; //invalid langtype reset to default
  1026. // Cash shop
  1027. sd->cashPoints = pc_readaccountreg(sd,"#CASHPOINTS");
  1028. sd->kafraPoints = pc_readaccountreg(sd,"#KAFRAPOINTS");
  1029. // Cooking Exp
  1030. sd->cook_mastery = pc_readglobalreg(sd,"COOK_MASTERY");
  1031. if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON )
  1032. { // Better check for class rather than skill to prevent "skill resets" from unsetting this
  1033. sd->mission_mobid = pc_readglobalreg(sd,"TK_MISSION_ID");
  1034. sd->mission_count = pc_readglobalreg(sd,"TK_MISSION_COUNT");
  1035. }
  1036. //SG map and mob read [Komurka]
  1037. for(i=0;i<MAX_PC_FEELHATE;i++) //for now - someone need to make reading from txt/sql
  1038. {
  1039. uint16 j;
  1040. if ((j = pc_readglobalreg(sd,sg_info[i].feel_var))!=0) {
  1041. sd->feel_map[i].index = j;
  1042. sd->feel_map[i].m = map_mapindex2mapid(j);
  1043. } else {
  1044. sd->feel_map[i].index = 0;
  1045. sd->feel_map[i].m = -1;
  1046. }
  1047. sd->hate_mob[i] = pc_readglobalreg(sd,sg_info[i].hate_var)-1;
  1048. }
  1049. if ((i = pc_checkskill(sd,RG_PLAGIARISM)) > 0) {
  1050. sd->cloneskill_idx = skill_get_index(pc_readglobalreg(sd,SKILL_VAR_PLAGIARISM));
  1051. if (sd->cloneskill_idx >= 0) {
  1052. sd->status.skill[sd->cloneskill_idx].id = pc_readglobalreg(sd,SKILL_VAR_PLAGIARISM);
  1053. sd->status.skill[sd->cloneskill_idx].lv = pc_readglobalreg(sd,SKILL_VAR_PLAGIARISM_LV);
  1054. if (sd->status.skill[sd->cloneskill_idx].lv > i)
  1055. sd->status.skill[sd->cloneskill_idx].lv = i;
  1056. sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
  1057. }
  1058. }
  1059. if ((i = pc_checkskill(sd,SC_REPRODUCE)) > 0) {
  1060. sd->reproduceskill_idx = skill_get_index(pc_readglobalreg(sd,SKILL_VAR_REPRODUCE));
  1061. if (sd->reproduceskill_idx >= 0) {
  1062. sd->status.skill[sd->reproduceskill_idx].id = pc_readglobalreg(sd,SKILL_VAR_REPRODUCE);
  1063. sd->status.skill[sd->reproduceskill_idx].lv = pc_readglobalreg(sd,SKILL_VAR_REPRODUCE_LV);
  1064. if (i < sd->status.skill[sd->reproduceskill_idx].lv)
  1065. sd->status.skill[sd->reproduceskill_idx].lv = i;
  1066. sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
  1067. }
  1068. }
  1069. //Weird... maybe registries were reloaded?
  1070. if (sd->state.active)
  1071. return 0;
  1072. sd->state.active = 1;
  1073. if (sd->status.party_id)
  1074. party_member_joined(sd);
  1075. if (sd->status.guild_id)
  1076. guild_member_joined(sd);
  1077. // pet
  1078. if (sd->status.pet_id > 0)
  1079. intif_request_petdata(sd->status.account_id, sd->status.char_id, sd->status.pet_id);
  1080. // Homunculus [albator]
  1081. if( sd->status.hom_id > 0 )
  1082. intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id);
  1083. if( sd->status.mer_id > 0 )
  1084. intif_mercenary_request(sd->status.mer_id, sd->status.char_id);
  1085. if( sd->status.ele_id > 0 )
  1086. intif_elemental_request(sd->status.ele_id, sd->status.char_id);
  1087. map_addiddb(&sd->bl);
  1088. map_delnickdb(sd->status.char_id, sd->status.name);
  1089. if (!chrif_auth_finished(sd))
  1090. ShowError("pc_reg_received: Failed to properly remove player %d:%d from logging db!\n", sd->status.account_id, sd->status.char_id);
  1091. pc_check_available_item(sd); // Check for invalid(ated) items.
  1092. pc_load_combo(sd);
  1093. status_calc_pc(sd,1);
  1094. chrif_scdata_request(sd->status.account_id, sd->status.char_id);
  1095. chrif_skillcooldown_request(sd->status.account_id, sd->status.char_id);
  1096. chrif_bsdata_request(sd->status.char_id);
  1097. sd->storage_size = MIN_STORAGE; //default to min
  1098. if(battle_config.feature_banking)
  1099. chrif_req_login_operation(sd->status.account_id, sd->status.name, 7, 0, 1, 0); //request Bank data
  1100. #ifdef VIP_ENABLE
  1101. sd->vip.time = 0;
  1102. sd->vip.enabled = 0;
  1103. chrif_req_login_operation(sd->status.account_id, sd->status.name, 6, 0, 1, 0); // request VIP informations
  1104. #endif
  1105. intif_Mail_requestinbox(sd->status.char_id, 0); // MAIL SYSTEM - Request Mail Inbox
  1106. intif_request_questlog(sd);
  1107. if (sd->state.connect_new == 0 && sd->fd) { //Character already loaded map! Gotta trigger LoadEndAck manually.
  1108. sd->state.connect_new = 1;
  1109. clif_parse_LoadEndAck(sd->fd, sd);
  1110. }
  1111. pc_inventory_rentals(sd);
  1112. if( sd->sc.option&OPTION_INVISIBLE ) {
  1113. sd->vd.class_ = INVISIBLE_CLASS;
  1114. clif_displaymessage( sd->fd, msg_txt( sd, 11 ) ); // Invisible: On
  1115. // decrement the number of pvp players on the map
  1116. map[sd->bl.m].users_pvp--;
  1117. if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER ){
  1118. // unregister the player for ranking
  1119. delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  1120. sd->pvp_timer = INVALID_TIMER;
  1121. }
  1122. clif_changeoption( &sd->bl );
  1123. }
  1124. return 1;
  1125. }
  1126. static int pc_calc_skillpoint(struct map_session_data* sd)
  1127. {
  1128. uint16 i, skill_point=0;
  1129. nullpo_ret(sd);
  1130. for(i=1;i<MAX_SKILL;i++){
  1131. uint8 skill_lv;
  1132. if( (skill_lv = pc_checkskill(sd,i)) > 0) {
  1133. uint16 inf2 = skill_get_inf2(i);
  1134. if((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  1135. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) //Do not count wedding/link skills. [Skotlex]
  1136. ) {
  1137. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  1138. skill_point += skill_lv;
  1139. else
  1140. if(sd->status.skill[i].flag == SKILL_FLAG_REPLACED_LV_0)
  1141. skill_point += (sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0);
  1142. }
  1143. }
  1144. }
  1145. return skill_point;
  1146. }
  1147. /*==========================================
  1148. * Calculation of skill level.
  1149. *------------------------------------------*/
  1150. int pc_calc_skilltree(struct map_session_data *sd)
  1151. {
  1152. int i,id=0,flag;
  1153. int c=0;
  1154. nullpo_ret(sd);
  1155. i = pc_calc_skilltree_normalize_job(sd);
  1156. c = pc_mapid2jobid(i, sd->status.sex);
  1157. if( c == -1 )
  1158. { //Unable to normalize job??
  1159. 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);
  1160. return 1;
  1161. }
  1162. c = pc_class2idx(c);
  1163. for( i = 0; i < MAX_SKILL; i++ ) {
  1164. if( sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED ) //Don't touch these
  1165. sd->status.skill[i].id = 0; //First clear skills.
  1166. /* permanent skills that must be re-checked */
  1167. if( sd->status.skill[i].flag == SKILL_FLAG_PERM_GRANTED ) {
  1168. switch( i ) {
  1169. case NV_TRICKDEAD:
  1170. if( (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ) {
  1171. sd->status.skill[i].id = 0;
  1172. sd->status.skill[i].lv = 0;
  1173. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1174. }
  1175. break;
  1176. }
  1177. }
  1178. }
  1179. for( i = 0; i < MAX_SKILL; i++ )
  1180. {
  1181. 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 )
  1182. { // Restore original level of skills after deleting earned skills.
  1183. sd->status.skill[i].lv = (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  1184. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1185. }
  1186. if( sd->sc.count && sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_BARDDANCER && i >= DC_HUMMING && i<= DC_SERVICEFORYOU )
  1187. { //Enable Bard/Dancer spirit linked skills.
  1188. if( sd->status.sex )
  1189. { //Link dancer skills to bard.
  1190. if( sd->status.skill[i-8].lv < 10 )
  1191. continue;
  1192. sd->status.skill[i].id = i;
  1193. sd->status.skill[i].lv = sd->status.skill[i-8].lv; // Set the level to the same as the linking skill
  1194. sd->status.skill[i].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
  1195. }
  1196. else
  1197. { //Link bard skills to dancer.
  1198. if( sd->status.skill[i].lv < 10 )
  1199. continue;
  1200. sd->status.skill[i-8].id = i - 8;
  1201. sd->status.skill[i-8].lv = sd->status.skill[i].lv; // Set the level to the same as the linking skill
  1202. sd->status.skill[i-8].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
  1203. }
  1204. }
  1205. }
  1206. if( pc_has_permission(sd, PC_PERM_ALL_SKILL) ) {
  1207. for( i = 0; i < MAX_SKILL; i++ ) {
  1208. switch(i) {
  1209. /**
  1210. * Dummy skills must be added here otherwise they'll be displayed in the,
  1211. * skill tree and since they have no icons they'll give resource errors
  1212. **/
  1213. case SM_SELFPROVOKE:
  1214. case AB_DUPLELIGHT_MELEE:
  1215. case AB_DUPLELIGHT_MAGIC:
  1216. case WL_CHAINLIGHTNING_ATK:
  1217. case WL_TETRAVORTEX_FIRE:
  1218. case WL_TETRAVORTEX_WATER:
  1219. case WL_TETRAVORTEX_WIND:
  1220. case WL_TETRAVORTEX_GROUND:
  1221. case WL_SUMMON_ATK_FIRE:
  1222. case WL_SUMMON_ATK_WIND:
  1223. case WL_SUMMON_ATK_WATER:
  1224. case WL_SUMMON_ATK_GROUND:
  1225. case LG_OVERBRAND_BRANDISH:
  1226. case LG_OVERBRAND_PLUSATK:
  1227. case WM_SEVERE_RAINSTORM_MELEE:
  1228. continue;
  1229. default:
  1230. break;
  1231. }
  1232. if( skill_get_inf2(i)&(INF2_NPC_SKILL|INF2_GUILD_SKILL) )
  1233. continue; //Only skills you can't have are npc/guild ones
  1234. if( skill_get_max(i) > 0 )
  1235. sd->status.skill[i].id = i;
  1236. }
  1237. return 0;
  1238. }
  1239. do {
  1240. flag = 0;
  1241. for( i = 0; i < MAX_SKILL_TREE && (id = skill_tree[c][i].id) > 0; i++ )
  1242. {
  1243. int f;
  1244. if( sd->status.skill[id].id )
  1245. continue; //Skill already known.
  1246. f = 1;
  1247. if(!battle_config.skillfree) {
  1248. int j;
  1249. for(j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
  1250. int k;
  1251. if((k=skill_tree[c][i].need[j].id))
  1252. {
  1253. if (sd->status.skill[k].id == 0 || sd->status.skill[k].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[k].flag == SKILL_FLAG_PLAGIARIZED)
  1254. k = 0; //Not learned.
  1255. else
  1256. if (sd->status.skill[k].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
  1257. k = sd->status.skill[skill_tree[c][i].need[j].id].flag - SKILL_FLAG_REPLACED_LV_0;
  1258. else
  1259. k = pc_checkskill(sd,k);
  1260. if (k < skill_tree[c][i].need[j].lv)
  1261. {
  1262. f = 0;
  1263. break;
  1264. }
  1265. }
  1266. }
  1267. if( sd->status.job_level < skill_tree[c][i].joblv ) { //We need to get the actual class in this case
  1268. int class_ = pc_mapid2jobid(sd->class_, sd->status.sex);
  1269. class_ = pc_class2idx(class_);
  1270. if (class_ == c || (class_ != c && sd->status.job_level < skill_tree[class_][i].joblv))
  1271. f = 0; // job level requirement wasn't satisfied
  1272. }
  1273. }
  1274. if( f ) {
  1275. int inf2;
  1276. inf2 = skill_get_inf2(id);
  1277. if(!sd->status.skill[id].lv && (
  1278. (inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  1279. inf2&INF2_WEDDING_SKILL ||
  1280. (inf2&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
  1281. ))
  1282. continue; //Cannot be learned via normal means. Note this check DOES allows raising already known skills.
  1283. sd->status.skill[id].id = id;
  1284. if(inf2&INF2_SPIRIT_SKILL) { //Spirit skills cannot be learned, they will only show up on your tree when you get buffed.
  1285. sd->status.skill[id].lv = 1; // need to manually specify a skill level
  1286. sd->status.skill[id].flag = SKILL_FLAG_TEMPORARY; //So it is not saved, and tagged as a "bonus" skill.
  1287. }
  1288. flag = 1; // skill list has changed, perform another pass
  1289. }
  1290. }
  1291. } while(flag);
  1292. //
  1293. 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) )
  1294. {
  1295. /* Taekwon Ranger Bonus Skill Tree
  1296. ============================================
  1297. - Grant All Taekwon Tree, but only as Bonus Skills in case they drop from ranking.
  1298. - (c > 0) to avoid grant Novice Skill Tree in case of Skill Reset (need more logic)
  1299. - (sd->status.skill_point == 0) to wait until all skill points are asigned to avoid problems with Job Change quest. */
  1300. for( i = 0; i < MAX_SKILL_TREE && (id = skill_tree[c][i].id) > 0; i++ )
  1301. {
  1302. if( (skill_get_inf2(id)&(INF2_QUEST_SKILL|INF2_WEDDING_SKILL)) )
  1303. continue; //Do not include Quest/Wedding skills.
  1304. if( sd->status.skill[id].id == 0 )
  1305. {
  1306. sd->status.skill[id].id = id;
  1307. sd->status.skill[id].flag = SKILL_FLAG_TEMPORARY; // So it is not saved, and tagged as a "bonus" skill.
  1308. }
  1309. else if( id != NV_BASIC )
  1310. {
  1311. sd->status.skill[id].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[id].lv; // Remember original level
  1312. }
  1313. sd->status.skill[id].lv = skill_tree_get_max(id, sd->status.class_);
  1314. }
  1315. }
  1316. return 0;
  1317. }
  1318. //Checks if you can learn a new skill after having leveled up a skill.
  1319. static void pc_check_skilltree(struct map_session_data *sd, int skill)
  1320. {
  1321. int i,id=0,flag;
  1322. int c=0;
  1323. if(battle_config.skillfree)
  1324. return; //Function serves no purpose if this is set
  1325. i = pc_calc_skilltree_normalize_job(sd);
  1326. c = pc_mapid2jobid(i, sd->status.sex);
  1327. if (c == -1) { //Unable to normalize job??
  1328. 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);
  1329. return;
  1330. }
  1331. c = pc_class2idx(c);
  1332. do {
  1333. flag = 0;
  1334. for( i = 0; i < MAX_SKILL_TREE && (id=skill_tree[c][i].id)>0; i++ )
  1335. {
  1336. int j, f = 1;
  1337. if( sd->status.skill[id].id ) //Already learned
  1338. continue;
  1339. for( j = 0; j < MAX_PC_SKILL_REQUIRE; j++ ){
  1340. int k = skill_tree[c][i].need[j].id;
  1341. if( k != 0 ){
  1342. if( sd->status.skill[k].id == 0 || sd->status.skill[k].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[k].flag == SKILL_FLAG_PLAGIARIZED )
  1343. k = 0; //Not learned.
  1344. else
  1345. if( sd->status.skill[k].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
  1346. k = sd->status.skill[skill_tree[c][i].need[j].id].flag - SKILL_FLAG_REPLACED_LV_0;
  1347. else
  1348. k = pc_checkskill(sd,k);
  1349. if( k < skill_tree[c][i].need[j].lv )
  1350. {
  1351. f = 0;
  1352. break;
  1353. }
  1354. }
  1355. }
  1356. if( !f )
  1357. continue;
  1358. if( sd->status.job_level < skill_tree[c][i].joblv )
  1359. continue;
  1360. j = skill_get_inf2(id);
  1361. if( !sd->status.skill[id].lv && (
  1362. (j&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  1363. j&INF2_WEDDING_SKILL ||
  1364. (j&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
  1365. ) )
  1366. continue; //Cannot be learned via normal means.
  1367. sd->status.skill[id].id = id;
  1368. flag = 1;
  1369. }
  1370. } while(flag);
  1371. }
  1372. // Make sure all the skills are in the correct condition
  1373. // before persisting to the backend.. [MouseJstr]
  1374. void pc_clean_skilltree(struct map_session_data *sd)
  1375. {
  1376. uint16 i;
  1377. for (i = 0; i < MAX_SKILL; i++){
  1378. if (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED)
  1379. {
  1380. sd->status.skill[i].id = 0;
  1381. sd->status.skill[i].lv = 0;
  1382. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1383. }
  1384. else
  1385. if (sd->status.skill[i].flag == SKILL_FLAG_REPLACED_LV_0){
  1386. sd->status.skill[i].lv = sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  1387. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1388. }
  1389. }
  1390. }
  1391. int pc_calc_skilltree_normalize_job(struct map_session_data *sd)
  1392. {
  1393. int skill_point, novice_skills;
  1394. int c = sd->class_;
  1395. if (!battle_config.skillup_limit || pc_has_permission(sd, PC_PERM_ALL_SKILL))
  1396. return c;
  1397. skill_point = pc_calc_skillpoint(sd);
  1398. novice_skills = job_info[pc_class2idx(JOB_NOVICE)].max_level[1] - 1;
  1399. // limit 1st class and above to novice job levels
  1400. if(skill_point < novice_skills)
  1401. {
  1402. c = MAPID_NOVICE;
  1403. }
  1404. // limit 2nd class and above to first class job levels (super novices are exempt)
  1405. else if ((sd->class_&JOBL_2) && (sd->class_&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE)
  1406. {
  1407. // regenerate change_level_2nd
  1408. if (!sd->change_level_2nd)
  1409. {
  1410. if (sd->class_&JOBL_THIRD)
  1411. {
  1412. // if neither 2nd nor 3rd jobchange levels are known, we have to assume a default for 2nd
  1413. if (!sd->change_level_3rd)
  1414. sd->change_level_2nd = job_info[pc_class2idx(pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex))].max_level[1];
  1415. else
  1416. sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
  1417. - (sd->status.job_level - 1)
  1418. - (sd->change_level_3rd - 1)
  1419. - novice_skills;
  1420. }
  1421. else
  1422. {
  1423. sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
  1424. - (sd->status.job_level - 1)
  1425. - novice_skills;
  1426. }
  1427. pc_setglobalreg (sd, "jobchange_level", sd->change_level_2nd);
  1428. }
  1429. if (skill_point < novice_skills + (sd->change_level_2nd - 1))
  1430. {
  1431. c &= MAPID_BASEMASK;
  1432. }
  1433. // limit 3rd class to 2nd class/trans job levels
  1434. else if(sd->class_&JOBL_THIRD)
  1435. {
  1436. // regenerate change_level_3rd
  1437. if (!sd->change_level_3rd)
  1438. {
  1439. sd->change_level_3rd = 1 + skill_point + sd->status.skill_point
  1440. - (sd->status.job_level - 1)
  1441. - (sd->change_level_2nd - 1)
  1442. - novice_skills;
  1443. pc_setglobalreg (sd, "jobchange_level_3rd", sd->change_level_3rd);
  1444. }
  1445. if (skill_point < novice_skills + (sd->change_level_2nd - 1) + (sd->change_level_3rd - 1))
  1446. c &= MAPID_UPPERMASK;
  1447. }
  1448. }
  1449. // restore non-limiting flags
  1450. c |= sd->class_&(JOBL_UPPER|JOBL_BABY);
  1451. return c;
  1452. }
  1453. /*==========================================
  1454. * Updates the weight status
  1455. *------------------------------------------
  1456. * 1: overweight 50%
  1457. * 2: overweight 90%
  1458. * It's assumed that SC_WEIGHT50 and SC_WEIGHT90 are only started/stopped here.
  1459. */
  1460. int pc_updateweightstatus(struct map_session_data *sd)
  1461. {
  1462. int old_overweight;
  1463. int new_overweight;
  1464. nullpo_retr(1, sd);
  1465. old_overweight = (sd->sc.data[SC_WEIGHT90]) ? 2 : (sd->sc.data[SC_WEIGHT50]) ? 1 : 0;
  1466. new_overweight = (pc_is90overweight(sd)) ? 2 : (pc_is50overweight(sd)) ? 1 : 0;
  1467. if( old_overweight == new_overweight )
  1468. return 0; // no change
  1469. // stop old status change
  1470. if( old_overweight == 1 )
  1471. status_change_end(&sd->bl, SC_WEIGHT50, INVALID_TIMER);
  1472. else if( old_overweight == 2 )
  1473. status_change_end(&sd->bl, SC_WEIGHT90, INVALID_TIMER);
  1474. // start new status change
  1475. if( new_overweight == 1 )
  1476. sc_start(&sd->bl,&sd->bl, SC_WEIGHT50, 100, 0, 0);
  1477. else if( new_overweight == 2 )
  1478. sc_start(&sd->bl,&sd->bl, SC_WEIGHT90, 100, 0, 0);
  1479. // update overweight status
  1480. sd->regen.state.overweight = new_overweight;
  1481. return 0;
  1482. }
  1483. int pc_disguise(struct map_session_data *sd, int class_)
  1484. {
  1485. if (!class_ && !sd->disguise)
  1486. return 0;
  1487. if (class_ && sd->disguise == class_)
  1488. return 0;
  1489. if(sd->sc.option&OPTION_INVISIBLE)
  1490. { //Character is invisible. Stealth class-change. [Skotlex]
  1491. sd->disguise = class_; //viewdata is set on uncloaking.
  1492. return 2;
  1493. }
  1494. if (sd->bl.prev != NULL) {
  1495. pc_stop_walking(sd, 0);
  1496. clif_clearunit_area(&sd->bl, CLR_OUTSIGHT);
  1497. }
  1498. if (!class_) {
  1499. sd->disguise = 0;
  1500. class_ = sd->status.class_;
  1501. } else
  1502. sd->disguise=class_;
  1503. status_set_viewdata(&sd->bl, class_);
  1504. clif_changeoption(&sd->bl);
  1505. if (sd->bl.prev != NULL) {
  1506. clif_spawn(&sd->bl);
  1507. if (class_ == sd->status.class_ && pc_iscarton(sd))
  1508. { //It seems the cart info is lost on undisguise.
  1509. clif_cartlist(sd);
  1510. clif_updatestatus(sd,SP_CARTINFO);
  1511. }
  1512. if (sd->chatID) {
  1513. struct chat_data* cd;
  1514. nullpo_retr(1, sd);
  1515. cd = (struct chat_data*)map_id2bl(sd->chatID);
  1516. if( cd != NULL || (struct block_list*)sd == cd->owner )
  1517. clif_dispchat(cd,0);
  1518. }
  1519. }
  1520. return 1;
  1521. }
  1522. static int pc_bonus_autospell(struct s_autospell *spell, int max, short id, short lv, short rate, short flag, short card_id)
  1523. {
  1524. int i;
  1525. if( !rate )
  1526. return 0;
  1527. for( i = 0; i < max && spell[i].id; i++ )
  1528. {
  1529. if( (spell[i].card_id == card_id || spell[i].rate < 0 || rate < 0) && spell[i].id == id && spell[i].lv == lv )
  1530. {
  1531. if( !battle_config.autospell_stacking && spell[i].rate > 0 && rate > 0 )
  1532. return 0;
  1533. rate += spell[i].rate;
  1534. break;
  1535. }
  1536. }
  1537. if (i == max) {
  1538. ShowWarning("pc_bonus: Reached max (%d) number of autospells per character!\n", max);
  1539. return 0;
  1540. }
  1541. spell[i].id = id;
  1542. spell[i].lv = lv;
  1543. spell[i].rate = rate;
  1544. //Auto-update flag value.
  1545. if (!(flag&BF_RANGEMASK)) flag|=BF_SHORT|BF_LONG; //No range defined? Use both.
  1546. if (!(flag&BF_WEAPONMASK)) flag|=BF_WEAPON; //No attack type defined? Use weapon.
  1547. if (!(flag&BF_SKILLMASK)) {
  1548. if (flag&(BF_MAGIC|BF_MISC)) flag|=BF_SKILL; //These two would never trigger without BF_SKILL
  1549. if (flag&BF_WEAPON) flag|=BF_NORMAL; //By default autospells should only trigger on normal weapon attacks.
  1550. }
  1551. spell[i].flag|= flag;
  1552. spell[i].card_id = card_id;
  1553. return 1;
  1554. }
  1555. static int pc_bonus_autospell_onskill(struct s_autospell *spell, int max, short src_skill, short id, short lv, short rate, short card_id)
  1556. {
  1557. int i;
  1558. if( !rate )
  1559. return 0;
  1560. for( i = 0; i < max && spell[i].id; i++ )
  1561. {
  1562. ; // each autospell works independently
  1563. }
  1564. if( i == max )
  1565. {
  1566. ShowWarning("pc_bonus: Reached max (%d) number of autospells per character!\n", max);
  1567. return 0;
  1568. }
  1569. spell[i].flag = src_skill;
  1570. spell[i].id = id;
  1571. spell[i].lv = lv;
  1572. spell[i].rate = rate;
  1573. spell[i].card_id = card_id;
  1574. return 1;
  1575. }
  1576. static int pc_bonus_addeff(struct s_addeffect* effect, int max, enum sc_type id, short rate, short arrow_rate, unsigned char flag)
  1577. {
  1578. int i;
  1579. if (!(flag&(ATF_SHORT|ATF_LONG)))
  1580. flag|=ATF_SHORT|ATF_LONG; //Default range: both
  1581. if (!(flag&(ATF_TARGET|ATF_SELF)))
  1582. flag|=ATF_TARGET; //Default target: enemy.
  1583. if (!(flag&(ATF_WEAPON|ATF_MAGIC|ATF_MISC)))
  1584. flag|=ATF_WEAPON; //Default type: weapon.
  1585. for (i = 0; i < max && effect[i].flag; i++) {
  1586. if (effect[i].id == id && effect[i].flag == flag)
  1587. {
  1588. effect[i].rate += rate;
  1589. effect[i].arrow_rate += arrow_rate;
  1590. return 1;
  1591. }
  1592. }
  1593. if (i == max) {
  1594. ShowWarning("pc_bonus: Reached max (%d) number of add effects per character!\n", max);
  1595. return 0;
  1596. }
  1597. effect[i].id = id;
  1598. effect[i].rate = rate;
  1599. effect[i].arrow_rate = arrow_rate;
  1600. effect[i].flag = flag;
  1601. return 1;
  1602. }
  1603. static int pc_bonus_addeff_onskill(struct s_addeffectonskill* effect, int max, enum sc_type id, short rate, short skill, unsigned char target)
  1604. {
  1605. int i;
  1606. for( i = 0; i < max && effect[i].skill; i++ )
  1607. {
  1608. if( effect[i].id == id && effect[i].skill == skill && effect[i].target == target )
  1609. {
  1610. effect[i].rate += rate;
  1611. return 1;
  1612. }
  1613. }
  1614. if( i == max ) {
  1615. ShowWarning("pc_bonus: Reached max (%d) number of add effects on skill per character!\n", max);
  1616. return 0;
  1617. }
  1618. effect[i].id = id;
  1619. effect[i].rate = rate;
  1620. effect[i].skill = skill;
  1621. effect[i].target = target;
  1622. return 1;
  1623. }
  1624. /** Adjust/add drop rate modifier for player
  1625. * @param drop: sd->add_drop (struct s_add_drop)
  1626. * @param max: max stacked bonus
  1627. * @param id: item id that will be dropped
  1628. * @param group: group id
  1629. * @param class_: target class
  1630. * @param race: target race
  1631. * @param rate: rate value
  1632. * @return true/false: false if max limit is reached
  1633. */
  1634. static void pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id, short group, int class_, int race, int rate)
  1635. {
  1636. int i;
  1637. //Apply config rate adjustment settings.
  1638. if (rate >= 0) { //Absolute drop.
  1639. if (battle_config.item_rate_adddrop != 100)
  1640. rate = rate*battle_config.item_rate_adddrop/100;
  1641. if (rate < battle_config.item_drop_adddrop_min)
  1642. rate = battle_config.item_drop_adddrop_min;
  1643. else if (rate > battle_config.item_drop_adddrop_max)
  1644. rate = battle_config.item_drop_adddrop_max;
  1645. } else { //Relative drop, max/min limits are applied at drop time.
  1646. if (battle_config.item_rate_adddrop != 100)
  1647. rate = rate*battle_config.item_rate_adddrop/100;
  1648. if (rate > -1)
  1649. rate = -1;
  1650. }
  1651. for(i = 0; i < max && (drop[i].id || drop[i].group); i++) {
  1652. if(
  1653. ((id && drop[i].id == id) || (group && drop[i].group == group)) &&
  1654. ((race > RC_NONE_ && race < RC_MAX) || (class_ > CLASS_NONE && class_ < CLASS_MAX))
  1655. ) {
  1656. if(race > RC_NONE_ && race < RC_MAX)
  1657. drop[i].race |= 1<<race;
  1658. if(class_ > CLASS_NONE && class_ < CLASS_MAX)
  1659. drop[i].class_ |= 1<<class_;
  1660. if(drop[i].rate > 0 && rate > 0)
  1661. { //Both are absolute rates.
  1662. if (drop[i].rate < rate)
  1663. drop[i].rate = rate;
  1664. } else if(drop[i].rate < 0 && rate < 0) {
  1665. //Both are relative rates.
  1666. if (drop[i].rate > rate)
  1667. drop[i].rate = rate;
  1668. } else if (rate < 0) //Give preference to relative rate.
  1669. drop[i].rate = rate;
  1670. return;
  1671. }
  1672. }
  1673. if(i == max) {
  1674. ShowWarning("pc_bonus: Reached max (%d) number of added drops per character!\n", max);
  1675. return;
  1676. }
  1677. drop[i].id = id;
  1678. drop[i].group = group;
  1679. if(race>RC_NONE_ && race<RC_MAX)
  1680. drop[i].race = 1<<race;
  1681. else
  1682. drop[i].race = race;
  1683. if(class_>CLASS_NONE && class_<CLASS_MAX)
  1684. drop[i].class_ = 1<<class_;
  1685. else
  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. default:
  2439. ShowWarning("pc_bonus: unknown type %d %d !\n",type,val);
  2440. break;
  2441. }
  2442. return 0;
  2443. }
  2444. /*==========================================
  2445. * Player bonus (type) with args type2 and val, called trough bonus2 (npc)
  2446. *------------------------------------------*/
  2447. int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
  2448. {
  2449. int i;
  2450. nullpo_ret(sd);
  2451. switch(type){
  2452. case SP_ADDELE:
  2453. if(type2 > ELE_ALL) {
  2454. ShowError("pc_bonus2: SP_ADDELE: Invalid element %d\n", type2);
  2455. break;
  2456. }
  2457. if(!sd->state.lr_flag)
  2458. sd->right_weapon.addele[type2]+=val;
  2459. else if(sd->state.lr_flag == 1)
  2460. sd->left_weapon.addele[type2]+=val;
  2461. else if(sd->state.lr_flag == 2)
  2462. sd->arrow_addele[type2]+=val;
  2463. break;
  2464. case SP_ADDRACE:
  2465. if(!sd->state.lr_flag)
  2466. sd->right_weapon.addrace[type2]+=val;
  2467. else if(sd->state.lr_flag == 1)
  2468. sd->left_weapon.addrace[type2]+=val;
  2469. else if(sd->state.lr_flag == 2)
  2470. sd->arrow_addrace[type2]+=val;
  2471. break;
  2472. case SP_ADDCLASS:
  2473. if(!sd->state.lr_flag)
  2474. sd->right_weapon.addclass[type2]+=val;
  2475. else if(sd->state.lr_flag == 1)
  2476. sd->left_weapon.addclass[type2]+=val;
  2477. else if(sd->state.lr_flag == 2)
  2478. sd->arrow_addclass[type2]+=val;
  2479. break;
  2480. case SP_ADDSIZE:
  2481. if(!sd->state.lr_flag)
  2482. sd->right_weapon.addsize[type2]+=val;
  2483. else if(sd->state.lr_flag == 1)
  2484. sd->left_weapon.addsize[type2]+=val;
  2485. else if(sd->state.lr_flag == 2)
  2486. sd->arrow_addsize[type2]+=val;
  2487. break;
  2488. case SP_SUBELE:
  2489. if(type2 > ELE_ALL) {
  2490. ShowError("pc_bonus2: SP_SUBELE: Invalid element %d\n", type2);
  2491. break;
  2492. }
  2493. if(sd->state.lr_flag != 2)
  2494. sd->subele[type2]+=val;
  2495. break;
  2496. case SP_SUBRACE:
  2497. if(sd->state.lr_flag != 2)
  2498. sd->subrace[type2]+=val;
  2499. break;
  2500. case SP_SUBCLASS:
  2501. if(sd->state.lr_flag != 2)
  2502. sd->subclass[type2]+=val;
  2503. break;
  2504. case SP_ADDEFF:
  2505. if (type2 > SC_MAX) {
  2506. ShowWarning("pc_bonus2 (Add Effect): %d is not supported.\n", type2);
  2507. break;
  2508. }
  2509. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  2510. sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, 0);
  2511. break;
  2512. case SP_ADDEFF2:
  2513. if (type2 > SC_MAX) {
  2514. ShowWarning("pc_bonus2 (Add Effect2): %d is not supported.\n", type2);
  2515. break;
  2516. }
  2517. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  2518. sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, ATF_SELF);
  2519. break;
  2520. case SP_RESEFF:
  2521. if (type2 < SC_COMMON_MIN || type2 > SC_COMMON_MAX) {
  2522. ShowWarning("pc_bonus2 (Resist Effect): %d is not supported.\n", type2);
  2523. break;
  2524. }
  2525. if(sd->state.lr_flag == 2)
  2526. break;
  2527. i = sd->reseff[type2-SC_COMMON_MIN]+val;
  2528. sd->reseff[type2-SC_COMMON_MIN]= cap_value(i, 0, 10000);
  2529. break;
  2530. case SP_MAGIC_ADDELE:
  2531. if(type2 > ELE_ALL) {
  2532. ShowError("pc_bonus2: SP_MAGIC_ADDELE: Invalid element %d\n", type2);
  2533. break;
  2534. }
  2535. if(sd->state.lr_flag != 2)
  2536. sd->magic_addele[type2]+=val;
  2537. break;
  2538. case SP_MAGIC_ADDRACE:
  2539. if(sd->state.lr_flag != 2)
  2540. sd->magic_addrace[type2]+=val;
  2541. break;
  2542. case SP_MAGIC_ADDCLASS:
  2543. if(sd->state.lr_flag != 2)
  2544. sd->magic_addclass[type2]+=val;
  2545. break;
  2546. case SP_MAGIC_ADDSIZE:
  2547. if(sd->state.lr_flag != 2)
  2548. sd->magic_addsize[type2]+=val;
  2549. break;
  2550. case SP_MAGIC_ATK_ELE:
  2551. if(sd->state.lr_flag != 2)
  2552. sd->magic_atk_ele[type2]+=val;
  2553. break;
  2554. case SP_ADD_DAMAGE_CLASS:
  2555. switch (sd->state.lr_flag) {
  2556. case 0: //Right hand
  2557. 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);
  2558. if (i == ARRAYLENGTH(sd->right_weapon.add_dmg))
  2559. {
  2560. ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->right_weapon.add_dmg));
  2561. break;
  2562. }
  2563. sd->right_weapon.add_dmg[i].class_ = type2;
  2564. sd->right_weapon.add_dmg[i].rate += val;
  2565. if (!sd->right_weapon.add_dmg[i].rate) //Shift the rest of elements up.
  2566. 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]));
  2567. break;
  2568. case 1: //Left hand
  2569. 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);
  2570. if (i == ARRAYLENGTH(sd->left_weapon.add_dmg))
  2571. {
  2572. ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->left_weapon.add_dmg));
  2573. break;
  2574. }
  2575. sd->left_weapon.add_dmg[i].class_ = type2;
  2576. sd->left_weapon.add_dmg[i].rate += val;
  2577. if (!sd->left_weapon.add_dmg[i].rate) //Shift the rest of elements up.
  2578. 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]));
  2579. break;
  2580. }
  2581. break;
  2582. case SP_ADD_MAGIC_DAMAGE_CLASS:
  2583. if(sd->state.lr_flag == 2)
  2584. break;
  2585. ARR_FIND(0, ARRAYLENGTH(sd->add_mdmg), i, sd->add_mdmg[i].rate == 0 || sd->add_mdmg[i].class_ == type2);
  2586. if (i == ARRAYLENGTH(sd->add_mdmg))
  2587. {
  2588. ShowWarning("pc_bonus2: Reached max (%d) number of add Class magic dmg bonuses per character!\n", ARRAYLENGTH(sd->add_mdmg));
  2589. break;
  2590. }
  2591. sd->add_mdmg[i].class_ = type2;
  2592. sd->add_mdmg[i].rate += val;
  2593. if (!sd->add_mdmg[i].rate) //Shift the rest of elements up.
  2594. memmove(&sd->add_mdmg[i], &sd->add_mdmg[i+1], sizeof(sd->add_mdmg) - (i+1)*sizeof(sd->add_mdmg[0]));
  2595. break;
  2596. case SP_ADD_DEF_MONSTER:
  2597. if(sd->state.lr_flag == 2)
  2598. break;
  2599. ARR_FIND(0, ARRAYLENGTH(sd->add_def), i, sd->add_def[i].rate == 0 || sd->add_def[i].class_ == type2);
  2600. if (i == ARRAYLENGTH(sd->add_def))
  2601. {
  2602. ShowWarning("pc_bonus2: Reached max (%d) number of add Class def bonuses per character!\n", ARRAYLENGTH(sd->add_def));
  2603. break;
  2604. }
  2605. sd->add_def[i].class_ = type2;
  2606. sd->add_def[i].rate += val;
  2607. if (!sd->add_def[i].rate) //Shift the rest of elements up.
  2608. memmove(&sd->add_def[i], &sd->add_def[i+1], sizeof(sd->add_def) - (i+1)*sizeof(sd->add_def[0]));
  2609. break;
  2610. case SP_ADD_MDEF_MONSTER:
  2611. if(sd->state.lr_flag == 2)
  2612. break;
  2613. ARR_FIND(0, ARRAYLENGTH(sd->add_mdef), i, sd->add_mdef[i].rate == 0 || sd->add_mdef[i].class_ == type2);
  2614. if (i == ARRAYLENGTH(sd->add_mdef))
  2615. {
  2616. ShowWarning("pc_bonus2: Reached max (%d) number of add Class mdef bonuses per character!\n", ARRAYLENGTH(sd->add_mdef));
  2617. break;
  2618. }
  2619. sd->add_mdef[i].class_ = type2;
  2620. sd->add_mdef[i].rate += val;
  2621. if (!sd->add_mdef[i].rate) //Shift the rest of elements up.
  2622. memmove(&sd->add_mdef[i], &sd->add_mdef[i+1], sizeof(sd->add_mdef) - (i+1)*sizeof(sd->add_mdef[0]));
  2623. break;
  2624. case SP_HP_DRAIN_RATE:
  2625. if(!sd->state.lr_flag) {
  2626. sd->right_weapon.hp_drain_class[CLASS_NORMAL].rate += type2;
  2627. sd->right_weapon.hp_drain_class[CLASS_NORMAL].per += val;
  2628. sd->right_weapon.hp_drain_class[CLASS_BOSS].rate += type2;
  2629. sd->right_weapon.hp_drain_class[CLASS_BOSS].per += val;
  2630. }
  2631. else if(sd->state.lr_flag == 1) {
  2632. sd->left_weapon.hp_drain_class[CLASS_NORMAL].rate += type2;
  2633. sd->left_weapon.hp_drain_class[CLASS_NORMAL].per += val;
  2634. sd->left_weapon.hp_drain_class[CLASS_BOSS].rate += type2;
  2635. sd->left_weapon.hp_drain_class[CLASS_BOSS].per += val;
  2636. }
  2637. break;
  2638. case SP_HP_DRAIN_VALUE:
  2639. if(!sd->state.lr_flag) {
  2640. sd->right_weapon.hp_drain_class[CLASS_NORMAL].value += type2;
  2641. sd->right_weapon.hp_drain_class[CLASS_NORMAL].type = val;
  2642. sd->right_weapon.hp_drain_class[CLASS_BOSS].value += type2;
  2643. sd->right_weapon.hp_drain_class[CLASS_BOSS].type = val;
  2644. }
  2645. else if(sd->state.lr_flag == 1) {
  2646. sd->left_weapon.hp_drain_class[CLASS_NORMAL].value += type2;
  2647. sd->left_weapon.hp_drain_class[CLASS_NORMAL].type = val;
  2648. sd->left_weapon.hp_drain_class[CLASS_BOSS].value += type2;
  2649. sd->left_weapon.hp_drain_class[CLASS_BOSS].type = val;
  2650. }
  2651. break;
  2652. case SP_SP_DRAIN_RATE:
  2653. if(!sd->state.lr_flag) {
  2654. sd->right_weapon.sp_drain_class[CLASS_NORMAL].rate += type2;
  2655. sd->right_weapon.sp_drain_class[CLASS_NORMAL].per += val;
  2656. sd->right_weapon.sp_drain_class[CLASS_BOSS].rate += type2;
  2657. sd->right_weapon.sp_drain_class[CLASS_BOSS].per += val;
  2658. }
  2659. else if(sd->state.lr_flag == 1) {
  2660. sd->left_weapon.sp_drain_class[CLASS_NORMAL].rate += type2;
  2661. sd->left_weapon.sp_drain_class[CLASS_NORMAL].per += val;
  2662. sd->left_weapon.sp_drain_class[CLASS_BOSS].rate += type2;
  2663. sd->left_weapon.sp_drain_class[CLASS_BOSS].per += val;
  2664. }
  2665. break;
  2666. case SP_SP_DRAIN_VALUE:
  2667. if(!sd->state.lr_flag) {
  2668. sd->right_weapon.sp_drain_class[CLASS_NORMAL].value += type2;
  2669. sd->right_weapon.sp_drain_class[CLASS_NORMAL].type = val;
  2670. sd->right_weapon.sp_drain_class[CLASS_BOSS].value += type2;
  2671. sd->right_weapon.sp_drain_class[CLASS_BOSS].type = val;
  2672. }
  2673. else if(sd->state.lr_flag == 1) {
  2674. sd->left_weapon.sp_drain_class[CLASS_NORMAL].value += type2;
  2675. sd->left_weapon.sp_drain_class[CLASS_NORMAL].type = val;
  2676. sd->left_weapon.sp_drain_class[CLASS_BOSS].value += type2;
  2677. sd->left_weapon.sp_drain_class[CLASS_BOSS].type = val;
  2678. }
  2679. break;
  2680. case SP_SP_VANISH_RATE:
  2681. if(sd->state.lr_flag != 2) {
  2682. sd->bonus.sp_vanish_rate += type2;
  2683. sd->bonus.sp_vanish_per += val;
  2684. }
  2685. break;
  2686. case SP_HP_VANISH_RATE:
  2687. if(sd->state.lr_flag != 2) {
  2688. sd->bonus.hp_vanish_rate += type2;
  2689. sd->bonus.hp_vanish_per += val;
  2690. }
  2691. break;
  2692. case SP_GET_ZENY_NUM:
  2693. if(sd->state.lr_flag != 2 && sd->bonus.get_zeny_rate < val) {
  2694. sd->bonus.get_zeny_rate = val;
  2695. sd->bonus.get_zeny_num = type2;
  2696. }
  2697. break;
  2698. case SP_ADD_GET_ZENY_NUM:
  2699. if(sd->state.lr_flag != 2) {
  2700. sd->bonus.get_zeny_rate += val;
  2701. sd->bonus.get_zeny_num += type2;
  2702. }
  2703. break;
  2704. case SP_WEAPON_COMA_ELE:
  2705. if(type2 > ELE_ALL) {
  2706. ShowError("pc_bonus2: SP_WEAPON_COMA_ELE: Invalid element %d\n", type2);
  2707. break;
  2708. }
  2709. if(sd->state.lr_flag == 2)
  2710. break;
  2711. sd->weapon_coma_ele[type2] += val;
  2712. sd->special_state.bonus_coma = 1;
  2713. break;
  2714. case SP_WEAPON_COMA_RACE:
  2715. if(sd->state.lr_flag == 2)
  2716. break;
  2717. sd->weapon_coma_race[type2] += val;
  2718. sd->special_state.bonus_coma = 1;
  2719. break;
  2720. case SP_WEAPON_COMA_CLASS:
  2721. if(sd->state.lr_flag == 2)
  2722. break;
  2723. sd->weapon_coma_class[type2] += val;
  2724. sd->special_state.bonus_coma = 1;
  2725. break;
  2726. case SP_WEAPON_ATK:
  2727. if(sd->state.lr_flag != 2)
  2728. sd->weapon_atk[type2]+=val;
  2729. break;
  2730. case SP_WEAPON_ATK_RATE:
  2731. if(sd->state.lr_flag != 2)
  2732. sd->weapon_atk_rate[type2]+=val;
  2733. break;
  2734. case SP_CRITICAL_ADDRACE:
  2735. if(sd->state.lr_flag != 2)
  2736. sd->critaddrace[type2] += val*10;
  2737. break;
  2738. case SP_ADDEFF_WHENHIT:
  2739. if (type2 > SC_MAX) {
  2740. ShowWarning("pc_bonus2 (Add Effect when hit): %d is not supported.\n", type2);
  2741. break;
  2742. }
  2743. if(sd->state.lr_flag != 2)
  2744. pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, val, 0, 0);
  2745. break;
  2746. case SP_SKILL_ATK:
  2747. if(sd->state.lr_flag == 2)
  2748. break;
  2749. ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == 0 || sd->skillatk[i].id == type2);
  2750. if (i == ARRAYLENGTH(sd->skillatk))
  2751. { //Better mention this so the array length can be updated. [Skotlex]
  2752. ShowDebug("run_script: bonus2 bSkillAtk reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillatk), type2, val);
  2753. break;
  2754. }
  2755. if (sd->skillatk[i].id == type2)
  2756. sd->skillatk[i].val += val;
  2757. else {
  2758. sd->skillatk[i].id = type2;
  2759. sd->skillatk[i].val = val;
  2760. }
  2761. break;
  2762. case SP_SKILL_HEAL:
  2763. if(sd->state.lr_flag == 2)
  2764. break;
  2765. ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == 0 || sd->skillheal[i].id == type2);
  2766. if (i == ARRAYLENGTH(sd->skillheal))
  2767. { // Better mention this so the array length can be updated. [Skotlex]
  2768. ShowDebug("run_script: bonus2 bSkillHeal reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal), type2, val);
  2769. break;
  2770. }
  2771. if (sd->skillheal[i].id == type2)
  2772. sd->skillheal[i].val += val;
  2773. else {
  2774. sd->skillheal[i].id = type2;
  2775. sd->skillheal[i].val = val;
  2776. }
  2777. break;
  2778. case SP_SKILL_HEAL2:
  2779. if(sd->state.lr_flag == 2)
  2780. break;
  2781. ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == 0 || sd->skillheal2[i].id == type2);
  2782. if (i == ARRAYLENGTH(sd->skillheal2))
  2783. { // Better mention this so the array length can be updated. [Skotlex]
  2784. ShowDebug("run_script: bonus2 bSkillHeal2 reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal2), type2, val);
  2785. break;
  2786. }
  2787. if (sd->skillheal2[i].id == type2)
  2788. sd->skillheal2[i].val += val;
  2789. else {
  2790. sd->skillheal2[i].id = type2;
  2791. sd->skillheal2[i].val = val;
  2792. }
  2793. break;
  2794. case SP_ADD_SKILL_BLOW:
  2795. if(sd->state.lr_flag == 2)
  2796. break;
  2797. ARR_FIND(0, ARRAYLENGTH(sd->skillblown), i, sd->skillblown[i].id == 0 || sd->skillblown[i].id == type2);
  2798. if (i == ARRAYLENGTH(sd->skillblown))
  2799. { //Better mention this so the array length can be updated. [Skotlex]
  2800. ShowDebug("run_script: bonus2 bSkillBlown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillblown), type2, val);
  2801. break;
  2802. }
  2803. if(sd->skillblown[i].id == type2)
  2804. sd->skillblown[i].val += val;
  2805. else {
  2806. sd->skillblown[i].id = type2;
  2807. sd->skillblown[i].val = val;
  2808. }
  2809. break;
  2810. #ifndef RENEWAL_CAST
  2811. case SP_VARCASTRATE:
  2812. #endif
  2813. case SP_CASTRATE:
  2814. if(sd->state.lr_flag == 2)
  2815. break;
  2816. ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2);
  2817. if (i == ARRAYLENGTH(sd->skillcast))
  2818. { //Better mention this so the array length can be updated. [Skotlex]
  2819. ShowDebug("run_script: bonus2 %s reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",
  2820. #ifndef RENEWAL_CAST
  2821. "bCastRate",
  2822. #else
  2823. "bVariableCastrate",
  2824. #endif
  2825. ARRAYLENGTH(sd->skillcast), type2, val);
  2826. break;
  2827. }
  2828. if(sd->skillcast[i].id == type2)
  2829. sd->skillcast[i].val += val;
  2830. else {
  2831. sd->skillcast[i].id = type2;
  2832. sd->skillcast[i].val = val;
  2833. }
  2834. break;
  2835. case SP_FIXCASTRATE:
  2836. if(sd->state.lr_flag == 2)
  2837. break;
  2838. ARR_FIND(0, ARRAYLENGTH(sd->skillfixcastrate), i, sd->skillfixcastrate[i].id == 0 || sd->skillfixcastrate[i].id == type2);
  2839. if (i == ARRAYLENGTH(sd->skillfixcastrate))
  2840. {
  2841. ShowDebug("run_script: bonus2 bFixedCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcastrate), type2, val);
  2842. break;
  2843. }
  2844. if(sd->skillfixcastrate[i].id == type2)
  2845. sd->skillfixcastrate[i].val += val;
  2846. else {
  2847. sd->skillfixcastrate[i].id = type2;
  2848. sd->skillfixcastrate[i].val = val;
  2849. }
  2850. break;
  2851. case SP_HP_LOSS_RATE:
  2852. if(sd->state.lr_flag != 2) {
  2853. sd->hp_loss.value = type2;
  2854. sd->hp_loss.rate = val;
  2855. }
  2856. break;
  2857. case SP_HP_REGEN_RATE:
  2858. if(sd->state.lr_flag != 2) {
  2859. sd->hp_regen.value = type2;
  2860. sd->hp_regen.rate = val;
  2861. }
  2862. break;
  2863. case SP_ADDRACE2:
  2864. if (!(type2 > RC2_NONE && type2 < RC2_MAX))
  2865. break;
  2866. if(sd->state.lr_flag != 2)
  2867. sd->right_weapon.addrace2[type2] += val;
  2868. else
  2869. sd->left_weapon.addrace2[type2] += val;
  2870. break;
  2871. case SP_SUBSIZE:
  2872. if(sd->state.lr_flag != 2)
  2873. sd->subsize[type2]+=val;
  2874. break;
  2875. case SP_SUBRACE2:
  2876. if (!(type2 > RC2_NONE && type2 < RC2_MAX))
  2877. break;
  2878. if(sd->state.lr_flag != 2)
  2879. sd->subrace2[type2]+=val;
  2880. break;
  2881. case SP_ADD_ITEM_HEAL_RATE:
  2882. if(sd->state.lr_flag == 2)
  2883. break;
  2884. if (type2 < MAX_ITEMGROUP) { //Group bonus
  2885. sd->itemgrouphealrate[type2] += val;
  2886. break;
  2887. }
  2888. //Standard item bonus.
  2889. for(i=0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++);
  2890. if(i == ARRAYLENGTH(sd->itemhealrate)) {
  2891. ShowWarning("pc_bonus2: Reached max (%d) number of item heal bonuses per character!\n", ARRAYLENGTH(sd->itemhealrate));
  2892. break;
  2893. }
  2894. sd->itemhealrate[i].nameid = type2;
  2895. sd->itemhealrate[i].rate += val;
  2896. break;
  2897. case SP_EXP_ADDRACE:
  2898. if(sd->state.lr_flag != 2)
  2899. sd->expaddrace[type2]+=val;
  2900. break;
  2901. case SP_EXP_ADDCLASS:
  2902. if(sd->state.lr_flag != 2)
  2903. sd->expaddclass[type2]+=val;
  2904. break;
  2905. case SP_SP_GAIN_RACE:
  2906. if(sd->state.lr_flag != 2)
  2907. sd->sp_gain_race[type2]+=val;
  2908. break;
  2909. case SP_ADD_MONSTER_DROP_ITEM:
  2910. if (sd->state.lr_flag != 2)
  2911. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, CLASS_ALL, RC_NONE_, val);
  2912. break;
  2913. case SP_ADD_MONSTER_DROP_ITEMGROUP:
  2914. if (sd->state.lr_flag != 2)
  2915. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, CLASS_ALL, RC_NONE_, val);
  2916. break;
  2917. case SP_SP_LOSS_RATE:
  2918. if(sd->state.lr_flag != 2) {
  2919. sd->sp_loss.value = type2;
  2920. sd->sp_loss.rate = val;
  2921. }
  2922. break;
  2923. case SP_SP_REGEN_RATE:
  2924. if(sd->state.lr_flag != 2) {
  2925. sd->sp_regen.value = type2;
  2926. sd->sp_regen.rate = val;
  2927. }
  2928. break;
  2929. case SP_HP_DRAIN_VALUE_RACE:
  2930. if(!sd->state.lr_flag) {
  2931. sd->right_weapon.hp_drain_race[type2].value += val;
  2932. }
  2933. else if(sd->state.lr_flag == 1) {
  2934. sd->left_weapon.hp_drain_race[type2].value += val;
  2935. }
  2936. break;
  2937. case SP_SP_DRAIN_VALUE_RACE:
  2938. if(!sd->state.lr_flag) {
  2939. sd->right_weapon.sp_drain_race[type2].value += val;
  2940. }
  2941. else if(sd->state.lr_flag == 1) {
  2942. sd->left_weapon.sp_drain_race[type2].value += val;
  2943. }
  2944. break;
  2945. case SP_HP_DRAIN_VALUE_CLASS:
  2946. if(!sd->state.lr_flag) {
  2947. sd->right_weapon.hp_drain_class[type2].value += val;
  2948. }
  2949. else if(sd->state.lr_flag == 1) {
  2950. sd->left_weapon.hp_drain_class[type2].value += val;
  2951. }
  2952. break;
  2953. case SP_SP_DRAIN_VALUE_CLASS:
  2954. if(!sd->state.lr_flag) {
  2955. sd->right_weapon.sp_drain_class[type2].value += val;
  2956. }
  2957. else if(sd->state.lr_flag == 1) {
  2958. sd->left_weapon.sp_drain_class[type2].value += val;
  2959. }
  2960. break;
  2961. case SP_IGNORE_MDEF_RACE_RATE:
  2962. if(sd->state.lr_flag != 2)
  2963. sd->ignore_mdef_by_race[type2] += val;
  2964. break;
  2965. case SP_IGNORE_MDEF_CLASS_RATE:
  2966. if(sd->state.lr_flag != 2)
  2967. sd->ignore_mdef_by_class[type2] += val;
  2968. break;
  2969. case SP_IGNORE_DEF_RACE_RATE:
  2970. if(sd->state.lr_flag != 2)
  2971. sd->ignore_def_by_race[type2] += val;
  2972. break;
  2973. case SP_SP_GAIN_RACE_ATTACK:
  2974. if(sd->state.lr_flag != 2)
  2975. sd->sp_gain_race_attack[type2] = cap_value(sd->sp_gain_race_attack[type2] + val, 0, INT16_MAX);
  2976. break;
  2977. case SP_HP_GAIN_RACE_ATTACK:
  2978. if(sd->state.lr_flag != 2)
  2979. sd->hp_gain_race_attack[type2] = cap_value(sd->hp_gain_race_attack[type2] + val, 0, INT16_MAX);
  2980. break;
  2981. case SP_SKILL_USE_SP_RATE: //bonus2 bSkillUseSPrate,n,x;
  2982. if(sd->state.lr_flag == 2)
  2983. break;
  2984. ARR_FIND(0, ARRAYLENGTH(sd->skillusesprate), i, sd->skillusesprate[i].id == 0 || sd->skillusesprate[i].id == type2);
  2985. if (i == ARRAYLENGTH(sd->skillusesprate)) {
  2986. ShowDebug("run_script: bonus2 bSkillUseSPrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesprate), type2, val);
  2987. break;
  2988. }
  2989. if (sd->skillusesprate[i].id == type2)
  2990. sd->skillusesprate[i].val += val;
  2991. else {
  2992. sd->skillusesprate[i].id = type2;
  2993. sd->skillusesprate[i].val = val;
  2994. }
  2995. break;
  2996. case SP_SKILL_COOLDOWN:
  2997. if(sd->state.lr_flag == 2)
  2998. break;
  2999. ARR_FIND(0, ARRAYLENGTH(sd->skillcooldown), i, sd->skillcooldown[i].id == 0 || sd->skillcooldown[i].id == type2);
  3000. if (i == ARRAYLENGTH(sd->skillcooldown))
  3001. {
  3002. ShowDebug("run_script: bonus2 bSkillCoolDown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillcooldown), type2, val);
  3003. break;
  3004. }
  3005. if (sd->skillcooldown[i].id == type2)
  3006. sd->skillcooldown[i].val += val;
  3007. else {
  3008. sd->skillcooldown[i].id = type2;
  3009. sd->skillcooldown[i].val = val;
  3010. }
  3011. break;
  3012. case SP_SKILL_FIXEDCAST:
  3013. if(sd->state.lr_flag == 2)
  3014. break;
  3015. ARR_FIND(0, ARRAYLENGTH(sd->skillfixcast), i, sd->skillfixcast[i].id == 0 || sd->skillfixcast[i].id == type2);
  3016. if (i == ARRAYLENGTH(sd->skillfixcast))
  3017. {
  3018. ShowDebug("run_script: bonus2 bSkillFixedCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcast), type2, val);
  3019. break;
  3020. }
  3021. if (sd->skillfixcast[i].id == type2)
  3022. sd->skillfixcast[i].val += val;
  3023. else {
  3024. sd->skillfixcast[i].id = type2;
  3025. sd->skillfixcast[i].val = val;
  3026. }
  3027. break;
  3028. case SP_SKILL_VARIABLECAST:
  3029. if(sd->state.lr_flag == 2)
  3030. break;
  3031. ARR_FIND(0, ARRAYLENGTH(sd->skillvarcast), i, sd->skillvarcast[i].id == 0 || sd->skillvarcast[i].id == type2);
  3032. if (i == ARRAYLENGTH(sd->skillvarcast))
  3033. {
  3034. ShowDebug("run_script: bonus2 bSkillVariableCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillvarcast), type2, val);
  3035. break;
  3036. }
  3037. if (sd->skillvarcast[i].id == type2)
  3038. sd->skillvarcast[i].val += val;
  3039. else {
  3040. sd->skillvarcast[i].id = type2;
  3041. sd->skillvarcast[i].val = val;
  3042. }
  3043. break;
  3044. #ifdef RENEWAL_CAST
  3045. case SP_VARCASTRATE:
  3046. if(sd->state.lr_flag == 2)
  3047. break;
  3048. ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2);
  3049. if (i == ARRAYLENGTH(sd->skillcast))
  3050. {
  3051. ShowDebug("run_script: bonus2 bVariableCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",ARRAYLENGTH(sd->skillcast), type2, val);
  3052. break;
  3053. }
  3054. if(sd->skillcast[i].id == type2)
  3055. sd->skillcast[i].val -= val;
  3056. else {
  3057. sd->skillcast[i].id = type2;
  3058. sd->skillcast[i].val -= val;
  3059. }
  3060. break;
  3061. #endif
  3062. case SP_SKILL_USE_SP: //bonus2 bSkillUseSP,n,x;
  3063. if(sd->state.lr_flag == 2)
  3064. break;
  3065. ARR_FIND(0, ARRAYLENGTH(sd->skillusesp), i, sd->skillusesp[i].id == 0 || sd->skillusesp[i].id == type2);
  3066. if (i == ARRAYLENGTH(sd->skillusesp)) {
  3067. ShowDebug("run_script: bonus2 bSkillUseSP reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesp), type2, val);
  3068. break;
  3069. }
  3070. if (sd->skillusesp[i].id == type2)
  3071. sd->skillusesp[i].val += val;
  3072. else {
  3073. sd->skillusesp[i].id = type2;
  3074. sd->skillusesp[i].val = val;
  3075. }
  3076. break;
  3077. default:
  3078. ShowWarning("pc_bonus2: unknown type %d %d %d!\n",type,type2,val);
  3079. break;
  3080. }
  3081. return 0;
  3082. }
  3083. int pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
  3084. {
  3085. nullpo_ret(sd);
  3086. switch(type){
  3087. case SP_ADD_MONSTER_DROP_ITEM:
  3088. if(sd->state.lr_flag != 2)
  3089. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, CLASS_NONE, type3, val);
  3090. break;
  3091. case SP_ADD_MONSTER_ID_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_CLASS_DROP_ITEM:
  3096. if(sd->state.lr_flag != 2)
  3097. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, type3, RC_NONE_, val);
  3098. break;
  3099. case SP_AUTOSPELL:
  3100. if(sd->state.lr_flag != 2)
  3101. {
  3102. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3103. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3104. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell),
  3105. target?-type2:type2, type3, val, 0, current_equip_card_id);
  3106. }
  3107. break;
  3108. case SP_AUTOSPELL_WHENHIT:
  3109. if(sd->state.lr_flag != 2)
  3110. {
  3111. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3112. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3113. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2),
  3114. target?-type2:type2, type3, val, BF_NORMAL|BF_SKILL, current_equip_card_id);
  3115. }
  3116. break;
  3117. case SP_SP_DRAIN_RATE:
  3118. if(!sd->state.lr_flag) {
  3119. sd->right_weapon.sp_drain_class[CLASS_NORMAL].rate += type2;
  3120. sd->right_weapon.sp_drain_class[CLASS_NORMAL].per += type3;
  3121. sd->right_weapon.sp_drain_class[CLASS_NORMAL].type = val;
  3122. sd->right_weapon.sp_drain_class[CLASS_BOSS].rate += type2;
  3123. sd->right_weapon.sp_drain_class[CLASS_BOSS].per += type3;
  3124. sd->right_weapon.sp_drain_class[CLASS_BOSS].type = val;
  3125. }
  3126. else if(sd->state.lr_flag == 1) {
  3127. sd->left_weapon.sp_drain_class[CLASS_NORMAL].rate += type2;
  3128. sd->left_weapon.sp_drain_class[CLASS_NORMAL].per += type3;
  3129. sd->left_weapon.sp_drain_class[CLASS_NORMAL].type = val;
  3130. sd->left_weapon.sp_drain_class[CLASS_BOSS].rate += type2;
  3131. sd->left_weapon.sp_drain_class[CLASS_BOSS].per += type3;
  3132. sd->left_weapon.sp_drain_class[CLASS_BOSS].type = val;
  3133. }
  3134. break;
  3135. case SP_ADD_MONSTER_DROP_ITEMGROUP:
  3136. if (sd->state.lr_flag != 2)
  3137. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, CLASS_NONE, type3, val);
  3138. break;
  3139. case SP_ADD_CLASS_DROP_ITEMGROUP:
  3140. if (sd->state.lr_flag != 2)
  3141. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, type3, RC_NONE_, val);
  3142. break;
  3143. case SP_ADDEFF:
  3144. if (type2 > SC_MAX) {
  3145. ShowWarning("pc_bonus3 (Add Effect): %d is not supported.\n", type2);
  3146. break;
  3147. }
  3148. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  3149. sd->state.lr_flag!=2?type3:0, sd->state.lr_flag==2?type3:0, val);
  3150. break;
  3151. case SP_ADDEFF_WHENHIT:
  3152. if (type2 > SC_MAX) {
  3153. ShowWarning("pc_bonus3 (Add Effect when hit): %d is not supported.\n", type2);
  3154. break;
  3155. }
  3156. if(sd->state.lr_flag != 2)
  3157. pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, type3, 0, val);
  3158. break;
  3159. case SP_ADDEFF_ONSKILL:
  3160. if( type3 > SC_MAX ) {
  3161. ShowWarning("pc_bonus3 (Add Effect on skill): %d is not supported.\n", type3);
  3162. break;
  3163. }
  3164. if( sd->state.lr_flag != 2 )
  3165. pc_bonus_addeff_onskill(sd->addeff3, ARRAYLENGTH(sd->addeff3), (sc_type)type3, val, type2, ATF_TARGET);
  3166. break;
  3167. case SP_ADDELE:
  3168. if (type2 > ELE_ALL) {
  3169. ShowWarning("pc_bonus3 (SP_ADDELE): element %d is out of range.\n", type2);
  3170. break;
  3171. }
  3172. if (sd->state.lr_flag != 2)
  3173. pc_bonus_addele(sd, (unsigned char)type2, type3, val);
  3174. break;
  3175. case SP_SUBELE:
  3176. if (type2 > ELE_ALL) {
  3177. ShowWarning("pc_bonus3 (SP_SUBELE): element %d is out of range.\n", type2);
  3178. break;
  3179. }
  3180. if (sd->state.lr_flag != 2)
  3181. pc_bonus_subele(sd, (unsigned char)type2, type3, val);
  3182. break;
  3183. default:
  3184. ShowWarning("pc_bonus3: unknown type %d %d %d %d!\n",type,type2,type3,val);
  3185. break;
  3186. }
  3187. return 0;
  3188. }
  3189. int pc_bonus4(struct map_session_data *sd,int type,int type2,int type3,int type4,int val)
  3190. {
  3191. nullpo_ret(sd);
  3192. switch(type){
  3193. case SP_AUTOSPELL:
  3194. if(sd->state.lr_flag != 2)
  3195. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
  3196. break;
  3197. case SP_AUTOSPELL_WHENHIT:
  3198. if(sd->state.lr_flag != 2)
  3199. 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);
  3200. break;
  3201. case SP_AUTOSPELL_ONSKILL:
  3202. if(sd->state.lr_flag != 2)
  3203. {
  3204. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3205. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3206. pc_bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, target?-type3:type3, type4, val, current_equip_card_id);
  3207. }
  3208. break;
  3209. case SP_ADDEFF_ONSKILL:
  3210. if( type2 > SC_MAX ) {
  3211. ShowWarning("pc_bonus4 (Add Effect on skill): %d is not supported.\n", type2);
  3212. break;
  3213. }
  3214. if( sd->state.lr_flag != 2 )
  3215. pc_bonus_addeff_onskill(sd->addeff3, ARRAYLENGTH(sd->addeff3), (sc_type)type3, type4, type2, val);
  3216. break;
  3217. case SP_DEF_SET: //bonus4 bSetDefRace,n,x,r,y;
  3218. if( type2 > RC_ALL ) {
  3219. ShowWarning("pc_bonus4 (DEF_SET): %d is not supported.\n", type2);
  3220. break;
  3221. }
  3222. if(sd->state.lr_flag == 2)
  3223. break;
  3224. sd->def_set_race[type2].rate = type3;
  3225. sd->def_set_race[type2].tick = type4;
  3226. sd->def_set_race[type2].value = val;
  3227. break;
  3228. case SP_MDEF_SET: //bonus4 bSetMDefRace,n,x,r,y;
  3229. if( type2 > RC_ALL ) {
  3230. ShowWarning("pc_bonus4 (MDEF_SET): %d is not supported.\n", type2);
  3231. break;
  3232. }
  3233. if(sd->state.lr_flag == 2)
  3234. break;
  3235. sd->mdef_set_race[type2].rate = type3;
  3236. sd->mdef_set_race[type2].tick = type4;
  3237. sd->mdef_set_race[type2].value = val;
  3238. break;
  3239. default:
  3240. ShowWarning("pc_bonus4: unknown type %d %d %d %d %d!\n",type,type2,type3,type4,val);
  3241. break;
  3242. }
  3243. return 0;
  3244. }
  3245. int pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4,int type5,int val)
  3246. {
  3247. nullpo_ret(sd);
  3248. switch(type){
  3249. case SP_AUTOSPELL:
  3250. if(sd->state.lr_flag != 2)
  3251. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  3252. break;
  3253. case SP_AUTOSPELL_WHENHIT:
  3254. if(sd->state.lr_flag != 2)
  3255. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  3256. break;
  3257. case SP_AUTOSPELL_ONSKILL:
  3258. if(sd->state.lr_flag != 2)
  3259. pc_bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, (val&1?-type3:type3), (val&2?-type4:type4), type5, current_equip_card_id);
  3260. break;
  3261. default:
  3262. ShowWarning("pc_bonus5: unknown type %d %d %d %d %d %d!\n",type,type2,type3,type4,type5,val);
  3263. break;
  3264. }
  3265. return 0;
  3266. }
  3267. /*==========================================
  3268. * Grants a player a given skill. Flag values are:
  3269. * 0 - Grant permanent skill to be bound to skill tree
  3270. * 1 - Grant an item skill (temporary)
  3271. * 2 - Like 1, except the level granted can stack with previously learned level.
  3272. * 4 - Like 0, except the skill will ignore skill tree (saves through job changes and resets).
  3273. *------------------------------------------*/
  3274. int pc_skill(TBL_PC* sd, int id, int level, int flag)
  3275. {
  3276. nullpo_ret(sd);
  3277. if( id <= 0 || id >= MAX_SKILL || skill_db[id].name == NULL) {
  3278. ShowError("pc_skill: Skill with id %d does not exist in the skill database\n", id);
  3279. return 0;
  3280. }
  3281. if( level > MAX_SKILL_LEVEL ) {
  3282. ShowError("pc_skill: Skill level %d too high. Max lv supported is %d\n", level, MAX_SKILL_LEVEL);
  3283. return 0;
  3284. }
  3285. if( flag == 2 && sd->status.skill[id].lv + level > MAX_SKILL_LEVEL ) {
  3286. 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);
  3287. return 0;
  3288. }
  3289. switch( flag ){
  3290. case 0: //Set skill data overwriting whatever was there before.
  3291. sd->status.skill[id].id = id;
  3292. sd->status.skill[id].lv = level;
  3293. sd->status.skill[id].flag = SKILL_FLAG_PERMANENT;
  3294. if( level == 0 ) { //Remove skill.
  3295. sd->status.skill[id].id = 0;
  3296. clif_deleteskill(sd,id);
  3297. } else
  3298. clif_addskill(sd,id);
  3299. if( !skill_get_inf(id) ) //Only recalculate for passive skills.
  3300. status_calc_pc(sd, 0);
  3301. break;
  3302. case 1: //Item bonus skill.
  3303. if( sd->status.skill[id].id == id ){
  3304. if( sd->status.skill[id].lv >= level )
  3305. return 0;
  3306. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT ) //Non-granted skill, store it's level.
  3307. sd->status.skill[id].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[id].lv;
  3308. } else {
  3309. sd->status.skill[id].id = id;
  3310. sd->status.skill[id].flag = SKILL_FLAG_TEMPORARY;
  3311. }
  3312. sd->status.skill[id].lv = level;
  3313. break;
  3314. case 2: //Add skill bonus on top of what you had.
  3315. if( sd->status.skill[id].id == id ){
  3316. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  3317. sd->status.skill[id].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[id].lv; // Store previous level.
  3318. } else {
  3319. sd->status.skill[id].id = id;
  3320. sd->status.skill[id].flag = SKILL_FLAG_TEMPORARY; //Set that this is a bonus skill.
  3321. }
  3322. sd->status.skill[id].lv += level;
  3323. break;
  3324. case 4: //Permanent granted skills ignore the skill tree
  3325. sd->status.skill[id].id = id;
  3326. sd->status.skill[id].lv = level;
  3327. sd->status.skill[id].flag = SKILL_FLAG_PERM_GRANTED;
  3328. if( level == 0 ) { //Remove skill.
  3329. sd->status.skill[id].id = 0;
  3330. clif_deleteskill(sd,id);
  3331. } else
  3332. clif_addskill(sd,id);
  3333. if( !skill_get_inf(id) ) //Only recalculate for passive skills.
  3334. status_calc_pc(sd, 0);
  3335. break;
  3336. default: //Unknown flag?
  3337. return 0;
  3338. }
  3339. return 1;
  3340. }
  3341. /*==========================================
  3342. * Append a card to an item ?
  3343. *------------------------------------------*/
  3344. int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip)
  3345. {
  3346. int i;
  3347. int nameid;
  3348. nullpo_ret(sd);
  3349. if( idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL )
  3350. return 0; //Invalid item index.
  3351. if( idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL )
  3352. return 0; //Invalid card index.
  3353. if( sd->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1 )
  3354. return 0; // target item missing
  3355. if( sd->status.inventory[idx_card].nameid <= 0 || sd->status.inventory[idx_card].amount < 1 )
  3356. return 0; // target card missing
  3357. if( sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR )
  3358. return 0; // only weapons and armor are allowed
  3359. if( sd->inventory_data[idx_card]->type != IT_CARD )
  3360. return 0; // must be a card
  3361. if( sd->status.inventory[idx_equip].identify == 0 )
  3362. return 0; // target must be identified
  3363. if( itemdb_isspecial(sd->status.inventory[idx_equip].card[0]) )
  3364. return 0; // card slots reserved for other purposes
  3365. if( (sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0 )
  3366. return 0; // card cannot be compounded on this item type
  3367. if( sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD )
  3368. return 0; // attempted to place shield card on left-hand weapon.
  3369. if( sd->status.inventory[idx_equip].equip != 0 )
  3370. return 0; // item must be unequipped
  3371. ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0 );
  3372. if( i == sd->inventory_data[idx_equip]->slot )
  3373. return 0; // no free slots
  3374. // remember the card id to insert
  3375. nameid = sd->status.inventory[idx_card].nameid;
  3376. if( pc_delitem(sd,idx_card,1,1,0,LOG_TYPE_OTHER) == 1 )
  3377. {// failed
  3378. clif_insert_card(sd,idx_equip,idx_card,1);
  3379. }
  3380. else
  3381. {// success
  3382. log_pick_pc(sd, LOG_TYPE_OTHER, -1, &sd->status.inventory[idx_equip]);
  3383. sd->status.inventory[idx_equip].card[i] = nameid;
  3384. log_pick_pc(sd, LOG_TYPE_OTHER, 1, &sd->status.inventory[idx_equip]);
  3385. clif_insert_card(sd,idx_equip,idx_card,0);
  3386. }
  3387. return 0;
  3388. }
  3389. //
  3390. // Items
  3391. //
  3392. /*==========================================
  3393. * Update buying value by skills
  3394. *------------------------------------------*/
  3395. int pc_modifybuyvalue(struct map_session_data *sd,int orig_value)
  3396. {
  3397. int skill,val = orig_value,rate1 = 0,rate2 = 0;
  3398. if((skill=pc_checkskill(sd,MC_DISCOUNT))>0) // merchant discount
  3399. rate1 = 5+skill*2-((skill==10)? 1:0);
  3400. if((skill=pc_checkskill(sd,RG_COMPULSION))>0) // rogue discount
  3401. rate2 = 5+skill*4;
  3402. if(rate1 < rate2) rate1 = rate2;
  3403. if(rate1)
  3404. val = (int)((double)orig_value*(double)(100-rate1)/100.);
  3405. if(val < 0) val = 0;
  3406. if(orig_value > 0 && val < 1) val = 1;
  3407. return val;
  3408. }
  3409. /*==========================================
  3410. * Update selling value by skills
  3411. *------------------------------------------*/
  3412. int pc_modifysellvalue(struct map_session_data *sd,int orig_value)
  3413. {
  3414. int skill,val = orig_value,rate = 0;
  3415. if((skill=pc_checkskill(sd,MC_OVERCHARGE))>0) //OverCharge
  3416. rate = 5+skill*2-((skill==10)? 1:0);
  3417. if(rate)
  3418. val = (int)((double)orig_value*(double)(100+rate)/100.);
  3419. if(val < 0) val = 0;
  3420. if(orig_value > 0 && val < 1) val = 1;
  3421. return val;
  3422. }
  3423. /*==========================================
  3424. * Checking if we have enough place on inventory for new item
  3425. * Make sure to take 30k as limit (for client I guess)
  3426. *------------------------------------------*/
  3427. int pc_checkadditem(struct map_session_data *sd,int nameid,int amount)
  3428. {
  3429. int i;
  3430. struct item_data* data;
  3431. nullpo_ret(sd);
  3432. if(amount > MAX_AMOUNT)
  3433. return CHKADDITEM_OVERAMOUNT;
  3434. data = itemdb_search(nameid);
  3435. if(!itemdb_isstackable2(data))
  3436. return CHKADDITEM_NEW;
  3437. if( data->stack.inventory && amount > data->stack.amount )
  3438. return CHKADDITEM_OVERAMOUNT;
  3439. for(i=0;i<MAX_INVENTORY;i++){
  3440. // FIXME: This does not consider the checked item's cards, thus could check a wrong slot for stackability.
  3441. if(sd->status.inventory[i].nameid==nameid){
  3442. if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) )
  3443. return CHKADDITEM_OVERAMOUNT;
  3444. return CHKADDITEM_EXIST;
  3445. }
  3446. }
  3447. return CHKADDITEM_NEW;
  3448. }
  3449. /*==========================================
  3450. * Return number of available place in inventory
  3451. * Each non stackable item will reduce place by 1
  3452. *------------------------------------------*/
  3453. int pc_inventoryblank(struct map_session_data *sd)
  3454. {
  3455. int i,b;
  3456. nullpo_ret(sd);
  3457. for(i=0,b=0;i<MAX_INVENTORY;i++){
  3458. if(sd->status.inventory[i].nameid==0)
  3459. b++;
  3460. }
  3461. return b;
  3462. }
  3463. /*==========================================
  3464. * attempts to remove zeny from player (sd)
  3465. *------------------------------------------*/
  3466. int pc_payzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type, struct map_session_data *tsd)
  3467. {
  3468. nullpo_retr(-1,sd);
  3469. zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3470. if( zeny < 0 )
  3471. {
  3472. ShowError("pc_payzeny: Paying negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
  3473. return 1;
  3474. }
  3475. if( sd->status.zeny < zeny )
  3476. return 1; //Not enough.
  3477. sd->status.zeny -= zeny;
  3478. clif_updatestatus(sd,SP_ZENY);
  3479. if(!tsd) tsd = sd;
  3480. log_zeny(sd, type, tsd, -zeny);
  3481. if( zeny > 0 && sd->state.showzeny ) {
  3482. char output[255];
  3483. sprintf(output, "Removed %dz.", zeny);
  3484. clif_disp_onlyself(sd,output,strlen(output));
  3485. }
  3486. return 0;
  3487. }
  3488. /*==========================================
  3489. * Cash Shop
  3490. *------------------------------------------*/
  3491. int pc_paycash(struct map_session_data *sd, int price, int points, e_log_pick_type type ){
  3492. int cash;
  3493. nullpo_retr(-1,sd);
  3494. points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3495. if( price < 0 || points < 0 )
  3496. {
  3497. 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);
  3498. return -2;
  3499. }
  3500. if( points > price )
  3501. {
  3502. 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);
  3503. points = price;
  3504. }
  3505. cash = price-points;
  3506. if( sd->cashPoints < cash || sd->kafraPoints < points )
  3507. {
  3508. 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);
  3509. return -1;
  3510. }
  3511. pc_setaccountreg(sd, "#CASHPOINTS", sd->cashPoints-cash);
  3512. if( cash ){
  3513. log_cash( sd, type, LOG_CASH_TYPE_CASH, -cash );
  3514. }
  3515. pc_setaccountreg(sd, "#KAFRAPOINTS", sd->kafraPoints-points);
  3516. if( points ){
  3517. log_cash( sd, type, LOG_CASH_TYPE_KAFRA, -points );
  3518. }
  3519. if( battle_config.cashshop_show_points )
  3520. {
  3521. char output[128];
  3522. sprintf(output, msg_txt(sd,504), points, cash, sd->kafraPoints, sd->cashPoints);
  3523. clif_disp_onlyself(sd, output, strlen(output));
  3524. }
  3525. return cash+points;
  3526. }
  3527. int pc_getcash( struct map_session_data *sd, int cash, int points, e_log_pick_type type ){
  3528. char output[128];
  3529. nullpo_retr(-1,sd);
  3530. cash = cap_value(cash,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3531. points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3532. if( cash > 0 )
  3533. {
  3534. if( cash > MAX_ZENY-sd->cashPoints )
  3535. {
  3536. 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);
  3537. cash = MAX_ZENY-sd->cashPoints;
  3538. }
  3539. pc_setaccountreg(sd, "#CASHPOINTS", sd->cashPoints+cash);
  3540. if( cash ){
  3541. log_cash( sd, type, LOG_CASH_TYPE_CASH, cash );
  3542. }
  3543. if( battle_config.cashshop_show_points )
  3544. {
  3545. sprintf(output, msg_txt(sd,505), cash, sd->cashPoints);
  3546. clif_disp_onlyself(sd, output, strlen(output));
  3547. }
  3548. return cash;
  3549. }
  3550. else if( cash < 0 )
  3551. {
  3552. 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);
  3553. return -1;
  3554. }
  3555. if( points > 0 )
  3556. {
  3557. if( points > MAX_ZENY-sd->kafraPoints )
  3558. {
  3559. 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);
  3560. points = MAX_ZENY-sd->kafraPoints;
  3561. }
  3562. pc_setaccountreg(sd, "#KAFRAPOINTS", sd->kafraPoints+points);
  3563. if( points ){
  3564. log_cash( sd, type, LOG_CASH_TYPE_KAFRA, points );
  3565. }
  3566. if( battle_config.cashshop_show_points )
  3567. {
  3568. sprintf(output, msg_txt(sd,506), points, sd->kafraPoints);
  3569. clif_disp_onlyself(sd, output, strlen(output));
  3570. }
  3571. return points;
  3572. }
  3573. else if( points < 0 )
  3574. {
  3575. 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);
  3576. return -1;
  3577. }
  3578. return -2; //shouldn't happen but jsut in case
  3579. }
  3580. /*==========================================
  3581. * Attempts to give zeny to player (sd)
  3582. * tsd (optional) from who for log (if null take sd)
  3583. *------------------------------------------*/
  3584. int pc_getzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type, struct map_session_data *tsd)
  3585. {
  3586. nullpo_retr(-1,sd);
  3587. zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3588. if( zeny < 0 )
  3589. {
  3590. ShowError("pc_getzeny: Obtaining negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
  3591. return 1;
  3592. }
  3593. if( zeny > MAX_ZENY - sd->status.zeny )
  3594. zeny = MAX_ZENY - sd->status.zeny;
  3595. sd->status.zeny += zeny;
  3596. clif_updatestatus(sd,SP_ZENY);
  3597. if(!tsd) tsd = sd;
  3598. log_zeny(sd, type, tsd, zeny);
  3599. if( zeny > 0 && sd->state.showzeny ) {
  3600. char output[255];
  3601. sprintf(output, "Gained %dz.", zeny);
  3602. clif_disp_onlyself(sd,output,strlen(output));
  3603. }
  3604. return 0;
  3605. }
  3606. /*==========================================
  3607. * Searching a specified itemid in inventory and return his stored index
  3608. *------------------------------------------*/
  3609. int pc_search_inventory(struct map_session_data *sd,int item_id)
  3610. {
  3611. int i;
  3612. nullpo_retr(-1, sd);
  3613. ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == item_id && (sd->status.inventory[i].amount > 0 || item_id == 0) );
  3614. return ( i < MAX_INVENTORY ) ? i : -1;
  3615. }
  3616. /*==========================================
  3617. * Attempt to add a new item to inventory.
  3618. * Return:
  3619. 0 = success
  3620. 1 = invalid itemid not found or negative amount
  3621. 2 = overweight
  3622. 3 = ?
  3623. 4 = no free place found
  3624. 5 = max amount reached
  3625. 6 = ?
  3626. 7 = stack limitation
  3627. *------------------------------------------*/
  3628. int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type)
  3629. {
  3630. struct item_data *data;
  3631. int i;
  3632. unsigned int w;
  3633. nullpo_retr(1, sd);
  3634. nullpo_retr(1, item_data);
  3635. if( item_data->nameid <= 0 || amount <= 0 )
  3636. return ADDITEM_INVALID;
  3637. if( amount > MAX_AMOUNT )
  3638. return ADDITEM_OVERAMOUNT;
  3639. data = itemdb_search(item_data->nameid);
  3640. if( data->stack.inventory && amount > data->stack.amount )
  3641. {// item stack limitation
  3642. return ADDITEM_STACKLIMIT;
  3643. }
  3644. w = data->weight*amount;
  3645. if(sd->weight + w > sd->max_weight)
  3646. return ADDITEM_OVERWEIGHT;
  3647. i = MAX_INVENTORY;
  3648. if( itemdb_isstackable2(data) && item_data->expire_time == 0 )
  3649. { // Stackable | Non Rental
  3650. for( i = 0; i < MAX_INVENTORY; i++ )
  3651. {
  3652. 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 )
  3653. {
  3654. if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) )
  3655. return 5;
  3656. sd->status.inventory[i].amount += amount;
  3657. clif_additem(sd,i,amount,0);
  3658. break;
  3659. }
  3660. }
  3661. }
  3662. if( i >= MAX_INVENTORY )
  3663. {
  3664. i = pc_search_inventory(sd,0);
  3665. if( i < 0 )
  3666. return ADDITEM_OVERITEM;
  3667. memcpy(&sd->status.inventory[i], item_data, sizeof(sd->status.inventory[0]));
  3668. // clear equips field first, just in case
  3669. if( item_data->equip )
  3670. sd->status.inventory[i].equip = 0;
  3671. sd->status.inventory[i].amount = amount;
  3672. sd->inventory_data[i] = data;
  3673. clif_additem(sd,i,amount,0);
  3674. }
  3675. #ifdef NSI_UNIQUE_ID
  3676. if( !itemdb_isstackable2(data) && !item_data->unique_id )
  3677. sd->status.inventory[i].unique_id = itemdb_unique_id(0,0);
  3678. #endif
  3679. log_pick_pc(sd, log_type, amount, &sd->status.inventory[i]);
  3680. sd->weight += w;
  3681. clif_updatestatus(sd,SP_WEIGHT);
  3682. //Auto-equip
  3683. if(data->flag.autoequip)
  3684. pc_equipitem(sd, i, data->equip);
  3685. /* rental item check */
  3686. if( item_data->expire_time ) {
  3687. if( time(NULL) > item_data->expire_time ) {
  3688. clif_rental_expired(sd->fd, i, sd->status.inventory[i].nameid);
  3689. pc_delitem(sd, i, sd->status.inventory[i].amount, 1, 0, LOG_TYPE_OTHER);
  3690. } else {
  3691. int seconds = (int)( item_data->expire_time - time(NULL) );
  3692. clif_rental_time(sd->fd, sd->status.inventory[i].nameid, seconds);
  3693. pc_inventory_rental_add(sd, seconds);
  3694. }
  3695. }
  3696. return ADDITEM_SUCCESS;
  3697. }
  3698. /*==========================================
  3699. * Remove an item at index n from inventory by amount.
  3700. * Parameters :
  3701. * @type
  3702. * 1 : don't notify deletion
  3703. * 2 : don't notify weight change
  3704. * Return:
  3705. * 0 = success
  3706. * 1 = invalid itemid or negative amount
  3707. *------------------------------------------*/
  3708. int pc_delitem(struct map_session_data *sd,int n,int amount,int type, short reason, e_log_pick_type log_type)
  3709. {
  3710. nullpo_retr(1, sd);
  3711. if(n < 0 || sd->status.inventory[n].nameid==0 || amount <= 0 || sd->status.inventory[n].amount<amount || sd->inventory_data[n] == NULL)
  3712. return 1;
  3713. log_pick_pc(sd, log_type, -amount, &sd->status.inventory[n]);
  3714. sd->status.inventory[n].amount -= amount;
  3715. sd->weight -= sd->inventory_data[n]->weight*amount ;
  3716. if( sd->status.inventory[n].amount <= 0 ){
  3717. if(sd->status.inventory[n].equip)
  3718. pc_unequipitem(sd,n,3);
  3719. memset(&sd->status.inventory[n],0,sizeof(sd->status.inventory[0]));
  3720. sd->inventory_data[n] = NULL;
  3721. }
  3722. if(!(type&1))
  3723. clif_delitem(sd,n,amount,reason);
  3724. if(!(type&2))
  3725. clif_updatestatus(sd,SP_WEIGHT);
  3726. return 0;
  3727. }
  3728. /*==========================================
  3729. * Attempt to drop an item.
  3730. * Return:
  3731. * 0 = fail
  3732. * 1 = success
  3733. *------------------------------------------*/
  3734. int pc_dropitem(struct map_session_data *sd,int n,int amount)
  3735. {
  3736. nullpo_retr(1, sd);
  3737. if(n < 0 || n >= MAX_INVENTORY)
  3738. return 0;
  3739. if(amount <= 0)
  3740. return 0;
  3741. if(sd->status.inventory[n].nameid <= 0 ||
  3742. sd->status.inventory[n].amount <= 0 ||
  3743. sd->status.inventory[n].amount < amount ||
  3744. sd->state.trading || sd->state.vending ||
  3745. !sd->inventory_data[n] //pc_delitem would fail on this case.
  3746. )
  3747. return 0;
  3748. if( map[sd->bl.m].flag.nodrop )
  3749. {
  3750. clif_displaymessage (sd->fd, msg_txt(sd,271));
  3751. return 0; //Can't drop items in nodrop mapflag maps.
  3752. }
  3753. if( !pc_candrop(sd,&sd->status.inventory[n]) )
  3754. {
  3755. clif_displaymessage (sd->fd, msg_txt(sd,263));
  3756. return 0;
  3757. }
  3758. if (!map_addflooritem(&sd->status.inventory[n], amount, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 2))
  3759. return 0;
  3760. pc_delitem(sd, n, amount, 1, 0, LOG_TYPE_PICKDROP_PLAYER);
  3761. clif_dropitem(sd, n, amount);
  3762. return 1;
  3763. }
  3764. /*==========================================
  3765. * Attempt to pick up an item.
  3766. * Return:
  3767. * 0 = fail
  3768. * 1 = success
  3769. *------------------------------------------*/
  3770. int pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem)
  3771. {
  3772. int flag=0;
  3773. unsigned int tick = gettick();
  3774. struct party_data *p=NULL;
  3775. nullpo_ret(sd);
  3776. nullpo_ret(fitem);
  3777. if(!check_distance_bl(&fitem->bl, &sd->bl, 2) && sd->ud.skill_id!=BS_GREED)
  3778. return 0; // Distance is too far
  3779. if( sd->sc.cant.pickup )
  3780. return 0;
  3781. if (sd->status.party_id)
  3782. p = party_search(sd->status.party_id);
  3783. if(fitem->first_get_charid > 0 && fitem->first_get_charid != sd->status.char_id) {
  3784. struct map_session_data *first_sd = map_charid2sd(fitem->first_get_charid);
  3785. if(DIFF_TICK(tick,fitem->first_get_tick) < 0) {
  3786. if (!(p && p->party.item&1 &&
  3787. first_sd && first_sd->status.party_id == sd->status.party_id
  3788. ))
  3789. return 0;
  3790. }
  3791. else if(fitem->second_get_charid > 0 && fitem->second_get_charid != sd->status.char_id) {
  3792. struct map_session_data *second_sd = map_charid2sd(fitem->second_get_charid);
  3793. if(DIFF_TICK(tick, fitem->second_get_tick) < 0) {
  3794. if(!(p && p->party.item&1 &&
  3795. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  3796. (second_sd && second_sd->status.party_id == sd->status.party_id))
  3797. ))
  3798. return 0;
  3799. }
  3800. else if(fitem->third_get_charid > 0 && fitem->third_get_charid != sd->status.char_id){
  3801. struct map_session_data *third_sd = map_charid2sd(fitem->third_get_charid);
  3802. if(DIFF_TICK(tick,fitem->third_get_tick) < 0) {
  3803. if(!(p && p->party.item&1 &&
  3804. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  3805. (second_sd && second_sd->status.party_id == sd->status.party_id) ||
  3806. (third_sd && third_sd->status.party_id == sd->status.party_id))
  3807. ))
  3808. return 0;
  3809. }
  3810. }
  3811. }
  3812. }
  3813. //This function takes care of giving the item to whoever should have it, considering party-share options.
  3814. if ((flag = party_share_loot(p,sd,&fitem->item_data, fitem->first_get_charid))) {
  3815. clif_additem(sd,0,0,flag);
  3816. return 1;
  3817. }
  3818. //Display pickup animation.
  3819. pc_stop_attack(sd);
  3820. clif_takeitem(&sd->bl,&fitem->bl);
  3821. map_clearflooritem(&fitem->bl);
  3822. return 1;
  3823. }
  3824. /*==========================================
  3825. * Check if item is usable.
  3826. * Return:
  3827. * 0 = no
  3828. * 1 = yes
  3829. *------------------------------------------*/
  3830. int pc_isUseitem(struct map_session_data *sd,int n)
  3831. {
  3832. struct item_data *item;
  3833. int nameid;
  3834. nullpo_ret(sd);
  3835. item = sd->inventory_data[n];
  3836. nameid = sd->status.inventory[n].nameid;
  3837. if( item == NULL )
  3838. return 0;
  3839. //Not consumable item
  3840. if( item->type != IT_HEALING && item->type != IT_USABLE && item->type != IT_CASH )
  3841. return 0;
  3842. if( !item->script ) //if it has no script, you can't really consume it!
  3843. return 0;
  3844. if (pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL))
  3845. return 1;
  3846. if(map[sd->bl.m].flag.noitemconsumption) //consumable but mapflag prevent it
  3847. return 0;
  3848. //Prevent mass item usage. [Skotlex]
  3849. if( DIFF_TICK(sd->canuseitem_tick,gettick()) > 0 ||
  3850. (itemdb_iscashfood(nameid) && DIFF_TICK(sd->canusecashfood_tick,gettick()) > 0)
  3851. )
  3852. return 0;
  3853. if( (item->item_usage.flag&NOUSE_SITTING) && (pc_issit(sd) == 1) && (pc_get_group_level(sd) < item->item_usage.override) ) {
  3854. return 0; // You cannot use this item while sitting.
  3855. }
  3856. if (sd->state.storage_flag && item->type != IT_CASH) {
  3857. clif_colormes(sd, color_table[COLOR_RED], msg_txt(sd,388));
  3858. return 0; // You cannot use this item while storage is open.
  3859. }
  3860. switch( nameid ) {
  3861. case ITEMID_ANODYNE:
  3862. if( map_flag_gvg(sd->bl.m) )
  3863. return 0;
  3864. case ITEMID_ALOEBERA:
  3865. if( pc_issit(sd) )
  3866. return 0;
  3867. break;
  3868. case ITEMID_WING_OF_FLY:
  3869. case ITEMID_GIANT_FLY_WING:
  3870. if( map[sd->bl.m].flag.noteleport || map_flag_gvg(sd->bl.m) ) {
  3871. clif_skill_teleportmessage(sd,0);
  3872. return 0;
  3873. }
  3874. case ITEMID_WING_OF_BUTTERFLY:
  3875. case ITEMID_DUN_TELE_SCROLL1:
  3876. case ITEMID_DUN_TELE_SCROLL2:
  3877. case ITEMID_DUN_TELE_SCROLL3:
  3878. case ITEMID_WOB_RUNE:
  3879. case ITEMID_WOB_SCHWALTZ:
  3880. case ITEMID_WOB_RACHEL:
  3881. case ITEMID_WOB_LOCAL:
  3882. case ITEMID_SIEGE_TELEPORT_SCROLL:
  3883. if( sd->duel_group && !battle_config.duel_allow_teleport ) {
  3884. clif_displaymessage(sd->fd, msg_txt(sd,663));
  3885. return 0;
  3886. }
  3887. if( nameid != 601 && nameid != 12212 && map[sd->bl.m].flag.noreturn )
  3888. return 0;
  3889. break;
  3890. case ITEMID_BRANCH_OF_DEAD_TREE:
  3891. case ITEMID_RED_POUCH_OF_SURPRISE:
  3892. case ITEMID_BLOODY_DEAD_BRANCH:
  3893. case ITEMID_PORING_BOX:
  3894. case ITEMID_TREASURE_CHEST_SUMMONED_II:
  3895. if( map[sd->bl.m].flag.nobranch || map_flag_gvg(sd->bl.m) )
  3896. return 0;
  3897. break;
  3898. case ITEMID_BUBBLE_GUM:
  3899. case ITEMID_COMP_BUBBLE_GUM:
  3900. if( sd->sc.data[SC_ITEMBOOST] )
  3901. return 0;
  3902. break;
  3903. case ITEMID_BATTLE_MANUAL:
  3904. case ITEMID_COMP_BATTLE_MANUAL:
  3905. case ITEMID_THICK_BATTLE_MANUAL:
  3906. case ITEMID_NOBLE_NAMEPLATE:
  3907. case ITEMID_BATTLE_MANUAL25:
  3908. case ITEMID_BATTLE_MANUAL100:
  3909. case ITEMID_BATTLE_MANUAL300:
  3910. if( sd->sc.data[SC_EXPBOOST] )
  3911. return 0;
  3912. break;
  3913. case ITEMID_JOB_MANUAL50:
  3914. if( sd->sc.data[SC_JEXPBOOST] )
  3915. return 0;
  3916. break;
  3917. case ITEMID_MERCENARY_RED_POTION:
  3918. case ITEMID_MERCENARY_BLUE_POTION:
  3919. case ITEMID_M_CENTER_POTION:
  3920. case ITEMID_M_AWAKENING_POTION:
  3921. case ITEMID_M_BERSERK_POTION:
  3922. if( sd->md == NULL || sd->md->db == NULL )
  3923. return 0;
  3924. if (sd->md->sc.data[SC_BERSERK] || sd->md->sc.data[SC_SATURDAYNIGHTFEVER])
  3925. return 0;
  3926. if( nameid == ITEMID_M_AWAKENING_POTION && sd->md->db->lv < 40 )
  3927. return 0;
  3928. if( nameid == ITEMID_M_BERSERK_POTION && sd->md->db->lv < 80 )
  3929. return 0;
  3930. break;
  3931. case ITEMID_NEURALIZER:
  3932. if( !map[sd->bl.m].flag.reset )
  3933. return 0;
  3934. break;
  3935. }
  3936. if( nameid >= ITEMID_BOW_MERCENARY_SCROLL1 && nameid <= ITEMID_SPEARMERCENARY_SCROLL10 && sd->md != NULL )
  3937. return 0; // Mercenary Scrolls
  3938. /**
  3939. * Only Rune Knights may use runes
  3940. **/
  3941. if( itemdb_is_rune(nameid) && (sd->class_&MAPID_THIRDMASK) != MAPID_RUNE_KNIGHT )
  3942. return 0;
  3943. /**
  3944. * Only GCross may use poisons
  3945. **/
  3946. else if( itemdb_is_poison(nameid) && (sd->class_&MAPID_THIRDMASK) != MAPID_GUILLOTINE_CROSS )
  3947. return 0;
  3948. //Gender check
  3949. if(item->sex != 2 && sd->status.sex != item->sex)
  3950. return 0;
  3951. //Required level check
  3952. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  3953. return 0;
  3954. #ifdef RENEWAL
  3955. if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
  3956. return 0;
  3957. #endif
  3958. //Not equipable by class. [Skotlex]
  3959. if (!(
  3960. (1<<(sd->class_&MAPID_BASEMASK)) &
  3961. (item->class_base[sd->class_&JOBL_2_1?1:(sd->class_&JOBL_2_2?2:0)])
  3962. ))
  3963. return 0;
  3964. if (sd->sc.count && (
  3965. sd->sc.data[SC_BERSERK] || sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  3966. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF) ||
  3967. sd->sc.data[SC_TRICKDEAD] ||
  3968. sd->sc.data[SC_HIDING] ||
  3969. sd->sc.data[SC__SHADOWFORM] ||
  3970. sd->sc.data[SC__INVISIBILITY] ||
  3971. sd->sc.data[SC__MANHOLE] ||
  3972. sd->sc.data[SC_KAGEHUMI] ||
  3973. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM) ||
  3974. sd->sc.data[SC_HEAT_BARREL_AFTER]))
  3975. return 0;
  3976. if (!pc_isItemClass(sd,item))
  3977. return 0;
  3978. //Dead Branch & Bloody Branch & Porings Box
  3979. if( nameid == ITEMID_BRANCH_OF_DEAD_TREE || nameid == ITEMID_BLOODY_DEAD_BRANCH || nameid == ITEMID_PORING_BOX || nameid == ITEMID_TREASURE_CHEST_SUMMONED_II )
  3980. log_branch(sd);
  3981. return 1;
  3982. }
  3983. /*==========================================
  3984. * Last checks to use an item.
  3985. * Return:
  3986. * 0 = fail
  3987. * 1 = success
  3988. *------------------------------------------*/
  3989. int pc_useitem(struct map_session_data *sd,int n)
  3990. {
  3991. unsigned int tick = gettick();
  3992. int amount, nameid;
  3993. struct script_code *script;
  3994. struct item item;
  3995. struct item_data *id;
  3996. nullpo_ret(sd);
  3997. if( sd->npc_id ){
  3998. #ifdef RENEWAL
  3999. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  4000. return 0;
  4001. #else
  4002. if( !sd->npc_item_flag )
  4003. return 0;
  4004. #endif
  4005. }
  4006. item = sd->status.inventory[n];
  4007. id = sd->inventory_data[n];
  4008. if (item.nameid <= 0 || item.amount <= 0)
  4009. return 0;
  4010. if( !pc_isUseitem(sd,n) )
  4011. return 0;
  4012. // Store information for later use before it is lost (via pc_delitem) [Paradox924X]
  4013. nameid = id->nameid;
  4014. if (nameid != ITEMID_NAUTHIZ && sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  4015. return 0;
  4016. /* Items with delayed consume are not meant to work while in mounts except reins of mount(12622) */
  4017. if( id->flag.delay_consume ) {
  4018. if( nameid != ITEMID_REINS_OF_MOUNT && sd->sc.option&OPTION_MOUNTING )
  4019. return 0;
  4020. else if( pc_issit(sd) )
  4021. return 0;
  4022. }
  4023. //Since most delay-consume items involve using a "skill-type" target cursor,
  4024. //perform a skill-use check before going through. [Skotlex]
  4025. //resurrection was picked as testing skill, as a non-offensive, generic skill, it will do.
  4026. //FIXME: Is this really needed here? It'll be checked in unit.c after all and this prevents skill items using when silenced [Inkfish]
  4027. if( id->flag.delay_consume && ( sd->ud.skilltimer != INVALID_TIMER /*|| !status_check_skilluse(&sd->bl, &sd->bl, ALL_RESURRECTION, 0)*/ ) )
  4028. return 0;
  4029. if( id->delay > 0 && !pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL) ) {
  4030. int i;
  4031. ARR_FIND(0, MAX_ITEMDELAYS, i, sd->item_delay[i].nameid == nameid );
  4032. if( i == MAX_ITEMDELAYS ) /* item not found. try first empty now */
  4033. ARR_FIND(0, MAX_ITEMDELAYS, i, !sd->item_delay[i].nameid );
  4034. if( i < MAX_ITEMDELAYS ) {
  4035. if( sd->item_delay[i].nameid ) {// found
  4036. if( DIFF_TICK(sd->item_delay[i].tick, tick) > 0 ) {
  4037. int e_tick = DIFF_TICK(sd->item_delay[i].tick, tick)/1000;
  4038. char e_msg[100];
  4039. if( e_tick > 99 )
  4040. sprintf(e_msg,msg_txt(sd,379), //Item Failed. [%s] is cooling down. Wait %.1f minutes.
  4041. itemdb_jname(item.nameid),
  4042. (double)e_tick / 60);
  4043. else
  4044. sprintf(e_msg,msg_txt(sd,380), //Item Failed. [%s] is cooling down. Wait %d seconds.
  4045. itemdb_jname(item.nameid),
  4046. e_tick+1);
  4047. clif_colormes(sd,color_table[COLOR_RED],e_msg);
  4048. return 0; // Delay has not expired yet
  4049. }
  4050. } else {// not yet used item (all slots are initially empty)
  4051. sd->item_delay[i].nameid = nameid;
  4052. }
  4053. if( !(nameid == ITEMID_REINS_OF_MOUNT && sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR)) )
  4054. sd->item_delay[i].tick = tick + sd->inventory_data[n]->delay;
  4055. } else {// should not happen
  4056. ShowError("pc_useitem: Exceeded item delay array capacity! (nameid=%d, char_id=%d)\n", nameid, sd->status.char_id);
  4057. }
  4058. //clean up used delays so we can give room for more
  4059. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  4060. if( DIFF_TICK(sd->item_delay[i].tick, tick) <= 0 ) {
  4061. sd->item_delay[i].tick = 0;
  4062. sd->item_delay[i].nameid = 0;
  4063. }
  4064. }
  4065. }
  4066. /* on restricted maps the item is consumed but the effect is not used */
  4067. if (!pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL) && itemdb_isNoEquip(id,sd->bl.m)) {
  4068. if( battle_config.allow_consume_restricted_item ) {
  4069. clif_useitemack(sd,n,item.amount-1,true);
  4070. pc_delitem(sd,n,1,1,0,LOG_TYPE_CONSUME);
  4071. }
  4072. return 0;/* regardless, effect is not run */
  4073. }
  4074. sd->itemid = item.nameid;
  4075. sd->itemindex = n;
  4076. if(sd->catch_target_class != -1) //Abort pet catching.
  4077. sd->catch_target_class = -1;
  4078. amount = item.amount;
  4079. script = id->script;
  4080. //Check if the item is to be consumed immediately [Skotlex]
  4081. if (id->flag.delay_consume)
  4082. clif_useitemack(sd, n, amount, true);
  4083. else
  4084. {
  4085. if (item.expire_time == 0)
  4086. {
  4087. clif_useitemack(sd, n, amount - 1, true);
  4088. pc_delitem(sd, n, 1, 1, 0, LOG_TYPE_CONSUME); // Rental Usable Items are not deleted until expiration
  4089. }
  4090. else
  4091. clif_useitemack(sd, n, 0, false);
  4092. }
  4093. if(item.card[0]==CARD0_CREATE &&
  4094. pc_famerank(MakeDWord(item.card[2],item.card[3]), MAPID_ALCHEMIST))
  4095. {
  4096. potion_flag = 2; // Famous player's potions have 50% more efficiency
  4097. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_ROGUE)
  4098. potion_flag = 3; //Even more effective potions.
  4099. }
  4100. //Update item use time.
  4101. sd->canuseitem_tick = tick + battle_config.item_use_interval;
  4102. if( itemdb_iscashfood(nameid) )
  4103. sd->canusecashfood_tick = tick + battle_config.cashfood_use_interval;
  4104. run_script(script,0,sd->bl.id,fake_nd->bl.id);
  4105. potion_flag = 0;
  4106. return 1;
  4107. }
  4108. /*==========================================
  4109. * Add item on cart for given index.
  4110. * Return:
  4111. * 0 = success
  4112. * 1 = fail
  4113. *------------------------------------------*/
  4114. int pc_cart_additem(struct map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type)
  4115. {
  4116. struct item_data *data;
  4117. int i,w;
  4118. nullpo_retr(1, sd);
  4119. nullpo_retr(1, item_data);
  4120. if(item_data->nameid <= 0 || amount <= 0)
  4121. return 1;
  4122. data = itemdb_search(item_data->nameid);
  4123. if( data->stack.cart && amount > data->stack.amount )
  4124. {// item stack limitation
  4125. return 1;
  4126. }
  4127. if( !itemdb_cancartstore(item_data, pc_get_group_level(sd)) || (item_data->bound > 1 && !pc_can_give_bounded_items(sd)))
  4128. { // Check item trade restrictions [Skotlex]
  4129. clif_displaymessage (sd->fd, msg_txt(sd,264));
  4130. return 1;
  4131. }
  4132. if( (w = data->weight*amount) + sd->cart_weight > sd->cart_weight_max )
  4133. return 1;
  4134. i = MAX_CART;
  4135. if( itemdb_isstackable2(data) && !item_data->expire_time )
  4136. {
  4137. ARR_FIND( 0, MAX_CART, i,
  4138. sd->status.cart[i].nameid == item_data->nameid && sd->status.cart[i].bound == item_data->bound &&
  4139. sd->status.cart[i].card[0] == item_data->card[0] && sd->status.cart[i].card[1] == item_data->card[1] &&
  4140. sd->status.cart[i].card[2] == item_data->card[2] && sd->status.cart[i].card[3] == item_data->card[3] );
  4141. };
  4142. if( i < MAX_CART )
  4143. {// item already in cart, stack it
  4144. if( amount > MAX_AMOUNT - sd->status.cart[i].amount || ( data->stack.cart && amount > data->stack.amount - sd->status.cart[i].amount ) )
  4145. return 2; // no slot
  4146. sd->status.cart[i].amount+=amount;
  4147. clif_cart_additem(sd,i,amount,0);
  4148. }
  4149. else
  4150. {// item not stackable or not present, add it
  4151. ARR_FIND( 0, MAX_CART, i, sd->status.cart[i].nameid == 0 );
  4152. if( i == MAX_CART )
  4153. return 2; // no slot
  4154. memcpy(&sd->status.cart[i],item_data,sizeof(sd->status.cart[0]));
  4155. sd->status.cart[i].amount=amount;
  4156. sd->cart_num++;
  4157. clif_cart_additem(sd,i,amount,0);
  4158. }
  4159. sd->status.cart[i].favorite = 0;/* clear */
  4160. log_pick_pc(sd, log_type, amount, &sd->status.cart[i]);
  4161. sd->cart_weight += w;
  4162. clif_updatestatus(sd,SP_CARTINFO);
  4163. return 0;
  4164. }
  4165. /*==========================================
  4166. * Delete item on cart for given index.
  4167. * Return:
  4168. * 0 = success
  4169. * 1 = fail
  4170. *------------------------------------------*/
  4171. int pc_cart_delitem(struct map_session_data *sd,int n,int amount,int type,e_log_pick_type log_type)
  4172. {
  4173. nullpo_retr(1, sd);
  4174. if(sd->status.cart[n].nameid==0 ||
  4175. sd->status.cart[n].amount<amount)
  4176. return 1;
  4177. log_pick_pc(sd, log_type, -amount, &sd->status.cart[n]);
  4178. sd->status.cart[n].amount -= amount;
  4179. sd->cart_weight -= itemdb_weight(sd->status.cart[n].nameid)*amount ;
  4180. if(sd->status.cart[n].amount <= 0){
  4181. memset(&sd->status.cart[n],0,sizeof(sd->status.cart[0]));
  4182. sd->cart_num--;
  4183. }
  4184. if(!type) {
  4185. clif_cart_delitem(sd,n,amount);
  4186. clif_updatestatus(sd,SP_CARTINFO);
  4187. }
  4188. return 0;
  4189. }
  4190. /*==========================================
  4191. * Transfer item from inventory to cart.
  4192. * Return:
  4193. * 0 = fail
  4194. * 1 = succes
  4195. *------------------------------------------*/
  4196. int pc_putitemtocart(struct map_session_data *sd,int idx,int amount)
  4197. {
  4198. struct item *item_data;
  4199. short flag;
  4200. nullpo_ret(sd);
  4201. if (idx < 0 || idx >= MAX_INVENTORY) //Invalid index check [Skotlex]
  4202. return 1;
  4203. item_data = &sd->status.inventory[idx];
  4204. if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
  4205. return 1;
  4206. if( (flag = pc_cart_additem(sd,item_data,amount,LOG_TYPE_NONE)) == 0 )
  4207. return pc_delitem(sd,idx,amount,0,5,LOG_TYPE_NONE);
  4208. return flag;
  4209. }
  4210. /*==========================================
  4211. * Get number of item in cart.
  4212. * Return:
  4213. -1 = itemid not found or no amount found
  4214. x = remaining itemid on cart after get
  4215. *------------------------------------------*/
  4216. int pc_cartitem_amount(struct map_session_data* sd, int idx, int amount)
  4217. {
  4218. struct item* item_data;
  4219. nullpo_retr(-1, sd);
  4220. item_data = &sd->status.cart[idx];
  4221. if( item_data->nameid == 0 || item_data->amount == 0 )
  4222. return -1;
  4223. return item_data->amount - amount;
  4224. }
  4225. /*==========================================
  4226. * Retrieve an item at index idx from cart.
  4227. * Return:
  4228. * 0 = player not found or (FIXME) succes (from pc_cart_delitem)
  4229. * 1 = failure
  4230. *------------------------------------------*/
  4231. int pc_getitemfromcart(struct map_session_data *sd,int idx,int amount)
  4232. {
  4233. struct item *item_data;
  4234. int flag;
  4235. nullpo_ret(sd);
  4236. if (idx < 0 || idx >= MAX_CART) //Invalid index check [Skotlex]
  4237. return 1;
  4238. item_data=&sd->status.cart[idx];
  4239. if(item_data->nameid==0 || amount < 1 || item_data->amount<amount || sd->state.vending )
  4240. return 1;
  4241. if((flag = pc_additem(sd,item_data,amount,LOG_TYPE_NONE)) == 0)
  4242. return pc_cart_delitem(sd,idx,amount,0,LOG_TYPE_NONE);
  4243. clif_additem(sd,0,0,flag);
  4244. return 1;
  4245. }
  4246. /*==========================================
  4247. * Bound Item Check
  4248. * Type:
  4249. * 1 Account Bound
  4250. * 2 Guild Bound
  4251. * 3 Party Bound
  4252. * 4 Character Bound
  4253. *------------------------------------------*/
  4254. int pc_bound_chk(TBL_PC *sd,int type,int *idxlist)
  4255. {
  4256. int i=0, j=0;
  4257. for(i=0;i<MAX_INVENTORY;i++){
  4258. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0 && sd->status.inventory[i].bound == type) {
  4259. idxlist[j] = i;
  4260. j++;
  4261. }
  4262. }
  4263. return j;
  4264. }
  4265. /*==========================================
  4266. * Display item stolen msg to player sd
  4267. *------------------------------------------*/
  4268. int pc_show_steal(struct block_list *bl,va_list ap)
  4269. {
  4270. struct map_session_data *sd;
  4271. int itemid;
  4272. struct item_data *item=NULL;
  4273. char output[100];
  4274. sd=va_arg(ap,struct map_session_data *);
  4275. itemid=va_arg(ap,int);
  4276. if((item=itemdb_exists(itemid))==NULL)
  4277. sprintf(output,"%s stole an Unknown Item (id: %i).",sd->status.name, itemid);
  4278. else
  4279. sprintf(output,"%s stole %s.",sd->status.name,item->jname);
  4280. clif_displaymessage( ((struct map_session_data *)bl)->fd, output);
  4281. return 0;
  4282. }
  4283. /*==========================================
  4284. * Steal an item from bl (mob).
  4285. * Return:
  4286. * 0 = fail
  4287. * 1 = succes
  4288. *------------------------------------------*/
  4289. int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv)
  4290. {
  4291. int i,itemid,flag;
  4292. double rate;
  4293. struct status_data *sd_status, *md_status;
  4294. struct mob_data *md;
  4295. struct item tmp_item;
  4296. if(!sd || !bl || bl->type!=BL_MOB)
  4297. return 0;
  4298. md = (TBL_MOB *)bl;
  4299. 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
  4300. return 0;
  4301. sd_status= status_get_status_data(&sd->bl);
  4302. md_status= status_get_status_data(bl);
  4303. if( md->master_id || md_status->mode&MD_BOSS || mob_is_treasure(md) ||
  4304. map[bl->m].flag.nomobloot || // check noloot map flag [Lorky]
  4305. (battle_config.skill_steal_max_tries && //Reached limit of steal attempts. [Lupus]
  4306. md->state.steal_flag++ >= battle_config.skill_steal_max_tries)
  4307. ) { //Can't steal from
  4308. md->state.steal_flag = UCHAR_MAX;
  4309. return 0;
  4310. }
  4311. // base skill success chance (percentual)
  4312. rate = (sd_status->dex - md_status->dex)/2 + skill_lv*6 + 4;
  4313. rate += sd->bonus.add_steal_rate;
  4314. if( rate < 1 )
  4315. return 0;
  4316. // Try dropping one item, in the order from first to last possible slot.
  4317. // Droprate is affected by the skill success rate.
  4318. for( i = 0; i < MAX_STEAL_DROP; i++ )
  4319. if( md->db->dropitem[i].nameid > 0 && itemdb_exists(md->db->dropitem[i].nameid) && rnd() % 10000 < md->db->dropitem[i].p * rate/100. )
  4320. break;
  4321. if( i == MAX_STEAL_DROP )
  4322. return 0;
  4323. itemid = md->db->dropitem[i].nameid;
  4324. memset(&tmp_item,0,sizeof(tmp_item));
  4325. tmp_item.nameid = itemid;
  4326. tmp_item.amount = 1;
  4327. tmp_item.identify = itemdb_isidentified(itemid);
  4328. flag = pc_additem(sd,&tmp_item,1,LOG_TYPE_PICKDROP_PLAYER);
  4329. //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?
  4330. md->state.steal_flag = UCHAR_MAX; //you can't steal from this mob any more
  4331. if(flag) { //Failed to steal due to overweight
  4332. clif_additem(sd,0,0,flag);
  4333. return 0;
  4334. }
  4335. if(battle_config.show_steal_in_same_party)
  4336. party_foreachsamemap(pc_show_steal,sd,AREA_SIZE,sd,tmp_item.nameid);
  4337. //Logs items, Stolen from mobs [Lupus]
  4338. log_pick_mob(md, LOG_TYPE_STEAL, -1, &tmp_item);
  4339. //A Rare Steal Global Announce by Lupus
  4340. if(md->db->dropitem[i].p<=battle_config.rare_drop_announce) {
  4341. struct item_data *i_data;
  4342. char message[128];
  4343. i_data = itemdb_search(itemid);
  4344. 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);
  4345. //MSG: "'%s' stole %s's %s (chance: %0.02f%%)"
  4346. intif_broadcast(message,strlen(message)+1,0);
  4347. }
  4348. return 1;
  4349. }
  4350. /*==========================================
  4351. * Stole zeny from bl (mob)
  4352. * return
  4353. * 0 = fail
  4354. * 1 = success
  4355. *------------------------------------------*/
  4356. int pc_steal_coin(struct map_session_data *sd,struct block_list *target)
  4357. {
  4358. int rate,skill;
  4359. struct mob_data *md;
  4360. if(!sd || !target || target->type != BL_MOB)
  4361. return 0;
  4362. md = (TBL_MOB*)target;
  4363. if( md->state.steal_coin_flag || md->sc.data[SC_STONE] || md->sc.data[SC_FREEZE] || md->status.mode&MD_BOSS )
  4364. return 0;
  4365. if( mob_is_treasure(md) )
  4366. return 0;
  4367. // FIXME: This formula is either custom or outdated.
  4368. skill = pc_checkskill(sd,RG_STEALCOIN)*10;
  4369. rate = skill + (sd->status.base_level - md->level)*3 + sd->battle_status.dex*2 + sd->battle_status.luk*2;
  4370. if(rnd()%1000 < rate)
  4371. {
  4372. int amount = md->level*10 + rnd()%100;
  4373. pc_getzeny(sd, amount, LOG_TYPE_STEAL, NULL);
  4374. md->state.steal_coin_flag = 1;
  4375. return 1;
  4376. }
  4377. return 0;
  4378. }
  4379. /*==========================================
  4380. * Set's a player position.
  4381. * Return values:
  4382. * 0 - Success.
  4383. * 1 - Invalid map index.
  4384. * 2 - Map not in this map-server, and failed to locate alternate map-server.
  4385. *------------------------------------------*/
  4386. int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype)
  4387. {
  4388. int16 m;
  4389. nullpo_ret(sd);
  4390. if( !mapindex || !mapindex_id2name(mapindex) ) {
  4391. ShowDebug("pc_setpos: Passed mapindex(%d) is invalid!\n", mapindex);
  4392. return 1;
  4393. }
  4394. if( pc_isdead(sd) ) { //Revive dead people before warping them
  4395. pc_setstand(sd);
  4396. pc_setrestartvalue(sd,1);
  4397. }
  4398. m = map_mapindex2mapid(mapindex);
  4399. sd->state.changemap = (sd->mapindex != mapindex);
  4400. sd->state.warping = 1;
  4401. if(sd->status.party_id && map[sd->bl.m].instance_id && sd->state.changemap && !map[m].instance_id) {
  4402. struct party_data *p;
  4403. if((p = party_search(sd->status.party_id)) != NULL && p->instance_id )
  4404. instance_delusers(p->instance_id);
  4405. }
  4406. if( sd->state.changemap ) { // Misc map-changing settings
  4407. int i;
  4408. sd->state.pmap = sd->bl.m;
  4409. if (sd->sc.count) { // Cancel some map related stuff.
  4410. if (sd->sc.data[SC_JAILED])
  4411. return 1; //You may not get out!
  4412. status_change_end(&sd->bl, SC_BOSSMAPINFO, INVALID_TIMER);
  4413. status_change_end(&sd->bl, SC_WARM, INVALID_TIMER);
  4414. status_change_end(&sd->bl, SC_SUN_COMFORT, INVALID_TIMER);
  4415. status_change_end(&sd->bl, SC_MOON_COMFORT, INVALID_TIMER);
  4416. status_change_end(&sd->bl, SC_STAR_COMFORT, INVALID_TIMER);
  4417. status_change_end(&sd->bl, SC_MIRACLE, INVALID_TIMER);
  4418. if (sd->sc.data[SC_KNOWLEDGE]) {
  4419. struct status_change_entry *sce = sd->sc.data[SC_KNOWLEDGE];
  4420. if (sce->timer != INVALID_TIMER)
  4421. delete_timer(sce->timer, status_change_timer);
  4422. sce->timer = add_timer(gettick() + skill_get_time(SG_KNOWLEDGE, sce->val1), status_change_timer, sd->bl.id, SC_KNOWLEDGE);
  4423. }
  4424. status_change_end(&sd->bl, SC_PROPERTYWALK, INVALID_TIMER);
  4425. status_change_end(&sd->bl, SC_CLOAKING, INVALID_TIMER);
  4426. status_change_end(&sd->bl, SC_CLOAKINGEXCEED, INVALID_TIMER);
  4427. }
  4428. for( i = 0; i < EQI_MAX; i++ ) {
  4429. if( sd->equip_index[ i ] >= 0 )
  4430. if( !pc_isequip( sd , sd->equip_index[ i ] ) )
  4431. pc_unequipitem( sd , sd->equip_index[ i ] , 2 );
  4432. }
  4433. if (battle_config.clear_unit_onwarp&BL_PC)
  4434. skill_clear_unitgroup(&sd->bl);
  4435. party_send_dot_remove(sd); //minimap dot fix [Kevin]
  4436. guild_send_dot_remove(sd);
  4437. bg_send_dot_remove(sd);
  4438. if (sd->regen.state.gc)
  4439. sd->regen.state.gc = 0;
  4440. // make sure vending is allowed here
  4441. if (sd->state.vending && map[m].flag.novending) {
  4442. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  4443. vending_closevending(sd);
  4444. }
  4445. channel_pcquit(sd,4); //quit map chan
  4446. }
  4447. if( m < 0 )
  4448. {
  4449. uint32 ip;
  4450. uint16 port;
  4451. //if can't find any map-servers, just abort setting position.
  4452. if(!sd->mapindex || map_mapname2ipport(mapindex,&ip,&port))
  4453. return 2;
  4454. if (sd->npc_id)
  4455. npc_event_dequeue(sd);
  4456. npc_script_event(sd, NPCE_LOGOUT);
  4457. //remove from map, THEN change x/y coordinates
  4458. unit_remove_map_pc(sd,clrtype);
  4459. sd->mapindex = mapindex;
  4460. sd->bl.x=x;
  4461. sd->bl.y=y;
  4462. pc_clean_skilltree(sd);
  4463. chrif_save(sd,2);
  4464. chrif_changemapserver(sd, ip, (short)port);
  4465. //Free session data from this map server [Kevin]
  4466. unit_free_pc(sd);
  4467. return 0;
  4468. }
  4469. if( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys )
  4470. {
  4471. 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);
  4472. x = y = 0; // make it random
  4473. }
  4474. if( x == 0 && y == 0 )
  4475. {// pick a random walkable cell
  4476. do {
  4477. x=rnd()%(map[m].xs-2)+1;
  4478. y=rnd()%(map[m].ys-2)+1;
  4479. } while(map_getcell(m,x,y,CELL_CHKNOPASS));
  4480. }
  4481. if (sd->state.vending && map_getcell(m,x,y,CELL_CHKNOVENDING)) {
  4482. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  4483. vending_closevending(sd);
  4484. }
  4485. if(sd->bl.prev != NULL){
  4486. unit_remove_map_pc(sd,clrtype);
  4487. clif_changemap(sd,m,x,y); // [MouseJstr]
  4488. } else if(sd->state.active) //Tag player for rewarping after map-loading is done. [Skotlex]
  4489. sd->state.rewarp = 1;
  4490. sd->mapindex = mapindex;
  4491. sd->bl.m = m;
  4492. sd->bl.x = sd->ud.to_x = x;
  4493. sd->bl.y = sd->ud.to_y = y;
  4494. if( sd->status.guild_id > 0 && map[m].flag.gvg_castle )
  4495. { // Increased guild castle regen [Valaris]
  4496. struct guild_castle *gc = guild_mapindex2gc(sd->mapindex);
  4497. if(gc && gc->guild_id == sd->status.guild_id)
  4498. sd->regen.state.gc = 1;
  4499. }
  4500. if( sd->status.pet_id > 0 && sd->pd && sd->pd->pet.intimate > 0 )
  4501. {
  4502. sd->pd->bl.m = m;
  4503. sd->pd->bl.x = sd->pd->ud.to_x = x;
  4504. sd->pd->bl.y = sd->pd->ud.to_y = y;
  4505. sd->pd->ud.dir = sd->ud.dir;
  4506. }
  4507. if( merc_is_hom_active(sd->hd) )
  4508. {
  4509. sd->hd->bl.m = m;
  4510. sd->hd->bl.x = sd->hd->ud.to_x = x;
  4511. sd->hd->bl.y = sd->hd->ud.to_y = y;
  4512. sd->hd->ud.dir = sd->ud.dir;
  4513. }
  4514. if( sd->md )
  4515. {
  4516. sd->md->bl.m = m;
  4517. sd->md->bl.x = sd->md->ud.to_x = x;
  4518. sd->md->bl.y = sd->md->ud.to_y = y;
  4519. sd->md->ud.dir = sd->ud.dir;
  4520. }
  4521. pc_cell_basilica(sd);
  4522. return 0;
  4523. }
  4524. /*==========================================
  4525. * Warp player sd to random location on current map.
  4526. * May fail if no walkable cell found (1000 attempts).
  4527. * Return:
  4528. * 0 = fail or FIXME success (from pc_setpos)
  4529. * x(1|2) = fail
  4530. *------------------------------------------*/
  4531. int pc_randomwarp(struct map_session_data *sd, clr_type type)
  4532. {
  4533. int x,y,i=0;
  4534. int16 m;
  4535. nullpo_ret(sd);
  4536. m=sd->bl.m;
  4537. if (map[sd->bl.m].flag.noteleport) //Teleport forbidden
  4538. return 0;
  4539. do{
  4540. x=rnd()%(map[m].xs-2)+1;
  4541. y=rnd()%(map[m].ys-2)+1;
  4542. }while(map_getcell(m,x,y,CELL_CHKNOPASS) && (i++)<1000 );
  4543. if (i < 1000)
  4544. return pc_setpos(sd,map[sd->bl.m].index,x,y,type);
  4545. return 0;
  4546. }
  4547. /*==========================================
  4548. * Records a memo point at sd's current position
  4549. * pos - entry to replace, (-1: shift oldest entry out)
  4550. *------------------------------------------*/
  4551. int pc_memo(struct map_session_data* sd, int pos)
  4552. {
  4553. int skill;
  4554. nullpo_ret(sd);
  4555. // check mapflags
  4556. 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) ) {
  4557. clif_skill_teleportmessage(sd, 1); // "Saved point cannot be memorized."
  4558. return 0;
  4559. }
  4560. // check inputs
  4561. if( pos < -1 || pos >= MAX_MEMOPOINTS )
  4562. return 0; // invalid input
  4563. // check required skill level
  4564. skill = pc_checkskill(sd, AL_WARP);
  4565. if( skill < 1 ) {
  4566. clif_skill_memomessage(sd,2); // "You haven't learned Warp."
  4567. return 0;
  4568. }
  4569. if( skill < 2 || skill - 2 < pos ) {
  4570. clif_skill_memomessage(sd,1); // "Skill Level is not high enough."
  4571. return 0;
  4572. }
  4573. if( pos == -1 )
  4574. {
  4575. int i;
  4576. // prevent memo-ing the same map multiple times
  4577. ARR_FIND( 0, MAX_MEMOPOINTS, i, sd->status.memo_point[i].map == map_id2index(sd->bl.m) );
  4578. memmove(&sd->status.memo_point[1], &sd->status.memo_point[0], (min(i,MAX_MEMOPOINTS-1))*sizeof(struct point));
  4579. pos = 0;
  4580. }
  4581. if( map[sd->bl.m].instance_id ) {
  4582. clif_displaymessage( sd->fd, msg_txt(sd,384) ); // You cannot create a memo in an instance.
  4583. return 0;
  4584. }
  4585. sd->status.memo_point[pos].map = map_id2index(sd->bl.m);
  4586. sd->status.memo_point[pos].x = sd->bl.x;
  4587. sd->status.memo_point[pos].y = sd->bl.y;
  4588. clif_skill_memomessage(sd, 0);
  4589. return 1;
  4590. }
  4591. //
  4592. // Skills
  4593. //
  4594. /*==========================================
  4595. * Return player sd skill_lv learned for given skill
  4596. *------------------------------------------*/
  4597. int pc_checkskill(struct map_session_data *sd,uint16 skill_id)
  4598. {
  4599. if(sd == NULL) return 0;
  4600. if( skill_id >= GD_SKILLBASE && skill_id < GD_MAX ) {
  4601. struct guild *g;
  4602. if( sd->status.guild_id>0 && (g=sd->guild)!=NULL)
  4603. return guild_checkskill(g,skill_id);
  4604. return 0;
  4605. } else if(skill_id >= ARRAYLENGTH(sd->status.skill) ) {
  4606. ShowError("pc_checkskill: Invalid skill id %d (char_id=%d).\n", skill_id, sd->status.char_id);
  4607. return 0;
  4608. }
  4609. if(sd->status.skill[skill_id].id == skill_id)
  4610. return (sd->status.skill[skill_id].lv);
  4611. return 0;
  4612. }
  4613. /**
  4614. * Chk if we still have the correct weapon to continue the skill (actually status)
  4615. * If not ending it
  4616. * @param sd
  4617. * @return 0:error, 1:check done
  4618. */
  4619. static void pc_checkallowskill(struct map_session_data *sd)
  4620. {
  4621. const enum sc_type scw_list[] = {
  4622. SC_TWOHANDQUICKEN,
  4623. SC_ONEHAND,
  4624. SC_AURABLADE,
  4625. SC_PARRYING,
  4626. SC_SPEARQUICKEN,
  4627. SC_ADRENALINE,
  4628. SC_ADRENALINE2,
  4629. SC_DANCING,
  4630. SC_GATLINGFEVER,
  4631. SC_FEARBREEZE
  4632. };
  4633. uint8 i;
  4634. nullpo_retv(sd);
  4635. if(!sd->sc.count)
  4636. return;
  4637. for (i = 0; i < ARRAYLENGTH(scw_list); i++)
  4638. { // Skills requiring specific weapon types
  4639. if( scw_list[i] == SC_DANCING && !battle_config.dancing_weaponswitch_fix )
  4640. continue;
  4641. if(sd->sc.data[scw_list[i]] &&
  4642. !pc_check_weapontype(sd,skill_get_weapontype(status_sc2skill(scw_list[i]))))
  4643. status_change_end(&sd->bl, scw_list[i], INVALID_TIMER);
  4644. }
  4645. if(sd->sc.data[SC_SPURT] && sd->status.weapon)
  4646. // Spurt requires bare hands (feet, in fact xD)
  4647. status_change_end(&sd->bl, SC_SPURT, INVALID_TIMER);
  4648. if(sd->status.shield <= 0) { // Skills requiring a shield
  4649. const enum sc_type scs_list[] = {
  4650. SC_AUTOGUARD,
  4651. SC_DEFENDER,
  4652. SC_REFLECTSHIELD,
  4653. SC_REFLECTDAMAGE
  4654. };
  4655. for (i = 0; i < ARRAYLENGTH(scs_list); i++)
  4656. if(sd->sc.data[scs_list[i]])
  4657. status_change_end(&sd->bl, scs_list[i], INVALID_TIMER);
  4658. }
  4659. }
  4660. /*==========================================
  4661. * Return equiped itemid? on player sd at pos
  4662. * Return
  4663. * -1 : mean nothing equiped
  4664. * idx : (this index could be used in inventory to found item_data)
  4665. *------------------------------------------*/
  4666. short pc_checkequip(struct map_session_data *sd,int pos)
  4667. {
  4668. uint8 i;
  4669. nullpo_retr(-1, sd);
  4670. for(i=0;i<EQI_MAX;i++){
  4671. if(pos & equip_pos[i])
  4672. return sd->equip_index[i];
  4673. }
  4674. return -1;
  4675. }
  4676. /*==========================================
  4677. * Check if sd as nameid equiped somewhere
  4678. * @sd : the player session
  4679. * @nameid : id of the item to check
  4680. * @min : : see pc.h enum equip_index from ? to @max
  4681. * @max : see pc.h enum equip_index for @min to ?
  4682. * -return true,false
  4683. *------------------------------------------*/
  4684. bool pc_checkequip2(struct map_session_data *sd,int nameid, int min, int max){
  4685. int i;
  4686. for(i=min;i<max;i++){
  4687. if(equip_pos[i]){
  4688. int idx = sd->equip_index[i];
  4689. if (sd->status.inventory[idx].nameid == nameid)
  4690. return true;
  4691. }
  4692. }
  4693. return false;
  4694. }
  4695. /*==========================================
  4696. * Convert's from the client's lame Job ID system
  4697. * to the map server's 'makes sense' system. [Skotlex]
  4698. *------------------------------------------*/
  4699. int pc_jobid2mapid(unsigned short b_class)
  4700. {
  4701. switch(b_class)
  4702. {
  4703. //Novice And 1-1 Jobs
  4704. case JOB_NOVICE: return MAPID_NOVICE;
  4705. case JOB_SWORDMAN: return MAPID_SWORDMAN;
  4706. case JOB_MAGE: return MAPID_MAGE;
  4707. case JOB_ARCHER: return MAPID_ARCHER;
  4708. case JOB_ACOLYTE: return MAPID_ACOLYTE;
  4709. case JOB_MERCHANT: return MAPID_MERCHANT;
  4710. case JOB_THIEF: return MAPID_THIEF;
  4711. case JOB_TAEKWON: return MAPID_TAEKWON;
  4712. case JOB_WEDDING: return MAPID_WEDDING;
  4713. case JOB_GUNSLINGER: return MAPID_GUNSLINGER;
  4714. case JOB_NINJA: return MAPID_NINJA;
  4715. case JOB_XMAS: return MAPID_XMAS;
  4716. case JOB_SUMMER: return MAPID_SUMMER;
  4717. case JOB_HANBOK: return MAPID_HANBOK;
  4718. case JOB_OKTOBERFEST: return MAPID_OKTOBERFEST;
  4719. case JOB_GANGSI: return MAPID_GANGSI;
  4720. //2-1 Jobs
  4721. case JOB_SUPER_NOVICE: return MAPID_SUPER_NOVICE;
  4722. case JOB_KNIGHT: return MAPID_KNIGHT;
  4723. case JOB_WIZARD: return MAPID_WIZARD;
  4724. case JOB_HUNTER: return MAPID_HUNTER;
  4725. case JOB_PRIEST: return MAPID_PRIEST;
  4726. case JOB_BLACKSMITH: return MAPID_BLACKSMITH;
  4727. case JOB_ASSASSIN: return MAPID_ASSASSIN;
  4728. case JOB_STAR_GLADIATOR: return MAPID_STAR_GLADIATOR;
  4729. case JOB_KAGEROU:
  4730. case JOB_OBORO: return MAPID_KAGEROUOBORO;
  4731. case JOB_REBELLION: return MAPID_REBELLION;
  4732. case JOB_DEATH_KNIGHT: return MAPID_DEATH_KNIGHT;
  4733. //2-2 Jobs
  4734. case JOB_CRUSADER: return MAPID_CRUSADER;
  4735. case JOB_SAGE: return MAPID_SAGE;
  4736. case JOB_BARD:
  4737. case JOB_DANCER: return MAPID_BARDDANCER;
  4738. case JOB_MONK: return MAPID_MONK;
  4739. case JOB_ALCHEMIST: return MAPID_ALCHEMIST;
  4740. case JOB_ROGUE: return MAPID_ROGUE;
  4741. case JOB_SOUL_LINKER: return MAPID_SOUL_LINKER;
  4742. case JOB_DARK_COLLECTOR: return MAPID_DARK_COLLECTOR;
  4743. //Trans Novice And Trans 1-1 Jobs
  4744. case JOB_NOVICE_HIGH: return MAPID_NOVICE_HIGH;
  4745. case JOB_SWORDMAN_HIGH: return MAPID_SWORDMAN_HIGH;
  4746. case JOB_MAGE_HIGH: return MAPID_MAGE_HIGH;
  4747. case JOB_ARCHER_HIGH: return MAPID_ARCHER_HIGH;
  4748. case JOB_ACOLYTE_HIGH: return MAPID_ACOLYTE_HIGH;
  4749. case JOB_MERCHANT_HIGH: return MAPID_MERCHANT_HIGH;
  4750. case JOB_THIEF_HIGH: return MAPID_THIEF_HIGH;
  4751. //Trans 2-1 Jobs
  4752. case JOB_LORD_KNIGHT: return MAPID_LORD_KNIGHT;
  4753. case JOB_HIGH_WIZARD: return MAPID_HIGH_WIZARD;
  4754. case JOB_SNIPER: return MAPID_SNIPER;
  4755. case JOB_HIGH_PRIEST: return MAPID_HIGH_PRIEST;
  4756. case JOB_WHITESMITH: return MAPID_WHITESMITH;
  4757. case JOB_ASSASSIN_CROSS: return MAPID_ASSASSIN_CROSS;
  4758. //Trans 2-2 Jobs
  4759. case JOB_PALADIN: return MAPID_PALADIN;
  4760. case JOB_PROFESSOR: return MAPID_PROFESSOR;
  4761. case JOB_CLOWN:
  4762. case JOB_GYPSY: return MAPID_CLOWNGYPSY;
  4763. case JOB_CHAMPION: return MAPID_CHAMPION;
  4764. case JOB_CREATOR: return MAPID_CREATOR;
  4765. case JOB_STALKER: return MAPID_STALKER;
  4766. //Baby Novice And Baby 1-1 Jobs
  4767. case JOB_BABY: return MAPID_BABY;
  4768. case JOB_BABY_SWORDMAN: return MAPID_BABY_SWORDMAN;
  4769. case JOB_BABY_MAGE: return MAPID_BABY_MAGE;
  4770. case JOB_BABY_ARCHER: return MAPID_BABY_ARCHER;
  4771. case JOB_BABY_ACOLYTE: return MAPID_BABY_ACOLYTE;
  4772. case JOB_BABY_MERCHANT: return MAPID_BABY_MERCHANT;
  4773. case JOB_BABY_THIEF: return MAPID_BABY_THIEF;
  4774. //Baby 2-1 Jobs
  4775. case JOB_SUPER_BABY: return MAPID_SUPER_BABY;
  4776. case JOB_BABY_KNIGHT: return MAPID_BABY_KNIGHT;
  4777. case JOB_BABY_WIZARD: return MAPID_BABY_WIZARD;
  4778. case JOB_BABY_HUNTER: return MAPID_BABY_HUNTER;
  4779. case JOB_BABY_PRIEST: return MAPID_BABY_PRIEST;
  4780. case JOB_BABY_BLACKSMITH: return MAPID_BABY_BLACKSMITH;
  4781. case JOB_BABY_ASSASSIN: return MAPID_BABY_ASSASSIN;
  4782. //Baby 2-2 Jobs
  4783. case JOB_BABY_CRUSADER: return MAPID_BABY_CRUSADER;
  4784. case JOB_BABY_SAGE: return MAPID_BABY_SAGE;
  4785. case JOB_BABY_BARD:
  4786. case JOB_BABY_DANCER: return MAPID_BABY_BARDDANCER;
  4787. case JOB_BABY_MONK: return MAPID_BABY_MONK;
  4788. case JOB_BABY_ALCHEMIST: return MAPID_BABY_ALCHEMIST;
  4789. case JOB_BABY_ROGUE: return MAPID_BABY_ROGUE;
  4790. //3-1 Jobs
  4791. case JOB_SUPER_NOVICE_E: return MAPID_SUPER_NOVICE_E;
  4792. case JOB_RUNE_KNIGHT: return MAPID_RUNE_KNIGHT;
  4793. case JOB_WARLOCK: return MAPID_WARLOCK;
  4794. case JOB_RANGER: return MAPID_RANGER;
  4795. case JOB_ARCH_BISHOP: return MAPID_ARCH_BISHOP;
  4796. case JOB_MECHANIC: return MAPID_MECHANIC;
  4797. case JOB_GUILLOTINE_CROSS: return MAPID_GUILLOTINE_CROSS;
  4798. //3-2 Jobs
  4799. case JOB_ROYAL_GUARD: return MAPID_ROYAL_GUARD;
  4800. case JOB_SORCERER: return MAPID_SORCERER;
  4801. case JOB_MINSTREL:
  4802. case JOB_WANDERER: return MAPID_MINSTRELWANDERER;
  4803. case JOB_SURA: return MAPID_SURA;
  4804. case JOB_GENETIC: return MAPID_GENETIC;
  4805. case JOB_SHADOW_CHASER: return MAPID_SHADOW_CHASER;
  4806. //Trans 3-1 Jobs
  4807. case JOB_RUNE_KNIGHT_T: return MAPID_RUNE_KNIGHT_T;
  4808. case JOB_WARLOCK_T: return MAPID_WARLOCK_T;
  4809. case JOB_RANGER_T: return MAPID_RANGER_T;
  4810. case JOB_ARCH_BISHOP_T: return MAPID_ARCH_BISHOP_T;
  4811. case JOB_MECHANIC_T: return MAPID_MECHANIC_T;
  4812. case JOB_GUILLOTINE_CROSS_T: return MAPID_GUILLOTINE_CROSS_T;
  4813. //Trans 3-2 Jobs
  4814. case JOB_ROYAL_GUARD_T: return MAPID_ROYAL_GUARD_T;
  4815. case JOB_SORCERER_T: return MAPID_SORCERER_T;
  4816. case JOB_MINSTREL_T:
  4817. case JOB_WANDERER_T: return MAPID_MINSTRELWANDERER_T;
  4818. case JOB_SURA_T: return MAPID_SURA_T;
  4819. case JOB_GENETIC_T: return MAPID_GENETIC_T;
  4820. case JOB_SHADOW_CHASER_T: return MAPID_SHADOW_CHASER_T;
  4821. //Baby 3-1 Jobs
  4822. case JOB_SUPER_BABY_E: return MAPID_SUPER_BABY_E;
  4823. case JOB_BABY_RUNE: return MAPID_BABY_RUNE;
  4824. case JOB_BABY_WARLOCK: return MAPID_BABY_WARLOCK;
  4825. case JOB_BABY_RANGER: return MAPID_BABY_RANGER;
  4826. case JOB_BABY_BISHOP: return MAPID_BABY_BISHOP;
  4827. case JOB_BABY_MECHANIC: return MAPID_BABY_MECHANIC;
  4828. case JOB_BABY_CROSS: return MAPID_BABY_CROSS;
  4829. //Baby 3-2 Jobs
  4830. case JOB_BABY_GUARD: return MAPID_BABY_GUARD;
  4831. case JOB_BABY_SORCERER: return MAPID_BABY_SORCERER;
  4832. case JOB_BABY_MINSTREL:
  4833. case JOB_BABY_WANDERER: return MAPID_BABY_MINSTRELWANDERER;
  4834. case JOB_BABY_SURA: return MAPID_BABY_SURA;
  4835. case JOB_BABY_GENETIC: return MAPID_BABY_GENETIC;
  4836. case JOB_BABY_CHASER: return MAPID_BABY_CHASER;
  4837. default:
  4838. return -1;
  4839. }
  4840. }
  4841. //Reverts the map-style class id to the client-style one.
  4842. int pc_mapid2jobid(unsigned short class_, int sex)
  4843. {
  4844. switch(class_)
  4845. {
  4846. //Novice And 1-1 Jobs
  4847. case MAPID_NOVICE: return JOB_NOVICE;
  4848. case MAPID_SWORDMAN: return JOB_SWORDMAN;
  4849. case MAPID_MAGE: return JOB_MAGE;
  4850. case MAPID_ARCHER: return JOB_ARCHER;
  4851. case MAPID_ACOLYTE: return JOB_ACOLYTE;
  4852. case MAPID_MERCHANT: return JOB_MERCHANT;
  4853. case MAPID_THIEF: return JOB_THIEF;
  4854. case MAPID_TAEKWON: return JOB_TAEKWON;
  4855. case MAPID_WEDDING: return JOB_WEDDING;
  4856. case MAPID_GUNSLINGER: return JOB_GUNSLINGER;
  4857. case MAPID_NINJA: return JOB_NINJA;
  4858. case MAPID_XMAS: return JOB_XMAS;
  4859. case MAPID_SUMMER: return JOB_SUMMER;
  4860. case MAPID_HANBOK: return JOB_HANBOK;
  4861. case MAPID_OKTOBERFEST: return JOB_OKTOBERFEST;
  4862. case MAPID_GANGSI: return JOB_GANGSI;
  4863. //2-1 Jobs
  4864. case MAPID_SUPER_NOVICE: return JOB_SUPER_NOVICE;
  4865. case MAPID_KNIGHT: return JOB_KNIGHT;
  4866. case MAPID_WIZARD: return JOB_WIZARD;
  4867. case MAPID_HUNTER: return JOB_HUNTER;
  4868. case MAPID_PRIEST: return JOB_PRIEST;
  4869. case MAPID_BLACKSMITH: return JOB_BLACKSMITH;
  4870. case MAPID_ASSASSIN: return JOB_ASSASSIN;
  4871. case MAPID_STAR_GLADIATOR: return JOB_STAR_GLADIATOR;
  4872. case MAPID_KAGEROUOBORO: return sex?JOB_KAGEROU:JOB_OBORO;
  4873. case MAPID_REBELLION: return JOB_REBELLION;
  4874. case MAPID_DEATH_KNIGHT: return JOB_DEATH_KNIGHT;
  4875. //2-2 Jobs
  4876. case MAPID_CRUSADER: return JOB_CRUSADER;
  4877. case MAPID_SAGE: return JOB_SAGE;
  4878. case MAPID_BARDDANCER: return sex?JOB_BARD:JOB_DANCER;
  4879. case MAPID_MONK: return JOB_MONK;
  4880. case MAPID_ALCHEMIST: return JOB_ALCHEMIST;
  4881. case MAPID_ROGUE: return JOB_ROGUE;
  4882. case MAPID_SOUL_LINKER: return JOB_SOUL_LINKER;
  4883. case MAPID_DARK_COLLECTOR: return JOB_DARK_COLLECTOR;
  4884. //Trans Novice And Trans 2-1 Jobs
  4885. case MAPID_NOVICE_HIGH: return JOB_NOVICE_HIGH;
  4886. case MAPID_SWORDMAN_HIGH: return JOB_SWORDMAN_HIGH;
  4887. case MAPID_MAGE_HIGH: return JOB_MAGE_HIGH;
  4888. case MAPID_ARCHER_HIGH: return JOB_ARCHER_HIGH;
  4889. case MAPID_ACOLYTE_HIGH: return JOB_ACOLYTE_HIGH;
  4890. case MAPID_MERCHANT_HIGH: return JOB_MERCHANT_HIGH;
  4891. case MAPID_THIEF_HIGH: return JOB_THIEF_HIGH;
  4892. //Trans 2-1 Jobs
  4893. case MAPID_LORD_KNIGHT: return JOB_LORD_KNIGHT;
  4894. case MAPID_HIGH_WIZARD: return JOB_HIGH_WIZARD;
  4895. case MAPID_SNIPER: return JOB_SNIPER;
  4896. case MAPID_HIGH_PRIEST: return JOB_HIGH_PRIEST;
  4897. case MAPID_WHITESMITH: return JOB_WHITESMITH;
  4898. case MAPID_ASSASSIN_CROSS: return JOB_ASSASSIN_CROSS;
  4899. //Trans 2-2 Jobs
  4900. case MAPID_PALADIN: return JOB_PALADIN;
  4901. case MAPID_PROFESSOR: return JOB_PROFESSOR;
  4902. case MAPID_CLOWNGYPSY: return sex?JOB_CLOWN:JOB_GYPSY;
  4903. case MAPID_CHAMPION: return JOB_CHAMPION;
  4904. case MAPID_CREATOR: return JOB_CREATOR;
  4905. case MAPID_STALKER: return JOB_STALKER;
  4906. //Baby Novice And Baby 1-1 Jobs
  4907. case MAPID_BABY: return JOB_BABY;
  4908. case MAPID_BABY_SWORDMAN: return JOB_BABY_SWORDMAN;
  4909. case MAPID_BABY_MAGE: return JOB_BABY_MAGE;
  4910. case MAPID_BABY_ARCHER: return JOB_BABY_ARCHER;
  4911. case MAPID_BABY_ACOLYTE: return JOB_BABY_ACOLYTE;
  4912. case MAPID_BABY_MERCHANT: return JOB_BABY_MERCHANT;
  4913. case MAPID_BABY_THIEF: return JOB_BABY_THIEF;
  4914. //Baby 2-1 Jobs
  4915. case MAPID_SUPER_BABY: return JOB_SUPER_BABY;
  4916. case MAPID_BABY_KNIGHT: return JOB_BABY_KNIGHT;
  4917. case MAPID_BABY_WIZARD: return JOB_BABY_WIZARD;
  4918. case MAPID_BABY_HUNTER: return JOB_BABY_HUNTER;
  4919. case MAPID_BABY_PRIEST: return JOB_BABY_PRIEST;
  4920. case MAPID_BABY_BLACKSMITH: return JOB_BABY_BLACKSMITH;
  4921. case MAPID_BABY_ASSASSIN: return JOB_BABY_ASSASSIN;
  4922. //Baby 2-2 Jobs
  4923. case MAPID_BABY_CRUSADER: return JOB_BABY_CRUSADER;
  4924. case MAPID_BABY_SAGE: return JOB_BABY_SAGE;
  4925. case MAPID_BABY_BARDDANCER: return sex?JOB_BABY_BARD:JOB_BABY_DANCER;
  4926. case MAPID_BABY_MONK: return JOB_BABY_MONK;
  4927. case MAPID_BABY_ALCHEMIST: return JOB_BABY_ALCHEMIST;
  4928. case MAPID_BABY_ROGUE: return JOB_BABY_ROGUE;
  4929. //3-1 Jobs
  4930. case MAPID_SUPER_NOVICE_E: return JOB_SUPER_NOVICE_E;
  4931. case MAPID_RUNE_KNIGHT: return JOB_RUNE_KNIGHT;
  4932. case MAPID_WARLOCK: return JOB_WARLOCK;
  4933. case MAPID_RANGER: return JOB_RANGER;
  4934. case MAPID_ARCH_BISHOP: return JOB_ARCH_BISHOP;
  4935. case MAPID_MECHANIC: return JOB_MECHANIC;
  4936. case MAPID_GUILLOTINE_CROSS: return JOB_GUILLOTINE_CROSS;
  4937. //3-2 Jobs
  4938. case MAPID_ROYAL_GUARD: return JOB_ROYAL_GUARD;
  4939. case MAPID_SORCERER: return JOB_SORCERER;
  4940. case MAPID_MINSTRELWANDERER: return sex?JOB_MINSTREL:JOB_WANDERER;
  4941. case MAPID_SURA: return JOB_SURA;
  4942. case MAPID_GENETIC: return JOB_GENETIC;
  4943. case MAPID_SHADOW_CHASER: return JOB_SHADOW_CHASER;
  4944. //Trans 3-1 Jobs
  4945. case MAPID_RUNE_KNIGHT_T: return JOB_RUNE_KNIGHT_T;
  4946. case MAPID_WARLOCK_T: return JOB_WARLOCK_T;
  4947. case MAPID_RANGER_T: return JOB_RANGER_T;
  4948. case MAPID_ARCH_BISHOP_T: return JOB_ARCH_BISHOP_T;
  4949. case MAPID_MECHANIC_T: return JOB_MECHANIC_T;
  4950. case MAPID_GUILLOTINE_CROSS_T: return JOB_GUILLOTINE_CROSS_T;
  4951. //Trans 3-2 Jobs
  4952. case MAPID_ROYAL_GUARD_T: return JOB_ROYAL_GUARD_T;
  4953. case MAPID_SORCERER_T: return JOB_SORCERER_T;
  4954. case MAPID_MINSTRELWANDERER_T: return sex?JOB_MINSTREL_T:JOB_WANDERER_T;
  4955. case MAPID_SURA_T: return JOB_SURA_T;
  4956. case MAPID_GENETIC_T: return JOB_GENETIC_T;
  4957. case MAPID_SHADOW_CHASER_T: return JOB_SHADOW_CHASER_T;
  4958. //Baby 3-1 Jobs
  4959. case MAPID_SUPER_BABY_E: return JOB_SUPER_BABY_E;
  4960. case MAPID_BABY_RUNE: return JOB_BABY_RUNE;
  4961. case MAPID_BABY_WARLOCK: return JOB_BABY_WARLOCK;
  4962. case MAPID_BABY_RANGER: return JOB_BABY_RANGER;
  4963. case MAPID_BABY_BISHOP: return JOB_BABY_BISHOP;
  4964. case MAPID_BABY_MECHANIC: return JOB_BABY_MECHANIC;
  4965. case MAPID_BABY_CROSS: return JOB_BABY_CROSS;
  4966. //Baby 3-2 Jobs
  4967. case MAPID_BABY_GUARD: return JOB_BABY_GUARD;
  4968. case MAPID_BABY_SORCERER: return JOB_BABY_SORCERER;
  4969. case MAPID_BABY_MINSTRELWANDERER: return sex?JOB_BABY_MINSTREL:JOB_BABY_WANDERER;
  4970. case MAPID_BABY_SURA: return JOB_BABY_SURA;
  4971. case MAPID_BABY_GENETIC: return JOB_BABY_GENETIC;
  4972. case MAPID_BABY_CHASER: return JOB_BABY_CHASER;
  4973. default:
  4974. return -1;
  4975. }
  4976. }
  4977. /*====================================================
  4978. * This function return the name of the job (by [Yor])
  4979. *----------------------------------------------------*/
  4980. const char* job_name(int class_)
  4981. {
  4982. switch (class_) {
  4983. case JOB_NOVICE:
  4984. case JOB_SWORDMAN:
  4985. case JOB_MAGE:
  4986. case JOB_ARCHER:
  4987. case JOB_ACOLYTE:
  4988. case JOB_MERCHANT:
  4989. case JOB_THIEF:
  4990. return msg_txt(NULL,550 - JOB_NOVICE+class_);
  4991. case JOB_KNIGHT:
  4992. case JOB_PRIEST:
  4993. case JOB_WIZARD:
  4994. case JOB_BLACKSMITH:
  4995. case JOB_HUNTER:
  4996. case JOB_ASSASSIN:
  4997. return msg_txt(NULL,557 - JOB_KNIGHT+class_);
  4998. case JOB_KNIGHT2:
  4999. return msg_txt(NULL,557);
  5000. case JOB_CRUSADER:
  5001. case JOB_MONK:
  5002. case JOB_SAGE:
  5003. case JOB_ROGUE:
  5004. case JOB_ALCHEMIST:
  5005. case JOB_BARD:
  5006. case JOB_DANCER:
  5007. return msg_txt(NULL,563 - JOB_CRUSADER+class_);
  5008. case JOB_CRUSADER2:
  5009. return msg_txt(NULL,563);
  5010. case JOB_WEDDING:
  5011. case JOB_SUPER_NOVICE:
  5012. case JOB_GUNSLINGER:
  5013. case JOB_NINJA:
  5014. case JOB_XMAS:
  5015. return msg_txt(NULL,570 - JOB_WEDDING+class_);
  5016. case JOB_SUMMER:
  5017. return msg_txt(NULL,621);
  5018. case JOB_HANBOK:
  5019. return msg_txt(NULL,694);
  5020. case JOB_OKTOBERFEST:
  5021. return msg_txt(NULL,696);
  5022. case JOB_NOVICE_HIGH:
  5023. case JOB_SWORDMAN_HIGH:
  5024. case JOB_MAGE_HIGH:
  5025. case JOB_ARCHER_HIGH:
  5026. case JOB_ACOLYTE_HIGH:
  5027. case JOB_MERCHANT_HIGH:
  5028. case JOB_THIEF_HIGH:
  5029. return msg_txt(NULL,575 - JOB_NOVICE_HIGH+class_);
  5030. case JOB_LORD_KNIGHT:
  5031. case JOB_HIGH_PRIEST:
  5032. case JOB_HIGH_WIZARD:
  5033. case JOB_WHITESMITH:
  5034. case JOB_SNIPER:
  5035. case JOB_ASSASSIN_CROSS:
  5036. return msg_txt(NULL,582 - JOB_LORD_KNIGHT+class_);
  5037. case JOB_LORD_KNIGHT2:
  5038. return msg_txt(NULL,582);
  5039. case JOB_PALADIN:
  5040. case JOB_CHAMPION:
  5041. case JOB_PROFESSOR:
  5042. case JOB_STALKER:
  5043. case JOB_CREATOR:
  5044. case JOB_CLOWN:
  5045. case JOB_GYPSY:
  5046. return msg_txt(NULL,588 - JOB_PALADIN + class_);
  5047. case JOB_PALADIN2:
  5048. return msg_txt(NULL,588);
  5049. case JOB_BABY:
  5050. case JOB_BABY_SWORDMAN:
  5051. case JOB_BABY_MAGE:
  5052. case JOB_BABY_ARCHER:
  5053. case JOB_BABY_ACOLYTE:
  5054. case JOB_BABY_MERCHANT:
  5055. case JOB_BABY_THIEF:
  5056. return msg_txt(NULL,595 - JOB_BABY + class_);
  5057. case JOB_BABY_KNIGHT:
  5058. case JOB_BABY_PRIEST:
  5059. case JOB_BABY_WIZARD:
  5060. case JOB_BABY_BLACKSMITH:
  5061. case JOB_BABY_HUNTER:
  5062. case JOB_BABY_ASSASSIN:
  5063. return msg_txt(NULL,602 - JOB_BABY_KNIGHT + class_);
  5064. case JOB_BABY_KNIGHT2:
  5065. return msg_txt(NULL,602);
  5066. case JOB_BABY_CRUSADER:
  5067. case JOB_BABY_MONK:
  5068. case JOB_BABY_SAGE:
  5069. case JOB_BABY_ROGUE:
  5070. case JOB_BABY_ALCHEMIST:
  5071. case JOB_BABY_BARD:
  5072. case JOB_BABY_DANCER:
  5073. return msg_txt(NULL,608 - JOB_BABY_CRUSADER + class_);
  5074. case JOB_BABY_CRUSADER2:
  5075. return msg_txt(NULL,608);
  5076. case JOB_SUPER_BABY:
  5077. return msg_txt(NULL,615);
  5078. case JOB_TAEKWON:
  5079. return msg_txt(NULL,616);
  5080. case JOB_STAR_GLADIATOR:
  5081. case JOB_STAR_GLADIATOR2:
  5082. return msg_txt(NULL,617);
  5083. case JOB_SOUL_LINKER:
  5084. return msg_txt(NULL,618);
  5085. case JOB_GANGSI:
  5086. case JOB_DEATH_KNIGHT:
  5087. case JOB_DARK_COLLECTOR:
  5088. return msg_txt(NULL,622 - JOB_GANGSI+class_);
  5089. case JOB_RUNE_KNIGHT:
  5090. case JOB_WARLOCK:
  5091. case JOB_RANGER:
  5092. case JOB_ARCH_BISHOP:
  5093. case JOB_MECHANIC:
  5094. case JOB_GUILLOTINE_CROSS:
  5095. return msg_txt(NULL,625 - JOB_RUNE_KNIGHT+class_);
  5096. case JOB_RUNE_KNIGHT_T:
  5097. case JOB_WARLOCK_T:
  5098. case JOB_RANGER_T:
  5099. case JOB_ARCH_BISHOP_T:
  5100. case JOB_MECHANIC_T:
  5101. case JOB_GUILLOTINE_CROSS_T:
  5102. return msg_txt(NULL,681 - JOB_RUNE_KNIGHT_T+class_);
  5103. case JOB_ROYAL_GUARD:
  5104. case JOB_SORCERER:
  5105. case JOB_MINSTREL:
  5106. case JOB_WANDERER:
  5107. case JOB_SURA:
  5108. case JOB_GENETIC:
  5109. case JOB_SHADOW_CHASER:
  5110. return msg_txt(NULL,631 - JOB_ROYAL_GUARD+class_);
  5111. case JOB_ROYAL_GUARD_T:
  5112. case JOB_SORCERER_T:
  5113. case JOB_MINSTREL_T:
  5114. case JOB_WANDERER_T:
  5115. case JOB_SURA_T:
  5116. case JOB_GENETIC_T:
  5117. case JOB_SHADOW_CHASER_T:
  5118. return msg_txt(NULL,687 - JOB_ROYAL_GUARD_T+class_);
  5119. case JOB_RUNE_KNIGHT2:
  5120. case JOB_RUNE_KNIGHT_T2:
  5121. return msg_txt(NULL,625);
  5122. case JOB_ROYAL_GUARD2:
  5123. case JOB_ROYAL_GUARD_T2:
  5124. return msg_txt(NULL,631);
  5125. case JOB_RANGER2:
  5126. case JOB_RANGER_T2:
  5127. return msg_txt(NULL,627);
  5128. case JOB_MECHANIC2:
  5129. case JOB_MECHANIC_T2:
  5130. return msg_txt(NULL,629);
  5131. case JOB_BABY_RUNE:
  5132. case JOB_BABY_WARLOCK:
  5133. case JOB_BABY_RANGER:
  5134. case JOB_BABY_BISHOP:
  5135. case JOB_BABY_MECHANIC:
  5136. case JOB_BABY_CROSS:
  5137. case JOB_BABY_GUARD:
  5138. case JOB_BABY_SORCERER:
  5139. case JOB_BABY_MINSTREL:
  5140. case JOB_BABY_WANDERER:
  5141. case JOB_BABY_SURA:
  5142. case JOB_BABY_GENETIC:
  5143. case JOB_BABY_CHASER:
  5144. return msg_txt(NULL,638 - JOB_BABY_RUNE+class_);
  5145. case JOB_BABY_RUNE2:
  5146. return msg_txt(NULL,638);
  5147. case JOB_BABY_GUARD2:
  5148. return msg_txt(NULL,644);
  5149. case JOB_BABY_RANGER2:
  5150. return msg_txt(NULL,640);
  5151. case JOB_BABY_MECHANIC2:
  5152. return msg_txt(NULL,642);
  5153. case JOB_SUPER_NOVICE_E:
  5154. case JOB_SUPER_BABY_E:
  5155. return msg_txt(NULL,651 - JOB_SUPER_NOVICE_E+class_);
  5156. case JOB_KAGEROU:
  5157. case JOB_OBORO:
  5158. return msg_txt(NULL,653 - JOB_KAGEROU+class_);
  5159. case JOB_REBELLION:
  5160. return msg_txt(NULL,695);
  5161. default:
  5162. return msg_txt(NULL,655);
  5163. }
  5164. }
  5165. /*====================================================
  5166. * Timered function to make id follow a target.
  5167. * @id = bl.id (player only atm)
  5168. * target is define in sd->followtarget (bl.id)
  5169. * used by pc_follow
  5170. *----------------------------------------------------*/
  5171. int pc_follow_timer(int tid, unsigned int tick, int id, intptr_t data)
  5172. {
  5173. struct map_session_data *sd;
  5174. struct block_list *tbl;
  5175. sd = map_id2sd(id);
  5176. nullpo_ret(sd);
  5177. if (sd->followtimer != tid){
  5178. ShowError("pc_follow_timer %d != %d\n",sd->followtimer,tid);
  5179. sd->followtimer = INVALID_TIMER;
  5180. return 0;
  5181. }
  5182. sd->followtimer = INVALID_TIMER;
  5183. tbl = map_id2bl(sd->followtarget);
  5184. if (tbl == NULL || pc_isdead(sd) || status_isdead(tbl))
  5185. {
  5186. pc_stop_following(sd);
  5187. return 0;
  5188. }
  5189. // either player or target is currently detached from map blocks (could be teleporting),
  5190. // but still connected to this map, so we'll just increment the timer and check back later
  5191. if (sd->bl.prev != NULL && tbl->prev != NULL &&
  5192. sd->ud.skilltimer == INVALID_TIMER && sd->ud.attacktimer == INVALID_TIMER && sd->ud.walktimer == INVALID_TIMER)
  5193. {
  5194. if((sd->bl.m == tbl->m) && unit_can_reach_bl(&sd->bl,tbl, AREA_SIZE, 0, NULL, NULL)) {
  5195. if (!check_distance_bl(&sd->bl, tbl, 5))
  5196. unit_walktobl(&sd->bl, tbl, 5, 0);
  5197. } else
  5198. pc_setpos(sd, map_id2index(tbl->m), tbl->x, tbl->y, CLR_TELEPORT);
  5199. }
  5200. sd->followtimer = add_timer(
  5201. tick + 1000, // increase time a bit to loosen up map's load
  5202. pc_follow_timer, sd->bl.id, 0);
  5203. return 0;
  5204. }
  5205. int pc_stop_following (struct map_session_data *sd)
  5206. {
  5207. nullpo_ret(sd);
  5208. if (sd->followtimer != INVALID_TIMER) {
  5209. delete_timer(sd->followtimer,pc_follow_timer);
  5210. sd->followtimer = INVALID_TIMER;
  5211. }
  5212. sd->followtarget = -1;
  5213. sd->ud.target_to = 0;
  5214. unit_stop_walking(&sd->bl, 1);
  5215. return 0;
  5216. }
  5217. int pc_follow(struct map_session_data *sd,int target_id)
  5218. {
  5219. struct block_list *bl = map_id2bl(target_id);
  5220. if (bl == NULL /*|| bl->type != BL_PC*/)
  5221. return 1;
  5222. if (sd->followtimer != INVALID_TIMER)
  5223. pc_stop_following(sd);
  5224. sd->followtarget = target_id;
  5225. pc_follow_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
  5226. return 0;
  5227. }
  5228. int pc_checkbaselevelup(struct map_session_data *sd) {
  5229. unsigned int next = pc_nextbaseexp(sd);
  5230. if (!next || sd->status.base_exp < next)
  5231. return 0;
  5232. do {
  5233. sd->status.base_exp -= next;
  5234. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  5235. if(!battle_config.multi_level_up && sd->status.base_exp > next-1)
  5236. sd->status.base_exp = next-1;
  5237. next = pc_gets_status_point(sd->status.base_level);
  5238. sd->status.base_level ++;
  5239. sd->status.status_point += next;
  5240. } while ((next=pc_nextbaseexp(sd)) > 0 && sd->status.base_exp >= next);
  5241. if (battle_config.pet_lv_rate && sd->pd) //<Skotlex> update pet's level
  5242. status_calc_pet(sd->pd,0);
  5243. clif_updatestatus(sd,SP_STATUSPOINT);
  5244. clif_updatestatus(sd,SP_BASELEVEL);
  5245. clif_updatestatus(sd,SP_BASEEXP);
  5246. clif_updatestatus(sd,SP_NEXTBASEEXP);
  5247. status_calc_pc(sd,0);
  5248. status_percent_heal(&sd->bl,100,100);
  5249. if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) {
  5250. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_KYRIE),100,1,skill_get_time(PR_KYRIE,1));
  5251. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_IMPOSITIO),100,1,skill_get_time(PR_IMPOSITIO,1));
  5252. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_MAGNIFICAT),100,1,skill_get_time(PR_MAGNIFICAT,1));
  5253. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_GLORIA),100,1,skill_get_time(PR_GLORIA,1));
  5254. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_SUFFRAGIUM),100,1,skill_get_time(PR_SUFFRAGIUM,1));
  5255. if (sd->state.snovice_dead_flag)
  5256. sd->state.snovice_dead_flag = 0; //Reenable steelbody resurrection on dead.
  5257. } else if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON ) {
  5258. sc_start(&sd->bl,&sd->bl,status_skill2sc(AL_INCAGI),100,10,600000);
  5259. sc_start(&sd->bl,&sd->bl,status_skill2sc(AL_BLESSING),100,10,600000);
  5260. }
  5261. clif_misceffect(&sd->bl,0);
  5262. npc_script_event(sd, NPCE_BASELVUP); //LORDALFA - LVLUPEVENT
  5263. if(sd->status.party_id)
  5264. party_send_levelup(sd);
  5265. pc_baselevelchanged(sd);
  5266. return 1;
  5267. }
  5268. void pc_baselevelchanged(struct map_session_data *sd) {
  5269. #ifdef RENEWAL
  5270. int i;
  5271. for( i = 0; i < EQI_MAX; i++ ) {
  5272. if( sd->equip_index[i] >= 0 ) {
  5273. if( sd->inventory_data[ sd->equip_index[i] ]->elvmax && sd->status.base_level > (unsigned int)sd->inventory_data[ sd->equip_index[i] ]->elvmax )
  5274. pc_unequipitem(sd, sd->equip_index[i], 3);
  5275. }
  5276. }
  5277. #endif
  5278. }
  5279. int pc_checkjoblevelup(struct map_session_data *sd)
  5280. {
  5281. unsigned int next = pc_nextjobexp(sd);
  5282. nullpo_ret(sd);
  5283. if(!next || sd->status.job_exp < next)
  5284. return 0;
  5285. do {
  5286. sd->status.job_exp -= next;
  5287. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  5288. if(!battle_config.multi_level_up && sd->status.job_exp > next-1)
  5289. sd->status.job_exp = next-1;
  5290. sd->status.job_level ++;
  5291. sd->status.skill_point ++;
  5292. } while ((next=pc_nextjobexp(sd)) > 0 && sd->status.job_exp >= next);
  5293. clif_updatestatus(sd,SP_JOBLEVEL);
  5294. clif_updatestatus(sd,SP_JOBEXP);
  5295. clif_updatestatus(sd,SP_NEXTJOBEXP);
  5296. clif_updatestatus(sd,SP_SKILLPOINT);
  5297. status_calc_pc(sd,0);
  5298. clif_misceffect(&sd->bl,1);
  5299. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  5300. clif_status_change(&sd->bl,SI_DEVIL, 1, 0, 0, 0, 1); //Permanent blind effect from SG_DEVIL.
  5301. npc_script_event(sd, NPCE_JOBLVUP);
  5302. return 1;
  5303. }
  5304. /*==========================================
  5305. * Alters experienced based on self bonuses that do not get even shared to the party.
  5306. *------------------------------------------*/
  5307. static void pc_calcexp(struct map_session_data *sd, unsigned int *base_exp, unsigned int *job_exp, struct block_list *src)
  5308. {
  5309. int bonus = 0;
  5310. struct status_data *status = status_get_status_data(src);
  5311. if( sd->expaddrace[status->race] )
  5312. bonus += sd->expaddrace[status->race];
  5313. if( sd->expaddrace[RC_ALL] )
  5314. bonus += sd->expaddrace[RC_ALL];
  5315. if( sd->expaddclass[status->class_] )
  5316. bonus += sd->expaddclass[status->class_];
  5317. if( sd->expaddclass[CLASS_ALL] )
  5318. bonus += sd->expaddclass[CLASS_ALL];
  5319. if (battle_config.pk_mode &&
  5320. (int)(status_get_lv(src) - sd->status.base_level) >= 20)
  5321. bonus += 15; // pk_mode additional exp if monster >20 levels [Valaris]
  5322. if (sd->sc.data[SC_EXPBOOST]) {
  5323. bonus += sd->sc.data[SC_EXPBOOST]->val1;
  5324. if( battle_config.vip_bm_increase && pc_isvip(sd) ) // Increase Battle Manual EXP rate for VIP.
  5325. bonus += ( sd->sc.data[SC_EXPBOOST]->val1 / battle_config.vip_bm_increase );
  5326. }
  5327. *base_exp = (unsigned int) cap_value(*base_exp + (double)*base_exp * bonus/100., 1, UINT_MAX);
  5328. if (sd->sc.data[SC_JEXPBOOST])
  5329. bonus += sd->sc.data[SC_JEXPBOOST]->val1;
  5330. *job_exp = (unsigned int) cap_value(*job_exp + (double)*job_exp * bonus/100., 1, UINT_MAX);
  5331. return;
  5332. }
  5333. /*==========================================
  5334. * Give x exp at sd player and calculate remaining exp for next lvl
  5335. *------------------------------------------*/
  5336. int pc_gainexp(struct map_session_data *sd, struct block_list *src, unsigned int base_exp,unsigned int job_exp,bool quest)
  5337. {
  5338. float nextbp=0, nextjp=0;
  5339. unsigned int nextb=0, nextj=0;
  5340. nullpo_ret(sd);
  5341. if(sd->bl.prev == NULL || pc_isdead(sd))
  5342. return 0;
  5343. if(!battle_config.pvp_exp && map[sd->bl.m].flag.pvp) // [MouseJstr]
  5344. return 0; // no exp on pvp maps
  5345. if(sd->status.guild_id>0)
  5346. base_exp-=guild_payexp(sd,base_exp);
  5347. if(src) pc_calcexp(sd, &base_exp, &job_exp, src);
  5348. nextb = pc_nextbaseexp(sd);
  5349. nextj = pc_nextjobexp(sd);
  5350. if(sd->state.showexp || battle_config.max_exp_gain_rate){
  5351. if (nextb > 0)
  5352. nextbp = (float) base_exp / (float) nextb;
  5353. if (nextj > 0)
  5354. nextjp = (float) job_exp / (float) nextj;
  5355. if(battle_config.max_exp_gain_rate) {
  5356. if (nextbp > battle_config.max_exp_gain_rate/1000.) {
  5357. //Note that this value should never be greater than the original
  5358. //base_exp, therefore no overflow checks are needed. [Skotlex]
  5359. base_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextb);
  5360. if (sd->state.showexp)
  5361. nextbp = (float) base_exp / (float) nextb;
  5362. }
  5363. if (nextjp > battle_config.max_exp_gain_rate/1000.) {
  5364. job_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextj);
  5365. if (sd->state.showexp)
  5366. nextjp = (float) job_exp / (float) nextj;
  5367. }
  5368. }
  5369. }
  5370. //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]
  5371. if (base_exp) {
  5372. nextb = nextb?UINT_MAX:pc_thisbaseexp(sd);
  5373. if(sd->status.base_exp > nextb - base_exp)
  5374. sd->status.base_exp = nextb;
  5375. else
  5376. sd->status.base_exp += base_exp;
  5377. pc_checkbaselevelup(sd);
  5378. clif_updatestatus(sd,SP_BASEEXP);
  5379. }
  5380. if (job_exp) {
  5381. nextj = nextj?UINT_MAX:pc_thisjobexp(sd);
  5382. if(sd->status.job_exp > nextj - job_exp)
  5383. sd->status.job_exp = nextj;
  5384. else
  5385. sd->status.job_exp += job_exp;
  5386. pc_checkjoblevelup(sd);
  5387. clif_updatestatus(sd,SP_JOBEXP);
  5388. }
  5389. if(base_exp)
  5390. clif_displayexp(sd, base_exp, SP_BASEEXP, quest);
  5391. if(job_exp)
  5392. clif_displayexp(sd, job_exp, SP_JOBEXP, quest);
  5393. if(sd->state.showexp) {
  5394. char output[256];
  5395. sprintf(output,
  5396. "Experience Gained Base:%u (%.2f%%) Job:%u (%.2f%%)",base_exp,nextbp*(float)100,job_exp,nextjp*(float)100);
  5397. clif_disp_onlyself(sd,output,strlen(output));
  5398. }
  5399. return 1;
  5400. }
  5401. /*==========================================
  5402. * Returns max level for this character.
  5403. *------------------------------------------*/
  5404. unsigned int pc_maxbaselv(struct map_session_data *sd){
  5405. return job_info[pc_class2idx(sd->status.class_)].max_level[0];
  5406. }
  5407. unsigned int pc_maxjoblv(struct map_session_data *sd){
  5408. return job_info[pc_class2idx(sd->status.class_)].max_level[1];
  5409. }
  5410. /*==========================================
  5411. * base level exp lookup.
  5412. *------------------------------------------*/
  5413. //Base exp needed for next level.
  5414. unsigned int pc_nextbaseexp(struct map_session_data *sd){
  5415. nullpo_ret(sd);
  5416. if(sd->status.base_level>=pc_maxbaselv(sd) || sd->status.base_level==0)
  5417. return 0;
  5418. return job_info[pc_class2idx(sd->status.class_)].exp_table[0][sd->status.base_level-1];
  5419. }
  5420. //Base exp needed for this level.
  5421. unsigned int pc_thisbaseexp(struct map_session_data *sd){
  5422. if(sd->status.base_level>pc_maxbaselv(sd) || sd->status.base_level<=1)
  5423. return 0;
  5424. return job_info[pc_class2idx(sd->status.class_)].exp_table[0][sd->status.base_level-2];
  5425. }
  5426. /*==========================================
  5427. * job level exp lookup
  5428. * Return:
  5429. * 0 = not found
  5430. * x = exp for level
  5431. *------------------------------------------*/
  5432. //Job exp needed for next level.
  5433. unsigned int pc_nextjobexp(struct map_session_data *sd){
  5434. nullpo_ret(sd);
  5435. if(sd->status.job_level>=pc_maxjoblv(sd) || sd->status.job_level==0)
  5436. return 0;
  5437. return job_info[pc_class2idx(sd->status.class_)].exp_table[1][sd->status.job_level-1];
  5438. }
  5439. //Job exp needed for this level.
  5440. unsigned int pc_thisjobexp(struct map_session_data *sd){
  5441. if(sd->status.job_level>pc_maxjoblv(sd) || sd->status.job_level<=1)
  5442. return 0;
  5443. return job_info[pc_class2idx(sd->status.class_)].exp_table[1][sd->status.job_level-2];
  5444. }
  5445. /// Returns the value of the specified stat.
  5446. static int pc_getstat(struct map_session_data* sd, int type)
  5447. {
  5448. nullpo_retr(-1, sd);
  5449. switch( type ) {
  5450. case SP_STR: return sd->status.str;
  5451. case SP_AGI: return sd->status.agi;
  5452. case SP_VIT: return sd->status.vit;
  5453. case SP_INT: return sd->status.int_;
  5454. case SP_DEX: return sd->status.dex;
  5455. case SP_LUK: return sd->status.luk;
  5456. default:
  5457. return -1;
  5458. }
  5459. }
  5460. /// Sets the specified stat to the specified value.
  5461. /// Returns the new value.
  5462. static int pc_setstat(struct map_session_data* sd, int type, int val)
  5463. {
  5464. nullpo_retr(-1, sd);
  5465. switch( type ) {
  5466. case SP_STR: sd->status.str = val; break;
  5467. case SP_AGI: sd->status.agi = val; break;
  5468. case SP_VIT: sd->status.vit = val; break;
  5469. case SP_INT: sd->status.int_ = val; break;
  5470. case SP_DEX: sd->status.dex = val; break;
  5471. case SP_LUK: sd->status.luk = val; break;
  5472. default:
  5473. return -1;
  5474. }
  5475. return val;
  5476. }
  5477. // Calculates the number of status points PC gets when leveling up (from level to level+1)
  5478. int pc_gets_status_point(int level)
  5479. {
  5480. if (battle_config.use_statpoint_table) //Use values from "db/statpoint.txt"
  5481. return (statp[level+1] - statp[level]);
  5482. else //Default increase
  5483. return ((level+15) / 5);
  5484. }
  5485. /// Returns the number of stat points needed to change the specified stat by val.
  5486. /// If val is negative, returns the number of stat points that would be needed to
  5487. /// raise the specified stat from (current value - val) to current value.
  5488. int pc_need_status_point(struct map_session_data* sd, int type, int val)
  5489. {
  5490. int low, high, sp = 0, max = 0;
  5491. if ( val == 0 )
  5492. return 0;
  5493. low = pc_getstat(sd,type);
  5494. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR));
  5495. if ( low >= max && val > 0 )
  5496. return 0; // Official servers show '0' when max is reached
  5497. high = low + val;
  5498. if ( val < 0 )
  5499. swap(low, high);
  5500. for ( ; low < high; low++ )
  5501. #ifdef RENEWAL // renewal status point cost formula
  5502. sp += (low < 100) ? (2 + (low - 1) / 10) : (16 + 4 * ((low - 100) / 5));
  5503. #else
  5504. sp += ( 1 + (low + 9) / 10 );
  5505. #endif
  5506. return sp;
  5507. }
  5508. /// Raises a stat by 1.
  5509. /// Obeys max_parameter limits.
  5510. /// Subtracts stat points.
  5511. ///
  5512. /// @param type The stat to change (see enum _sp)
  5513. int pc_statusup(struct map_session_data* sd, int type)
  5514. {
  5515. int max, need, val;
  5516. nullpo_ret(sd);
  5517. // check conditions
  5518. need = pc_need_status_point(sd,type,1);
  5519. if( type < SP_STR || type > SP_LUK || need < 0 || need > sd->status.status_point )
  5520. {
  5521. clif_statusupack(sd,type,0,0);
  5522. return 1;
  5523. }
  5524. // check limits
  5525. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR));
  5526. if( pc_getstat(sd,type) >= max )
  5527. {
  5528. clif_statusupack(sd,type,0,0);
  5529. return 1;
  5530. }
  5531. // set new values
  5532. val = pc_setstat(sd, type, pc_getstat(sd,type) + 1);
  5533. sd->status.status_point -= need;
  5534. status_calc_pc(sd,0);
  5535. // update increase cost indicator
  5536. if( need != pc_need_status_point(sd,type,1) )
  5537. clif_updatestatus(sd, SP_USTR + type-SP_STR);
  5538. // update statpoint count
  5539. clif_updatestatus(sd,SP_STATUSPOINT);
  5540. // update stat value
  5541. clif_statusupack(sd,type,1,val); // required
  5542. if( val > 255 )
  5543. clif_updatestatus(sd,type); // send after the 'ack' to override the truncated value
  5544. return 0;
  5545. }
  5546. /// Raises a stat by the specified amount.
  5547. /// Obeys max_parameter limits.
  5548. /// Does not subtract stat points.
  5549. ///
  5550. /// @param type The stat to change (see enum _sp)
  5551. /// @param val The stat increase amount.
  5552. int pc_statusup2(struct map_session_data* sd, int type, int val)
  5553. {
  5554. int max, need;
  5555. nullpo_ret(sd);
  5556. if( type < SP_STR || type > SP_LUK )
  5557. {
  5558. clif_statusupack(sd,type,0,0);
  5559. return 1;
  5560. }
  5561. need = pc_need_status_point(sd,type,1);
  5562. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR)); // set new value
  5563. val = pc_setstat(sd, type, cap_value(pc_getstat(sd,type) + val, 1, max));
  5564. status_calc_pc(sd,0);
  5565. // update increase cost indicator
  5566. if( need != pc_need_status_point(sd,type,1) )
  5567. clif_updatestatus(sd, SP_USTR + type-SP_STR);
  5568. // update stat value
  5569. clif_statusupack(sd,type,1,val); // required
  5570. if( val > 255 )
  5571. clif_updatestatus(sd,type); // send after the 'ack' to override the truncated value
  5572. return 0;
  5573. }
  5574. /*==========================================
  5575. * Update skill_lv for player sd
  5576. * Skill point allocation
  5577. *------------------------------------------*/
  5578. int pc_skillup(struct map_session_data *sd,uint16 skill_id)
  5579. {
  5580. nullpo_ret(sd);
  5581. if( skill_id >= GD_SKILLBASE && skill_id < GD_SKILLBASE+MAX_GUILDSKILL )
  5582. {
  5583. guild_skillup(sd, skill_id);
  5584. return 0;
  5585. }
  5586. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE+MAX_HOMUNSKILL && sd->hd )
  5587. {
  5588. merc_hom_skillup(sd->hd, skill_id);
  5589. return 0;
  5590. }
  5591. if(skill_id >= MAX_SKILL )
  5592. return 0;
  5593. if( sd->status.skill_point > 0 &&
  5594. sd->status.skill[skill_id].id &&
  5595. sd->status.skill[skill_id].flag == SKILL_FLAG_PERMANENT && //Don't allow raising while you have granted skills. [Skotlex]
  5596. sd->status.skill[skill_id].lv < skill_tree_get_max(skill_id, sd->status.class_) )
  5597. {
  5598. int lv,range, upgradable;
  5599. sd->status.skill[skill_id].lv++;
  5600. sd->status.skill_point--;
  5601. if( !skill_get_inf(skill_id) )
  5602. status_calc_pc(sd,0); // Only recalculate for passive skills.
  5603. 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) )
  5604. pc_calc_skilltree(sd); // Required to grant all TK Ranger skills.
  5605. else
  5606. pc_check_skilltree(sd, skill_id); // Check if a new skill can Lvlup
  5607. lv = sd->status.skill[skill_id].lv;
  5608. range = skill_get_range2(&sd->bl, skill_id, lv);
  5609. upgradable = (lv < skill_tree_get_max(sd->status.skill[skill_id].id, sd->status.class_)) ? 1 : 0;
  5610. clif_skillup(sd,skill_id,lv,range,upgradable);
  5611. clif_updatestatus(sd,SP_SKILLPOINT);
  5612. if( skill_id == GN_REMODELING_CART ) /* cart weight info was updated by status_calc_pc */
  5613. clif_updatestatus(sd,SP_CARTINFO);
  5614. if (!pc_has_permission(sd, PC_PERM_ALL_SKILL)) // may skill everything at any time anyways, and this would cause a huge slowdown
  5615. clif_skillinfoblock(sd);
  5616. }
  5617. return 0;
  5618. }
  5619. /*==========================================
  5620. * /allskill
  5621. *------------------------------------------*/
  5622. int pc_allskillup(struct map_session_data *sd)
  5623. {
  5624. int i;
  5625. nullpo_ret(sd);
  5626. for(i=0;i<MAX_SKILL;i++){
  5627. 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) {
  5628. sd->status.skill[i].lv = (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  5629. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  5630. if (sd->status.skill[i].lv == 0)
  5631. sd->status.skill[i].id = 0;
  5632. }
  5633. }
  5634. if (pc_has_permission(sd, PC_PERM_ALL_SKILL))
  5635. { //Get ALL skills except npc/guild ones. [Skotlex]
  5636. //and except SG_DEVIL [Komurka] and MO_TRIPLEATTACK and RG_SNATCHER [ultramage]
  5637. for(i=0;i<MAX_SKILL;i++){
  5638. switch( i ) {
  5639. case SG_DEVIL:
  5640. case MO_TRIPLEATTACK:
  5641. case RG_SNATCHER:
  5642. continue;
  5643. default:
  5644. if( !(skill_get_inf2(i)&(INF2_NPC_SKILL|INF2_GUILD_SKILL)) )
  5645. if ( ( sd->status.skill[i].lv = skill_get_max(i) ) )//Nonexistant skills should return a max of 0 anyway.
  5646. sd->status.skill[i].id = i;
  5647. }
  5648. }
  5649. } else {
  5650. int id;
  5651. for(i=0;i < MAX_SKILL_TREE && (id=skill_tree[pc_class2idx(sd->status.class_)][i].id)>0;i++){
  5652. int inf2 = skill_get_inf2(id);
  5653. if (
  5654. (inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  5655. (inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) ||
  5656. id==SG_DEVIL
  5657. )
  5658. continue; //Cannot be learned normally.
  5659. sd->status.skill[id].id = id;
  5660. sd->status.skill[id].lv = skill_tree_get_max(id, sd->status.class_); // celest
  5661. }
  5662. }
  5663. status_calc_pc(sd,0);
  5664. //Required because if you could level up all skills previously,
  5665. //the update will not be sent as only the lv variable changes.
  5666. clif_skillinfoblock(sd);
  5667. return 0;
  5668. }
  5669. /*==========================================
  5670. * /resetlvl
  5671. *------------------------------------------*/
  5672. int pc_resetlvl(struct map_session_data* sd,int type)
  5673. {
  5674. int i;
  5675. nullpo_ret(sd);
  5676. if (type != 3) //Also reset skills
  5677. pc_resetskill(sd, 0);
  5678. if(type == 1){
  5679. sd->status.skill_point=0;
  5680. sd->status.base_level=1;
  5681. sd->status.job_level=1;
  5682. sd->status.base_exp=0;
  5683. sd->status.job_exp=0;
  5684. if(sd->sc.option !=0)
  5685. sd->sc.option = 0;
  5686. sd->status.str=1;
  5687. sd->status.agi=1;
  5688. sd->status.vit=1;
  5689. sd->status.int_=1;
  5690. sd->status.dex=1;
  5691. sd->status.luk=1;
  5692. if(sd->status.class_ == JOB_NOVICE_HIGH) {
  5693. sd->status.status_point=100; // not 88 [celest]
  5694. // give platinum skills upon changing
  5695. pc_skill(sd,142,1,0);
  5696. pc_skill(sd,143,1,0);
  5697. }
  5698. }
  5699. if(type == 2){
  5700. sd->status.skill_point=0;
  5701. sd->status.base_level=1;
  5702. sd->status.job_level=1;
  5703. sd->status.base_exp=0;
  5704. sd->status.job_exp=0;
  5705. }
  5706. if(type == 3){
  5707. sd->status.base_level=1;
  5708. sd->status.base_exp=0;
  5709. }
  5710. if(type == 4){
  5711. sd->status.job_level=1;
  5712. sd->status.job_exp=0;
  5713. }
  5714. clif_updatestatus(sd,SP_STATUSPOINT);
  5715. clif_updatestatus(sd,SP_STR);
  5716. clif_updatestatus(sd,SP_AGI);
  5717. clif_updatestatus(sd,SP_VIT);
  5718. clif_updatestatus(sd,SP_INT);
  5719. clif_updatestatus(sd,SP_DEX);
  5720. clif_updatestatus(sd,SP_LUK);
  5721. clif_updatestatus(sd,SP_BASELEVEL);
  5722. clif_updatestatus(sd,SP_JOBLEVEL);
  5723. clif_updatestatus(sd,SP_STATUSPOINT);
  5724. clif_updatestatus(sd,SP_BASEEXP);
  5725. clif_updatestatus(sd,SP_JOBEXP);
  5726. clif_updatestatus(sd,SP_NEXTBASEEXP);
  5727. clif_updatestatus(sd,SP_NEXTJOBEXP);
  5728. clif_updatestatus(sd,SP_SKILLPOINT);
  5729. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  5730. clif_updatestatus(sd,SP_UAGI);
  5731. clif_updatestatus(sd,SP_UVIT);
  5732. clif_updatestatus(sd,SP_UINT);
  5733. clif_updatestatus(sd,SP_UDEX);
  5734. clif_updatestatus(sd,SP_ULUK); // End Addition
  5735. for(i=0;i<EQI_MAX;i++) { // unequip items that can't be equipped by base 1 [Valaris]
  5736. if(sd->equip_index[i] >= 0)
  5737. if(!pc_isequip(sd,sd->equip_index[i]))
  5738. pc_unequipitem(sd,sd->equip_index[i],2);
  5739. }
  5740. if ((type == 1 || type == 2 || type == 3) && sd->status.party_id)
  5741. party_send_levelup(sd);
  5742. status_calc_pc(sd,0);
  5743. clif_skillinfoblock(sd);
  5744. return 0;
  5745. }
  5746. /*==========================================
  5747. * /resetstate
  5748. *------------------------------------------*/
  5749. int pc_resetstate(struct map_session_data* sd)
  5750. {
  5751. nullpo_ret(sd);
  5752. if (battle_config.use_statpoint_table)
  5753. { // New statpoint table used here - Dexity
  5754. if (sd->status.base_level > MAX_LEVEL)
  5755. { //statp[] goes out of bounds, can't reset!
  5756. ShowError("pc_resetstate: Can't reset stats of %d:%d, the base level (%d) is greater than the max level supported (%d)\n",
  5757. sd->status.account_id, sd->status.char_id, sd->status.base_level, MAX_LEVEL);
  5758. return 0;
  5759. }
  5760. sd->status.status_point = statp[sd->status.base_level] + ( sd->class_&JOBL_UPPER ? 52 : 0 ); // extra 52+48=100 stat points
  5761. }
  5762. else
  5763. {
  5764. int add=0;
  5765. add += pc_need_status_point(sd, SP_STR, 1-pc_getstat(sd, SP_STR));
  5766. add += pc_need_status_point(sd, SP_AGI, 1-pc_getstat(sd, SP_AGI));
  5767. add += pc_need_status_point(sd, SP_VIT, 1-pc_getstat(sd, SP_VIT));
  5768. add += pc_need_status_point(sd, SP_INT, 1-pc_getstat(sd, SP_INT));
  5769. add += pc_need_status_point(sd, SP_DEX, 1-pc_getstat(sd, SP_DEX));
  5770. add += pc_need_status_point(sd, SP_LUK, 1-pc_getstat(sd, SP_LUK));
  5771. sd->status.status_point+=add;
  5772. }
  5773. pc_setstat(sd, SP_STR, 1);
  5774. pc_setstat(sd, SP_AGI, 1);
  5775. pc_setstat(sd, SP_VIT, 1);
  5776. pc_setstat(sd, SP_INT, 1);
  5777. pc_setstat(sd, SP_DEX, 1);
  5778. pc_setstat(sd, SP_LUK, 1);
  5779. clif_updatestatus(sd,SP_STR);
  5780. clif_updatestatus(sd,SP_AGI);
  5781. clif_updatestatus(sd,SP_VIT);
  5782. clif_updatestatus(sd,SP_INT);
  5783. clif_updatestatus(sd,SP_DEX);
  5784. clif_updatestatus(sd,SP_LUK);
  5785. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  5786. clif_updatestatus(sd,SP_UAGI);
  5787. clif_updatestatus(sd,SP_UVIT);
  5788. clif_updatestatus(sd,SP_UINT);
  5789. clif_updatestatus(sd,SP_UDEX);
  5790. clif_updatestatus(sd,SP_ULUK); // End Addition
  5791. clif_updatestatus(sd,SP_STATUSPOINT);
  5792. if( sd->mission_mobid ) { //bugreport:2200
  5793. sd->mission_mobid = 0;
  5794. sd->mission_count = 0;
  5795. pc_setglobalreg(sd,"TK_MISSION_ID", 0);
  5796. }
  5797. status_calc_pc(sd,0);
  5798. return 1;
  5799. }
  5800. /*==========================================
  5801. * /resetskill
  5802. * if flag&1, perform block resync and status_calc call.
  5803. * if flag&2, just count total amount of skill points used by player, do not really reset.
  5804. * if flag&4, just reset the skills if the player class is a bard/dancer type (for changesex.)
  5805. *------------------------------------------*/
  5806. int pc_resetskill(struct map_session_data* sd, int flag)
  5807. {
  5808. int i, skill_point=0;
  5809. nullpo_ret(sd);
  5810. if( flag&4 && (sd->class_&MAPID_UPPERMASK) != MAPID_BARDDANCER )
  5811. return 0;
  5812. if( !(flag&2) ) { //Remove stuff lost when resetting skills.
  5813. /**
  5814. * 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)
  5815. **/
  5816. if( (sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc_famerank(sd->status.char_id, MAPID_TAEKWON) )
  5817. return 0;
  5818. if( pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd) )
  5819. clif_status_load(&sd->bl, SI_DEVIL, 0); //Remove perma blindness due to skill-reset. [Skotlex]
  5820. i = sd->sc.option;
  5821. if( i&OPTION_RIDING && pc_checkskill(sd, KN_RIDING) )
  5822. i &= ~OPTION_RIDING;
  5823. if( i&OPTION_FALCON && pc_checkskill(sd, HT_FALCON) )
  5824. i &= ~OPTION_FALCON;
  5825. if( i&OPTION_DRAGON && pc_checkskill(sd, RK_DRAGONTRAINING) )
  5826. i &= ~OPTION_DRAGON;
  5827. if( i&OPTION_WUG && pc_checkskill(sd, RA_WUGMASTERY) )
  5828. i &= ~OPTION_WUG;
  5829. if( i&OPTION_WUGRIDER && pc_checkskill(sd, RA_WUGRIDER) )
  5830. i &= ~OPTION_WUGRIDER;
  5831. if( i&OPTION_MADOGEAR && ( sd->class_&MAPID_THIRDMASK ) == MAPID_MECHANIC )
  5832. i &= ~OPTION_MADOGEAR;
  5833. if( i&OPTION_MOUNTING )
  5834. i &= ~OPTION_MOUNTING;
  5835. #ifndef NEW_CARTS
  5836. if( i&OPTION_CART && pc_checkskill(sd, MC_PUSHCART) )
  5837. i &= ~OPTION_CART;
  5838. #else
  5839. if( sd->sc.data[SC_PUSH_CART] )
  5840. pc_setcart(sd, 0);
  5841. #endif
  5842. if( i != sd->sc.option )
  5843. pc_setoption(sd, i);
  5844. if( merc_is_hom_active(sd->hd) && pc_checkskill(sd, AM_CALLHOMUN) )
  5845. merc_hom_vaporize(sd, HOM_ST_ACTIVE);
  5846. }
  5847. for( i = 1; i < MAX_SKILL; i++ )
  5848. {
  5849. int lv = sd->status.skill[i].lv;
  5850. int inf2;
  5851. if (lv < 1) continue;
  5852. inf2 = skill_get_inf2(i);
  5853. if( inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL) ) //Avoid reseting wedding/linker skills.
  5854. continue;
  5855. // Don't reset trick dead if not a novice/baby
  5856. if( i == NV_TRICKDEAD && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE )
  5857. {
  5858. sd->status.skill[i].lv = 0;
  5859. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  5860. continue;
  5861. }
  5862. // do not reset basic skill
  5863. if( i == NV_BASIC && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE )
  5864. continue;
  5865. if( sd->status.skill[i].flag == SKILL_FLAG_PERM_GRANTED )
  5866. continue;
  5867. if( flag&4 && !skill_ischangesex(i) )
  5868. continue;
  5869. if( inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn )
  5870. { //Only handle quest skills in a special way when you can't learn them manually
  5871. if( battle_config.quest_skill_reset && !(flag&2) )
  5872. { //Wipe them
  5873. sd->status.skill[i].lv = 0;
  5874. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  5875. }
  5876. continue;
  5877. }
  5878. if( sd->status.skill[i].flag == SKILL_FLAG_PERMANENT )
  5879. skill_point += lv;
  5880. else
  5881. if( sd->status.skill[i].flag == SKILL_FLAG_REPLACED_LV_0 )
  5882. skill_point += (sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0);
  5883. if( !(flag&2) )
  5884. {// reset
  5885. sd->status.skill[i].lv = 0;
  5886. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  5887. }
  5888. }
  5889. if( flag&2 || !skill_point ) return skill_point;
  5890. sd->status.skill_point += skill_point;
  5891. if( flag&1 )
  5892. {
  5893. clif_updatestatus(sd,SP_SKILLPOINT);
  5894. clif_skillinfoblock(sd);
  5895. status_calc_pc(sd,0);
  5896. }
  5897. return skill_point;
  5898. }
  5899. /*==========================================
  5900. * /resetfeel [Komurka]
  5901. *------------------------------------------*/
  5902. int pc_resetfeel(struct map_session_data* sd)
  5903. {
  5904. int i;
  5905. nullpo_ret(sd);
  5906. for (i=0; i<MAX_PC_FEELHATE; i++)
  5907. {
  5908. sd->feel_map[i].m = -1;
  5909. sd->feel_map[i].index = 0;
  5910. pc_setglobalreg(sd,sg_info[i].feel_var,0);
  5911. }
  5912. return 0;
  5913. }
  5914. int pc_resethate(struct map_session_data* sd)
  5915. {
  5916. int i;
  5917. nullpo_ret(sd);
  5918. for (i=0; i<3; i++)
  5919. {
  5920. sd->hate_mob[i] = -1;
  5921. pc_setglobalreg(sd,sg_info[i].hate_var,0);
  5922. }
  5923. return 0;
  5924. }
  5925. int pc_skillatk_bonus(struct map_session_data *sd, uint16 skill_id)
  5926. {
  5927. int i, bonus = 0;
  5928. nullpo_ret(sd);
  5929. ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == skill_id);
  5930. if( i < ARRAYLENGTH(sd->skillatk) ) bonus = sd->skillatk[i].val;
  5931. if(sd->sc.data[SC_PYROTECHNIC_OPTION] || sd->sc.data[SC_AQUAPLAY_OPTION])
  5932. bonus += 10;
  5933. return bonus;
  5934. }
  5935. int pc_skillheal_bonus(struct map_session_data *sd, uint16 skill_id) {
  5936. int i, bonus = sd->bonus.add_heal_rate;
  5937. if( bonus ) {
  5938. switch( skill_id ) {
  5939. case AL_HEAL: if( !(battle_config.skill_add_heal_rate&1) ) bonus = 0; break;
  5940. case PR_SANCTUARY: if( !(battle_config.skill_add_heal_rate&2) ) bonus = 0; break;
  5941. case AM_POTIONPITCHER: if( !(battle_config.skill_add_heal_rate&4) ) bonus = 0; break;
  5942. case CR_SLIMPITCHER: if( !(battle_config.skill_add_heal_rate&8) ) bonus = 0; break;
  5943. case BA_APPLEIDUN: if( !(battle_config.skill_add_heal_rate&16)) bonus = 0; break;
  5944. }
  5945. }
  5946. ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == skill_id);
  5947. if( i < ARRAYLENGTH(sd->skillheal) )
  5948. bonus += sd->skillheal[i].val;
  5949. return bonus;
  5950. }
  5951. int pc_skillheal2_bonus(struct map_session_data *sd, uint16 skill_id) {
  5952. int i, bonus = sd->bonus.add_heal2_rate;
  5953. ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == skill_id);
  5954. if( i < ARRAYLENGTH(sd->skillheal2) )
  5955. bonus += sd->skillheal2[i].val;
  5956. return bonus;
  5957. }
  5958. void pc_respawn(struct map_session_data* sd, clr_type clrtype)
  5959. {
  5960. if( !pc_isdead(sd) )
  5961. return; // not applicable
  5962. if( sd->bg_id && bg_member_respawn(sd) )
  5963. return; // member revived by battleground
  5964. pc_setstand(sd);
  5965. pc_setrestartvalue(sd,3);
  5966. if( pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype) )
  5967. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  5968. }
  5969. static int pc_respawn_timer(int tid, unsigned int tick, int id, intptr_t data)
  5970. {
  5971. struct map_session_data *sd = map_id2sd(id);
  5972. if( sd != NULL )
  5973. {
  5974. sd->pvp_point=0;
  5975. pc_respawn(sd,CLR_OUTSIGHT);
  5976. }
  5977. return 0;
  5978. }
  5979. /*==========================================
  5980. * Invoked when a player has received damage
  5981. *------------------------------------------*/
  5982. void pc_damage(struct map_session_data *sd,struct block_list *src,unsigned int hp, unsigned int sp)
  5983. {
  5984. if (sp) clif_updatestatus(sd,SP_SP);
  5985. if (hp) clif_updatestatus(sd,SP_HP);
  5986. else return;
  5987. if( !src || src == &sd->bl )
  5988. return;
  5989. if( pc_issit(sd) ) {
  5990. pc_setstand(sd);
  5991. skill_sit(sd,0);
  5992. }
  5993. if( sd->progressbar.npc_id )
  5994. clif_progressbar_abort(sd);
  5995. if( sd->status.pet_id > 0 && sd->pd && battle_config.pet_damage_support )
  5996. pet_target_check(sd,src,1);
  5997. if( sd->status.ele_id > 0 )
  5998. elemental_set_target(sd,src);
  5999. sd->canlog_tick = gettick();
  6000. }
  6001. int pc_close_npc_timer(int tid, unsigned int tick, int id, intptr_t data)
  6002. {
  6003. TBL_PC *sd = map_id2sd(id);
  6004. if(sd) pc_close_npc(sd,data);
  6005. return 0;
  6006. }
  6007. /*
  6008. * Method to properly close npc for player and clear anything related
  6009. * @flag == 1 : produce close button
  6010. * @flag == 2 : directly close it
  6011. */
  6012. void pc_close_npc(struct map_session_data *sd,int flag)
  6013. {
  6014. nullpo_retv(sd);
  6015. if (sd->npc_id || sd->npc_shopid) {
  6016. if (sd->state.using_fake_npc) {
  6017. clif_clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd);
  6018. sd->state.using_fake_npc = 0;
  6019. }
  6020. if (sd->st) {
  6021. if(sd->st->state == RUN){ //wait ending code execution
  6022. add_timer(gettick()+500,pc_close_npc_timer,sd->bl.id,flag);
  6023. return;
  6024. }
  6025. sd->st->state = ((flag==1 && sd->st->mes_active)?CLOSE:END);
  6026. sd->st->mes_active = 0;
  6027. }
  6028. sd->state.menu_or_input = 0;
  6029. sd->npc_menu = 0;
  6030. sd->npc_shopid = 0;
  6031. #ifdef SECURE_NPCTIMEOUT
  6032. sd->npc_idle_timer = INVALID_TIMER;
  6033. #endif
  6034. clif_scriptclose(sd,sd->npc_id);
  6035. clif_scriptclear(sd,sd->npc_id); // [Ind/Hercules]
  6036. if(sd->st && sd->st->state == END ) {// free attached scripts that are waiting
  6037. script_free_state(sd->st);
  6038. sd->st = NULL;
  6039. sd->npc_id = 0;
  6040. }
  6041. }
  6042. }
  6043. /*==========================================
  6044. * Invoked when a player has negative current hp
  6045. *------------------------------------------*/
  6046. int pc_dead(struct map_session_data *sd,struct block_list *src)
  6047. {
  6048. int i=0,k=0;
  6049. unsigned int tick = gettick();
  6050. // Activate Steel body if a super novice dies at 99+% exp [celest]
  6051. // Super Novices have no kill or die functions attached when saved by their angel
  6052. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && !sd->state.snovice_dead_flag) {
  6053. unsigned int next = pc_nextbaseexp(sd);
  6054. if( next == 0 ) next = pc_thisbaseexp(sd);
  6055. if( get_percentage(sd->status.base_exp,next) >= 99 ) {
  6056. sd->state.snovice_dead_flag = 1;
  6057. pc_setrestartvalue(sd,1);
  6058. status_percent_heal(&sd->bl, 100, 100);
  6059. clif_resurrection(&sd->bl, 1);
  6060. if(battle_config.pc_invincible_time)
  6061. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  6062. sc_start(&sd->bl,&sd->bl,status_skill2sc(MO_STEELBODY),100,5,skill_get_time(MO_STEELBODY,5));
  6063. if(map_flag_gvg(sd->bl.m))
  6064. pc_respawn_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
  6065. return 0;
  6066. }
  6067. }
  6068. for(k = 0; k < 5; k++)
  6069. if (sd->devotion[k]){
  6070. struct map_session_data *devsd = map_id2sd(sd->devotion[k]);
  6071. if (devsd)
  6072. status_change_end(&devsd->bl, SC_DEVOTION, INVALID_TIMER);
  6073. sd->devotion[k] = 0;
  6074. }
  6075. if(sd->shadowform_id) { //if we were target of shadowform
  6076. status_change_end(map_id2bl(sd->shadowform_id), SC__SHADOWFORM, INVALID_TIMER);
  6077. sd->shadowform_id = 0; //should be remove on status end anyway
  6078. }
  6079. if(sd->status.pet_id > 0 && sd->pd) {
  6080. struct pet_data *pd = sd->pd;
  6081. if( !map[sd->bl.m].flag.noexppenalty ) {
  6082. pet_set_intimate(pd, pd->pet.intimate - pd->petDB->die);
  6083. if( pd->pet.intimate < 0 )
  6084. pd->pet.intimate = 0;
  6085. clif_send_petdata(sd,sd->pd,1,pd->pet.intimate);
  6086. }
  6087. if( sd->pd->target_id ) // Unlock all targets...
  6088. pet_unlocktarget(sd->pd);
  6089. }
  6090. if (sd->status.hom_id > 0) {
  6091. if(battle_config.homunculus_auto_vapor && sd->hd && !sd->hd->sc.data[SC_LIGHT_OF_REGENE])
  6092. merc_hom_vaporize(sd, HOM_ST_ACTIVE);
  6093. }
  6094. if( sd->md )
  6095. merc_delete(sd->md, 3); // Your mercenary soldier has ran away.
  6096. if( sd->ed )
  6097. elemental_delete(sd->ed, 0);
  6098. // Leave duel if you die [LuzZza]
  6099. if(battle_config.duel_autoleave_when_die) {
  6100. if(sd->duel_group > 0)
  6101. duel_leave(sd->duel_group, sd);
  6102. if(sd->duel_invite > 0)
  6103. duel_reject(sd->duel_invite, sd);
  6104. }
  6105. pc_close_npc(sd,2); //close npc if we were using one
  6106. /* e.g. not killed thru pc_damage */
  6107. if( pc_issit(sd) ) {
  6108. clif_status_load(&sd->bl,SI_SIT,0);
  6109. }
  6110. pc_setdead(sd);
  6111. pc_setglobalreg(sd,"PC_DIE_COUNTER",sd->die_counter+1);
  6112. pc_setparam(sd, SP_KILLERRID, src?src->id:0);
  6113. //Reset menu skills/item skills
  6114. if ((sd->skillitem) != 0)
  6115. sd->skillitem = sd->skillitemlv = 0;
  6116. if ((sd->menuskill_id) != 0)
  6117. sd->menuskill_id = sd->menuskill_val = 0;
  6118. //Reset ticks.
  6119. sd->hp_loss.tick = sd->sp_loss.tick = sd->hp_regen.tick = sd->sp_regen.tick = 0;
  6120. if ( sd->spiritball !=0 )
  6121. pc_delspiritball(sd,sd->spiritball,0);
  6122. for(i = 1; i < 5; i++)
  6123. pc_del_talisman(sd, sd->talisman[i], i);
  6124. if (src)
  6125. switch (src->type) {
  6126. case BL_MOB:
  6127. {
  6128. struct mob_data *md=(struct mob_data *)src;
  6129. if(md->target_id==sd->bl.id)
  6130. mob_unlocktarget(md,tick);
  6131. if(battle_config.mobs_level_up && md->status.hp &&
  6132. (unsigned int)md->level < pc_maxbaselv(sd) &&
  6133. !md->guardian_data && !md->special_state.ai// Guardians/summons should not level. [Skotlex]
  6134. ) { // monster level up [Valaris]
  6135. clif_misceffect(&md->bl,0);
  6136. md->level++;
  6137. status_calc_mob(md, 0);
  6138. status_percent_heal(src,10,0);
  6139. if( battle_config.show_mob_info&4 )
  6140. {// update name with new level
  6141. clif_charnameack(0, &md->bl);
  6142. }
  6143. }
  6144. src = battle_get_master(src); // Maybe Player Summon
  6145. }
  6146. break;
  6147. case BL_PET: //Pass on to master...
  6148. case BL_HOM:
  6149. case BL_MER:
  6150. src = battle_get_master(src);
  6151. break;
  6152. }
  6153. if (src && src->type == BL_PC) {
  6154. struct map_session_data *ssd = (struct map_session_data *)src;
  6155. pc_setparam(ssd, SP_KILLEDRID, sd->bl.id);
  6156. npc_script_event(ssd, NPCE_KILLPC);
  6157. if (battle_config.pk_mode&2) {
  6158. ssd->status.manner -= 5;
  6159. if(ssd->status.manner < 0)
  6160. sc_start(&sd->bl,src,SC_NOCHAT,100,0,0);
  6161. #if 0
  6162. // PK/Karma system code (not enabled yet) [celest]
  6163. // originally from Kade Online, so i don't know if any of these is correct ^^;
  6164. // note: karma is measured REVERSE, so more karma = more 'evil' / less honourable,
  6165. // karma going down = more 'good' / more honourable.
  6166. // The Karma System way...
  6167. if (sd->status.karma > ssd->status.karma) { // If player killed was more evil
  6168. sd->status.karma--;
  6169. ssd->status.karma--;
  6170. }
  6171. else if (sd->status.karma < ssd->status.karma) // If player killed was more good
  6172. ssd->status.karma++;
  6173. // or the PK System way...
  6174. if (sd->status.karma > 0) // player killed is dishonourable?
  6175. ssd->status.karma--; // honour points earned
  6176. sd->status.karma++; // honour points lost
  6177. // To-do: Receive exp on certain occasions
  6178. #endif
  6179. }
  6180. }
  6181. if(battle_config.bone_drop==2
  6182. || (battle_config.bone_drop==1 && map[sd->bl.m].flag.pvp))
  6183. {
  6184. struct item item_tmp;
  6185. memset(&item_tmp,0,sizeof(item_tmp));
  6186. item_tmp.nameid=ITEMID_SKULL_;
  6187. item_tmp.identify=1;
  6188. item_tmp.card[0]=CARD0_CREATE;
  6189. item_tmp.card[1]=0;
  6190. item_tmp.card[2]=GetWord(sd->status.char_id,0); // CharId
  6191. item_tmp.card[3]=GetWord(sd->status.char_id,1);
  6192. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
  6193. }
  6194. //Remove bonus_script when dead
  6195. pc_bonus_script_clear(sd,BONUS_FLAG_REM_ON_DEAD);
  6196. // changed penalty options, added death by player if pk_mode [Valaris]
  6197. if(battle_config.death_penalty_type
  6198. && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE // only novices will receive no penalty
  6199. && !map[sd->bl.m].flag.noexppenalty && !map_flag_gvg(sd->bl.m)
  6200. && !sd->sc.data[SC_BABY] && !sd->sc.data[SC_LIFEINSURANCE])
  6201. {
  6202. uint32 base_penalty = battle_config.death_penalty_base;
  6203. uint32 job_penalty = battle_config.death_penalty_job;
  6204. uint32 zeny_penalty = battle_config.zeny_penalty;
  6205. #ifdef VIP_ENABLE
  6206. if(pc_isvip(sd)){
  6207. base_penalty *= battle_config.vip_exp_penalty_base;
  6208. job_penalty *= battle_config.vip_exp_penalty_job;
  6209. }
  6210. else {
  6211. base_penalty *= battle_config.vip_exp_penalty_base_normal;
  6212. job_penalty *= battle_config.vip_exp_penalty_job_normal;
  6213. }
  6214. #endif
  6215. if (base_penalty > 0) {
  6216. switch (battle_config.death_penalty_type) {
  6217. case 1: base_penalty = (uint32) ( pc_nextbaseexp(sd) * ( base_penalty / 10000. ) ); break;
  6218. case 2: base_penalty = (uint32) ( sd->status.base_exp * ( base_penalty / 10000. ) ); break;
  6219. }
  6220. if (base_penalty > 0){ //recheck after altering to speedup
  6221. if (battle_config.pk_mode && src && src->type==BL_PC)
  6222. base_penalty*=2;
  6223. sd->status.base_exp -= min(sd->status.base_exp, base_penalty);
  6224. clif_updatestatus(sd,SP_BASEEXP);
  6225. }
  6226. }
  6227. if(job_penalty > 0) {
  6228. switch (battle_config.death_penalty_type) {
  6229. case 1: job_penalty = (uint32) ( pc_nextjobexp(sd) * ( job_penalty / 10000. ) ); break;
  6230. case 2: job_penalty = (uint32) ( sd->status.job_exp * ( job_penalty /10000. ) ); break;
  6231. }
  6232. if(job_penalty) {
  6233. if (battle_config.pk_mode && src && src->type==BL_PC)
  6234. job_penalty*=2;
  6235. sd->status.job_exp -= min(sd->status.job_exp, job_penalty);
  6236. clif_updatestatus(sd,SP_JOBEXP);
  6237. }
  6238. }
  6239. if( zeny_penalty > 0 && !map[sd->bl.m].flag.nozenypenalty) {
  6240. zeny_penalty = (uint32)( sd->status.zeny * ( zeny_penalty / 10000. ) );
  6241. if(zeny_penalty)
  6242. pc_payzeny(sd, zeny_penalty, LOG_TYPE_PICKDROP_PLAYER, NULL);
  6243. }
  6244. }
  6245. if(map[sd->bl.m].flag.pvp_nightmaredrop) { // Moved this outside so it works when PVP isn't enabled and during pk mode [Ancyker]
  6246. int j;
  6247. for(j=0;j<MAX_DROP_PER_MAP;j++){
  6248. int id = map[sd->bl.m].drop_list[j].drop_id;
  6249. int type = map[sd->bl.m].drop_list[j].drop_type;
  6250. int per = map[sd->bl.m].drop_list[j].drop_per;
  6251. if(id == 0)
  6252. continue;
  6253. if(id == -1){
  6254. int eq_num=0,eq_n[MAX_INVENTORY];
  6255. memset(eq_n,0,sizeof(eq_n));
  6256. for(i=0;i<MAX_INVENTORY;i++) {
  6257. if( (type == 1 && !sd->status.inventory[i].equip)
  6258. || (type == 2 && sd->status.inventory[i].equip)
  6259. || type == 3)
  6260. {
  6261. int k;
  6262. ARR_FIND( 0, MAX_INVENTORY, k, eq_n[k] <= 0 );
  6263. if( k < MAX_INVENTORY )
  6264. eq_n[k] = i;
  6265. eq_num++;
  6266. }
  6267. }
  6268. if(eq_num > 0){
  6269. int n = eq_n[rnd()%eq_num];
  6270. if(rnd()%10000 < per) {
  6271. if(sd->status.inventory[n].equip)
  6272. pc_unequipitem(sd,n,3);
  6273. pc_dropitem(sd,n,1);
  6274. }
  6275. }
  6276. }
  6277. else if(id > 0) {
  6278. for(i=0;i<MAX_INVENTORY;i++){
  6279. if(sd->status.inventory[i].nameid == id
  6280. && rnd()%10000 < per
  6281. && ((type == 1 && !sd->status.inventory[i].equip)
  6282. || (type == 2 && sd->status.inventory[i].equip)
  6283. || type == 3) ){
  6284. if(sd->status.inventory[i].equip)
  6285. pc_unequipitem(sd,i,3);
  6286. pc_dropitem(sd,i,1);
  6287. break;
  6288. }
  6289. }
  6290. }
  6291. }
  6292. }
  6293. // pvp
  6294. // disable certain pvp functions on pk_mode [Valaris]
  6295. if( map[sd->bl.m].flag.pvp && !battle_config.pk_mode && !map[sd->bl.m].flag.pvp_nocalcrank ) {
  6296. sd->pvp_point -= 5;
  6297. sd->pvp_lost++;
  6298. if( src && src->type == BL_PC ) {
  6299. struct map_session_data *ssd = (struct map_session_data *)src;
  6300. ssd->pvp_point++;
  6301. ssd->pvp_won++;
  6302. }
  6303. if( sd->pvp_point < 0 ) {
  6304. add_timer(tick+1000, pc_respawn_timer,sd->bl.id,0);
  6305. return 1|8;
  6306. }
  6307. }
  6308. //GvG
  6309. if( map_flag_gvg(sd->bl.m) ) {
  6310. add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
  6311. return 1|8;
  6312. }
  6313. else if( sd->bg_id ) {
  6314. struct battleground_data *bg = bg_team_search(sd->bg_id);
  6315. if( bg && bg->mapindex > 0 ) { // Respawn by BG
  6316. add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
  6317. return 1|8;
  6318. }
  6319. }
  6320. //Reset "can log out" tick.
  6321. if( battle_config.prevent_logout )
  6322. sd->canlog_tick = gettick() - battle_config.prevent_logout;
  6323. return 1;
  6324. }
  6325. void pc_revive(struct map_session_data *sd,unsigned int hp, unsigned int sp) {
  6326. if(hp) clif_updatestatus(sd,SP_HP);
  6327. if(sp) clif_updatestatus(sd,SP_SP);
  6328. pc_setstand(sd);
  6329. if(battle_config.pc_invincible_time > 0)
  6330. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  6331. if( sd->state.gmaster_flag ) {
  6332. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  6333. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  6334. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  6335. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  6336. }
  6337. }
  6338. // script
  6339. //
  6340. /*==========================================
  6341. * script reading pc status registry
  6342. *------------------------------------------*/
  6343. int pc_readparam(struct map_session_data* sd,int type)
  6344. {
  6345. int val = 0;
  6346. nullpo_ret(sd);
  6347. switch(type) {
  6348. case SP_SKILLPOINT: val = sd->status.skill_point; break;
  6349. case SP_STATUSPOINT: val = sd->status.status_point; break;
  6350. case SP_ZENY: val = sd->status.zeny; break;
  6351. case SP_BASELEVEL: val = sd->status.base_level; break;
  6352. case SP_JOBLEVEL: val = sd->status.job_level; break;
  6353. case SP_CLASS: val = sd->status.class_; break;
  6354. case SP_BASEJOB: val = pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex); break; //Base job, extracting upper type.
  6355. case SP_UPPER: val = sd->class_&JOBL_UPPER?1:(sd->class_&JOBL_BABY?2:0); break;
  6356. case SP_BASECLASS: val = pc_mapid2jobid(sd->class_&MAPID_BASEMASK, sd->status.sex); break; //Extract base class tree. [Skotlex]
  6357. case SP_SEX: val = sd->status.sex; break;
  6358. case SP_WEIGHT: val = sd->weight; break;
  6359. case SP_MAXWEIGHT: val = sd->max_weight; break;
  6360. case SP_BASEEXP: val = sd->status.base_exp; break;
  6361. case SP_JOBEXP: val = sd->status.job_exp; break;
  6362. case SP_NEXTBASEEXP: val = pc_nextbaseexp(sd); break;
  6363. case SP_NEXTJOBEXP: val = pc_nextjobexp(sd); break;
  6364. case SP_HP: val = sd->battle_status.hp; break;
  6365. case SP_MAXHP: val = sd->battle_status.max_hp; break;
  6366. case SP_SP: val = sd->battle_status.sp; break;
  6367. case SP_MAXSP: val = sd->battle_status.max_sp; break;
  6368. case SP_STR: val = sd->status.str; break;
  6369. case SP_AGI: val = sd->status.agi; break;
  6370. case SP_VIT: val = sd->status.vit; break;
  6371. case SP_INT: val = sd->status.int_; break;
  6372. case SP_DEX: val = sd->status.dex; break;
  6373. case SP_LUK: val = sd->status.luk; break;
  6374. case SP_KARMA: val = sd->status.karma; break;
  6375. case SP_MANNER: val = sd->status.manner; break;
  6376. case SP_FAME: val = sd->status.fame; break;
  6377. case SP_KILLERRID: val = sd->killerrid; break;
  6378. case SP_KILLEDRID: val = sd->killedrid; break;
  6379. case SP_SITTING: val = pc_issit(sd)?1:0; break;
  6380. case SP_CHARMOVE: val = sd->status.character_moves; break;
  6381. case SP_CRITICAL: val = sd->battle_status.cri/10; break;
  6382. case SP_ASPD: val = (2000-sd->battle_status.amotion)/10; break;
  6383. case SP_BASE_ATK: val = sd->battle_status.batk; break;
  6384. case SP_DEF1: val = sd->battle_status.def; break;
  6385. case SP_DEF2: val = sd->battle_status.def2; break;
  6386. case SP_MDEF1: val = sd->battle_status.mdef; break;
  6387. case SP_MDEF2: val = sd->battle_status.mdef2; break;
  6388. case SP_HIT: val = sd->battle_status.hit; break;
  6389. case SP_FLEE1: val = sd->battle_status.flee; break;
  6390. case SP_FLEE2: val = sd->battle_status.flee2; break;
  6391. case SP_DEFELE: val = sd->battle_status.def_ele; break;
  6392. #ifndef RENEWAL_CAST
  6393. case SP_VARCASTRATE:
  6394. #endif
  6395. case SP_CASTRATE:
  6396. val = sd->castrate+=val;
  6397. break;
  6398. case SP_MAXHPRATE: val = sd->hprate; break;
  6399. case SP_MAXSPRATE: val = sd->sprate; break;
  6400. case SP_SPRATE: val = sd->dsprate; break;
  6401. case SP_SPEED_RATE: val = sd->bonus.speed_rate; break;
  6402. case SP_SPEED_ADDRATE: val = sd->bonus.speed_add_rate; break;
  6403. case SP_ASPD_RATE:
  6404. #ifndef RENEWAL_ASPD
  6405. val = sd->battle_status.aspd_rate;
  6406. #else
  6407. val = sd->battle_status.aspd_rate2;
  6408. #endif
  6409. break;
  6410. case SP_HP_RECOV_RATE: val = sd->hprecov_rate; break;
  6411. case SP_SP_RECOV_RATE: val = sd->sprecov_rate; break;
  6412. case SP_CRITICAL_DEF: val = sd->bonus.critical_def; break;
  6413. case SP_NEAR_ATK_DEF: val = sd->bonus.near_attack_def_rate; break;
  6414. case SP_LONG_ATK_DEF: val = sd->bonus.long_attack_def_rate; break;
  6415. case SP_DOUBLE_RATE: val = sd->bonus.double_rate; break;
  6416. case SP_DOUBLE_ADD_RATE: val = sd->bonus.double_add_rate; break;
  6417. case SP_MATK_RATE: val = sd->matk_rate; break;
  6418. case SP_ATK_RATE: val = sd->bonus.atk_rate; break;
  6419. case SP_MAGIC_ATK_DEF: val = sd->bonus.magic_def_rate; break;
  6420. case SP_MISC_ATK_DEF: val = sd->bonus.misc_def_rate; break;
  6421. case SP_PERFECT_HIT_RATE:val = sd->bonus.perfect_hit; break;
  6422. case SP_PERFECT_HIT_ADD_RATE: val = sd->bonus.perfect_hit_add; break;
  6423. case SP_CRITICAL_RATE: val = sd->critical_rate; break;
  6424. case SP_HIT_RATE: val = sd->hit_rate; break;
  6425. case SP_FLEE_RATE: val = sd->flee_rate; break;
  6426. case SP_FLEE2_RATE: val = sd->flee2_rate; break;
  6427. case SP_DEF_RATE: val = sd->def_rate; break;
  6428. case SP_DEF2_RATE: val = sd->def2_rate; break;
  6429. case SP_MDEF_RATE: val = sd->mdef_rate; break;
  6430. case SP_MDEF2_RATE: val = sd->mdef2_rate; break;
  6431. case SP_RESTART_FULL_RECOVER: val = sd->special_state.restart_full_recover?1:0; break;
  6432. case SP_NO_CASTCANCEL: val = sd->special_state.no_castcancel?1:0; break;
  6433. case SP_NO_CASTCANCEL2: val = sd->special_state.no_castcancel2?1:0; break;
  6434. case SP_NO_SIZEFIX: val = sd->special_state.no_sizefix?1:0; break;
  6435. case SP_NO_MAGIC_DAMAGE: val = sd->special_state.no_magic_damage; break;
  6436. case SP_NO_WEAPON_DAMAGE:val = sd->special_state.no_weapon_damage; break;
  6437. case SP_NO_MISC_DAMAGE: val = sd->special_state.no_misc_damage; break;
  6438. case SP_NO_GEMSTONE: val = sd->special_state.no_gemstone?1:0; break;
  6439. case SP_INTRAVISION: val = sd->special_state.intravision?1:0; break;
  6440. case SP_NO_KNOCKBACK: val = sd->special_state.no_knockback?1:0; break;
  6441. case SP_SPLASH_RANGE: val = sd->bonus.splash_range; break;
  6442. case SP_SPLASH_ADD_RANGE:val = sd->bonus.splash_add_range; break;
  6443. case SP_SHORT_WEAPON_DAMAGE_RETURN: val = sd->bonus.short_weapon_damage_return; break;
  6444. case SP_LONG_WEAPON_DAMAGE_RETURN: val = sd->bonus.long_weapon_damage_return; break;
  6445. case SP_MAGIC_DAMAGE_RETURN: val = sd->bonus.magic_damage_return; break;
  6446. case SP_PERFECT_HIDE: val = sd->special_state.perfect_hiding?1:0; break;
  6447. case SP_UNBREAKABLE: val = sd->bonus.unbreakable; break;
  6448. case SP_UNBREAKABLE_WEAPON: val = (sd->bonus.unbreakable_equip&EQP_WEAPON)?1:0; break;
  6449. case SP_UNBREAKABLE_ARMOR: val = (sd->bonus.unbreakable_equip&EQP_ARMOR)?1:0; break;
  6450. case SP_UNBREAKABLE_HELM: val = (sd->bonus.unbreakable_equip&EQP_HELM)?1:0; break;
  6451. case SP_UNBREAKABLE_SHIELD: val = (sd->bonus.unbreakable_equip&EQP_SHIELD)?1:0; break;
  6452. case SP_UNBREAKABLE_GARMENT: val = (sd->bonus.unbreakable_equip&EQP_GARMENT)?1:0; break;
  6453. case SP_UNBREAKABLE_SHOES: val = (sd->bonus.unbreakable_equip&EQP_SHOES)?1:0; break;
  6454. case SP_CLASSCHANGE: val = sd->bonus.classchange; break;
  6455. case SP_LONG_ATK_RATE: val = sd->bonus.long_attack_atk_rate; break;
  6456. case SP_BREAK_WEAPON_RATE: val = sd->bonus.break_weapon_rate; break;
  6457. case SP_BREAK_ARMOR_RATE: val = sd->bonus.break_armor_rate; break;
  6458. case SP_ADD_STEAL_RATE: val = sd->bonus.add_steal_rate; break;
  6459. case SP_DELAYRATE: val = sd->delayrate; break;
  6460. case SP_CRIT_ATK_RATE: val = sd->bonus.crit_atk_rate; break;
  6461. case SP_UNSTRIPABLE_WEAPON: val = (sd->bonus.unstripable_equip&EQP_WEAPON)?1:0; break;
  6462. case SP_UNSTRIPABLE:
  6463. case SP_UNSTRIPABLE_ARMOR:
  6464. val = (sd->bonus.unstripable_equip&EQP_ARMOR)?1:0;
  6465. break;
  6466. case SP_UNSTRIPABLE_HELM: val = (sd->bonus.unstripable_equip&EQP_HELM)?1:0; break;
  6467. case SP_UNSTRIPABLE_SHIELD: val = (sd->bonus.unstripable_equip&EQP_SHIELD)?1:0; break;
  6468. case SP_SP_GAIN_VALUE: val = sd->bonus.sp_gain_value; break;
  6469. case SP_HP_GAIN_VALUE: val = sd->bonus.hp_gain_value; break;
  6470. case SP_MAGIC_SP_GAIN_VALUE: val = sd->bonus.magic_sp_gain_value; break;
  6471. case SP_MAGIC_HP_GAIN_VALUE: val = sd->bonus.magic_hp_gain_value; break;
  6472. case SP_ADD_HEAL_RATE: val = sd->bonus.add_heal_rate; break;
  6473. case SP_ADD_HEAL2_RATE: val = sd->bonus.add_heal2_rate; break;
  6474. case SP_ADD_ITEM_HEAL_RATE: val = sd->bonus.itemhealrate2; break;
  6475. case SP_EMATK: val = sd->bonus.ematk; break;
  6476. case SP_FIXCASTRATE: val = sd->bonus.fixcastrate; break;
  6477. case SP_ADD_FIXEDCAST: val = sd->bonus.add_fixcast; break;
  6478. #ifdef RENEWAL_CAST
  6479. case SP_VARCASTRATE: val = sd->bonus.varcastrate; break;
  6480. case SP_ADD_VARIABLECAST:val = sd->bonus.add_varcast; break;
  6481. #endif
  6482. }
  6483. return val;
  6484. }
  6485. /*==========================================
  6486. * script set pc status registry
  6487. *------------------------------------------*/
  6488. bool pc_setparam(struct map_session_data *sd,int type,int val)
  6489. {
  6490. nullpo_retr(false,sd);
  6491. switch(type){
  6492. case SP_BASELEVEL:
  6493. if ((unsigned int)val > pc_maxbaselv(sd)) //Capping to max
  6494. val = pc_maxbaselv(sd);
  6495. if ((unsigned int)val > sd->status.base_level) {
  6496. int i = 0;
  6497. int stat=0;
  6498. for (i = 0; i < (int)((unsigned int)val - sd->status.base_level); i++)
  6499. stat += pc_gets_status_point(sd->status.base_level + i);
  6500. sd->status.status_point += stat;
  6501. }
  6502. sd->status.base_level = (unsigned int)val;
  6503. sd->status.base_exp = 0;
  6504. // clif_updatestatus(sd, SP_BASELEVEL); // Gets updated at the bottom
  6505. clif_updatestatus(sd, SP_NEXTBASEEXP);
  6506. clif_updatestatus(sd, SP_STATUSPOINT);
  6507. clif_updatestatus(sd, SP_BASEEXP);
  6508. status_calc_pc(sd, 0);
  6509. if(sd->status.party_id)
  6510. {
  6511. party_send_levelup(sd);
  6512. }
  6513. break;
  6514. case SP_JOBLEVEL:
  6515. if ((unsigned int)val >= sd->status.job_level) {
  6516. if ((unsigned int)val > pc_maxjoblv(sd)) val = pc_maxjoblv(sd);
  6517. sd->status.skill_point += val - sd->status.job_level;
  6518. clif_updatestatus(sd, SP_SKILLPOINT);
  6519. }
  6520. sd->status.job_level = (unsigned int)val;
  6521. sd->status.job_exp = 0;
  6522. // clif_updatestatus(sd, SP_JOBLEVEL); // Gets updated at the bottom
  6523. clif_updatestatus(sd, SP_NEXTJOBEXP);
  6524. clif_updatestatus(sd, SP_JOBEXP);
  6525. status_calc_pc(sd, 0);
  6526. break;
  6527. case SP_SKILLPOINT:
  6528. sd->status.skill_point = val;
  6529. break;
  6530. case SP_STATUSPOINT:
  6531. sd->status.status_point = val;
  6532. break;
  6533. case SP_ZENY:
  6534. if( val < 0 )
  6535. return false;// can't set negative zeny
  6536. log_zeny(sd, LOG_TYPE_SCRIPT, sd, -(sd->status.zeny - cap_value(val, 0, MAX_ZENY)));
  6537. sd->status.zeny = cap_value(val, 0, MAX_ZENY);
  6538. break;
  6539. case SP_BASEEXP:
  6540. if(pc_nextbaseexp(sd) > 0) {
  6541. sd->status.base_exp = val;
  6542. pc_checkbaselevelup(sd);
  6543. }
  6544. break;
  6545. case SP_JOBEXP:
  6546. if(pc_nextjobexp(sd) > 0) {
  6547. sd->status.job_exp = val;
  6548. pc_checkjoblevelup(sd);
  6549. }
  6550. break;
  6551. case SP_SEX:
  6552. sd->status.sex = val ? SEX_MALE : SEX_FEMALE;
  6553. break;
  6554. case SP_WEIGHT:
  6555. sd->weight = val;
  6556. break;
  6557. case SP_MAXWEIGHT:
  6558. sd->max_weight = val;
  6559. break;
  6560. case SP_HP:
  6561. sd->battle_status.hp = cap_value(val, 1, (int)sd->battle_status.max_hp);
  6562. break;
  6563. case SP_MAXHP:
  6564. sd->battle_status.max_hp = cap_value(val, 1, battle_config.max_hp);
  6565. if( sd->battle_status.max_hp < sd->battle_status.hp )
  6566. {
  6567. sd->battle_status.hp = sd->battle_status.max_hp;
  6568. clif_updatestatus(sd, SP_HP);
  6569. }
  6570. break;
  6571. case SP_SP:
  6572. sd->battle_status.sp = cap_value(val, 0, (int)sd->battle_status.max_sp);
  6573. break;
  6574. case SP_MAXSP:
  6575. sd->battle_status.max_sp = cap_value(val, 1, battle_config.max_sp);
  6576. if( sd->battle_status.max_sp < sd->battle_status.sp )
  6577. {
  6578. sd->battle_status.sp = sd->battle_status.max_sp;
  6579. clif_updatestatus(sd, SP_SP);
  6580. }
  6581. break;
  6582. case SP_STR:
  6583. sd->status.str = cap_value(val, 1, pc_maxparameter(sd,PARAM_STR));
  6584. break;
  6585. case SP_AGI:
  6586. sd->status.agi = cap_value(val, 1, pc_maxparameter(sd,PARAM_AGI));
  6587. break;
  6588. case SP_VIT:
  6589. sd->status.vit = cap_value(val, 1, pc_maxparameter(sd,PARAM_VIT));
  6590. break;
  6591. case SP_INT:
  6592. sd->status.int_ = cap_value(val, 1, pc_maxparameter(sd,PARAM_INT));
  6593. break;
  6594. case SP_DEX:
  6595. sd->status.dex = cap_value(val, 1, pc_maxparameter(sd,PARAM_DEX));
  6596. break;
  6597. case SP_LUK:
  6598. sd->status.luk = cap_value(val, 1, pc_maxparameter(sd,PARAM_LUK));
  6599. break;
  6600. case SP_KARMA:
  6601. sd->status.karma = val;
  6602. break;
  6603. case SP_MANNER:
  6604. sd->status.manner = val;
  6605. break;
  6606. case SP_FAME:
  6607. sd->status.fame = val;
  6608. break;
  6609. case SP_KILLERRID:
  6610. sd->killerrid = val;
  6611. return true;
  6612. case SP_KILLEDRID:
  6613. sd->killedrid = val;
  6614. return true;
  6615. case SP_CHARMOVE:
  6616. sd->status.character_moves = val;
  6617. return true;
  6618. default:
  6619. ShowError("pc_setparam: Attempted to set unknown parameter '%d'.\n", type);
  6620. return false;
  6621. }
  6622. clif_updatestatus(sd,type);
  6623. return true;
  6624. }
  6625. /*==========================================
  6626. * HP/SP Healing. If flag is passed, the heal type is through clif_heal, otherwise update status.
  6627. *------------------------------------------*/
  6628. void pc_heal(struct map_session_data *sd,unsigned int hp,unsigned int sp, int type)
  6629. {
  6630. if (type) {
  6631. if (hp)
  6632. clif_heal(sd->fd,SP_HP,hp);
  6633. if (sp)
  6634. clif_heal(sd->fd,SP_SP,sp);
  6635. } else {
  6636. if(hp)
  6637. clif_updatestatus(sd,SP_HP);
  6638. if(sp)
  6639. clif_updatestatus(sd,SP_SP);
  6640. }
  6641. return;
  6642. }
  6643. /*==========================================
  6644. * HP/SP Recovery
  6645. * Heal player hp and/or sp linearly.
  6646. * Calculate bonus by status.
  6647. *------------------------------------------*/
  6648. int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
  6649. {
  6650. int bonus;
  6651. if(hp) {
  6652. int i;
  6653. bonus = 100 + (sd->battle_status.vit<<1)
  6654. + pc_checkskill(sd,SM_RECOVERY)*10
  6655. + pc_checkskill(sd,AM_LEARNINGPOTION)*5;
  6656. // A potion produced by an Alchemist in the Fame Top 10 gets +50% effect [DracoRPG]
  6657. if (potion_flag > 1)
  6658. bonus += bonus*(potion_flag-1)*50/100;
  6659. //All item bonuses.
  6660. bonus += sd->bonus.itemhealrate2;
  6661. //Item Group bonuses
  6662. bonus += bonus*itemdb_group_bonus(sd, itemid)/100;
  6663. //Individual item bonuses.
  6664. for(i = 0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid; i++)
  6665. {
  6666. if (sd->itemhealrate[i].nameid == itemid) {
  6667. bonus += bonus*sd->itemhealrate[i].rate/100;
  6668. break;
  6669. }
  6670. }
  6671. if(bonus!=100)
  6672. hp = hp * bonus / 100;
  6673. // Recovery Potion
  6674. if( sd->sc.data[SC_INCHEALRATE] )
  6675. hp += (int)(hp * sd->sc.data[SC_INCHEALRATE]->val1/100.);
  6676. }
  6677. if(sp) {
  6678. bonus = 100 + (sd->battle_status.int_<<1)
  6679. + pc_checkskill(sd,MG_SRECOVERY)*10
  6680. + pc_checkskill(sd,AM_LEARNINGPOTION)*5;
  6681. if (potion_flag > 1)
  6682. bonus += bonus*(potion_flag-1)*50/100;
  6683. if(bonus != 100)
  6684. sp = sp * bonus / 100;
  6685. }
  6686. if( sd->sc.count ) {
  6687. if ( sd->sc.data[SC_CRITICALWOUND] ) {
  6688. hp -= hp * sd->sc.data[SC_CRITICALWOUND]->val2 / 100;
  6689. sp -= sp * sd->sc.data[SC_CRITICALWOUND]->val2 / 100;
  6690. }
  6691. if ( sd->sc.data[SC_DEATHHURT] ) {
  6692. hp -= hp * 20 / 100;
  6693. sp -= sp * 20 / 100;
  6694. }
  6695. if( sd->sc.data[SC_VITALITYACTIVATION] ){
  6696. hp += hp / 2; // 1.5 times
  6697. sp -= sp / 2;
  6698. }
  6699. if( sd->sc.data[SC_WATER_INSIGNIA] && sd->sc.data[SC_WATER_INSIGNIA]->val1 == 2 ) {
  6700. hp += hp / 10;
  6701. sp += sp / 10;
  6702. }
  6703. #ifdef RENEWAL
  6704. if( sd->sc.data[SC_EXTREMITYFIST2] )
  6705. sp = 0;
  6706. #endif
  6707. }
  6708. return status_heal(&sd->bl, hp, sp, 1);
  6709. }
  6710. /*==========================================
  6711. * HP/SP Recovery
  6712. * Heal player hp nad/or sp by rate
  6713. *------------------------------------------*/
  6714. int pc_percentheal(struct map_session_data *sd,int hp,int sp)
  6715. {
  6716. nullpo_ret(sd);
  6717. if (hp > 100) hp = 100;
  6718. else if (hp <-100) hp = -100;
  6719. if (sp > 100) sp = 100;
  6720. else if (sp <-100) sp = -100;
  6721. if(hp >= 0 && sp >= 0) //Heal
  6722. return status_percent_heal(&sd->bl, hp, sp);
  6723. if(hp <= 0 && sp <= 0) //Damage (negative rates indicate % of max rather than current), and only kill target IF the specified amount is 100%
  6724. return status_percent_damage(NULL, &sd->bl, hp, sp, hp==-100);
  6725. //Crossed signs
  6726. if(hp) {
  6727. if(hp > 0)
  6728. status_percent_heal(&sd->bl, hp, 0);
  6729. else
  6730. status_percent_damage(NULL, &sd->bl, hp, 0, hp==-100);
  6731. }
  6732. if(sp) {
  6733. if(sp > 0)
  6734. status_percent_heal(&sd->bl, 0, sp);
  6735. else
  6736. status_percent_damage(NULL, &sd->bl, 0, sp, false);
  6737. }
  6738. return 0;
  6739. }
  6740. static int jobchange_killclone(struct block_list *bl, va_list ap)
  6741. {
  6742. struct mob_data *md;
  6743. int flag;
  6744. md = (struct mob_data *)bl;
  6745. nullpo_ret(md);
  6746. flag = va_arg(ap, int);
  6747. if (md->master_id && md->special_state.clone && md->master_id == flag)
  6748. status_kill(&md->bl);
  6749. return 1;
  6750. }
  6751. /*==========================================
  6752. * Called when player changes job
  6753. * Rewrote to make it tidider [Celest]
  6754. *------------------------------------------*/
  6755. int pc_jobchange(struct map_session_data *sd,int job, int upper)
  6756. {
  6757. int i, fame_flag=0;
  6758. int b_class;
  6759. nullpo_ret(sd);
  6760. if (job < 0)
  6761. return 1;
  6762. //Normalize job.
  6763. b_class = pc_jobid2mapid(job);
  6764. if (b_class == -1)
  6765. return 1;
  6766. switch (upper) {
  6767. case 1:
  6768. b_class|= JOBL_UPPER;
  6769. break;
  6770. case 2:
  6771. b_class|= JOBL_BABY;
  6772. break;
  6773. }
  6774. //This will automatically adjust bard/dancer classes to the correct gender
  6775. //That is, if you try to jobchange into dancer, it will turn you to bard.
  6776. job = pc_mapid2jobid(b_class, sd->status.sex);
  6777. if (job == -1)
  6778. return 1;
  6779. if ((unsigned short)b_class == sd->class_)
  6780. return 1; //Nothing to change.
  6781. // changing from 1st to 2nd job
  6782. if ((b_class&JOBL_2) && !(sd->class_&JOBL_2) && (b_class&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE) {
  6783. sd->change_level_2nd = sd->status.job_level;
  6784. pc_setglobalreg (sd, "jobchange_level", sd->change_level_2nd);
  6785. }
  6786. // changing from 2nd to 3rd job
  6787. else if((b_class&JOBL_THIRD) && !(sd->class_&JOBL_THIRD)) {
  6788. sd->change_level_3rd = sd->status.job_level;
  6789. pc_setglobalreg (sd, "jobchange_level_3rd", sd->change_level_3rd);
  6790. }
  6791. if(sd->cloneskill_idx >= 0) {
  6792. if( sd->status.skill[sd->cloneskill_idx].flag == SKILL_FLAG_PLAGIARIZED ) {
  6793. sd->status.skill[sd->cloneskill_idx].id = 0;
  6794. sd->status.skill[sd->cloneskill_idx].lv = 0;
  6795. sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PERMANENT;
  6796. clif_deleteskill(sd,pc_readglobalreg(sd,SKILL_VAR_PLAGIARISM));
  6797. }
  6798. sd->cloneskill_idx = -1;
  6799. pc_setglobalreg(sd,SKILL_VAR_PLAGIARISM, 0);
  6800. pc_setglobalreg(sd,SKILL_VAR_PLAGIARISM_LV, 0);
  6801. }
  6802. if(sd->reproduceskill_idx >= 0) {
  6803. if( sd->status.skill[sd->reproduceskill_idx].flag == SKILL_FLAG_PLAGIARIZED ) {
  6804. sd->status.skill[sd->reproduceskill_idx].id = 0;
  6805. sd->status.skill[sd->reproduceskill_idx].lv = 0;
  6806. sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PERMANENT;
  6807. clif_deleteskill(sd,pc_readglobalreg(sd,SKILL_VAR_REPRODUCE));
  6808. }
  6809. sd->reproduceskill_idx = -1;
  6810. pc_setglobalreg(sd,SKILL_VAR_REPRODUCE,0);
  6811. pc_setglobalreg(sd,SKILL_VAR_REPRODUCE_LV,0);
  6812. }
  6813. // Give or reduce transcendent status points
  6814. if( (b_class&JOBL_UPPER) && !(sd->class_&JOBL_UPPER) ){ // Change from a non t class to a t class -> give points
  6815. sd->status.status_point += 52;
  6816. clif_updatestatus(sd,SP_STATUSPOINT);
  6817. }else if( !(b_class&JOBL_UPPER) && (sd->class_&JOBL_UPPER) ){ // Change from a t class to a non t class -> remove points
  6818. if( sd->status.status_point < 52 ){
  6819. // The player already used his bonus points, so we have to reset his status points
  6820. pc_resetstate(sd);
  6821. }
  6822. sd->status.status_point -= 52;
  6823. clif_updatestatus(sd,SP_STATUSPOINT);
  6824. }
  6825. if ( (b_class&MAPID_UPPERMASK) != (sd->class_&MAPID_UPPERMASK) ) { //Things to remove when changing class tree.
  6826. const int class_ = pc_class2idx(sd->status.class_);
  6827. short id;
  6828. for(i = 0; i < MAX_SKILL_TREE && (id = skill_tree[class_][i].id) > 0; i++) {
  6829. //Remove status specific to your current tree skills.
  6830. enum sc_type sc = status_skill2sc(id);
  6831. if (sc > SC_COMMON_MAX && sd->sc.data[sc])
  6832. status_change_end(&sd->bl, sc, INVALID_TIMER);
  6833. }
  6834. }
  6835. if( (sd->class_&MAPID_UPPERMASK) == MAPID_STAR_GLADIATOR && (b_class&MAPID_UPPERMASK) != MAPID_STAR_GLADIATOR) {
  6836. /* going off star glad lineage, reset feel to not store no-longer-used vars in the database */
  6837. pc_resetfeel(sd);
  6838. }
  6839. sd->status.class_ = job;
  6840. fame_flag = pc_famerank(sd->status.char_id,sd->class_&MAPID_UPPERMASK);
  6841. sd->class_ = (unsigned short)b_class;
  6842. sd->status.job_level=1;
  6843. sd->status.job_exp=0;
  6844. if (sd->status.base_level > pc_maxbaselv(sd)) {
  6845. sd->status.base_level = pc_maxbaselv(sd);
  6846. sd->status.base_exp=0;
  6847. pc_resetstate(sd);
  6848. clif_updatestatus(sd,SP_STATUSPOINT);
  6849. clif_updatestatus(sd,SP_BASELEVEL);
  6850. clif_updatestatus(sd,SP_BASEEXP);
  6851. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6852. }
  6853. clif_updatestatus(sd,SP_JOBLEVEL);
  6854. clif_updatestatus(sd,SP_JOBEXP);
  6855. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6856. for(i=0;i<EQI_MAX;i++) {
  6857. if(sd->equip_index[i] >= 0)
  6858. if(!pc_isequip(sd,sd->equip_index[i]))
  6859. pc_unequipitem(sd,sd->equip_index[i],2); // unequip invalid item for class
  6860. }
  6861. //Change look, if disguised, you need to undisguise
  6862. //to correctly calculate new job sprite without
  6863. if (sd->disguise)
  6864. pc_disguise(sd, 0);
  6865. status_set_viewdata(&sd->bl, job);
  6866. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_); // move sprite update to prevent client crashes with incompatible equipment [Valaris]
  6867. if(sd->vd.cloth_color)
  6868. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  6869. //Update skill tree.
  6870. pc_calc_skilltree(sd);
  6871. clif_skillinfoblock(sd);
  6872. if (sd->ed)
  6873. elemental_delete(sd->ed, 0);
  6874. if (sd->state.vending)
  6875. vending_closevending(sd);
  6876. map_foreachinmap(jobchange_killclone, sd->bl.m, BL_MOB, sd->bl.id);
  6877. //Remove peco/cart/falcon
  6878. i = sd->sc.option;
  6879. if( i&OPTION_RIDING && !pc_checkskill(sd, KN_RIDING) )
  6880. i&=~OPTION_RIDING;
  6881. if( i&OPTION_FALCON && !pc_checkskill(sd, HT_FALCON) )
  6882. i&=~OPTION_FALCON;
  6883. if( i&OPTION_DRAGON && !pc_checkskill(sd,RK_DRAGONTRAINING) )
  6884. i&=~OPTION_DRAGON;
  6885. if( i&OPTION_WUGRIDER && !pc_checkskill(sd,RA_WUGMASTERY) )
  6886. i&=~OPTION_WUGRIDER;
  6887. if( i&OPTION_WUG && !pc_checkskill(sd,RA_WUGMASTERY) )
  6888. i&=~OPTION_WUG;
  6889. if( i&OPTION_MADOGEAR ) //You do not need a skill for this.
  6890. i&=~OPTION_MADOGEAR;
  6891. #ifndef NEW_CARTS
  6892. if( i&OPTION_CART && !pc_checkskill(sd, MC_PUSHCART) )
  6893. i&=~OPTION_CART;
  6894. #else
  6895. if( sd->sc.data[SC_PUSH_CART] && !pc_checkskill(sd, MC_PUSHCART) )
  6896. pc_setcart(sd, 0);
  6897. #endif
  6898. if(i != sd->sc.option)
  6899. pc_setoption(sd, i);
  6900. if(merc_is_hom_active(sd->hd) && !pc_checkskill(sd, AM_CALLHOMUN))
  6901. merc_hom_vaporize(sd, HOM_ST_ACTIVE);
  6902. if(sd->status.manner < 0)
  6903. clif_changestatus(sd,SP_MANNER,sd->status.manner);
  6904. status_calc_pc(sd,0);
  6905. pc_checkallowskill(sd);
  6906. pc_equiplookall(sd);
  6907. //if you were previously famous, not anymore.
  6908. if (fame_flag) {
  6909. chrif_save(sd,0);
  6910. chrif_buildfamelist();
  6911. } else if (sd->status.fame > 0) {
  6912. //It may be that now they are famous?
  6913. switch (sd->class_&MAPID_UPPERMASK) {
  6914. case MAPID_BLACKSMITH:
  6915. case MAPID_ALCHEMIST:
  6916. case MAPID_TAEKWON:
  6917. chrif_save(sd,0);
  6918. chrif_buildfamelist();
  6919. break;
  6920. }
  6921. }
  6922. return 0;
  6923. }
  6924. /*==========================================
  6925. * Tell client player sd has change equipement
  6926. *------------------------------------------*/
  6927. void pc_equiplookall(struct map_session_data *sd)
  6928. {
  6929. nullpo_retv(sd);
  6930. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6931. clif_changelook(&sd->bl,LOOK_SHOES,0);
  6932. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  6933. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  6934. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  6935. clif_changelook(&sd->bl,LOOK_ROBE, sd->status.robe);
  6936. }
  6937. /*==========================================
  6938. * Tell client player sd has change look (hair,equip...)
  6939. *------------------------------------------*/
  6940. void pc_changelook(struct map_session_data *sd,int type,int val)
  6941. {
  6942. nullpo_retv(sd);
  6943. switch(type){
  6944. case LOOK_HAIR: //Use the battle_config limits! [Skotlex]
  6945. val = cap_value(val, MIN_HAIR_STYLE, MAX_HAIR_STYLE);
  6946. if (sd->status.hair != val)
  6947. {
  6948. sd->status.hair=val;
  6949. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  6950. intif_guild_change_memberinfo(sd->status.guild_id,sd->status.account_id,sd->status.char_id,
  6951. GMI_HAIR,&sd->status.hair,sizeof(sd->status.hair));
  6952. }
  6953. break;
  6954. case LOOK_WEAPON:
  6955. sd->status.weapon=val;
  6956. break;
  6957. case LOOK_HEAD_BOTTOM:
  6958. sd->status.head_bottom=val;
  6959. break;
  6960. case LOOK_HEAD_TOP:
  6961. sd->status.head_top=val;
  6962. break;
  6963. case LOOK_HEAD_MID:
  6964. sd->status.head_mid=val;
  6965. break;
  6966. case LOOK_HAIR_COLOR: //Use the battle_config limits! [Skotlex]
  6967. val = cap_value(val, MIN_HAIR_COLOR, MAX_HAIR_COLOR);
  6968. if (sd->status.hair_color != val) {
  6969. sd->status.hair_color=val;
  6970. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  6971. intif_guild_change_memberinfo(sd->status.guild_id,sd->status.account_id,sd->status.char_id,
  6972. GMI_HAIR_COLOR,&sd->status.hair_color,sizeof(sd->status.hair_color));
  6973. }
  6974. break;
  6975. case LOOK_CLOTHES_COLOR: //Use the battle_config limits! [Skotlex]
  6976. val = cap_value(val, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  6977. sd->status.clothes_color=val;
  6978. break;
  6979. case LOOK_SHIELD:
  6980. sd->status.shield=val;
  6981. break;
  6982. case LOOK_SHOES:
  6983. break;
  6984. case LOOK_ROBE:
  6985. sd->status.robe = val;
  6986. break;
  6987. }
  6988. clif_changelook(&sd->bl,type,val);
  6989. }
  6990. /*==========================================
  6991. * Give an option (type) to player (sd) and display it to client
  6992. *------------------------------------------*/
  6993. void pc_setoption(struct map_session_data *sd,int type)
  6994. {
  6995. int p_type, new_look=0;
  6996. nullpo_retv(sd);
  6997. p_type = sd->sc.option;
  6998. //Option has to be changed client-side before the class sprite or it won't always work (eg: Wedding sprite) [Skotlex]
  6999. sd->sc.option=type;
  7000. clif_changeoption(&sd->bl);
  7001. if( (type&OPTION_RIDING && !(p_type&OPTION_RIDING)) || (type&OPTION_DRAGON && !(p_type&OPTION_DRAGON) && pc_checkskill(sd,RK_DRAGONTRAINING) > 0) )
  7002. { // Mounting
  7003. clif_status_load(&sd->bl,SI_RIDING,1);
  7004. status_calc_pc(sd,0);
  7005. }
  7006. else if( (!(type&OPTION_RIDING) && p_type&OPTION_RIDING) || (!(type&OPTION_DRAGON) && p_type&OPTION_DRAGON && pc_checkskill(sd,RK_DRAGONTRAINING) > 0) )
  7007. { // Dismount
  7008. clif_status_load(&sd->bl,SI_RIDING,0);
  7009. status_calc_pc(sd,0);
  7010. }
  7011. #ifndef NEW_CARTS
  7012. if( type&OPTION_CART && !( p_type&OPTION_CART ) ) { //Cart On
  7013. clif_cartlist(sd);
  7014. clif_updatestatus(sd, SP_CARTINFO);
  7015. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7016. status_calc_pc(sd,0); //Apply speed penalty.
  7017. } else if( !( type&OPTION_CART ) && p_type&OPTION_CART ){ //Cart Off
  7018. clif_clearcart(sd->fd);
  7019. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7020. status_calc_pc(sd,0); //Remove speed penalty.
  7021. }
  7022. #endif
  7023. if (type&OPTION_MOUNTING && !(p_type&OPTION_MOUNTING) ) {
  7024. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  7025. status_calc_pc(sd,0);
  7026. } else if (!(type&OPTION_MOUNTING) && p_type&OPTION_MOUNTING) {
  7027. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,0,0,0,0);
  7028. status_calc_pc(sd,0);
  7029. }
  7030. if (type&OPTION_FALCON && !(p_type&OPTION_FALCON)) //Falcon ON
  7031. clif_status_load(&sd->bl,SI_FALCON,1);
  7032. else if (!(type&OPTION_FALCON) && p_type&OPTION_FALCON) //Falcon OFF
  7033. clif_status_load(&sd->bl,SI_FALCON,0);
  7034. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER ) {
  7035. if( type&OPTION_WUGRIDER && !(p_type&OPTION_WUGRIDER) ) { // Mounting
  7036. clif_status_load(&sd->bl,SI_WUGRIDER,1);
  7037. status_calc_pc(sd,0);
  7038. } else if( !(type&OPTION_WUGRIDER) && p_type&OPTION_WUGRIDER ) { // Dismount
  7039. clif_status_load(&sd->bl,SI_WUGRIDER,0);
  7040. status_calc_pc(sd,0);
  7041. }
  7042. }
  7043. if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  7044. if( type&OPTION_MADOGEAR && !(p_type&OPTION_MADOGEAR) ) {
  7045. status_calc_pc(sd, 0);
  7046. status_change_end(&sd->bl,SC_MAXIMIZEPOWER,INVALID_TIMER);
  7047. status_change_end(&sd->bl,SC_OVERTHRUST,INVALID_TIMER);
  7048. status_change_end(&sd->bl,SC_WEAPONPERFECTION,INVALID_TIMER);
  7049. status_change_end(&sd->bl,SC_ADRENALINE,INVALID_TIMER);
  7050. status_change_end(&sd->bl,SC_CARTBOOST,INVALID_TIMER);
  7051. status_change_end(&sd->bl,SC_MELTDOWN,INVALID_TIMER);
  7052. status_change_end(&sd->bl,SC_MAXOVERTHRUST,INVALID_TIMER);
  7053. } else if( !(type&OPTION_MADOGEAR) && p_type&OPTION_MADOGEAR ) {
  7054. status_calc_pc(sd, 0);
  7055. status_change_end(&sd->bl,SC_SHAPESHIFT,INVALID_TIMER);
  7056. status_change_end(&sd->bl,SC_HOVERING,INVALID_TIMER);
  7057. status_change_end(&sd->bl,SC_ACCELERATION,INVALID_TIMER);
  7058. status_change_end(&sd->bl,SC_OVERHEAT_LIMITPOINT,INVALID_TIMER);
  7059. status_change_end(&sd->bl,SC_OVERHEAT,INVALID_TIMER);
  7060. }
  7061. }
  7062. if (type&OPTION_FLYING && !(p_type&OPTION_FLYING))
  7063. new_look = JOB_STAR_GLADIATOR2;
  7064. else if (!(type&OPTION_FLYING) && p_type&OPTION_FLYING)
  7065. new_look = -1;
  7066. if (type&OPTION_WEDDING && !(p_type&OPTION_WEDDING))
  7067. new_look = JOB_WEDDING;
  7068. else if (!(type&OPTION_WEDDING) && p_type&OPTION_WEDDING)
  7069. new_look = -1;
  7070. if (type&OPTION_XMAS && !(p_type&OPTION_XMAS))
  7071. new_look = JOB_XMAS;
  7072. else if (!(type&OPTION_XMAS) && p_type&OPTION_XMAS)
  7073. new_look = -1;
  7074. if (type&OPTION_SUMMER && !(p_type&OPTION_SUMMER))
  7075. new_look = JOB_SUMMER;
  7076. else if (!(type&OPTION_SUMMER) && p_type&OPTION_SUMMER)
  7077. new_look = -1;
  7078. if (type&OPTION_HANBOK && !(p_type&OPTION_HANBOK))
  7079. new_look = JOB_HANBOK;
  7080. else if (!(type&OPTION_HANBOK) && p_type&OPTION_HANBOK)
  7081. new_look = -1;
  7082. if (type&OPTION_OKTOBERFEST && !(p_type&OPTION_OKTOBERFEST))
  7083. new_look = JOB_OKTOBERFEST;
  7084. else if (!(type&OPTION_OKTOBERFEST) && p_type&OPTION_OKTOBERFEST)
  7085. new_look = -1;
  7086. if (sd->disguise || !new_look)
  7087. return; //Disguises break sprite changes
  7088. if (new_look < 0) { //Restore normal look.
  7089. status_set_viewdata(&sd->bl, sd->status.class_);
  7090. new_look = sd->vd.class_;
  7091. }
  7092. pc_stop_attack(sd); //Stop attacking on new view change (to prevent wedding/santa attacks.
  7093. clif_changelook(&sd->bl,LOOK_BASE,new_look);
  7094. if (sd->vd.cloth_color)
  7095. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7096. clif_skillinfoblock(sd); // Skill list needs to be updated after base change.
  7097. }
  7098. /*==========================================
  7099. * Give player a cart
  7100. *------------------------------------------*/
  7101. bool pc_setcart(struct map_session_data *sd,int type) {
  7102. #ifndef NEW_CARTS
  7103. int cart[6] = {0x0000,OPTION_CART1,OPTION_CART2,OPTION_CART3,OPTION_CART4,OPTION_CART5};
  7104. int option;
  7105. #endif
  7106. nullpo_retr(false,sd);
  7107. if( type < 0 || type > MAX_CARTS )
  7108. return false;// Never trust the values sent by the client! [Skotlex]
  7109. if( pc_checkskill(sd,MC_PUSHCART) <= 0 && type != 0 )
  7110. return false;// Push cart is required
  7111. #ifdef NEW_CARTS
  7112. switch( type ) {
  7113. case 0:
  7114. if( !sd->sc.data[SC_PUSH_CART] )
  7115. return 0;
  7116. status_change_end(&sd->bl,SC_PUSH_CART,INVALID_TIMER);
  7117. clif_clearcart(sd->fd);
  7118. break;
  7119. default:/* everything else is an allowed ID so we can move on */
  7120. if( !sd->sc.data[SC_PUSH_CART] ) /* first time, so fill cart data */
  7121. clif_cartlist(sd);
  7122. clif_updatestatus(sd, SP_CARTINFO);
  7123. sc_start(&sd->bl,&sd->bl, SC_PUSH_CART, 100, type, 0);
  7124. clif_status_load_notick(&sd->bl, SI_ON_PUSH_CART, 2 , type, 0, 0);
  7125. if( sd->sc.data[SC_PUSH_CART] )/* forcefully update */
  7126. sd->sc.data[SC_PUSH_CART]->val1 = type;
  7127. break;
  7128. }
  7129. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7130. status_calc_pc(sd,0); //Recalc speed penalty.
  7131. #else
  7132. // Update option
  7133. option = sd->sc.option;
  7134. option &= ~OPTION_CART;// clear cart bits
  7135. option |= cart[type]; // set cart
  7136. pc_setoption(sd, option);
  7137. #endif
  7138. return true;
  7139. }
  7140. /*==========================================
  7141. * Give player a falcon
  7142. *------------------------------------------*/
  7143. void pc_setfalcon(TBL_PC* sd, int flag)
  7144. {
  7145. if( flag ){
  7146. if( pc_checkskill(sd,HT_FALCON)>0 ) // add falcon if he have the skill
  7147. pc_setoption(sd,sd->sc.option|OPTION_FALCON);
  7148. } else if( pc_isfalcon(sd) ){
  7149. pc_setoption(sd,sd->sc.option&~OPTION_FALCON); // remove falcon
  7150. }
  7151. }
  7152. /*==========================================
  7153. * Set player riding
  7154. *------------------------------------------*/
  7155. void pc_setriding(TBL_PC* sd, int flag)
  7156. {
  7157. if( flag ){
  7158. if( pc_checkskill(sd,KN_RIDING) > 0 ) // add peco
  7159. pc_setoption(sd, sd->sc.option|OPTION_RIDING);
  7160. } else if( pc_isriding(sd) ){
  7161. pc_setoption(sd, sd->sc.option&~OPTION_RIDING);
  7162. }
  7163. }
  7164. /*==========================================
  7165. * Give player a mado
  7166. *------------------------------------------*/
  7167. void pc_setmadogear(TBL_PC* sd, int flag)
  7168. {
  7169. if( flag ){
  7170. if( pc_checkskill(sd,NC_MADOLICENCE) > 0 )
  7171. pc_setoption(sd, sd->sc.option|OPTION_MADOGEAR);
  7172. } else if( pc_ismadogear(sd) ){
  7173. pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR);
  7174. }
  7175. }
  7176. /*==========================================
  7177. * Check if player can drop an item
  7178. *------------------------------------------*/
  7179. bool pc_candrop(struct map_session_data *sd, struct item *item)
  7180. {
  7181. if( item && (item->expire_time || (item->bound && !pc_can_give_bounded_items(sd))) )
  7182. return false;
  7183. if( !pc_can_give_items(sd) || sd->sc.cant.drop) //check if this GM level can drop items
  7184. return false;
  7185. return (itemdb_isdropable(item, pc_get_group_level(sd)));
  7186. }
  7187. /*==========================================
  7188. * Read ram register for player sd
  7189. * get val (int) from reg for player sd
  7190. *------------------------------------------*/
  7191. int pc_readreg(struct map_session_data* sd, int reg)
  7192. {
  7193. int i;
  7194. nullpo_ret(sd);
  7195. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg );
  7196. return ( i < sd->reg_num ) ? sd->reg[i].data : 0;
  7197. }
  7198. /*==========================================
  7199. * Set ram register for player sd
  7200. * memo val(int) at reg for player sd
  7201. *------------------------------------------*/
  7202. bool pc_setreg(struct map_session_data* sd, int reg, int val)
  7203. {
  7204. int i;
  7205. nullpo_retr(false,sd);
  7206. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg );
  7207. if( i < sd->reg_num )
  7208. {// overwrite existing entry
  7209. sd->reg[i].data = val;
  7210. return true;
  7211. }
  7212. ARR_FIND( 0, sd->reg_num, i, sd->reg[i].data == 0 );
  7213. if( i == sd->reg_num )
  7214. {// nothing free, increase size
  7215. sd->reg_num++;
  7216. RECREATE(sd->reg, struct script_reg, sd->reg_num);
  7217. }
  7218. sd->reg[i].index = reg;
  7219. sd->reg[i].data = val;
  7220. return true;
  7221. }
  7222. /*==========================================
  7223. * Read ram register for player sd
  7224. * get val (str) from reg for player sd
  7225. *------------------------------------------*/
  7226. char* pc_readregstr(struct map_session_data* sd, int reg)
  7227. {
  7228. int i;
  7229. nullpo_ret(sd);
  7230. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg );
  7231. return ( i < sd->regstr_num ) ? sd->regstr[i].data : NULL;
  7232. }
  7233. /*==========================================
  7234. * Set ram register for player sd
  7235. * memo val(str) at reg for player sd
  7236. *------------------------------------------*/
  7237. bool pc_setregstr(struct map_session_data* sd, int reg, const char* str)
  7238. {
  7239. int i;
  7240. nullpo_retr(false,sd);
  7241. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg );
  7242. if( i < sd->regstr_num )
  7243. {// found entry, update
  7244. if( str == NULL || *str == '\0' )
  7245. {// empty string
  7246. if( sd->regstr[i].data != NULL )
  7247. aFree(sd->regstr[i].data);
  7248. sd->regstr[i].data = NULL;
  7249. }
  7250. else if( sd->regstr[i].data )
  7251. {// recreate
  7252. size_t len = strlen(str)+1;
  7253. RECREATE(sd->regstr[i].data, char, len);
  7254. memcpy(sd->regstr[i].data, str, len*sizeof(char));
  7255. }
  7256. else
  7257. {// create
  7258. sd->regstr[i].data = aStrdup(str);
  7259. }
  7260. return true;
  7261. }
  7262. if( str == NULL || *str == '\0' )
  7263. return true;// nothing to add, empty string
  7264. ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].data == NULL );
  7265. if( i == sd->regstr_num )
  7266. {// nothing free, increase size
  7267. sd->regstr_num++;
  7268. RECREATE(sd->regstr, struct script_regstr, sd->regstr_num);
  7269. }
  7270. sd->regstr[i].index = reg;
  7271. sd->regstr[i].data = aStrdup(str);
  7272. return true;
  7273. }
  7274. int pc_readregistry(struct map_session_data *sd,const char *reg,int type)
  7275. {
  7276. struct global_reg *sd_reg;
  7277. int i,max;
  7278. nullpo_ret(sd);
  7279. switch (type) {
  7280. case 3: //Char reg
  7281. sd_reg = sd->save_reg.global;
  7282. max = sd->save_reg.global_num;
  7283. break;
  7284. case 2: //Account reg
  7285. sd_reg = sd->save_reg.account;
  7286. max = sd->save_reg.account_num;
  7287. break;
  7288. case 1: //Account2 reg
  7289. sd_reg = sd->save_reg.account2;
  7290. max = sd->save_reg.account2_num;
  7291. break;
  7292. default:
  7293. return 0;
  7294. }
  7295. if (max == -1) {
  7296. ShowError("pc_readregistry: Trying to read reg value %s (type %d) before it's been loaded!\n", reg, type);
  7297. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  7298. intif_request_registry(sd,type==3?4:type);
  7299. return 0;
  7300. }
  7301. ARR_FIND( 0, max, i, strcmp(sd_reg[i].str,reg) == 0 );
  7302. return ( i < max ) ? atoi(sd_reg[i].value) : 0;
  7303. }
  7304. char* pc_readregistry_str(struct map_session_data *sd,const char *reg,int type)
  7305. {
  7306. struct global_reg *sd_reg;
  7307. int i,max;
  7308. nullpo_ret(sd);
  7309. switch (type) {
  7310. case 3: //Char reg
  7311. sd_reg = sd->save_reg.global;
  7312. max = sd->save_reg.global_num;
  7313. break;
  7314. case 2: //Account reg
  7315. sd_reg = sd->save_reg.account;
  7316. max = sd->save_reg.account_num;
  7317. break;
  7318. case 1: //Account2 reg
  7319. sd_reg = sd->save_reg.account2;
  7320. max = sd->save_reg.account2_num;
  7321. break;
  7322. default:
  7323. return NULL;
  7324. }
  7325. if (max == -1) {
  7326. ShowError("pc_readregistry: Trying to read reg value %s (type %d) before it's been loaded!\n", reg, type);
  7327. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  7328. intif_request_registry(sd,type==3?4:type);
  7329. return NULL;
  7330. }
  7331. ARR_FIND( 0, max, i, strcmp(sd_reg[i].str,reg) == 0 );
  7332. return ( i < max ) ? sd_reg[i].value : NULL;
  7333. }
  7334. bool pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type)
  7335. {
  7336. struct global_reg *sd_reg;
  7337. int i,*max, regmax;
  7338. nullpo_retr(false,sd);
  7339. switch( type )
  7340. {
  7341. case 3: //Char reg
  7342. if( !strcmp(reg,"PC_DIE_COUNTER") && sd->die_counter != val )
  7343. {
  7344. i = (!sd->die_counter && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE);
  7345. sd->die_counter = val;
  7346. if( i )
  7347. status_calc_pc(sd,0); // Lost the bonus.
  7348. }
  7349. else if( !strcmp(reg,"COOK_MASTERY") && sd->cook_mastery != val )
  7350. {
  7351. val = cap_value(val, 0, 1999);
  7352. sd->cook_mastery = val;
  7353. }
  7354. sd_reg = sd->save_reg.global;
  7355. max = &sd->save_reg.global_num;
  7356. regmax = GLOBAL_REG_NUM;
  7357. break;
  7358. case 2: //Account reg
  7359. if( !strcmp(reg,"#CASHPOINTS") && sd->cashPoints != val )
  7360. {
  7361. val = cap_value(val, 0, MAX_ZENY);
  7362. sd->cashPoints = val;
  7363. }
  7364. else if( !strcmp(reg,"#KAFRAPOINTS") && sd->kafraPoints != val )
  7365. {
  7366. val = cap_value(val, 0, MAX_ZENY);
  7367. sd->kafraPoints = val;
  7368. }
  7369. sd_reg = sd->save_reg.account;
  7370. max = &sd->save_reg.account_num;
  7371. regmax = ACCOUNT_REG_NUM;
  7372. break;
  7373. case 1: //Account2 reg
  7374. sd_reg = sd->save_reg.account2;
  7375. max = &sd->save_reg.account2_num;
  7376. regmax = ACCOUNT_REG2_NUM;
  7377. break;
  7378. default:
  7379. return false;
  7380. }
  7381. if (*max == -1) {
  7382. ShowError("pc_setregistry : refusing to set %s (type %d) until vars are received.\n", reg, type);
  7383. return true;
  7384. }
  7385. // delete reg
  7386. if (val == 0) {
  7387. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  7388. if( i < *max )
  7389. {
  7390. if (i != *max - 1)
  7391. memcpy(&sd_reg[i], &sd_reg[*max - 1], sizeof(struct global_reg));
  7392. memset(&sd_reg[*max - 1], 0, sizeof(struct global_reg));
  7393. (*max)--;
  7394. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  7395. }
  7396. return true;
  7397. }
  7398. // change value if found
  7399. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  7400. if( i < *max )
  7401. {
  7402. safesnprintf(sd_reg[i].value, sizeof(sd_reg[i].value), "%d", val);
  7403. sd->state.reg_dirty |= 1<<(type-1);
  7404. return true;
  7405. }
  7406. // add value if not found
  7407. if (i < regmax) {
  7408. memset(&sd_reg[i], 0, sizeof(struct global_reg));
  7409. safestrncpy(sd_reg[i].str, reg, sizeof(sd_reg[i].str));
  7410. safesnprintf(sd_reg[i].value, sizeof(sd_reg[i].value), "%d", val);
  7411. (*max)++;
  7412. sd->state.reg_dirty |= 1<<(type-1);
  7413. return true;
  7414. }
  7415. ShowError("pc_setregistry : couldn't set %s, limit of registries reached (%d)\n", reg, regmax);
  7416. return false;
  7417. }
  7418. bool pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *val,int type)
  7419. {
  7420. struct global_reg *sd_reg;
  7421. int i,*max, regmax;
  7422. nullpo_retr(false,sd);
  7423. if (reg[strlen(reg)-1] != '$') {
  7424. ShowError("pc_setregistry_str : reg %s must be string (end in '$') to use this!\n", reg);
  7425. return false;
  7426. }
  7427. switch (type) {
  7428. case 3: //Char reg
  7429. sd_reg = sd->save_reg.global;
  7430. max = &sd->save_reg.global_num;
  7431. regmax = GLOBAL_REG_NUM;
  7432. break;
  7433. case 2: //Account reg
  7434. sd_reg = sd->save_reg.account;
  7435. max = &sd->save_reg.account_num;
  7436. regmax = ACCOUNT_REG_NUM;
  7437. break;
  7438. case 1: //Account2 reg
  7439. sd_reg = sd->save_reg.account2;
  7440. max = &sd->save_reg.account2_num;
  7441. regmax = ACCOUNT_REG2_NUM;
  7442. break;
  7443. default:
  7444. return false;
  7445. }
  7446. if (*max == -1) {
  7447. ShowError("pc_setregistry_str : refusing to set %s (type %d) until vars are received.\n", reg, type);
  7448. return false;
  7449. }
  7450. // delete reg
  7451. if (!val || strcmp(val,"")==0)
  7452. {
  7453. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  7454. if( i < *max )
  7455. {
  7456. if (i != *max - 1)
  7457. memcpy(&sd_reg[i], &sd_reg[*max - 1], sizeof(struct global_reg));
  7458. memset(&sd_reg[*max - 1], 0, sizeof(struct global_reg));
  7459. (*max)--;
  7460. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  7461. if (type!=3) intif_saveregistry(sd,type);
  7462. }
  7463. return true;
  7464. }
  7465. // change value if found
  7466. ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 );
  7467. if( i < *max )
  7468. {
  7469. safestrncpy(sd_reg[i].value, val, sizeof(sd_reg[i].value));
  7470. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  7471. if (type!=3) intif_saveregistry(sd,type);
  7472. return true;
  7473. }
  7474. // add value if not found
  7475. if (i < regmax) {
  7476. memset(&sd_reg[i], 0, sizeof(struct global_reg));
  7477. safestrncpy(sd_reg[i].str, reg, sizeof(sd_reg[i].str));
  7478. safestrncpy(sd_reg[i].value, val, sizeof(sd_reg[i].value));
  7479. (*max)++;
  7480. sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved"
  7481. if (type!=3) intif_saveregistry(sd,type);
  7482. return true;
  7483. }
  7484. ShowError("pc_setregistry : couldn't set %s, limit of registries reached (%d)\n", reg, regmax);
  7485. return false;
  7486. }
  7487. /*==========================================
  7488. * Exec eventtimer for player sd (retrieved from map_session (id))
  7489. *------------------------------------------*/
  7490. static int pc_eventtimer(int tid, unsigned int tick, int id, intptr_t data)
  7491. {
  7492. struct map_session_data *sd=map_id2sd(id);
  7493. char *p = (char *)data;
  7494. int i;
  7495. if(sd==NULL)
  7496. return 0;
  7497. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == tid );
  7498. if( i < MAX_EVENTTIMER )
  7499. {
  7500. sd->eventtimer[i] = INVALID_TIMER;
  7501. sd->eventcount--;
  7502. npc_event(sd,p,0);
  7503. }
  7504. else
  7505. ShowError("pc_eventtimer: no such event timer\n");
  7506. if (p) aFree(p);
  7507. return 0;
  7508. }
  7509. /*==========================================
  7510. * Add eventtimer for player sd ?
  7511. *------------------------------------------*/
  7512. bool pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
  7513. {
  7514. int i;
  7515. nullpo_retr(false,sd);
  7516. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == INVALID_TIMER );
  7517. if( i == MAX_EVENTTIMER )
  7518. return false;
  7519. sd->eventtimer[i] = add_timer(gettick()+tick, pc_eventtimer, sd->bl.id, (intptr_t)aStrdup(name));
  7520. sd->eventcount++;
  7521. return true;
  7522. }
  7523. /*==========================================
  7524. * Del eventtimer for player sd ?
  7525. *------------------------------------------*/
  7526. bool pc_deleventtimer(struct map_session_data *sd,const char *name)
  7527. {
  7528. char* p = NULL;
  7529. int i;
  7530. nullpo_retr(false,sd);
  7531. if (sd->eventcount == 0)
  7532. return false;
  7533. // find the named event timer
  7534. ARR_FIND( 0, MAX_EVENTTIMER, i,
  7535. sd->eventtimer[i] != INVALID_TIMER &&
  7536. (p = (char *)(get_timer(sd->eventtimer[i])->data)) != NULL &&
  7537. strcmp(p, name) == 0
  7538. );
  7539. if( i == MAX_EVENTTIMER )
  7540. return false; // not found
  7541. delete_timer(sd->eventtimer[i],pc_eventtimer);
  7542. sd->eventtimer[i] = INVALID_TIMER;
  7543. if(sd->eventcount > 0)
  7544. sd->eventcount--;
  7545. aFree(p);
  7546. return true;
  7547. }
  7548. /*==========================================
  7549. * Update eventtimer count for player sd
  7550. *------------------------------------------*/
  7551. void pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick)
  7552. {
  7553. int i;
  7554. nullpo_retv(sd);
  7555. for(i=0;i<MAX_EVENTTIMER;i++)
  7556. if( sd->eventtimer[i] != INVALID_TIMER && strcmp(
  7557. (char *)(get_timer(sd->eventtimer[i])->data), name)==0 ){
  7558. addtick_timer(sd->eventtimer[i],tick);
  7559. break;
  7560. }
  7561. }
  7562. /*==========================================
  7563. * Remove all eventtimer for player sd
  7564. *------------------------------------------*/
  7565. void pc_cleareventtimer(struct map_session_data *sd)
  7566. {
  7567. int i;
  7568. nullpo_retv(sd);
  7569. if (sd->eventcount == 0)
  7570. return;
  7571. for(i=0;i<MAX_EVENTTIMER;i++){
  7572. if( sd->eventtimer[i] != INVALID_TIMER ){
  7573. char *p = (char *)(get_timer(sd->eventtimer[i])->data);
  7574. delete_timer(sd->eventtimer[i],pc_eventtimer);
  7575. sd->eventtimer[i] = INVALID_TIMER;
  7576. if(sd->eventcount > 0) //avoid looping to max val
  7577. sd->eventcount--;
  7578. if (p) aFree(p);
  7579. }
  7580. }
  7581. }
  7582. /**
  7583. * Called when an item with combo is worn
  7584. * @param *sd
  7585. * @param *data struct item_data
  7586. * @return success numbers of succeed combo
  7587. */
  7588. static int pc_checkcombo(struct map_session_data *sd, struct item_data *data) {
  7589. uint16 i;
  7590. int success = 0;
  7591. for( i = 0; i < data->combos_count; i++ ) {
  7592. int16 *combo_idx = NULL, idx, j;
  7593. /* ensure this isn't a duplicate combo */
  7594. if( sd->combos.bonus != NULL ) {
  7595. int x;
  7596. ARR_FIND( 0, sd->combos.count, x, sd->combos.id[x] == data->combos[i]->id );
  7597. /* found a match, skip this combo */
  7598. if( x < sd->combos.count )
  7599. continue;
  7600. }
  7601. CREATE(combo_idx,int16,data->combos[i]->count);
  7602. memset(combo_idx,-1,data->combos[i]->count * sizeof(int16));
  7603. for( j = 0; j < data->combos[i]->count; j++ ) {
  7604. uint16 id = data->combos[i]->nameid[j], k;
  7605. bool found = false;
  7606. for( k = 0; k < EQI_MAX; k++ ) {
  7607. bool do_continue = false; //used to continue that specific loop with some check that also use some loop
  7608. int16 index;
  7609. index = sd->equip_index[k];
  7610. if( index < 0 ) continue;
  7611. if( k == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue;
  7612. if( k == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index ) continue;
  7613. if( k == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index) ) continue;
  7614. if(!sd->inventory_data[index])
  7615. continue;
  7616. if(j>0){
  7617. uint8 z;
  7618. for (z = 0; z < data->combos[i]->count; z++)
  7619. if(combo_idx[z] == index) //we already have that index recorded
  7620. do_continue=true;
  7621. if(do_continue)
  7622. continue;
  7623. }
  7624. if ( itemdb_type(id) != IT_CARD ) {
  7625. if ( sd->inventory_data[index]->nameid != id )
  7626. continue;
  7627. combo_idx[j] = index;
  7628. found = true;
  7629. break;
  7630. } else { //Cards
  7631. uint16 z;
  7632. if ( sd->inventory_data[index]->slot == 0 || itemdb_isspecial(sd->status.inventory[index].card[0]) )
  7633. continue;
  7634. for (z = 0; z < sd->inventory_data[index]->slot; z++) {
  7635. if (sd->status.inventory[index].card[z] != id)
  7636. continue;
  7637. combo_idx[j] = index;
  7638. found = true;
  7639. break;
  7640. }
  7641. }
  7642. }
  7643. if( !found )
  7644. break;/* we haven't found all the ids for this combo, so we can return */
  7645. }
  7646. aFree(combo_idx);
  7647. /* means we broke out of the count loop w/o finding all ids, we can move to the next combo */
  7648. if( j < data->combos[i]->count )
  7649. continue;
  7650. /* we got here, means all items in the combo are matching */
  7651. idx = sd->combos.count;
  7652. if( sd->combos.bonus == NULL ) {
  7653. CREATE(sd->combos.bonus, struct script_code *, 1);
  7654. CREATE(sd->combos.id, unsigned short, 1);
  7655. sd->combos.count = 1;
  7656. } else {
  7657. RECREATE(sd->combos.bonus, struct script_code *, ++sd->combos.count);
  7658. RECREATE(sd->combos.id, unsigned short, sd->combos.count);
  7659. }
  7660. /* we simply copy the pointer */
  7661. sd->combos.bonus[idx] = data->combos[i]->script;
  7662. /* save this combo's id */
  7663. sd->combos.id[idx] = data->combos[i]->id;
  7664. success++;
  7665. }
  7666. return success;
  7667. }
  7668. /**
  7669. * Called when an item with combo is removed
  7670. * @param *sd
  7671. * @param *data struct item_data
  7672. * @return retval numbers of removed combo
  7673. */
  7674. static int pc_removecombo(struct map_session_data *sd, struct item_data *data ) {
  7675. int i, retval = 0;
  7676. if( sd->combos.bonus == NULL )
  7677. return 0;/* nothing to do here, player has no combos */
  7678. for( i = 0; i < data->combos_count; i++ ) {
  7679. /* check if this combo exists in this user */
  7680. int x = 0, cursor = 0, j;
  7681. ARR_FIND( 0, sd->combos.count, x, sd->combos.id[x] == data->combos[i]->id );
  7682. /* no match, skip this combo */
  7683. if( !(x < sd->combos.count) )
  7684. continue;
  7685. sd->combos.bonus[x] = NULL;
  7686. sd->combos.id[x] = 0;
  7687. retval++;
  7688. /* check if combo requirements still fit */
  7689. if( pc_checkcombo( sd, data ) )
  7690. continue;
  7691. /* move next value to empty slot */
  7692. for( j = 0, cursor = 0; j < sd->combos.count; j++ ) {
  7693. if( sd->combos.bonus[j] == NULL )
  7694. continue;
  7695. if( cursor != j ) {
  7696. sd->combos.bonus[cursor] = sd->combos.bonus[j];
  7697. sd->combos.id[cursor] = sd->combos.id[j];
  7698. }
  7699. cursor++;
  7700. }
  7701. /* it's empty, we can clear all the memory */
  7702. if( (sd->combos.count = cursor) == 0 ) {
  7703. aFree(sd->combos.bonus);
  7704. aFree(sd->combos.id);
  7705. sd->combos.bonus = NULL;
  7706. sd->combos.id = NULL;
  7707. return retval; /* we also can return at this point for we have no more combos to check */
  7708. }
  7709. }
  7710. return retval;
  7711. }
  7712. /**
  7713. * Load combo data(s) of player
  7714. * @param *sd
  7715. * @return ret numbers of succeed combo
  7716. */
  7717. int pc_load_combo(struct map_session_data *sd) {
  7718. int i, ret = 0;
  7719. for( i = 0; i < EQI_MAX; i++ ) {
  7720. struct item_data *id = NULL;
  7721. int idx = sd->equip_index[i];
  7722. if( sd->equip_index[i] < 0 || !(id = sd->inventory_data[idx] ) )
  7723. continue;
  7724. if( id->combos_count )
  7725. ret += pc_checkcombo(sd,id);
  7726. if(!itemdb_isspecial(sd->status.inventory[idx].card[0])) {
  7727. struct item_data *data;
  7728. int j;
  7729. for( j = 0; j < id->slot; j++ ) {
  7730. if (!sd->status.inventory[idx].card[j])
  7731. continue;
  7732. if ( ( data = itemdb_exists(sd->status.inventory[idx].card[j]) ) != NULL ) {
  7733. if( data->combos_count )
  7734. ret += pc_checkcombo(sd,data);
  7735. }
  7736. }
  7737. }
  7738. }
  7739. return ret;
  7740. }
  7741. /*==========================================
  7742. * Equip item on player sd at req_pos from inventory index n
  7743. * return: false - fail; true - success
  7744. *------------------------------------------*/
  7745. bool pc_equipitem(struct map_session_data *sd,int n,int req_pos)
  7746. {
  7747. int i,pos,flag=0,iflag;
  7748. struct item_data *id;
  7749. nullpo_retr(false,sd);
  7750. if( n < 0 || n >= MAX_INVENTORY ) {
  7751. clif_equipitemack(sd,0,0,0);
  7752. return false;
  7753. }
  7754. if( sd->sc.count && (
  7755. (sd->sc.data[SC_PYROCLASTIC] && sd->inventory_data[n]->type == IT_WEAPON) ||
  7756. sd->sc.data[SC_BERSERK] ||
  7757. sd->sc.data[SC_SATURDAYNIGHTFEVER]) )
  7758. {
  7759. clif_equipitemack(sd,0,0,0);
  7760. return false;
  7761. }
  7762. if( DIFF_TICK(sd->canequip_tick,gettick()) > 0 ) {
  7763. clif_equipitemack(sd,n,0,0);
  7764. return false;
  7765. }
  7766. if (!(id = sd->inventory_data[n]))
  7767. return false;
  7768. pos = pc_equippoint(sd,n); //With a few exceptions, item should go in all specified slots.
  7769. if(battle_config.battle_log)
  7770. ShowInfo("equip %d(%d) %x:%x\n",sd->status.inventory[n].nameid,n,id?id->equip:0,req_pos);
  7771. if(!pc_isequip(sd,n) || !(pos&req_pos) || sd->status.inventory[n].equip != 0 || sd->status.inventory[n].attribute==1 ) { // [Valaris]
  7772. // FIXME: pc_isequip: equip level failure uses 2 instead of 0
  7773. clif_equipitemack(sd,n,0,0); // fail
  7774. return false;
  7775. }
  7776. if(pos == EQP_ACC) { //Accesories should only go in one of the two,
  7777. pos = req_pos&EQP_ACC;
  7778. if (pos == EQP_ACC) //User specified both slots..
  7779. pos = sd->equip_index[EQI_ACC_R] >= 0 ? EQP_ACC_L : EQP_ACC_R;
  7780. }
  7781. if(pos == EQP_SHADOW_ACC) { // Shadow System
  7782. pos = req_pos&EQP_SHADOW_ACC;
  7783. if (pos == EQP_SHADOW_ACC)
  7784. pos = sd->equip_index[EQI_SHADOW_ACC_L] >= 0 ? EQP_SHADOW_ACC_R : EQP_SHADOW_ACC_L;
  7785. }
  7786. if(pos == EQP_ARMS && id->equip == EQP_HAND_R) { //Dual wield capable weapon.
  7787. pos = (req_pos&EQP_ARMS);
  7788. if (pos == EQP_ARMS) //User specified both slots, pick one for them.
  7789. pos = sd->equip_index[EQI_HAND_R] >= 0 ? EQP_HAND_L : EQP_HAND_R;
  7790. }
  7791. if (pos&EQP_HAND_R && battle_config.use_weapon_skill_range&BL_PC) {
  7792. //Update skill-block range database when weapon range changes. [Skotlex]
  7793. i = sd->equip_index[EQI_HAND_R];
  7794. if (i < 0 || !sd->inventory_data[i]) //No data, or no weapon equipped
  7795. flag = 1;
  7796. else
  7797. flag = id->range != sd->inventory_data[i]->range;
  7798. }
  7799. for(i=0;i<EQI_MAX;i++) {
  7800. if(pos & equip_pos[i]) {
  7801. if(sd->equip_index[i] >= 0) //Slot taken, remove item from there.
  7802. pc_unequipitem(sd,sd->equip_index[i],2);
  7803. sd->equip_index[i] = n;
  7804. }
  7805. }
  7806. if(pos==EQP_AMMO) {
  7807. clif_arrowequip(sd,n);
  7808. clif_arrow_fail(sd,3);
  7809. }
  7810. else
  7811. clif_equipitemack(sd,n,pos,1);
  7812. sd->status.inventory[n].equip=pos;
  7813. if(pos & EQP_HAND_R) {
  7814. if(id)
  7815. sd->weapontype1 = id->look;
  7816. else
  7817. sd->weapontype1 = 0;
  7818. pc_calcweapontype(sd);
  7819. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7820. }
  7821. if(pos & EQP_HAND_L) {
  7822. if(id) {
  7823. if(id->type == IT_WEAPON) {
  7824. sd->status.shield = 0;
  7825. sd->weapontype2 = id->look;
  7826. }
  7827. else
  7828. if(id->type == IT_ARMOR) {
  7829. sd->status.shield = id->look;
  7830. sd->weapontype2 = 0;
  7831. }
  7832. }
  7833. else
  7834. sd->status.shield = sd->weapontype2 = 0;
  7835. pc_calcweapontype(sd);
  7836. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7837. }
  7838. //Added check to prevent sending the same look on multiple slots ->
  7839. //causes client to redraw item on top of itself. (suggested by Lupus)
  7840. if(pos & EQP_HEAD_LOW && pc_checkequip(sd,EQP_COSTUME_HEAD_LOW) == -1) {
  7841. if(id && !(pos&(EQP_HEAD_TOP|EQP_HEAD_MID)))
  7842. sd->status.head_bottom = id->look;
  7843. else
  7844. sd->status.head_bottom = 0;
  7845. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  7846. }
  7847. if(pos & EQP_HEAD_TOP && pc_checkequip(sd,EQP_COSTUME_HEAD_TOP) == -1) {
  7848. if(id)
  7849. sd->status.head_top = id->look;
  7850. else
  7851. sd->status.head_top = 0;
  7852. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  7853. }
  7854. if(pos & EQP_HEAD_MID && pc_checkequip(sd,EQP_COSTUME_HEAD_MID) == -1) {
  7855. if(id && !(pos&EQP_HEAD_TOP))
  7856. sd->status.head_mid = id->look;
  7857. else
  7858. sd->status.head_mid = 0;
  7859. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  7860. }
  7861. if(pos & EQP_COSTUME_HEAD_TOP) {
  7862. if(id){
  7863. sd->status.head_top = id->look;
  7864. } else
  7865. sd->status.head_top = 0;
  7866. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  7867. }
  7868. if(pos & EQP_COSTUME_HEAD_MID) {
  7869. if(id && !(pos&EQP_HEAD_TOP)){
  7870. sd->status.head_mid = id->look;
  7871. } else
  7872. sd->status.head_mid = 0;
  7873. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  7874. }
  7875. if(pos & EQP_COSTUME_HEAD_LOW) {
  7876. if(id && !(pos&(EQP_HEAD_TOP|EQP_HEAD_MID))){
  7877. sd->status.head_bottom = id->look;
  7878. } else
  7879. sd->status.head_bottom = 0;
  7880. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  7881. }
  7882. if(pos & EQP_SHOES)
  7883. clif_changelook(&sd->bl,LOOK_SHOES,0);
  7884. if(pos&EQP_GARMENT && pc_checkequip(sd,EQP_COSTUME_GARMENT) == -1) {
  7885. sd->status.robe = id ? id->look : 0;
  7886. clif_changelook(&sd->bl, LOOK_ROBE, sd->status.robe);
  7887. }
  7888. if(pos & EQP_COSTUME_GARMENT) {
  7889. sd->status.robe = id ? id->look : 0;
  7890. clif_changelook(&sd->bl,LOOK_ROBE,sd->status.robe);
  7891. }
  7892. pc_checkallowskill(sd); //Check if status changes should be halted.
  7893. iflag = sd->npc_item_flag;
  7894. /* check for combos (MUST be before status_calc_pc) */
  7895. if( id->combos_count )
  7896. pc_checkcombo(sd,id);
  7897. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  7898. ; //No cards
  7899. else {
  7900. for( i = 0; i < id->slot; i++ ) {
  7901. struct item_data *data;
  7902. if (!sd->status.inventory[n].card[i])
  7903. continue;
  7904. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  7905. if( data->combos_count )
  7906. pc_checkcombo(sd,data);
  7907. }
  7908. }
  7909. }
  7910. status_calc_pc(sd,0);
  7911. if (flag) //Update skill data
  7912. clif_skillinfoblock(sd);
  7913. //OnEquip script [Skotlex]
  7914. if (id) {
  7915. //only run the script if item isn't restricted
  7916. if (id->equip_script && (pc_has_permission(sd,PC_PERM_USE_ALL_EQUIPMENT) || !itemdb_isNoEquip(id,sd->bl.m)))
  7917. run_script(id->equip_script,0,sd->bl.id,fake_nd->bl.id);
  7918. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  7919. ; //No cards
  7920. else {
  7921. for( i = 0; i < id->slot; i++ ) {
  7922. struct item_data *data;
  7923. if (!sd->status.inventory[n].card[i])
  7924. continue;
  7925. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  7926. if (data->equip_script && (pc_has_permission(sd,PC_PERM_USE_ALL_EQUIPMENT) || !itemdb_isNoEquip(data,sd->bl.m)))
  7927. run_script(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
  7928. }
  7929. }
  7930. }
  7931. }
  7932. sd->npc_item_flag = iflag;
  7933. return true;
  7934. }
  7935. /*==========================================
  7936. * Called when attemting to unequip an item from player
  7937. * type:
  7938. * 0 - only unequip
  7939. * 1 - calculate status after unequipping
  7940. * 2 - force unequip
  7941. * return: false - fail; true - success
  7942. *------------------------------------------*/
  7943. bool pc_unequipitem(struct map_session_data *sd,int n,int flag) {
  7944. int i,iflag;
  7945. bool status_cacl = false;
  7946. nullpo_retr(false,sd);
  7947. if( n < 0 || n >= MAX_INVENTORY ) {
  7948. clif_unequipitemack(sd,0,0,0);
  7949. return false;
  7950. }
  7951. // status change that makes player cannot unequip equipment
  7952. if( !(flag&2) && sd->sc.count && (
  7953. sd->sc.data[SC_BERSERK] ||
  7954. sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  7955. sd->sc.data[SC__BLOODYLUST] ||
  7956. sd->sc.data[SC_KYOUGAKU] ||
  7957. (sd->sc.data[SC_PYROCLASTIC] && sd->inventory_data[n]->type == IT_WEAPON)) ) // can't switch weapon
  7958. {
  7959. clif_unequipitemack(sd,n,0,0);
  7960. return false;
  7961. }
  7962. if (&sd->sc) {
  7963. if (sd->sc.data[SC_HEAT_BARREL])
  7964. status_change_end(&sd->bl,SC_HEAT_BARREL,INVALID_TIMER);
  7965. if (sd->sc.data[SC_P_ALTER] && (sd->inventory_data[n]->type == IT_WEAPON || sd->inventory_data[n]->type == IT_AMMO))
  7966. status_change_end(&sd->bl,SC_P_ALTER,INVALID_TIMER);
  7967. }
  7968. if(battle_config.battle_log)
  7969. ShowInfo("unequip %d %x:%x\n",n,pc_equippoint(sd,n),sd->status.inventory[n].equip);
  7970. if(!sd->status.inventory[n].equip){ //Nothing to unequip
  7971. clif_unequipitemack(sd,n,0,0);
  7972. return false;
  7973. }
  7974. for(i=0;i<EQI_MAX;i++) {
  7975. if(sd->status.inventory[n].equip & equip_pos[i])
  7976. sd->equip_index[i] = -1;
  7977. }
  7978. if(sd->status.inventory[n].equip & EQP_HAND_R) {
  7979. sd->weapontype1 = 0;
  7980. sd->status.weapon = sd->weapontype2;
  7981. pc_calcweapontype(sd);
  7982. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7983. if( !battle_config.dancing_weaponswitch_fix )
  7984. status_change_end(&sd->bl, SC_DANCING, INVALID_TIMER); // Unequipping => stop dancing.
  7985. }
  7986. if(sd->status.inventory[n].equip & EQP_HAND_L) {
  7987. sd->status.shield = sd->weapontype2 = 0;
  7988. pc_calcweapontype(sd);
  7989. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7990. }
  7991. if(sd->status.inventory[n].equip & EQP_HEAD_LOW && pc_checkequip(sd,EQP_COSTUME_HEAD_LOW) == -1 ) {
  7992. sd->status.head_bottom = 0;
  7993. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  7994. }
  7995. if(sd->status.inventory[n].equip & EQP_HEAD_TOP && pc_checkequip(sd,EQP_COSTUME_HEAD_TOP) == -1 ) {
  7996. sd->status.head_top = 0;
  7997. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  7998. }
  7999. if(sd->status.inventory[n].equip & EQP_HEAD_MID && pc_checkequip(sd,EQP_COSTUME_HEAD_MID) == -1 ) {
  8000. sd->status.head_mid = 0;
  8001. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8002. }
  8003. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_TOP) {
  8004. sd->status.head_top = ( pc_checkequip(sd,EQP_HEAD_TOP) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_TOP)]->look : 0;
  8005. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  8006. }
  8007. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_MID) {
  8008. sd->status.head_mid = ( pc_checkequip(sd,EQP_HEAD_MID) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_MID)]->look : 0;
  8009. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8010. }
  8011. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_LOW) {
  8012. sd->status.head_bottom = ( pc_checkequip(sd,EQP_HEAD_LOW) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_LOW)]->look : 0;
  8013. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  8014. }
  8015. if(sd->status.inventory[n].equip & EQP_SHOES)
  8016. clif_changelook(&sd->bl,LOOK_SHOES,0);
  8017. if(sd->status.inventory[n].equip&EQP_GARMENT && pc_checkequip(sd,EQP_COSTUME_GARMENT) == -1) {
  8018. sd->status.robe = 0;
  8019. clif_changelook(&sd->bl, LOOK_ROBE, 0);
  8020. }
  8021. if(sd->status.inventory[n].equip & EQP_COSTUME_GARMENT) {
  8022. sd->status.robe = ( pc_checkequip(sd,EQP_GARMENT) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_GARMENT)]->look : 0;
  8023. clif_changelook(&sd->bl,LOOK_ROBE,sd->status.robe);
  8024. }
  8025. clif_unequipitemack(sd,n,sd->status.inventory[n].equip,1);
  8026. if((sd->status.inventory[n].equip & EQP_ARMS) &&
  8027. sd->weapontype1 == 0 && sd->weapontype2 == 0 && (!sd->sc.data[SC_SEVENWIND] || sd->sc.data[SC_ASPERSIO])) //Check for seven wind (but not level seven!)
  8028. skill_enchant_elemental_end(&sd->bl,-1);
  8029. if(sd->status.inventory[n].equip & EQP_ARMOR) {
  8030. // On Armor Change...
  8031. status_change_end(&sd->bl, SC_BENEDICTIO, INVALID_TIMER);
  8032. status_change_end(&sd->bl, SC_ARMOR_RESIST, INVALID_TIMER);
  8033. }
  8034. if( sd->state.autobonus&sd->status.inventory[n].equip )
  8035. sd->state.autobonus &= ~sd->status.inventory[n].equip; //Check for activated autobonus [Inkfish]
  8036. sd->status.inventory[n].equip=0;
  8037. iflag = sd->npc_item_flag;
  8038. /* check for combos (MUST be before status_calc_pc) */
  8039. if ( sd->inventory_data[n] ) {
  8040. if( sd->inventory_data[n]->combos_count ) {
  8041. if( pc_removecombo(sd,sd->inventory_data[n]) )
  8042. status_cacl = true;
  8043. } if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  8044. ; //No cards
  8045. else {
  8046. for( i = 0; i < sd->inventory_data[n]->slot; i++ ) {
  8047. struct item_data *data;
  8048. if (!sd->status.inventory[n].card[i])
  8049. continue;
  8050. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  8051. if( data->combos_count ) {
  8052. if( pc_removecombo(sd,data) )
  8053. status_cacl = true;
  8054. }
  8055. }
  8056. }
  8057. }
  8058. }
  8059. if(flag&1 || status_cacl) {
  8060. pc_checkallowskill(sd);
  8061. status_calc_pc(sd,0);
  8062. }
  8063. if(sd->sc.data[SC_SIGNUMCRUCIS] && !battle_check_undead(sd->battle_status.race,sd->battle_status.def_ele))
  8064. status_change_end(&sd->bl, SC_SIGNUMCRUCIS, INVALID_TIMER);
  8065. //OnUnEquip script [Skotlex]
  8066. if (sd->inventory_data[n]) {
  8067. if (sd->inventory_data[n]->unequip_script)
  8068. run_script(sd->inventory_data[n]->unequip_script,0,sd->bl.id,fake_nd->bl.id);
  8069. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  8070. ; //No cards
  8071. else {
  8072. for( i = 0; i < sd->inventory_data[n]->slot; i++ ) {
  8073. struct item_data *data;
  8074. if (!sd->status.inventory[n].card[i])
  8075. continue;
  8076. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  8077. if( data->unequip_script )
  8078. run_script(data->unequip_script,0,sd->bl.id,fake_nd->bl.id);
  8079. }
  8080. }
  8081. }
  8082. }
  8083. sd->npc_item_flag = iflag;
  8084. return true;
  8085. }
  8086. /*==========================================
  8087. * Checking if player (sd) has an invalid item
  8088. * and is unequiped on map load (item_noequip)
  8089. *------------------------------------------*/
  8090. void pc_checkitem(struct map_session_data *sd) {
  8091. int i, calc_flag = 0;
  8092. struct item it;
  8093. nullpo_retv(sd);
  8094. if( sd->state.vending ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
  8095. return;
  8096. for( i = 0; i < MAX_INVENTORY; i++ ) {
  8097. it = sd->status.inventory[i];
  8098. if( it.nameid == 0 )
  8099. continue;
  8100. if( !it.equip )
  8101. continue;
  8102. if( it.equip&~pc_equippoint(sd,i) ) {
  8103. pc_unequipitem(sd, i, 2);
  8104. calc_flag = 1;
  8105. continue;
  8106. }
  8107. 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) ) {
  8108. pc_unequipitem(sd, i, 2);
  8109. calc_flag = 1;
  8110. continue;
  8111. }
  8112. }
  8113. if( calc_flag && sd->state.active ) {
  8114. pc_checkallowskill(sd);
  8115. status_calc_pc(sd,0);
  8116. }
  8117. return;
  8118. }
  8119. /*==========================================
  8120. * Checks for unavailable items and removes them.
  8121. *------------------------------------------*/
  8122. void pc_check_available_item(struct map_session_data *sd) {
  8123. int i, it;
  8124. char output[256];
  8125. nullpo_retv(sd);
  8126. if( battle_config.item_check&1 ) { // Check for invalid(ated) items in inventory.
  8127. for( i = 0; i < MAX_INVENTORY; i++ ) {
  8128. it = sd->status.inventory[i].nameid;
  8129. if( it && !itemdb_available(it) ) {
  8130. sprintf(output, msg_txt(sd, 709), it); // Item %d has been removed from your inventory.
  8131. clif_displaymessage(sd->fd, output);
  8132. 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);
  8133. pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
  8134. }
  8135. }
  8136. }
  8137. if( battle_config.item_check&2 ) { // Check for invalid(ated) items in cart.
  8138. for( i = 0; i < MAX_CART; i++ ) {
  8139. it = sd->status.cart[i].nameid;
  8140. if( it && !itemdb_available(it) ) {
  8141. sprintf(output, msg_txt(sd, 710), it); // Item %d has been removed from your cart.
  8142. clif_displaymessage(sd->fd, output);
  8143. 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);
  8144. pc_cart_delitem(sd, i, sd->status.cart[i].amount, 0, LOG_TYPE_OTHER);
  8145. }
  8146. }
  8147. }
  8148. if( battle_config.item_check&4 ) { // Check for invalid(ated) items in storage.
  8149. for( i = 0; i < sd->storage_size; i++ ) {
  8150. it = sd->status.storage.items[i].nameid;
  8151. if( it && !itemdb_available(it) ) {
  8152. sprintf(output, msg_txt(sd, 711), it); // Item %d has been removed from your storage.
  8153. clif_displaymessage(sd->fd, output);
  8154. 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);
  8155. storage_delitem(sd, i, sd->status.storage.items[i].amount);
  8156. }
  8157. }
  8158. }
  8159. }
  8160. /*==========================================
  8161. * Update PVP rank for sd1 in cmp to sd2
  8162. *------------------------------------------*/
  8163. static int pc_calc_pvprank_sub(struct block_list *bl,va_list ap)
  8164. {
  8165. struct map_session_data *sd1,*sd2;
  8166. sd1=(struct map_session_data *)bl;
  8167. sd2=va_arg(ap,struct map_session_data *);
  8168. if( sd1->sc.option&OPTION_INVISIBLE || sd2->sc.option&OPTION_INVISIBLE )
  8169. {// cannot register pvp rank for hidden GMs
  8170. return 0;
  8171. }
  8172. if( sd1->pvp_point > sd2->pvp_point )
  8173. sd2->pvp_rank++;
  8174. return 0;
  8175. }
  8176. /*==========================================
  8177. * Calculate new rank beetween all present players (map_foreachinarea)
  8178. * and display result
  8179. *------------------------------------------*/
  8180. int pc_calc_pvprank(struct map_session_data *sd)
  8181. {
  8182. int old = sd->pvp_rank;
  8183. struct map_data *m = &map[sd->bl.m];
  8184. sd->pvp_rank=1;
  8185. map_foreachinmap(pc_calc_pvprank_sub,sd->bl.m,BL_PC,sd);
  8186. if(old!=sd->pvp_rank || sd->pvp_lastusers!=m->users_pvp)
  8187. clif_pvpset(sd,sd->pvp_rank,sd->pvp_lastusers=m->users_pvp,0);
  8188. return sd->pvp_rank;
  8189. }
  8190. /*==========================================
  8191. * Calculate next sd ranking calculation from config
  8192. *------------------------------------------*/
  8193. int pc_calc_pvprank_timer(int tid, unsigned int tick, int id, intptr_t data)
  8194. {
  8195. struct map_session_data *sd;
  8196. sd=map_id2sd(id);
  8197. if(sd==NULL)
  8198. return 0;
  8199. sd->pvp_timer = INVALID_TIMER;
  8200. if( sd->sc.option&OPTION_INVISIBLE )
  8201. {// do not calculate the pvp rank for a hidden GM
  8202. return 0;
  8203. }
  8204. if( pc_calc_pvprank(sd) > 0 )
  8205. sd->pvp_timer = add_timer(gettick()+PVP_CALCRANK_INTERVAL,pc_calc_pvprank_timer,id,data);
  8206. return 0;
  8207. }
  8208. /*==========================================
  8209. * Checking if sd is married
  8210. * Return:
  8211. * partner_id = yes
  8212. * 0 = no
  8213. *------------------------------------------*/
  8214. int pc_ismarried(struct map_session_data *sd)
  8215. {
  8216. if(sd == NULL)
  8217. return -1;
  8218. if(sd->status.partner_id > 0)
  8219. return sd->status.partner_id;
  8220. else
  8221. return 0;
  8222. }
  8223. /*==========================================
  8224. * Marry player sd to player dstsd
  8225. * Return:
  8226. * false = fail
  8227. * true = success
  8228. *------------------------------------------*/
  8229. bool pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd)
  8230. {
  8231. if(sd == NULL || dstsd == NULL ||
  8232. sd->status.partner_id > 0 || dstsd->status.partner_id > 0 ||
  8233. (sd->class_&JOBL_BABY) || (dstsd->class_&JOBL_BABY))
  8234. return false;
  8235. sd->status.partner_id = dstsd->status.char_id;
  8236. dstsd->status.partner_id = sd->status.char_id;
  8237. return true;
  8238. }
  8239. /*==========================================
  8240. * Divorce sd from its partner
  8241. * Return:
  8242. * false = fail
  8243. * true = success
  8244. *------------------------------------------*/
  8245. bool pc_divorce(struct map_session_data *sd)
  8246. {
  8247. struct map_session_data *p_sd;
  8248. int i;
  8249. if( sd == NULL || !pc_ismarried(sd) )
  8250. return false;
  8251. if( !sd->status.partner_id )
  8252. return false; // Char is not married
  8253. if( (p_sd = map_charid2sd(sd->status.partner_id)) == NULL )
  8254. { // Lets char server do the divorce
  8255. if( chrif_divorce(sd->status.char_id, sd->status.partner_id) )
  8256. return false; // No char server connected
  8257. return true;
  8258. }
  8259. // Both players online, lets do the divorce manually
  8260. sd->status.partner_id = 0;
  8261. p_sd->status.partner_id = 0;
  8262. for( i = 0; i < MAX_INVENTORY; i++ )
  8263. {
  8264. if( sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F )
  8265. pc_delitem(sd, i, 1, 0, 0, LOG_TYPE_OTHER);
  8266. if( p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F )
  8267. pc_delitem(p_sd, i, 1, 0, 0, LOG_TYPE_OTHER);
  8268. }
  8269. clif_divorced(sd, p_sd->status.name);
  8270. clif_divorced(p_sd, sd->status.name);
  8271. return true;
  8272. }
  8273. /**
  8274. * Get the partner map_session_data of a player
  8275. * @param sd : the husband|wife session
  8276. * @return partner session or NULL
  8277. */
  8278. struct map_session_data *pc_get_partner(struct map_session_data *sd){
  8279. if (!sd || !pc_ismarried(sd))
  8280. return NULL;
  8281. return map_charid2sd(sd->status.partner_id);
  8282. }
  8283. /**
  8284. * Get the father map_session_data of a player
  8285. * @param sd : the baby session
  8286. * @return father session or NULL
  8287. */
  8288. struct map_session_data *pc_get_father (struct map_session_data *sd){
  8289. if (!sd || !(sd->class_&JOBL_BABY) || !sd->status.father)
  8290. return NULL;
  8291. return map_charid2sd(sd->status.father);
  8292. }
  8293. /**
  8294. * Get the mother map_session_data of a player
  8295. * @param sd : the baby session
  8296. * @return mother session or NULL
  8297. */
  8298. struct map_session_data *pc_get_mother (struct map_session_data *sd){
  8299. if (!sd || !(sd->class_&JOBL_BABY) || !sd->status.mother)
  8300. return NULL;
  8301. return map_charid2sd(sd->status.mother);
  8302. }
  8303. /*==========================================
  8304. * Get sd children charid. (Need to be married)
  8305. *------------------------------------------*/
  8306. struct map_session_data *pc_get_child (struct map_session_data *sd)
  8307. {
  8308. if (!sd || !pc_ismarried(sd) || !sd->status.child)
  8309. // charid2sd returns NULL if not found
  8310. return NULL;
  8311. return map_charid2sd(sd->status.child);
  8312. }
  8313. /*==========================================
  8314. * Set player sd to bleed. (losing hp and/or sp each diff_tick)
  8315. *------------------------------------------*/
  8316. void pc_bleeding (struct map_session_data *sd, unsigned int diff_tick)
  8317. {
  8318. int hp = 0, sp = 0;
  8319. if( pc_isdead(sd) )
  8320. return;
  8321. if (sd->hp_loss.value) {
  8322. sd->hp_loss.tick += diff_tick;
  8323. while (sd->hp_loss.tick >= sd->hp_loss.rate) {
  8324. hp += sd->hp_loss.value;
  8325. sd->hp_loss.tick -= sd->hp_loss.rate;
  8326. }
  8327. if(hp >= sd->battle_status.hp)
  8328. hp = sd->battle_status.hp-1; //Script drains cannot kill you.
  8329. }
  8330. if (sd->sp_loss.value) {
  8331. sd->sp_loss.tick += diff_tick;
  8332. while (sd->sp_loss.tick >= sd->sp_loss.rate) {
  8333. sp += sd->sp_loss.value;
  8334. sd->sp_loss.tick -= sd->sp_loss.rate;
  8335. }
  8336. }
  8337. if (hp > 0 || sp > 0)
  8338. status_zap(&sd->bl, hp, sp);
  8339. }
  8340. //Character regen. Flag is used to know which types of regen can take place.
  8341. //&1: HP regen
  8342. //&2: SP regen
  8343. void pc_regen (struct map_session_data *sd, unsigned int diff_tick)
  8344. {
  8345. int hp = 0, sp = 0;
  8346. if (sd->hp_regen.value) {
  8347. sd->hp_regen.tick += diff_tick;
  8348. while (sd->hp_regen.tick >= sd->hp_regen.rate) {
  8349. hp += sd->hp_regen.value;
  8350. sd->hp_regen.tick -= sd->hp_regen.rate;
  8351. }
  8352. }
  8353. if (sd->sp_regen.value) {
  8354. sd->sp_regen.tick += diff_tick;
  8355. while (sd->sp_regen.tick >= sd->sp_regen.rate) {
  8356. sp += sd->sp_regen.value;
  8357. sd->sp_regen.tick -= sd->sp_regen.rate;
  8358. }
  8359. }
  8360. if (hp > 0 || sp > 0)
  8361. status_heal(&sd->bl, hp, sp, 0);
  8362. }
  8363. /*==========================================
  8364. * Memo player sd savepoint. (map,x,y)
  8365. *------------------------------------------*/
  8366. void pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y)
  8367. {
  8368. nullpo_retv(sd);
  8369. sd->status.save_point.map = mapindex;
  8370. sd->status.save_point.x = x;
  8371. sd->status.save_point.y = y;
  8372. }
  8373. /*==========================================
  8374. * Save 1 player data at autosave intervalle
  8375. *------------------------------------------*/
  8376. static int pc_autosave(int tid, unsigned int tick, int id, intptr_t data)
  8377. {
  8378. int interval;
  8379. struct s_mapiterator* iter;
  8380. struct map_session_data* sd;
  8381. static int last_save_id = 0, save_flag = 0;
  8382. if(save_flag == 2) //Someone was saved on last call, normal cycle
  8383. save_flag = 0;
  8384. else
  8385. save_flag = 1; //Noone was saved, so save first found char.
  8386. iter = mapit_getallusers();
  8387. for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
  8388. {
  8389. if(sd->bl.id == last_save_id && save_flag != 1) {
  8390. save_flag = 1;
  8391. continue;
  8392. }
  8393. if(save_flag != 1) //Not our turn to save yet.
  8394. continue;
  8395. //Save char.
  8396. last_save_id = sd->bl.id;
  8397. save_flag = 2;
  8398. #ifdef VIP_ENABLE
  8399. if(sd->vip.enabled) //check if we're still vip
  8400. chrif_req_login_operation(1, sd->status.name, 6, 0, 1, 0);
  8401. #endif
  8402. chrif_save(sd,0);
  8403. break;
  8404. }
  8405. mapit_free(iter);
  8406. interval = autosave_interval/(map_usercount()+1);
  8407. if(interval < minsave_interval)
  8408. interval = minsave_interval;
  8409. add_timer(gettick()+interval,pc_autosave,0,0);
  8410. return 0;
  8411. }
  8412. static int pc_daynight_timer_sub(struct map_session_data *sd,va_list ap)
  8413. {
  8414. if (sd->state.night != night_flag && map[sd->bl.m].flag.nightenabled)
  8415. { //Night/day state does not match.
  8416. clif_status_load(&sd->bl, SI_NIGHT, night_flag); //New night effect by dynamix [Skotlex]
  8417. sd->state.night = night_flag;
  8418. return 1;
  8419. }
  8420. return 0;
  8421. }
  8422. /*================================================
  8423. * timer to do the day [Yor]
  8424. * data: 0 = called by timer, 1 = gmcommand/script
  8425. *------------------------------------------------*/
  8426. int map_day_timer(int tid, unsigned int tick, int id, intptr_t data)
  8427. {
  8428. char tmp_soutput[1024];
  8429. if (data == 0 && battle_config.day_duration <= 0) // if we want a day
  8430. return 0;
  8431. if (!night_flag)
  8432. return 0; //Already day.
  8433. night_flag = 0; // 0=day, 1=night [Yor]
  8434. map_foreachpc(pc_daynight_timer_sub);
  8435. strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,502) : msg_txt(NULL,60)); // The day has arrived!
  8436. intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, 0);
  8437. return 0;
  8438. }
  8439. /*================================================
  8440. * timer to do the night [Yor]
  8441. * data: 0 = called by timer, 1 = gmcommand/script
  8442. *------------------------------------------------*/
  8443. int map_night_timer(int tid, unsigned int tick, int id, intptr_t data)
  8444. {
  8445. char tmp_soutput[1024];
  8446. if (data == 0 && battle_config.night_duration <= 0) // if we want a night
  8447. return 0;
  8448. if (night_flag)
  8449. return 0; //Already nigth.
  8450. night_flag = 1; // 0=day, 1=night [Yor]
  8451. map_foreachpc(pc_daynight_timer_sub);
  8452. strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,503) : msg_txt(NULL,59)); // The night has fallen...
  8453. intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, 0);
  8454. return 0;
  8455. }
  8456. void pc_setstand(struct map_session_data *sd){
  8457. nullpo_retv(sd);
  8458. status_change_end(&sd->bl, SC_TENSIONRELAX, INVALID_TIMER);
  8459. clif_status_load(&sd->bl,SI_SIT,0);
  8460. clif_standing(&sd->bl); //Inform area PC is standing
  8461. //Reset sitting tick.
  8462. sd->ssregen.tick.hp = sd->ssregen.tick.sp = 0;
  8463. sd->state.dead_sit = sd->vd.dead_sit = 0;
  8464. }
  8465. /**
  8466. * Mechanic (MADO GEAR)
  8467. **/
  8468. void pc_overheat(struct map_session_data *sd, int val) {
  8469. int heat = val, skill,
  8470. limit[] = { 10, 20, 28, 46, 66 };
  8471. if( !pc_ismadogear(sd) || sd->sc.data[SC_OVERHEAT] )
  8472. return; // already burning
  8473. skill = cap_value(pc_checkskill(sd,NC_MAINFRAME),0,4);
  8474. if( sd->sc.data[SC_OVERHEAT_LIMITPOINT] ) {
  8475. heat += sd->sc.data[SC_OVERHEAT_LIMITPOINT]->val1;
  8476. status_change_end(&sd->bl,SC_OVERHEAT_LIMITPOINT,INVALID_TIMER);
  8477. }
  8478. heat = max(0,heat); // Avoid negative HEAT
  8479. if( heat >= limit[skill] )
  8480. sc_start(&sd->bl,&sd->bl,SC_OVERHEAT,100,0,1000);
  8481. else
  8482. sc_start(&sd->bl,&sd->bl,SC_OVERHEAT_LIMITPOINT,100,heat,30000);
  8483. return;
  8484. }
  8485. /**
  8486. * Check if player is autolooting given itemID.
  8487. */
  8488. bool pc_isautolooting(struct map_session_data *sd, int nameid)
  8489. {
  8490. uint8 i = 0;
  8491. bool j = false;
  8492. if (!sd->state.autolooting && !sd->state.autolootingtype)
  8493. return false;
  8494. if (sd->state.autolooting)
  8495. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == nameid);
  8496. if (sd->state.autolootingtype && sd->state.autoloottype&(1<<itemdb_type(nameid)))
  8497. j = true;
  8498. return (i != AUTOLOOTITEM_SIZE || j );
  8499. }
  8500. /**
  8501. * Checks if player can use @/#command
  8502. * @param sd Player map session data
  8503. * @param command Command name without @/# and params
  8504. * @param type is it atcommand or charcommand
  8505. */
  8506. bool pc_can_use_command(struct map_session_data *sd, const char *command, AtCommandType type)
  8507. {
  8508. return pc_group_can_use_command(pc_get_group_id(sd), command, type);
  8509. }
  8510. /**
  8511. * Checks if commands used by a player should be logged
  8512. * according to their group setting.
  8513. * @param sd Player map session data
  8514. */
  8515. bool pc_should_log_commands(struct map_session_data *sd)
  8516. {
  8517. return pc_group_should_log_commands(pc_get_group_id(sd));
  8518. }
  8519. static int pc_talisman_timer(int tid, unsigned int tick, int id, intptr_t data)
  8520. {
  8521. struct map_session_data *sd;
  8522. int i, type;
  8523. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  8524. return 1;
  8525. ARR_FIND(1, 5, type, sd->talisman[type] > 0);
  8526. if( sd->talisman[type] <= 0 )
  8527. {
  8528. 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);
  8529. sd->talisman[type] = 0;
  8530. return 0;
  8531. }
  8532. ARR_FIND(0, sd->talisman[type], i, sd->talisman_timer[type][i] == tid);
  8533. if( i == sd->talisman[type] )
  8534. {
  8535. ShowError("pc_talisman_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
  8536. return 0;
  8537. }
  8538. sd->talisman[type]--;
  8539. if( i != sd->talisman[type] )
  8540. memmove(sd->talisman_timer[type]+i, sd->talisman_timer[type]+i+1, (sd->talisman[type]-i)*sizeof(int));
  8541. sd->talisman_timer[type][sd->talisman[type]] = INVALID_TIMER;
  8542. clif_talisman(sd, type);
  8543. return 0;
  8544. }
  8545. int pc_add_talisman(struct map_session_data *sd,int interval,int max,int type)
  8546. {
  8547. int tid, i;
  8548. nullpo_ret(sd);
  8549. if(max > 10)
  8550. max = 10;
  8551. if(sd->talisman[type] < 0)
  8552. sd->talisman[type] = 0;
  8553. if( sd->talisman[type] && sd->talisman[type] >= max )
  8554. {
  8555. if(sd->talisman_timer[type][0] != INVALID_TIMER)
  8556. delete_timer(sd->talisman_timer[type][0],pc_talisman_timer);
  8557. sd->talisman[type]--;
  8558. if( sd->talisman[type] != 0 )
  8559. memmove(sd->talisman_timer[type]+0, sd->talisman_timer[type]+1, (sd->talisman[type])*sizeof(int));
  8560. sd->talisman_timer[type][sd->talisman[type]] = INVALID_TIMER;
  8561. }
  8562. tid = add_timer(gettick()+interval, pc_talisman_timer, sd->bl.id, 0);
  8563. 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);
  8564. if( i != sd->talisman[type] )
  8565. memmove(sd->talisman_timer[type]+i+1, sd->talisman_timer[type]+i, (sd->talisman[type]-i)*sizeof(int));
  8566. sd->talisman_timer[type][i] = tid;
  8567. sd->talisman[type]++;
  8568. clif_talisman(sd, type);
  8569. return 0;
  8570. }
  8571. int pc_del_talisman(struct map_session_data *sd,int count,int type)
  8572. {
  8573. int i;
  8574. nullpo_ret(sd);
  8575. if( sd->talisman[type] <= 0 ) {
  8576. sd->talisman[type] = 0;
  8577. return 0;
  8578. }
  8579. if( count <= 0 )
  8580. return 0;
  8581. if( count > sd->talisman[type] )
  8582. count = sd->talisman[type];
  8583. sd->talisman[type] -= count;
  8584. if( count > 10 )
  8585. count = 10;
  8586. for(i = 0; i < count; i++) {
  8587. if(sd->talisman_timer[type][i] != INVALID_TIMER) {
  8588. delete_timer(sd->talisman_timer[type][i],pc_talisman_timer);
  8589. sd->talisman_timer[type][i] = INVALID_TIMER;
  8590. }
  8591. }
  8592. for(i = count; i < 10; i++) {
  8593. sd->talisman_timer[type][i-count] = sd->talisman_timer[type][i];
  8594. sd->talisman_timer[type][i] = INVALID_TIMER;
  8595. }
  8596. clif_talisman(sd, type);
  8597. return 0;
  8598. }
  8599. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  8600. /*==========================================
  8601. * Renewal EXP/Itemdrop rate modifier base on level penalty
  8602. * 1=exp 2=itemdrop
  8603. *------------------------------------------*/
  8604. int pc_level_penalty_mod(struct map_session_data *sd, int mob_level, uint32 mob_class, int type)
  8605. {
  8606. int diff, rate = 100, i;
  8607. nullpo_ret(sd);
  8608. diff = mob_level - sd->status.base_level;
  8609. if( diff < 0 )
  8610. diff = MAX_LEVEL + ( ~diff + 1 );
  8611. for( i = 0; i < CLASS_ALL; i++ ) {
  8612. int tmp;
  8613. if( ( tmp = level_penalty[type][i][diff] ) > 0 ) {
  8614. rate = tmp;
  8615. break;
  8616. }
  8617. }
  8618. return rate;
  8619. }
  8620. #endif
  8621. int pc_split_str(char *str,char **val,int num)
  8622. {
  8623. int i;
  8624. for (i=0; i<num && str; i++){
  8625. val[i] = str;
  8626. str = strchr(str,',');
  8627. if (str && i<num-1) //Do not remove a trailing comma.
  8628. *str++=0;
  8629. }
  8630. return i;
  8631. }
  8632. int pc_split_atoi(char* str, int* val, char sep, int max)
  8633. {
  8634. int i,j;
  8635. for (i=0; i<max; i++) {
  8636. if (!str) break;
  8637. val[i] = atoi(str);
  8638. str = strchr(str,sep);
  8639. if (str)
  8640. *str++=0;
  8641. }
  8642. //Zero up the remaining.
  8643. for(j=i; j < max; j++)
  8644. val[j] = 0;
  8645. return i;
  8646. }
  8647. int pc_split_atoui(char* str, unsigned int* val, char sep, int max)
  8648. {
  8649. static int warning=0;
  8650. int i,j;
  8651. for (i=0; i<max; i++) {
  8652. double f;
  8653. if (!str) break;
  8654. f = atof(str);
  8655. if (f < 0)
  8656. val[i] = 0;
  8657. else if (f > UINT_MAX) {
  8658. val[i] = UINT_MAX;
  8659. if (!warning) {
  8660. warning = 1;
  8661. ShowWarning("pc_readdb (exp.txt): Required exp per level is capped to %u\n", UINT_MAX);
  8662. }
  8663. } else
  8664. val[i] = (unsigned int)f;
  8665. str = strchr(str,sep);
  8666. if (str)
  8667. *str++=0;
  8668. }
  8669. //Zero up the remaining.
  8670. for(j=i; j < max; j++)
  8671. val[j] = 0;
  8672. return i;
  8673. }
  8674. /*==========================================
  8675. * sub DB reading.
  8676. * Function used to read skill_tree.txt
  8677. *------------------------------------------*/
  8678. static bool pc_readdb_skilltree(char* fields[], int columns, int current)
  8679. {
  8680. unsigned char joblv = 0, skill_lv;
  8681. uint16 skill_id;
  8682. int idx, class_;
  8683. unsigned int i, offset = 3, skill_idx;
  8684. class_ = atoi(fields[0]);
  8685. skill_id = (uint16)atoi(fields[1]);
  8686. skill_lv = (unsigned char)atoi(fields[2]);
  8687. if(columns==4+MAX_PC_SKILL_REQUIRE*2)
  8688. {// job level requirement extra column
  8689. joblv = (unsigned char)atoi(fields[3]);
  8690. offset++;
  8691. }
  8692. if(!pcdb_checkid(class_))
  8693. {
  8694. ShowWarning("pc_readdb_skilltree: Invalid job class %d specified.\n", class_);
  8695. return false;
  8696. }
  8697. idx = pc_class2idx(class_);
  8698. //This is to avoid adding two lines for the same skill. [Skotlex]
  8699. ARR_FIND( 0, MAX_SKILL_TREE, skill_idx, skill_tree[idx][skill_idx].id == 0 || skill_tree[idx][skill_idx].id == skill_id );
  8700. if( skill_idx == MAX_SKILL_TREE )
  8701. {
  8702. 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_);
  8703. return false;
  8704. }
  8705. else if(skill_tree[idx][skill_idx].id)
  8706. {
  8707. ShowNotice("pc_readdb_skilltree: Overwriting skill %hu for job class %d.\n", skill_id, class_);
  8708. }
  8709. skill_tree[idx][skill_idx].id = skill_id;
  8710. skill_tree[idx][skill_idx].max = skill_lv;
  8711. skill_tree[idx][skill_idx].joblv = joblv;
  8712. for(i = 0; i < MAX_PC_SKILL_REQUIRE; i++)
  8713. {
  8714. skill_tree[idx][skill_idx].need[i].id = atoi(fields[i*2+offset]);
  8715. skill_tree[idx][skill_idx].need[i].lv = atoi(fields[i*2+offset+1]);
  8716. }
  8717. return true;
  8718. }
  8719. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  8720. static bool pc_readdb_levelpenalty(char* fields[], int columns, int current)
  8721. {
  8722. int type, class_, diff;
  8723. type = atoi(fields[0]); //1=experience, 2=item drop
  8724. class_ = atoi(fields[1]);
  8725. diff = atoi(fields[2]);
  8726. if( type != 1 && type != 2 ){
  8727. ShowWarning("pc_readdb_levelpenalty: Invalid type %d specified.\n", type);
  8728. return false;
  8729. }
  8730. if( class_ < 0 || class_ > CLASS_ALL ){
  8731. ShowWarning("pc_readdb_levelpenalty: Invalid class %d specified.\n", class_);
  8732. return false;
  8733. }
  8734. diff = min(diff, MAX_LEVEL);
  8735. if( diff < 0 )
  8736. diff = min(MAX_LEVEL + ( ~(diff) + 1 ), MAX_LEVEL*2);
  8737. level_penalty[type][class_][diff] = atoi(fields[3]);
  8738. return true;
  8739. }
  8740. #endif
  8741. /** [Cydh]
  8742. * Calculates base hp of player. Reference: http://irowiki.org/wiki/Max_HP
  8743. * @param level Base level of player
  8744. * @param idx Index of class
  8745. * @return base_hp
  8746. */
  8747. static unsigned int pc_calc_basehp(uint16 level, uint16 class_idx) {
  8748. double base_hp;
  8749. uint16 i;
  8750. base_hp = 35 + level * (job_info[class_idx].hp_multiplicator/100.);
  8751. for (i = 2; i <= level; i++)
  8752. base_hp += floor(((job_info[class_idx].hp_factor/100.) * i) + 0.5); //Don't have round()
  8753. return (unsigned int)base_hp;
  8754. }
  8755. //Reading job_db1.txt line, (class,weight,HPFactor,HPMultiplicator,SPFactor,aspd/lvl...)
  8756. static bool pc_readdb_job1(char* fields[], int columns, int current){
  8757. int idx, class_;
  8758. unsigned int i;
  8759. class_ = atoi(fields[0]);
  8760. if (!pcdb_checkid(class_)) {
  8761. ShowWarning("status_readdb_job1: Invalid job class %d specified.\n", class_);
  8762. return false;
  8763. }
  8764. idx = pc_class2idx(class_);
  8765. job_info[idx].max_weight_base = atoi(fields[1]);
  8766. job_info[idx].hp_factor = atoi(fields[2]);
  8767. job_info[idx].hp_multiplicator = atoi(fields[3]);
  8768. job_info[idx].sp_factor = atoi(fields[4]);
  8769. #ifdef RENEWAL_ASPD
  8770. for(i = 0; i <= MAX_WEAPON_TYPE; i++)
  8771. #else
  8772. for(i = 0; i < MAX_WEAPON_TYPE; i++)
  8773. #endif
  8774. {
  8775. job_info[idx].aspd_base[i] = atoi(fields[i+5]);
  8776. }
  8777. return true;
  8778. }
  8779. //Reading job_db2.txt line (class,JobLv1,JobLv2,JobLv3,...)
  8780. static bool pc_readdb_job2(char* fields[], int columns, int current)
  8781. {
  8782. int idx, class_, i;
  8783. class_ = atoi(fields[0]);
  8784. if(!pcdb_checkid(class_))
  8785. {
  8786. ShowWarning("status_readdb_job2: Invalid job class %d specified.\n", class_);
  8787. return false;
  8788. }
  8789. idx = pc_class2idx(class_);
  8790. for(i = 1; i < columns; i++)
  8791. {
  8792. job_info[idx].job_bonus[i-1] = atoi(fields[i]);
  8793. }
  8794. return true;
  8795. }
  8796. //Reading job_exp.txt line
  8797. //Max Level,Class list,Type (0 - Base Exp; 1 - Job Exp),Exp/lvl...
  8798. static bool pc_readdb_job_exp(char* fields[], int columns, int current)
  8799. {
  8800. int idx, i, type;
  8801. int job_id,job_count,jobs[CLASS_COUNT];
  8802. unsigned int ui, maxlvl;
  8803. maxlvl = atoi(fields[0]);
  8804. if(maxlvl > MAX_LEVEL || maxlvl<1){
  8805. ShowError("pc_readdb_job_exp: Invalid maxlevel %d specified.\n", maxlvl);
  8806. return false;
  8807. }
  8808. if((maxlvl+3) > columns){ //nb values = (maxlvl-startlvl)+1-index1stvalue
  8809. ShowError("pc_readdb_job_exp: Number of columns %d defined is too low for max level %d.\n",columns,maxlvl);
  8810. return false;
  8811. }
  8812. type = atoi(fields[2]);
  8813. if(type < 0 || type > 1){
  8814. ShowError("pc_readdb_job_exp: Invalid type %d specified.\n", type);
  8815. return false;
  8816. }
  8817. job_count = pc_split_atoi(fields[1],jobs,':',CLASS_COUNT);
  8818. if (job_count < 1)
  8819. return false;
  8820. job_id = jobs[0];
  8821. if(!pcdb_checkid(job_id)){
  8822. ShowError("pc_readdb_job_exp: Invalid job class %d specified.\n", job_id);
  8823. return false;
  8824. }
  8825. idx = pc_class2idx(job_id);
  8826. job_info[idx].max_level[type] = maxlvl;
  8827. for(i=0; i<maxlvl; i++) {
  8828. job_info[idx].exp_table[type][i] = ((uint32) atoi(fields[3+i]));
  8829. //Place the BaseHP/SP calculation here, so we can use the maxlevel from job_exp
  8830. if (type != 0)
  8831. continue;
  8832. job_info[idx].base_hp[i] = pc_calc_basehp(i+1,idx);
  8833. job_info[idx].base_sp[i] = 10 + ((i+1) * (job_info[idx].sp_factor/100));
  8834. }
  8835. //Reverse check in case the array has a bunch of trailing zeros... [Skotlex]
  8836. //The reasoning behind the -2 is this... if the max level is 5, then the array
  8837. //should look like this:
  8838. //0: x, 1: x, 2: x: 3: x 4: 0 <- last valid value is at 3.
  8839. while ((ui = job_info[idx].max_level[type]) >= 2 && job_info[idx].exp_table[type][ui-2] <= 0)
  8840. job_info[idx].max_level[type]--;
  8841. if (job_info[idx].max_level[type] < maxlvl) {
  8842. 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]);
  8843. ShowInfo("Filling the missing values with the last exp entry.\n");
  8844. //Fill the requested values with the last entry.
  8845. ui = (job_info[idx].max_level[type] <= 2? 0: job_info[idx].max_level[type]-2);
  8846. for (; ui+2 < maxlvl; ui++)
  8847. job_info[idx].exp_table[type][ui] = job_info[idx].exp_table[type][ui-1];
  8848. job_info[idx].max_level[type] = maxlvl;
  8849. }
  8850. // ShowInfo("%s - Class %d: %d\n", type?"Job":"Base", job_id, job_info[idx].max_level[type]);
  8851. for (i = 1; i < job_count; i++) {
  8852. uint16 j;
  8853. job_id = jobs[i];
  8854. if (!pcdb_checkid(job_id)) {
  8855. ShowError("pc_readdb_job_exp: Invalid job ID %d.\n", job_id);
  8856. continue;
  8857. }
  8858. idx = pc_class2idx(job_id);
  8859. 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]));
  8860. job_info[idx].max_level[type] = maxlvl;
  8861. // ShowInfo("%s - Class %d: %u\n", type?"Job":"Base", job_id, job_info[idx].max_level[type]);
  8862. //Place the BaseHP/SP calculation here, so we can use the maxlevel from job_exp
  8863. if (type != 0)
  8864. continue;
  8865. for (j = 0; j < maxlvl; j++) {
  8866. job_info[idx].base_hp[j] = pc_calc_basehp(j+1,idx);
  8867. job_info[idx].base_sp[j] = 10 + ((j+1) * (job_info[idx].sp_factor/100));
  8868. }
  8869. }
  8870. return true;
  8871. }
  8872. /**
  8873. * #ifdef HP_SP_TABLES, reads 'job_basehpsp_db.txt to replace hp/sp results from formula
  8874. * startlvl,endlvl,class,type,values...
  8875. */
  8876. #ifdef HP_SP_TABLES
  8877. static bool pc_readdb_job_basehpsp(char* fields[], int columns, int current)
  8878. {
  8879. int i, startlvl, endlvl;
  8880. int job_count,jobs[CLASS_COUNT];
  8881. short type;
  8882. startlvl = atoi(fields[0]);
  8883. if(startlvl<1){
  8884. ShowError("pc_readdb_job_basehpsp: Invalid start level %d specified.\n", startlvl);
  8885. return false;
  8886. }
  8887. endlvl = atoi(fields[1]);
  8888. if(endlvl<1 || endlvl<startlvl){
  8889. ShowError("pc_readdb_job_basehpsp: Invalid end level %d specified.\n", endlvl);
  8890. return false;
  8891. }
  8892. if((endlvl-startlvl+1+4) > columns){ //nb values = (maxlvl-startlvl)+1-index1stvalue
  8893. 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);
  8894. return false;
  8895. }
  8896. type = atoi(fields[3]);
  8897. if(type < 0 || type > 1){
  8898. ShowError("pc_readdb_job_basehpsp: Invalid type %d specified.\n", type);
  8899. return false;
  8900. }
  8901. job_count = pc_split_atoi(fields[2],jobs,':',CLASS_COUNT);
  8902. if (job_count < 1)
  8903. return false;
  8904. for (i = 0; i < job_count; i++) {
  8905. int idx, job_id = jobs[i], use_endlvl;
  8906. if (!pcdb_checkid(job_id)) {
  8907. ShowError("pc_readdb_job_basehpsp: Invalid job class %d specified.\n", job_id);
  8908. return false;
  8909. }
  8910. idx = pc_class2idx(job_id);
  8911. if (startlvl > job_info[idx].max_level[0]) {
  8912. ShowError("pc_readdb_job_basehpsp: Invalid start level %d specified.\n", startlvl);
  8913. return false;
  8914. }
  8915. //Just read until available max level for this job, don't use MAX_LEVEL!
  8916. use_endlvl = endlvl;
  8917. if (use_endlvl > job_info[idx].max_level[0])
  8918. use_endlvl = job_info[idx].max_level[0];
  8919. if(type == 0) { //hp type
  8920. uint16 j;
  8921. for(j = 0; j < use_endlvl; j++) {
  8922. if (atoi(fields[j+4])) {
  8923. uint16 lvl_idx = startlvl-1+j;
  8924. job_info[idx].base_hp[lvl_idx] = atoi(fields[j+4]);
  8925. //Tells if this HP is lower than previous level
  8926. if (lvl_idx-1 >= 0 && job_info[idx].base_hp[lvl_idx] < job_info[idx].base_hp[lvl_idx-1])
  8927. 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",
  8928. current,j+4,job_id,lvl_idx+1,job_info[idx].base_hp[lvl_idx-1],job_info[idx].base_hp[lvl_idx]);
  8929. }
  8930. }
  8931. }
  8932. else { //sp type
  8933. uint16 j;
  8934. for(j = 0; j < use_endlvl; j++) {
  8935. if (atoi(fields[j+4])) {
  8936. uint16 lvl_idx = startlvl-1+j;
  8937. job_info[idx].base_sp[lvl_idx] = atoi(fields[j+4]);
  8938. //Tells if this SP is lower than previous level
  8939. if (lvl_idx-1 >= 0 && job_info[idx].base_sp[lvl_idx] < job_info[idx].base_sp[lvl_idx-1])
  8940. 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",
  8941. current,j+4,job_id,lvl_idx+1,job_info[idx].base_sp[lvl_idx-1],job_info[idx].base_sp[lvl_idx]);
  8942. }
  8943. }
  8944. }
  8945. }
  8946. return true;
  8947. }
  8948. #endif
  8949. /** [Cydh]
  8950. * Reads 'job_param_db.txt' to check max. param each job and store them to job_info[].max_param.*
  8951. */
  8952. static bool pc_readdb_job_param(char* fields[], int columns, int current)
  8953. {
  8954. int idx, class_;
  8955. uint16 str, agi, vit, int_, dex, luk;
  8956. script_get_constant(trim(fields[0]),&class_);
  8957. if ((idx = pc_class2idx(class_)) < 0) {
  8958. ShowError("pc_readdb_job_param: Invalid job '%s'. Skipping!",fields[0]);
  8959. return false;
  8960. }
  8961. str = cap_value(atoi(fields[1]),10,SHRT_MAX);
  8962. agi = atoi(fields[2]) ? cap_value(atoi(fields[2]),10,SHRT_MAX) : str;
  8963. vit = atoi(fields[3]) ? cap_value(atoi(fields[3]),10,SHRT_MAX) : str;
  8964. int_ = atoi(fields[4]) ? cap_value(atoi(fields[4]),10,SHRT_MAX) : str;
  8965. dex = atoi(fields[5]) ? cap_value(atoi(fields[5]),10,SHRT_MAX) : str;
  8966. luk = atoi(fields[6]) ? cap_value(atoi(fields[6]),10,SHRT_MAX) : str;
  8967. job_info[idx].max_param.str = str;
  8968. job_info[idx].max_param.agi = agi;
  8969. job_info[idx].max_param.vit = vit;
  8970. job_info[idx].max_param.int_ = int_;
  8971. job_info[idx].max_param.dex = dex;
  8972. job_info[idx].max_param.luk = luk;
  8973. return true;
  8974. }
  8975. static int pc_read_statsdb(const char *basedir, int last_s, bool silent){
  8976. int i=1;
  8977. char line[24000]; //FIXME this seem too big
  8978. FILE *fp;
  8979. sprintf(line, "%s/statpoint.txt", basedir);
  8980. fp=fopen(line,"r");
  8981. if(fp == NULL){
  8982. if(silent==0) ShowWarning("Can't read '"CL_WHITE"%s"CL_RESET"'... Generating DB.\n",line);
  8983. return -1;
  8984. } else {
  8985. int entries=0;
  8986. while(fgets(line, sizeof(line), fp))
  8987. {
  8988. int stat;
  8989. trim(line);
  8990. if(line[0] == '\0' || (line[0]=='/' && line[1]=='/'))
  8991. continue;
  8992. if ((stat=strtoul(line,NULL,10))<0)
  8993. stat=0;
  8994. if (i > MAX_LEVEL)
  8995. break;
  8996. statp[i]=stat;
  8997. i++;
  8998. entries++;
  8999. }
  9000. fclose(fp);
  9001. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s/%s"CL_RESET"'.\n", entries, basedir,"statpoint.txt");
  9002. }
  9003. return max(last_s,i);
  9004. }
  9005. /*==========================================
  9006. * pc DB reading.
  9007. * job_exp.txt - required experience values
  9008. * skill_tree.txt - skill tree for every class
  9009. * attr_fix.txt - elemental adjustment table
  9010. * job_db1.txt - job,weight,hp_factor,hp_multiplicator,sp_factor,aspds/lvl
  9011. * job_db2.txt - job,stats bonuses/lvl
  9012. * job_maxhpsp_db.txt - strtlvl,maxlvl,job,type,values/lvl (values=hp|sp)
  9013. *------------------------------------------*/
  9014. int pc_readdb(void)
  9015. {
  9016. int i, k, s = 1;
  9017. const char* dbsubpath[] = {
  9018. "",
  9019. "import"
  9020. //add other path here
  9021. };
  9022. //reset
  9023. memset(job_info,0,sizeof(job_info)); // job_info table
  9024. // Reset and read skilltree
  9025. memset(skill_tree,0,sizeof(skill_tree));
  9026. 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);
  9027. 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);
  9028. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  9029. sv_readdb(db_path, "re/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty, 0);
  9030. sv_readdb(db_path, "import/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty, 1);
  9031. for( k=1; k < 3; k++ ){ // fill in the blanks
  9032. int j;
  9033. for( j = 0; j < CLASS_ALL; j++ ){
  9034. int tmp = 0;
  9035. for( i = 0; i < MAX_LEVEL*2; i++ ){
  9036. if( i == MAX_LEVEL+1 )
  9037. tmp = level_penalty[k][j][0];// reset
  9038. if( level_penalty[k][j][i] > 0 )
  9039. tmp = level_penalty[k][j][i];
  9040. else
  9041. level_penalty[k][j][i] = tmp;
  9042. }
  9043. }
  9044. }
  9045. #endif
  9046. // reset then read statspoint
  9047. memset(statp,0,sizeof(statp));
  9048. for(i=0; i<ARRAYLENGTH(dbsubpath); i++){
  9049. int n1 = strlen(db_path)+strlen(dbsubpath[i])+1;
  9050. int n2 = strlen(db_path)+strlen(DBPATH)+strlen(dbsubpath[i])+1;
  9051. char* dbsubpath1 = aMalloc(n1+1);
  9052. char* dbsubpath2 = aMalloc(n2+1);
  9053. safesnprintf(dbsubpath1,n1+1,"%s/%s",db_path,dbsubpath[i]);
  9054. if(i==0) safesnprintf(dbsubpath2,n2,"%s/%s%s",db_path,DBPATH,dbsubpath[i]);
  9055. else safesnprintf(dbsubpath2,n2,"%s/%s",db_path,dbsubpath[i]);
  9056. s = pc_read_statsdb(dbsubpath2,s,i);
  9057. #ifdef RENEWAL_ASPD
  9058. sv_readdb(dbsubpath1, "re/job_db1.txt",',',6+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
  9059. #else
  9060. sv_readdb(dbsubpath1, "pre-re/job_db1.txt",',',5+MAX_WEAPON_TYPE,5+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
  9061. #endif
  9062. sv_readdb(dbsubpath1, "job_db2.txt",',',1,1+MAX_LEVEL,CLASS_COUNT,&pc_readdb_job2, i);
  9063. sv_readdb(dbsubpath2, "job_exp.txt",',',4,1000+3,CLASS_COUNT*2,&pc_readdb_job_exp, i); //support till 1000lvl
  9064. #ifdef HP_SP_TABLES
  9065. sv_readdb(dbsubpath2, "job_basehpsp_db.txt", ',', 4, 4+500, CLASS_COUNT*2, &pc_readdb_job_basehpsp, i); //Make it support until lvl 500!
  9066. #endif
  9067. sv_readdb(dbsubpath2, "job_param_db.txt", ',', 2, PARAM_MAX+1, CLASS_COUNT, &pc_readdb_job_param, i);
  9068. aFree(dbsubpath1);
  9069. aFree(dbsubpath2);
  9070. }
  9071. // generate the remaining parts of the db if necessary
  9072. k = battle_config.use_statpoint_table; //save setting
  9073. battle_config.use_statpoint_table = 0; //temporarily disable to force pc_gets_status_point use default values
  9074. statp[0] = 45; // seed value
  9075. for (; s <= MAX_LEVEL; s++)
  9076. statp[s] = statp[s-1] + pc_gets_status_point(s-1);
  9077. battle_config.use_statpoint_table = k; //restore setting
  9078. //Checking if all class have their data
  9079. for (i = 0; i < JOB_MAX; i++) {
  9080. int idx;
  9081. if (!pcdb_checkid(i)) continue;
  9082. if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER || i == JOB_HANBOK || i == JOB_OKTOBERFEST)
  9083. continue; //Classes that do not need exp tables.
  9084. idx = pc_class2idx(i);
  9085. if (!job_info[idx].max_level[0])
  9086. ShowWarning("Class %s (%d) does not have a base exp table.\n", job_name(i), i);
  9087. if (!job_info[idx].max_level[1])
  9088. ShowWarning("Class %s (%d) does not have a job exp table.\n", job_name(i), i);
  9089. }
  9090. return 0;
  9091. }
  9092. // Read MOTD on startup. [Valaris]
  9093. int pc_read_motd(void)
  9094. {
  9095. FILE* fp;
  9096. // clear old MOTD
  9097. memset(motd_text, 0, sizeof(motd_text));
  9098. // read current MOTD
  9099. if( ( fp = fopen(motd_txt, "r") ) != NULL )
  9100. {
  9101. unsigned int entries = 0;
  9102. while( entries < MOTD_LINE_SIZE && fgets(motd_text[entries], sizeof(motd_text[entries]), fp) )
  9103. {
  9104. char* buf = motd_text[entries];
  9105. unsigned int lines = 0;
  9106. size_t len;
  9107. lines++;
  9108. if( buf[0] == '/' && buf[1] == '/' )
  9109. continue;
  9110. len = strlen(buf);
  9111. while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) ) // strip trailing EOL characters
  9112. len--;
  9113. if( len ) {
  9114. char * ptr;
  9115. buf[len] = 0;
  9116. if( ( ptr = strstr(buf, " :") ) != NULL && ptr-buf >= NAME_LENGTH ) // crashes newer clients
  9117. 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);
  9118. }
  9119. else {// empty line
  9120. buf[0] = ' ';
  9121. buf[1] = 0;
  9122. }
  9123. entries++;
  9124. }
  9125. fclose(fp);
  9126. ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, motd_txt);
  9127. }
  9128. else
  9129. ShowWarning("File '"CL_WHITE"%s"CL_RESET"' not found.\n", motd_txt);
  9130. return 0;
  9131. }
  9132. void pc_itemcd_do(struct map_session_data *sd, bool load) {
  9133. int i,cursor = 0;
  9134. struct item_cd* cd = NULL;
  9135. if( load ) {
  9136. if( !(cd = idb_get(itemcd_db, sd->status.char_id)) ) {
  9137. // no skill cooldown is associated with this character
  9138. return;
  9139. }
  9140. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  9141. if( cd->nameid[i] && DIFF_TICK(gettick(),cd->tick[i]) < 0 ) {
  9142. sd->item_delay[cursor].tick = cd->tick[i];
  9143. sd->item_delay[cursor].nameid = cd->nameid[i];
  9144. cursor++;
  9145. }
  9146. }
  9147. idb_remove(itemcd_db,sd->status.char_id);
  9148. } else {
  9149. if( !(cd = idb_get(itemcd_db,sd->status.char_id)) ) {
  9150. // create a new skill cooldown object for map storage
  9151. CREATE( cd, struct item_cd, 1 );
  9152. idb_put( itemcd_db, sd->status.char_id, cd );
  9153. }
  9154. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  9155. if( sd->item_delay[i].nameid && DIFF_TICK(gettick(),sd->item_delay[i].tick) < 0 ) {
  9156. cd->tick[cursor] = sd->item_delay[i].tick;
  9157. cd->nameid[cursor] = sd->item_delay[i].nameid;
  9158. cursor++;
  9159. }
  9160. }
  9161. }
  9162. return;
  9163. }
  9164. /**
  9165. * Clear the dmglog data from player
  9166. * @param sd
  9167. * @param md
  9168. **/
  9169. static void pc_clear_log_damage_sub(int char_id, struct mob_data *md)
  9170. {
  9171. uint8 i;
  9172. ARR_FIND(0,DAMAGELOG_SIZE,i,md->dmglog[i].id == char_id);
  9173. if (i < DAMAGELOG_SIZE) {
  9174. md->dmglog[i].id=0;
  9175. md->dmglog[i].dmg=0;
  9176. md->dmglog[i].flag=0;
  9177. }
  9178. }
  9179. /**
  9180. * Add log to player's dmglog
  9181. * @param sd
  9182. * @param id Monster's GID
  9183. **/
  9184. void pc_damage_log_add(struct map_session_data *sd, int id)
  9185. {
  9186. uint8 i = 0;
  9187. if (!sd)
  9188. return;
  9189. //Only store new data, don't need to renew the old one with same id
  9190. for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
  9191. if (sd->dmglog[i] == id)
  9192. return;
  9193. sd->dmglog[i] = id;
  9194. return;
  9195. }
  9196. }
  9197. /**
  9198. * Clear dmglog data from player
  9199. * @param sd
  9200. * @param id Monster's id
  9201. **/
  9202. void pc_damage_log_clear(struct map_session_data *sd, int id)
  9203. {
  9204. uint8 i;
  9205. struct mob_data *md = NULL;
  9206. if (!sd)
  9207. return;
  9208. if (!id) {
  9209. for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
  9210. if( !sd->dmglog[i] ) //skip the empty value
  9211. continue;
  9212. if ((md = map_id2md(sd->dmglog[i])))
  9213. pc_clear_log_damage_sub(sd->status.char_id,md);
  9214. sd->dmglog[i] = 0;
  9215. }
  9216. }
  9217. else {
  9218. if ((md = map_id2md(id)))
  9219. pc_clear_log_damage_sub(sd->status.char_id,md);
  9220. ARR_FIND(0,DAMAGELOG_SIZE_PC,i,sd->dmglog[i] == id); // find the id position
  9221. if (i < DAMAGELOG_SIZE_PC)
  9222. sd->dmglog[i] = 0;
  9223. }
  9224. }
  9225. /**
  9226. * Deposit some money to bank
  9227. * @param sd
  9228. * @param money Amount of money to deposit
  9229. **/
  9230. enum e_BANKING_DEPOSIT_ACK pc_bank_deposit(struct map_session_data *sd, int money) {
  9231. unsigned int limit_check = money+sd->status.bank_vault;
  9232. if( money <= 0 || limit_check > MAX_BANK_ZENY ) {
  9233. return BDA_OVERFLOW;
  9234. } else if ( money > sd->status.zeny ) {
  9235. return BDA_NO_MONEY;
  9236. }
  9237. if( pc_payzeny(sd,money, LOG_TYPE_BANK, NULL) )
  9238. return BDA_NO_MONEY;
  9239. sd->status.bank_vault += money;
  9240. if( save_settings&256 )
  9241. chrif_save(sd,0);
  9242. return BDA_SUCCESS;
  9243. }
  9244. /**
  9245. * Withdraw money from bank
  9246. * @param sd
  9247. * @param money Amount of money that will be withdrawn
  9248. **/
  9249. enum e_BANKING_WITHDRAW_ACK pc_bank_withdraw(struct map_session_data *sd, int money) {
  9250. unsigned int limit_check = money+sd->status.zeny;
  9251. if( money <= 0 ) {
  9252. return BWA_UNKNOWN_ERROR;
  9253. } else if ( money > sd->status.bank_vault ) {
  9254. return BWA_NO_MONEY;
  9255. } else if ( limit_check > MAX_ZENY ) {
  9256. /* no official response for this scenario exists. */
  9257. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1495)); //You can't withdraw that much money
  9258. return BWA_UNKNOWN_ERROR;
  9259. }
  9260. if( pc_getzeny(sd,money, LOG_TYPE_BANK, NULL) )
  9261. return BWA_NO_MONEY;
  9262. sd->status.bank_vault -= money;
  9263. if( save_settings&256 )
  9264. chrif_save(sd,0);
  9265. return BWA_SUCCESS;
  9266. }
  9267. /**
  9268. * Clear Cirmson Marker data from caster
  9269. * @param sd: Player
  9270. **/
  9271. void pc_crimson_marker_clear(struct map_session_data *sd) {
  9272. uint8 i;
  9273. if (!sd || !(&sd->c_marker) || !sd->c_marker.target)
  9274. return;
  9275. for (i = 0; i < MAX_SKILL_CRIMSON_MARKER; i++) {
  9276. struct block_list *bl = NULL;
  9277. if (sd->c_marker.target[i] && (bl = map_id2bl(sd->c_marker.target[i])))
  9278. status_change_end(bl,SC_C_MARKER,INVALID_TIMER);
  9279. }
  9280. }
  9281. /**
  9282. * Show version to player
  9283. * @param sd: Player
  9284. **/
  9285. void pc_show_version(struct map_session_data *sd) {
  9286. const char* svn = get_svn_revision();
  9287. char buf[CHAT_SIZE_MAX];
  9288. if( svn[0] != UNKNOWN_VERSION )
  9289. sprintf(buf,msg_txt(sd,1295),"SVN: r",svn); //rAthena Version SVN: r%s
  9290. else {
  9291. const char* git = get_git_hash();
  9292. if( git[0] != UNKNOWN_VERSION )
  9293. sprintf(buf,msg_txt(sd,1295),"Git Hash: ",git); //rAthena Version Git Hash: %s
  9294. else
  9295. sprintf(buf,"%s",msg_txt(sd,1296)); //Cannot determine SVN/Git version.
  9296. }
  9297. clif_displaymessage(sd->fd,buf);
  9298. }
  9299. /** [Cydh]
  9300. * Timer for bonus_script
  9301. * @param tid
  9302. * @param tick
  9303. * @param id
  9304. * @param data
  9305. **/
  9306. int pc_bonus_script_timer(int tid, unsigned int tick, int id, intptr_t data) {
  9307. uint8 i = (uint8)data;
  9308. struct map_session_data *sd;
  9309. sd = map_id2sd(id);
  9310. if (!sd) {
  9311. ShowDebug("pc_bonus_script_timer: Null pointer id: %d data: %d\n",id,data);
  9312. return 0;
  9313. }
  9314. if (i > MAX_PC_BONUS_SCRIPT|| !(&sd->bonus_script[i]) || !sd->bonus_script[i].script) {
  9315. ShowDebug("pc_bonus_script_timer: Invalid index %d\n",i);
  9316. return 0;
  9317. }
  9318. pc_bonus_script_remove(sd,i);
  9319. status_calc_pc(sd,false);
  9320. return 0;
  9321. }
  9322. /** [Cydh]
  9323. * Remove bonus_script data from sd (not deleting timer)
  9324. * @param sd: Target player
  9325. * @param i: Bonus script index
  9326. **/
  9327. void pc_bonus_script_remove(struct map_session_data *sd, uint8 i) {
  9328. if (!sd || i >= MAX_PC_BONUS_SCRIPT)
  9329. return;
  9330. script_free_code(sd->bonus_script[i].script);
  9331. memset(&sd->bonus_script[i].script,0,sizeof(sd->bonus_script[i].script));
  9332. sd->bonus_script[i].script_str[0] = '\0';
  9333. sd->bonus_script[i].tick = 0;
  9334. sd->bonus_script[i].tid = 0;
  9335. sd->bonus_script[i].flag = 0;
  9336. clif_status_change(&sd->bl,sd->bonus_script[i].icon,0,0,0,0,0);
  9337. sd->bonus_script[i].icon = SI_BLANK;
  9338. }
  9339. /** [Cydh]
  9340. * Check then clear all active timer(s) of bonus_script data from player based on reason
  9341. * @param sd: Target player
  9342. * @param flag: Reason to remove the bonus_script. e_bonus_script_flags or e_bonus_script_types
  9343. **/
  9344. void pc_bonus_script_clear(struct map_session_data *sd, uint16 flag) {
  9345. uint8 i, count = 0;
  9346. if (!sd)
  9347. return;
  9348. for (i = 0; i < MAX_PC_BONUS_SCRIPT; i++) {
  9349. if (&sd->bonus_script[i] && sd->bonus_script[i].script &&
  9350. (sd->bonus_script[i].flag&flag || //Remove bonus script based on e_bonus_script_flags
  9351. (sd->bonus_script[i].type && (
  9352. (flag&BONUS_FLAG_REM_BUFF && sd->bonus_script[i].type == 1) || //Remove bonus script based on buff type
  9353. (flag&BONUS_FLAG_REM_DEBUFF && sd->bonus_script[i].type == 2)) //Remove bonus script based on debuff type
  9354. )))
  9355. {
  9356. delete_timer(sd->bonus_script[i].tid,pc_bonus_script_timer);
  9357. pc_bonus_script_remove(sd,i);
  9358. count++;
  9359. }
  9360. }
  9361. if (count && !(flag&BONUS_FLAG_REM_ON_LOGOUT)) //Don't need to do this if log out
  9362. status_calc_pc(sd,false);
  9363. }
  9364. /** [Cydh]
  9365. * Gives/removes SC_BASILICA when player steps in/out the cell with 'cell_basilica'
  9366. * @param sd: Target player
  9367. */
  9368. void pc_cell_basilica(struct map_session_data *sd) {
  9369. nullpo_retv(sd);
  9370. if (!map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKBASILICA)) {
  9371. if (&sd->sc && sd->sc.data[SC_BASILICA])
  9372. status_change_end(&sd->bl,SC_BASILICA,INVALID_TIMER);
  9373. }
  9374. else if (!(&sd->sc) || !sd->sc.data[SC_BASILICA])
  9375. sc_start(&sd->bl,&sd->bl,SC_BASILICA,100,0,-1);
  9376. }
  9377. /** [Cydh]
  9378. * Get maximum specified parameter for specified class
  9379. * @param class_: sd->class
  9380. * @param sex: sd->status.sex
  9381. * @param flag: parameter will be checked
  9382. * @return max_param
  9383. */
  9384. short pc_maxparameter(struct map_session_data *sd, enum e_params param) {
  9385. int idx = -1, class_ = sd->class_;
  9386. if ((idx = pc_class2idx(pc_mapid2jobid(class_,sd->status.sex))) >= 0) {
  9387. short max_param = 0;
  9388. switch (param) {
  9389. case PARAM_STR: max_param = job_info[idx].max_param.str; break;
  9390. case PARAM_AGI: max_param = job_info[idx].max_param.agi; break;
  9391. case PARAM_VIT: max_param = job_info[idx].max_param.vit; break;
  9392. case PARAM_INT: max_param = job_info[idx].max_param.int_; break;
  9393. case PARAM_DEX: max_param = job_info[idx].max_param.dex; break;
  9394. case PARAM_LUK: max_param = job_info[idx].max_param.luk; break;
  9395. }
  9396. if (max_param > 0)
  9397. return max_param;
  9398. }
  9399. return ((class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO || (class_&MAPID_UPPERMASK) == MAPID_REBELLION) ? battle_config.max_extended_parameter :
  9400. ((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)) :
  9401. ((class_&JOBL_BABY) ? battle_config.max_baby_parameter :
  9402. ((class_&JOBL_UPPER) ? battle_config.max_trans_parameter : battle_config.max_parameter)));
  9403. }
  9404. /*==========================================
  9405. * pc Init/Terminate
  9406. *------------------------------------------*/
  9407. void do_final_pc(void) {
  9408. db_destroy(itemcd_db);
  9409. do_final_pc_groups();
  9410. return;
  9411. }
  9412. int do_init_pc(void) {
  9413. itemcd_db = idb_alloc(DB_OPT_RELEASE_DATA);
  9414. pc_readdb();
  9415. pc_read_motd(); // Read MOTD [Valaris]
  9416. add_timer_func_list(pc_invincible_timer, "pc_invincible_timer");
  9417. add_timer_func_list(pc_eventtimer, "pc_eventtimer");
  9418. add_timer_func_list(pc_inventory_rental_end, "pc_inventory_rental_end");
  9419. add_timer_func_list(pc_calc_pvprank_timer, "pc_calc_pvprank_timer");
  9420. add_timer_func_list(pc_autosave, "pc_autosave");
  9421. add_timer_func_list(pc_spiritball_timer, "pc_spiritball_timer");
  9422. add_timer_func_list(pc_follow_timer, "pc_follow_timer");
  9423. add_timer_func_list(pc_endautobonus, "pc_endautobonus");
  9424. add_timer_func_list(pc_talisman_timer, "pc_talisman_timer");
  9425. add_timer(gettick() + autosave_interval, pc_autosave, 0, 0);
  9426. // 0=day, 1=night [Yor]
  9427. night_flag = battle_config.night_at_start ? 1 : 0;
  9428. if (battle_config.day_duration > 0 && battle_config.night_duration > 0) {
  9429. int day_duration = battle_config.day_duration;
  9430. int night_duration = battle_config.night_duration;
  9431. // add night/day timer [Yor]
  9432. add_timer_func_list(map_day_timer, "map_day_timer");
  9433. add_timer_func_list(map_night_timer, "map_night_timer");
  9434. day_timer_tid = add_timer_interval(gettick() + (night_flag ? 0 : day_duration) + night_duration, map_day_timer, 0, 0, day_duration + night_duration);
  9435. night_timer_tid = add_timer_interval(gettick() + day_duration + (night_flag ? night_duration : 0), map_night_timer, 0, 0, day_duration + night_duration);
  9436. }
  9437. do_init_pc_groups();
  9438. return 0;
  9439. }