pc.c 245 KB

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