pc.c 204 KB

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