pc.c 218 KB

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