pc.c 214 KB

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