pc.c 208 KB

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