pc.c 363 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921
  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 "map.h"
  16. #include "battle.h" // battle_config
  17. #include "battleground.h"
  18. #include "channel.h"
  19. #include "chat.h"
  20. #include "chrif.h"
  21. #include "date.h" // is_day_of_*()
  22. #include "duel.h"
  23. #include "intif.h"
  24. #include "homunculus.h"
  25. #include "instance.h"
  26. #include "mercenary.h"
  27. #include "elemental.h"
  28. #include "pet.h" // pet_unlocktarget()
  29. #include "party.h" // party_search()
  30. #include "storage.h"
  31. #include "quest.h"
  32. #include <stdlib.h>
  33. #include <math.h>
  34. int pc_split_atoui(char* str, unsigned int* val, char sep, int max);
  35. #define PVP_CALCRANK_INTERVAL 1000 // PVP calculation interval
  36. static unsigned int statp[MAX_LEVEL+1];
  37. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  38. static unsigned int level_penalty[3][CLASS_MAX][MAX_LEVEL*2+1];
  39. #endif
  40. // h-files are for declarations, not for implementations... [Shinomori]
  41. struct skill_tree_entry skill_tree[CLASS_COUNT][MAX_SKILL_TREE];
  42. // timer for night.day implementation
  43. int day_timer_tid = INVALID_TIMER;
  44. int night_timer_tid = INVALID_TIMER;
  45. struct eri *pc_sc_display_ers = NULL;
  46. struct eri *pc_itemgrouphealrate_ers = NULL;
  47. int pc_expiration_tid = INVALID_TIMER;
  48. struct fame_list smith_fame_list[MAX_FAME_LIST];
  49. struct fame_list chemist_fame_list[MAX_FAME_LIST];
  50. struct fame_list taekwon_fame_list[MAX_FAME_LIST];
  51. static unsigned int equip_pos[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_COSTUME_GARMENT,EQP_AMMO,EQP_SHADOW_ARMOR,EQP_SHADOW_WEAPON,EQP_SHADOW_SHIELD,EQP_SHADOW_SHOES,EQP_SHADOW_ACC_R,EQP_SHADOW_ACC_L};
  52. #define MOTD_LINE_SIZE 128
  53. static char motd_text[MOTD_LINE_SIZE][CHAT_SIZE_MAX]; // Message of the day buffer [Valaris]
  54. //Links related info to the sd->hate_mob[]/sd->feel_map[] entries
  55. const struct sg_data sg_info[MAX_PC_FEELHATE] = {
  56. { SG_SUN_ANGER, SG_SUN_BLESS, SG_SUN_COMFORT, "PC_FEEL_SUN", "PC_HATE_MOB_SUN", is_day_of_sun },
  57. { SG_MOON_ANGER, SG_MOON_BLESS, SG_MOON_COMFORT, "PC_FEEL_MOON", "PC_HATE_MOB_MOON", is_day_of_moon },
  58. { SG_STAR_ANGER, SG_STAR_BLESS, SG_STAR_COMFORT, "PC_FEEL_STAR", "PC_HATE_MOB_STAR", is_day_of_star }
  59. };
  60. /**
  61. * Item Cool Down Delay Saving
  62. * Struct item_cd is not a member of struct map_session_data
  63. * to keep cooldowns in memory between player log-ins.
  64. * All cooldowns are reset when server is restarted.
  65. **/
  66. DBMap* itemcd_db = NULL; // char_id -> struct item_cd
  67. struct item_cd {
  68. unsigned int tick[MAX_ITEMDELAYS]; //tick
  69. unsigned short nameid[MAX_ITEMDELAYS]; //item id
  70. };
  71. /**
  72. * Converts a class to its array index for CLASS_COUNT defined arrays.
  73. * Note that it does not do a validity check for speed purposes, where parsing
  74. * player input make sure to use a pcdb_checkid first!
  75. * @param class_
  76. * @return Class Index
  77. */
  78. int pc_class2idx(int class_) {
  79. if (class_ >= JOB_NOVICE_HIGH)
  80. return class_- JOB_NOVICE_HIGH+JOB_MAX_BASIC;
  81. return class_;
  82. }
  83. /**
  84. * Get player's group ID
  85. * @param sd
  86. * @return Group ID
  87. */
  88. inline int pc_get_group_id(struct map_session_data *sd) {
  89. return sd->group_id;
  90. }
  91. /** Get player's group Level
  92. * @param sd
  93. * @return Group Level
  94. */
  95. inline int pc_get_group_level(struct map_session_data *sd) {
  96. return sd->group_level;
  97. }
  98. static int pc_invincible_timer(int tid, unsigned int tick, int id, intptr_t data)
  99. {
  100. struct map_session_data *sd;
  101. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  102. return 1;
  103. if(sd->invincible_timer != tid){
  104. ShowError("invincible_timer %d != %d\n",sd->invincible_timer,tid);
  105. return 0;
  106. }
  107. sd->invincible_timer = INVALID_TIMER;
  108. skill_unit_move(&sd->bl,tick,1);
  109. return 0;
  110. }
  111. void pc_setinvincibletimer(struct map_session_data* sd, int val) {
  112. nullpo_retv(sd);
  113. if( sd->invincible_timer != INVALID_TIMER )
  114. delete_timer(sd->invincible_timer,pc_invincible_timer);
  115. sd->invincible_timer = add_timer(gettick()+val,pc_invincible_timer,sd->bl.id,0);
  116. }
  117. void pc_delinvincibletimer(struct map_session_data* sd)
  118. {
  119. nullpo_retv(sd);
  120. if( sd->invincible_timer != INVALID_TIMER )
  121. {
  122. delete_timer(sd->invincible_timer,pc_invincible_timer);
  123. sd->invincible_timer = INVALID_TIMER;
  124. skill_unit_move(&sd->bl,gettick(),1);
  125. }
  126. }
  127. static int pc_spiritball_timer(int tid, unsigned int tick, int id, intptr_t data)
  128. {
  129. struct map_session_data *sd;
  130. int i;
  131. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  132. return 1;
  133. if( sd->spiritball <= 0 )
  134. {
  135. 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);
  136. sd->spiritball = 0;
  137. return 0;
  138. }
  139. ARR_FIND(0, sd->spiritball, i, sd->spirit_timer[i] == tid);
  140. if( i == sd->spiritball )
  141. {
  142. ShowError("pc_spiritball_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
  143. return 0;
  144. }
  145. sd->spiritball--;
  146. if( i != sd->spiritball )
  147. memmove(sd->spirit_timer+i, sd->spirit_timer+i+1, (sd->spiritball-i)*sizeof(int));
  148. sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
  149. clif_spiritball(&sd->bl);
  150. return 0;
  151. }
  152. /**
  153. * Adds a spiritball to player for 'interval' ms
  154. * @param sd
  155. * @param interval
  156. * @param max
  157. */
  158. void pc_addspiritball(struct map_session_data *sd,int interval,int max)
  159. {
  160. int tid;
  161. uint8 i;
  162. nullpo_retv(sd);
  163. if(max > MAX_SPIRITBALL)
  164. max = MAX_SPIRITBALL;
  165. if(sd->spiritball < 0)
  166. sd->spiritball = 0;
  167. if( sd->spiritball && sd->spiritball >= max )
  168. {
  169. if(sd->spirit_timer[0] != INVALID_TIMER)
  170. delete_timer(sd->spirit_timer[0],pc_spiritball_timer);
  171. sd->spiritball--;
  172. if( sd->spiritball != 0 )
  173. memmove(sd->spirit_timer+0, sd->spirit_timer+1, (sd->spiritball)*sizeof(int));
  174. sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
  175. }
  176. tid = add_timer(gettick()+interval, pc_spiritball_timer, sd->bl.id, 0);
  177. 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);
  178. if( i != sd->spiritball )
  179. memmove(sd->spirit_timer+i+1, sd->spirit_timer+i, (sd->spiritball-i)*sizeof(int));
  180. sd->spirit_timer[i] = tid;
  181. sd->spiritball++;
  182. if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
  183. clif_millenniumshield(&sd->bl,sd->spiritball);
  184. else
  185. clif_spiritball(&sd->bl);
  186. }
  187. /**
  188. * Removes number of spiritball from player
  189. * @param sd
  190. * @param count
  191. * @param type 1 = doesn't give client effect
  192. */
  193. void pc_delspiritball(struct map_session_data *sd,int count,int type)
  194. {
  195. uint8 i;
  196. nullpo_retv(sd);
  197. if(sd->spiritball <= 0) {
  198. sd->spiritball = 0;
  199. return;
  200. }
  201. if(count == 0)
  202. return;
  203. if(count > sd->spiritball)
  204. count = sd->spiritball;
  205. sd->spiritball -= count;
  206. if(count > MAX_SPIRITBALL)
  207. count = MAX_SPIRITBALL;
  208. for(i=0;i<count;i++) {
  209. if(sd->spirit_timer[i] != INVALID_TIMER) {
  210. delete_timer(sd->spirit_timer[i],pc_spiritball_timer);
  211. sd->spirit_timer[i] = INVALID_TIMER;
  212. }
  213. }
  214. for(i=count;i<MAX_SPIRITBALL;i++) {
  215. sd->spirit_timer[i-count] = sd->spirit_timer[i];
  216. sd->spirit_timer[i] = INVALID_TIMER;
  217. }
  218. if(!type) {
  219. if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
  220. clif_millenniumshield(&sd->bl,sd->spiritball);
  221. else
  222. clif_spiritball(&sd->bl);
  223. }
  224. }
  225. static int pc_check_banding( struct block_list *bl, va_list ap ) {
  226. int *c, *b_sd;
  227. struct block_list *src;
  228. struct map_session_data *tsd;
  229. struct status_change *sc;
  230. nullpo_ret(bl);
  231. nullpo_ret(tsd = (struct map_session_data*)bl);
  232. nullpo_ret(src = va_arg(ap,struct block_list *));
  233. c = va_arg(ap,int *);
  234. b_sd = va_arg(ap, int *);
  235. if(pc_isdead(tsd))
  236. return 0;
  237. sc = status_get_sc(bl);
  238. if( bl == src )
  239. return 0;
  240. if( sc && sc->data[SC_BANDING] )
  241. {
  242. b_sd[(*c)++] = tsd->bl.id;
  243. return 1;
  244. }
  245. return 0;
  246. }
  247. int pc_banding(struct map_session_data *sd, uint16 skill_lv) {
  248. int c;
  249. int b_sd[MAX_PARTY]; // In case of a full Royal Guard party.
  250. int i, j, hp, extra_hp = 0, tmp_qty = 0;
  251. int range = skill_get_splash(LG_BANDING,skill_lv);
  252. nullpo_ret(sd);
  253. c = 0;
  254. memset(b_sd, 0, sizeof(b_sd));
  255. i = party_foreachsamemap(pc_check_banding,sd,range,&sd->bl,&c,&b_sd);
  256. if( c < 1 ) //just recalc status no need to recalc hp
  257. { // No more Royal Guards in Banding found.
  258. struct status_change *sc;
  259. if( (sc = status_get_sc(&sd->bl)) != NULL && sc->data[SC_BANDING] )
  260. {
  261. sc->data[SC_BANDING]->val2 = 0; // Reset the counter
  262. status_calc_bl(&sd->bl, status_sc2scb_flag(SC_BANDING));
  263. }
  264. return 0;
  265. }
  266. //Add yourself
  267. hp = status_get_hp(&sd->bl);
  268. i++;
  269. // Get total HP of all Royal Guards in party.
  270. for( j = 0; j < i; j++ ){
  271. struct map_session_data *bsd = map_id2sd(b_sd[j]);
  272. if( bsd != NULL )
  273. hp += status_get_hp(&bsd->bl);
  274. }
  275. // Set average HP.
  276. hp = hp / i;
  277. // If a Royal Guard have full HP, give more HP to others that haven't full HP.
  278. for( j = 0; j < i; j++ )
  279. {
  280. int tmp_hp=0;
  281. struct map_session_data *bsd = map_id2sd(b_sd[j]);
  282. if( bsd != NULL && (tmp_hp = hp - status_get_max_hp(&bsd->bl)) > 0 ){
  283. extra_hp += tmp_hp;
  284. tmp_qty++;
  285. }
  286. }
  287. if( extra_hp > 0 && tmp_qty > 0 )
  288. hp += extra_hp / tmp_qty;
  289. for( j = 0; j < i; j++ ){
  290. struct map_session_data *bsd = map_id2sd(b_sd[j]);
  291. if( bsd != NULL )
  292. {
  293. struct status_change *sc;
  294. status_set_hp(&bsd->bl,hp,0); // Set hp
  295. if( (sc = status_get_sc(&bsd->bl)) != NULL && sc->data[SC_BANDING] )
  296. {
  297. sc->data[SC_BANDING]->val2 = c; // Set the counter. It doesn't count your self.
  298. status_calc_bl(&bsd->bl, status_sc2scb_flag(SC_BANDING)); // Set atk and def.
  299. }
  300. }
  301. }
  302. return c;
  303. }
  304. /**
  305. * Increases a player's fame points and displays a notice to him
  306. * @param sd Player
  307. * @param count Fame point
  308. */
  309. void pc_addfame(struct map_session_data *sd,int count)
  310. {
  311. int ranktype=-1;
  312. nullpo_retv(sd);
  313. sd->status.fame += count;
  314. if(sd->status.fame > MAX_FAME)
  315. sd->status.fame = MAX_FAME;
  316. switch(sd->class_&MAPID_UPPERMASK){
  317. case MAPID_BLACKSMITH: ranktype = 0; break;
  318. case MAPID_ALCHEMIST: ranktype = 1; break;
  319. case MAPID_TAEKWON: ranktype = 2; break;
  320. }
  321. clif_update_rankingpoint(sd,ranktype,count);
  322. chrif_updatefamelist(sd);
  323. }
  324. /**
  325. * Check whether a player ID is in the fame rankers list of its job, returns his/her position if so, 0 else
  326. * @param sd
  327. * @param job Job use enum e_mapid
  328. * @return Rank
  329. */
  330. unsigned char pc_famerank(uint32 char_id, int job)
  331. {
  332. uint8 i;
  333. switch(job){
  334. case MAPID_BLACKSMITH: // Blacksmith
  335. for(i = 0; i < MAX_FAME_LIST; i++){
  336. if(smith_fame_list[i].id == char_id)
  337. return i + 1;
  338. }
  339. break;
  340. case MAPID_ALCHEMIST: // Alchemist
  341. for(i = 0; i < MAX_FAME_LIST; i++){
  342. if(chemist_fame_list[i].id == char_id)
  343. return i + 1;
  344. }
  345. break;
  346. case MAPID_TAEKWON: // Taekwon
  347. for(i = 0; i < MAX_FAME_LIST; i++){
  348. if(taekwon_fame_list[i].id == char_id)
  349. return i + 1;
  350. }
  351. break;
  352. }
  353. return 0;
  354. }
  355. /**
  356. * Restart player's HP & SP value
  357. * @param sd
  358. * @param type Restart type: 1 - Normal Resurection
  359. */
  360. void pc_setrestartvalue(struct map_session_data *sd, char type) {
  361. struct status_data *status, *b_status;
  362. nullpo_retv(sd);
  363. b_status = &sd->base_status;
  364. status = &sd->battle_status;
  365. if (type&1) { //Normal resurrection
  366. status->hp = 1; //Otherwise status_heal may fail if dead.
  367. status_heal(&sd->bl, b_status->hp, 0, 1);
  368. if( status->sp < b_status->sp )
  369. status_set_sp(&sd->bl, b_status->sp, 1);
  370. } else { //Just for saving on the char-server (with values as if respawned)
  371. sd->status.hp = b_status->hp;
  372. sd->status.sp = (status->sp < b_status->sp)?b_status->sp:status->sp;
  373. }
  374. }
  375. /*==========================================
  376. Rental System
  377. *------------------------------------------*/
  378. /** Ends rental */
  379. static int pc_inventory_rental_end(int tid, unsigned int tick, int id, intptr_t data)
  380. {
  381. struct map_session_data *sd = map_id2sd(id);
  382. if( sd == NULL )
  383. return 0;
  384. if( tid != sd->rental_timer ) {
  385. ShowError("pc_inventory_rental_end: invalid timer id.\n");
  386. return 0;
  387. }
  388. pc_inventory_rentals(sd);
  389. return 1;
  390. }
  391. void pc_inventory_rental_clear(struct map_session_data *sd)
  392. {
  393. if( sd->rental_timer != INVALID_TIMER ) {
  394. delete_timer(sd->rental_timer, pc_inventory_rental_end);
  395. sd->rental_timer = INVALID_TIMER;
  396. }
  397. }
  398. /** Assumes I is valid (from default areas where it is called, it is) */
  399. void pc_rental_expire(struct map_session_data *sd, int i)
  400. {
  401. unsigned short nameid = sd->status.inventory[i].nameid;
  402. /* Soon to be dropped, we got plans to integrate it with item db */
  403. switch( nameid ) {
  404. case ITEMID_REINS_OF_MOUNT:
  405. if( &sd->sc && sd->sc.data[SC_ALL_RIDING] )
  406. status_change_end(&sd->bl, SC_ALL_RIDING, INVALID_TIMER);
  407. break;
  408. case ITEMID_LOVE_ANGEL:
  409. if( sd->status.font == 1 ) {
  410. sd->status.font = 0;
  411. clif_font(sd);
  412. }
  413. break;
  414. case ITEMID_SQUIRREL:
  415. if( sd->status.font == 2 ) {
  416. sd->status.font = 0;
  417. clif_font(sd);
  418. }
  419. break;
  420. case ITEMID_GOGO:
  421. if( sd->status.font == 3 ) {
  422. sd->status.font = 0;
  423. clif_font(sd);
  424. }
  425. break;
  426. case ITEMID_PICTURE_DIARY:
  427. if( sd->status.font == 4 ) {
  428. sd->status.font = 0;
  429. clif_font(sd);
  430. }
  431. break;
  432. case ITEMID_MINI_HEART:
  433. if( sd->status.font == 5 ) {
  434. sd->status.font = 0;
  435. clif_font(sd);
  436. }
  437. break;
  438. case ITEMID_NEWCOMER:
  439. if( sd->status.font == 6 ) {
  440. sd->status.font = 0;
  441. clif_font(sd);
  442. }
  443. break;
  444. case ITEMID_KID:
  445. if( sd->status.font == 7 ) {
  446. sd->status.font = 0;
  447. clif_font(sd);
  448. }
  449. break;
  450. case ITEMID_MAGIC_CASTLE:
  451. if( sd->status.font == 8 ) {
  452. sd->status.font = 0;
  453. clif_font(sd);
  454. }
  455. break;
  456. case ITEMID_BULGING_HEAD:
  457. if( sd->status.font == 9 ) {
  458. sd->status.font = 0;
  459. clif_font(sd);
  460. }
  461. break;
  462. }
  463. // Remove visuals effect from headgear
  464. if( &sd->sc && sd->sc.data[SC_MOONSTAR] )
  465. status_change_end(&sd->bl, SC_MOONSTAR, INVALID_TIMER);
  466. if( &sd->sc && sd->sc.data[SC_SUPER_STAR] )
  467. status_change_end(&sd->bl, SC_SUPER_STAR, INVALID_TIMER);
  468. if( &sd->sc && sd->sc.data[SC_DECORATION_OF_MUSIC] )
  469. status_change_end(&sd->bl, SC_DECORATION_OF_MUSIC, INVALID_TIMER);
  470. if( &sd->sc && sd->sc.data[SC_STRANGELIGHTS] )
  471. status_change_end(&sd->bl, SC_STRANGELIGHTS, INVALID_TIMER);
  472. clif_rental_expired(sd->fd, i, sd->status.inventory[i].nameid);
  473. pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
  474. }
  475. void pc_inventory_rentals(struct map_session_data *sd)
  476. {
  477. int i, c = 0;
  478. unsigned int expire_tick, next_tick = UINT_MAX;
  479. for( i = 0; i < MAX_INVENTORY; i++ ) { // Check for Rentals on Inventory
  480. if( sd->status.inventory[i].nameid == 0 )
  481. continue; // Nothing here
  482. if( sd->status.inventory[i].expire_time == 0 )
  483. continue;
  484. if( sd->status.inventory[i].expire_time <= time(NULL) )
  485. pc_rental_expire(sd, i);
  486. else {
  487. expire_tick = (unsigned int)(sd->status.inventory[i].expire_time - time(NULL)) * 1000;
  488. clif_rental_time(sd->fd, sd->status.inventory[i].nameid, (int)(expire_tick / 1000));
  489. next_tick = umin(expire_tick, next_tick);
  490. c++;
  491. }
  492. }
  493. 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
  494. sd->rental_timer = add_timer(gettick() + umin(next_tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
  495. else
  496. sd->rental_timer = INVALID_TIMER;
  497. }
  498. void pc_inventory_rental_add(struct map_session_data *sd, unsigned int seconds)
  499. {
  500. unsigned int tick = seconds * 1000;
  501. if( sd == NULL )
  502. return;
  503. if( sd->rental_timer != INVALID_TIMER ) {
  504. const struct TimerData * td;
  505. td = get_timer(sd->rental_timer);
  506. if( DIFF_TICK(td->tick, gettick()) > tick ) { // Update Timer as this one ends first than the current one
  507. pc_inventory_rental_clear(sd);
  508. sd->rental_timer = add_timer(gettick() + tick, pc_inventory_rental_end, sd->bl.id, 0);
  509. }
  510. } else
  511. sd->rental_timer = add_timer(gettick() + umin(tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
  512. }
  513. /**
  514. * Determines if player can give / drop / trade / vend items
  515. */
  516. bool pc_can_give_items(struct map_session_data *sd)
  517. {
  518. return pc_has_permission(sd, PC_PERM_TRADE);
  519. }
  520. /**
  521. * Determines if player can give / drop / trade / vend bounded items
  522. */
  523. bool pc_can_give_bounded_items(struct map_session_data *sd)
  524. {
  525. return pc_has_permission(sd, PC_PERM_TRADE_BOUNDED);
  526. }
  527. /*==========================================
  528. * Prepares character for saving.
  529. * @param sd
  530. *------------------------------------------*/
  531. void pc_makesavestatus(struct map_session_data *sd) {
  532. nullpo_retv(sd);
  533. if(!battle_config.save_clothcolor)
  534. sd->status.clothes_color = 0;
  535. // Since this is currently not officially released,
  536. // its best to have a forced option to not save body styles.
  537. if(!battle_config.save_body_style)
  538. sd->status.body = 0;
  539. //Only copy the Cart/Peco/Falcon options, the rest are handled via
  540. //status change load/saving. [Skotlex]
  541. #ifdef NEW_CARTS
  542. sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
  543. #else
  544. sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_CART|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
  545. #endif
  546. if (sd->sc.data[SC_JAILED]) { //When Jailed, do not move last point.
  547. if(pc_isdead(sd)){
  548. pc_setrestartvalue(sd, 0);
  549. } else {
  550. sd->status.hp = sd->battle_status.hp;
  551. sd->status.sp = sd->battle_status.sp;
  552. }
  553. sd->status.last_point.map = sd->mapindex;
  554. sd->status.last_point.x = sd->bl.x;
  555. sd->status.last_point.y = sd->bl.y;
  556. return;
  557. }
  558. if(pc_isdead(sd)) {
  559. pc_setrestartvalue(sd, 0);
  560. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  561. } else {
  562. sd->status.hp = sd->battle_status.hp;
  563. sd->status.sp = sd->battle_status.sp;
  564. sd->status.last_point.map = sd->mapindex;
  565. sd->status.last_point.x = sd->bl.x;
  566. sd->status.last_point.y = sd->bl.y;
  567. }
  568. if(map[sd->bl.m].flag.nosave) {
  569. struct map_data *m=&map[sd->bl.m];
  570. if(m->save.map)
  571. memcpy(&sd->status.last_point,&m->save,sizeof(sd->status.last_point));
  572. else
  573. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  574. }
  575. }
  576. /*==========================================
  577. * Off init ? Connection?
  578. *------------------------------------------*/
  579. void pc_setnewpc(struct map_session_data *sd, uint32 account_id, uint32 char_id, int login_id1, unsigned int client_tick, int sex, int fd) {
  580. nullpo_retv(sd);
  581. sd->bl.id = account_id;
  582. sd->status.account_id = account_id;
  583. sd->status.char_id = char_id;
  584. sd->status.sex = sex;
  585. sd->login_id1 = login_id1;
  586. sd->login_id2 = 0; // at this point, we can not know the value :(
  587. sd->client_tick = client_tick;
  588. sd->state.active = 0; //to be set to 1 after player is fully authed and loaded.
  589. sd->bl.type = BL_PC;
  590. sd->canlog_tick = gettick();
  591. //Required to prevent homunculus copuing a base speed of 0.
  592. sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
  593. }
  594. /**
  595. * Get equip point for an equip
  596. * @param sd
  597. * @param n Equip index in inventory
  598. */
  599. int pc_equippoint(struct map_session_data *sd,int n){
  600. int ep = 0;
  601. nullpo_ret(sd);
  602. if(!sd->inventory_data[n])
  603. return 0;
  604. if (!itemdb_isequip2(sd->inventory_data[n]))
  605. return 0; //Not equippable by players.
  606. ep = sd->inventory_data[n]->equip;
  607. if(sd->inventory_data[n]->look == W_DAGGER ||
  608. sd->inventory_data[n]->look == W_1HSWORD ||
  609. sd->inventory_data[n]->look == W_1HAXE) {
  610. if(ep == EQP_HAND_R && (pc_checkskill(sd,AS_LEFT) > 0 || (sd->class_&MAPID_UPPERMASK) == MAPID_ASSASSIN ||
  611. (sd->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO))//Kagerou and Oboro can dual wield daggers. [Rytech]
  612. return EQP_ARMS;
  613. }
  614. return ep;
  615. }
  616. /**
  617. * Fill inventory_data with struct *item_data through inventory (fill with struct *item)
  618. * @param sd : player session
  619. * @return 0 sucess, 1:invalid sd
  620. */
  621. void pc_setinventorydata(struct map_session_data *sd)
  622. {
  623. uint8 i;
  624. nullpo_retv(sd);
  625. for(i = 0; i < MAX_INVENTORY; i++) {
  626. unsigned short id = sd->status.inventory[i].nameid;
  627. sd->inventory_data[i] = id?itemdb_search(id):NULL;
  628. }
  629. }
  630. /**
  631. * 'Calculates' weapon type
  632. * @param sd : player
  633. */
  634. void pc_calcweapontype(struct map_session_data *sd)
  635. {
  636. nullpo_retv(sd);
  637. // single-hand
  638. if(sd->weapontype2 == W_FIST) {
  639. sd->status.weapon = sd->weapontype1;
  640. return;
  641. }
  642. if(sd->weapontype1 == W_FIST) {
  643. sd->status.weapon = sd->weapontype2;
  644. return;
  645. }
  646. // dual-wield
  647. sd->status.weapon = 0;
  648. switch (sd->weapontype1){
  649. case W_DAGGER:
  650. switch (sd->weapontype2) {
  651. case W_DAGGER: sd->status.weapon = W_DOUBLE_DD; break;
  652. case W_1HSWORD: sd->status.weapon = W_DOUBLE_DS; break;
  653. case W_1HAXE: sd->status.weapon = W_DOUBLE_DA; break;
  654. }
  655. break;
  656. case W_1HSWORD:
  657. switch (sd->weapontype2) {
  658. case W_DAGGER: sd->status.weapon = W_DOUBLE_DS; break;
  659. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SS; break;
  660. case W_1HAXE: sd->status.weapon = W_DOUBLE_SA; break;
  661. }
  662. break;
  663. case W_1HAXE:
  664. switch (sd->weapontype2) {
  665. case W_DAGGER: sd->status.weapon = W_DOUBLE_DA; break;
  666. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SA; break;
  667. case W_1HAXE: sd->status.weapon = W_DOUBLE_AA; break;
  668. }
  669. }
  670. // unknown, default to right hand type
  671. if (!sd->status.weapon)
  672. sd->status.weapon = sd->weapontype1;
  673. }
  674. /**
  675. * Set equip index
  676. * @param sd : Player
  677. */
  678. void pc_setequipindex(struct map_session_data *sd)
  679. {
  680. uint16 i;
  681. nullpo_retv(sd);
  682. for (i = 0; i < EQI_MAX; i++)
  683. sd->equip_index[i] = -1;
  684. for (i = 0; i < MAX_INVENTORY; i++) {
  685. if (sd->status.inventory[i].nameid <= 0)
  686. continue;
  687. if (sd->status.inventory[i].equip) {
  688. uint8 j;
  689. for (j = 0; j < EQI_MAX; j++)
  690. if (sd->status.inventory[i].equip & equip_pos[j])
  691. sd->equip_index[j] = i;
  692. if (sd->status.inventory[i].equip & EQP_HAND_R) {
  693. if (sd->inventory_data[i])
  694. sd->weapontype1 = sd->inventory_data[i]->look;
  695. else
  696. sd->weapontype1 = 0;
  697. }
  698. if( sd->status.inventory[i].equip & EQP_HAND_L ) {
  699. if( sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON )
  700. sd->weapontype2 = sd->inventory_data[i]->look;
  701. else
  702. sd->weapontype2 = 0;
  703. }
  704. }
  705. }
  706. pc_calcweapontype(sd);
  707. }
  708. //static int pc_isAllowedCardOn(struct map_session_data *sd,int s,int eqindex,int flag)
  709. //{
  710. // int i;
  711. // struct item *item = &sd->status.inventory[eqindex];
  712. // struct item_data *data;
  713. //
  714. // //Crafted/made/hatched items.
  715. // if (itemdb_isspecial(item->card[0]))
  716. // return 1;
  717. //
  718. // /* scan for enchant armor gems */
  719. // if( item->card[MAX_SLOTS - 1] && s < MAX_SLOTS - 1 )
  720. // s = MAX_SLOTS - 1;
  721. //
  722. // ARR_FIND( 0, s, i, item->card[i] && (data = itemdb_exists(item->card[i])) != NULL && data->flag.no_equip&flag );
  723. // return( i < s ) ? 0 : 1;
  724. //}
  725. /**
  726. * Check if an item is equiped by player
  727. * (Check if the itemid is equiped then search if that match the index in inventory (should be))
  728. * @param sd : player session
  729. * @param nameid : itemid
  730. * @return 1:yes, 0:no
  731. */
  732. bool pc_isequipped(struct map_session_data *sd, unsigned short nameid)
  733. {
  734. uint8 i;
  735. for( i = 0; i < EQI_MAX; i++ )
  736. {
  737. short index = sd->equip_index[i], j;
  738. if( index < 0 )
  739. continue;
  740. if( pc_is_same_equip_index((enum equip_index)i, sd->equip_index, index) )
  741. continue;
  742. if( !sd->inventory_data[index] )
  743. continue;
  744. if( sd->inventory_data[index]->nameid == nameid )
  745. return true;
  746. for( j = 0; j < sd->inventory_data[index]->slot; j++ ){
  747. if( sd->status.inventory[index].card[j] == nameid )
  748. return true;
  749. }
  750. }
  751. return false;
  752. }
  753. /** Check adopt rule
  754. * @param p1_sd Player 1
  755. * @param p2_sd Player 2
  756. * @param b_sd Player that will be adopted
  757. * @return True - if can be adopted, False otherwise
  758. */
  759. bool pc_can_Adopt(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd )
  760. {
  761. if( !p1_sd || !p2_sd || !b_sd )
  762. return false;
  763. if( b_sd->status.father || b_sd->status.mother || b_sd->adopt_invite )
  764. return false; // already adopted baby / in adopt request
  765. if( !p1_sd->status.partner_id || !p1_sd->status.party_id || p1_sd->status.party_id != b_sd->status.party_id )
  766. return false; // You need to be married and in party with baby to adopt
  767. if( p1_sd->status.partner_id != p2_sd->status.char_id || p2_sd->status.partner_id != p1_sd->status.char_id )
  768. return false; // Not married, wrong married
  769. if( p2_sd->status.party_id != p1_sd->status.party_id )
  770. return false; // Both parents need to be in the same party
  771. // Parents need to have their ring equipped
  772. if( !pc_isequipped(p1_sd, WEDDING_RING_M) && !pc_isequipped(p1_sd, WEDDING_RING_F) )
  773. return false;
  774. if( !pc_isequipped(p2_sd, WEDDING_RING_M) && !pc_isequipped(p2_sd, WEDDING_RING_F) )
  775. return false;
  776. // Already adopted a baby
  777. if( p1_sd->status.child || p2_sd->status.child ) {
  778. clif_Adopt_reply(p1_sd, 0);
  779. return false;
  780. }
  781. // Parents need at least lvl 70 to adopt
  782. if( p1_sd->status.base_level < 70 || p2_sd->status.base_level < 70 ) {
  783. clif_Adopt_reply(p1_sd, 1);
  784. return false;
  785. }
  786. if( b_sd->status.partner_id ) {
  787. clif_Adopt_reply(p1_sd, 2);
  788. return false;
  789. }
  790. if( !( ( b_sd->status.class_ >= JOB_NOVICE && b_sd->status.class_ <= JOB_THIEF ) || b_sd->status.class_ == JOB_SUPER_NOVICE || b_sd->status.class_ == JOB_SUPER_NOVICE_E ) )
  791. return false;
  792. return true;
  793. }
  794. /*==========================================
  795. * Adoption Process
  796. *------------------------------------------*/
  797. bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
  798. {
  799. int job, joblevel;
  800. unsigned int jobexp;
  801. if( !pc_can_Adopt(p1_sd, p2_sd, b_sd) )
  802. return false;
  803. // Preserve current job levels and progress
  804. joblevel = b_sd->status.job_level;
  805. jobexp = b_sd->status.job_exp;
  806. job = pc_mapid2jobid(b_sd->class_|JOBL_BABY, b_sd->status.sex);
  807. if( job != -1 && pc_jobchange(b_sd, job, 0) )
  808. { // Success, proceed to configure parents and baby skills
  809. p1_sd->status.child = b_sd->status.char_id;
  810. p2_sd->status.child = b_sd->status.char_id;
  811. b_sd->status.father = p1_sd->status.char_id;
  812. b_sd->status.mother = p2_sd->status.char_id;
  813. // Restore progress
  814. b_sd->status.job_level = joblevel;
  815. clif_updatestatus(b_sd, SP_JOBLEVEL);
  816. b_sd->status.job_exp = jobexp;
  817. clif_updatestatus(b_sd, SP_JOBEXP);
  818. // Baby Skills
  819. pc_skill(b_sd, WE_BABY, 1, ADDSKILL_PERMANENT);
  820. pc_skill(b_sd, WE_CALLPARENT, 1, ADDSKILL_PERMANENT);
  821. // Parents Skills
  822. pc_skill(p1_sd, WE_CALLBABY, 1, ADDSKILL_PERMANENT);
  823. pc_skill(p2_sd, WE_CALLBABY, 1, ADDSKILL_PERMANENT);
  824. return true;
  825. }
  826. return false; // Job Change Fail
  827. }
  828. /*==========================================
  829. * Check if player can use/equip selected item. Used by pc_isUseitem and pc_isequip
  830. Returns:
  831. false : Cannot use/equip
  832. true : Can use/equip
  833. * Credits:
  834. [Inkfish] for first idea
  835. [Haru] for third-classes extension
  836. [Cydh] finishing :D
  837. *------------------------------------------*/
  838. static bool pc_isItemClass (struct map_session_data *sd, struct item_data* item) {
  839. while (1) {
  840. if (item->class_upper&ITEMJ_NORMAL && !(sd->class_&(JOBL_UPPER|JOBL_THIRD|JOBL_BABY))) //normal classes (no upper, no baby, no third)
  841. break;
  842. #ifndef RENEWAL
  843. //allow third classes to use trans. class items
  844. if (item->class_upper&ITEMJ_UPPER && sd->class_&(JOBL_UPPER|JOBL_THIRD)) //trans. classes
  845. break;
  846. //third-baby classes can use same item too
  847. if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY) //baby classes
  848. break;
  849. //don't need to decide specific rules for third-classes?
  850. //items for third classes can be used for all third classes
  851. if (item->class_upper&(ITEMJ_THIRD|ITEMJ_THIRD_TRANS|ITEMJ_THIRD_BABY) && sd->class_&JOBL_THIRD)
  852. break;
  853. #else
  854. //trans. classes (exl. third-trans.)
  855. if (item->class_upper&ITEMJ_UPPER && sd->class_&JOBL_UPPER && !(sd->class_&JOBL_THIRD))
  856. break;
  857. //baby classes (exl. third-baby)
  858. if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY && !(sd->class_&JOBL_THIRD))
  859. break;
  860. //third classes (exl. third-trans. and baby-third)
  861. if (item->class_upper&ITEMJ_THIRD && sd->class_&JOBL_THIRD && !(sd->class_&(JOBL_UPPER|JOBL_BABY)))
  862. break;
  863. //trans-third classes
  864. if (item->class_upper&ITEMJ_THIRD_TRANS && sd->class_&JOBL_THIRD && sd->class_&JOBL_UPPER)
  865. break;
  866. //third-baby classes
  867. if (item->class_upper&ITEMJ_THIRD_BABY && sd->class_&JOBL_THIRD && sd->class_&JOBL_BABY)
  868. break;
  869. #endif
  870. return false;
  871. }
  872. return true;
  873. }
  874. /*=================================================
  875. * Checks if the player can equip the item at index n in inventory.
  876. * @param sd
  877. * @param n Item index in inventory
  878. * @return ITEM_EQUIP_ACK_OK(0) if can be equipped, or ITEM_EQUIP_ACK_FAIL(1)/ITEM_EQUIP_ACK_FAILLEVEL(2) if can't
  879. *------------------------------------------------*/
  880. uint8 pc_isequip(struct map_session_data *sd,int n)
  881. {
  882. struct item_data *item;
  883. nullpo_retr(ITEM_EQUIP_ACK_FAIL, sd);
  884. item = sd->inventory_data[n];
  885. if(pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT))
  886. return ITEM_EQUIP_ACK_OK;
  887. if(item == NULL)
  888. return ITEM_EQUIP_ACK_FAIL;
  889. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  890. return ITEM_EQUIP_ACK_FAILLEVEL;
  891. if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
  892. return ITEM_EQUIP_ACK_FAILLEVEL;
  893. if(item->sex != 2 && sd->status.sex != item->sex)
  894. return ITEM_EQUIP_ACK_FAIL;
  895. if (sd->sc.count) {
  896. if(item->equip & EQP_ARMS && item->type == IT_WEAPON && sd->sc.data[SC_STRIPWEAPON]) // Also works with left-hand weapons [DracoRPG]
  897. return ITEM_EQUIP_ACK_FAIL;
  898. if(item->equip & EQP_SHIELD && item->type == IT_ARMOR && sd->sc.data[SC_STRIPSHIELD])
  899. return ITEM_EQUIP_ACK_FAIL;
  900. if(item->equip & EQP_ARMOR && sd->sc.data[SC_STRIPARMOR])
  901. return ITEM_EQUIP_ACK_FAIL;
  902. if(item->equip & EQP_HEAD_TOP && sd->sc.data[SC_STRIPHELM])
  903. return ITEM_EQUIP_ACK_FAIL;
  904. if(item->equip & EQP_ACC && sd->sc.data[SC__STRIPACCESSORY])
  905. return ITEM_EQUIP_ACK_FAIL;
  906. if(item->equip && sd->sc.data[SC_KYOUGAKU])
  907. return ITEM_EQUIP_ACK_FAIL;
  908. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_SUPERNOVICE) {
  909. //Spirit of Super Novice equip bonuses. [Skotlex]
  910. if (sd->status.base_level > 90 && item->equip & EQP_HELM)
  911. return ITEM_EQUIP_ACK_OK; //Can equip all helms
  912. if (sd->status.base_level > 96 && item->equip & EQP_ARMS && item->type == IT_WEAPON && item->wlv == 4)
  913. switch(item->look) { //In weapons, the look determines type of weapon.
  914. case W_DAGGER: //All level 4 - Daggers
  915. case W_1HSWORD: //All level 4 - 1H Swords
  916. case W_1HAXE: //All level 4 - 1H Axes
  917. case W_MACE: //All level 4 - 1H Maces
  918. case W_STAFF: //All level 4 - 1H Staves
  919. case W_2HSTAFF: //All level 4 - 2H Staves
  920. return ITEM_EQUIP_ACK_OK;
  921. }
  922. }
  923. }
  924. //fail to equip if item is restricted
  925. if (!battle_config.allow_equip_restricted_item && itemdb_isNoEquip(item, sd->bl.m))
  926. return ITEM_EQUIP_ACK_FAIL;
  927. //Not equipable by class. [Skotlex]
  928. if (!(1<<(sd->class_&MAPID_BASEMASK)&item->class_base[(sd->class_&JOBL_2_1)?1:((sd->class_&JOBL_2_2)?2:0)]))
  929. return ITEM_EQUIP_ACK_FAIL;
  930. if (!pc_isItemClass(sd,item))
  931. return ITEM_EQUIP_ACK_FAIL;
  932. return ITEM_EQUIP_ACK_OK;
  933. }
  934. /*==========================================
  935. * No problem with the session id
  936. * set the status that has been sent from char server
  937. *------------------------------------------*/
  938. bool pc_authok(struct map_session_data *sd, uint32 login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers)
  939. {
  940. int i;
  941. #ifdef BOUND_ITEMS
  942. int j;
  943. int idxlist[MAX_INVENTORY];
  944. #endif
  945. unsigned long tick = gettick();
  946. uint32 ip = session[sd->fd]->client_addr;
  947. sd->login_id2 = login_id2;
  948. sd->group_id = group_id;
  949. /* load user permissions */
  950. pc_group_pc_load(sd);
  951. memcpy(&sd->status, st, sizeof(*st));
  952. if (st->sex != sd->status.sex) {
  953. clif_authfail_fd(sd->fd, 0);
  954. return false;
  955. }
  956. //Set the map-server used job id. [Skotlex]
  957. i = pc_jobid2mapid(sd->status.class_);
  958. if (i == -1) { //Invalid class?
  959. 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);
  960. sd->status.class_ = JOB_NOVICE;
  961. sd->class_ = MAPID_NOVICE;
  962. } else
  963. sd->class_ = i;
  964. // Checks and fixes to character status data, that are required
  965. // in case of configuration change or stuff, which cannot be
  966. // checked on char-server.
  967. sd->status.hair = cap_value(sd->status.hair,MIN_HAIR_STYLE,MAX_HAIR_STYLE);
  968. sd->status.hair_color = cap_value(sd->status.hair_color,MIN_HAIR_COLOR,MAX_HAIR_COLOR);
  969. sd->status.clothes_color = cap_value(sd->status.clothes_color,MIN_CLOTH_COLOR,MAX_CLOTH_COLOR);
  970. sd->status.body = cap_value(sd->status.body,MIN_BODY_STYLE,MAX_BODY_STYLE);
  971. //Initializations to null/0 unneeded since map_session_data was filled with 0 upon allocation.
  972. if(!sd->status.hp) pc_setdead(sd);
  973. sd->state.connect_new = 1;
  974. sd->followtimer = INVALID_TIMER; // [MouseJstr]
  975. sd->invincible_timer = INVALID_TIMER;
  976. sd->npc_timer_id = INVALID_TIMER;
  977. sd->pvp_timer = INVALID_TIMER;
  978. sd->expiration_tid = INVALID_TIMER;
  979. sd->autotrade_tid = INVALID_TIMER;
  980. #ifdef SECURE_NPCTIMEOUT
  981. // Initialize to defaults/expected
  982. sd->npc_idle_timer = INVALID_TIMER;
  983. sd->npc_idle_tick = tick;
  984. sd->npc_idle_type = NPCT_INPUT;
  985. sd->state.ignoretimeout = false;
  986. #endif
  987. sd->canuseitem_tick = tick;
  988. sd->canusecashfood_tick = tick;
  989. sd->canequip_tick = tick;
  990. sd->cantalk_tick = tick;
  991. sd->canskill_tick = tick;
  992. sd->cansendmail_tick = tick;
  993. sd->idletime = last_tick;
  994. for(i = 0; i < MAX_SPIRITBALL; i++)
  995. sd->spirit_timer[i] = INVALID_TIMER;
  996. for(i = 0; i < ARRAYLENGTH(sd->autobonus); i++)
  997. sd->autobonus[i].active = INVALID_TIMER;
  998. for(i = 0; i < ARRAYLENGTH(sd->autobonus2); i++)
  999. sd->autobonus2[i].active = INVALID_TIMER;
  1000. for(i = 0; i < ARRAYLENGTH(sd->autobonus3); i++)
  1001. sd->autobonus3[i].active = INVALID_TIMER;
  1002. if (battle_config.item_auto_get)
  1003. sd->state.autoloot = 10000;
  1004. if (battle_config.disp_experience)
  1005. sd->state.showexp = 1;
  1006. if (battle_config.disp_zeny)
  1007. sd->state.showzeny = 1;
  1008. #ifdef VIP_ENABLE
  1009. if (!battle_config.vip_disp_rate)
  1010. sd->disableshowrate = 1;
  1011. #endif
  1012. if (!(battle_config.display_skill_fail&2))
  1013. sd->state.showdelay = 1;
  1014. pc_setinventorydata(sd);
  1015. pc_setequipindex(sd);
  1016. if( sd->status.option&OPTION_INVISIBLE && !pc_can_use_command( sd, "hide", COMMAND_ATCOMMAND ) ){
  1017. sd->status.option &= ~OPTION_INVISIBLE;
  1018. }
  1019. status_change_init(&sd->bl);
  1020. sd->sc.option = sd->status.option; //This is the actual option used in battle.
  1021. //Set here because we need the inventory data for weapon sprite parsing.
  1022. status_set_viewdata(&sd->bl, sd->status.class_);
  1023. unit_dataset(&sd->bl);
  1024. sd->guild_x = -1;
  1025. sd->guild_y = -1;
  1026. sd->delayed_damage = 0;
  1027. // Event Timers
  1028. for( i = 0; i < MAX_EVENTTIMER; i++ )
  1029. sd->eventtimer[i] = INVALID_TIMER;
  1030. // Rental Timer
  1031. sd->rental_timer = INVALID_TIMER;
  1032. for( i = 0; i < 3; i++ )
  1033. sd->hate_mob[i] = -1;
  1034. sd->quest_log = NULL;
  1035. sd->num_quests = 0;
  1036. sd->avail_quests = 0;
  1037. sd->save_quest = false;
  1038. sd->count_rewarp = 0;
  1039. sd->regs.vars = i64db_alloc(DB_OPT_BASE);
  1040. sd->regs.arrays = NULL;
  1041. sd->vars_dirty = false;
  1042. sd->vars_ok = false;
  1043. sd->vars_received = 0x0;
  1044. sd->qi_display = NULL;
  1045. sd->qi_count = 0;
  1046. //warp player
  1047. if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != 0) {
  1048. 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);
  1049. // try warping to a default map instead (church graveyard)
  1050. if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != 0) {
  1051. // if we fail again
  1052. clif_authfail_fd(sd->fd, 0);
  1053. return false;
  1054. }
  1055. }
  1056. clif_authok(sd);
  1057. //Prevent S. Novices from getting the no-death bonus just yet. [Skotlex]
  1058. sd->die_counter=-1;
  1059. //display login notice
  1060. ShowInfo("'"CL_WHITE"%s"CL_RESET"' logged in."
  1061. " (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"',"
  1062. " Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%d.%d.%d.%d"CL_RESET"',"
  1063. " Group '"CL_WHITE"%d"CL_RESET"').\n",
  1064. sd->status.name, sd->status.account_id, sd->status.char_id,
  1065. sd->packet_ver, CONVIP(ip), sd->group_id);
  1066. // Send friends list
  1067. clif_friendslist_send(sd);
  1068. if( !changing_mapservers ) {
  1069. if (battle_config.display_version == 1)
  1070. pc_show_version(sd);
  1071. // Message of the Day [Valaris]
  1072. for(i=0; i < MOTD_LINE_SIZE && motd_text[i][0]; i++) {
  1073. if (battle_config.motd_type)
  1074. clif_disp_onlyself(sd,motd_text[i],strlen(motd_text[i]));
  1075. else
  1076. clif_displaymessage(sd->fd, motd_text[i]);
  1077. }
  1078. if (expiration_time != 0)
  1079. sd->expiration_time = expiration_time;
  1080. /**
  1081. * Fixes login-without-aura glitch (the screen won't blink at this point, don't worry :P)
  1082. **/
  1083. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  1084. }
  1085. /**
  1086. * Check if player have any item cooldowns on
  1087. **/
  1088. pc_itemcd_do(sd,true);
  1089. pc_validate_skill(sd);
  1090. #ifdef BOUND_ITEMS
  1091. // Party bound item check
  1092. if(sd->status.party_id == 0 && (j = pc_bound_chk(sd,BOUND_PARTY,idxlist))) { // Party was deleted while character offline
  1093. for(i=0;i<j;i++)
  1094. pc_delitem(sd,idxlist[i],sd->status.inventory[idxlist[i]].amount,0,1,LOG_TYPE_OTHER);
  1095. }
  1096. #endif
  1097. /* [Ind] */
  1098. sd->sc_display = NULL;
  1099. sd->sc_display_count = 0;
  1100. // Player has not yet received the CashShop list
  1101. sd->status.cashshop_sent = false;
  1102. sd->last_addeditem_index = -1;
  1103. sd->bonus_script.head = NULL;
  1104. sd->bonus_script.count = 0;
  1105. // Request all registries (auth is considered completed whence they arrive)
  1106. intif_request_registry(sd,7);
  1107. return true;
  1108. }
  1109. /*==========================================
  1110. * Closes a connection because it failed to be authenticated from the char server.
  1111. *------------------------------------------*/
  1112. void pc_authfail(struct map_session_data *sd)
  1113. {
  1114. clif_authfail_fd(sd->fd, 0);
  1115. return;
  1116. }
  1117. /**
  1118. * Player register a bl as hatred
  1119. * @param sd : player session
  1120. * @param pos : hate position [0;2]
  1121. * @param bl : target bl
  1122. * @return false:failed, true:success
  1123. */
  1124. bool pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl)
  1125. {
  1126. int class_;
  1127. if (!sd || !bl || pos < 0 || pos > 2)
  1128. return false;
  1129. if (sd->hate_mob[pos] != -1)
  1130. { //Can't change hate targets.
  1131. clif_hate_info(sd, pos, sd->hate_mob[pos], 0); //Display current
  1132. return false;
  1133. }
  1134. class_ = status_get_class(bl);
  1135. if (!pcdb_checkid(class_)) {
  1136. unsigned int max_hp = status_get_max_hp(bl);
  1137. if ((pos == 1 && max_hp < 6000) || (pos == 2 && max_hp < 20000))
  1138. return false;
  1139. if (pos != status_get_size(bl))
  1140. return false; //Wrong size
  1141. }
  1142. sd->hate_mob[pos] = class_;
  1143. pc_setglobalreg(sd, add_str(sg_info[pos].hate_var), class_+1);
  1144. clif_hate_info(sd, pos, class_, 1);
  1145. return true;
  1146. }
  1147. /*==========================================
  1148. * Invoked once after the char/account/account2 registry variables are received. [Skotlex]
  1149. *------------------------------------------*/
  1150. void pc_reg_received(struct map_session_data *sd)
  1151. {
  1152. uint8 i;
  1153. sd->vars_ok = true;
  1154. sd->change_level_2nd = pc_readglobalreg(sd, add_str("jobchange_level"));
  1155. sd->change_level_3rd = pc_readglobalreg(sd, add_str("jobchange_level_3rd"));
  1156. sd->die_counter = pc_readglobalreg(sd, add_str("PC_DIE_COUNTER"));
  1157. sd->langtype = pc_readaccountreg(sd, add_str("#langtype"));
  1158. if (msg_checklangtype(sd->langtype,true) < 0)
  1159. sd->langtype = 0; //invalid langtype reset to default
  1160. // Cash shop
  1161. sd->cashPoints = pc_readaccountreg(sd, add_str("#CASHPOINTS"));
  1162. sd->kafraPoints = pc_readaccountreg(sd, add_str("#KAFRAPOINTS"));
  1163. // Cooking Exp
  1164. sd->cook_mastery = pc_readglobalreg(sd, add_str("COOK_MASTERY"));
  1165. if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON )
  1166. { // Better check for class rather than skill to prevent "skill resets" from unsetting this
  1167. sd->mission_mobid = pc_readglobalreg(sd, add_str("TK_MISSION_ID"));
  1168. sd->mission_count = pc_readglobalreg(sd, add_str("TK_MISSION_COUNT"));
  1169. }
  1170. if (battle_config.feature_banking)
  1171. sd->bank_vault = pc_readreg2(sd, BANK_VAULT_VAR);
  1172. if (battle_config.feature_roulette) {
  1173. sd->roulette_point.bronze = pc_readreg2(sd, ROULETTE_BRONZE_VAR);
  1174. sd->roulette_point.silver = pc_readreg2(sd, ROULETTE_SILVER_VAR);
  1175. sd->roulette_point.gold = pc_readreg2(sd, ROULETTE_GOLD_VAR);
  1176. }
  1177. sd->roulette.prizeIdx = -1;
  1178. //SG map and mob read [Komurka]
  1179. for(i=0;i<MAX_PC_FEELHATE;i++) { //for now - someone need to make reading from txt/sql
  1180. uint16 j;
  1181. if ((j = pc_readglobalreg(sd, add_str(sg_info[i].feel_var))) != 0) {
  1182. sd->feel_map[i].index = j;
  1183. sd->feel_map[i].m = map_mapindex2mapid(j);
  1184. } else {
  1185. sd->feel_map[i].index = 0;
  1186. sd->feel_map[i].m = -1;
  1187. }
  1188. sd->hate_mob[i] = pc_readglobalreg(sd, add_str(sg_info[i].hate_var))-1;
  1189. }
  1190. if ((i = pc_checkskill(sd,RG_PLAGIARISM)) > 0) {
  1191. unsigned short skid = pc_readglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM));
  1192. sd->cloneskill_idx = skill_get_index(skid);
  1193. if (sd->cloneskill_idx > 0) {
  1194. sd->status.skill[sd->cloneskill_idx].id = skid;
  1195. sd->status.skill[sd->cloneskill_idx].lv = pc_readglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM_LV));
  1196. if (sd->status.skill[sd->cloneskill_idx].lv > i)
  1197. sd->status.skill[sd->cloneskill_idx].lv = i;
  1198. sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
  1199. }
  1200. }
  1201. if ((i = pc_checkskill(sd,SC_REPRODUCE)) > 0) {
  1202. unsigned short skid = pc_readglobalreg(sd, add_str(SKILL_VAR_REPRODUCE));
  1203. sd->reproduceskill_idx = skill_get_index(skid);
  1204. if (sd->reproduceskill_idx > 0) {
  1205. sd->status.skill[sd->reproduceskill_idx].id = skid;
  1206. sd->status.skill[sd->reproduceskill_idx].lv = pc_readglobalreg(sd, add_str(SKILL_VAR_REPRODUCE_LV));
  1207. if (i < sd->status.skill[sd->reproduceskill_idx].lv)
  1208. sd->status.skill[sd->reproduceskill_idx].lv = i;
  1209. sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
  1210. }
  1211. }
  1212. //Weird... maybe registries were reloaded?
  1213. if (sd->state.active)
  1214. return;
  1215. sd->state.active = 1;
  1216. if (sd->status.party_id)
  1217. party_member_joined(sd);
  1218. if (sd->status.guild_id)
  1219. guild_member_joined(sd);
  1220. // pet
  1221. if (sd->status.pet_id > 0)
  1222. intif_request_petdata(sd->status.account_id, sd->status.char_id, sd->status.pet_id);
  1223. // Homunculus [albator]
  1224. if( sd->status.hom_id > 0 )
  1225. intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id);
  1226. if( sd->status.mer_id > 0 )
  1227. intif_mercenary_request(sd->status.mer_id, sd->status.char_id);
  1228. if( sd->status.ele_id > 0 )
  1229. intif_elemental_request(sd->status.ele_id, sd->status.char_id);
  1230. map_addiddb(&sd->bl);
  1231. map_delnickdb(sd->status.char_id, sd->status.name);
  1232. if (!chrif_auth_finished(sd))
  1233. ShowError("pc_reg_received: Failed to properly remove player %d:%d from logging db!\n", sd->status.account_id, sd->status.char_id);
  1234. pc_load_combo(sd);
  1235. status_calc_pc(sd, (enum e_status_calc_opt)(SCO_FIRST|SCO_FORCE));
  1236. chrif_scdata_request(sd->status.account_id, sd->status.char_id);
  1237. chrif_skillcooldown_request(sd->status.account_id, sd->status.char_id);
  1238. chrif_bsdata_request(sd->status.char_id);
  1239. sd->storage_size = MIN_STORAGE; //default to min
  1240. #ifdef VIP_ENABLE
  1241. sd->vip.time = 0;
  1242. sd->vip.enabled = 0;
  1243. chrif_req_login_operation(sd->status.account_id, sd->status.name, CHRIF_OP_LOGIN_VIP, 0, 1, 0); // request VIP informations
  1244. #endif
  1245. intif_Mail_requestinbox(sd->status.char_id, 0); // MAIL SYSTEM - Request Mail Inbox
  1246. intif_request_questlog(sd);
  1247. if (sd->state.connect_new == 0 && sd->fd) { //Character already loaded map! Gotta trigger LoadEndAck manually.
  1248. sd->state.connect_new = 1;
  1249. clif_parse_LoadEndAck(sd->fd, sd);
  1250. }
  1251. if( sd->sc.option&OPTION_INVISIBLE ) {
  1252. sd->vd.class_ = INVISIBLE_CLASS;
  1253. clif_displaymessage( sd->fd, msg_txt( sd, 11 ) ); // Invisible: On
  1254. // decrement the number of pvp players on the map
  1255. map[sd->bl.m].users_pvp--;
  1256. if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER ){
  1257. // unregister the player for ranking
  1258. delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  1259. sd->pvp_timer = INVALID_TIMER;
  1260. }
  1261. clif_changeoption( &sd->bl );
  1262. }
  1263. pc_check_expiration(sd);
  1264. if( sd->state.autotrade ) {
  1265. clif_parse_LoadEndAck(sd->fd, sd);
  1266. sd->autotrade_tid = add_timer(gettick() + battle_config.feature_autotrade_open_delay, pc_autotrade_timer, sd->bl.id, 0);
  1267. }
  1268. }
  1269. static int pc_calc_skillpoint(struct map_session_data* sd)
  1270. {
  1271. uint16 i, skill_point = 0;
  1272. nullpo_ret(sd);
  1273. for(i = 1; i < MAX_SKILL; i++) {
  1274. if( sd->status.skill[i].id && sd->status.skill[i].lv > 0) {
  1275. uint16 inf2 = skill_get_inf2(sd->status.skill[i].id);
  1276. if ((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  1277. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) //Do not count wedding/link skills. [Skotlex]
  1278. )
  1279. {
  1280. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  1281. skill_point += sd->status.skill[i].lv;
  1282. else if(sd->status.skill[i].flag >= SKILL_FLAG_REPLACED_LV_0)
  1283. skill_point += (sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0);
  1284. }
  1285. }
  1286. }
  1287. return skill_point;
  1288. }
  1289. static bool pc_grant_allskills(struct map_session_data *sd, bool addlv) {
  1290. uint16 i = 0;
  1291. if (!sd || !pc_has_permission(sd, PC_PERM_ALL_SKILL) || !SKILL_MAX_DB())
  1292. return false;
  1293. /**
  1294. * Dummy skills must NOT be added here otherwise they'll be displayed in the,
  1295. * skill tree and since they have no icons they'll give resource errors
  1296. * Get ALL skills except npc/guild ones. [Skotlex]
  1297. * Don't add SG_DEVIL [Komurka] and MO_TRIPLEATTACK and RG_SNATCHER [ultramage]
  1298. **/
  1299. for( i = 0; i < MAX_SKILL; i++ ) {
  1300. uint16 skill_id = skill_idx2id(i);
  1301. if (!skill_id || (skill_get_inf2(skill_id)&(INF2_NPC_SKILL|INF2_GUILD_SKILL)))
  1302. continue;
  1303. switch (skill_id) {
  1304. case SM_SELFPROVOKE:
  1305. case AB_DUPLELIGHT_MELEE:
  1306. case AB_DUPLELIGHT_MAGIC:
  1307. case WL_CHAINLIGHTNING_ATK:
  1308. case WL_TETRAVORTEX_FIRE:
  1309. case WL_TETRAVORTEX_WATER:
  1310. case WL_TETRAVORTEX_WIND:
  1311. case WL_TETRAVORTEX_GROUND:
  1312. case WL_SUMMON_ATK_FIRE:
  1313. case WL_SUMMON_ATK_WIND:
  1314. case WL_SUMMON_ATK_WATER:
  1315. case WL_SUMMON_ATK_GROUND:
  1316. case LG_OVERBRAND_BRANDISH:
  1317. case LG_OVERBRAND_PLUSATK:
  1318. case WM_SEVERE_RAINSTORM_MELEE:
  1319. case RL_R_TRIP_PLUSATK:
  1320. case SG_DEVIL:
  1321. case MO_TRIPLEATTACK:
  1322. case RG_SNATCHER:
  1323. continue;
  1324. default:
  1325. {
  1326. uint8 lv = (uint8)skill_get_max(skill_id);
  1327. if (lv > 0) {
  1328. sd->status.skill[i].id = skill_id;
  1329. if (addlv)
  1330. sd->status.skill[i].lv = lv;
  1331. }
  1332. }
  1333. break;
  1334. }
  1335. }
  1336. return true;
  1337. }
  1338. /*==========================================
  1339. * Calculation of skill level.
  1340. * @param sd
  1341. *------------------------------------------*/
  1342. void pc_calc_skilltree(struct map_session_data *sd)
  1343. {
  1344. int i, flag;
  1345. int c = 0;
  1346. nullpo_retv(sd);
  1347. i = pc_calc_skilltree_normalize_job(sd);
  1348. c = pc_mapid2jobid(i, sd->status.sex);
  1349. if( c == -1 )
  1350. { //Unable to normalize job??
  1351. 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);
  1352. return;
  1353. }
  1354. c = pc_class2idx(c);
  1355. for( i = 0; i < MAX_SKILL; i++ ) {
  1356. if( sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED ) //Don't touch these
  1357. sd->status.skill[i].id = 0; //First clear skills.
  1358. /* permanent skills that must be re-checked */
  1359. if( sd->status.skill[i].flag == SKILL_FLAG_PERM_GRANTED ) {
  1360. uint16 sk_id = skill_idx2id(i);
  1361. if (!sk_id) {
  1362. sd->status.skill[i].id = 0;
  1363. sd->status.skill[i].lv = 0;
  1364. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1365. continue;
  1366. }
  1367. switch (sk_id) {
  1368. case NV_TRICKDEAD:
  1369. if( (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ) {
  1370. sd->status.skill[i].id = 0;
  1371. sd->status.skill[i].lv = 0;
  1372. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1373. }
  1374. break;
  1375. }
  1376. }
  1377. }
  1378. for( i = 0; i < MAX_SKILL; i++ ) {
  1379. uint16 skill_id = 0;
  1380. // Restore original level of skills after deleting earned skills.
  1381. if( sd->status.skill[i].flag != SKILL_FLAG_PERMANENT && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED && sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED ) {
  1382. sd->status.skill[i].lv = (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  1383. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1384. }
  1385. //Enable Bard/Dancer spirit linked skills.
  1386. if (!(skill_id = skill_idx2id(i)) || skill_id < DC_HUMMING || skill_id > DC_SERVICEFORYOU)
  1387. continue;
  1388. if( &sd->sc && sd->sc.count && sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_BARDDANCER ) {
  1389. //Link Dancer skills to bard.
  1390. if( sd->status.sex ) {
  1391. if( sd->status.skill[i-8].lv < 10 )
  1392. continue;
  1393. sd->status.skill[i].id = skill_id;
  1394. sd->status.skill[i].lv = sd->status.skill[i-8].lv; // Set the level to the same as the linking skill
  1395. sd->status.skill[i].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
  1396. }
  1397. //Link Bard skills to dancer.
  1398. else {
  1399. if( sd->status.skill[i].lv < 10 )
  1400. continue;
  1401. sd->status.skill[i-8].id = skill_id - 8;
  1402. sd->status.skill[i-8].lv = sd->status.skill[i].lv; // Set the level to the same as the linking skill
  1403. sd->status.skill[i-8].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
  1404. }
  1405. }
  1406. }
  1407. // Removes Taekwon Ranker skill bonus
  1408. if ((sd->class_&MAPID_UPPERMASK) != MAPID_TAEKWON) {
  1409. uint16 c_ = pc_class2idx(JOB_TAEKWON);
  1410. for (i = 0; i < MAX_SKILL_TREE; i++) {
  1411. uint16 sk_id = skill_tree[c_][i].id;
  1412. uint16 sk_idx = 0;
  1413. if (!sk_id || !(sk_idx = skill_get_index(skill_tree[c_][i].id)))
  1414. continue;
  1415. if (sd->status.skill[sk_idx].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[sk_idx].flag != SKILL_FLAG_PERM_GRANTED) {
  1416. if (sk_id == NV_BASIC || sk_id == NV_FIRSTAID || sk_id == WE_CALLBABY)
  1417. continue;
  1418. sd->status.skill[sk_idx].id = 0;
  1419. }
  1420. }
  1421. }
  1422. // Grant all skills
  1423. pc_grant_allskills(sd, false);
  1424. do {
  1425. uint16 skid = 0;
  1426. flag = 0;
  1427. for (i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[c][i].id) > 0; i++) {
  1428. bool fail = false;
  1429. uint16 sk_idx = skill_get_index(skid);
  1430. if (sd->status.skill[sk_idx].id)
  1431. continue; //Skill already known.
  1432. if (!battle_config.skillfree) {
  1433. uint8 j;
  1434. // Checking required skills
  1435. for(j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
  1436. uint16 sk_need_id = skill_tree[c][i].need[j].id;
  1437. uint16 sk_need_idx = 0;
  1438. if (sk_need_id && (sk_need_idx = skill_get_index(sk_need_id))) {
  1439. short sk_need = sk_need_id;
  1440. if (sd->status.skill[sk_need_idx].id == 0 || sd->status.skill[sk_need_idx].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[sk_need_idx].flag == SKILL_FLAG_PLAGIARIZED)
  1441. sk_need = 0; //Not learned.
  1442. else if (sd->status.skill[sk_need_idx].flag >= SKILL_FLAG_REPLACED_LV_0) //Real learned level
  1443. sk_need = sd->status.skill[sk_need_idx].flag - SKILL_FLAG_REPLACED_LV_0;
  1444. else
  1445. sk_need = pc_checkskill(sd,sk_need_id);
  1446. if (sk_need < skill_tree[c][i].need[j].lv) {
  1447. fail = true;
  1448. break;
  1449. }
  1450. }
  1451. }
  1452. if (sd->status.job_level < skill_tree[c][i].joblv) { //We need to get the actual class in this case
  1453. int class_ = pc_mapid2jobid(sd->class_, sd->status.sex);
  1454. class_ = pc_class2idx(class_);
  1455. if (class_ == c || (class_ != c && sd->status.job_level < skill_tree[class_][i].joblv))
  1456. fail = true; // job level requirement wasn't satisfied
  1457. }
  1458. }
  1459. if (!fail) {
  1460. int inf2 = skill_get_inf2(skid);
  1461. if (!sd->status.skill[sk_idx].lv && (
  1462. (inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  1463. inf2&INF2_WEDDING_SKILL ||
  1464. (inf2&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
  1465. ))
  1466. continue; //Cannot be learned via normal means. Note this check DOES allows raising already known skills.
  1467. sd->status.skill[sk_idx].id = skid;
  1468. if(inf2&INF2_SPIRIT_SKILL) { //Spirit skills cannot be learned, they will only show up on your tree when you get buffed.
  1469. sd->status.skill[sk_idx].lv = 1; // need to manually specify a skill level
  1470. sd->status.skill[sk_idx].flag = SKILL_FLAG_TEMPORARY; //So it is not saved, and tagged as a "bonus" skill.
  1471. }
  1472. flag = 1; // skill list has changed, perform another pass
  1473. }
  1474. }
  1475. } while(flag);
  1476. if( c > 0 && sd->status.skill_point == 0 && pc_is_taekwon_ranker(sd) ) {
  1477. unsigned short skid = 0;
  1478. /* Taekwon Ranker Bonus Skill Tree
  1479. ============================================
  1480. - Grant All Taekwon Tree, but only as Bonus Skills in case they drop from ranking.
  1481. - (c > 0) to avoid grant Novice Skill Tree in case of Skill Reset (need more logic)
  1482. - (sd->status.skill_point == 0) to wait until all skill points are assigned to avoid problems with Job Change quest. */
  1483. for( i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[c][i].id) > 0; i++ ) {
  1484. uint16 sk_idx = 0;
  1485. if (!(sk_idx = skill_get_index(skid)))
  1486. continue;
  1487. if( (skill_get_inf2(skid)&(INF2_QUEST_SKILL|INF2_WEDDING_SKILL)) )
  1488. continue; //Do not include Quest/Wedding skills.
  1489. if( sd->status.skill[sk_idx].id == 0 ) {
  1490. sd->status.skill[sk_idx].id = skid;
  1491. sd->status.skill[sk_idx].flag = SKILL_FLAG_TEMPORARY; // So it is not saved, and tagged as a "bonus" skill.
  1492. } else if( skid != NV_BASIC )
  1493. sd->status.skill[sk_idx].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[sk_idx].lv; // Remember original level
  1494. sd->status.skill[sk_idx].lv = skill_tree_get_max(skid, sd->status.class_);
  1495. }
  1496. }
  1497. }
  1498. //Checks if you can learn a new skill after having leveled up a skill.
  1499. static void pc_check_skilltree(struct map_session_data *sd)
  1500. {
  1501. int i, flag = 0;
  1502. int c = 0;
  1503. if (battle_config.skillfree)
  1504. return; //Function serves no purpose if this is set
  1505. i = pc_calc_skilltree_normalize_job(sd);
  1506. c = pc_mapid2jobid(i, sd->status.sex);
  1507. if (c == -1) { //Unable to normalize job??
  1508. 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);
  1509. return;
  1510. }
  1511. c = pc_class2idx(c);
  1512. do {
  1513. uint16 skid = 0;
  1514. flag = 0;
  1515. for (i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[c][i].id) > 0; i++ ) {
  1516. uint16 sk_idx = skill_get_index(skid);
  1517. bool fail = false;
  1518. uint8 j = 0;
  1519. if (sd->status.skill[sk_idx].id) //Already learned
  1520. continue;
  1521. // Checking required skills
  1522. for (j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
  1523. uint16 sk_need_id = skill_tree[c][i].need[j].id;
  1524. uint16 sk_need_idx = 0;
  1525. if (sk_need_id && (sk_need_idx = skill_get_index(sk_need_id))) {
  1526. short sk_need = sk_need_id;
  1527. if (sd->status.skill[sk_need_idx].id == 0 || sd->status.skill[sk_need_idx].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[sk_need_idx].flag == SKILL_FLAG_PLAGIARIZED)
  1528. sk_need = 0; //Not learned.
  1529. else if (sd->status.skill[sk_need_idx].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
  1530. sk_need = sd->status.skill[sk_need_idx].flag - SKILL_FLAG_REPLACED_LV_0;
  1531. else
  1532. sk_need = pc_checkskill(sd,sk_need_id);
  1533. if (sk_need < skill_tree[c][i].need[j].lv) {
  1534. fail = true;
  1535. break;
  1536. }
  1537. }
  1538. }
  1539. if( fail )
  1540. continue;
  1541. if( sd->status.job_level < skill_tree[c][i].joblv )
  1542. continue;
  1543. j = skill_get_inf2(skid);
  1544. if( !sd->status.skill[sk_idx].lv && (
  1545. (j&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  1546. j&INF2_WEDDING_SKILL ||
  1547. (j&INF2_SPIRIT_SKILL && !sd->sc.data[SC_SPIRIT])
  1548. ) )
  1549. continue; //Cannot be learned via normal means.
  1550. sd->status.skill[sk_idx].id = skid;
  1551. flag = 1;
  1552. }
  1553. } while(flag);
  1554. }
  1555. // Make sure all the skills are in the correct condition
  1556. // before persisting to the backend.. [MouseJstr]
  1557. void pc_clean_skilltree(struct map_session_data *sd)
  1558. {
  1559. uint16 i;
  1560. for (i = 0; i < MAX_SKILL; i++){
  1561. if (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED) {
  1562. sd->status.skill[i].id = 0;
  1563. sd->status.skill[i].lv = 0;
  1564. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1565. }
  1566. else if (sd->status.skill[i].flag >= SKILL_FLAG_REPLACED_LV_0){
  1567. sd->status.skill[i].lv = sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  1568. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1569. }
  1570. }
  1571. }
  1572. int pc_calc_skilltree_normalize_job(struct map_session_data *sd)
  1573. {
  1574. int skill_point, novice_skills;
  1575. int c = sd->class_;
  1576. if (!battle_config.skillup_limit || pc_has_permission(sd, PC_PERM_ALL_SKILL))
  1577. return c;
  1578. skill_point = pc_calc_skillpoint(sd);
  1579. novice_skills = job_info[pc_class2idx(JOB_NOVICE)].max_level[1] - 1;
  1580. // limit 1st class and above to novice job levels
  1581. if(skill_point < novice_skills)
  1582. {
  1583. c = MAPID_NOVICE;
  1584. }
  1585. // limit 2nd class and above to first class job levels (super novices are exempt)
  1586. else if (sd->class_&JOBL_2 && (sd->class_&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE)
  1587. {
  1588. // regenerate change_level_2nd
  1589. if (!sd->change_level_2nd)
  1590. {
  1591. if (sd->class_&JOBL_THIRD)
  1592. {
  1593. // if neither 2nd nor 3rd jobchange levels are known, we have to assume a default for 2nd
  1594. if (!sd->change_level_3rd)
  1595. sd->change_level_2nd = job_info[pc_class2idx(pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex))].max_level[1];
  1596. else
  1597. sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
  1598. - (sd->status.job_level - 1)
  1599. - (sd->change_level_3rd - 1)
  1600. - novice_skills;
  1601. }
  1602. else
  1603. {
  1604. sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
  1605. - (sd->status.job_level - 1)
  1606. - novice_skills;
  1607. }
  1608. pc_setglobalreg(sd, add_str("jobchange_level"), sd->change_level_2nd);
  1609. }
  1610. if (skill_point < novice_skills + (sd->change_level_2nd - 1))
  1611. {
  1612. c &= MAPID_BASEMASK;
  1613. }
  1614. // limit 3rd class to 2nd class/trans job levels
  1615. else if(sd->class_&JOBL_THIRD)
  1616. {
  1617. // regenerate change_level_3rd
  1618. if (!sd->change_level_3rd)
  1619. {
  1620. sd->change_level_3rd = 1 + skill_point + sd->status.skill_point
  1621. - (sd->status.job_level - 1)
  1622. - (sd->change_level_2nd - 1)
  1623. - novice_skills;
  1624. pc_setglobalreg(sd, add_str("jobchange_level_3rd"), sd->change_level_3rd);
  1625. }
  1626. if (skill_point < novice_skills + (sd->change_level_2nd - 1) + (sd->change_level_3rd - 1))
  1627. c &= MAPID_UPPERMASK;
  1628. }
  1629. }
  1630. // restore non-limiting flags
  1631. c |= sd->class_&(JOBL_UPPER|JOBL_BABY);
  1632. return c;
  1633. }
  1634. /*==========================================
  1635. * Updates the weight status
  1636. *------------------------------------------
  1637. * 1: overweight 50%
  1638. * 2: overweight 90%
  1639. * It's assumed that SC_WEIGHT50 and SC_WEIGHT90 are only started/stopped here.
  1640. */
  1641. void pc_updateweightstatus(struct map_session_data *sd)
  1642. {
  1643. int old_overweight;
  1644. int new_overweight;
  1645. nullpo_retv(sd);
  1646. old_overweight = (sd->sc.data[SC_WEIGHT90]) ? 2 : (sd->sc.data[SC_WEIGHT50]) ? 1 : 0;
  1647. new_overweight = (pc_is90overweight(sd)) ? 2 : (pc_is50overweight(sd)) ? 1 : 0;
  1648. if( old_overweight == new_overweight )
  1649. return; // no change
  1650. // stop old status change
  1651. if( old_overweight == 1 )
  1652. status_change_end(&sd->bl, SC_WEIGHT50, INVALID_TIMER);
  1653. else if( old_overweight == 2 )
  1654. status_change_end(&sd->bl, SC_WEIGHT90, INVALID_TIMER);
  1655. // start new status change
  1656. if( new_overweight == 1 )
  1657. sc_start(&sd->bl,&sd->bl, SC_WEIGHT50, 100, 0, 0);
  1658. else if( new_overweight == 2 )
  1659. sc_start(&sd->bl,&sd->bl, SC_WEIGHT90, 100, 0, 0);
  1660. // update overweight status
  1661. sd->regen.state.overweight = new_overweight;
  1662. }
  1663. int pc_disguise(struct map_session_data *sd, int class_)
  1664. {
  1665. if (!class_ && !sd->disguise)
  1666. return 0;
  1667. if (class_ && sd->disguise == class_)
  1668. return 0;
  1669. if(sd->sc.option&OPTION_INVISIBLE)
  1670. { //Character is invisible. Stealth class-change. [Skotlex]
  1671. sd->disguise = class_; //viewdata is set on uncloaking.
  1672. return 2;
  1673. }
  1674. if (sd->bl.prev != NULL) {
  1675. pc_stop_walking(sd, 0);
  1676. clif_clearunit_area(&sd->bl, CLR_OUTSIGHT);
  1677. }
  1678. if (!class_) {
  1679. sd->disguise = 0;
  1680. class_ = sd->status.class_;
  1681. } else
  1682. sd->disguise=class_;
  1683. status_set_viewdata(&sd->bl, class_);
  1684. clif_changeoption(&sd->bl);
  1685. if (sd->bl.prev != NULL) {
  1686. clif_spawn(&sd->bl);
  1687. if (class_ == sd->status.class_ && pc_iscarton(sd))
  1688. { //It seems the cart info is lost on undisguise.
  1689. clif_cartlist(sd);
  1690. clif_updatestatus(sd,SP_CARTINFO);
  1691. }
  1692. if (sd->chatID) {
  1693. struct chat_data* cd;
  1694. if ((cd = (struct chat_data*)map_id2bl(sd->chatID)) != NULL)
  1695. clif_dispchat(cd,0);
  1696. }
  1697. }
  1698. return 1;
  1699. }
  1700. /// Show error message
  1701. #define PC_BONUS_SHOW_ERROR(type,type2,val) { ShowError("%s: %s: Invalid %s %d.\n",__FUNCTION__,#type,#type2,(val)); break; }
  1702. /// Check for valid Element, break & show error message if invalid Element
  1703. #define PC_BONUS_CHK_ELEMENT(ele,bonus) { if (!CHK_ELEMENT((ele))) { PC_BONUS_SHOW_ERROR((bonus),Element,(ele)); }}
  1704. /// Check for valid Race, break & show error message if invalid Race
  1705. #define PC_BONUS_CHK_RACE(rc,bonus) { if (!CHK_RACE((rc))) { PC_BONUS_SHOW_ERROR((bonus),Race,(rc)); }}
  1706. /// Check for valid Race2, break & show error message if invalid Race2
  1707. #define PC_BONUS_CHK_RACE2(rc2,bonus) { if (!CHK_RACE2((rc2))) { PC_BONUS_SHOW_ERROR((bonus),Race2,(rc2)); }}
  1708. /// Check for valid Class, break & show error message if invalid Class
  1709. #define PC_BONUS_CHK_CLASS(cl,bonus) { if (!CHK_CLASS((cl))) { PC_BONUS_SHOW_ERROR((bonus),Class,(cl)); }}
  1710. /// Check for valid Size, break & show error message if invalid Size
  1711. #define PC_BONUS_CHK_SIZE(sz,bonus) { if (!CHK_MOBSIZE((sz))) { PC_BONUS_SHOW_ERROR((bonus),Size,(sz)); }}
  1712. /// Check for valid SC, break & show error message if invalid SC
  1713. #define PC_BONUS_CHK_SC(sc,bonus) { if ((sc) <= SC_NONE || (sc) >= SC_MAX) { PC_BONUS_SHOW_ERROR((bonus),Effect,(sc)); }}
  1714. static void pc_bonus_autospell(struct s_autospell *spell, int max, short id, short lv, short rate, short flag, unsigned short card_id)
  1715. {
  1716. uint8 i;
  1717. if( !rate )
  1718. return;
  1719. for( i = 0; i < max && spell[i].id; i++ )
  1720. {
  1721. if( (spell[i].card_id == card_id || spell[i].rate < 0 || rate < 0) && spell[i].id == id && spell[i].lv == lv )
  1722. {
  1723. if( !battle_config.autospell_stacking && spell[i].rate > 0 && rate > 0 )
  1724. return;
  1725. rate += spell[i].rate;
  1726. break;
  1727. }
  1728. }
  1729. if (i == max) {
  1730. ShowWarning("pc_bonus_autospell: Reached max (%d) number of autospells per character!\n", max);
  1731. return;
  1732. }
  1733. spell[i].id = id;
  1734. spell[i].lv = lv;
  1735. spell[i].rate = rate;
  1736. //Auto-update flag value.
  1737. if (!(flag&BF_RANGEMASK)) flag|=BF_SHORT|BF_LONG; //No range defined? Use both.
  1738. if (!(flag&BF_WEAPONMASK)) flag|=BF_WEAPON; //No attack type defined? Use weapon.
  1739. if (!(flag&BF_SKILLMASK)) {
  1740. if (flag&(BF_MAGIC|BF_MISC)) flag|=BF_SKILL; //These two would never trigger without BF_SKILL
  1741. if (flag&BF_WEAPON) flag|=BF_NORMAL; //By default autospells should only trigger on normal weapon attacks.
  1742. }
  1743. spell[i].flag|= flag;
  1744. spell[i].card_id = card_id;
  1745. }
  1746. static void pc_bonus_autospell_onskill(struct s_autospell *spell, int max, short src_skill, short id, short lv, short rate, unsigned short card_id)
  1747. {
  1748. uint8 i;
  1749. if( !rate )
  1750. return;
  1751. for( i = 0; i < max && spell[i].id; i++ )
  1752. {
  1753. ; // each autospell works independently
  1754. }
  1755. if( i == max )
  1756. {
  1757. ShowWarning("pc_bonus_autospell_onskill: Reached max (%d) number of autospells per character!\n", max);
  1758. return;
  1759. }
  1760. spell[i].flag = src_skill;
  1761. spell[i].id = id;
  1762. spell[i].lv = lv;
  1763. spell[i].rate = rate;
  1764. spell[i].card_id = card_id;
  1765. return;
  1766. }
  1767. /**
  1768. * Add inflict effect bonus for player while attacking/atatcked
  1769. * @param effect Effect array
  1770. * @param pmax Max array
  1771. * @param sc SC/Effect type
  1772. * @param rate Success chance
  1773. * @param arrow_rate success chance if bonus comes from arrow-type item
  1774. * @param flag Target flag
  1775. * @param duration Duration. If 0 use default duration lookup for associated skill with level 7
  1776. **/
  1777. static void pc_bonus_addeff(struct s_addeffect* effect, int pmax, enum sc_type sc, short rate, short arrow_rate, unsigned char flag, unsigned int duration)
  1778. {
  1779. uint16 i;
  1780. if (!(flag&(ATF_SHORT|ATF_LONG)))
  1781. flag |= ATF_SHORT|ATF_LONG; //Default range: both
  1782. if (!(flag&(ATF_TARGET|ATF_SELF)))
  1783. flag |= ATF_TARGET; //Default target: enemy.
  1784. if (!(flag&(ATF_WEAPON|ATF_MAGIC|ATF_MISC)))
  1785. flag |= ATF_WEAPON; //Default type: weapon.
  1786. if (!duration)
  1787. duration =(unsigned int) skill_get_time2(status_sc2skill(sc),7);
  1788. for (i = 0; i < pmax && effect[i].flag; i++) {
  1789. if (effect[i].sc == sc && effect[i].flag == flag) {
  1790. effect[i].rate += rate;
  1791. effect[i].arrow_rate += arrow_rate;
  1792. effect[i].duration = umax(effect[i].duration, duration);
  1793. return;
  1794. }
  1795. }
  1796. if (i == pmax) {
  1797. ShowWarning("pc_bonus_addeff: Reached max (%d) number of add effects per character!\n", pmax);
  1798. return;
  1799. }
  1800. effect[i].sc = sc;
  1801. effect[i].rate = rate;
  1802. effect[i].arrow_rate = arrow_rate;
  1803. effect[i].flag = flag;
  1804. effect[i].duration = duration;
  1805. }
  1806. /**
  1807. * Add inflict effect bonus for player while attacking using skill
  1808. * @param effect Effect array
  1809. * @param pmax Max array
  1810. * @param sc SC/Effect type
  1811. * @param rate Success chance
  1812. * @param flag Target flag
  1813. * @param duration Duration. If 0 use default duration lookup for associated skill with level 7
  1814. **/
  1815. static void pc_bonus_addeff_onskill(struct s_addeffectonskill* effect, int pmax, enum sc_type sc, short rate, short skill_id, unsigned char target, unsigned int duration)
  1816. {
  1817. uint8 i;
  1818. if (!duration)
  1819. duration =(unsigned int) skill_get_time2(status_sc2skill(sc),7);
  1820. for( i = 0; i < pmax && effect[i].skill_id; i++ ) {
  1821. if( effect[i].sc == sc && effect[i].skill_id == skill_id && effect[i].target == target ) {
  1822. effect[i].rate += rate;
  1823. effect[i].duration = umax(effect[i].duration, duration);
  1824. return;
  1825. }
  1826. }
  1827. if( i == pmax ) {
  1828. ShowWarning("pc_bonus_addeff_onskill: Reached max (%d) number of add effects on skill per character!\n", pmax);
  1829. return;
  1830. }
  1831. effect[i].sc = sc;
  1832. effect[i].rate = rate;
  1833. effect[i].skill_id = skill_id;
  1834. effect[i].target = target;
  1835. effect[i].duration = duration;
  1836. }
  1837. /** Adjust/add drop rate modifier for player
  1838. * @param drop: Player's sd->add_drop (struct s_add_drop)
  1839. * @param max: Max bonus can be received
  1840. * @param nameid: item id that will be dropped
  1841. * @param group: group id
  1842. * @param class_: target class
  1843. * @param race: target race. if < 0, means monster_id
  1844. * @param rate: rate value: 1 ~ 10000. If < 0, it will be multiplied with mob level/10
  1845. */
  1846. static void pc_bonus_item_drop(struct s_add_drop *drop, const short max, unsigned short nameid, uint16 group, int class_, short race, int rate)
  1847. {
  1848. uint8 i;
  1849. if (!nameid && !group) {
  1850. ShowWarning("pc_bonus_item_drop: No Item ID nor Item Group ID specified.\n");
  1851. return;
  1852. }
  1853. if (nameid && !itemdb_exists(nameid)) {
  1854. ShowWarning("pc_bonus_item_drop: Invalid item id %hu\n",nameid);
  1855. return;
  1856. }
  1857. if (group && !itemdb_group_exists(group)) {
  1858. ShowWarning("pc_bonus_item_drop: Invalid Item Group %hu\n",group);
  1859. return;
  1860. }
  1861. //Apply config rate adjustment settings.
  1862. if (rate >= 0) { //Absolute drop.
  1863. if (battle_config.item_rate_adddrop != 100)
  1864. rate = rate*battle_config.item_rate_adddrop/100;
  1865. if (rate < battle_config.item_drop_adddrop_min)
  1866. rate = battle_config.item_drop_adddrop_min;
  1867. else if (rate > battle_config.item_drop_adddrop_max)
  1868. rate = battle_config.item_drop_adddrop_max;
  1869. } else { //Relative drop, max/min limits are applied at drop time.
  1870. if (battle_config.item_rate_adddrop != 100)
  1871. rate = rate*battle_config.item_rate_adddrop/100;
  1872. if (rate > -1)
  1873. rate = -1;
  1874. }
  1875. //Find match entry, and adjust the rate only
  1876. for (i = 0; i < max; i++) {
  1877. if (!&drop[i] || (!drop[i].nameid && !drop[i].group))
  1878. continue;
  1879. if (drop[i].nameid == nameid &&
  1880. drop[i].group == group &&
  1881. drop[i].race == race &&
  1882. drop[i].class_ == class_
  1883. )
  1884. {
  1885. //Adjust the rate if it has same classification
  1886. if ((rate < 0 && drop[i].rate < 0) ||
  1887. (rate > 0 && drop[i].rate > 0))
  1888. {
  1889. drop[i].rate += rate;
  1890. return;
  1891. }
  1892. }
  1893. }
  1894. ARR_FIND(0,max,i,!&drop[i] || (drop[i].nameid == 0 && drop[i].group == 0));
  1895. if (i >= max) {
  1896. ShowWarning("pc_bonus_item_drop: Reached max (%d) number of added drops per character! (nameid:%hu group:%d class_:%d race:%d rate:%d)\n",max,nameid,group,class_,race,rate);
  1897. return;
  1898. }
  1899. drop[i].nameid = nameid;
  1900. drop[i].group = group;
  1901. drop[i].race = race;
  1902. drop[i].class_ = class_;
  1903. drop[i].rate = rate;
  1904. }
  1905. bool pc_addautobonus(struct s_autobonus *bonus,char max,const char *script,short rate,unsigned int dur,short flag,const char *other_script,unsigned int pos,bool onskill)
  1906. {
  1907. int i;
  1908. ARR_FIND(0, max, i, bonus[i].rate == 0);
  1909. if( i == max )
  1910. {
  1911. ShowWarning("pc_addautobonus: Reached max (%d) number of autobonus per character!\n", max);
  1912. return false;
  1913. }
  1914. if( !onskill )
  1915. {
  1916. if( !(flag&BF_RANGEMASK) )
  1917. flag|=BF_SHORT|BF_LONG; //No range defined? Use both.
  1918. if( !(flag&BF_WEAPONMASK) )
  1919. flag|=BF_WEAPON; //No attack type defined? Use weapon.
  1920. if( !(flag&BF_SKILLMASK) )
  1921. {
  1922. if( flag&(BF_MAGIC|BF_MISC) )
  1923. flag|=BF_SKILL; //These two would never trigger without BF_SKILL
  1924. if( flag&BF_WEAPON )
  1925. flag|=BF_NORMAL|BF_SKILL;
  1926. }
  1927. }
  1928. bonus[i].rate = rate;
  1929. bonus[i].duration = dur;
  1930. bonus[i].active = INVALID_TIMER;
  1931. bonus[i].atk_type = flag;
  1932. bonus[i].pos = pos;
  1933. bonus[i].bonus_script = aStrdup(script);
  1934. bonus[i].other_script = other_script?aStrdup(other_script):NULL;
  1935. return true;
  1936. }
  1937. void pc_delautobonus(struct map_session_data* sd, struct s_autobonus *autobonus,char max,bool restore)
  1938. {
  1939. int i;
  1940. if (!sd)
  1941. return;
  1942. for( i = 0; i < max; i++ )
  1943. {
  1944. if( autobonus[i].active != INVALID_TIMER )
  1945. {
  1946. if( restore && (sd->state.autobonus&autobonus[i].pos) == autobonus[i].pos)
  1947. {
  1948. if( autobonus[i].bonus_script )
  1949. {
  1950. int j;
  1951. unsigned int equip_pos_idx = 0;
  1952. //Create a list of all equipped positions to see if all items needed for the autobonus are still present [Playtester]
  1953. for(j = 0; j < EQI_MAX; j++) {
  1954. if(sd->equip_index[j] >= 0)
  1955. equip_pos_idx |= sd->status.inventory[sd->equip_index[j]].equip;
  1956. }
  1957. if((equip_pos_idx&autobonus[i].pos) == autobonus[i].pos)
  1958. script_run_autobonus(autobonus[i].bonus_script,sd,autobonus[i].pos);
  1959. }
  1960. continue;
  1961. }
  1962. else
  1963. { // Logout / Unequipped an item with an activated bonus
  1964. delete_timer(autobonus[i].active,pc_endautobonus);
  1965. autobonus[i].active = INVALID_TIMER;
  1966. }
  1967. }
  1968. if( autobonus[i].bonus_script ) aFree(autobonus[i].bonus_script);
  1969. if( autobonus[i].other_script ) aFree(autobonus[i].other_script);
  1970. autobonus[i].bonus_script = autobonus[i].other_script = NULL;
  1971. autobonus[i].rate = autobonus[i].atk_type = autobonus[i].duration = autobonus[i].pos = 0;
  1972. autobonus[i].active = INVALID_TIMER;
  1973. }
  1974. }
  1975. void pc_exeautobonus(struct map_session_data *sd,struct s_autobonus *autobonus)
  1976. {
  1977. if (!sd || !autobonus)
  1978. return;
  1979. if( autobonus->other_script )
  1980. {
  1981. int j;
  1982. unsigned int equip_pos_idx = 0;
  1983. //Create a list of all equipped positions to see if all items needed for the autobonus are still present [Playtester]
  1984. for(j = 0; j < EQI_MAX; j++) {
  1985. if(sd->equip_index[j] >= 0)
  1986. equip_pos_idx |= sd->status.inventory[sd->equip_index[j]].equip;
  1987. }
  1988. if((equip_pos_idx&autobonus->pos) == autobonus->pos)
  1989. script_run_autobonus(autobonus->other_script,sd,autobonus->pos);
  1990. }
  1991. autobonus->active = add_timer(gettick()+autobonus->duration, pc_endautobonus, sd->bl.id, (intptr_t)autobonus);
  1992. sd->state.autobonus |= autobonus->pos;
  1993. status_calc_pc(sd,SCO_FORCE);
  1994. }
  1995. int pc_endautobonus(int tid, unsigned int tick, int id, intptr_t data)
  1996. {
  1997. struct map_session_data *sd = map_id2sd(id);
  1998. struct s_autobonus *autobonus = (struct s_autobonus *)data;
  1999. nullpo_ret(sd);
  2000. nullpo_ret(autobonus);
  2001. autobonus->active = INVALID_TIMER;
  2002. sd->state.autobonus &= ~autobonus->pos;
  2003. status_calc_pc(sd,SCO_FORCE);
  2004. return 0;
  2005. }
  2006. static void pc_bonus_addele(struct map_session_data* sd, unsigned char ele, short rate, short flag)
  2007. {
  2008. uint8 i;
  2009. struct weapon_data* wd;
  2010. wd = (sd->state.lr_flag ? &sd->left_weapon : &sd->right_weapon);
  2011. ARR_FIND(0, MAX_PC_BONUS, i, wd->addele2[i].rate == 0);
  2012. if (i == MAX_PC_BONUS)
  2013. {
  2014. ShowWarning("pc_bonus_addele: Reached max (%d) possible bonuses for this player.\n", MAX_PC_BONUS);
  2015. return;
  2016. }
  2017. if (!(flag&BF_RANGEMASK))
  2018. flag |= BF_SHORT|BF_LONG;
  2019. if (!(flag&BF_WEAPONMASK))
  2020. flag |= BF_WEAPON;
  2021. if (!(flag&BF_SKILLMASK))
  2022. {
  2023. if (flag&(BF_MAGIC|BF_MISC))
  2024. flag |= BF_SKILL;
  2025. if (flag&BF_WEAPON)
  2026. flag |= BF_NORMAL|BF_SKILL;
  2027. }
  2028. wd->addele2[i].ele = ele;
  2029. wd->addele2[i].rate = rate;
  2030. wd->addele2[i].flag = flag;
  2031. }
  2032. static void pc_bonus_subele(struct map_session_data* sd, unsigned char ele, short rate, short flag)
  2033. {
  2034. uint8 i;
  2035. ARR_FIND(0, MAX_PC_BONUS, i, sd->subele2[i].rate == 0);
  2036. if (i == MAX_PC_BONUS)
  2037. {
  2038. ShowWarning("pc_bonus_subele: Reached max (%d) possible bonuses for this player.\n", MAX_PC_BONUS);
  2039. return;
  2040. }
  2041. if (!(flag&BF_RANGEMASK))
  2042. flag |= BF_SHORT|BF_LONG;
  2043. if (!(flag&BF_WEAPONMASK))
  2044. flag |= BF_WEAPON;
  2045. if (!(flag&BF_SKILLMASK))
  2046. {
  2047. if (flag&(BF_MAGIC|BF_MISC))
  2048. flag |= BF_SKILL;
  2049. if (flag&BF_WEAPON)
  2050. flag |= BF_NORMAL|BF_SKILL;
  2051. }
  2052. sd->subele2[i].ele = ele;
  2053. sd->subele2[i].rate = rate;
  2054. sd->subele2[i].flag = flag;
  2055. }
  2056. /** Add item group heal rate bonus to player
  2057. * @param sd Player
  2058. * @param group_id Item Group ID
  2059. * @param rate
  2060. * @author Cydh
  2061. */
  2062. void pc_itemgrouphealrate(struct map_session_data *sd, uint16 group_id, short rate) {
  2063. struct s_pc_itemgrouphealrate *entry;
  2064. uint8 i;
  2065. for (i = 0; i < sd->itemgrouphealrate_count; i++) {
  2066. if (sd->itemgrouphealrate[i]->group_id == group_id)
  2067. break;
  2068. }
  2069. if (i != sd->itemgrouphealrate_count) {
  2070. sd->itemgrouphealrate[i]->rate += rate;
  2071. return;
  2072. }
  2073. if (i >= UINT8_MAX) {
  2074. ShowError("pc_itemgrouphealrate_add: Reached max (%d) possible bonuses for this player %d\n", UINT8_MAX);
  2075. return;
  2076. }
  2077. entry = ers_alloc(pc_itemgrouphealrate_ers, struct s_pc_itemgrouphealrate);
  2078. entry->group_id = group_id;
  2079. entry->rate = rate;
  2080. RECREATE(sd->itemgrouphealrate, struct s_pc_itemgrouphealrate *, sd->itemgrouphealrate_count+1);
  2081. sd->itemgrouphealrate[sd->itemgrouphealrate_count++] = entry;
  2082. }
  2083. /** Clear item group heal rate from player
  2084. * @param sd Player
  2085. * @author Cydh
  2086. */
  2087. void pc_itemgrouphealrate_clear(struct map_session_data *sd) {
  2088. if (!sd || !sd->itemgrouphealrate_count)
  2089. return;
  2090. else {
  2091. uint8 i;
  2092. for( i = 0; i < sd->itemgrouphealrate_count; i++ )
  2093. ers_free(pc_itemgrouphealrate_ers, sd->itemgrouphealrate[i]);
  2094. sd->itemgrouphealrate_count = 0;
  2095. aFree(sd->itemgrouphealrate);
  2096. sd->itemgrouphealrate = NULL;
  2097. }
  2098. }
  2099. /*==========================================
  2100. * Add a bonus(type) to player sd
  2101. * format: bonus bBonusName,val;
  2102. * @param sd
  2103. * @param type Bonus type used by bBonusName
  2104. * @param val Value that usually for rate or fixed value
  2105. *------------------------------------------*/
  2106. void pc_bonus(struct map_session_data *sd,int type,int val)
  2107. {
  2108. struct status_data *status;
  2109. int bonus;
  2110. nullpo_retv(sd);
  2111. status = &sd->base_status;
  2112. switch(type){
  2113. case SP_STR:
  2114. case SP_AGI:
  2115. case SP_VIT:
  2116. case SP_INT:
  2117. case SP_DEX:
  2118. case SP_LUK:
  2119. if(sd->state.lr_flag != 2)
  2120. sd->param_bonus[type-SP_STR]+=val;
  2121. break;
  2122. case SP_ATK1:
  2123. if(!sd->state.lr_flag) {
  2124. bonus = status->rhw.atk + val;
  2125. status->rhw.atk = cap_value(bonus, 0, USHRT_MAX);
  2126. }
  2127. else if(sd->state.lr_flag == 1) {
  2128. bonus = status->lhw.atk + val;
  2129. status->lhw.atk = cap_value(bonus, 0, USHRT_MAX);
  2130. }
  2131. break;
  2132. case SP_ATK2:
  2133. if(!sd->state.lr_flag) {
  2134. bonus = status->rhw.atk2 + val;
  2135. status->rhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
  2136. }
  2137. else if(sd->state.lr_flag == 1) {
  2138. bonus = status->lhw.atk2 + val;
  2139. status->lhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
  2140. }
  2141. break;
  2142. case SP_BASE_ATK:
  2143. if(sd->state.lr_flag != 2) {
  2144. #ifdef RENEWAL
  2145. sd->bonus.eatk += val;
  2146. #else
  2147. bonus = status->batk + val;
  2148. status->batk = cap_value(bonus, 0, USHRT_MAX);
  2149. #endif
  2150. }
  2151. break;
  2152. case SP_DEF1:
  2153. if(sd->state.lr_flag != 2) {
  2154. bonus = status->def + val;
  2155. #ifdef RENEWAL
  2156. status->def = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2157. #else
  2158. status->def = cap_value(bonus, CHAR_MIN, CHAR_MAX);
  2159. #endif
  2160. }
  2161. break;
  2162. case SP_DEF2:
  2163. if(sd->state.lr_flag != 2) {
  2164. bonus = status->def2 + val;
  2165. status->def2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2166. }
  2167. break;
  2168. case SP_MDEF1:
  2169. if(sd->state.lr_flag != 2) {
  2170. bonus = status->mdef + val;
  2171. #ifdef RENEWAL
  2172. status->mdef = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2173. #else
  2174. status->mdef = cap_value(bonus, CHAR_MIN, CHAR_MAX);
  2175. #endif
  2176. if( sd->state.lr_flag == 3 ) {//Shield, used for royal guard
  2177. sd->bonus.shieldmdef += bonus;
  2178. }
  2179. }
  2180. break;
  2181. case SP_MDEF2:
  2182. if(sd->state.lr_flag != 2) {
  2183. bonus = status->mdef2 + val;
  2184. status->mdef2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2185. }
  2186. break;
  2187. case SP_HIT:
  2188. if(sd->state.lr_flag != 2) {
  2189. bonus = status->hit + val;
  2190. status->hit = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2191. } else
  2192. sd->bonus.arrow_hit+=val;
  2193. break;
  2194. case SP_FLEE1:
  2195. if(sd->state.lr_flag != 2) {
  2196. bonus = status->flee + val;
  2197. status->flee = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2198. }
  2199. break;
  2200. case SP_FLEE2:
  2201. if(sd->state.lr_flag != 2) {
  2202. bonus = status->flee2 + val*10;
  2203. status->flee2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2204. }
  2205. break;
  2206. case SP_CRITICAL:
  2207. if(sd->state.lr_flag != 2) {
  2208. bonus = status->cri + val*10;
  2209. status->cri = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2210. } else
  2211. sd->bonus.arrow_cri += val*10;
  2212. break;
  2213. case SP_ATKELE:
  2214. PC_BONUS_CHK_ELEMENT(val,SP_ATKELE);
  2215. switch (sd->state.lr_flag)
  2216. {
  2217. case 2:
  2218. switch (sd->status.weapon) {
  2219. case W_BOW:
  2220. case W_REVOLVER:
  2221. case W_RIFLE:
  2222. case W_GATLING:
  2223. case W_SHOTGUN:
  2224. case W_GRENADE:
  2225. //Become weapon element.
  2226. status->rhw.ele=val;
  2227. break;
  2228. default: //Become arrow element.
  2229. sd->bonus.arrow_ele=val;
  2230. break;
  2231. }
  2232. break;
  2233. case 1:
  2234. status->lhw.ele=val;
  2235. break;
  2236. default:
  2237. status->rhw.ele=val;
  2238. break;
  2239. }
  2240. break;
  2241. case SP_DEFELE:
  2242. PC_BONUS_CHK_ELEMENT(val,SP_DEFELE);
  2243. if(sd->state.lr_flag != 2)
  2244. status->def_ele=val;
  2245. break;
  2246. case SP_MAXHP:
  2247. if(sd->state.lr_flag == 2)
  2248. break;
  2249. sd->bonus.hp += val;
  2250. break;
  2251. case SP_MAXSP:
  2252. if(sd->state.lr_flag == 2)
  2253. break;
  2254. sd->bonus.sp += val;
  2255. break;
  2256. case SP_MAXHPRATE:
  2257. if(sd->state.lr_flag != 2)
  2258. sd->hprate+=val;
  2259. break;
  2260. case SP_MAXSPRATE:
  2261. if(sd->state.lr_flag != 2)
  2262. sd->sprate+=val;
  2263. break;
  2264. case SP_SPRATE:
  2265. if(sd->state.lr_flag != 2)
  2266. sd->dsprate+=val;
  2267. break;
  2268. case SP_ATTACKRANGE:
  2269. switch (sd->state.lr_flag) {
  2270. case 2:
  2271. switch (sd->status.weapon) {
  2272. case W_BOW:
  2273. case W_REVOLVER:
  2274. case W_RIFLE:
  2275. case W_GATLING:
  2276. case W_SHOTGUN:
  2277. case W_GRENADE:
  2278. status->rhw.range += val;
  2279. }
  2280. break;
  2281. case 1:
  2282. status->lhw.range += val;
  2283. break;
  2284. default:
  2285. status->rhw.range += val;
  2286. break;
  2287. }
  2288. break;
  2289. case SP_SPEED_RATE: //Non stackable increase
  2290. if(sd->state.lr_flag != 2)
  2291. sd->bonus.speed_rate = min(sd->bonus.speed_rate, -val);
  2292. break;
  2293. case SP_SPEED_ADDRATE: //Stackable increase
  2294. if(sd->state.lr_flag != 2)
  2295. sd->bonus.speed_add_rate -= val;
  2296. break;
  2297. case SP_ASPD: //Raw increase
  2298. if(sd->state.lr_flag != 2)
  2299. sd->bonus.aspd_add -= 10*val;
  2300. break;
  2301. case SP_ASPD_RATE: //Stackable increase - Made it linear as per rodatazone
  2302. if(sd->state.lr_flag != 2)
  2303. #ifndef RENEWAL_ASPD
  2304. status->aspd_rate -= 10*val;
  2305. #else
  2306. status->aspd_rate2 += val;
  2307. #endif
  2308. break;
  2309. case SP_HP_RECOV_RATE:
  2310. if(sd->state.lr_flag != 2)
  2311. sd->hprecov_rate += val;
  2312. break;
  2313. case SP_SP_RECOV_RATE:
  2314. if(sd->state.lr_flag != 2)
  2315. sd->sprecov_rate += val;
  2316. break;
  2317. case SP_CRITICAL_DEF:
  2318. if(sd->state.lr_flag != 2)
  2319. sd->bonus.critical_def += val;
  2320. break;
  2321. case SP_NEAR_ATK_DEF:
  2322. if(sd->state.lr_flag != 2)
  2323. sd->bonus.near_attack_def_rate += val;
  2324. break;
  2325. case SP_LONG_ATK_DEF:
  2326. if(sd->state.lr_flag != 2)
  2327. sd->bonus.long_attack_def_rate += val;
  2328. break;
  2329. case SP_DOUBLE_RATE:
  2330. if(sd->state.lr_flag == 0 && sd->bonus.double_rate < val)
  2331. sd->bonus.double_rate = val;
  2332. break;
  2333. case SP_DOUBLE_ADD_RATE:
  2334. if(sd->state.lr_flag == 0)
  2335. sd->bonus.double_add_rate += val;
  2336. break;
  2337. case SP_MATK_RATE:
  2338. if(sd->state.lr_flag != 2)
  2339. sd->matk_rate += val;
  2340. break;
  2341. case SP_IGNORE_DEF_ELE:
  2342. PC_BONUS_CHK_ELEMENT(val,SP_IGNORE_DEF_ELE);
  2343. if(!sd->state.lr_flag)
  2344. sd->right_weapon.ignore_def_ele |= 1<<val;
  2345. else if(sd->state.lr_flag == 1)
  2346. sd->left_weapon.ignore_def_ele |= 1<<val;
  2347. break;
  2348. case SP_IGNORE_DEF_RACE:
  2349. PC_BONUS_CHK_RACE(val,SP_IGNORE_DEF_RACE);
  2350. if(!sd->state.lr_flag)
  2351. sd->right_weapon.ignore_def_race |= 1<<val;
  2352. else if(sd->state.lr_flag == 1)
  2353. sd->left_weapon.ignore_def_race |= 1<<val;
  2354. break;
  2355. case SP_IGNORE_DEF_CLASS:
  2356. PC_BONUS_CHK_CLASS(val,SP_IGNORE_DEF_CLASS);
  2357. if(!sd->state.lr_flag)
  2358. sd->right_weapon.ignore_def_class |= 1<<val;
  2359. else if(sd->state.lr_flag == 1)
  2360. sd->left_weapon.ignore_def_class |= 1<<val;
  2361. break;
  2362. case SP_ATK_RATE:
  2363. if(sd->state.lr_flag != 2)
  2364. sd->bonus.atk_rate += val;
  2365. break;
  2366. case SP_MAGIC_ATK_DEF:
  2367. if(sd->state.lr_flag != 2)
  2368. sd->bonus.magic_def_rate += val;
  2369. break;
  2370. case SP_MISC_ATK_DEF:
  2371. if(sd->state.lr_flag != 2)
  2372. sd->bonus.misc_def_rate += val;
  2373. break;
  2374. case SP_IGNORE_MDEF_ELE:
  2375. PC_BONUS_CHK_ELEMENT(val,SP_IGNORE_MDEF_ELE);
  2376. if(sd->state.lr_flag != 2)
  2377. sd->bonus.ignore_mdef_ele |= 1<<val;
  2378. break;
  2379. case SP_IGNORE_MDEF_RACE:
  2380. PC_BONUS_CHK_RACE(val,SP_IGNORE_MDEF_RACE);
  2381. if(sd->state.lr_flag != 2)
  2382. sd->bonus.ignore_mdef_race |= 1<<val;
  2383. break;
  2384. case SP_PERFECT_HIT_RATE:
  2385. if(sd->state.lr_flag != 2 && sd->bonus.perfect_hit < val)
  2386. sd->bonus.perfect_hit = val;
  2387. break;
  2388. case SP_PERFECT_HIT_ADD_RATE:
  2389. if(sd->state.lr_flag != 2)
  2390. sd->bonus.perfect_hit_add += val;
  2391. break;
  2392. case SP_CRITICAL_RATE:
  2393. if(sd->state.lr_flag != 2)
  2394. sd->critical_rate+=val;
  2395. break;
  2396. case SP_DEF_RATIO_ATK_ELE:
  2397. PC_BONUS_CHK_ELEMENT(val,SP_DEF_RATIO_ATK_ELE);
  2398. if(!sd->state.lr_flag)
  2399. sd->right_weapon.def_ratio_atk_ele |= 1<<val;
  2400. else if(sd->state.lr_flag == 1)
  2401. sd->left_weapon.def_ratio_atk_ele |= 1<<val;
  2402. break;
  2403. case SP_DEF_RATIO_ATK_RACE:
  2404. PC_BONUS_CHK_RACE(val,SP_DEF_RATIO_ATK_RACE);
  2405. if(!sd->state.lr_flag)
  2406. sd->right_weapon.def_ratio_atk_race |= 1<<val;
  2407. else if(sd->state.lr_flag == 1)
  2408. sd->left_weapon.def_ratio_atk_race |= 1<<val;
  2409. break;
  2410. case SP_DEF_RATIO_ATK_CLASS:
  2411. PC_BONUS_CHK_CLASS(val,SP_DEF_RATIO_ATK_CLASS);
  2412. if(!sd->state.lr_flag)
  2413. sd->right_weapon.def_ratio_atk_class |= 1<<val;
  2414. else if(sd->state.lr_flag == 1)
  2415. sd->left_weapon.def_ratio_atk_class |= 1<<val;
  2416. break;
  2417. case SP_HIT_RATE:
  2418. if(sd->state.lr_flag != 2)
  2419. sd->hit_rate += val;
  2420. break;
  2421. case SP_FLEE_RATE:
  2422. if(sd->state.lr_flag != 2)
  2423. sd->flee_rate += val;
  2424. break;
  2425. case SP_FLEE2_RATE:
  2426. if(sd->state.lr_flag != 2)
  2427. sd->flee2_rate += val;
  2428. break;
  2429. case SP_DEF_RATE:
  2430. if(sd->state.lr_flag != 2)
  2431. sd->def_rate += val;
  2432. break;
  2433. case SP_DEF2_RATE:
  2434. if(sd->state.lr_flag != 2)
  2435. sd->def2_rate += val;
  2436. break;
  2437. case SP_MDEF_RATE:
  2438. if(sd->state.lr_flag != 2)
  2439. sd->mdef_rate += val;
  2440. break;
  2441. case SP_MDEF2_RATE:
  2442. if(sd->state.lr_flag != 2)
  2443. sd->mdef2_rate += val;
  2444. break;
  2445. case SP_RESTART_FULL_RECOVER:
  2446. if(sd->state.lr_flag != 2)
  2447. sd->special_state.restart_full_recover = 1;
  2448. break;
  2449. case SP_NO_CASTCANCEL:
  2450. if(sd->state.lr_flag != 2)
  2451. sd->special_state.no_castcancel = 1;
  2452. break;
  2453. case SP_NO_CASTCANCEL2:
  2454. if(sd->state.lr_flag != 2)
  2455. sd->special_state.no_castcancel2 = 1;
  2456. break;
  2457. case SP_NO_SIZEFIX:
  2458. if(sd->state.lr_flag != 2)
  2459. sd->special_state.no_sizefix = 1;
  2460. break;
  2461. case SP_NO_MAGIC_DAMAGE:
  2462. if(sd->state.lr_flag == 2)
  2463. break;
  2464. val+= sd->special_state.no_magic_damage;
  2465. sd->special_state.no_magic_damage = cap_value(val,0,100);
  2466. break;
  2467. case SP_NO_WEAPON_DAMAGE:
  2468. if(sd->state.lr_flag == 2)
  2469. break;
  2470. val+= sd->special_state.no_weapon_damage;
  2471. sd->special_state.no_weapon_damage = cap_value(val,0,100);
  2472. break;
  2473. case SP_NO_MISC_DAMAGE:
  2474. if(sd->state.lr_flag == 2)
  2475. break;
  2476. val+= sd->special_state.no_misc_damage;
  2477. sd->special_state.no_misc_damage = cap_value(val,0,100);
  2478. break;
  2479. case SP_NO_GEMSTONE:
  2480. if(sd->state.lr_flag != 2 && sd->special_state.no_gemstone != 2)
  2481. sd->special_state.no_gemstone = 1;
  2482. break;
  2483. case SP_INTRAVISION: // Maya Purple Card effect allowing to see Hiding/Cloaking people [DracoRPG]
  2484. if(sd->state.lr_flag != 2) {
  2485. sd->special_state.intravision = 1;
  2486. clif_status_load(&sd->bl, SI_INTRAVISION, 1);
  2487. }
  2488. break;
  2489. case SP_NO_KNOCKBACK:
  2490. if(sd->state.lr_flag != 2)
  2491. sd->special_state.no_knockback = 1;
  2492. break;
  2493. case SP_SPLASH_RANGE:
  2494. if(sd->bonus.splash_range < val)
  2495. sd->bonus.splash_range = val;
  2496. break;
  2497. case SP_SPLASH_ADD_RANGE:
  2498. sd->bonus.splash_add_range += val;
  2499. break;
  2500. case SP_SHORT_WEAPON_DAMAGE_RETURN:
  2501. if(sd->state.lr_flag != 2)
  2502. sd->bonus.short_weapon_damage_return += val;
  2503. break;
  2504. case SP_LONG_WEAPON_DAMAGE_RETURN:
  2505. if(sd->state.lr_flag != 2)
  2506. sd->bonus.long_weapon_damage_return += val;
  2507. break;
  2508. case SP_MAGIC_DAMAGE_RETURN: //AppleGirl Was Here
  2509. if(sd->state.lr_flag != 2)
  2510. sd->bonus.magic_damage_return += val;
  2511. break;
  2512. case SP_ALL_STATS: // [Valaris]
  2513. if(sd->state.lr_flag!=2) {
  2514. sd->param_bonus[SP_STR-SP_STR]+=val;
  2515. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2516. sd->param_bonus[SP_VIT-SP_STR]+=val;
  2517. sd->param_bonus[SP_INT-SP_STR]+=val;
  2518. sd->param_bonus[SP_DEX-SP_STR]+=val;
  2519. sd->param_bonus[SP_LUK-SP_STR]+=val;
  2520. }
  2521. break;
  2522. case SP_AGI_VIT: // [Valaris]
  2523. if(sd->state.lr_flag!=2) {
  2524. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2525. sd->param_bonus[SP_VIT-SP_STR]+=val;
  2526. }
  2527. break;
  2528. case SP_AGI_DEX_STR: // [Valaris]
  2529. if(sd->state.lr_flag!=2) {
  2530. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2531. sd->param_bonus[SP_DEX-SP_STR]+=val;
  2532. sd->param_bonus[SP_STR-SP_STR]+=val;
  2533. }
  2534. break;
  2535. case SP_PERFECT_HIDE: // [Valaris]
  2536. if(sd->state.lr_flag!=2)
  2537. sd->special_state.perfect_hiding=1;
  2538. break;
  2539. case SP_UNBREAKABLE:
  2540. if(sd->state.lr_flag!=2)
  2541. sd->bonus.unbreakable += val;
  2542. break;
  2543. case SP_UNBREAKABLE_WEAPON:
  2544. if(sd->state.lr_flag != 2)
  2545. sd->bonus.unbreakable_equip |= EQP_WEAPON;
  2546. break;
  2547. case SP_UNBREAKABLE_ARMOR:
  2548. if(sd->state.lr_flag != 2)
  2549. sd->bonus.unbreakable_equip |= EQP_ARMOR;
  2550. break;
  2551. case SP_UNBREAKABLE_HELM:
  2552. if(sd->state.lr_flag != 2)
  2553. sd->bonus.unbreakable_equip |= EQP_HELM;
  2554. break;
  2555. case SP_UNBREAKABLE_SHIELD:
  2556. if(sd->state.lr_flag != 2)
  2557. sd->bonus.unbreakable_equip |= EQP_SHIELD;
  2558. break;
  2559. case SP_UNBREAKABLE_GARMENT:
  2560. if(sd->state.lr_flag != 2)
  2561. sd->bonus.unbreakable_equip |= EQP_GARMENT;
  2562. break;
  2563. case SP_UNBREAKABLE_SHOES:
  2564. if(sd->state.lr_flag != 2)
  2565. sd->bonus.unbreakable_equip |= EQP_SHOES;
  2566. break;
  2567. case SP_CLASSCHANGE: // [Valaris]
  2568. if(sd->state.lr_flag !=2)
  2569. sd->bonus.classchange=val;
  2570. break;
  2571. case SP_LONG_ATK_RATE:
  2572. if(sd->state.lr_flag != 2) //[Lupus] it should stack, too. As any other cards rate bonuses
  2573. sd->bonus.long_attack_atk_rate+=val;
  2574. break;
  2575. case SP_BREAK_WEAPON_RATE:
  2576. if(sd->state.lr_flag != 2)
  2577. sd->bonus.break_weapon_rate+=val;
  2578. break;
  2579. case SP_BREAK_ARMOR_RATE:
  2580. if(sd->state.lr_flag != 2)
  2581. sd->bonus.break_armor_rate+=val;
  2582. break;
  2583. case SP_ADD_STEAL_RATE:
  2584. if(sd->state.lr_flag != 2)
  2585. sd->bonus.add_steal_rate+=val;
  2586. break;
  2587. case SP_DELAYRATE:
  2588. if(sd->state.lr_flag != 2)
  2589. sd->delayrate+=val;
  2590. break;
  2591. case SP_CRIT_ATK_RATE:
  2592. if(sd->state.lr_flag != 2)
  2593. sd->bonus.crit_atk_rate += val;
  2594. break;
  2595. case SP_NO_REGEN:
  2596. if(sd->state.lr_flag != 2)
  2597. sd->regen.state.block|=val;
  2598. break;
  2599. case SP_UNSTRIPABLE_WEAPON:
  2600. if(sd->state.lr_flag != 2)
  2601. sd->bonus.unstripable_equip |= EQP_WEAPON;
  2602. break;
  2603. case SP_UNSTRIPABLE:
  2604. case SP_UNSTRIPABLE_ARMOR:
  2605. if(sd->state.lr_flag != 2)
  2606. sd->bonus.unstripable_equip |= EQP_ARMOR;
  2607. break;
  2608. case SP_UNSTRIPABLE_HELM:
  2609. if(sd->state.lr_flag != 2)
  2610. sd->bonus.unstripable_equip |= EQP_HELM;
  2611. break;
  2612. case SP_UNSTRIPABLE_SHIELD:
  2613. if(sd->state.lr_flag != 2)
  2614. sd->bonus.unstripable_equip |= EQP_SHIELD;
  2615. break;
  2616. case SP_HP_DRAIN_VALUE: // bonus bHPDrainValue,n;
  2617. if(!sd->state.lr_flag) {
  2618. sd->right_weapon.hp_drain_class[CLASS_NORMAL] += val;
  2619. sd->right_weapon.hp_drain_class[CLASS_BOSS] += val;
  2620. } else if(sd->state.lr_flag == 1) {
  2621. sd->left_weapon.hp_drain_class[CLASS_NORMAL] += val;
  2622. sd->left_weapon.hp_drain_class[CLASS_BOSS] += val;
  2623. }
  2624. break;
  2625. case SP_SP_DRAIN_VALUE: // bonus bSPDrainValue,n;
  2626. if(!sd->state.lr_flag) {
  2627. sd->right_weapon.sp_drain_class[CLASS_NORMAL] += val;
  2628. sd->right_weapon.sp_drain_class[CLASS_BOSS] += val;
  2629. } else if(sd->state.lr_flag == 1) {
  2630. sd->left_weapon.sp_drain_class[CLASS_NORMAL] += val;
  2631. sd->left_weapon.sp_drain_class[CLASS_BOSS] += val;
  2632. }
  2633. break;
  2634. case SP_SP_GAIN_VALUE:
  2635. if(!sd->state.lr_flag)
  2636. sd->bonus.sp_gain_value += val;
  2637. break;
  2638. case SP_HP_GAIN_VALUE:
  2639. if(!sd->state.lr_flag)
  2640. sd->bonus.hp_gain_value += val;
  2641. break;
  2642. case SP_MAGIC_SP_GAIN_VALUE:
  2643. if(!sd->state.lr_flag)
  2644. sd->bonus.magic_sp_gain_value += val;
  2645. break;
  2646. case SP_MAGIC_HP_GAIN_VALUE:
  2647. if(!sd->state.lr_flag)
  2648. sd->bonus.magic_hp_gain_value += val;
  2649. break;
  2650. case SP_ADD_HEAL_RATE:
  2651. if(sd->state.lr_flag != 2)
  2652. sd->bonus.add_heal_rate += val;
  2653. break;
  2654. case SP_ADD_HEAL2_RATE:
  2655. if(sd->state.lr_flag != 2)
  2656. sd->bonus.add_heal2_rate += val;
  2657. break;
  2658. case SP_ADD_ITEM_HEAL_RATE:
  2659. if(sd->state.lr_flag != 2)
  2660. sd->bonus.itemhealrate2 += val;
  2661. break;
  2662. case SP_EMATK:
  2663. if(sd->state.lr_flag != 2)
  2664. sd->bonus.ematk += val;
  2665. break;
  2666. #ifdef RENEWAL_CAST
  2667. case SP_FIXCASTRATE:
  2668. if(sd->state.lr_flag != 2)
  2669. sd->bonus.fixcastrate = min(sd->bonus.fixcastrate,val);
  2670. break;
  2671. case SP_ADD_FIXEDCAST:
  2672. if(sd->state.lr_flag != 2)
  2673. sd->bonus.add_fixcast += val;
  2674. break;
  2675. case SP_CASTRATE:
  2676. case SP_VARCASTRATE:
  2677. if(sd->state.lr_flag != 2)
  2678. sd->bonus.varcastrate -= val;
  2679. break;
  2680. case SP_ADD_VARIABLECAST:
  2681. if(sd->state.lr_flag != 2)
  2682. sd->bonus.add_varcast += val;
  2683. break;
  2684. #else
  2685. case SP_ADD_FIXEDCAST:
  2686. case SP_FIXCASTRATE:
  2687. case SP_ADD_VARIABLECAST:
  2688. //ShowWarning("pc_bonus: non-RENEWAL_CAST doesn't support this bonus %d.\n", type);
  2689. break;
  2690. case SP_VARCASTRATE:
  2691. case SP_CASTRATE:
  2692. if(sd->state.lr_flag != 2)
  2693. sd->castrate += val;
  2694. break;
  2695. #endif
  2696. case SP_ADDMAXWEIGHT:
  2697. if (sd->state.lr_flag != 2)
  2698. sd->max_weight += val;
  2699. break;
  2700. case SP_ABSORB_DMG_MAXHP: // bonus bAbsorbDmgMaxHP,n;
  2701. sd->bonus.absorb_dmg_maxhp = max(sd->bonus.absorb_dmg_maxhp, val);
  2702. break;
  2703. default:
  2704. ShowWarning("pc_bonus: unknown type %d %d !\n",type,val);
  2705. break;
  2706. }
  2707. }
  2708. /*==========================================
  2709. * Player bonus (type) with args type2 and val, called trough bonus2 (npc)
  2710. * format: bonus2 bBonusName,type2,val;
  2711. * @param sd
  2712. * @param type Bonus type used by bBonusName
  2713. * @param type2
  2714. * @param val Value that usually for rate or fixed value
  2715. *------------------------------------------*/
  2716. void pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
  2717. {
  2718. int i;
  2719. nullpo_retv(sd);
  2720. switch(type){
  2721. case SP_ADDELE: // bonus2 bAddEle,e,x;
  2722. PC_BONUS_CHK_ELEMENT(type2,SP_ADDELE);
  2723. if(!sd->state.lr_flag)
  2724. sd->right_weapon.addele[type2]+=val;
  2725. else if(sd->state.lr_flag == 1)
  2726. sd->left_weapon.addele[type2]+=val;
  2727. else if(sd->state.lr_flag == 2)
  2728. sd->arrow_addele[type2]+=val;
  2729. break;
  2730. case SP_ADDRACE: // bonus2 bAddRace,r,x;
  2731. PC_BONUS_CHK_RACE(type2,SP_ADDRACE);
  2732. if(!sd->state.lr_flag)
  2733. sd->right_weapon.addrace[type2]+=val;
  2734. else if(sd->state.lr_flag == 1)
  2735. sd->left_weapon.addrace[type2]+=val;
  2736. else if(sd->state.lr_flag == 2)
  2737. sd->arrow_addrace[type2]+=val;
  2738. break;
  2739. case SP_ADDCLASS: // bonus2 bAddClass,c,x;
  2740. PC_BONUS_CHK_CLASS(type2,SP_ADDCLASS);
  2741. if(!sd->state.lr_flag)
  2742. sd->right_weapon.addclass[type2]+=val;
  2743. else if(sd->state.lr_flag == 1)
  2744. sd->left_weapon.addclass[type2]+=val;
  2745. else if(sd->state.lr_flag == 2)
  2746. sd->arrow_addclass[type2]+=val;
  2747. break;
  2748. case SP_ADDSIZE: // bonus2 bAddSize,s,x;
  2749. PC_BONUS_CHK_SIZE(type2,SP_ADDSIZE);
  2750. if(!sd->state.lr_flag)
  2751. sd->right_weapon.addsize[type2]+=val;
  2752. else if(sd->state.lr_flag == 1)
  2753. sd->left_weapon.addsize[type2]+=val;
  2754. else if(sd->state.lr_flag == 2)
  2755. sd->arrow_addsize[type2]+=val;
  2756. break;
  2757. case SP_SUBELE: // bonus2 bSubEle,e,x;
  2758. PC_BONUS_CHK_ELEMENT(type2,SP_SUBELE);
  2759. if(sd->state.lr_flag != 2)
  2760. sd->subele[type2]+=val;
  2761. break;
  2762. case SP_SUBRACE: // bonus2 bSubRace,r,x;
  2763. PC_BONUS_CHK_RACE(type2,SP_SUBRACE);
  2764. if(sd->state.lr_flag != 2)
  2765. sd->subrace[type2]+=val;
  2766. break;
  2767. case SP_SUBCLASS: // bonus2 bSubClass,c,x;
  2768. PC_BONUS_CHK_CLASS(type2,SP_SUBCLASS);
  2769. if(sd->state.lr_flag != 2)
  2770. sd->subclass[type2]+=val;
  2771. break;
  2772. case SP_ADDEFF: // bonus2 bAddEff,eff,n;
  2773. PC_BONUS_CHK_SC(type2,SP_ADDEFF);
  2774. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  2775. sd->state.lr_flag != 2 ? val : 0, sd->state.lr_flag == 2 ? val : 0, 0, 0);
  2776. break;
  2777. case SP_ADDEFF2: // bonus2 bAddEff2,eff,n;
  2778. PC_BONUS_CHK_SC(type2,SP_ADDEFF2);
  2779. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  2780. sd->state.lr_flag != 2 ? val : 0, sd->state.lr_flag == 2 ? val : 0, ATF_SELF, 0);
  2781. break;
  2782. case SP_RESEFF: // bonus2 bResEff,eff,n;
  2783. if (type2 < SC_COMMON_MIN || type2 > SC_COMMON_MAX) {
  2784. ShowError("pc_bonus2: SP_RESEFF: %d is invalid effect.\n", type2);
  2785. break;
  2786. }
  2787. if(sd->state.lr_flag == 2)
  2788. break;
  2789. i = sd->reseff[type2]+val;
  2790. sd->reseff[type2]= cap_value(i, -10000, 10000);
  2791. break;
  2792. case SP_MAGIC_ADDELE: // bonus2 bMagicAddEle,e,x;
  2793. PC_BONUS_CHK_ELEMENT(type2,SP_MAGIC_ADDELE);
  2794. if(sd->state.lr_flag != 2)
  2795. sd->magic_addele[type2]+=val;
  2796. break;
  2797. case SP_MAGIC_ADDRACE: // bonus2 bMagicAddRace,r,x;
  2798. PC_BONUS_CHK_RACE(type2,SP_MAGIC_ADDRACE);
  2799. if(sd->state.lr_flag != 2)
  2800. sd->magic_addrace[type2]+=val;
  2801. break;
  2802. case SP_MAGIC_ADDCLASS: // bonus2 bMagicAddClass,c,x;
  2803. PC_BONUS_CHK_CLASS(type2,SP_MAGIC_ADDCLASS);
  2804. if(sd->state.lr_flag != 2)
  2805. sd->magic_addclass[type2]+=val;
  2806. break;
  2807. case SP_MAGIC_ADDSIZE: // bonus2 bMagicAddSize,s,x;
  2808. PC_BONUS_CHK_SIZE(type2,SP_MAGIC_ADDSIZE);
  2809. if(sd->state.lr_flag != 2)
  2810. sd->magic_addsize[type2]+=val;
  2811. break;
  2812. case SP_MAGIC_ATK_ELE: // bonus2 bMagicAtkEle,e,x;
  2813. PC_BONUS_CHK_ELEMENT(type2,SP_MAGIC_ATK_ELE);
  2814. if(sd->state.lr_flag != 2)
  2815. sd->magic_atk_ele[type2]+=val;
  2816. break;
  2817. case SP_ADD_DAMAGE_CLASS: // bonus2 bAddDamageClass,mid,x;
  2818. switch (sd->state.lr_flag) {
  2819. case 0: //Right hand
  2820. 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);
  2821. if (i == ARRAYLENGTH(sd->right_weapon.add_dmg))
  2822. {
  2823. ShowError("pc_bonus2: SP_ADD_DAMAGE_CLASS: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->right_weapon.add_dmg));
  2824. break;
  2825. }
  2826. sd->right_weapon.add_dmg[i].class_ = type2;
  2827. sd->right_weapon.add_dmg[i].rate += val;
  2828. if (!sd->right_weapon.add_dmg[i].rate) //Shift the rest of elements up.
  2829. 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]));
  2830. break;
  2831. case 1: //Left hand
  2832. 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);
  2833. if (i == ARRAYLENGTH(sd->left_weapon.add_dmg))
  2834. {
  2835. ShowError("pc_bonus2: SP_ADD_DAMAGE_CLASS: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->left_weapon.add_dmg));
  2836. break;
  2837. }
  2838. sd->left_weapon.add_dmg[i].class_ = type2;
  2839. sd->left_weapon.add_dmg[i].rate += val;
  2840. if (!sd->left_weapon.add_dmg[i].rate) //Shift the rest of elements up.
  2841. 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]));
  2842. break;
  2843. }
  2844. break;
  2845. case SP_ADD_MAGIC_DAMAGE_CLASS: // bonus2 bAddMagicDamageClass,mid,x;
  2846. if(sd->state.lr_flag == 2)
  2847. break;
  2848. ARR_FIND(0, ARRAYLENGTH(sd->add_mdmg), i, sd->add_mdmg[i].rate == 0 || sd->add_mdmg[i].class_ == type2);
  2849. if (i == ARRAYLENGTH(sd->add_mdmg))
  2850. {
  2851. ShowError("pc_bonus2: SP_ADD_MAGIC_DAMAGE_CLASS: Reached max (%d) number of add Class magic dmg bonuses per character!\n", ARRAYLENGTH(sd->add_mdmg));
  2852. break;
  2853. }
  2854. sd->add_mdmg[i].class_ = type2;
  2855. sd->add_mdmg[i].rate += val;
  2856. if (!sd->add_mdmg[i].rate) //Shift the rest of elements up.
  2857. memmove(&sd->add_mdmg[i], &sd->add_mdmg[i+1], sizeof(sd->add_mdmg) - (i+1)*sizeof(sd->add_mdmg[0]));
  2858. break;
  2859. case SP_ADD_DEF_MONSTER: // bonus2 bAddDefMonster,mid,x;
  2860. if(sd->state.lr_flag == 2)
  2861. break;
  2862. ARR_FIND(0, ARRAYLENGTH(sd->add_def), i, sd->add_def[i].rate == 0 || sd->add_def[i].class_ == type2);
  2863. if (i == ARRAYLENGTH(sd->add_def))
  2864. {
  2865. ShowError("pc_bonus2: SP_ADD_DEF_MONSTER: Reached max (%d) number of add Class def bonuses per character!\n", ARRAYLENGTH(sd->add_def));
  2866. break;
  2867. }
  2868. sd->add_def[i].class_ = type2;
  2869. sd->add_def[i].rate += val;
  2870. if (!sd->add_def[i].rate) //Shift the rest of elements up.
  2871. memmove(&sd->add_def[i], &sd->add_def[i+1], sizeof(sd->add_def) - (i+1)*sizeof(sd->add_def[0]));
  2872. break;
  2873. case SP_ADD_MDEF_MONSTER: // bonus2 bAddMDefMonster,mid,x;
  2874. if(sd->state.lr_flag == 2)
  2875. break;
  2876. ARR_FIND(0, ARRAYLENGTH(sd->add_mdef), i, sd->add_mdef[i].rate == 0 || sd->add_mdef[i].class_ == type2);
  2877. if (i == ARRAYLENGTH(sd->add_mdef))
  2878. {
  2879. ShowError("pc_bonus2: SP_ADD_MDEF_MONSTER: Reached max (%d) number of add Class mdef bonuses per character!\n", ARRAYLENGTH(sd->add_mdef));
  2880. break;
  2881. }
  2882. sd->add_mdef[i].class_ = type2;
  2883. sd->add_mdef[i].rate += val;
  2884. if (!sd->add_mdef[i].rate) //Shift the rest of elements up.
  2885. memmove(&sd->add_mdef[i], &sd->add_mdef[i+1], sizeof(sd->add_mdef) - (i+1)*sizeof(sd->add_mdef[0]));
  2886. break;
  2887. case SP_HP_DRAIN_RATE: // bonus2 bHPDrainRate,x,n;
  2888. if(!sd->state.lr_flag) {
  2889. sd->right_weapon.hp_drain_rate.rate += type2;
  2890. sd->right_weapon.hp_drain_rate.per += val;
  2891. }
  2892. else if(sd->state.lr_flag == 1) {
  2893. sd->left_weapon.hp_drain_rate.rate += type2;
  2894. sd->left_weapon.hp_drain_rate.per += val;
  2895. }
  2896. break;
  2897. case SP_SP_DRAIN_RATE: // bonus2 bSPDrainRate,x,n;
  2898. if(!sd->state.lr_flag) {
  2899. sd->right_weapon.sp_drain_rate.rate += type2;
  2900. sd->right_weapon.sp_drain_rate.per += val;
  2901. }
  2902. else if(sd->state.lr_flag == 1) {
  2903. sd->left_weapon.sp_drain_rate.rate += type2;
  2904. sd->left_weapon.sp_drain_rate.per += val;
  2905. }
  2906. break;
  2907. case SP_SP_VANISH_RATE: // bonus2 bSPVanishRate,x,n;
  2908. if(sd->state.lr_flag != 2) {
  2909. sd->bonus.sp_vanish_rate += type2;
  2910. sd->bonus.sp_vanish_per += val;
  2911. }
  2912. break;
  2913. case SP_HP_VANISH_RATE: // bonus2 bHPVanishRate,x,n;
  2914. if(sd->state.lr_flag != 2) {
  2915. sd->bonus.hp_vanish_rate += type2;
  2916. sd->bonus.hp_vanish_per += val;
  2917. }
  2918. break;
  2919. case SP_GET_ZENY_NUM: // bonus2 bGetZenyNum,x,n;
  2920. if(sd->state.lr_flag != 2 && sd->bonus.get_zeny_rate < val) {
  2921. sd->bonus.get_zeny_rate = val;
  2922. sd->bonus.get_zeny_num = type2;
  2923. }
  2924. break;
  2925. case SP_ADD_GET_ZENY_NUM: // bonus2 bAddGetZenyNum,x,n;
  2926. if(sd->state.lr_flag != 2) {
  2927. sd->bonus.get_zeny_rate += val;
  2928. sd->bonus.get_zeny_num += type2;
  2929. }
  2930. break;
  2931. case SP_WEAPON_COMA_ELE: // bonus2 bWeaponComaEle,e,n;
  2932. PC_BONUS_CHK_ELEMENT(type2,SP_WEAPON_COMA_ELE);
  2933. if(sd->state.lr_flag == 2)
  2934. break;
  2935. sd->weapon_coma_ele[type2] += val;
  2936. sd->special_state.bonus_coma = 1;
  2937. break;
  2938. case SP_WEAPON_COMA_RACE: // bonus2 bWeaponComaRace,r,n;
  2939. PC_BONUS_CHK_RACE(type2,SP_WEAPON_COMA_RACE);
  2940. if(sd->state.lr_flag == 2)
  2941. break;
  2942. sd->weapon_coma_race[type2] += val;
  2943. sd->special_state.bonus_coma = 1;
  2944. break;
  2945. case SP_WEAPON_COMA_CLASS: // bonus2 bWeaponComaClass,c,n;
  2946. PC_BONUS_CHK_CLASS(type2,SP_WEAPON_COMA_CLASS);
  2947. if(sd->state.lr_flag == 2)
  2948. break;
  2949. sd->weapon_coma_class[type2] += val;
  2950. sd->special_state.bonus_coma = 1;
  2951. break;
  2952. case SP_WEAPON_ATK: // bonus2 bWeaponAtk,w,n;
  2953. if(sd->state.lr_flag != 2)
  2954. sd->weapon_atk[type2]+=val;
  2955. break;
  2956. case SP_WEAPON_ATK_RATE: // bonus2 bWeaponAtkRate,w,n;
  2957. if(sd->state.lr_flag != 2)
  2958. sd->weapon_atk_rate[type2]+=val;
  2959. break;
  2960. case SP_CRITICAL_ADDRACE: // bonus2 bCriticalAddRace,r,n;
  2961. PC_BONUS_CHK_RACE(type2,SP_CRITICAL_ADDRACE);
  2962. if(sd->state.lr_flag != 2)
  2963. sd->critaddrace[type2] += val*10;
  2964. break;
  2965. case SP_ADDEFF_WHENHIT: // bonus2 bAddEffWhenHit,eff,n;
  2966. PC_BONUS_CHK_SC(type2,SP_ADDEFF_WHENHIT);
  2967. if(sd->state.lr_flag != 2)
  2968. pc_bonus_addeff(sd->addeff_atked, ARRAYLENGTH(sd->addeff_atked), (sc_type)type2, val, 0, 0, 0);
  2969. break;
  2970. case SP_SKILL_ATK: // bonus2 bSkillAtk,sk,n;
  2971. if(sd->state.lr_flag == 2)
  2972. break;
  2973. ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == 0 || sd->skillatk[i].id == type2);
  2974. if (i == ARRAYLENGTH(sd->skillatk))
  2975. { //Better mention this so the array length can be updated. [Skotlex]
  2976. ShowError("pc_bonus2: SP_SKILL_ATK: Reached max (%d) number of skills per character, bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillatk), type2, val);
  2977. break;
  2978. }
  2979. if (sd->skillatk[i].id == type2)
  2980. sd->skillatk[i].val += val;
  2981. else {
  2982. sd->skillatk[i].id = type2;
  2983. sd->skillatk[i].val = val;
  2984. }
  2985. break;
  2986. case SP_SKILL_HEAL: // bonus2 bSkillHeal,sk,n;
  2987. if(sd->state.lr_flag == 2)
  2988. break;
  2989. ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == 0 || sd->skillheal[i].id == type2);
  2990. if (i == ARRAYLENGTH(sd->skillheal))
  2991. { // Better mention this so the array length can be updated. [Skotlex]
  2992. ShowError("pc_bonus2: SP_SKILL_HEAL: Reached max (%d) number of skills per character, bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal), type2, val);
  2993. break;
  2994. }
  2995. if (sd->skillheal[i].id == type2)
  2996. sd->skillheal[i].val += val;
  2997. else {
  2998. sd->skillheal[i].id = type2;
  2999. sd->skillheal[i].val = val;
  3000. }
  3001. break;
  3002. case SP_SKILL_HEAL2: // bonus2 bSkillHeal2,sk,n;
  3003. if(sd->state.lr_flag == 2)
  3004. break;
  3005. ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == 0 || sd->skillheal2[i].id == type2);
  3006. if (i == ARRAYLENGTH(sd->skillheal2))
  3007. { // Better mention this so the array length can be updated. [Skotlex]
  3008. ShowError("pc_bonus2: SP_SKILL_HEAL2: Reached max (%d) number of skills per character, bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal2), type2, val);
  3009. break;
  3010. }
  3011. if (sd->skillheal2[i].id == type2)
  3012. sd->skillheal2[i].val += val;
  3013. else {
  3014. sd->skillheal2[i].id = type2;
  3015. sd->skillheal2[i].val = val;
  3016. }
  3017. break;
  3018. case SP_ADD_SKILL_BLOW: // bonus2 bAddSkillBlow,sk,n;
  3019. if(sd->state.lr_flag == 2)
  3020. break;
  3021. ARR_FIND(0, ARRAYLENGTH(sd->skillblown), i, sd->skillblown[i].id == 0 || sd->skillblown[i].id == type2);
  3022. if (i == ARRAYLENGTH(sd->skillblown))
  3023. { //Better mention this so the array length can be updated. [Skotlex]
  3024. ShowError("pc_bonus2: SP_ADD_SKILL_BLOW: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", ARRAYLENGTH(sd->skillblown), type2, val);
  3025. break;
  3026. }
  3027. if(sd->skillblown[i].id == type2)
  3028. sd->skillblown[i].val += val;
  3029. else {
  3030. sd->skillblown[i].id = type2;
  3031. sd->skillblown[i].val = val;
  3032. }
  3033. break;
  3034. case SP_HP_LOSS_RATE: // bonus2 bHPLossRate,n,t;
  3035. if(sd->state.lr_flag != 2) {
  3036. sd->hp_loss.value = type2;
  3037. sd->hp_loss.rate = val;
  3038. }
  3039. break;
  3040. case SP_HP_REGEN_RATE: // bonus2 bHPRegenRate,n,t;
  3041. if(sd->state.lr_flag != 2) {
  3042. sd->hp_regen.value = type2;
  3043. sd->hp_regen.rate = val;
  3044. }
  3045. break;
  3046. case SP_ADDRACE2: // bonus2 bAddRace2,mr,x;
  3047. PC_BONUS_CHK_RACE2(type2,SP_ADDRACE2);
  3048. if(sd->state.lr_flag != 2)
  3049. sd->right_weapon.addrace2[type2] += val;
  3050. else
  3051. sd->left_weapon.addrace2[type2] += val;
  3052. break;
  3053. case SP_SUBSIZE: // bonus2 bSubSize,s,x;
  3054. PC_BONUS_CHK_SIZE(type2,SP_SUBSIZE);
  3055. if(sd->state.lr_flag != 2)
  3056. sd->subsize[type2]+=val;
  3057. break;
  3058. case SP_SUBRACE2: // bonus2 bSubRace2,mr,x;
  3059. PC_BONUS_CHK_RACE2(type2,SP_SUBRACE2);
  3060. if(sd->state.lr_flag != 2)
  3061. sd->subrace2[type2]+=val;
  3062. break;
  3063. case SP_ADD_ITEM_HEAL_RATE: // bonus2 bAddItemHealRate,iid,n;
  3064. if(sd->state.lr_flag == 2)
  3065. break;
  3066. if (!itemdb_exists(type2)) {
  3067. ShowError("pc_bonus2: SP_ADD_ITEM_HEAL_RATE Invalid item with id %d\n", type2);
  3068. break;
  3069. }
  3070. for(i=0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++);
  3071. if(i == ARRAYLENGTH(sd->itemhealrate)) {
  3072. ShowError("pc_bonus2: SP_ADD_ITEM_HEAL_RATE: Reached max (%d) number of item heal bonuses per character!\n", ARRAYLENGTH(sd->itemhealrate));
  3073. break;
  3074. }
  3075. sd->itemhealrate[i].nameid = type2;
  3076. sd->itemhealrate[i].rate += val;
  3077. break;
  3078. case SP_ADD_ITEMGROUP_HEAL_RATE: // bonus2 bAddItemGroupHealRate,ig,n;
  3079. if (sd->state.lr_flag == 2)
  3080. break;
  3081. if (!type2 || !itemdb_group_exists(type2)) {
  3082. ShowError("pc_bonus2: SP_ADD_ITEMGROUP_HEAL_RATE: Invalid item group with id %d\n", type2);
  3083. break;
  3084. }
  3085. pc_itemgrouphealrate(sd, type2, val);
  3086. break;
  3087. case SP_EXP_ADDRACE: // bonus2 bExpAddRace,r,x;
  3088. PC_BONUS_CHK_RACE(type2,SP_EXP_ADDRACE);
  3089. if(sd->state.lr_flag != 2)
  3090. sd->expaddrace[type2]+=val;
  3091. break;
  3092. case SP_EXP_ADDCLASS: // bonus2 bExpAddClass,c,x;
  3093. PC_BONUS_CHK_CLASS(type2,SP_EXP_ADDCLASS);
  3094. if(sd->state.lr_flag != 2)
  3095. sd->expaddclass[type2]+=val;
  3096. break;
  3097. case SP_SP_GAIN_RACE: // bonus2 bSPGainRace,r,n;
  3098. PC_BONUS_CHK_RACE(type2,SP_SP_GAIN_RACE);
  3099. if(sd->state.lr_flag != 2)
  3100. sd->sp_gain_race[type2]+=val;
  3101. break;
  3102. case SP_ADD_MONSTER_DROP_ITEM: // bonus2 bAddMonsterDropItem,iid,n;
  3103. if (sd->state.lr_flag != 2)
  3104. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, CLASS_ALL, RC_NONE_, val);
  3105. break;
  3106. case SP_ADD_MONSTER_DROP_ITEMGROUP: // bonus2 bAddMonsterDropItemGroup,ig,n;
  3107. if (sd->state.lr_flag != 2)
  3108. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, CLASS_ALL, RC_NONE_, val);
  3109. break;
  3110. case SP_SP_LOSS_RATE: // bonus2 bSPLossRate,n,t;
  3111. if(sd->state.lr_flag != 2) {
  3112. sd->sp_loss.value = type2;
  3113. sd->sp_loss.rate = val;
  3114. }
  3115. break;
  3116. case SP_SP_REGEN_RATE: // bonus2 bSPRegenRate,n,t;
  3117. if(sd->state.lr_flag != 2) {
  3118. sd->sp_regen.value = type2;
  3119. sd->sp_regen.rate = val;
  3120. }
  3121. break;
  3122. case SP_HP_DRAIN_VALUE_RACE: // bonus2 bHPDrainValueRace,r,n;
  3123. PC_BONUS_CHK_RACE(type2,SP_HP_DRAIN_VALUE_RACE);
  3124. if(!sd->state.lr_flag) {
  3125. sd->right_weapon.hp_drain_race[type2] += val;
  3126. }
  3127. else if(sd->state.lr_flag == 1) {
  3128. sd->left_weapon.hp_drain_race[type2] += val;
  3129. }
  3130. break;
  3131. case SP_SP_DRAIN_VALUE_RACE: // bonus2 bSPDrainValueRace,r,n;
  3132. PC_BONUS_CHK_RACE(type2,SP_SP_DRAIN_VALUE_RACE);
  3133. if(!sd->state.lr_flag) {
  3134. sd->right_weapon.sp_drain_race[type2] += val;
  3135. }
  3136. else if(sd->state.lr_flag == 1) {
  3137. sd->left_weapon.sp_drain_race[type2] += val;
  3138. }
  3139. break;
  3140. case SP_HP_DRAIN_VALUE_CLASS: // bonus2 bHPDrainValueClass,c,n;
  3141. PC_BONUS_CHK_CLASS(type2,SP_HP_DRAIN_VALUE_CLASS);
  3142. if(!sd->state.lr_flag) {
  3143. sd->right_weapon.hp_drain_class[type2] += val;
  3144. }
  3145. else if(sd->state.lr_flag == 1) {
  3146. sd->left_weapon.hp_drain_class[type2] += val;
  3147. }
  3148. break;
  3149. case SP_SP_DRAIN_VALUE_CLASS: // bonus2 bSPDrainValueClass,c,n;
  3150. PC_BONUS_CHK_CLASS(type2,SP_SP_DRAIN_VALUE_CLASS);
  3151. if(!sd->state.lr_flag) {
  3152. sd->right_weapon.sp_drain_class[type2] += val;
  3153. }
  3154. else if(sd->state.lr_flag == 1) {
  3155. sd->left_weapon.sp_drain_class[type2] += val;
  3156. }
  3157. break;
  3158. case SP_IGNORE_MDEF_RACE_RATE: // bonus2 bIgnoreMdefRaceRate,r,n;
  3159. PC_BONUS_CHK_RACE(type2,SP_IGNORE_MDEF_RACE_RATE);
  3160. if(sd->state.lr_flag != 2)
  3161. sd->ignore_mdef_by_race[type2] += val;
  3162. break;
  3163. case SP_IGNORE_MDEF_CLASS_RATE: // bonus2 bIgnoreMdefClassRate,c,n;
  3164. PC_BONUS_CHK_CLASS(type2,SP_IGNORE_MDEF_CLASS_RATE);
  3165. if(sd->state.lr_flag != 2)
  3166. sd->ignore_mdef_by_class[type2] += val;
  3167. break;
  3168. case SP_IGNORE_DEF_RACE_RATE: // bonus2 bIgnoreDefRaceRate,r,n;
  3169. PC_BONUS_CHK_RACE(type2,SP_IGNORE_DEF_RACE_RATE);
  3170. if(sd->state.lr_flag != 2)
  3171. sd->ignore_def_by_race[type2] += val;
  3172. break;
  3173. case SP_SKILL_USE_SP_RATE: // bonus2 bSkillUseSPrate,sk,n;
  3174. if(sd->state.lr_flag == 2)
  3175. break;
  3176. ARR_FIND(0, ARRAYLENGTH(sd->skillusesprate), i, sd->skillusesprate[i].id == 0 || sd->skillusesprate[i].id == type2);
  3177. if (i == ARRAYLENGTH(sd->skillusesprate)) {
  3178. ShowError("pc_bonus2: SP_SKILL_USE_SP_RATE: Reached max (%d) number of skills per character, bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesprate), type2, val);
  3179. break;
  3180. }
  3181. if (sd->skillusesprate[i].id == type2)
  3182. sd->skillusesprate[i].val += val;
  3183. else {
  3184. sd->skillusesprate[i].id = type2;
  3185. sd->skillusesprate[i].val = val;
  3186. }
  3187. break;
  3188. case SP_SKILL_COOLDOWN: // bonus2 bSkillCooldown,sk,t;
  3189. if(sd->state.lr_flag == 2)
  3190. break;
  3191. ARR_FIND(0, ARRAYLENGTH(sd->skillcooldown), i, sd->skillcooldown[i].id == 0 || sd->skillcooldown[i].id == type2);
  3192. if (i == ARRAYLENGTH(sd->skillcooldown))
  3193. {
  3194. ShowError("pc_bonus2: SP_SKILL_COOLDOWN: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", ARRAYLENGTH(sd->skillcooldown), type2, val);
  3195. break;
  3196. }
  3197. if (sd->skillcooldown[i].id == type2)
  3198. sd->skillcooldown[i].val += val;
  3199. else {
  3200. sd->skillcooldown[i].id = type2;
  3201. sd->skillcooldown[i].val = val;
  3202. }
  3203. break;
  3204. #ifdef RENEWAL_CAST
  3205. case SP_SKILL_FIXEDCAST: // bonus2 bSkillFixedCast,sk,t;
  3206. if(sd->state.lr_flag == 2)
  3207. break;
  3208. ARR_FIND(0, ARRAYLENGTH(sd->skillfixcast), i, sd->skillfixcast[i].id == 0 || sd->skillfixcast[i].id == type2);
  3209. if (i == ARRAYLENGTH(sd->skillfixcast))
  3210. {
  3211. ShowError("pc_bonus2: SP_SKILL_FIXEDCAST: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", ARRAYLENGTH(sd->skillfixcast), type2, val);
  3212. break;
  3213. }
  3214. if (sd->skillfixcast[i].id == type2)
  3215. sd->skillfixcast[i].val += val;
  3216. else {
  3217. sd->skillfixcast[i].id = type2;
  3218. sd->skillfixcast[i].val = val;
  3219. }
  3220. break;
  3221. case SP_SKILL_VARIABLECAST: // bonus2 bSkillVariableCast,sk,t;
  3222. if(sd->state.lr_flag == 2)
  3223. break;
  3224. ARR_FIND(0, ARRAYLENGTH(sd->skillvarcast), i, sd->skillvarcast[i].id == 0 || sd->skillvarcast[i].id == type2);
  3225. if (i == ARRAYLENGTH(sd->skillvarcast))
  3226. {
  3227. ShowError("pc_bonus2: SP_SKILL_VARIABLECAST: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", ARRAYLENGTH(sd->skillvarcast), type2, val);
  3228. break;
  3229. }
  3230. if (sd->skillvarcast[i].id == type2)
  3231. sd->skillvarcast[i].val += val;
  3232. else {
  3233. sd->skillvarcast[i].id = type2;
  3234. sd->skillvarcast[i].val = val;
  3235. }
  3236. break;
  3237. case SP_CASTRATE: // bonus2 bCastrate,sk,n;
  3238. case SP_VARCASTRATE: // bonus2 bVariableCastrate,sk,n;
  3239. if(sd->state.lr_flag == 2)
  3240. break;
  3241. ARR_FIND(0, ARRAYLENGTH(sd->skillcastrate), i, sd->skillcastrate[i].id == 0 || sd->skillcastrate[i].id == type2);
  3242. if (i == ARRAYLENGTH(sd->skillcastrate))
  3243. {
  3244. ShowError("pc_bonus2: SP_VARCASTRATE: Reached max (%d) number of skills per character, bonus skill %d (%d%%) lost.\n",ARRAYLENGTH(sd->skillcastrate), type2, val);
  3245. break;
  3246. }
  3247. if(sd->skillcastrate[i].id == type2)
  3248. sd->skillcastrate[i].val -= val;
  3249. else {
  3250. sd->skillcastrate[i].id = type2;
  3251. sd->skillcastrate[i].val -= val;
  3252. }
  3253. break;
  3254. case SP_FIXCASTRATE: // bonus2 bFixedCastrate,sk,n;
  3255. if(sd->state.lr_flag == 2)
  3256. break;
  3257. ARR_FIND(0, ARRAYLENGTH(sd->skillfixcastrate), i, sd->skillfixcastrate[i].id == 0 || sd->skillfixcastrate[i].id == type2);
  3258. if (i == ARRAYLENGTH(sd->skillfixcastrate))
  3259. {
  3260. ShowError("pc_bonus2: SP_FIXCASTRATE: Reached max (%d) number of skills per character, bonus skill %d (%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcastrate), type2, val);
  3261. break;
  3262. }
  3263. if(sd->skillfixcastrate[i].id == type2)
  3264. sd->skillfixcastrate[i].val -= val;
  3265. else {
  3266. sd->skillfixcastrate[i].id = type2;
  3267. sd->skillfixcastrate[i].val -= val;
  3268. }
  3269. break;
  3270. #else
  3271. case SP_SKILL_FIXEDCAST: // bonus2 bSkillFixedCast,sk,t;
  3272. case SP_SKILL_VARIABLECAST: // bonus2 bSkillVariableCast,sk,t;
  3273. case SP_FIXCASTRATE: // bonus2 bFixedCastrate,sk,n;
  3274. //ShowWarning("pc_bonus2: Non-RENEWAL_CAST doesn't support this bonus %d.\n", type);
  3275. break;
  3276. case SP_VARCASTRATE: // bonus2 bVariableCastrate,sk,n;
  3277. case SP_CASTRATE: // bonus2 bCastrate,sk,n;
  3278. if(sd->state.lr_flag == 2)
  3279. break;
  3280. ARR_FIND(0, ARRAYLENGTH(sd->skillcastrate), i, sd->skillcastrate[i].id == 0 || sd->skillcastrate[i].id == type2);
  3281. if (i == ARRAYLENGTH(sd->skillcastrate))
  3282. { //Better mention this so the array length can be updated. [Skotlex]
  3283. ShowError("pc_bonus2: %s: Reached max (%d) number of skills per character, bonus skill %d (%d%%) lost.\n",
  3284. (type == SP_CASTRATE) ? "SP_CASTRATE" : "SP_VARCASTRATE", ARRAYLENGTH(sd->skillcastrate), type2, val);
  3285. break;
  3286. }
  3287. if(sd->skillcastrate[i].id == type2)
  3288. sd->skillcastrate[i].val += val;
  3289. else {
  3290. sd->skillcastrate[i].id = type2;
  3291. sd->skillcastrate[i].val = val;
  3292. }
  3293. break;
  3294. #endif
  3295. case SP_SKILL_USE_SP: // bonus2 bSkillUseSP,sk,n;
  3296. if(sd->state.lr_flag == 2)
  3297. break;
  3298. ARR_FIND(0, ARRAYLENGTH(sd->skillusesp), i, sd->skillusesp[i].id == 0 || sd->skillusesp[i].id == type2);
  3299. if (i == ARRAYLENGTH(sd->skillusesp)) {
  3300. ShowError("pc_bonus2: SP_SKILL_USE_SP: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", ARRAYLENGTH(sd->skillusesp), type2, val);
  3301. break;
  3302. }
  3303. if (sd->skillusesp[i].id == type2)
  3304. sd->skillusesp[i].val += val;
  3305. else {
  3306. sd->skillusesp[i].id = type2;
  3307. sd->skillusesp[i].val = val;
  3308. }
  3309. break;
  3310. case SP_SUB_SKILL: // bonus2 bSubSkill,sk,n;
  3311. ARR_FIND(0, ARRAYLENGTH(sd->subskill), i, sd->subskill[i].id == type2 || sd->subskill[i].id == 0);
  3312. if (i == ARRAYLENGTH(sd->subskill)) {
  3313. ShowError("pc_bonus2: SP_SUB_SKILL: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", ARRAYLENGTH(sd->subskill), type2, val);
  3314. break;
  3315. }
  3316. if (sd->subskill[i].id == type2)
  3317. sd->subskill[i].val += val;
  3318. else {
  3319. sd->subskill[i].id = type2;
  3320. sd->subskill[i].val = val;
  3321. }
  3322. break;
  3323. case SP_SUBDEF_ELE: // bonus2 bSubDefEle,e,x;
  3324. PC_BONUS_CHK_ELEMENT(type2,SP_SUBDEF_ELE);
  3325. sd->subdefele[type2] += val;
  3326. break;
  3327. case SP_COMA_CLASS: // bonus2 bComaClass,c,n;
  3328. PC_BONUS_CHK_CLASS(type2,SP_COMA_CLASS);
  3329. sd->coma_class[type2] += val;
  3330. sd->special_state.bonus_coma = 1;
  3331. break;
  3332. case SP_COMA_RACE: // bonus2 bComaRace,r,n;
  3333. PC_BONUS_CHK_RACE(type2,SP_COMA_RACE);
  3334. sd->coma_race[type2] += val;
  3335. sd->special_state.bonus_coma = 1;
  3336. break;
  3337. default:
  3338. ShowWarning("pc_bonus2: unknown type %d %d %d!\n",type,type2,val);
  3339. break;
  3340. }
  3341. }
  3342. /**
  3343. * Gives item bonus to player for format: bonus3 bBonusName,type2,val;
  3344. * @param sd
  3345. * @param type Bonus type used by bBonusName
  3346. * @param type2
  3347. * @param val Value that usually for rate or fixed value
  3348. */
  3349. void pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
  3350. {
  3351. nullpo_retv(sd);
  3352. switch(type){
  3353. case SP_ADD_MONSTER_DROP_ITEM: // bonus3 bAddMonsterDropItem,iid,r,n;
  3354. if(sd->state.lr_flag != 2)
  3355. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, CLASS_NONE, type3, val);
  3356. break;
  3357. case SP_ADD_MONSTER_ID_DROP_ITEM: // bonus3 bAddMonsterIdDropItem,iid,mid,n;
  3358. if(sd->state.lr_flag != 2)
  3359. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, CLASS_NONE, -type3, val);
  3360. break;
  3361. case SP_ADD_CLASS_DROP_ITEM: // bonus3 bAddClassDropItem,iid,c,n;
  3362. if(sd->state.lr_flag != 2)
  3363. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, type3, RC_NONE_, val);
  3364. break;
  3365. case SP_AUTOSPELL: // bonus3 bAutoSpell,sk,y,n;
  3366. if(sd->state.lr_flag != 2)
  3367. {
  3368. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3369. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3370. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell),
  3371. target?-type2:type2, type3, val, 0, current_equip_card_id);
  3372. }
  3373. break;
  3374. case SP_AUTOSPELL_WHENHIT: // bonus3 bAutoSpellWhenHit,sk,y,n;
  3375. if(sd->state.lr_flag != 2)
  3376. {
  3377. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3378. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3379. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2),
  3380. target?-type2:type2, type3, val, BF_NORMAL|BF_SKILL, current_equip_card_id);
  3381. }
  3382. break;
  3383. case SP_ADD_MONSTER_DROP_ITEMGROUP: // bonus3 bAddMonsterDropItemGroup,ig,r,n;
  3384. if (sd->state.lr_flag != 2)
  3385. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, CLASS_NONE, type3, val);
  3386. break;
  3387. case SP_ADD_CLASS_DROP_ITEMGROUP: // bonus3 bAddClassDropItemGroup,ig,c,n;
  3388. if (sd->state.lr_flag != 2)
  3389. pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, type3, RC_NONE_, val);
  3390. break;
  3391. case SP_ADDEFF: // bonus3 bAddEff,eff,n,y;
  3392. PC_BONUS_CHK_SC(type2,SP_ADDEFF);
  3393. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  3394. sd->state.lr_flag != 2 ? type3 : 0, sd->state.lr_flag == 2 ? type3 : 0, val, 0);
  3395. break;
  3396. case SP_ADDEFF_WHENHIT: // bonus3 bAddEffWhenHit,eff,n,y;
  3397. PC_BONUS_CHK_SC(type2,SP_ADDEFF_WHENHIT);
  3398. if(sd->state.lr_flag != 2)
  3399. pc_bonus_addeff(sd->addeff_atked, ARRAYLENGTH(sd->addeff_atked), (sc_type)type2, type3, 0, val, 0);
  3400. break;
  3401. case SP_ADDEFF_ONSKILL: // bonus3 bAddEffOnSkill,sk,eff,n;
  3402. PC_BONUS_CHK_SC(type2,SP_ADDEFF_ONSKILL);
  3403. if( sd->state.lr_flag != 2 )
  3404. pc_bonus_addeff_onskill(sd->addeff_onskill, ARRAYLENGTH(sd->addeff_onskill), (sc_type)type3, val, type2, ATF_TARGET, 0);
  3405. break;
  3406. case SP_ADDELE: // bonus3 bAddEle,e,x,bf;
  3407. PC_BONUS_CHK_ELEMENT(type2,SP_ADDELE);
  3408. if (sd->state.lr_flag != 2)
  3409. pc_bonus_addele(sd, (unsigned char)type2, type3, val);
  3410. break;
  3411. case SP_SUBELE: // bonus3 bSubEle,e,x,bf;
  3412. PC_BONUS_CHK_ELEMENT(type2,SP_SUBELE);
  3413. if (sd->state.lr_flag != 2)
  3414. pc_bonus_subele(sd, (unsigned char)type2, type3, val);
  3415. break;
  3416. case SP_SP_VANISH_RACE_RATE: // bonus3 bSPVanishRaceRate,r,x,n;
  3417. PC_BONUS_CHK_RACE(type2,SP_SP_VANISH_RACE_RATE);
  3418. if(sd->state.lr_flag != 2) {
  3419. sd->sp_vanish_race[type2].rate += type3;
  3420. sd->sp_vanish_race[type2].per += val;
  3421. }
  3422. break;
  3423. case SP_HP_VANISH_RACE_RATE: // bonus3 bHPVanishRaceRate,r,x,n;
  3424. PC_BONUS_CHK_RACE(type2,SP_HP_VANISH_RACE_RATE);
  3425. if(sd->state.lr_flag != 2) {
  3426. sd->hp_vanish_race[type2].rate += type3;
  3427. sd->hp_vanish_race[type2].per += val;
  3428. }
  3429. break;
  3430. case SP_STATE_NORECOVER_RACE: // bonus3 bStateNoRecoverRace,r,x,t;
  3431. PC_BONUS_CHK_RACE(type2, SP_STATE_NORECOVER_RACE);
  3432. if (sd->state.lr_flag == 2)
  3433. break;
  3434. //! CONFIRM: Is it not stackable? Does not check max or min value?
  3435. //if (type3 > sd->norecover_state_race[type2].rate) {
  3436. // sd->norecover_state_race[type2].rate = type3;
  3437. // sd->norecover_state_race[type2].tick = val;
  3438. // break;
  3439. //}
  3440. sd->norecover_state_race[type2].rate = type3;
  3441. sd->norecover_state_race[type2].tick = val;
  3442. break;
  3443. default:
  3444. ShowWarning("pc_bonus3: unknown type %d %d %d %d!\n",type,type2,type3,val);
  3445. break;
  3446. }
  3447. }
  3448. /**
  3449. * Gives item bonus to player for format: bonus4 bBonusName,type2,type3,val;
  3450. * @param sd
  3451. * @param type Bonus type used by bBonusName
  3452. * @param type2
  3453. * @param type3
  3454. * @param val Value that usually for rate or fixed value
  3455. */
  3456. void pc_bonus4(struct map_session_data *sd,int type,int type2,int type3,int type4,int val)
  3457. {
  3458. nullpo_retv(sd);
  3459. switch(type){
  3460. case SP_AUTOSPELL: // bonus4 bAutoSpell,sk,y,n,i;
  3461. if(sd->state.lr_flag != 2)
  3462. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
  3463. break;
  3464. case SP_AUTOSPELL_WHENHIT: // bonus4 bAutoSpellWhenHit,sk,y,n,i;
  3465. if(sd->state.lr_flag != 2)
  3466. 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);
  3467. break;
  3468. case SP_AUTOSPELL_ONSKILL: // bonus4 bAutoSpellOnSkill,sk,x,y,n;
  3469. if(sd->state.lr_flag != 2)
  3470. {
  3471. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3472. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill_get_inf2(type2)&INF2_NO_TARGET_SELF));
  3473. pc_bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, target?-type3:type3, type4, val, current_equip_card_id);
  3474. }
  3475. break;
  3476. case SP_ADDEFF: // bonus4 bAddEff,eff,n,y,t;
  3477. PC_BONUS_CHK_SC(type2,SP_ADDEFF);
  3478. pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2,
  3479. sd->state.lr_flag != 2 ? type3 : 0, sd->state.lr_flag == 2 ? type3 : 0, type4, val);
  3480. break;
  3481. case SP_ADDEFF_WHENHIT: // bonus4 bAddEffWhenHit,eff,n,y,t;
  3482. PC_BONUS_CHK_SC(type2,SP_ADDEFF_WHENHIT);
  3483. if (sd->state.lr_flag != 2)
  3484. pc_bonus_addeff(sd->addeff_atked, ARRAYLENGTH(sd->addeff_atked), (sc_type)type2, type3, 0, type4, val);
  3485. break;
  3486. case SP_ADDEFF_ONSKILL: // bonus4 bAddEffOnSkill,sk,eff,n,y;
  3487. PC_BONUS_CHK_SC(type3,SP_ADDEFF_ONSKILL);
  3488. if( sd->state.lr_flag != 2 )
  3489. pc_bonus_addeff_onskill(sd->addeff_onskill, ARRAYLENGTH(sd->addeff_onskill), (sc_type)type3, type4, type2, val, 0);
  3490. break;
  3491. case SP_SET_DEF_RACE: // bonus4 bSetDefRace,r,n,t,y;
  3492. PC_BONUS_CHK_RACE(type2,SP_SET_DEF_RACE);
  3493. if(sd->state.lr_flag == 2)
  3494. break;
  3495. sd->def_set_race[type2].rate = type3;
  3496. sd->def_set_race[type2].tick = type4;
  3497. sd->def_set_race[type2].value = val;
  3498. break;
  3499. case SP_SET_MDEF_RACE: // bonus4 bSetMDefRace,r,n,t,y;
  3500. PC_BONUS_CHK_RACE(type2,SP_SET_MDEF_RACE);
  3501. if(sd->state.lr_flag == 2)
  3502. break;
  3503. sd->mdef_set_race[type2].rate = type3;
  3504. sd->mdef_set_race[type2].tick = type4;
  3505. sd->mdef_set_race[type2].value = val;
  3506. break;
  3507. default:
  3508. ShowWarning("pc_bonus4: unknown type %d %d %d %d %d!\n",type,type2,type3,type4,val);
  3509. break;
  3510. }
  3511. }
  3512. /**
  3513. * Gives item bonus to player for format: bonus5 bBonusName,type2,type3,type4,val;
  3514. * @param sd
  3515. * @param type Bonus type used by bBonusName
  3516. * @param type2
  3517. * @param type3
  3518. * @param type4
  3519. * @param val Value that usually for rate or fixed value
  3520. */
  3521. void pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4,int type5,int val)
  3522. {
  3523. nullpo_retv(sd);
  3524. switch(type){
  3525. case SP_AUTOSPELL: // bonus5 bAutoSpell,sk,y,n,bf,i;
  3526. if(sd->state.lr_flag != 2)
  3527. pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  3528. break;
  3529. case SP_AUTOSPELL_WHENHIT: // bonus5 bAutoSpellWhenHit,sk,y,n,bf,i;
  3530. if(sd->state.lr_flag != 2)
  3531. pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  3532. break;
  3533. case SP_AUTOSPELL_ONSKILL: // bonus5 bAutoSpellOnSkill,sk,x,y,n,i;
  3534. if(sd->state.lr_flag != 2)
  3535. pc_bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, (val&1?-type3:type3), (val&2?-type4:type4), type5, current_equip_card_id);
  3536. break;
  3537. case SP_ADDEFF_ONSKILL: // bonus5 bAddEffOnSkill,sk,eff,n,y,t;
  3538. PC_BONUS_CHK_SC(type3,SP_ADDEFF_ONSKILL);
  3539. if( sd->state.lr_flag != 2 )
  3540. pc_bonus_addeff_onskill(sd->addeff_onskill, ARRAYLENGTH(sd->addeff_onskill), (sc_type)type3, type4, type2, type5, val);
  3541. break;
  3542. default:
  3543. ShowWarning("pc_bonus5: unknown type %d %d %d %d %d %d!\n",type,type2,type3,type4,type5,val);
  3544. break;
  3545. }
  3546. }
  3547. /*==========================================
  3548. * Grants a player a given skill. Flag values are:
  3549. * 0 - Grant permanent skill to be bound to skill tree
  3550. * 1 - Grant an item skill (temporary)
  3551. * 2 - Like 1, except the level granted can stack with previously learned level.
  3552. * 4 - Like 0, except the skill will ignore skill tree (saves through job changes and resets).
  3553. *------------------------------------------*/
  3554. bool pc_skill(TBL_PC* sd, uint16 skill_id, int level, enum e_addskill_type type) {
  3555. uint16 idx = 0;
  3556. nullpo_ret(sd);
  3557. if (!skill_id || !(idx = skill_get_index(skill_id))) {
  3558. ShowError("pc_skill: Skill with id %d does not exist in the skill database\n", skill_id);
  3559. return false;
  3560. }
  3561. if (level > MAX_SKILL_LEVEL) {
  3562. ShowError("pc_skill: Skill level %d too high. Max lv supported is %d\n", level, MAX_SKILL_LEVEL);
  3563. return false;
  3564. }
  3565. if (type == ADDSKILL_TEMP_ADDLEVEL && sd->status.skill[idx].lv + level > MAX_SKILL_LEVEL) {
  3566. ShowWarning("pc_skill: Skill level bonus %d too high. Max lv supported is %d. Curr lv is %d. Set to max level.\n", level, MAX_SKILL_LEVEL, sd->status.skill[idx].lv);
  3567. level = MAX_SKILL_LEVEL - sd->status.skill[idx].lv;
  3568. }
  3569. switch (type) {
  3570. case ADDSKILL_PERMANENT: //Set skill data overwriting whatever was there before.
  3571. sd->status.skill[idx].id = skill_id;
  3572. sd->status.skill[idx].lv = level;
  3573. sd->status.skill[idx].flag = SKILL_FLAG_PERMANENT;
  3574. if (level == 0) { //Remove skill.
  3575. sd->status.skill[idx].id = 0;
  3576. clif_deleteskill(sd,skill_id);
  3577. } else
  3578. clif_addskill(sd,skill_id);
  3579. if (!skill_get_inf(skill_id)) //Only recalculate for passive skills.
  3580. status_calc_pc(sd, SCO_NONE);
  3581. break;
  3582. case ADDSKILL_TEMP: //Item bonus skill.
  3583. if (sd->status.skill[idx].id != 0) {
  3584. if (sd->status.skill[idx].lv >= level)
  3585. return true;
  3586. if (sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT) //Non-granted skill, store it's level.
  3587. sd->status.skill[idx].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[idx].lv;
  3588. } else {
  3589. sd->status.skill[idx].id = skill_id;
  3590. sd->status.skill[idx].flag = SKILL_FLAG_TEMPORARY;
  3591. }
  3592. sd->status.skill[idx].lv = level;
  3593. break;
  3594. case ADDSKILL_TEMP_ADDLEVEL: //Add skill bonus on top of what you had.
  3595. if (sd->status.skill[idx].id != 0) {
  3596. if (sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT)
  3597. sd->status.skill[idx].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[idx].lv; // Store previous level.
  3598. } else {
  3599. sd->status.skill[idx].id = skill_id;
  3600. sd->status.skill[idx].flag = SKILL_FLAG_TEMPORARY; //Set that this is a bonus skill.
  3601. }
  3602. sd->status.skill[idx].lv += level;
  3603. break;
  3604. case ADDSKILL_PERMANENT_GRANTED: //Permanent granted skills ignore the skill tree
  3605. sd->status.skill[idx].id = skill_id;
  3606. sd->status.skill[idx].lv = level;
  3607. sd->status.skill[idx].flag = SKILL_FLAG_PERM_GRANTED;
  3608. if (level == 0) { //Remove skill.
  3609. sd->status.skill[idx].id = 0;
  3610. clif_deleteskill(sd,skill_id);
  3611. } else
  3612. clif_addskill(sd,skill_id);
  3613. if (!skill_get_inf(skill_id)) //Only recalculate for passive skills.
  3614. status_calc_pc(sd, SCO_NONE);
  3615. break;
  3616. default:
  3617. return false;
  3618. }
  3619. return true;
  3620. }
  3621. /*==========================================
  3622. * Append a card to an item ?
  3623. *------------------------------------------*/
  3624. int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip)
  3625. {
  3626. int i;
  3627. unsigned short nameid;
  3628. nullpo_ret(sd);
  3629. if( idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL )
  3630. return 0; //Invalid item index.
  3631. if( idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL )
  3632. return 0; //Invalid card index.
  3633. if( sd->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1 )
  3634. return 0; // target item missing
  3635. if( sd->status.inventory[idx_card].nameid <= 0 || sd->status.inventory[idx_card].amount < 1 )
  3636. return 0; // target card missing
  3637. if( sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR )
  3638. return 0; // only weapons and armor are allowed
  3639. if( sd->inventory_data[idx_card]->type != IT_CARD )
  3640. return 0; // must be a card
  3641. if( sd->status.inventory[idx_equip].identify == 0 )
  3642. return 0; // target must be identified
  3643. if( itemdb_isspecial(sd->status.inventory[idx_equip].card[0]) )
  3644. return 0; // card slots reserved for other purposes
  3645. if( (sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0 )
  3646. return 0; // card cannot be compounded on this item type
  3647. if( sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD )
  3648. return 0; // attempted to place shield card on left-hand weapon.
  3649. if( sd->status.inventory[idx_equip].equip != 0 )
  3650. return 0; // item must be unequipped
  3651. ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0 );
  3652. if( i == sd->inventory_data[idx_equip]->slot )
  3653. return 0; // no free slots
  3654. // remember the card id to insert
  3655. nameid = sd->status.inventory[idx_card].nameid;
  3656. if( pc_delitem(sd,idx_card,1,1,0,LOG_TYPE_OTHER) == 1 )
  3657. {// failed
  3658. clif_insert_card(sd,idx_equip,idx_card,1);
  3659. }
  3660. else
  3661. {// success
  3662. log_pick_pc(sd, LOG_TYPE_OTHER, -1, &sd->status.inventory[idx_equip]);
  3663. sd->status.inventory[idx_equip].card[i] = nameid;
  3664. log_pick_pc(sd, LOG_TYPE_OTHER, 1, &sd->status.inventory[idx_equip]);
  3665. clif_insert_card(sd,idx_equip,idx_card,0);
  3666. }
  3667. return 0;
  3668. }
  3669. //
  3670. // Items
  3671. //
  3672. /*==========================================
  3673. * Update buying value by skills
  3674. *------------------------------------------*/
  3675. int pc_modifybuyvalue(struct map_session_data *sd,int orig_value)
  3676. {
  3677. int skill,val = orig_value,rate1 = 0,rate2 = 0;
  3678. if((skill=pc_checkskill(sd,MC_DISCOUNT))>0) // merchant discount
  3679. rate1 = 5+skill*2-((skill==10)? 1:0);
  3680. if((skill=pc_checkskill(sd,RG_COMPULSION))>0) // rogue discount
  3681. rate2 = 5+skill*4;
  3682. if(rate1 < rate2) rate1 = rate2;
  3683. if(rate1)
  3684. val = (int)((double)orig_value*(double)(100-rate1)/100.);
  3685. if(val < 0) val = 0;
  3686. if(orig_value > 0 && val < 1) val = 1;
  3687. return val;
  3688. }
  3689. /*==========================================
  3690. * Update selling value by skills
  3691. *------------------------------------------*/
  3692. int pc_modifysellvalue(struct map_session_data *sd,int orig_value)
  3693. {
  3694. int skill,val = orig_value,rate = 0;
  3695. if((skill=pc_checkskill(sd,MC_OVERCHARGE))>0) //OverCharge
  3696. rate = 5+skill*2-((skill==10)? 1:0);
  3697. if(rate)
  3698. val = (int)((double)orig_value*(double)(100+rate)/100.);
  3699. if(val < 0) val = 0;
  3700. if(orig_value > 0 && val < 1) val = 1;
  3701. return val;
  3702. }
  3703. /*==========================================
  3704. * Checking if we have enough place on inventory for new item
  3705. * Make sure to take 30k as limit (for client I guess)
  3706. * @param sd
  3707. * @param nameid
  3708. * @param amount
  3709. * @return e_chkitem_result
  3710. *------------------------------------------*/
  3711. char pc_checkadditem(struct map_session_data *sd, unsigned short nameid, int amount)
  3712. {
  3713. int i;
  3714. struct item_data* data;
  3715. nullpo_ret(sd);
  3716. if(amount > MAX_AMOUNT)
  3717. return CHKADDITEM_OVERAMOUNT;
  3718. data = itemdb_search(nameid);
  3719. if(!itemdb_isstackable2(data))
  3720. return CHKADDITEM_NEW;
  3721. if( data->stack.inventory && amount > data->stack.amount )
  3722. return CHKADDITEM_OVERAMOUNT;
  3723. for(i=0;i<MAX_INVENTORY;i++){
  3724. // FIXME: This does not consider the checked item's cards, thus could check a wrong slot for stackability.
  3725. if(sd->status.inventory[i].nameid==nameid){
  3726. if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) )
  3727. return CHKADDITEM_OVERAMOUNT;
  3728. return CHKADDITEM_EXIST;
  3729. }
  3730. }
  3731. return CHKADDITEM_NEW;
  3732. }
  3733. /*==========================================
  3734. * Return number of available place in inventory
  3735. * Each non stackable item will reduce place by 1
  3736. * @param sd
  3737. * @return Number of empty slots
  3738. *------------------------------------------*/
  3739. uint8 pc_inventoryblank(struct map_session_data *sd)
  3740. {
  3741. uint8 i, b;
  3742. nullpo_ret(sd);
  3743. for(i = 0, b = 0; i < MAX_INVENTORY; i++){
  3744. if(sd->status.inventory[i].nameid==0)
  3745. b++;
  3746. }
  3747. return b;
  3748. }
  3749. /*==========================================
  3750. * attempts to remove zeny from player (sd)
  3751. * @param sd
  3752. * @param zeny Zeny removed
  3753. * @param type e_log_pick_type
  3754. * @param tsd (just for log?)
  3755. * @return 0 - Success, 1 - Failed
  3756. *------------------------------------------*/
  3757. char pc_payzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type, struct map_session_data *tsd)
  3758. {
  3759. nullpo_retr(2,sd);
  3760. zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3761. if( zeny < 0 )
  3762. {
  3763. ShowError("pc_payzeny: Paying negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
  3764. return 1;
  3765. }
  3766. if( sd->status.zeny < zeny )
  3767. return 1; //Not enough.
  3768. sd->status.zeny -= zeny;
  3769. clif_updatestatus(sd,SP_ZENY);
  3770. if(!tsd) tsd = sd;
  3771. log_zeny(sd, type, tsd, -zeny);
  3772. if( zeny > 0 && sd->state.showzeny ) {
  3773. char output[255];
  3774. sprintf(output, "Removed %dz.", zeny);
  3775. clif_disp_onlyself(sd,output,strlen(output));
  3776. }
  3777. return 0;
  3778. }
  3779. /** Makes player pays by using cash points
  3780. * @param sd Player who pays
  3781. * @param price How many point player has to pay
  3782. * @param points
  3783. * @param type e_log_pick_type
  3784. * @return -2: Paying negative points, -1: Not enough points, otherwise is succes (cash+points)
  3785. */
  3786. int pc_paycash(struct map_session_data *sd, int price, int points, e_log_pick_type type ){
  3787. int cash;
  3788. nullpo_retr(-1,sd);
  3789. points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3790. if( price < 0 || points < 0 )
  3791. {
  3792. 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);
  3793. return -2;
  3794. }
  3795. if( points > price )
  3796. {
  3797. 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);
  3798. points = price;
  3799. }
  3800. cash = price-points;
  3801. if( sd->cashPoints < cash || sd->kafraPoints < points )
  3802. {
  3803. 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);
  3804. return -1;
  3805. }
  3806. pc_setaccountreg(sd, add_str("#CASHPOINTS"), sd->cashPoints-cash);
  3807. if( cash ){
  3808. log_cash( sd, type, LOG_CASH_TYPE_CASH, -cash );
  3809. }
  3810. pc_setaccountreg(sd, add_str("#KAFRAPOINTS"), sd->kafraPoints-points);
  3811. if( points ){
  3812. log_cash( sd, type, LOG_CASH_TYPE_KAFRA, -points );
  3813. }
  3814. if( battle_config.cashshop_show_points )
  3815. {
  3816. char output[128];
  3817. sprintf(output, msg_txt(sd,504), points, cash, sd->kafraPoints, sd->cashPoints);
  3818. clif_disp_onlyself(sd, output, strlen(output));
  3819. }
  3820. return cash+points;
  3821. }
  3822. int pc_getcash( struct map_session_data *sd, int cash, int points, e_log_pick_type type ){
  3823. char output[128];
  3824. nullpo_retr(-1,sd);
  3825. cash = cap_value(cash,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3826. points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3827. if( cash > 0 )
  3828. {
  3829. if( cash > MAX_ZENY-sd->cashPoints )
  3830. {
  3831. 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);
  3832. cash = MAX_ZENY-sd->cashPoints;
  3833. }
  3834. pc_setaccountreg(sd, add_str("#CASHPOINTS"), sd->cashPoints+cash);
  3835. if( cash ){
  3836. log_cash( sd, type, LOG_CASH_TYPE_CASH, cash );
  3837. }
  3838. if( battle_config.cashshop_show_points )
  3839. {
  3840. sprintf(output, msg_txt(sd,505), cash, sd->cashPoints);
  3841. clif_disp_onlyself(sd, output, strlen(output));
  3842. }
  3843. return cash;
  3844. }
  3845. else if( cash < 0 )
  3846. {
  3847. 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);
  3848. return -1;
  3849. }
  3850. if( points > 0 )
  3851. {
  3852. if( points > MAX_ZENY-sd->kafraPoints )
  3853. {
  3854. 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);
  3855. points = MAX_ZENY-sd->kafraPoints;
  3856. }
  3857. pc_setaccountreg(sd, add_str("#KAFRAPOINTS"), sd->kafraPoints+points);
  3858. if( points ){
  3859. log_cash( sd, type, LOG_CASH_TYPE_KAFRA, points );
  3860. }
  3861. if( battle_config.cashshop_show_points )
  3862. {
  3863. sprintf(output, msg_txt(sd,506), points, sd->kafraPoints);
  3864. clif_disp_onlyself(sd, output, strlen(output));
  3865. }
  3866. return points;
  3867. }
  3868. else if( points < 0 )
  3869. {
  3870. 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);
  3871. return -1;
  3872. }
  3873. return -2; //shouldn't happen but jsut in case
  3874. }
  3875. /*==========================================
  3876. * Attempts to give zeny to player (sd)
  3877. * tsd (optional) from who for log (if null take sd)
  3878. *------------------------------------------*/
  3879. char pc_getzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type, struct map_session_data *tsd)
  3880. {
  3881. nullpo_retr(-1,sd);
  3882. zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
  3883. if( zeny < 0 )
  3884. {
  3885. ShowError("pc_getzeny: Obtaining negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
  3886. return 1;
  3887. }
  3888. if( zeny > MAX_ZENY - sd->status.zeny )
  3889. zeny = MAX_ZENY - sd->status.zeny;
  3890. sd->status.zeny += zeny;
  3891. clif_updatestatus(sd,SP_ZENY);
  3892. if(!tsd) tsd = sd;
  3893. log_zeny(sd, type, tsd, zeny);
  3894. if( zeny > 0 && sd->state.showzeny ) {
  3895. char output[255];
  3896. sprintf(output, "Gained %dz.", zeny);
  3897. clif_disp_onlyself(sd,output,strlen(output));
  3898. }
  3899. return 0;
  3900. }
  3901. /**
  3902. * Searching a specified itemid in inventory and return his stored index
  3903. * @param sd Player
  3904. * @param nameid Find this Item!
  3905. * @return Stored index in inventory, or -1 if not found.
  3906. **/
  3907. short pc_search_inventory(struct map_session_data *sd, unsigned short nameid) {
  3908. short i;
  3909. nullpo_retr(-1, sd);
  3910. ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == nameid && (sd->status.inventory[i].amount > 0 || nameid == 0) );
  3911. return ( i < MAX_INVENTORY ) ? i : -1;
  3912. }
  3913. /** Attempt to add a new item to player inventory
  3914. * @param sd
  3915. * @param item_data
  3916. * @param amount
  3917. * @param log_type
  3918. * @return
  3919. * 0 = success
  3920. * 1 = invalid itemid not found or negative amount
  3921. * 2 = overweight
  3922. * 3 = ?
  3923. * 4 = no free place found
  3924. * 5 = max amount reached
  3925. * 6 = ?
  3926. * 7 = stack limitation
  3927. */
  3928. char pc_additem(struct map_session_data *sd,struct item *item,int amount,e_log_pick_type log_type) {
  3929. struct item_data *id;
  3930. int16 i;
  3931. unsigned int w;
  3932. nullpo_retr(1, sd);
  3933. nullpo_retr(1, item);
  3934. if( item->nameid == 0 || amount <= 0 )
  3935. return ADDITEM_INVALID;
  3936. if( amount > MAX_AMOUNT )
  3937. return ADDITEM_OVERAMOUNT;
  3938. id = itemdb_search(item->nameid);
  3939. if( id->stack.inventory && amount > id->stack.amount )
  3940. {// item stack limitation
  3941. return ADDITEM_STACKLIMIT;
  3942. }
  3943. w = id->weight*amount;
  3944. if(sd->weight + w > sd->max_weight)
  3945. return ADDITEM_OVERWEIGHT;
  3946. i = MAX_INVENTORY;
  3947. if (id->flag.guid && !item->unique_id)
  3948. item->unique_id = pc_generate_unique_id(sd);
  3949. // Stackable | Non Rental
  3950. if( itemdb_isstackable2(id) && item->expire_time == 0 ) {
  3951. for( i = 0; i < MAX_INVENTORY; i++ ) {
  3952. if( sd->status.inventory[i].nameid == item->nameid &&
  3953. sd->status.inventory[i].bound == item->bound &&
  3954. sd->status.inventory[i].expire_time == 0 &&
  3955. sd->status.inventory[i].unique_id == item->unique_id &&
  3956. memcmp(&sd->status.inventory[i].card, &item->card, sizeof(item->card)) == 0
  3957. )
  3958. {
  3959. if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( id->stack.inventory && amount > id->stack.amount - sd->status.inventory[i].amount ) )
  3960. return ADDITEM_OVERAMOUNT;
  3961. sd->status.inventory[i].amount += amount;
  3962. clif_additem(sd,i,amount,0);
  3963. break;
  3964. }
  3965. }
  3966. }
  3967. if (i >= MAX_INVENTORY) {
  3968. i = pc_search_inventory(sd,0);
  3969. if( i < 0 )
  3970. return ADDITEM_OVERITEM;
  3971. memcpy(&sd->status.inventory[i], item, sizeof(sd->status.inventory[0]));
  3972. // clear equip and favorite fields first, just in case
  3973. if( item->equip )
  3974. sd->status.inventory[i].equip = 0;
  3975. if( item->favorite )
  3976. sd->status.inventory[i].favorite = 0;
  3977. sd->status.inventory[i].amount = amount;
  3978. sd->inventory_data[i] = id;
  3979. sd->last_addeditem_index = i;
  3980. if (!itemdb_isstackable2(id) || id->flag.guid)
  3981. sd->status.inventory[i].unique_id = item->unique_id ? item->unique_id : pc_generate_unique_id(sd);
  3982. clif_additem(sd,i,amount,0);
  3983. }
  3984. log_pick_pc(sd, log_type, amount, &sd->status.inventory[i]);
  3985. sd->weight += w;
  3986. clif_updatestatus(sd,SP_WEIGHT);
  3987. //Auto-equip
  3988. if(id->flag.autoequip)
  3989. pc_equipitem(sd, i, id->equip);
  3990. /* rental item check */
  3991. if( item->expire_time ) {
  3992. if( time(NULL) > item->expire_time ) {
  3993. clif_rental_expired(sd->fd, i, sd->status.inventory[i].nameid);
  3994. pc_delitem(sd, i, sd->status.inventory[i].amount, 1, 0, LOG_TYPE_OTHER);
  3995. } else {
  3996. unsigned int seconds = (unsigned int)( item->expire_time - time(NULL) );
  3997. clif_rental_time(sd->fd, sd->status.inventory[i].nameid, seconds);
  3998. pc_inventory_rental_add(sd, seconds);
  3999. }
  4000. }
  4001. return ADDITEM_SUCCESS;
  4002. }
  4003. /*==========================================
  4004. * Remove an item at index n from inventory by amount.
  4005. * @param sd
  4006. * @param n Item index in inventory
  4007. * @param amount
  4008. * @param type &1: Don't notify deletion; &2 Don't notify weight change
  4009. * @param reason Delete reason
  4010. * @param log_type e_log_pick_type
  4011. * @return 1 - invalid itemid or negative amount; 0 - Success
  4012. *------------------------------------------*/
  4013. char pc_delitem(struct map_session_data *sd,int n,int amount,int type, short reason, e_log_pick_type log_type)
  4014. {
  4015. nullpo_retr(1, sd);
  4016. if(n < 0 || sd->status.inventory[n].nameid==0 || amount <= 0 || sd->status.inventory[n].amount<amount || sd->inventory_data[n] == NULL)
  4017. return 1;
  4018. log_pick_pc(sd, log_type, -amount, &sd->status.inventory[n]);
  4019. sd->status.inventory[n].amount -= amount;
  4020. sd->weight -= sd->inventory_data[n]->weight*amount ;
  4021. if( sd->status.inventory[n].amount <= 0 ){
  4022. if(sd->status.inventory[n].equip)
  4023. pc_unequipitem(sd,n,3);
  4024. memset(&sd->status.inventory[n],0,sizeof(sd->status.inventory[0]));
  4025. sd->inventory_data[n] = NULL;
  4026. }
  4027. if(!(type&1))
  4028. clif_delitem(sd,n,amount,reason);
  4029. if(!(type&2))
  4030. clif_updatestatus(sd,SP_WEIGHT);
  4031. return 0;
  4032. }
  4033. /*==========================================
  4034. * Attempt to drop an item.
  4035. * @param sd
  4036. * @param n Item index in inventory
  4037. * @param amount Amount of item
  4038. * @return False = fail; True = success
  4039. *------------------------------------------*/
  4040. bool pc_dropitem(struct map_session_data *sd,int n,int amount)
  4041. {
  4042. nullpo_retr(1, sd);
  4043. if(n < 0 || n >= MAX_INVENTORY)
  4044. return false;
  4045. if(amount <= 0)
  4046. return false;
  4047. if(sd->status.inventory[n].nameid <= 0 ||
  4048. sd->status.inventory[n].amount <= 0 ||
  4049. sd->status.inventory[n].amount < amount ||
  4050. sd->state.trading || sd->state.vending ||
  4051. !sd->inventory_data[n] //pc_delitem would fail on this case.
  4052. )
  4053. return false;
  4054. if( map[sd->bl.m].flag.nodrop )
  4055. {
  4056. clif_displaymessage (sd->fd, msg_txt(sd,271));
  4057. return false; //Can't drop items in nodrop mapflag maps.
  4058. }
  4059. if( !pc_candrop(sd,&sd->status.inventory[n]) )
  4060. {
  4061. clif_displaymessage (sd->fd, msg_txt(sd,263));
  4062. return false;
  4063. }
  4064. if (!map_addflooritem(&sd->status.inventory[n], amount, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 2, 0))
  4065. return false;
  4066. pc_delitem(sd, n, amount, 1, 0, LOG_TYPE_PICKDROP_PLAYER);
  4067. clif_dropitem(sd, n, amount);
  4068. return true;
  4069. }
  4070. /*==========================================
  4071. * Attempt to pick up an item.
  4072. * @param sd
  4073. * @param fitem Item that will be picked
  4074. * @return False = fail; True = success
  4075. *------------------------------------------*/
  4076. bool pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem)
  4077. {
  4078. int flag = 0;
  4079. unsigned int tick = gettick();
  4080. struct party_data *p = NULL;
  4081. nullpo_ret(sd);
  4082. nullpo_ret(fitem);
  4083. if (!check_distance_bl(&fitem->bl, &sd->bl, 2) && sd->ud.skill_id!=BS_GREED)
  4084. return false; // Distance is too far
  4085. if (sd->sc.cant.pickup)
  4086. return false;
  4087. if (sd->status.party_id)
  4088. p = party_search(sd->status.party_id);
  4089. if (fitem->first_get_charid > 0 && fitem->first_get_charid != sd->status.char_id) {
  4090. struct map_session_data *first_sd = map_charid2sd(fitem->first_get_charid);
  4091. if (DIFF_TICK(tick,fitem->first_get_tick) < 0) {
  4092. if (!(p && p->party.item&1 &&
  4093. first_sd && first_sd->status.party_id == sd->status.party_id
  4094. ))
  4095. return false;
  4096. }
  4097. else if (fitem->second_get_charid > 0 && fitem->second_get_charid != sd->status.char_id) {
  4098. struct map_session_data *second_sd = map_charid2sd(fitem->second_get_charid);
  4099. if (DIFF_TICK(tick, fitem->second_get_tick) < 0) {
  4100. if (!(p && p->party.item&1 &&
  4101. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  4102. (second_sd && second_sd->status.party_id == sd->status.party_id))
  4103. ))
  4104. return false;
  4105. }
  4106. else if (fitem->third_get_charid > 0 && fitem->third_get_charid != sd->status.char_id){
  4107. struct map_session_data *third_sd = map_charid2sd(fitem->third_get_charid);
  4108. if (DIFF_TICK(tick,fitem->third_get_tick) < 0) {
  4109. if(!(p && p->party.item&1 &&
  4110. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  4111. (second_sd && second_sd->status.party_id == sd->status.party_id) ||
  4112. (third_sd && third_sd->status.party_id == sd->status.party_id))
  4113. ))
  4114. return false;
  4115. }
  4116. }
  4117. }
  4118. }
  4119. //This function takes care of giving the item to whoever should have it, considering party-share options.
  4120. if ((flag = party_share_loot(p,sd,&fitem->item, fitem->first_get_charid))) {
  4121. clif_additem(sd,0,0,flag);
  4122. return true;
  4123. }
  4124. //Display pickup animation.
  4125. pc_stop_attack(sd);
  4126. clif_takeitem(&sd->bl,&fitem->bl);
  4127. if (fitem->mob_id &&
  4128. (itemdb_search(fitem->item.nameid))->flag.broadcast &&
  4129. (!p || !(p->party.item&2)) // Somehow, if party's pickup distribution is 'Even Share', no announcemet
  4130. )
  4131. intif_broadcast_obtain_special_item(sd, fitem->item.nameid, fitem->mob_id, ITEMOBTAIN_TYPE_MONSTER_ITEM);
  4132. map_clearflooritem(&fitem->bl);
  4133. return true;
  4134. }
  4135. /*==========================================
  4136. * Check if item is usable.
  4137. * Return:
  4138. * 0 = no
  4139. * 1 = yes
  4140. *------------------------------------------*/
  4141. bool pc_isUseitem(struct map_session_data *sd,int n)
  4142. {
  4143. struct item_data *item;
  4144. unsigned short nameid;
  4145. nullpo_ret(sd);
  4146. item = sd->inventory_data[n];
  4147. nameid = sd->status.inventory[n].nameid;
  4148. if( item == NULL )
  4149. return false;
  4150. //Not consumable item
  4151. if( item->type != IT_HEALING && item->type != IT_USABLE && item->type != IT_CASH )
  4152. return false;
  4153. if( !item->script ) //if it has no script, you can't really consume it!
  4154. return false;
  4155. if (pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL))
  4156. return true;
  4157. if(map[sd->bl.m].flag.noitemconsumption) //consumable but mapflag prevent it
  4158. return false;
  4159. //Prevent mass item usage. [Skotlex]
  4160. if( DIFF_TICK(sd->canuseitem_tick,gettick()) > 0 ||
  4161. (itemdb_iscashfood(nameid) && DIFF_TICK(sd->canusecashfood_tick,gettick()) > 0)
  4162. )
  4163. return false;
  4164. if( (item->item_usage.flag&NOUSE_SITTING) && (pc_issit(sd) == 1) && (pc_get_group_level(sd) < item->item_usage.override) ) {
  4165. clif_msg(sd,ITEM_NOUSE_SITTING);
  4166. return false; // You cannot use this item while sitting.
  4167. }
  4168. if (sd->state.storage_flag && item->type != IT_CASH) {
  4169. clif_colormes(sd->fd, color_table[COLOR_RED], msg_txt(sd,388));
  4170. return false; // You cannot use this item while storage is open.
  4171. }
  4172. if (item->flag.dead_branch && (map[sd->bl.m].flag.nobranch || map_flag_gvg(sd->bl.m)))
  4173. return false;
  4174. switch( nameid ) {
  4175. case ITEMID_ANODYNE:
  4176. if( map_flag_gvg(sd->bl.m) )
  4177. return false;
  4178. case ITEMID_ALOEBERA:
  4179. if( pc_issit(sd) )
  4180. return false;
  4181. break;
  4182. case ITEMID_WING_OF_FLY:
  4183. case ITEMID_GIANT_FLY_WING:
  4184. if( map[sd->bl.m].flag.noteleport || map_flag_gvg(sd->bl.m) ) {
  4185. clif_skill_teleportmessage(sd,0);
  4186. return false;
  4187. }
  4188. case ITEMID_WING_OF_BUTTERFLY:
  4189. case ITEMID_DUN_TELE_SCROLL1:
  4190. case ITEMID_DUN_TELE_SCROLL2:
  4191. case ITEMID_DUN_TELE_SCROLL3:
  4192. case ITEMID_WOB_RUNE:
  4193. case ITEMID_WOB_SCHWALTZ:
  4194. case ITEMID_WOB_RACHEL:
  4195. case ITEMID_WOB_LOCAL:
  4196. case ITEMID_SIEGE_TELEPORT_SCROLL:
  4197. if( sd->duel_group && !battle_config.duel_allow_teleport ) {
  4198. clif_displaymessage(sd->fd, msg_txt(sd,663));
  4199. return false;
  4200. }
  4201. if( nameid != 601 && nameid != 12212 && map[sd->bl.m].flag.noreturn )
  4202. return false;
  4203. break;
  4204. case ITEMID_BUBBLE_GUM:
  4205. case ITEMID_COMP_BUBBLE_GUM:
  4206. if( sd->sc.data[SC_ITEMBOOST] )
  4207. return false;
  4208. break;
  4209. case ITEMID_BATTLE_MANUAL:
  4210. case ITEMID_COMP_BATTLE_MANUAL:
  4211. case ITEMID_THICK_BATTLE_MANUAL:
  4212. case ITEMID_NOBLE_NAMEPLATE:
  4213. case ITEMID_BATTLE_MANUAL25:
  4214. case ITEMID_BATTLE_MANUAL100:
  4215. case ITEMID_BATTLE_MANUAL300:
  4216. if( sd->sc.data[SC_EXPBOOST] )
  4217. return false;
  4218. break;
  4219. case ITEMID_JOB_MANUAL50:
  4220. if( sd->sc.data[SC_JEXPBOOST] )
  4221. return false;
  4222. break;
  4223. case ITEMID_MERCENARY_RED_POTION:
  4224. case ITEMID_MERCENARY_BLUE_POTION:
  4225. case ITEMID_M_CENTER_POTION:
  4226. case ITEMID_M_AWAKENING_POTION:
  4227. case ITEMID_M_BERSERK_POTION:
  4228. if( sd->md == NULL || sd->md->db == NULL )
  4229. return false;
  4230. if( sd->md->sc.data[SC_BERSERK] )
  4231. return false;
  4232. if( nameid == ITEMID_M_AWAKENING_POTION && sd->md->db->lv < 40 )
  4233. return false;
  4234. if( nameid == ITEMID_M_BERSERK_POTION && sd->md->db->lv < 80 )
  4235. return false;
  4236. break;
  4237. case ITEMID_NEURALIZER:
  4238. if( !map[sd->bl.m].flag.reset )
  4239. return false;
  4240. break;
  4241. }
  4242. if( nameid >= ITEMID_BOW_MERCENARY_SCROLL1 && nameid <= ITEMID_SPEARMERCENARY_SCROLL10 && sd->md != NULL )
  4243. return false; // Mercenary Scrolls
  4244. /**
  4245. * Only Rune Knights may use runes
  4246. **/
  4247. if( itemdb_is_rune(nameid) && (sd->class_&MAPID_THIRDMASK) != MAPID_RUNE_KNIGHT )
  4248. return false;
  4249. /**
  4250. * Only GCross may use poisons
  4251. **/
  4252. else if( itemdb_is_poison(nameid) && (sd->class_&MAPID_THIRDMASK) != MAPID_GUILLOTINE_CROSS )
  4253. return false;
  4254. if( item->flag.group || item->type == IT_CASH) { //safe check type cash disappear when overweight [Napster]
  4255. if( pc_is90overweight(sd) ) {
  4256. clif_msg(sd, ITEM_CANT_OBTAIN_WEIGHT);
  4257. return false;
  4258. }
  4259. if( !pc_inventoryblank(sd) ) {
  4260. clif_colormes(sd->fd, color_table[COLOR_RED], msg_txt(sd, 732)); //Item cannot be open when inventory is full
  4261. return false;
  4262. }
  4263. }
  4264. //Gender check
  4265. if(item->sex != 2 && sd->status.sex != item->sex)
  4266. return false;
  4267. //Required level check
  4268. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  4269. return false;
  4270. if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
  4271. return false;
  4272. //Not equipable by class. [Skotlex]
  4273. if (!(
  4274. (1<<(sd->class_&MAPID_BASEMASK)) &
  4275. (item->class_base[sd->class_&JOBL_2_1?1:(sd->class_&JOBL_2_2?2:0)])
  4276. ))
  4277. return false;
  4278. if (sd->sc.count && (
  4279. sd->sc.data[SC_BERSERK] || sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  4280. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF) ||
  4281. sd->sc.data[SC_TRICKDEAD] ||
  4282. sd->sc.data[SC_HIDING] ||
  4283. sd->sc.data[SC__SHADOWFORM] ||
  4284. sd->sc.data[SC__INVISIBILITY] ||
  4285. sd->sc.data[SC__MANHOLE] ||
  4286. sd->sc.data[SC_KAGEHUMI] ||
  4287. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM) ||
  4288. sd->sc.data[SC_HEAT_BARREL_AFTER]))
  4289. return false;
  4290. if (!pc_isItemClass(sd,item))
  4291. return false;
  4292. //Dead Branch items
  4293. if( item->flag.dead_branch )
  4294. log_branch(sd);
  4295. return true;
  4296. }
  4297. /*==========================================
  4298. * Last checks to use an item.
  4299. * Return:
  4300. * 0 = fail
  4301. * 1 = success
  4302. *------------------------------------------*/
  4303. int pc_useitem(struct map_session_data *sd,int n)
  4304. {
  4305. unsigned int tick = gettick();
  4306. int amount;
  4307. unsigned short nameid;
  4308. struct script_code *script;
  4309. struct item item;
  4310. struct item_data *id;
  4311. nullpo_ret(sd);
  4312. if (sd->npc_id) {
  4313. #ifdef RENEWAL
  4314. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  4315. return 0;
  4316. #else
  4317. if( !sd->npc_item_flag )
  4318. return 0;
  4319. #endif
  4320. }
  4321. item = sd->status.inventory[n];
  4322. id = sd->inventory_data[n];
  4323. if (item.nameid == 0 || item.amount <= 0)
  4324. return 0;
  4325. if( !pc_isUseitem(sd,n) )
  4326. return 0;
  4327. // Store information for later use before it is lost (via pc_delitem) [Paradox924X]
  4328. nameid = id->nameid;
  4329. if (nameid != ITEMID_NAUTHIZ && sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  4330. return 0;
  4331. /* Items with delayed consume are not meant to work while in mounts except reins of mount(12622) */
  4332. if( id->flag.delay_consume ) {
  4333. if( nameid != ITEMID_REINS_OF_MOUNT && &sd->sc && sd->sc.data[SC_ALL_RIDING] )
  4334. return 0;
  4335. else if( pc_issit(sd) )
  4336. return 0;
  4337. }
  4338. //Since most delay-consume items involve using a "skill-type" target cursor,
  4339. //perform a skill-use check before going through. [Skotlex]
  4340. //resurrection was picked as testing skill, as a non-offensive, generic skill, it will do.
  4341. //FIXME: Is this really needed here? It'll be checked in unit.c after all and this prevents skill items using when silenced [Inkfish]
  4342. if( id->flag.delay_consume && ( sd->ud.skilltimer != INVALID_TIMER /*|| !status_check_skilluse(&sd->bl, &sd->bl, ALL_RESURRECTION, 0)*/ ) )
  4343. return 0;
  4344. if( id->delay > 0 && !pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL) && pc_itemcd_check(sd, id, tick, n))
  4345. return 0;
  4346. /* on restricted maps the item is consumed but the effect is not used */
  4347. if (!pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL) && itemdb_isNoEquip(id,sd->bl.m)) {
  4348. clif_msg(sd,ITEM_CANT_USE_AREA); // This item cannot be used within this area
  4349. if( battle_config.allow_consume_restricted_item && !id->flag.delay_consume ) { //need confirmation for delayed consumption items
  4350. clif_useitemack(sd,n,item.amount-1,true);
  4351. pc_delitem(sd,n,1,1,0,LOG_TYPE_CONSUME);
  4352. }
  4353. return 0;/* regardless, effect is not run */
  4354. }
  4355. sd->itemid = item.nameid;
  4356. sd->itemindex = n;
  4357. if(sd->catch_target_class != -1) //Abort pet catching.
  4358. sd->catch_target_class = -1;
  4359. amount = item.amount;
  4360. script = id->script;
  4361. //Check if the item is to be consumed immediately [Skotlex]
  4362. if (id->flag.delay_consume)
  4363. clif_useitemack(sd, n, amount, true);
  4364. else
  4365. {
  4366. if( item.expire_time == 0 && nameid != ITEMID_REINS_OF_MOUNT )
  4367. {
  4368. clif_useitemack(sd, n, amount - 1, true);
  4369. pc_delitem(sd, n, 1, 1, 0, LOG_TYPE_CONSUME); // Rental Usable Items are not deleted until expiration
  4370. }
  4371. else
  4372. clif_useitemack(sd, n, 0, false);
  4373. }
  4374. if(item.card[0]==CARD0_CREATE &&
  4375. pc_famerank(MakeDWord(item.card[2],item.card[3]), MAPID_ALCHEMIST))
  4376. {
  4377. potion_flag = 2; // Famous player's potions have 50% more efficiency
  4378. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_ROGUE)
  4379. potion_flag = 3; //Even more effective potions.
  4380. }
  4381. //Update item use time.
  4382. sd->canuseitem_tick = tick + battle_config.item_use_interval;
  4383. if( itemdb_iscashfood(nameid) )
  4384. sd->canusecashfood_tick = tick + battle_config.cashfood_use_interval;
  4385. run_script(script,0,sd->bl.id,fake_nd->bl.id);
  4386. potion_flag = 0;
  4387. return 1;
  4388. }
  4389. /**
  4390. * Add item on cart for given index.
  4391. * @param sd
  4392. * @param item
  4393. * @param amount
  4394. * @param log_type
  4395. * @return 0 = success; 1 = fail; 2 = no slot
  4396. */
  4397. unsigned char pc_cart_additem(struct map_session_data *sd,struct item *item,int amount,e_log_pick_type log_type)
  4398. {
  4399. struct item_data *data;
  4400. int i,w;
  4401. nullpo_retr(1, sd);
  4402. nullpo_retr(1, item);
  4403. if(item->nameid == 0 || amount <= 0)
  4404. return 1;
  4405. data = itemdb_search(item->nameid);
  4406. if( data->stack.cart && amount > data->stack.amount )
  4407. {// item stack limitation
  4408. return 1;
  4409. }
  4410. if( !itemdb_cancartstore(item, pc_get_group_level(sd)) || (item->bound > BOUND_ACCOUNT && !pc_can_give_bounded_items(sd)))
  4411. { // Check item trade restrictions [Skotlex]
  4412. clif_displaymessage (sd->fd, msg_txt(sd,264));
  4413. return 1;
  4414. }
  4415. if( (w = data->weight*amount) + sd->cart_weight > sd->cart_weight_max )
  4416. return 1;
  4417. // ID no longer points to inventory/kafra ID. While we get a new one we don't want to mess up vending creation.
  4418. item->id = 0;
  4419. i = MAX_CART;
  4420. if( itemdb_isstackable2(data) && !item->expire_time )
  4421. {
  4422. for (i = 0; i < MAX_CART; i++) {
  4423. if (sd->status.cart[i].nameid == item->nameid
  4424. && sd->status.cart[i].bound == item->bound
  4425. && sd->status.cart[i].unique_id == item->unique_id
  4426. && memcmp(sd->status.cart[i].card, item->card, sizeof(item->card)) == 0
  4427. )
  4428. break;
  4429. }
  4430. }
  4431. if( i < MAX_CART )
  4432. {// item already in cart, stack it
  4433. if( amount > MAX_AMOUNT - sd->status.cart[i].amount || ( data->stack.cart && amount > data->stack.amount - sd->status.cart[i].amount ) )
  4434. return 2; // no slot
  4435. sd->status.cart[i].amount+=amount;
  4436. clif_cart_additem(sd,i,amount,0);
  4437. }
  4438. else
  4439. {// item not stackable or not present, add it
  4440. ARR_FIND( 0, MAX_CART, i, sd->status.cart[i].nameid == 0 );
  4441. if( i == MAX_CART )
  4442. return 2; // no slot
  4443. memcpy(&sd->status.cart[i],item,sizeof(sd->status.cart[0]));
  4444. sd->status.cart[i].amount=amount;
  4445. sd->cart_num++;
  4446. clif_cart_additem(sd,i,amount,0);
  4447. }
  4448. sd->status.cart[i].favorite = 0;/* clear */
  4449. log_pick_pc(sd, log_type, amount, &sd->status.cart[i]);
  4450. sd->cart_weight += w;
  4451. clif_updatestatus(sd,SP_CARTINFO);
  4452. return 0;
  4453. }
  4454. /*==========================================
  4455. * Delete item on cart for given index.
  4456. *------------------------------------------*/
  4457. void pc_cart_delitem(struct map_session_data *sd,int n,int amount,int type,e_log_pick_type log_type)
  4458. {
  4459. nullpo_retv(sd);
  4460. if(sd->status.cart[n].nameid == 0 ||
  4461. sd->status.cart[n].amount<amount)
  4462. return;
  4463. log_pick_pc(sd, log_type, -amount, &sd->status.cart[n]);
  4464. sd->status.cart[n].amount -= amount;
  4465. sd->cart_weight -= itemdb_weight(sd->status.cart[n].nameid)*amount ;
  4466. if(sd->status.cart[n].amount <= 0){
  4467. memset(&sd->status.cart[n],0,sizeof(sd->status.cart[0]));
  4468. sd->cart_num--;
  4469. }
  4470. if(!type) {
  4471. clif_cart_delitem(sd,n,amount);
  4472. clif_updatestatus(sd,SP_CARTINFO);
  4473. }
  4474. }
  4475. /*==========================================
  4476. * Transfer item from inventory to cart.
  4477. *------------------------------------------*/
  4478. void pc_putitemtocart(struct map_session_data *sd,int idx,int amount)
  4479. {
  4480. struct item *item_data;
  4481. char flag;
  4482. nullpo_retv(sd);
  4483. if (idx < 0 || idx >= MAX_INVENTORY) //Invalid index check [Skotlex]
  4484. return;
  4485. item_data = &sd->status.inventory[idx];
  4486. if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
  4487. return;
  4488. if( (flag = pc_cart_additem(sd,item_data,amount,LOG_TYPE_NONE)) == 0 )
  4489. pc_delitem(sd,idx,amount,0,5,LOG_TYPE_NONE);
  4490. else {
  4491. clif_dropitem(sd,idx,0);
  4492. clif_cart_additem_ack(sd,(flag==1)?ADDITEM_TO_CART_FAIL_WEIGHT:ADDITEM_TO_CART_FAIL_COUNT);
  4493. }
  4494. }
  4495. /*==========================================
  4496. * Get number of item in cart.
  4497. * Return:
  4498. -1 = itemid not found or no amount found
  4499. x = remaining itemid on cart after get
  4500. *------------------------------------------*/
  4501. int pc_cartitem_amount(struct map_session_data* sd, int idx, int amount)
  4502. {
  4503. struct item* item_data;
  4504. nullpo_retr(-1, sd);
  4505. item_data = &sd->status.cart[idx];
  4506. if( item_data->nameid == 0 || item_data->amount == 0 )
  4507. return -1;
  4508. return item_data->amount - amount;
  4509. }
  4510. /*==========================================
  4511. * Retrieve an item at index idx from cart.
  4512. *------------------------------------------*/
  4513. void pc_getitemfromcart(struct map_session_data *sd,int idx,int amount)
  4514. {
  4515. struct item *item_data;
  4516. unsigned char flag = 0;
  4517. nullpo_retv(sd);
  4518. if (idx < 0 || idx >= MAX_CART) //Invalid index check [Skotlex]
  4519. return;
  4520. item_data=&sd->status.cart[idx];
  4521. if(item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
  4522. return;
  4523. if((flag = pc_additem(sd,item_data,amount,LOG_TYPE_NONE)) == 0)
  4524. pc_cart_delitem(sd,idx,amount,0,LOG_TYPE_NONE);
  4525. else {
  4526. clif_dropitem(sd,idx,0);
  4527. clif_additem(sd,0,0,flag);
  4528. }
  4529. }
  4530. /*==========================================
  4531. * Bound Item Check
  4532. * Type:
  4533. * 1 Account Bound
  4534. * 2 Guild Bound
  4535. * 3 Party Bound
  4536. * 4 Character Bound
  4537. *------------------------------------------*/
  4538. int pc_bound_chk(TBL_PC *sd,enum bound_type type,int *idxlist)
  4539. {
  4540. int i=0, j=0;
  4541. for(i=0;i<MAX_INVENTORY;i++){
  4542. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0 && sd->status.inventory[i].bound == type) {
  4543. idxlist[j] = i;
  4544. j++;
  4545. }
  4546. }
  4547. return j;
  4548. }
  4549. /*==========================================
  4550. * Display item stolen msg to player sd
  4551. *------------------------------------------*/
  4552. int pc_show_steal(struct block_list *bl,va_list ap)
  4553. {
  4554. struct map_session_data *sd;
  4555. int itemid;
  4556. struct item_data *item=NULL;
  4557. char output[100];
  4558. sd=va_arg(ap,struct map_session_data *);
  4559. itemid=va_arg(ap,int);
  4560. if((item=itemdb_exists(itemid))==NULL)
  4561. sprintf(output,"%s stole an Unknown Item (id: %i).",sd->status.name, itemid);
  4562. else
  4563. sprintf(output,"%s stole %s.",sd->status.name,item->jname);
  4564. clif_displaymessage( ((struct map_session_data *)bl)->fd, output);
  4565. return 0;
  4566. }
  4567. /*==========================================
  4568. * Steal an item from bl (mob).
  4569. * Return:
  4570. * 0 = fail
  4571. * 1 = succes
  4572. *------------------------------------------*/
  4573. int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv)
  4574. {
  4575. int i,itemid;
  4576. double rate;
  4577. unsigned char flag = 0;
  4578. struct status_data *sd_status, *md_status;
  4579. struct mob_data *md;
  4580. struct item tmp_item;
  4581. if(!sd || !bl || bl->type!=BL_MOB)
  4582. return 0;
  4583. md = (TBL_MOB *)bl;
  4584. if(md->state.steal_flag == UCHAR_MAX || ( md->sc.opt1 && md->sc.opt1 != OPT1_BURNING && md->sc.opt1 != OPT1_CRYSTALIZE ) ) //already stolen from / status change check
  4585. return 0;
  4586. sd_status= status_get_status_data(&sd->bl);
  4587. md_status= status_get_status_data(bl);
  4588. if( md->master_id || md_status->mode&MD_BOSS || mob_is_treasure(md) ||
  4589. map[bl->m].flag.nomobloot || // check noloot map flag [Lorky]
  4590. (battle_config.skill_steal_max_tries && //Reached limit of steal attempts. [Lupus]
  4591. md->state.steal_flag++ >= battle_config.skill_steal_max_tries)
  4592. ) { //Can't steal from
  4593. md->state.steal_flag = UCHAR_MAX;
  4594. return 0;
  4595. }
  4596. // base skill success chance (percentual)
  4597. rate = (sd_status->dex - md_status->dex)/2 + skill_lv*6 + 4;
  4598. rate += sd->bonus.add_steal_rate;
  4599. if( rate < 1 )
  4600. return 0;
  4601. // Try dropping one item, in the order from first to last possible slot.
  4602. // Droprate is affected by the skill success rate.
  4603. for( i = 0; i < MAX_STEAL_DROP; i++ )
  4604. if( md->db->dropitem[i].nameid > 0 && itemdb_exists(md->db->dropitem[i].nameid) && rnd() % 10000 < md->db->dropitem[i].p * rate/100. )
  4605. break;
  4606. if( i == MAX_STEAL_DROP )
  4607. return 0;
  4608. itemid = md->db->dropitem[i].nameid;
  4609. memset(&tmp_item,0,sizeof(tmp_item));
  4610. tmp_item.nameid = itemid;
  4611. tmp_item.amount = 1;
  4612. tmp_item.identify = itemdb_isidentified(itemid);
  4613. flag = pc_additem(sd,&tmp_item,1,LOG_TYPE_PICKDROP_PLAYER);
  4614. //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?
  4615. md->state.steal_flag = UCHAR_MAX; //you can't steal from this mob any more
  4616. if(flag) { //Failed to steal due to overweight
  4617. clif_additem(sd,0,0,flag);
  4618. return 0;
  4619. }
  4620. if(battle_config.show_steal_in_same_party)
  4621. party_foreachsamemap(pc_show_steal,sd,AREA_SIZE,sd,tmp_item.nameid);
  4622. //Logs items, Stolen from mobs [Lupus]
  4623. log_pick_mob(md, LOG_TYPE_STEAL, -1, &tmp_item);
  4624. //A Rare Steal Global Announce by Lupus
  4625. if(md->db->dropitem[i].p<=battle_config.rare_drop_announce) {
  4626. struct item_data *i_data;
  4627. char message[128];
  4628. i_data = itemdb_search(itemid);
  4629. sprintf (message, msg_txt(sd,542), (sd->status.name != NULL)?sd->status.name :"GM", md->db->jname, i_data->jname, (float)md->db->dropitem[i].p/100);
  4630. //MSG: "'%s' stole %s's %s (chance: %0.02f%%)"
  4631. intif_broadcast(message, strlen(message) + 1, BC_DEFAULT);
  4632. }
  4633. return 1;
  4634. }
  4635. /*==========================================
  4636. * Stole zeny from bl (mob)
  4637. * return
  4638. * 0 = fail
  4639. * 1 = success
  4640. *------------------------------------------*/
  4641. int pc_steal_coin(struct map_session_data *sd,struct block_list *target)
  4642. {
  4643. int rate,skill;
  4644. struct mob_data *md;
  4645. if(!sd || !target || target->type != BL_MOB)
  4646. return 0;
  4647. md = (TBL_MOB*)target;
  4648. if( md->state.steal_coin_flag || md->sc.data[SC_STONE] || md->sc.data[SC_FREEZE] || md->status.mode&MD_BOSS )
  4649. return 0;
  4650. if( mob_is_treasure(md) )
  4651. return 0;
  4652. // FIXME: This formula is either custom or outdated.
  4653. skill = pc_checkskill(sd,RG_STEALCOIN)*10;
  4654. rate = skill + (sd->status.base_level - md->level)*3 + sd->battle_status.dex*2 + sd->battle_status.luk*2;
  4655. if(rnd()%1000 < rate)
  4656. {
  4657. int amount = md->level*10 + rnd()%100;
  4658. pc_getzeny(sd, amount, LOG_TYPE_STEAL, NULL);
  4659. md->state.steal_coin_flag = 1;
  4660. return 1;
  4661. }
  4662. return 0;
  4663. }
  4664. /*==========================================
  4665. * Set's a player position.
  4666. * @param sd
  4667. * @param mapindex
  4668. * @param x
  4669. * @param y
  4670. * @param clrtype
  4671. * @return 0 - Success; 1 - Invalid map index; 2 - Map not in this map-server, and failed to locate alternate map-server.
  4672. *------------------------------------------*/
  4673. char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype)
  4674. {
  4675. int16 m;
  4676. nullpo_ret(sd);
  4677. if( !mapindex || !mapindex_id2name(mapindex) ) {
  4678. ShowDebug("pc_setpos: Passed mapindex(%d) is invalid!\n", mapindex);
  4679. return 1;
  4680. }
  4681. if ( sd->state.autotrade && (sd->vender_id || sd->buyer_id) ) // Player with autotrade just causes clif glitch! @ FIXME
  4682. return 1;
  4683. if( battle_config.revive_onwarp && pc_isdead(sd) ) { //Revive dead people before warping them
  4684. pc_setstand(sd, true);
  4685. pc_setrestartvalue(sd,1);
  4686. }
  4687. m = map_mapindex2mapid(mapindex);
  4688. sd->state.changemap = (sd->mapindex != mapindex);
  4689. sd->state.warping = 1;
  4690. if(sd->status.party_id && map[sd->bl.m].instance_id && sd->state.changemap && !map[m].instance_id) {
  4691. struct party_data *p;
  4692. if((p = party_search(sd->status.party_id)) != NULL && p->instance_id )
  4693. instance_delusers(p->instance_id);
  4694. }
  4695. if( sd->state.changemap ) { // Misc map-changing settings
  4696. int i;
  4697. sd->state.pmap = sd->bl.m;
  4698. if (sd->sc.count) { // Cancel some map related stuff.
  4699. if (sd->sc.data[SC_JAILED])
  4700. return 1; //You may not get out!
  4701. status_change_end(&sd->bl, SC_BOSSMAPINFO, INVALID_TIMER);
  4702. status_change_end(&sd->bl, SC_WARM, INVALID_TIMER);
  4703. status_change_end(&sd->bl, SC_SUN_COMFORT, INVALID_TIMER);
  4704. status_change_end(&sd->bl, SC_MOON_COMFORT, INVALID_TIMER);
  4705. status_change_end(&sd->bl, SC_STAR_COMFORT, INVALID_TIMER);
  4706. status_change_end(&sd->bl, SC_MIRACLE, INVALID_TIMER);
  4707. if (sd->sc.data[SC_KNOWLEDGE]) {
  4708. struct status_change_entry *sce = sd->sc.data[SC_KNOWLEDGE];
  4709. if (sce->timer != INVALID_TIMER)
  4710. delete_timer(sce->timer, status_change_timer);
  4711. sce->timer = add_timer(gettick() + skill_get_time(SG_KNOWLEDGE, sce->val1), status_change_timer, sd->bl.id, SC_KNOWLEDGE);
  4712. }
  4713. status_change_end(&sd->bl, SC_PROPERTYWALK, INVALID_TIMER);
  4714. status_change_end(&sd->bl, SC_CLOAKING, INVALID_TIMER);
  4715. status_change_end(&sd->bl, SC_CLOAKINGEXCEED, INVALID_TIMER);
  4716. }
  4717. for( i = 0; i < EQI_MAX; i++ ) {
  4718. if( sd->equip_index[i] >= 0 )
  4719. if( pc_isequip(sd,sd->equip_index[i]) )
  4720. pc_unequipitem(sd,sd->equip_index[i],2);
  4721. }
  4722. if (battle_config.clear_unit_onwarp&BL_PC)
  4723. skill_clear_unitgroup(&sd->bl);
  4724. party_send_dot_remove(sd); //minimap dot fix [Kevin]
  4725. guild_send_dot_remove(sd);
  4726. bg_send_dot_remove(sd);
  4727. if (sd->regen.state.gc)
  4728. sd->regen.state.gc = 0;
  4729. // make sure vending is allowed here
  4730. if (sd->state.vending && map[m].flag.novending) {
  4731. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  4732. vending_closevending(sd);
  4733. }
  4734. channel_pcquit(sd,4); //quit map chan
  4735. }
  4736. if( m < 0 )
  4737. {
  4738. uint32 ip;
  4739. uint16 port;
  4740. //if can't find any map-servers, just abort setting position.
  4741. if(!sd->mapindex || map_mapname2ipport(mapindex,&ip,&port))
  4742. return 2;
  4743. if (sd->npc_id)
  4744. npc_event_dequeue(sd);
  4745. npc_script_event(sd, NPCE_LOGOUT);
  4746. //remove from map, THEN change x/y coordinates
  4747. unit_remove_map_pc(sd,clrtype);
  4748. sd->mapindex = mapindex;
  4749. sd->bl.x=x;
  4750. sd->bl.y=y;
  4751. pc_clean_skilltree(sd);
  4752. chrif_save(sd,2);
  4753. chrif_changemapserver(sd, ip, (short)port);
  4754. //Free session data from this map server [Kevin]
  4755. unit_free_pc(sd);
  4756. return 0;
  4757. }
  4758. if( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys )
  4759. {
  4760. 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);
  4761. x = y = 0; // make it random
  4762. }
  4763. if( x == 0 && y == 0 ) { // pick a random walkable cell
  4764. int c=0;
  4765. do {
  4766. x = rnd()%(map[m].xs-2)+1;
  4767. y = rnd()%(map[m].ys-2)+1;
  4768. c++;
  4769. if(c > (map[m].xs * map[m].ys)*3){ //force out
  4770. ShowError("pc_setpos: couldn't found a valid coordinates for player '%s' (%d:%d) on (%s), preventing warp\n", sd->status.name, sd->status.account_id, sd->status.char_id, mapindex_id2name(mapindex));
  4771. return 0; //preventing warp
  4772. //break; //allow warp anyway
  4773. }
  4774. } while(map_getcell(m,x,y,CELL_CHKNOPASS) || (!battle_config.teleport_on_portal && npc_check_areanpc(1,m,x,y,1)));
  4775. }
  4776. if (sd->state.vending && map_getcell(m,x,y,CELL_CHKNOVENDING)) {
  4777. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  4778. vending_closevending(sd);
  4779. }
  4780. if(sd->bl.prev != NULL){
  4781. unit_remove_map_pc(sd,clrtype);
  4782. clif_changemap(sd,m,x,y); // [MouseJstr]
  4783. } else if(sd->state.active) //Tag player for rewarping after map-loading is done. [Skotlex]
  4784. sd->state.rewarp = 1;
  4785. sd->mapindex = mapindex;
  4786. sd->bl.m = m;
  4787. sd->bl.x = sd->ud.to_x = x;
  4788. sd->bl.y = sd->ud.to_y = y;
  4789. if( sd->status.guild_id > 0 && map[m].flag.gvg_castle )
  4790. { // Increased guild castle regen [Valaris]
  4791. struct guild_castle *gc = guild_mapindex2gc(sd->mapindex);
  4792. if(gc && gc->guild_id == sd->status.guild_id)
  4793. sd->regen.state.gc = 1;
  4794. }
  4795. if( sd->status.pet_id > 0 && sd->pd && sd->pd->pet.intimate > 0 )
  4796. {
  4797. sd->pd->bl.m = m;
  4798. sd->pd->bl.x = sd->pd->ud.to_x = x;
  4799. sd->pd->bl.y = sd->pd->ud.to_y = y;
  4800. sd->pd->ud.dir = sd->ud.dir;
  4801. }
  4802. if( hom_is_active(sd->hd) )
  4803. {
  4804. sd->hd->bl.m = m;
  4805. sd->hd->bl.x = sd->hd->ud.to_x = x;
  4806. sd->hd->bl.y = sd->hd->ud.to_y = y;
  4807. sd->hd->ud.dir = sd->ud.dir;
  4808. }
  4809. if( sd->md )
  4810. {
  4811. sd->md->bl.m = m;
  4812. sd->md->bl.x = sd->md->ud.to_x = x;
  4813. sd->md->bl.y = sd->md->ud.to_y = y;
  4814. sd->md->ud.dir = sd->ud.dir;
  4815. }
  4816. if( sd->ed ) {
  4817. sd->ed->bl.m = m;
  4818. sd->ed->bl.x = sd->ed->ud.to_x = x;
  4819. sd->ed->bl.y = sd->ed->ud.to_y = y;
  4820. sd->ed->ud.dir = sd->ud.dir;
  4821. }
  4822. pc_cell_basilica(sd);
  4823. //check if we gonna be rewarped [lighta]
  4824. if(npc_check_areanpc(1,m,x,y,0)){
  4825. sd->count_rewarp++;
  4826. }
  4827. else
  4828. sd->count_rewarp = 0;
  4829. return 0;
  4830. }
  4831. /*==========================================
  4832. * Warp player sd to random location on current map.
  4833. * May fail if no walkable cell found (1000 attempts).
  4834. * Return:
  4835. * 0 = Success
  4836. * 1,2,3 = Fail
  4837. *------------------------------------------*/
  4838. char pc_randomwarp(struct map_session_data *sd, clr_type type)
  4839. {
  4840. int x,y,i=0;
  4841. int16 m;
  4842. nullpo_ret(sd);
  4843. m=sd->bl.m;
  4844. if (map[sd->bl.m].flag.noteleport) //Teleport forbidden
  4845. return 3;
  4846. do {
  4847. x = rnd()%(map[m].xs-2)+1;
  4848. y = rnd()%(map[m].ys-2)+1;
  4849. } while((map_getcell(m,x,y,CELL_CHKNOPASS) || (!battle_config.teleport_on_portal && npc_check_areanpc(1,m,x,y,1))) && (i++) < 1000);
  4850. if (i < 1000)
  4851. return pc_setpos(sd,map[sd->bl.m].index,x,y,type);
  4852. return 3;
  4853. }
  4854. /*==========================================
  4855. * Records a memo point at sd's current position
  4856. * pos - entry to replace, (-1: shift oldest entry out)
  4857. *------------------------------------------*/
  4858. bool pc_memo(struct map_session_data* sd, int pos)
  4859. {
  4860. int skill;
  4861. nullpo_ret(sd);
  4862. // check mapflags
  4863. if( sd->bl.m >= 0 && (map[sd->bl.m].flag.nomemo || map[sd->bl.m].flag.nowarpto) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE) ) {
  4864. clif_skill_teleportmessage(sd, 1); // "Saved point cannot be memorized."
  4865. return false;
  4866. }
  4867. // check inputs
  4868. if( pos < -1 || pos >= MAX_MEMOPOINTS )
  4869. return false; // invalid input
  4870. // check required skill level
  4871. skill = pc_checkskill(sd, AL_WARP);
  4872. if( skill < 1 ) {
  4873. clif_skill_memomessage(sd,2); // "You haven't learned Warp."
  4874. return false;
  4875. }
  4876. if( skill < 2 || skill - 2 < pos ) {
  4877. clif_skill_memomessage(sd,1); // "Skill Level is not high enough."
  4878. return false;
  4879. }
  4880. if( pos == -1 )
  4881. {
  4882. uint8 i;
  4883. // prevent memo-ing the same map multiple times
  4884. ARR_FIND( 0, MAX_MEMOPOINTS, i, sd->status.memo_point[i].map == map_id2index(sd->bl.m) );
  4885. memmove(&sd->status.memo_point[1], &sd->status.memo_point[0], (u8min(i,MAX_MEMOPOINTS-1))*sizeof(struct point));
  4886. pos = 0;
  4887. }
  4888. if( map[sd->bl.m].instance_id ) {
  4889. clif_displaymessage( sd->fd, msg_txt(sd,384) ); // You cannot create a memo in an instance.
  4890. return false;
  4891. }
  4892. sd->status.memo_point[pos].map = map_id2index(sd->bl.m);
  4893. sd->status.memo_point[pos].x = sd->bl.x;
  4894. sd->status.memo_point[pos].y = sd->bl.y;
  4895. clif_skill_memomessage(sd, 0);
  4896. return true;
  4897. }
  4898. //
  4899. // Skills
  4900. //
  4901. /**
  4902. * Get the skill current cooldown for player.
  4903. * (get the db base cooldown for skill + player specific cooldown)
  4904. * @param sd : player pointer
  4905. * @param id : skill id
  4906. * @param lv : skill lv
  4907. * @return player skill cooldown
  4908. */
  4909. int pc_get_skillcooldown(struct map_session_data *sd, uint16 skill_id, uint16 skill_lv) {
  4910. uint8 i;
  4911. uint16 idx = skill_get_index(skill_id);
  4912. int cooldown = 0, cooldownlen = ARRAYLENGTH(sd->skillcooldown);
  4913. if (!idx) return 0;
  4914. if (skill_db[idx]->cooldown[skill_lv - 1])
  4915. cooldown = skill_db[idx]->cooldown[skill_lv - 1];
  4916. ARR_FIND(0, cooldownlen, i, sd->skillcooldown[i].id == skill_id);
  4917. if (i < cooldownlen) {
  4918. cooldown += sd->skillcooldown[i].val;
  4919. cooldown = max(0,cooldown);
  4920. }
  4921. return cooldown;
  4922. }
  4923. /*==========================================
  4924. * Return player sd skill_lv learned for given skill
  4925. *------------------------------------------*/
  4926. uint8 pc_checkskill(struct map_session_data *sd, uint16 skill_id)
  4927. {
  4928. uint16 idx = 0;
  4929. if (sd == NULL)
  4930. return 0;
  4931. if ((idx = skill_get_index(skill_id)) == 0) {
  4932. ShowError("pc_checkskill: Invalid skill id %d (char_id=%d).\n", skill_id, sd->status.char_id);
  4933. return 0;
  4934. }
  4935. if (SKILL_CHK_GUILD(skill_id) ) {
  4936. struct guild *g;
  4937. if( sd->status.guild_id>0 && (g=sd->guild)!=NULL)
  4938. return guild_checkskill(g,skill_id);
  4939. return 0;
  4940. }
  4941. return (sd->status.skill[idx].id == skill_id) ? sd->status.skill[idx].lv : 0;
  4942. }
  4943. /**
  4944. * Check if we still have the correct weapon to continue the skill (actually status)
  4945. * If not ending it
  4946. * @param sd
  4947. * @return 0:error, 1:check done
  4948. */
  4949. static void pc_checkallowskill(struct map_session_data *sd)
  4950. {
  4951. const enum sc_type scw_list[] = {
  4952. SC_TWOHANDQUICKEN,
  4953. SC_ONEHAND,
  4954. SC_AURABLADE,
  4955. SC_PARRYING,
  4956. SC_SPEARQUICKEN,
  4957. SC_ADRENALINE,
  4958. SC_ADRENALINE2,
  4959. SC_DANCING,
  4960. SC_GATLINGFEVER,
  4961. };
  4962. uint8 i;
  4963. nullpo_retv(sd);
  4964. if(!sd->sc.count)
  4965. return;
  4966. for (i = 0; i < ARRAYLENGTH(scw_list); i++)
  4967. { // Skills requiring specific weapon types
  4968. if( scw_list[i] == SC_DANCING && !battle_config.dancing_weaponswitch_fix )
  4969. continue;
  4970. if(sd->sc.data[scw_list[i]] &&
  4971. !pc_check_weapontype(sd,skill_get_weapontype(status_sc2skill(scw_list[i]))))
  4972. status_change_end(&sd->bl, scw_list[i], INVALID_TIMER);
  4973. }
  4974. if(sd->sc.data[SC_SPURT] && sd->status.weapon)
  4975. // Spurt requires bare hands (feet, in fact xD)
  4976. status_change_end(&sd->bl, SC_SPURT, INVALID_TIMER);
  4977. if(sd->status.shield <= 0) { // Skills requiring a shield
  4978. const enum sc_type scs_list[] = {
  4979. SC_AUTOGUARD,
  4980. SC_DEFENDER,
  4981. SC_REFLECTSHIELD,
  4982. SC_REFLECTDAMAGE
  4983. };
  4984. for (i = 0; i < ARRAYLENGTH(scs_list); i++)
  4985. if(sd->sc.data[scs_list[i]])
  4986. status_change_end(&sd->bl, scs_list[i], INVALID_TIMER);
  4987. }
  4988. }
  4989. /*==========================================
  4990. * Return equipped index of item on player sd at pos
  4991. * Return
  4992. * -1 : Nothing equipped
  4993. * idx : (this index could be used in inventory to found item_data)
  4994. *------------------------------------------*/
  4995. short pc_checkequip(struct map_session_data *sd,int pos)
  4996. {
  4997. uint8 i;
  4998. nullpo_retr(-1, sd);
  4999. for(i=0;i<EQI_MAX;i++){
  5000. if(pos & equip_pos[i])
  5001. return sd->equip_index[i];
  5002. }
  5003. return -1;
  5004. }
  5005. /*==========================================
  5006. * Check if sd has nameid equipped somewhere
  5007. * @sd : the player session
  5008. * @nameid : id of the item to check
  5009. * @min : : see pc.h enum equip_index from ? to @max
  5010. * @max : see pc.h enum equip_index for @min to ?
  5011. * -return true,false
  5012. *------------------------------------------*/
  5013. bool pc_checkequip2(struct map_session_data *sd, unsigned short nameid, int min, int max)
  5014. {
  5015. int i;
  5016. for(i = min; i < max; i++) {
  5017. if(equip_pos[i]) {
  5018. int idx = sd->equip_index[i];
  5019. if (sd->status.inventory[idx].nameid == nameid)
  5020. return true;
  5021. }
  5022. }
  5023. return false;
  5024. }
  5025. /*==========================================
  5026. * Convert's from the client's lame Job ID system
  5027. * to the map server's 'makes sense' system. [Skotlex]
  5028. *------------------------------------------*/
  5029. int pc_jobid2mapid(unsigned short b_class)
  5030. {
  5031. switch(b_class)
  5032. {
  5033. //Novice And 1-1 Jobs
  5034. case JOB_NOVICE: return MAPID_NOVICE;
  5035. case JOB_SWORDMAN: return MAPID_SWORDMAN;
  5036. case JOB_MAGE: return MAPID_MAGE;
  5037. case JOB_ARCHER: return MAPID_ARCHER;
  5038. case JOB_ACOLYTE: return MAPID_ACOLYTE;
  5039. case JOB_MERCHANT: return MAPID_MERCHANT;
  5040. case JOB_THIEF: return MAPID_THIEF;
  5041. case JOB_TAEKWON: return MAPID_TAEKWON;
  5042. case JOB_WEDDING: return MAPID_WEDDING;
  5043. case JOB_GUNSLINGER: return MAPID_GUNSLINGER;
  5044. case JOB_NINJA: return MAPID_NINJA;
  5045. case JOB_XMAS: return MAPID_XMAS;
  5046. case JOB_SUMMER: return MAPID_SUMMER;
  5047. case JOB_HANBOK: return MAPID_HANBOK;
  5048. case JOB_GANGSI: return MAPID_GANGSI;
  5049. case JOB_OKTOBERFEST: return MAPID_OKTOBERFEST;
  5050. //2-1 Jobs
  5051. case JOB_SUPER_NOVICE: return MAPID_SUPER_NOVICE;
  5052. case JOB_KNIGHT: return MAPID_KNIGHT;
  5053. case JOB_WIZARD: return MAPID_WIZARD;
  5054. case JOB_HUNTER: return MAPID_HUNTER;
  5055. case JOB_PRIEST: return MAPID_PRIEST;
  5056. case JOB_BLACKSMITH: return MAPID_BLACKSMITH;
  5057. case JOB_ASSASSIN: return MAPID_ASSASSIN;
  5058. case JOB_STAR_GLADIATOR: return MAPID_STAR_GLADIATOR;
  5059. case JOB_KAGEROU:
  5060. case JOB_OBORO: return MAPID_KAGEROUOBORO;
  5061. case JOB_REBELLION: return MAPID_REBELLION;
  5062. case JOB_DEATH_KNIGHT: return MAPID_DEATH_KNIGHT;
  5063. //2-2 Jobs
  5064. case JOB_CRUSADER: return MAPID_CRUSADER;
  5065. case JOB_SAGE: return MAPID_SAGE;
  5066. case JOB_BARD:
  5067. case JOB_DANCER: return MAPID_BARDDANCER;
  5068. case JOB_MONK: return MAPID_MONK;
  5069. case JOB_ALCHEMIST: return MAPID_ALCHEMIST;
  5070. case JOB_ROGUE: return MAPID_ROGUE;
  5071. case JOB_SOUL_LINKER: return MAPID_SOUL_LINKER;
  5072. case JOB_DARK_COLLECTOR: return MAPID_DARK_COLLECTOR;
  5073. //Trans Novice And Trans 1-1 Jobs
  5074. case JOB_NOVICE_HIGH: return MAPID_NOVICE_HIGH;
  5075. case JOB_SWORDMAN_HIGH: return MAPID_SWORDMAN_HIGH;
  5076. case JOB_MAGE_HIGH: return MAPID_MAGE_HIGH;
  5077. case JOB_ARCHER_HIGH: return MAPID_ARCHER_HIGH;
  5078. case JOB_ACOLYTE_HIGH: return MAPID_ACOLYTE_HIGH;
  5079. case JOB_MERCHANT_HIGH: return MAPID_MERCHANT_HIGH;
  5080. case JOB_THIEF_HIGH: return MAPID_THIEF_HIGH;
  5081. //Trans 2-1 Jobs
  5082. case JOB_LORD_KNIGHT: return MAPID_LORD_KNIGHT;
  5083. case JOB_HIGH_WIZARD: return MAPID_HIGH_WIZARD;
  5084. case JOB_SNIPER: return MAPID_SNIPER;
  5085. case JOB_HIGH_PRIEST: return MAPID_HIGH_PRIEST;
  5086. case JOB_WHITESMITH: return MAPID_WHITESMITH;
  5087. case JOB_ASSASSIN_CROSS: return MAPID_ASSASSIN_CROSS;
  5088. //Trans 2-2 Jobs
  5089. case JOB_PALADIN: return MAPID_PALADIN;
  5090. case JOB_PROFESSOR: return MAPID_PROFESSOR;
  5091. case JOB_CLOWN:
  5092. case JOB_GYPSY: return MAPID_CLOWNGYPSY;
  5093. case JOB_CHAMPION: return MAPID_CHAMPION;
  5094. case JOB_CREATOR: return MAPID_CREATOR;
  5095. case JOB_STALKER: return MAPID_STALKER;
  5096. //Baby Novice And Baby 1-1 Jobs
  5097. case JOB_BABY: return MAPID_BABY;
  5098. case JOB_BABY_SWORDMAN: return MAPID_BABY_SWORDMAN;
  5099. case JOB_BABY_MAGE: return MAPID_BABY_MAGE;
  5100. case JOB_BABY_ARCHER: return MAPID_BABY_ARCHER;
  5101. case JOB_BABY_ACOLYTE: return MAPID_BABY_ACOLYTE;
  5102. case JOB_BABY_MERCHANT: return MAPID_BABY_MERCHANT;
  5103. case JOB_BABY_THIEF: return MAPID_BABY_THIEF;
  5104. //Baby 2-1 Jobs
  5105. case JOB_SUPER_BABY: return MAPID_SUPER_BABY;
  5106. case JOB_BABY_KNIGHT: return MAPID_BABY_KNIGHT;
  5107. case JOB_BABY_WIZARD: return MAPID_BABY_WIZARD;
  5108. case JOB_BABY_HUNTER: return MAPID_BABY_HUNTER;
  5109. case JOB_BABY_PRIEST: return MAPID_BABY_PRIEST;
  5110. case JOB_BABY_BLACKSMITH: return MAPID_BABY_BLACKSMITH;
  5111. case JOB_BABY_ASSASSIN: return MAPID_BABY_ASSASSIN;
  5112. //Baby 2-2 Jobs
  5113. case JOB_BABY_CRUSADER: return MAPID_BABY_CRUSADER;
  5114. case JOB_BABY_SAGE: return MAPID_BABY_SAGE;
  5115. case JOB_BABY_BARD:
  5116. case JOB_BABY_DANCER: return MAPID_BABY_BARDDANCER;
  5117. case JOB_BABY_MONK: return MAPID_BABY_MONK;
  5118. case JOB_BABY_ALCHEMIST: return MAPID_BABY_ALCHEMIST;
  5119. case JOB_BABY_ROGUE: return MAPID_BABY_ROGUE;
  5120. //3-1 Jobs
  5121. case JOB_SUPER_NOVICE_E: return MAPID_SUPER_NOVICE_E;
  5122. case JOB_RUNE_KNIGHT: return MAPID_RUNE_KNIGHT;
  5123. case JOB_WARLOCK: return MAPID_WARLOCK;
  5124. case JOB_RANGER: return MAPID_RANGER;
  5125. case JOB_ARCH_BISHOP: return MAPID_ARCH_BISHOP;
  5126. case JOB_MECHANIC: return MAPID_MECHANIC;
  5127. case JOB_GUILLOTINE_CROSS: return MAPID_GUILLOTINE_CROSS;
  5128. //3-2 Jobs
  5129. case JOB_ROYAL_GUARD: return MAPID_ROYAL_GUARD;
  5130. case JOB_SORCERER: return MAPID_SORCERER;
  5131. case JOB_MINSTREL:
  5132. case JOB_WANDERER: return MAPID_MINSTRELWANDERER;
  5133. case JOB_SURA: return MAPID_SURA;
  5134. case JOB_GENETIC: return MAPID_GENETIC;
  5135. case JOB_SHADOW_CHASER: return MAPID_SHADOW_CHASER;
  5136. //Trans 3-1 Jobs
  5137. case JOB_RUNE_KNIGHT_T: return MAPID_RUNE_KNIGHT_T;
  5138. case JOB_WARLOCK_T: return MAPID_WARLOCK_T;
  5139. case JOB_RANGER_T: return MAPID_RANGER_T;
  5140. case JOB_ARCH_BISHOP_T: return MAPID_ARCH_BISHOP_T;
  5141. case JOB_MECHANIC_T: return MAPID_MECHANIC_T;
  5142. case JOB_GUILLOTINE_CROSS_T: return MAPID_GUILLOTINE_CROSS_T;
  5143. //Trans 3-2 Jobs
  5144. case JOB_ROYAL_GUARD_T: return MAPID_ROYAL_GUARD_T;
  5145. case JOB_SORCERER_T: return MAPID_SORCERER_T;
  5146. case JOB_MINSTREL_T:
  5147. case JOB_WANDERER_T: return MAPID_MINSTRELWANDERER_T;
  5148. case JOB_SURA_T: return MAPID_SURA_T;
  5149. case JOB_GENETIC_T: return MAPID_GENETIC_T;
  5150. case JOB_SHADOW_CHASER_T: return MAPID_SHADOW_CHASER_T;
  5151. //Baby 3-1 Jobs
  5152. case JOB_SUPER_BABY_E: return MAPID_SUPER_BABY_E;
  5153. case JOB_BABY_RUNE: return MAPID_BABY_RUNE;
  5154. case JOB_BABY_WARLOCK: return MAPID_BABY_WARLOCK;
  5155. case JOB_BABY_RANGER: return MAPID_BABY_RANGER;
  5156. case JOB_BABY_BISHOP: return MAPID_BABY_BISHOP;
  5157. case JOB_BABY_MECHANIC: return MAPID_BABY_MECHANIC;
  5158. case JOB_BABY_CROSS: return MAPID_BABY_CROSS;
  5159. //Baby 3-2 Jobs
  5160. case JOB_BABY_GUARD: return MAPID_BABY_GUARD;
  5161. case JOB_BABY_SORCERER: return MAPID_BABY_SORCERER;
  5162. case JOB_BABY_MINSTREL:
  5163. case JOB_BABY_WANDERER: return MAPID_BABY_MINSTRELWANDERER;
  5164. case JOB_BABY_SURA: return MAPID_BABY_SURA;
  5165. case JOB_BABY_GENETIC: return MAPID_BABY_GENETIC;
  5166. case JOB_BABY_CHASER: return MAPID_BABY_CHASER;
  5167. default:
  5168. return -1;
  5169. }
  5170. }
  5171. //Reverts the map-style class id to the client-style one.
  5172. int pc_mapid2jobid(unsigned short class_, int sex)
  5173. {
  5174. switch(class_) {
  5175. //Novice And 1-1 Jobs
  5176. case MAPID_NOVICE: return JOB_NOVICE;
  5177. case MAPID_SWORDMAN: return JOB_SWORDMAN;
  5178. case MAPID_MAGE: return JOB_MAGE;
  5179. case MAPID_ARCHER: return JOB_ARCHER;
  5180. case MAPID_ACOLYTE: return JOB_ACOLYTE;
  5181. case MAPID_MERCHANT: return JOB_MERCHANT;
  5182. case MAPID_THIEF: return JOB_THIEF;
  5183. case MAPID_TAEKWON: return JOB_TAEKWON;
  5184. case MAPID_WEDDING: return JOB_WEDDING;
  5185. case MAPID_GUNSLINGER: return JOB_GUNSLINGER;
  5186. case MAPID_NINJA: return JOB_NINJA;
  5187. case MAPID_XMAS: return JOB_XMAS;
  5188. case MAPID_SUMMER: return JOB_SUMMER;
  5189. case MAPID_HANBOK: return JOB_HANBOK;
  5190. case MAPID_GANGSI: return JOB_GANGSI;
  5191. case MAPID_OKTOBERFEST: return JOB_OKTOBERFEST;
  5192. //2-1 Jobs
  5193. case MAPID_SUPER_NOVICE: return JOB_SUPER_NOVICE;
  5194. case MAPID_KNIGHT: return JOB_KNIGHT;
  5195. case MAPID_WIZARD: return JOB_WIZARD;
  5196. case MAPID_HUNTER: return JOB_HUNTER;
  5197. case MAPID_PRIEST: return JOB_PRIEST;
  5198. case MAPID_BLACKSMITH: return JOB_BLACKSMITH;
  5199. case MAPID_ASSASSIN: return JOB_ASSASSIN;
  5200. case MAPID_STAR_GLADIATOR: return JOB_STAR_GLADIATOR;
  5201. case MAPID_KAGEROUOBORO: return sex?JOB_KAGEROU:JOB_OBORO;
  5202. case MAPID_REBELLION: return JOB_REBELLION;
  5203. case MAPID_DEATH_KNIGHT: return JOB_DEATH_KNIGHT;
  5204. //2-2 Jobs
  5205. case MAPID_CRUSADER: return JOB_CRUSADER;
  5206. case MAPID_SAGE: return JOB_SAGE;
  5207. case MAPID_BARDDANCER: return sex?JOB_BARD:JOB_DANCER;
  5208. case MAPID_MONK: return JOB_MONK;
  5209. case MAPID_ALCHEMIST: return JOB_ALCHEMIST;
  5210. case MAPID_ROGUE: return JOB_ROGUE;
  5211. case MAPID_SOUL_LINKER: return JOB_SOUL_LINKER;
  5212. case MAPID_DARK_COLLECTOR: return JOB_DARK_COLLECTOR;
  5213. //Trans Novice And Trans 2-1 Jobs
  5214. case MAPID_NOVICE_HIGH: return JOB_NOVICE_HIGH;
  5215. case MAPID_SWORDMAN_HIGH: return JOB_SWORDMAN_HIGH;
  5216. case MAPID_MAGE_HIGH: return JOB_MAGE_HIGH;
  5217. case MAPID_ARCHER_HIGH: return JOB_ARCHER_HIGH;
  5218. case MAPID_ACOLYTE_HIGH: return JOB_ACOLYTE_HIGH;
  5219. case MAPID_MERCHANT_HIGH: return JOB_MERCHANT_HIGH;
  5220. case MAPID_THIEF_HIGH: return JOB_THIEF_HIGH;
  5221. //Trans 2-1 Jobs
  5222. case MAPID_LORD_KNIGHT: return JOB_LORD_KNIGHT;
  5223. case MAPID_HIGH_WIZARD: return JOB_HIGH_WIZARD;
  5224. case MAPID_SNIPER: return JOB_SNIPER;
  5225. case MAPID_HIGH_PRIEST: return JOB_HIGH_PRIEST;
  5226. case MAPID_WHITESMITH: return JOB_WHITESMITH;
  5227. case MAPID_ASSASSIN_CROSS: return JOB_ASSASSIN_CROSS;
  5228. //Trans 2-2 Jobs
  5229. case MAPID_PALADIN: return JOB_PALADIN;
  5230. case MAPID_PROFESSOR: return JOB_PROFESSOR;
  5231. case MAPID_CLOWNGYPSY: return sex?JOB_CLOWN:JOB_GYPSY;
  5232. case MAPID_CHAMPION: return JOB_CHAMPION;
  5233. case MAPID_CREATOR: return JOB_CREATOR;
  5234. case MAPID_STALKER: return JOB_STALKER;
  5235. //Baby Novice And Baby 1-1 Jobs
  5236. case MAPID_BABY: return JOB_BABY;
  5237. case MAPID_BABY_SWORDMAN: return JOB_BABY_SWORDMAN;
  5238. case MAPID_BABY_MAGE: return JOB_BABY_MAGE;
  5239. case MAPID_BABY_ARCHER: return JOB_BABY_ARCHER;
  5240. case MAPID_BABY_ACOLYTE: return JOB_BABY_ACOLYTE;
  5241. case MAPID_BABY_MERCHANT: return JOB_BABY_MERCHANT;
  5242. case MAPID_BABY_THIEF: return JOB_BABY_THIEF;
  5243. //Baby 2-1 Jobs
  5244. case MAPID_SUPER_BABY: return JOB_SUPER_BABY;
  5245. case MAPID_BABY_KNIGHT: return JOB_BABY_KNIGHT;
  5246. case MAPID_BABY_WIZARD: return JOB_BABY_WIZARD;
  5247. case MAPID_BABY_HUNTER: return JOB_BABY_HUNTER;
  5248. case MAPID_BABY_PRIEST: return JOB_BABY_PRIEST;
  5249. case MAPID_BABY_BLACKSMITH: return JOB_BABY_BLACKSMITH;
  5250. case MAPID_BABY_ASSASSIN: return JOB_BABY_ASSASSIN;
  5251. //Baby 2-2 Jobs
  5252. case MAPID_BABY_CRUSADER: return JOB_BABY_CRUSADER;
  5253. case MAPID_BABY_SAGE: return JOB_BABY_SAGE;
  5254. case MAPID_BABY_BARDDANCER: return sex?JOB_BABY_BARD:JOB_BABY_DANCER;
  5255. case MAPID_BABY_MONK: return JOB_BABY_MONK;
  5256. case MAPID_BABY_ALCHEMIST: return JOB_BABY_ALCHEMIST;
  5257. case MAPID_BABY_ROGUE: return JOB_BABY_ROGUE;
  5258. //3-1 Jobs
  5259. case MAPID_SUPER_NOVICE_E: return JOB_SUPER_NOVICE_E;
  5260. case MAPID_RUNE_KNIGHT: return JOB_RUNE_KNIGHT;
  5261. case MAPID_WARLOCK: return JOB_WARLOCK;
  5262. case MAPID_RANGER: return JOB_RANGER;
  5263. case MAPID_ARCH_BISHOP: return JOB_ARCH_BISHOP;
  5264. case MAPID_MECHANIC: return JOB_MECHANIC;
  5265. case MAPID_GUILLOTINE_CROSS: return JOB_GUILLOTINE_CROSS;
  5266. //3-2 Jobs
  5267. case MAPID_ROYAL_GUARD: return JOB_ROYAL_GUARD;
  5268. case MAPID_SORCERER: return JOB_SORCERER;
  5269. case MAPID_MINSTRELWANDERER: return sex?JOB_MINSTREL:JOB_WANDERER;
  5270. case MAPID_SURA: return JOB_SURA;
  5271. case MAPID_GENETIC: return JOB_GENETIC;
  5272. case MAPID_SHADOW_CHASER: return JOB_SHADOW_CHASER;
  5273. //Trans 3-1 Jobs
  5274. case MAPID_RUNE_KNIGHT_T: return JOB_RUNE_KNIGHT_T;
  5275. case MAPID_WARLOCK_T: return JOB_WARLOCK_T;
  5276. case MAPID_RANGER_T: return JOB_RANGER_T;
  5277. case MAPID_ARCH_BISHOP_T: return JOB_ARCH_BISHOP_T;
  5278. case MAPID_MECHANIC_T: return JOB_MECHANIC_T;
  5279. case MAPID_GUILLOTINE_CROSS_T: return JOB_GUILLOTINE_CROSS_T;
  5280. //Trans 3-2 Jobs
  5281. case MAPID_ROYAL_GUARD_T: return JOB_ROYAL_GUARD_T;
  5282. case MAPID_SORCERER_T: return JOB_SORCERER_T;
  5283. case MAPID_MINSTRELWANDERER_T: return sex?JOB_MINSTREL_T:JOB_WANDERER_T;
  5284. case MAPID_SURA_T: return JOB_SURA_T;
  5285. case MAPID_GENETIC_T: return JOB_GENETIC_T;
  5286. case MAPID_SHADOW_CHASER_T: return JOB_SHADOW_CHASER_T;
  5287. //Baby 3-1 Jobs
  5288. case MAPID_SUPER_BABY_E: return JOB_SUPER_BABY_E;
  5289. case MAPID_BABY_RUNE: return JOB_BABY_RUNE;
  5290. case MAPID_BABY_WARLOCK: return JOB_BABY_WARLOCK;
  5291. case MAPID_BABY_RANGER: return JOB_BABY_RANGER;
  5292. case MAPID_BABY_BISHOP: return JOB_BABY_BISHOP;
  5293. case MAPID_BABY_MECHANIC: return JOB_BABY_MECHANIC;
  5294. case MAPID_BABY_CROSS: return JOB_BABY_CROSS;
  5295. //Baby 3-2 Jobs
  5296. case MAPID_BABY_GUARD: return JOB_BABY_GUARD;
  5297. case MAPID_BABY_SORCERER: return JOB_BABY_SORCERER;
  5298. case MAPID_BABY_MINSTRELWANDERER: return sex?JOB_BABY_MINSTREL:JOB_BABY_WANDERER;
  5299. case MAPID_BABY_SURA: return JOB_BABY_SURA;
  5300. case MAPID_BABY_GENETIC: return JOB_BABY_GENETIC;
  5301. case MAPID_BABY_CHASER: return JOB_BABY_CHASER;
  5302. default:
  5303. return -1;
  5304. }
  5305. }
  5306. /*====================================================
  5307. * This function return the name of the job (by [Yor])
  5308. *----------------------------------------------------*/
  5309. const char* job_name(int class_)
  5310. {
  5311. switch (class_) {
  5312. case JOB_NOVICE:
  5313. case JOB_SWORDMAN:
  5314. case JOB_MAGE:
  5315. case JOB_ARCHER:
  5316. case JOB_ACOLYTE:
  5317. case JOB_MERCHANT:
  5318. case JOB_THIEF:
  5319. return msg_txt(NULL,550 - JOB_NOVICE+class_);
  5320. case JOB_KNIGHT:
  5321. case JOB_PRIEST:
  5322. case JOB_WIZARD:
  5323. case JOB_BLACKSMITH:
  5324. case JOB_HUNTER:
  5325. case JOB_ASSASSIN:
  5326. return msg_txt(NULL,557 - JOB_KNIGHT+class_);
  5327. case JOB_KNIGHT2:
  5328. return msg_txt(NULL,557);
  5329. case JOB_CRUSADER:
  5330. case JOB_MONK:
  5331. case JOB_SAGE:
  5332. case JOB_ROGUE:
  5333. case JOB_ALCHEMIST:
  5334. case JOB_BARD:
  5335. case JOB_DANCER:
  5336. return msg_txt(NULL,563 - JOB_CRUSADER+class_);
  5337. case JOB_CRUSADER2:
  5338. return msg_txt(NULL,563);
  5339. case JOB_WEDDING:
  5340. case JOB_SUPER_NOVICE:
  5341. case JOB_GUNSLINGER:
  5342. case JOB_NINJA:
  5343. case JOB_XMAS:
  5344. return msg_txt(NULL,570 - JOB_WEDDING+class_);
  5345. case JOB_SUMMER:
  5346. return msg_txt(NULL,621);
  5347. case JOB_HANBOK:
  5348. return msg_txt(NULL,694);
  5349. case JOB_OKTOBERFEST:
  5350. return msg_txt(NULL,696);
  5351. case JOB_NOVICE_HIGH:
  5352. case JOB_SWORDMAN_HIGH:
  5353. case JOB_MAGE_HIGH:
  5354. case JOB_ARCHER_HIGH:
  5355. case JOB_ACOLYTE_HIGH:
  5356. case JOB_MERCHANT_HIGH:
  5357. case JOB_THIEF_HIGH:
  5358. return msg_txt(NULL,575 - JOB_NOVICE_HIGH+class_);
  5359. case JOB_LORD_KNIGHT:
  5360. case JOB_HIGH_PRIEST:
  5361. case JOB_HIGH_WIZARD:
  5362. case JOB_WHITESMITH:
  5363. case JOB_SNIPER:
  5364. case JOB_ASSASSIN_CROSS:
  5365. return msg_txt(NULL,582 - JOB_LORD_KNIGHT+class_);
  5366. case JOB_LORD_KNIGHT2:
  5367. return msg_txt(NULL,582);
  5368. case JOB_PALADIN:
  5369. case JOB_CHAMPION:
  5370. case JOB_PROFESSOR:
  5371. case JOB_STALKER:
  5372. case JOB_CREATOR:
  5373. case JOB_CLOWN:
  5374. case JOB_GYPSY:
  5375. return msg_txt(NULL,588 - JOB_PALADIN + class_);
  5376. case JOB_PALADIN2:
  5377. return msg_txt(NULL,588);
  5378. case JOB_BABY:
  5379. case JOB_BABY_SWORDMAN:
  5380. case JOB_BABY_MAGE:
  5381. case JOB_BABY_ARCHER:
  5382. case JOB_BABY_ACOLYTE:
  5383. case JOB_BABY_MERCHANT:
  5384. case JOB_BABY_THIEF:
  5385. return msg_txt(NULL,595 - JOB_BABY + class_);
  5386. case JOB_BABY_KNIGHT:
  5387. case JOB_BABY_PRIEST:
  5388. case JOB_BABY_WIZARD:
  5389. case JOB_BABY_BLACKSMITH:
  5390. case JOB_BABY_HUNTER:
  5391. case JOB_BABY_ASSASSIN:
  5392. return msg_txt(NULL,602 - JOB_BABY_KNIGHT + class_);
  5393. case JOB_BABY_KNIGHT2:
  5394. return msg_txt(NULL,602);
  5395. case JOB_BABY_CRUSADER:
  5396. case JOB_BABY_MONK:
  5397. case JOB_BABY_SAGE:
  5398. case JOB_BABY_ROGUE:
  5399. case JOB_BABY_ALCHEMIST:
  5400. case JOB_BABY_BARD:
  5401. case JOB_BABY_DANCER:
  5402. return msg_txt(NULL,608 - JOB_BABY_CRUSADER + class_);
  5403. case JOB_BABY_CRUSADER2:
  5404. return msg_txt(NULL,608);
  5405. case JOB_SUPER_BABY:
  5406. return msg_txt(NULL,615);
  5407. case JOB_TAEKWON:
  5408. return msg_txt(NULL,616);
  5409. case JOB_STAR_GLADIATOR:
  5410. case JOB_STAR_GLADIATOR2:
  5411. return msg_txt(NULL,617);
  5412. case JOB_SOUL_LINKER:
  5413. return msg_txt(NULL,618);
  5414. case JOB_GANGSI:
  5415. case JOB_DEATH_KNIGHT:
  5416. case JOB_DARK_COLLECTOR:
  5417. return msg_txt(NULL,622 - JOB_GANGSI+class_);
  5418. case JOB_RUNE_KNIGHT:
  5419. case JOB_WARLOCK:
  5420. case JOB_RANGER:
  5421. case JOB_ARCH_BISHOP:
  5422. case JOB_MECHANIC:
  5423. case JOB_GUILLOTINE_CROSS:
  5424. return msg_txt(NULL,625 - JOB_RUNE_KNIGHT+class_);
  5425. case JOB_RUNE_KNIGHT_T:
  5426. case JOB_WARLOCK_T:
  5427. case JOB_RANGER_T:
  5428. case JOB_ARCH_BISHOP_T:
  5429. case JOB_MECHANIC_T:
  5430. case JOB_GUILLOTINE_CROSS_T:
  5431. return msg_txt(NULL,681 - JOB_RUNE_KNIGHT_T+class_);
  5432. case JOB_ROYAL_GUARD:
  5433. case JOB_SORCERER:
  5434. case JOB_MINSTREL:
  5435. case JOB_WANDERER:
  5436. case JOB_SURA:
  5437. case JOB_GENETIC:
  5438. case JOB_SHADOW_CHASER:
  5439. return msg_txt(NULL,631 - JOB_ROYAL_GUARD+class_);
  5440. case JOB_ROYAL_GUARD_T:
  5441. case JOB_SORCERER_T:
  5442. case JOB_MINSTREL_T:
  5443. case JOB_WANDERER_T:
  5444. case JOB_SURA_T:
  5445. case JOB_GENETIC_T:
  5446. case JOB_SHADOW_CHASER_T:
  5447. return msg_txt(NULL,687 - JOB_ROYAL_GUARD_T+class_);
  5448. case JOB_RUNE_KNIGHT2:
  5449. case JOB_RUNE_KNIGHT_T2:
  5450. return msg_txt(NULL,625);
  5451. case JOB_ROYAL_GUARD2:
  5452. case JOB_ROYAL_GUARD_T2:
  5453. return msg_txt(NULL,631);
  5454. case JOB_RANGER2:
  5455. case JOB_RANGER_T2:
  5456. return msg_txt(NULL,627);
  5457. case JOB_MECHANIC2:
  5458. case JOB_MECHANIC_T2:
  5459. return msg_txt(NULL,629);
  5460. case JOB_BABY_RUNE:
  5461. case JOB_BABY_WARLOCK:
  5462. case JOB_BABY_RANGER:
  5463. case JOB_BABY_BISHOP:
  5464. case JOB_BABY_MECHANIC:
  5465. case JOB_BABY_CROSS:
  5466. case JOB_BABY_GUARD:
  5467. case JOB_BABY_SORCERER:
  5468. case JOB_BABY_MINSTREL:
  5469. case JOB_BABY_WANDERER:
  5470. case JOB_BABY_SURA:
  5471. case JOB_BABY_GENETIC:
  5472. case JOB_BABY_CHASER:
  5473. return msg_txt(NULL,638 - JOB_BABY_RUNE+class_);
  5474. case JOB_BABY_RUNE2:
  5475. return msg_txt(NULL,638);
  5476. case JOB_BABY_GUARD2:
  5477. return msg_txt(NULL,644);
  5478. case JOB_BABY_RANGER2:
  5479. return msg_txt(NULL,640);
  5480. case JOB_BABY_MECHANIC2:
  5481. return msg_txt(NULL,642);
  5482. case JOB_SUPER_NOVICE_E:
  5483. case JOB_SUPER_BABY_E:
  5484. return msg_txt(NULL,651 - JOB_SUPER_NOVICE_E+class_);
  5485. case JOB_KAGEROU:
  5486. case JOB_OBORO:
  5487. return msg_txt(NULL,653 - JOB_KAGEROU+class_);
  5488. case JOB_REBELLION:
  5489. return msg_txt(NULL,695);
  5490. default:
  5491. return msg_txt(NULL,655);
  5492. }
  5493. }
  5494. /*====================================================
  5495. * Timered function to make id follow a target.
  5496. * @id = bl.id (player only atm)
  5497. * target is define in sd->followtarget (bl.id)
  5498. * used by pc_follow
  5499. *----------------------------------------------------*/
  5500. int pc_follow_timer(int tid, unsigned int tick, int id, intptr_t data)
  5501. {
  5502. struct map_session_data *sd;
  5503. struct block_list *tbl;
  5504. sd = map_id2sd(id);
  5505. nullpo_ret(sd);
  5506. if (sd->followtimer != tid){
  5507. ShowError("pc_follow_timer %d != %d\n",sd->followtimer,tid);
  5508. sd->followtimer = INVALID_TIMER;
  5509. return 0;
  5510. }
  5511. sd->followtimer = INVALID_TIMER;
  5512. tbl = map_id2bl(sd->followtarget);
  5513. if (tbl == NULL || pc_isdead(sd) || status_isdead(tbl))
  5514. {
  5515. pc_stop_following(sd);
  5516. return 0;
  5517. }
  5518. // either player or target is currently detached from map blocks (could be teleporting),
  5519. // but still connected to this map, so we'll just increment the timer and check back later
  5520. if (sd->bl.prev != NULL && tbl->prev != NULL &&
  5521. sd->ud.skilltimer == INVALID_TIMER && sd->ud.attacktimer == INVALID_TIMER && sd->ud.walktimer == INVALID_TIMER)
  5522. {
  5523. if((sd->bl.m == tbl->m) && unit_can_reach_bl(&sd->bl,tbl, AREA_SIZE, 0, NULL, NULL)) {
  5524. if (!check_distance_bl(&sd->bl, tbl, 5))
  5525. unit_walktobl(&sd->bl, tbl, 5, 0);
  5526. } else
  5527. pc_setpos(sd, map_id2index(tbl->m), tbl->x, tbl->y, CLR_TELEPORT);
  5528. }
  5529. sd->followtimer = add_timer(
  5530. tick + 1000, // increase time a bit to loosen up map's load
  5531. pc_follow_timer, sd->bl.id, 0);
  5532. return 0;
  5533. }
  5534. int pc_stop_following (struct map_session_data *sd)
  5535. {
  5536. nullpo_ret(sd);
  5537. if (sd->followtimer != INVALID_TIMER) {
  5538. delete_timer(sd->followtimer,pc_follow_timer);
  5539. sd->followtimer = INVALID_TIMER;
  5540. }
  5541. sd->followtarget = -1;
  5542. sd->ud.target_to = 0;
  5543. unit_stop_walking(&sd->bl, 1);
  5544. return 0;
  5545. }
  5546. int pc_follow(struct map_session_data *sd,int target_id)
  5547. {
  5548. struct block_list *bl = map_id2bl(target_id);
  5549. if (bl == NULL /*|| bl->type != BL_PC*/)
  5550. return 1;
  5551. if (sd->followtimer != INVALID_TIMER)
  5552. pc_stop_following(sd);
  5553. sd->followtarget = target_id;
  5554. pc_follow_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
  5555. return 0;
  5556. }
  5557. int pc_checkbaselevelup(struct map_session_data *sd) {
  5558. unsigned int next = pc_nextbaseexp(sd);
  5559. if (!next || sd->status.base_exp < next)
  5560. return 0;
  5561. do {
  5562. sd->status.base_exp -= next;
  5563. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  5564. if(!battle_config.multi_level_up && sd->status.base_exp > next-1)
  5565. sd->status.base_exp = next-1;
  5566. next = pc_gets_status_point(sd->status.base_level);
  5567. sd->status.base_level ++;
  5568. sd->status.status_point += next;
  5569. } while ((next=pc_nextbaseexp(sd)) > 0 && sd->status.base_exp >= next);
  5570. if (battle_config.pet_lv_rate && sd->pd) //<Skotlex> update pet's level
  5571. status_calc_pet(sd->pd,SCO_NONE);
  5572. clif_updatestatus(sd,SP_STATUSPOINT);
  5573. clif_updatestatus(sd,SP_BASELEVEL);
  5574. clif_updatestatus(sd,SP_BASEEXP);
  5575. clif_updatestatus(sd,SP_NEXTBASEEXP);
  5576. status_calc_pc(sd,SCO_FORCE);
  5577. status_percent_heal(&sd->bl,100,100);
  5578. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) {
  5579. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_KYRIE),100,1,skill_get_time(PR_KYRIE,1));
  5580. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_IMPOSITIO),100,1,skill_get_time(PR_IMPOSITIO,1));
  5581. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_MAGNIFICAT),100,1,skill_get_time(PR_MAGNIFICAT,1));
  5582. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_GLORIA),100,1,skill_get_time(PR_GLORIA,1));
  5583. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_SUFFRAGIUM),100,1,skill_get_time(PR_SUFFRAGIUM,1));
  5584. if (sd->state.snovice_dead_flag)
  5585. sd->state.snovice_dead_flag = 0; //Reenable steelbody resurrection on dead.
  5586. } else if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON ) {
  5587. sc_start(&sd->bl,&sd->bl,status_skill2sc(AL_INCAGI),100,10,600000);
  5588. sc_start(&sd->bl,&sd->bl,status_skill2sc(AL_BLESSING),100,10,600000);
  5589. }
  5590. clif_misceffect(&sd->bl,0);
  5591. npc_script_event(sd, NPCE_BASELVUP); //LORDALFA - LVLUPEVENT
  5592. if(sd->status.party_id)
  5593. party_send_levelup(sd);
  5594. pc_baselevelchanged(sd);
  5595. return 1;
  5596. }
  5597. void pc_baselevelchanged(struct map_session_data *sd) {
  5598. uint8 i;
  5599. for( i = 0; i < EQI_MAX; i++ ) {
  5600. if( sd->equip_index[i] >= 0 ) {
  5601. if( sd->inventory_data[ sd->equip_index[i] ]->elvmax && sd->status.base_level > (unsigned int)sd->inventory_data[ sd->equip_index[i] ]->elvmax )
  5602. pc_unequipitem(sd, sd->equip_index[i], 3);
  5603. }
  5604. }
  5605. pc_show_questinfo(sd);
  5606. }
  5607. int pc_checkjoblevelup(struct map_session_data *sd)
  5608. {
  5609. unsigned int next = pc_nextjobexp(sd);
  5610. nullpo_ret(sd);
  5611. if(!next || sd->status.job_exp < next)
  5612. return 0;
  5613. do {
  5614. sd->status.job_exp -= next;
  5615. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  5616. if(!battle_config.multi_level_up && sd->status.job_exp > next-1)
  5617. sd->status.job_exp = next-1;
  5618. sd->status.job_level ++;
  5619. sd->status.skill_point ++;
  5620. } while ((next=pc_nextjobexp(sd)) > 0 && sd->status.job_exp >= next);
  5621. clif_updatestatus(sd,SP_JOBLEVEL);
  5622. clif_updatestatus(sd,SP_JOBEXP);
  5623. clif_updatestatus(sd,SP_NEXTJOBEXP);
  5624. clif_updatestatus(sd,SP_SKILLPOINT);
  5625. status_calc_pc(sd,SCO_FORCE);
  5626. clif_misceffect(&sd->bl,1);
  5627. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  5628. clif_status_change(&sd->bl,SI_DEVIL, 1, 0, 0, 0, 1); //Permanent blind effect from SG_DEVIL.
  5629. npc_script_event(sd, NPCE_JOBLVUP);
  5630. return 1;
  5631. }
  5632. /** Alters experiences calculation based on self bonuses that do not get even shared to the party.
  5633. * @param sd Player
  5634. * @param base_exp Base EXP before peronal bonuses
  5635. * @param job_exp Job EXP before peronal bonuses
  5636. * @param src Block list that affecting the exp calculation
  5637. */
  5638. static void pc_calcexp(struct map_session_data *sd, unsigned int *base_exp, unsigned int *job_exp, struct block_list *src)
  5639. {
  5640. int bonus = 0, vip_bonus_base = 0, vip_bonus_job = 0;
  5641. if (src) {
  5642. struct status_data *status = status_get_status_data(src);
  5643. if( sd->expaddrace[status->race] )
  5644. bonus += sd->expaddrace[status->race];
  5645. if( sd->expaddrace[RC_ALL] )
  5646. bonus += sd->expaddrace[RC_ALL];
  5647. if( sd->expaddclass[status->class_] )
  5648. bonus += sd->expaddclass[status->class_];
  5649. if( sd->expaddclass[CLASS_ALL] )
  5650. bonus += sd->expaddclass[CLASS_ALL];
  5651. if (battle_config.pk_mode &&
  5652. (int)(status_get_lv(src) - sd->status.base_level) >= 20)
  5653. bonus += 15; // pk_mode additional exp if monster >20 levels [Valaris]
  5654. #ifdef VIP_ENABLE
  5655. //EXP bonus for VIP player
  5656. if (src && src->type == BL_MOB && pc_isvip(sd)) {
  5657. vip_bonus_base = battle_config.vip_base_exp_increase;
  5658. vip_bonus_job = battle_config.vip_job_exp_increase;
  5659. }
  5660. #endif
  5661. }
  5662. if (&sd->sc && sd->sc.data[SC_EXPBOOST]) {
  5663. bonus += sd->sc.data[SC_EXPBOOST]->val1;
  5664. if( battle_config.vip_bm_increase && pc_isvip(sd) ) // Increase Battle Manual EXP rate for VIP.
  5665. bonus += ( sd->sc.data[SC_EXPBOOST]->val1 / battle_config.vip_bm_increase );
  5666. }
  5667. *base_exp = (unsigned int) cap_value(*base_exp + (double)*base_exp * (bonus + vip_bonus_base)/100., 1, UINT_MAX);
  5668. if (&sd->sc && sd->sc.data[SC_JEXPBOOST])
  5669. bonus += sd->sc.data[SC_JEXPBOOST]->val1;
  5670. *job_exp = (unsigned int) cap_value(*job_exp + (double)*job_exp * (bonus + vip_bonus_job)/100., 1, UINT_MAX);
  5671. return;
  5672. }
  5673. /*==========================================
  5674. * Give x exp at sd player and calculate remaining exp for next lvl
  5675. *------------------------------------------*/
  5676. int pc_gainexp(struct map_session_data *sd, struct block_list *src, unsigned int base_exp, unsigned int job_exp, bool quest)
  5677. {
  5678. float nextbp = 0, nextjp = 0;
  5679. unsigned int nextb = 0, nextj = 0;
  5680. nullpo_ret(sd);
  5681. if(sd->bl.prev == NULL || pc_isdead(sd))
  5682. return 0;
  5683. if(!battle_config.pvp_exp && map[sd->bl.m].flag.pvp) // [MouseJstr]
  5684. return 0; // no exp on pvp maps
  5685. if(sd->status.guild_id>0)
  5686. base_exp-=guild_payexp(sd,base_exp);
  5687. pc_calcexp(sd, &base_exp, &job_exp, src); // Give (J)EXPBOOST for quests even if src is NULL.
  5688. nextb = pc_nextbaseexp(sd);
  5689. nextj = pc_nextjobexp(sd);
  5690. if(sd->state.showexp || battle_config.max_exp_gain_rate){
  5691. if (nextb > 0)
  5692. nextbp = (float) base_exp / (float) nextb;
  5693. if (nextj > 0)
  5694. nextjp = (float) job_exp / (float) nextj;
  5695. if(battle_config.max_exp_gain_rate) {
  5696. if (nextbp > battle_config.max_exp_gain_rate/1000.) {
  5697. //Note that this value should never be greater than the original
  5698. //base_exp, therefore no overflow checks are needed. [Skotlex]
  5699. base_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextb);
  5700. if (sd->state.showexp)
  5701. nextbp = (float) base_exp / (float) nextb;
  5702. }
  5703. if (nextjp > battle_config.max_exp_gain_rate/1000.) {
  5704. job_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextj);
  5705. if (sd->state.showexp)
  5706. nextjp = (float) job_exp / (float) nextj;
  5707. }
  5708. }
  5709. }
  5710. //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]
  5711. if (base_exp) {
  5712. nextb = nextb?UINT_MAX:pc_thisbaseexp(sd);
  5713. if(sd->status.base_exp > nextb - base_exp)
  5714. sd->status.base_exp = nextb;
  5715. else
  5716. sd->status.base_exp += base_exp;
  5717. pc_checkbaselevelup(sd);
  5718. clif_updatestatus(sd,SP_BASEEXP);
  5719. }
  5720. if (job_exp) {
  5721. nextj = nextj?UINT_MAX:pc_thisjobexp(sd);
  5722. if(sd->status.job_exp > nextj - job_exp)
  5723. sd->status.job_exp = nextj;
  5724. else
  5725. sd->status.job_exp += job_exp;
  5726. pc_checkjoblevelup(sd);
  5727. clif_updatestatus(sd,SP_JOBEXP);
  5728. }
  5729. if(base_exp)
  5730. clif_displayexp(sd, base_exp, SP_BASEEXP, quest);
  5731. if(job_exp)
  5732. clif_displayexp(sd, job_exp, SP_JOBEXP, quest);
  5733. if(sd->state.showexp) {
  5734. char output[256];
  5735. sprintf(output,
  5736. "Experience Gained Base:%u (%.2f%%) Job:%u (%.2f%%)",base_exp,nextbp*(float)100,job_exp,nextjp*(float)100);
  5737. clif_disp_onlyself(sd,output,strlen(output));
  5738. }
  5739. return 1;
  5740. }
  5741. /*==========================================
  5742. * Returns max level for this character.
  5743. *------------------------------------------*/
  5744. unsigned int pc_maxbaselv(struct map_session_data *sd){
  5745. return job_info[pc_class2idx(sd->status.class_)].max_level[0];
  5746. }
  5747. unsigned int pc_maxjoblv(struct map_session_data *sd){
  5748. return job_info[pc_class2idx(sd->status.class_)].max_level[1];
  5749. }
  5750. /*==========================================
  5751. * base level exp lookup.
  5752. *------------------------------------------*/
  5753. //Base exp needed for next level.
  5754. unsigned int pc_nextbaseexp(struct map_session_data *sd){
  5755. nullpo_ret(sd);
  5756. if(sd->status.base_level>=pc_maxbaselv(sd) || sd->status.base_level==0)
  5757. return 0;
  5758. return job_info[pc_class2idx(sd->status.class_)].exp_table[0][sd->status.base_level-1];
  5759. }
  5760. //Base exp needed for this level.
  5761. unsigned int pc_thisbaseexp(struct map_session_data *sd){
  5762. if(sd->status.base_level>pc_maxbaselv(sd) || sd->status.base_level<=1)
  5763. return 0;
  5764. return job_info[pc_class2idx(sd->status.class_)].exp_table[0][sd->status.base_level-2];
  5765. }
  5766. /*==========================================
  5767. * job level exp lookup
  5768. * Return:
  5769. * 0 = not found
  5770. * x = exp for level
  5771. *------------------------------------------*/
  5772. //Job exp needed for next level.
  5773. unsigned int pc_nextjobexp(struct map_session_data *sd){
  5774. nullpo_ret(sd);
  5775. if(sd->status.job_level>=pc_maxjoblv(sd) || sd->status.job_level==0)
  5776. return 0;
  5777. return job_info[pc_class2idx(sd->status.class_)].exp_table[1][sd->status.job_level-1];
  5778. }
  5779. //Job exp needed for this level.
  5780. unsigned int pc_thisjobexp(struct map_session_data *sd){
  5781. if(sd->status.job_level>pc_maxjoblv(sd) || sd->status.job_level<=1)
  5782. return 0;
  5783. return job_info[pc_class2idx(sd->status.class_)].exp_table[1][sd->status.job_level-2];
  5784. }
  5785. /// Returns the value of the specified stat.
  5786. static int pc_getstat(struct map_session_data* sd, int type)
  5787. {
  5788. nullpo_retr(-1, sd);
  5789. switch( type ) {
  5790. case SP_STR: return sd->status.str;
  5791. case SP_AGI: return sd->status.agi;
  5792. case SP_VIT: return sd->status.vit;
  5793. case SP_INT: return sd->status.int_;
  5794. case SP_DEX: return sd->status.dex;
  5795. case SP_LUK: return sd->status.luk;
  5796. default:
  5797. return -1;
  5798. }
  5799. }
  5800. /// Sets the specified stat to the specified value.
  5801. /// Returns the new value.
  5802. static int pc_setstat(struct map_session_data* sd, int type, int val)
  5803. {
  5804. nullpo_retr(-1, sd);
  5805. switch( type ) {
  5806. case SP_STR: sd->status.str = val; break;
  5807. case SP_AGI: sd->status.agi = val; break;
  5808. case SP_VIT: sd->status.vit = val; break;
  5809. case SP_INT: sd->status.int_ = val; break;
  5810. case SP_DEX: sd->status.dex = val; break;
  5811. case SP_LUK: sd->status.luk = val; break;
  5812. default:
  5813. return -1;
  5814. }
  5815. return val;
  5816. }
  5817. // Calculates the number of status points PC gets when leveling up (from level to level+1)
  5818. int pc_gets_status_point(int level)
  5819. {
  5820. if (battle_config.use_statpoint_table) //Use values from "db/statpoint.txt"
  5821. return (statp[level+1] - statp[level]);
  5822. else //Default increase
  5823. return ((level+15) / 5);
  5824. }
  5825. #ifdef RENEWAL_STAT
  5826. /// Renewal status point cost formula
  5827. #define PC_STATUS_POINT_COST(low) (((low) < 100) ? (2 + ((low) - 1) / 10) : (16 + 4 * (((low) - 100) / 5)))
  5828. #else
  5829. /// Pre-Renewal status point cost formula
  5830. #define PC_STATUS_POINT_COST(low) (( 1 + ((low) + 9) / 10 ))
  5831. #endif
  5832. /// Returns the number of stat points needed to change the specified stat by val.
  5833. /// If val is negative, returns the number of stat points that would be needed to
  5834. /// raise the specified stat from (current value - val) to current value.
  5835. int pc_need_status_point(struct map_session_data* sd, int type, int val)
  5836. {
  5837. int low, high, sp = 0, max = 0;
  5838. if ( val == 0 )
  5839. return 0;
  5840. low = pc_getstat(sd,type);
  5841. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR));
  5842. if ( low >= max && val > 0 )
  5843. return 0; // Official servers show '0' when max is reached
  5844. high = low + val;
  5845. if ( val < 0 )
  5846. swap(low, high);
  5847. for ( ; low < high; low++ )
  5848. sp += PC_STATUS_POINT_COST(low);
  5849. return sp;
  5850. }
  5851. /**
  5852. * Returns the value the specified stat can be increased by with the current
  5853. * amount of available status points for the current character's class.
  5854. *
  5855. * @param sd The target character.
  5856. * @param type Stat to verify.
  5857. * @return Maximum value the stat could grow by.
  5858. */
  5859. int pc_maxparameterincrease(struct map_session_data* sd, int type)
  5860. {
  5861. int base, final_val, status_points, max_param;
  5862. nullpo_ret(sd);
  5863. base = final_val = pc_getstat(sd, type);
  5864. status_points = sd->status.status_point;
  5865. max_param = pc_maxparameter(sd, (enum e_params)(type-SP_STR));
  5866. while (final_val <= max_param && status_points >= 0) {
  5867. status_points -= PC_STATUS_POINT_COST(final_val);
  5868. final_val++;
  5869. }
  5870. final_val--;
  5871. return (final_val > base ? final_val-base : 0);
  5872. }
  5873. /**
  5874. * Raises a stat by the specified amount.
  5875. *
  5876. * Obeys max_parameter limits.
  5877. * Subtracts status points according to the cost of the increased stat points.
  5878. *
  5879. * @param sd The target character.
  5880. * @param type The stat to change (see enum _sp)
  5881. * @param increase The stat increase (strictly positive) amount.
  5882. * @retval true if the stat was increased by any amount.
  5883. * @retval false if there were no changes.
  5884. */
  5885. bool pc_statusup(struct map_session_data* sd, int type, int increase)
  5886. {
  5887. int max_increase = 0, current = 0, needed_points = 0, final_value = 0;
  5888. nullpo_ret(sd);
  5889. // check conditions
  5890. if (type < SP_STR || type > SP_LUK || increase <= 0) {
  5891. clif_statusupack(sd, type, 0, 0);
  5892. return false;
  5893. }
  5894. // check limits
  5895. current = pc_getstat(sd, type);
  5896. max_increase = pc_maxparameterincrease(sd, type);
  5897. increase = cap_value(increase, 0, max_increase); // cap to the maximum status points available
  5898. if (increase <= 0 || current + increase > pc_maxparameter(sd, (enum e_params)(type-SP_STR))) {
  5899. clif_statusupack(sd, type, 0, 0);
  5900. return false;
  5901. }
  5902. // check status points
  5903. needed_points = pc_need_status_point(sd, type, increase);
  5904. if (needed_points < 0 || needed_points > sd->status.status_point) { // Sanity check
  5905. clif_statusupack(sd, type, 0, 0);
  5906. return false;
  5907. }
  5908. // set new values
  5909. final_value = pc_setstat(sd, type, current + increase);
  5910. sd->status.status_point -= needed_points;
  5911. status_calc_pc(sd,SCO_NONE);
  5912. // update increase cost indicator
  5913. clif_updatestatus(sd, SP_USTR + type-SP_STR);
  5914. // update statpoint count
  5915. clif_updatestatus(sd, SP_STATUSPOINT);
  5916. // update stat value
  5917. clif_statusupack(sd, type, 1, final_value); // required
  5918. if( final_value > 255 )
  5919. clif_updatestatus(sd, type); // send after the 'ack' to override the truncated value
  5920. return true;
  5921. }
  5922. /**
  5923. * Raises a stat by the specified amount.
  5924. *
  5925. * Obeys max_parameter limits.
  5926. * Does not subtract status points for the cost of the modified stat points.
  5927. *
  5928. * @param sd The target character.
  5929. * @param type The stat to change (see enum _sp)
  5930. * @param val The stat increase (or decrease) amount.
  5931. * @return the stat increase amount.
  5932. * @retval 0 if no changes were made.
  5933. */
  5934. int pc_statusup2(struct map_session_data* sd, int type, int val)
  5935. {
  5936. int max, need;
  5937. nullpo_ret(sd);
  5938. if( type < SP_STR || type > SP_LUK )
  5939. {
  5940. clif_statusupack(sd,type,0,0);
  5941. return 0;
  5942. }
  5943. need = pc_need_status_point(sd,type,1);
  5944. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR)); // set new value
  5945. val = pc_setstat(sd, type, cap_value(pc_getstat(sd,type) + val, 1, max));
  5946. status_calc_pc(sd,SCO_NONE);
  5947. // update increase cost indicator
  5948. if( need != pc_need_status_point(sd,type,1) )
  5949. clif_updatestatus(sd, SP_USTR + type-SP_STR);
  5950. // update stat value
  5951. clif_statusupack(sd,type,1,val); // required
  5952. if( val > 255 )
  5953. clif_updatestatus(sd,type); // send after the 'ack' to override the truncated value
  5954. return val;
  5955. }
  5956. /*==========================================
  5957. * Update skill_lv for player sd
  5958. * Skill point allocation
  5959. *------------------------------------------*/
  5960. void pc_skillup(struct map_session_data *sd,uint16 skill_id)
  5961. {
  5962. uint16 idx = skill_get_index(skill_id);
  5963. nullpo_retv(sd);
  5964. if (!idx) {
  5965. if (skill_id)
  5966. ShowError("pc_skillup: Player attempts to level up invalid skill '%d'\n", skill_id);
  5967. return;
  5968. }
  5969. // Level up guild skill
  5970. if (SKILL_CHK_GUILD(skill_id)) {
  5971. guild_skillup(sd, skill_id);
  5972. return;
  5973. }
  5974. // Level up homunculus skill
  5975. else if (sd->hd && SKILL_CHK_HOMUN(skill_id)) {
  5976. hom_skillup(sd->hd, skill_id);
  5977. return;
  5978. }
  5979. else {
  5980. if( sd->status.skill_point > 0 &&
  5981. sd->status.skill[idx].id &&
  5982. sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT && //Don't allow raising while you have granted skills. [Skotlex]
  5983. sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_) )
  5984. {
  5985. int lv, range, upgradable;
  5986. sd->status.skill[idx].lv++;
  5987. sd->status.skill_point--;
  5988. if( !skill_get_inf(skill_id) )
  5989. status_calc_pc(sd,SCO_NONE); // Only recalculate for passive skills.
  5990. else if( sd->status.skill_point == 0 && pc_is_taekwon_ranker(sd) )
  5991. pc_calc_skilltree(sd); // Required to grant all TK Ranker skills.
  5992. else
  5993. pc_check_skilltree(sd); // Check if a new skill can Lvlup
  5994. lv = sd->status.skill[idx].lv;
  5995. range = skill_get_range2(&sd->bl, skill_id, lv);
  5996. upgradable = (lv < skill_tree_get_max(sd->status.skill[idx].id, sd->status.class_)) ? 1 : 0;
  5997. clif_skillup(sd,skill_id,lv,range,upgradable);
  5998. clif_updatestatus(sd,SP_SKILLPOINT);
  5999. if( skill_id == GN_REMODELING_CART ) /* cart weight info was updated by status_calc_pc */
  6000. clif_updatestatus(sd,SP_CARTINFO);
  6001. if (!pc_has_permission(sd, PC_PERM_ALL_SKILL)) // may skill everything at any time anyways, and this would cause a huge slowdown
  6002. clif_skillinfoblock(sd);
  6003. }
  6004. //else
  6005. // ShowDebug("Skill Level up failed. ID:%d idx:%d (CID=%d. AID=%d)\n", skill_id, idx, sd->status.char_id, sd->status.account_id);
  6006. }
  6007. }
  6008. /*==========================================
  6009. * /allskill
  6010. *------------------------------------------*/
  6011. int pc_allskillup(struct map_session_data *sd)
  6012. {
  6013. int i;
  6014. nullpo_ret(sd);
  6015. for (i = 0; i < MAX_SKILL; i++) {
  6016. if (sd->status.skill[i].flag != SKILL_FLAG_PERMANENT && sd->status.skill[i].flag != SKILL_FLAG_PERM_GRANTED && sd->status.skill[i].flag != SKILL_FLAG_PLAGIARIZED) {
  6017. sd->status.skill[i].lv = (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  6018. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  6019. if (sd->status.skill[i].lv == 0)
  6020. sd->status.skill[i].id = 0;
  6021. }
  6022. }
  6023. if (!pc_grant_allskills(sd, true)) {
  6024. uint16 sk_id;
  6025. for (i = 0; i < MAX_SKILL_TREE && (sk_id = skill_tree[pc_class2idx(sd->status.class_)][i].id) > 0;i++){
  6026. int inf2 = 0;
  6027. uint16 sk_idx = 0;
  6028. if (!sk_id || !(sk_idx = skill_get_index(sk_id)))
  6029. continue;
  6030. inf2 = skill_get_inf2(sk_id);
  6031. if (
  6032. (inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn) ||
  6033. (inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) ||
  6034. sk_id == SG_DEVIL
  6035. )
  6036. continue; //Cannot be learned normally.
  6037. sd->status.skill[sk_idx].id = sk_id;
  6038. sd->status.skill[sk_idx].lv = skill_tree_get_max(sk_id, sd->status.class_); // celest
  6039. }
  6040. }
  6041. status_calc_pc(sd,SCO_NONE);
  6042. //Required because if you could level up all skills previously,
  6043. //the update will not be sent as only the lv variable changes.
  6044. clif_skillinfoblock(sd);
  6045. return 0;
  6046. }
  6047. /*==========================================
  6048. * /resetlvl
  6049. *------------------------------------------*/
  6050. int pc_resetlvl(struct map_session_data* sd,int type)
  6051. {
  6052. int i;
  6053. nullpo_ret(sd);
  6054. if (type != 3) //Also reset skills
  6055. pc_resetskill(sd, 0);
  6056. if(type == 1){
  6057. sd->status.skill_point=0;
  6058. sd->status.base_level=1;
  6059. sd->status.job_level=1;
  6060. sd->status.base_exp=0;
  6061. sd->status.job_exp=0;
  6062. if(sd->sc.option !=0)
  6063. sd->sc.option = 0;
  6064. sd->status.str=1;
  6065. sd->status.agi=1;
  6066. sd->status.vit=1;
  6067. sd->status.int_=1;
  6068. sd->status.dex=1;
  6069. sd->status.luk=1;
  6070. if(sd->status.class_ == JOB_NOVICE_HIGH) {
  6071. sd->status.status_point=100; // not 88 [celest]
  6072. // give platinum skills upon changing
  6073. pc_skill(sd,NV_FIRSTAID,1,ADDSKILL_PERMANENT);
  6074. pc_skill(sd,NV_TRICKDEAD,1,ADDSKILL_PERMANENT);
  6075. }
  6076. }
  6077. if(type == 2){
  6078. sd->status.skill_point=0;
  6079. sd->status.base_level=1;
  6080. sd->status.job_level=1;
  6081. sd->status.base_exp=0;
  6082. sd->status.job_exp=0;
  6083. }
  6084. if(type == 3){
  6085. sd->status.base_level=1;
  6086. sd->status.base_exp=0;
  6087. }
  6088. if(type == 4){
  6089. sd->status.job_level=1;
  6090. sd->status.job_exp=0;
  6091. }
  6092. clif_updatestatus(sd,SP_STATUSPOINT);
  6093. clif_updatestatus(sd,SP_STR);
  6094. clif_updatestatus(sd,SP_AGI);
  6095. clif_updatestatus(sd,SP_VIT);
  6096. clif_updatestatus(sd,SP_INT);
  6097. clif_updatestatus(sd,SP_DEX);
  6098. clif_updatestatus(sd,SP_LUK);
  6099. clif_updatestatus(sd,SP_BASELEVEL);
  6100. clif_updatestatus(sd,SP_JOBLEVEL);
  6101. clif_updatestatus(sd,SP_STATUSPOINT);
  6102. clif_updatestatus(sd,SP_BASEEXP);
  6103. clif_updatestatus(sd,SP_JOBEXP);
  6104. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6105. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6106. clif_updatestatus(sd,SP_SKILLPOINT);
  6107. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  6108. clif_updatestatus(sd,SP_UAGI);
  6109. clif_updatestatus(sd,SP_UVIT);
  6110. clif_updatestatus(sd,SP_UINT);
  6111. clif_updatestatus(sd,SP_UDEX);
  6112. clif_updatestatus(sd,SP_ULUK); // End Addition
  6113. for(i=0;i<EQI_MAX;i++) { // unequip items that can't be equipped by base 1 [Valaris]
  6114. if(sd->equip_index[i] >= 0)
  6115. if(pc_isequip(sd,sd->equip_index[i]))
  6116. pc_unequipitem(sd,sd->equip_index[i],2);
  6117. }
  6118. if ((type == 1 || type == 2 || type == 3) && sd->status.party_id)
  6119. party_send_levelup(sd);
  6120. status_calc_pc(sd, SCO_FORCE);
  6121. clif_skillinfoblock(sd);
  6122. return 0;
  6123. }
  6124. /*==========================================
  6125. * /resetstate
  6126. *------------------------------------------*/
  6127. int pc_resetstate(struct map_session_data* sd)
  6128. {
  6129. nullpo_ret(sd);
  6130. if (battle_config.use_statpoint_table)
  6131. { // New statpoint table used here - Dexity
  6132. if (sd->status.base_level > MAX_LEVEL)
  6133. { //statp[] goes out of bounds, can't reset!
  6134. ShowError("pc_resetstate: Can't reset stats of %d:%d, the base level (%d) is greater than the max level supported (%d)\n",
  6135. sd->status.account_id, sd->status.char_id, sd->status.base_level, MAX_LEVEL);
  6136. return 0;
  6137. }
  6138. sd->status.status_point = statp[sd->status.base_level] + ( sd->class_&JOBL_UPPER ? 52 : 0 ); // extra 52+48=100 stat points
  6139. }
  6140. else
  6141. {
  6142. int add=0;
  6143. add += pc_need_status_point(sd, SP_STR, 1-pc_getstat(sd, SP_STR));
  6144. add += pc_need_status_point(sd, SP_AGI, 1-pc_getstat(sd, SP_AGI));
  6145. add += pc_need_status_point(sd, SP_VIT, 1-pc_getstat(sd, SP_VIT));
  6146. add += pc_need_status_point(sd, SP_INT, 1-pc_getstat(sd, SP_INT));
  6147. add += pc_need_status_point(sd, SP_DEX, 1-pc_getstat(sd, SP_DEX));
  6148. add += pc_need_status_point(sd, SP_LUK, 1-pc_getstat(sd, SP_LUK));
  6149. sd->status.status_point+=add;
  6150. }
  6151. pc_setstat(sd, SP_STR, 1);
  6152. pc_setstat(sd, SP_AGI, 1);
  6153. pc_setstat(sd, SP_VIT, 1);
  6154. pc_setstat(sd, SP_INT, 1);
  6155. pc_setstat(sd, SP_DEX, 1);
  6156. pc_setstat(sd, SP_LUK, 1);
  6157. clif_updatestatus(sd,SP_STR);
  6158. clif_updatestatus(sd,SP_AGI);
  6159. clif_updatestatus(sd,SP_VIT);
  6160. clif_updatestatus(sd,SP_INT);
  6161. clif_updatestatus(sd,SP_DEX);
  6162. clif_updatestatus(sd,SP_LUK);
  6163. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  6164. clif_updatestatus(sd,SP_UAGI);
  6165. clif_updatestatus(sd,SP_UVIT);
  6166. clif_updatestatus(sd,SP_UINT);
  6167. clif_updatestatus(sd,SP_UDEX);
  6168. clif_updatestatus(sd,SP_ULUK); // End Addition
  6169. clif_updatestatus(sd,SP_STATUSPOINT);
  6170. if( sd->mission_mobid ) { //bugreport:2200
  6171. sd->mission_mobid = 0;
  6172. sd->mission_count = 0;
  6173. pc_setglobalreg(sd, add_str("TK_MISSION_ID"), 0);
  6174. }
  6175. status_calc_pc(sd, SCO_NONE);
  6176. return 1;
  6177. }
  6178. /*==========================================
  6179. * /resetskill
  6180. * if flag&1, perform block resync and status_calc call.
  6181. * if flag&2, just count total amount of skill points used by player, do not really reset.
  6182. * if flag&4, just reset the skills if the player class is a bard/dancer type (for changesex.)
  6183. *------------------------------------------*/
  6184. int pc_resetskill(struct map_session_data* sd, int flag)
  6185. {
  6186. int i, skill_point=0;
  6187. nullpo_ret(sd);
  6188. if( flag&4 && (sd->class_&MAPID_UPPERMASK) != MAPID_BARDDANCER )
  6189. return 0;
  6190. if( !(flag&2) ) { //Remove stuff lost when resetting skills.
  6191. /**
  6192. * It has been confirmed on official servers that when you reset skills with a ranked Taekwon your skills are not reset (because you have all of them anyway)
  6193. **/
  6194. if( pc_is_taekwon_ranker(sd) )
  6195. return 0;
  6196. if( pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd) )
  6197. clif_status_load(&sd->bl, SI_DEVIL, 0); //Remove perma blindness due to skill-reset. [Skotlex]
  6198. i = sd->sc.option;
  6199. if( i&OPTION_RIDING && pc_checkskill(sd, KN_RIDING) )
  6200. i &= ~OPTION_RIDING;
  6201. if( i&OPTION_FALCON && pc_checkskill(sd, HT_FALCON) )
  6202. i &= ~OPTION_FALCON;
  6203. if( i&OPTION_DRAGON && pc_checkskill(sd, RK_DRAGONTRAINING) )
  6204. i &= ~OPTION_DRAGON;
  6205. if( i&OPTION_WUG && pc_checkskill(sd, RA_WUGMASTERY) )
  6206. i &= ~OPTION_WUG;
  6207. if( i&OPTION_WUGRIDER && pc_checkskill(sd, RA_WUGRIDER) )
  6208. i &= ~OPTION_WUGRIDER;
  6209. if( i&OPTION_MADOGEAR && ( sd->class_&MAPID_THIRDMASK ) == MAPID_MECHANIC )
  6210. i &= ~OPTION_MADOGEAR;
  6211. #ifndef NEW_CARTS
  6212. if( i&OPTION_CART && pc_checkskill(sd, MC_PUSHCART) )
  6213. i &= ~OPTION_CART;
  6214. #else
  6215. if( sd->sc.data[SC_PUSH_CART] )
  6216. pc_setcart(sd, 0);
  6217. #endif
  6218. if( i != sd->sc.option )
  6219. pc_setoption(sd, i);
  6220. if( hom_is_active(sd->hd) && pc_checkskill(sd, AM_CALLHOMUN) )
  6221. hom_vaporize(sd, HOM_ST_ACTIVE);
  6222. }
  6223. for( i = 1; i < MAX_SKILL; i++ )
  6224. {
  6225. uint8 lv = sd->status.skill[i].lv;
  6226. int inf2;
  6227. uint16 skill_id = skill_idx2id(i);
  6228. if (lv == 0 || skill_id == 0)
  6229. continue;
  6230. inf2 = skill_get_inf2(skill_id);
  6231. if( inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL) ) //Avoid reseting wedding/linker skills.
  6232. continue;
  6233. // Don't reset trick dead if not a novice/baby
  6234. if( skill_id == NV_TRICKDEAD && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE )
  6235. {
  6236. sd->status.skill[i].lv = 0;
  6237. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  6238. continue;
  6239. }
  6240. // do not reset basic skill
  6241. if( skill_id == NV_BASIC && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE )
  6242. continue;
  6243. if( sd->status.skill[i].flag == SKILL_FLAG_PERM_GRANTED )
  6244. continue;
  6245. if( flag&4 && !skill_ischangesex(skill_id) )
  6246. continue;
  6247. if( inf2&INF2_QUEST_SKILL && !battle_config.quest_skill_learn )
  6248. { //Only handle quest skills in a special way when you can't learn them manually
  6249. if( battle_config.quest_skill_reset && !(flag&2) )
  6250. { //Wipe them
  6251. sd->status.skill[i].lv = 0;
  6252. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  6253. }
  6254. continue;
  6255. }
  6256. if( sd->status.skill[i].flag == SKILL_FLAG_PERMANENT )
  6257. skill_point += lv;
  6258. else
  6259. if( sd->status.skill[i].flag >= SKILL_FLAG_REPLACED_LV_0 )
  6260. skill_point += (sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0);
  6261. if( !(flag&2) )
  6262. {// reset
  6263. sd->status.skill[i].lv = 0;
  6264. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  6265. }
  6266. }
  6267. if( flag&2 || !skill_point ) return skill_point;
  6268. sd->status.skill_point += skill_point;
  6269. if (flag&1) {
  6270. clif_updatestatus(sd,SP_SKILLPOINT);
  6271. clif_skillinfoblock(sd);
  6272. status_calc_pc(sd, SCO_FORCE);
  6273. }
  6274. return skill_point;
  6275. }
  6276. /*==========================================
  6277. * /resetfeel [Komurka]
  6278. *------------------------------------------*/
  6279. int pc_resetfeel(struct map_session_data* sd)
  6280. {
  6281. int i;
  6282. nullpo_ret(sd);
  6283. for (i=0; i<MAX_PC_FEELHATE; i++)
  6284. {
  6285. sd->feel_map[i].m = -1;
  6286. sd->feel_map[i].index = 0;
  6287. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), 0);
  6288. }
  6289. return 0;
  6290. }
  6291. int pc_resethate(struct map_session_data* sd)
  6292. {
  6293. int i;
  6294. nullpo_ret(sd);
  6295. for (i=0; i<3; i++)
  6296. {
  6297. sd->hate_mob[i] = -1;
  6298. pc_setglobalreg(sd, add_str(sg_info[i].hate_var), 0);
  6299. }
  6300. return 0;
  6301. }
  6302. int pc_skillatk_bonus(struct map_session_data *sd, uint16 skill_id)
  6303. {
  6304. int i, bonus = 0;
  6305. nullpo_ret(sd);
  6306. skill_id = skill_dummy2skill_id(skill_id);
  6307. ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == skill_id);
  6308. if( i < ARRAYLENGTH(sd->skillatk) )
  6309. bonus = sd->skillatk[i].val;
  6310. return bonus;
  6311. }
  6312. int pc_sub_skillatk_bonus(struct map_session_data *sd, uint16 skill_id)
  6313. {
  6314. int i, bonus = 0;
  6315. nullpo_ret(sd);
  6316. skill_id = skill_dummy2skill_id(skill_id);
  6317. ARR_FIND(0, ARRAYLENGTH(sd->subskill), i, sd->subskill[i].id == skill_id);
  6318. if( i < ARRAYLENGTH(sd->subskill) )
  6319. bonus = sd->subskill[i].val;
  6320. return bonus;
  6321. }
  6322. int pc_skillheal_bonus(struct map_session_data *sd, uint16 skill_id) {
  6323. int i, bonus = sd->bonus.add_heal_rate;
  6324. skill_id = skill_dummy2skill_id(skill_id);
  6325. if( bonus ) {
  6326. switch( skill_id ) {
  6327. case AL_HEAL: if( !(battle_config.skill_add_heal_rate&1) ) bonus = 0; break;
  6328. case PR_SANCTUARY: if( !(battle_config.skill_add_heal_rate&2) ) bonus = 0; break;
  6329. case AM_POTIONPITCHER: if( !(battle_config.skill_add_heal_rate&4) ) bonus = 0; break;
  6330. case CR_SLIMPITCHER: if( !(battle_config.skill_add_heal_rate&8) ) bonus = 0; break;
  6331. case BA_APPLEIDUN: if( !(battle_config.skill_add_heal_rate&16)) bonus = 0; break;
  6332. }
  6333. }
  6334. ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == skill_id);
  6335. if( i < ARRAYLENGTH(sd->skillheal) )
  6336. bonus += sd->skillheal[i].val;
  6337. return bonus;
  6338. }
  6339. int pc_skillheal2_bonus(struct map_session_data *sd, uint16 skill_id) {
  6340. int i, bonus = sd->bonus.add_heal2_rate;
  6341. skill_id = skill_dummy2skill_id(skill_id);
  6342. ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == skill_id);
  6343. if( i < ARRAYLENGTH(sd->skillheal2) )
  6344. bonus += sd->skillheal2[i].val;
  6345. return bonus;
  6346. }
  6347. void pc_respawn(struct map_session_data* sd, clr_type clrtype)
  6348. {
  6349. if( !pc_isdead(sd) )
  6350. return; // not applicable
  6351. if( sd->bg_id && bg_member_respawn(sd) )
  6352. return; // member revived by battleground
  6353. pc_setstand(sd, true);
  6354. pc_setrestartvalue(sd,3);
  6355. if( pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype) )
  6356. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  6357. }
  6358. static int pc_respawn_timer(int tid, unsigned int tick, int id, intptr_t data)
  6359. {
  6360. struct map_session_data *sd = map_id2sd(id);
  6361. if( sd != NULL )
  6362. {
  6363. sd->pvp_point=0;
  6364. pc_respawn(sd,CLR_OUTSIGHT);
  6365. }
  6366. return 0;
  6367. }
  6368. /*==========================================
  6369. * Invoked when a player has received damage
  6370. *------------------------------------------*/
  6371. void pc_damage(struct map_session_data *sd,struct block_list *src,unsigned int hp, unsigned int sp)
  6372. {
  6373. if (sp) clif_updatestatus(sd,SP_SP);
  6374. if (hp) clif_updatestatus(sd,SP_HP);
  6375. else return;
  6376. if( !src || src == &sd->bl )
  6377. return;
  6378. if( pc_issit(sd) ) {
  6379. pc_setstand(sd, true);
  6380. skill_sit(sd,0);
  6381. }
  6382. if( sd->progressbar.npc_id )
  6383. clif_progressbar_abort(sd);
  6384. if( sd->status.pet_id > 0 && sd->pd && battle_config.pet_damage_support )
  6385. pet_target_check(sd->pd,src,1);
  6386. if( sd->status.ele_id > 0 )
  6387. elemental_set_target(sd,src);
  6388. sd->canlog_tick = gettick();
  6389. }
  6390. int pc_close_npc_timer(int tid, unsigned int tick, int id, intptr_t data)
  6391. {
  6392. TBL_PC *sd = map_id2sd(id);
  6393. if(sd) pc_close_npc(sd,data);
  6394. return 0;
  6395. }
  6396. /*
  6397. * Method to properly close npc for player and clear anything related
  6398. * @flag == 1 : produce close button
  6399. * @flag == 2 : directly close it
  6400. */
  6401. void pc_close_npc(struct map_session_data *sd,int flag)
  6402. {
  6403. nullpo_retv(sd);
  6404. if (sd->npc_id || sd->npc_shopid) {
  6405. if (sd->state.using_fake_npc) {
  6406. clif_clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd);
  6407. sd->state.using_fake_npc = 0;
  6408. }
  6409. if (sd->st) {
  6410. if(sd->st->state == RUN){ //wait ending code execution
  6411. add_timer(gettick()+500,pc_close_npc_timer,sd->bl.id,flag);
  6412. return;
  6413. }
  6414. sd->st->state = ((flag==1 && sd->st->mes_active)?CLOSE:END);
  6415. sd->st->mes_active = 0;
  6416. }
  6417. sd->state.menu_or_input = 0;
  6418. sd->npc_menu = 0;
  6419. sd->npc_shopid = 0;
  6420. #ifdef SECURE_NPCTIMEOUT
  6421. sd->npc_idle_timer = INVALID_TIMER;
  6422. #endif
  6423. clif_scriptclose(sd,sd->npc_id);
  6424. clif_scriptclear(sd,sd->npc_id); // [Ind/Hercules]
  6425. if(sd->st && sd->st->state == END ) {// free attached scripts that are waiting
  6426. script_free_state(sd->st);
  6427. sd->st = NULL;
  6428. sd->npc_id = 0;
  6429. }
  6430. }
  6431. }
  6432. /*==========================================
  6433. * Invoked when a player has negative current hp
  6434. *------------------------------------------*/
  6435. int pc_dead(struct map_session_data *sd,struct block_list *src)
  6436. {
  6437. int i=0,k=0;
  6438. unsigned int tick = gettick();
  6439. // Activate Steel body if a super novice dies at 99+% exp [celest]
  6440. // Super Novices have no kill or die functions attached when saved by their angel
  6441. if (!sd->state.snovice_dead_flag && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) {
  6442. unsigned int next = pc_nextbaseexp(sd);
  6443. if( next == 0 ) next = pc_thisbaseexp(sd);
  6444. if( get_percentage(sd->status.base_exp,next) >= 99 ) {
  6445. sd->state.snovice_dead_flag = 1;
  6446. pc_setrestartvalue(sd,1);
  6447. status_percent_heal(&sd->bl, 100, 100);
  6448. clif_resurrection(&sd->bl, 1);
  6449. if(battle_config.pc_invincible_time)
  6450. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  6451. sc_start(&sd->bl,&sd->bl,status_skill2sc(MO_STEELBODY),100,5,skill_get_time(MO_STEELBODY,5));
  6452. if(map_flag_gvg(sd->bl.m))
  6453. pc_respawn_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
  6454. return 0;
  6455. }
  6456. }
  6457. for(k = 0; k < MAX_DEVOTION; k++) {
  6458. if (sd->devotion[k]){
  6459. struct map_session_data *devsd = map_id2sd(sd->devotion[k]);
  6460. if (devsd)
  6461. status_change_end(&devsd->bl, SC_DEVOTION, INVALID_TIMER);
  6462. sd->devotion[k] = 0;
  6463. }
  6464. }
  6465. if(sd->shadowform_id) { //if we were target of shadowform
  6466. status_change_end(map_id2bl(sd->shadowform_id), SC__SHADOWFORM, INVALID_TIMER);
  6467. sd->shadowform_id = 0; //should be remove on status end anyway
  6468. }
  6469. if(sd->status.pet_id > 0 && sd->pd) {
  6470. struct pet_data *pd = sd->pd;
  6471. if( !map[sd->bl.m].flag.noexppenalty ) {
  6472. pet_set_intimate(pd, pd->pet.intimate - pd->petDB->die);
  6473. if( pd->pet.intimate < 0 )
  6474. pd->pet.intimate = 0;
  6475. clif_send_petdata(sd,sd->pd,1,pd->pet.intimate);
  6476. }
  6477. if( sd->pd->target_id ) // Unlock all targets...
  6478. pet_unlocktarget(sd->pd);
  6479. }
  6480. if (sd->status.hom_id > 0) {
  6481. if(battle_config.homunculus_auto_vapor && sd->hd)
  6482. hom_vaporize(sd, HOM_ST_ACTIVE);
  6483. }
  6484. if( sd->md )
  6485. mercenary_delete(sd->md, 3); // Your mercenary soldier has ran away.
  6486. if( sd->ed )
  6487. elemental_delete(sd->ed);
  6488. // Leave duel if you die [LuzZza]
  6489. if(battle_config.duel_autoleave_when_die) {
  6490. if(sd->duel_group > 0)
  6491. duel_leave(sd->duel_group, sd);
  6492. if(sd->duel_invite > 0)
  6493. duel_reject(sd->duel_invite, sd);
  6494. }
  6495. pc_close_npc(sd,2); //close npc if we were using one
  6496. /* e.g. not killed thru pc_damage */
  6497. if( pc_issit(sd) ) {
  6498. clif_status_load(&sd->bl,SI_SIT,0);
  6499. }
  6500. pc_setdead(sd);
  6501. pc_setglobalreg(sd, add_str("PC_DIE_COUNTER"), sd->die_counter+1);
  6502. pc_setparam(sd, SP_KILLERRID, src?src->id:0);
  6503. //Reset menu skills/item skills
  6504. if ((sd->skillitem) != 0)
  6505. sd->skillitem = sd->skillitemlv = 0;
  6506. if ((sd->menuskill_id) != 0)
  6507. sd->menuskill_id = sd->menuskill_val = 0;
  6508. //Reset ticks.
  6509. sd->hp_loss.tick = sd->sp_loss.tick = sd->hp_regen.tick = sd->sp_regen.tick = 0;
  6510. if ( sd->spiritball !=0 )
  6511. pc_delspiritball(sd,sd->spiritball,0);
  6512. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  6513. pc_delspiritcharm(sd,sd->spiritcharm,sd->spiritcharm_type);
  6514. if (src)
  6515. switch (src->type) {
  6516. case BL_MOB:
  6517. {
  6518. struct mob_data *md=(struct mob_data *)src;
  6519. if(md->target_id==sd->bl.id)
  6520. mob_unlocktarget(md,tick);
  6521. if(battle_config.mobs_level_up && md->status.hp &&
  6522. (unsigned int)md->level < pc_maxbaselv(sd) &&
  6523. !md->guardian_data && !md->special_state.ai// Guardians/summons should not level. [Skotlex]
  6524. ) { // monster level up [Valaris]
  6525. clif_misceffect(&md->bl,0);
  6526. md->level++;
  6527. status_calc_mob(md, SCO_NONE);
  6528. status_percent_heal(src,10,0);
  6529. if( battle_config.show_mob_info&4 )
  6530. {// update name with new level
  6531. clif_charnameack(0, &md->bl);
  6532. }
  6533. }
  6534. src = battle_get_master(src); // Maybe Player Summon
  6535. }
  6536. break;
  6537. case BL_PET: //Pass on to master...
  6538. case BL_HOM:
  6539. case BL_MER:
  6540. src = battle_get_master(src);
  6541. break;
  6542. }
  6543. if (src && src->type == BL_PC) {
  6544. struct map_session_data *ssd = (struct map_session_data *)src;
  6545. pc_setparam(ssd, SP_KILLEDRID, sd->bl.id);
  6546. npc_script_event(ssd, NPCE_KILLPC);
  6547. if (battle_config.pk_mode&2) {
  6548. ssd->status.manner -= 5;
  6549. if(ssd->status.manner < 0)
  6550. sc_start(&sd->bl,src,SC_NOCHAT,100,0,0);
  6551. #if 0
  6552. // PK/Karma system code (not enabled yet) [celest]
  6553. // originally from Kade Online, so i don't know if any of these is correct ^^;
  6554. // note: karma is measured REVERSE, so more karma = more 'evil' / less honourable,
  6555. // karma going down = more 'good' / more honourable.
  6556. // The Karma System way...
  6557. if (sd->status.karma > ssd->status.karma) { // If player killed was more evil
  6558. sd->status.karma--;
  6559. ssd->status.karma--;
  6560. }
  6561. else if (sd->status.karma < ssd->status.karma) // If player killed was more good
  6562. ssd->status.karma++;
  6563. // or the PK System way...
  6564. if (sd->status.karma > 0) // player killed is dishonourable?
  6565. ssd->status.karma--; // honour points earned
  6566. sd->status.karma++; // honour points lost
  6567. // To-do: Receive exp on certain occasions
  6568. #endif
  6569. }
  6570. }
  6571. if(battle_config.bone_drop==2
  6572. || (battle_config.bone_drop==1 && map[sd->bl.m].flag.pvp))
  6573. {
  6574. struct item item_tmp;
  6575. memset(&item_tmp,0,sizeof(item_tmp));
  6576. item_tmp.nameid=ITEMID_SKULL_;
  6577. item_tmp.identify=1;
  6578. item_tmp.card[0]=CARD0_CREATE;
  6579. item_tmp.card[1]=0;
  6580. item_tmp.card[2]=GetWord(sd->status.char_id,0); // CharId
  6581. item_tmp.card[3]=GetWord(sd->status.char_id,1);
  6582. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0,0);
  6583. }
  6584. //Remove bonus_script when dead
  6585. pc_bonus_script_clear(sd,BSF_REM_ON_DEAD);
  6586. // changed penalty options, added death by player if pk_mode [Valaris]
  6587. if(battle_config.death_penalty_type
  6588. && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE // only novices will receive no penalty
  6589. && !map[sd->bl.m].flag.noexppenalty && !map_flag_gvg(sd->bl.m)
  6590. && !sd->sc.data[SC_BABY] && !sd->sc.data[SC_LIFEINSURANCE])
  6591. {
  6592. uint32 base_penalty = battle_config.death_penalty_base;
  6593. uint32 job_penalty = battle_config.death_penalty_job;
  6594. uint32 zeny_penalty = battle_config.zeny_penalty;
  6595. #ifdef VIP_ENABLE
  6596. if(pc_isvip(sd)){
  6597. base_penalty *= battle_config.vip_exp_penalty_base;
  6598. job_penalty *= battle_config.vip_exp_penalty_job;
  6599. }
  6600. else {
  6601. base_penalty *= battle_config.vip_exp_penalty_base_normal;
  6602. job_penalty *= battle_config.vip_exp_penalty_job_normal;
  6603. }
  6604. #endif
  6605. if (base_penalty > 0) {
  6606. switch (battle_config.death_penalty_type) {
  6607. case 1: base_penalty = (uint32) ( pc_nextbaseexp(sd) * ( base_penalty / 10000. ) ); break;
  6608. case 2: base_penalty = (uint32) ( sd->status.base_exp * ( base_penalty / 10000. ) ); break;
  6609. }
  6610. if (base_penalty > 0){ //recheck after altering to speedup
  6611. if (battle_config.pk_mode && src && src->type==BL_PC)
  6612. base_penalty*=2;
  6613. sd->status.base_exp -= u32min(sd->status.base_exp, base_penalty);
  6614. clif_updatestatus(sd,SP_BASEEXP);
  6615. }
  6616. }
  6617. if(job_penalty > 0) {
  6618. switch (battle_config.death_penalty_type) {
  6619. case 1: job_penalty = (uint32) ( pc_nextjobexp(sd) * ( job_penalty / 10000. ) ); break;
  6620. case 2: job_penalty = (uint32) ( sd->status.job_exp * ( job_penalty /10000. ) ); break;
  6621. }
  6622. if(job_penalty) {
  6623. if (battle_config.pk_mode && src && src->type==BL_PC)
  6624. job_penalty*=2;
  6625. sd->status.job_exp -= u32min(sd->status.job_exp, job_penalty);
  6626. clif_updatestatus(sd,SP_JOBEXP);
  6627. }
  6628. }
  6629. if( zeny_penalty > 0 && !map[sd->bl.m].flag.nozenypenalty) {
  6630. zeny_penalty = (uint32)( sd->status.zeny * ( zeny_penalty / 10000. ) );
  6631. if(zeny_penalty)
  6632. pc_payzeny(sd, zeny_penalty, LOG_TYPE_PICKDROP_PLAYER, NULL);
  6633. }
  6634. }
  6635. if(map[sd->bl.m].flag.pvp_nightmaredrop) { // Moved this outside so it works when PVP isn't enabled and during pk mode [Ancyker]
  6636. int j;
  6637. for(j=0;j<MAX_DROP_PER_MAP;j++){
  6638. int id = map[sd->bl.m].drop_list[j].drop_id;
  6639. int type = map[sd->bl.m].drop_list[j].drop_type;
  6640. int per = map[sd->bl.m].drop_list[j].drop_per;
  6641. if(id == 0)
  6642. continue;
  6643. if(id == -1){
  6644. int eq_num=0,eq_n[MAX_INVENTORY];
  6645. memset(eq_n,0,sizeof(eq_n));
  6646. for(i=0;i<MAX_INVENTORY;i++) {
  6647. if( (type == 1 && !sd->status.inventory[i].equip)
  6648. || (type == 2 && sd->status.inventory[i].equip)
  6649. || type == 3)
  6650. {
  6651. int l;
  6652. ARR_FIND( 0, MAX_INVENTORY, l, eq_n[l] <= 0 );
  6653. if( l < MAX_INVENTORY )
  6654. eq_n[l] = i;
  6655. eq_num++;
  6656. }
  6657. }
  6658. if(eq_num > 0){
  6659. int n = eq_n[rnd()%eq_num];
  6660. if(rnd()%10000 < per) {
  6661. if(sd->status.inventory[n].equip)
  6662. pc_unequipitem(sd,n,3);
  6663. pc_dropitem(sd,n,1);
  6664. }
  6665. }
  6666. }
  6667. else if(id > 0) {
  6668. for(i=0;i<MAX_INVENTORY;i++){
  6669. if(sd->status.inventory[i].nameid == id
  6670. && rnd()%10000 < per
  6671. && ((type == 1 && !sd->status.inventory[i].equip)
  6672. || (type == 2 && sd->status.inventory[i].equip)
  6673. || type == 3) ){
  6674. if(sd->status.inventory[i].equip)
  6675. pc_unequipitem(sd,i,3);
  6676. pc_dropitem(sd,i,1);
  6677. break;
  6678. }
  6679. }
  6680. }
  6681. }
  6682. }
  6683. // pvp
  6684. // disable certain pvp functions on pk_mode [Valaris]
  6685. if( map[sd->bl.m].flag.pvp && !battle_config.pk_mode && !map[sd->bl.m].flag.pvp_nocalcrank ) {
  6686. sd->pvp_point -= 5;
  6687. sd->pvp_lost++;
  6688. if( src && src->type == BL_PC ) {
  6689. struct map_session_data *ssd = (struct map_session_data *)src;
  6690. ssd->pvp_point++;
  6691. ssd->pvp_won++;
  6692. }
  6693. if( sd->pvp_point < 0 ) {
  6694. add_timer(tick+1000, pc_respawn_timer,sd->bl.id,0);
  6695. return 1|8;
  6696. }
  6697. }
  6698. //GvG
  6699. if( map_flag_gvg(sd->bl.m) ) {
  6700. add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
  6701. return 1|8;
  6702. }
  6703. else if( sd->bg_id ) {
  6704. struct battleground_data *bg = bg_team_search(sd->bg_id);
  6705. if( bg && bg->mapindex > 0 ) { // Respawn by BG
  6706. add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
  6707. return 1|8;
  6708. }
  6709. }
  6710. //Reset "can log out" tick.
  6711. if( battle_config.prevent_logout )
  6712. sd->canlog_tick = gettick() - battle_config.prevent_logout;
  6713. return 1;
  6714. }
  6715. void pc_revive(struct map_session_data *sd,unsigned int hp, unsigned int sp) {
  6716. if(hp) clif_updatestatus(sd,SP_HP);
  6717. if(sp) clif_updatestatus(sd,SP_SP);
  6718. pc_setstand(sd, true);
  6719. if(battle_config.pc_invincible_time > 0)
  6720. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  6721. if( sd->state.gmaster_flag ) {
  6722. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  6723. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  6724. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  6725. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  6726. }
  6727. }
  6728. // script
  6729. //
  6730. /*==========================================
  6731. * script reading pc status registry
  6732. *------------------------------------------*/
  6733. int pc_readparam(struct map_session_data* sd,int type)
  6734. {
  6735. int val = 0;
  6736. nullpo_ret(sd);
  6737. switch(type) {
  6738. case SP_SKILLPOINT: val = sd->status.skill_point; break;
  6739. case SP_STATUSPOINT: val = sd->status.status_point; break;
  6740. case SP_ZENY: val = sd->status.zeny; break;
  6741. case SP_BASELEVEL: val = sd->status.base_level; break;
  6742. case SP_JOBLEVEL: val = sd->status.job_level; break;
  6743. case SP_CLASS: val = sd->status.class_; break;
  6744. case SP_BASEJOB: val = pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex); break; //Base job, extracting upper type.
  6745. case SP_UPPER: val = sd->class_&JOBL_UPPER?1:(sd->class_&JOBL_BABY?2:0); break;
  6746. case SP_BASECLASS: val = pc_mapid2jobid(sd->class_&MAPID_BASEMASK, sd->status.sex); break; //Extract base class tree. [Skotlex]
  6747. case SP_SEX: val = sd->status.sex; break;
  6748. case SP_WEIGHT: val = sd->weight; break;
  6749. case SP_MAXWEIGHT: val = sd->max_weight; break;
  6750. case SP_BASEEXP: val = sd->status.base_exp; break;
  6751. case SP_JOBEXP: val = sd->status.job_exp; break;
  6752. case SP_NEXTBASEEXP: val = pc_nextbaseexp(sd); break;
  6753. case SP_NEXTJOBEXP: val = pc_nextjobexp(sd); break;
  6754. case SP_HP: val = sd->battle_status.hp; break;
  6755. case SP_MAXHP: val = sd->battle_status.max_hp; break;
  6756. case SP_SP: val = sd->battle_status.sp; break;
  6757. case SP_MAXSP: val = sd->battle_status.max_sp; break;
  6758. case SP_STR: val = sd->status.str; break;
  6759. case SP_AGI: val = sd->status.agi; break;
  6760. case SP_VIT: val = sd->status.vit; break;
  6761. case SP_INT: val = sd->status.int_; break;
  6762. case SP_DEX: val = sd->status.dex; break;
  6763. case SP_LUK: val = sd->status.luk; break;
  6764. case SP_KARMA: val = sd->status.karma; break;
  6765. case SP_MANNER: val = sd->status.manner; break;
  6766. case SP_FAME: val = sd->status.fame; break;
  6767. case SP_KILLERRID: val = sd->killerrid; break;
  6768. case SP_KILLEDRID: val = sd->killedrid; break;
  6769. case SP_SITTING: val = pc_issit(sd)?1:0; break;
  6770. case SP_CHARMOVE: val = sd->status.character_moves; break;
  6771. case SP_CHARRENAME: val = sd->status.rename; break;
  6772. case SP_CHARFONT: val = sd->status.font; break;
  6773. case SP_BANK_VAULT: val = sd->bank_vault; break;
  6774. case SP_ROULETTE_BRONZE: val = sd->roulette_point.bronze; break;
  6775. case SP_ROULETTE_SILVER: val = sd->roulette_point.silver; break;
  6776. case SP_ROULETTE_GOLD: val = sd->roulette_point.gold; break;
  6777. case SP_CRITICAL: val = sd->battle_status.cri/10; break;
  6778. case SP_ASPD: val = (2000-sd->battle_status.amotion)/10; break;
  6779. case SP_BASE_ATK: val = sd->battle_status.batk; break;
  6780. case SP_DEF1: val = sd->battle_status.def; break;
  6781. case SP_DEF2: val = sd->battle_status.def2; break;
  6782. case SP_MDEF1: val = sd->battle_status.mdef; break;
  6783. case SP_MDEF2: val = sd->battle_status.mdef2; break;
  6784. case SP_HIT: val = sd->battle_status.hit; break;
  6785. case SP_FLEE1: val = sd->battle_status.flee; break;
  6786. case SP_FLEE2: val = sd->battle_status.flee2; break;
  6787. case SP_DEFELE: val = sd->battle_status.def_ele; break;
  6788. case SP_MAXHPRATE: val = sd->hprate; break;
  6789. case SP_MAXSPRATE: val = sd->sprate; break;
  6790. case SP_SPRATE: val = sd->dsprate; break;
  6791. case SP_SPEED_RATE: val = sd->bonus.speed_rate; break;
  6792. case SP_SPEED_ADDRATE: val = sd->bonus.speed_add_rate; break;
  6793. case SP_ASPD_RATE:
  6794. #ifndef RENEWAL_ASPD
  6795. val = sd->battle_status.aspd_rate;
  6796. #else
  6797. val = sd->battle_status.aspd_rate2;
  6798. #endif
  6799. break;
  6800. case SP_HP_RECOV_RATE: val = sd->hprecov_rate; break;
  6801. case SP_SP_RECOV_RATE: val = sd->sprecov_rate; break;
  6802. case SP_CRITICAL_DEF: val = sd->bonus.critical_def; break;
  6803. case SP_NEAR_ATK_DEF: val = sd->bonus.near_attack_def_rate; break;
  6804. case SP_LONG_ATK_DEF: val = sd->bonus.long_attack_def_rate; break;
  6805. case SP_DOUBLE_RATE: val = sd->bonus.double_rate; break;
  6806. case SP_DOUBLE_ADD_RATE: val = sd->bonus.double_add_rate; break;
  6807. case SP_MATK_RATE: val = sd->matk_rate; break;
  6808. case SP_ATK_RATE: val = sd->bonus.atk_rate; break;
  6809. case SP_MAGIC_ATK_DEF: val = sd->bonus.magic_def_rate; break;
  6810. case SP_MISC_ATK_DEF: val = sd->bonus.misc_def_rate; break;
  6811. case SP_PERFECT_HIT_RATE:val = sd->bonus.perfect_hit; break;
  6812. case SP_PERFECT_HIT_ADD_RATE: val = sd->bonus.perfect_hit_add; break;
  6813. case SP_CRITICAL_RATE: val = sd->critical_rate; break;
  6814. case SP_HIT_RATE: val = sd->hit_rate; break;
  6815. case SP_FLEE_RATE: val = sd->flee_rate; break;
  6816. case SP_FLEE2_RATE: val = sd->flee2_rate; break;
  6817. case SP_DEF_RATE: val = sd->def_rate; break;
  6818. case SP_DEF2_RATE: val = sd->def2_rate; break;
  6819. case SP_MDEF_RATE: val = sd->mdef_rate; break;
  6820. case SP_MDEF2_RATE: val = sd->mdef2_rate; break;
  6821. case SP_RESTART_FULL_RECOVER: val = sd->special_state.restart_full_recover?1:0; break;
  6822. case SP_NO_CASTCANCEL: val = sd->special_state.no_castcancel?1:0; break;
  6823. case SP_NO_CASTCANCEL2: val = sd->special_state.no_castcancel2?1:0; break;
  6824. case SP_NO_SIZEFIX: val = sd->special_state.no_sizefix?1:0; break;
  6825. case SP_NO_MAGIC_DAMAGE: val = sd->special_state.no_magic_damage; break;
  6826. case SP_NO_WEAPON_DAMAGE:val = sd->special_state.no_weapon_damage; break;
  6827. case SP_NO_MISC_DAMAGE: val = sd->special_state.no_misc_damage; break;
  6828. case SP_NO_GEMSTONE: val = sd->special_state.no_gemstone?1:0; break;
  6829. case SP_INTRAVISION: val = sd->special_state.intravision?1:0; break;
  6830. case SP_NO_KNOCKBACK: val = sd->special_state.no_knockback?1:0; break;
  6831. case SP_SPLASH_RANGE: val = sd->bonus.splash_range; break;
  6832. case SP_SPLASH_ADD_RANGE:val = sd->bonus.splash_add_range; break;
  6833. case SP_SHORT_WEAPON_DAMAGE_RETURN: val = sd->bonus.short_weapon_damage_return; break;
  6834. case SP_LONG_WEAPON_DAMAGE_RETURN: val = sd->bonus.long_weapon_damage_return; break;
  6835. case SP_MAGIC_DAMAGE_RETURN: val = sd->bonus.magic_damage_return; break;
  6836. case SP_PERFECT_HIDE: val = sd->special_state.perfect_hiding?1:0; break;
  6837. case SP_UNBREAKABLE: val = sd->bonus.unbreakable; break;
  6838. case SP_UNBREAKABLE_WEAPON: val = (sd->bonus.unbreakable_equip&EQP_WEAPON)?1:0; break;
  6839. case SP_UNBREAKABLE_ARMOR: val = (sd->bonus.unbreakable_equip&EQP_ARMOR)?1:0; break;
  6840. case SP_UNBREAKABLE_HELM: val = (sd->bonus.unbreakable_equip&EQP_HELM)?1:0; break;
  6841. case SP_UNBREAKABLE_SHIELD: val = (sd->bonus.unbreakable_equip&EQP_SHIELD)?1:0; break;
  6842. case SP_UNBREAKABLE_GARMENT: val = (sd->bonus.unbreakable_equip&EQP_GARMENT)?1:0; break;
  6843. case SP_UNBREAKABLE_SHOES: val = (sd->bonus.unbreakable_equip&EQP_SHOES)?1:0; break;
  6844. case SP_CLASSCHANGE: val = sd->bonus.classchange; break;
  6845. case SP_LONG_ATK_RATE: val = sd->bonus.long_attack_atk_rate; break;
  6846. case SP_BREAK_WEAPON_RATE: val = sd->bonus.break_weapon_rate; break;
  6847. case SP_BREAK_ARMOR_RATE: val = sd->bonus.break_armor_rate; break;
  6848. case SP_ADD_STEAL_RATE: val = sd->bonus.add_steal_rate; break;
  6849. case SP_DELAYRATE: val = sd->delayrate; break;
  6850. case SP_CRIT_ATK_RATE: val = sd->bonus.crit_atk_rate; break;
  6851. case SP_UNSTRIPABLE_WEAPON: val = (sd->bonus.unstripable_equip&EQP_WEAPON)?1:0; break;
  6852. case SP_UNSTRIPABLE:
  6853. case SP_UNSTRIPABLE_ARMOR:
  6854. val = (sd->bonus.unstripable_equip&EQP_ARMOR)?1:0;
  6855. break;
  6856. case SP_UNSTRIPABLE_HELM: val = (sd->bonus.unstripable_equip&EQP_HELM)?1:0; break;
  6857. case SP_UNSTRIPABLE_SHIELD: val = (sd->bonus.unstripable_equip&EQP_SHIELD)?1:0; break;
  6858. case SP_SP_GAIN_VALUE: val = sd->bonus.sp_gain_value; break;
  6859. case SP_HP_GAIN_VALUE: val = sd->bonus.hp_gain_value; break;
  6860. case SP_MAGIC_SP_GAIN_VALUE: val = sd->bonus.magic_sp_gain_value; break;
  6861. case SP_MAGIC_HP_GAIN_VALUE: val = sd->bonus.magic_hp_gain_value; break;
  6862. case SP_ADD_HEAL_RATE: val = sd->bonus.add_heal_rate; break;
  6863. case SP_ADD_HEAL2_RATE: val = sd->bonus.add_heal2_rate; break;
  6864. case SP_ADD_ITEM_HEAL_RATE: val = sd->bonus.itemhealrate2; break;
  6865. case SP_EMATK: val = sd->bonus.ematk; break;
  6866. case SP_FIXCASTRATE: val = sd->bonus.fixcastrate; break;
  6867. case SP_ADD_FIXEDCAST: val = sd->bonus.add_fixcast; break;
  6868. case SP_ADD_VARIABLECAST: val = sd->bonus.add_varcast; break;
  6869. case SP_CASTRATE:
  6870. case SP_VARCASTRATE:
  6871. #ifdef RENEWAL_CAST
  6872. val = sd->bonus.varcastrate; break;
  6873. #else
  6874. val = sd->castrate; break;
  6875. #endif
  6876. default:
  6877. ShowError("pc_readparam: Attempt to read unknown parameter '%d'.\n", type);
  6878. return -1;
  6879. }
  6880. return val;
  6881. }
  6882. /*==========================================
  6883. * script set pc status registry
  6884. *------------------------------------------*/
  6885. bool pc_setparam(struct map_session_data *sd,int type,int val)
  6886. {
  6887. nullpo_retr(false,sd);
  6888. switch(type){
  6889. case SP_BASELEVEL:
  6890. if ((unsigned int)val > pc_maxbaselv(sd)) //Capping to max
  6891. val = pc_maxbaselv(sd);
  6892. if ((unsigned int)val > sd->status.base_level) {
  6893. int i = 0;
  6894. int stat=0;
  6895. for (i = 0; i < (int)((unsigned int)val - sd->status.base_level); i++)
  6896. stat += pc_gets_status_point(sd->status.base_level + i);
  6897. sd->status.status_point += stat;
  6898. }
  6899. sd->status.base_level = (unsigned int)val;
  6900. sd->status.base_exp = 0;
  6901. // clif_updatestatus(sd, SP_BASELEVEL); // Gets updated at the bottom
  6902. clif_updatestatus(sd, SP_NEXTBASEEXP);
  6903. clif_updatestatus(sd, SP_STATUSPOINT);
  6904. clif_updatestatus(sd, SP_BASEEXP);
  6905. status_calc_pc(sd, SCO_FORCE);
  6906. if(sd->status.party_id)
  6907. party_send_levelup(sd);
  6908. break;
  6909. case SP_JOBLEVEL:
  6910. if ((unsigned int)val >= sd->status.job_level) {
  6911. if ((unsigned int)val > pc_maxjoblv(sd)) val = pc_maxjoblv(sd);
  6912. sd->status.skill_point += val - sd->status.job_level;
  6913. clif_updatestatus(sd, SP_SKILLPOINT);
  6914. }
  6915. sd->status.job_level = (unsigned int)val;
  6916. sd->status.job_exp = 0;
  6917. // clif_updatestatus(sd, SP_JOBLEVEL); // Gets updated at the bottom
  6918. clif_updatestatus(sd, SP_NEXTJOBEXP);
  6919. clif_updatestatus(sd, SP_JOBEXP);
  6920. status_calc_pc(sd, SCO_FORCE);
  6921. break;
  6922. case SP_SKILLPOINT:
  6923. sd->status.skill_point = val;
  6924. break;
  6925. case SP_STATUSPOINT:
  6926. sd->status.status_point = val;
  6927. break;
  6928. case SP_ZENY:
  6929. if( val < 0 )
  6930. return false;// can't set negative zeny
  6931. log_zeny(sd, LOG_TYPE_SCRIPT, sd, -(sd->status.zeny - cap_value(val, 0, MAX_ZENY)));
  6932. sd->status.zeny = cap_value(val, 0, MAX_ZENY);
  6933. break;
  6934. case SP_BASEEXP:
  6935. if(pc_nextbaseexp(sd) > 0) {
  6936. sd->status.base_exp = val;
  6937. pc_checkbaselevelup(sd);
  6938. }
  6939. break;
  6940. case SP_JOBEXP:
  6941. if(pc_nextjobexp(sd) > 0) {
  6942. sd->status.job_exp = val;
  6943. pc_checkjoblevelup(sd);
  6944. }
  6945. break;
  6946. case SP_SEX:
  6947. sd->status.sex = val ? SEX_MALE : SEX_FEMALE;
  6948. break;
  6949. case SP_WEIGHT:
  6950. sd->weight = val;
  6951. break;
  6952. case SP_MAXWEIGHT:
  6953. sd->max_weight = val;
  6954. break;
  6955. case SP_HP:
  6956. sd->battle_status.hp = cap_value(val, 1, (int)sd->battle_status.max_hp);
  6957. break;
  6958. case SP_MAXHP:
  6959. sd->battle_status.max_hp = cap_value(val, 1, battle_config.max_hp);
  6960. if( sd->battle_status.max_hp < sd->battle_status.hp )
  6961. {
  6962. sd->battle_status.hp = sd->battle_status.max_hp;
  6963. clif_updatestatus(sd, SP_HP);
  6964. }
  6965. break;
  6966. case SP_SP:
  6967. sd->battle_status.sp = cap_value(val, 0, (int)sd->battle_status.max_sp);
  6968. break;
  6969. case SP_MAXSP:
  6970. sd->battle_status.max_sp = cap_value(val, 1, battle_config.max_sp);
  6971. if( sd->battle_status.max_sp < sd->battle_status.sp )
  6972. {
  6973. sd->battle_status.sp = sd->battle_status.max_sp;
  6974. clif_updatestatus(sd, SP_SP);
  6975. }
  6976. break;
  6977. case SP_STR:
  6978. sd->status.str = cap_value(val, 1, pc_maxparameter(sd,PARAM_STR));
  6979. break;
  6980. case SP_AGI:
  6981. sd->status.agi = cap_value(val, 1, pc_maxparameter(sd,PARAM_AGI));
  6982. break;
  6983. case SP_VIT:
  6984. sd->status.vit = cap_value(val, 1, pc_maxparameter(sd,PARAM_VIT));
  6985. break;
  6986. case SP_INT:
  6987. sd->status.int_ = cap_value(val, 1, pc_maxparameter(sd,PARAM_INT));
  6988. break;
  6989. case SP_DEX:
  6990. sd->status.dex = cap_value(val, 1, pc_maxparameter(sd,PARAM_DEX));
  6991. break;
  6992. case SP_LUK:
  6993. sd->status.luk = cap_value(val, 1, pc_maxparameter(sd,PARAM_LUK));
  6994. break;
  6995. case SP_KARMA:
  6996. sd->status.karma = val;
  6997. break;
  6998. case SP_MANNER:
  6999. sd->status.manner = val;
  7000. if( val < 0 )
  7001. sc_start(NULL, &sd->bl, SC_NOCHAT, 100, 0, 0);
  7002. else {
  7003. status_change_end(&sd->bl, SC_NOCHAT, INVALID_TIMER);
  7004. clif_manner_message(sd, 5);
  7005. }
  7006. return true; // status_change_start/status_change_end already sends packets warning the client
  7007. case SP_FAME:
  7008. sd->status.fame = val;
  7009. break;
  7010. case SP_KILLERRID:
  7011. sd->killerrid = val;
  7012. return true;
  7013. case SP_KILLEDRID:
  7014. sd->killedrid = val;
  7015. return true;
  7016. case SP_CHARMOVE:
  7017. sd->status.character_moves = val;
  7018. return true;
  7019. case SP_CHARRENAME:
  7020. sd->status.rename = val;
  7021. return true;
  7022. case SP_CHARFONT:
  7023. sd->status.font = val;
  7024. clif_font(sd);
  7025. return true;
  7026. case SP_BANK_VAULT:
  7027. if (val < 0)
  7028. return false;
  7029. log_zeny(sd, LOG_TYPE_BANK, sd, -(sd->bank_vault - cap_value(val, 0, MAX_BANK_ZENY)));
  7030. sd->bank_vault = cap_value(val, 0, MAX_BANK_ZENY);
  7031. pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
  7032. return true;
  7033. case SP_ROULETTE_BRONZE:
  7034. sd->roulette_point.bronze = val;
  7035. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  7036. return true;
  7037. case SP_ROULETTE_SILVER:
  7038. sd->roulette_point.silver = val;
  7039. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  7040. return true;
  7041. case SP_ROULETTE_GOLD:
  7042. sd->roulette_point.gold = val;
  7043. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  7044. return true;
  7045. default:
  7046. ShowError("pc_setparam: Attempted to set unknown parameter '%d'.\n", type);
  7047. return false;
  7048. }
  7049. clif_updatestatus(sd,type);
  7050. return true;
  7051. }
  7052. /*==========================================
  7053. * HP/SP Healing. If flag is passed, the heal type is through clif_heal, otherwise update status.
  7054. *------------------------------------------*/
  7055. void pc_heal(struct map_session_data *sd,unsigned int hp,unsigned int sp, int type)
  7056. {
  7057. if (type) {
  7058. if (hp)
  7059. clif_heal(sd->fd,SP_HP,hp);
  7060. if (sp)
  7061. clif_heal(sd->fd,SP_SP,sp);
  7062. } else {
  7063. if(hp)
  7064. clif_updatestatus(sd,SP_HP);
  7065. if(sp)
  7066. clif_updatestatus(sd,SP_SP);
  7067. }
  7068. return;
  7069. }
  7070. /*==========================================
  7071. * HP/SP Recovery
  7072. * Heal player hp and/or sp linearly.
  7073. * Calculate bonus by status.
  7074. *------------------------------------------*/
  7075. int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
  7076. {
  7077. int bonus, tmp, penalty = 0;
  7078. if(hp) {
  7079. int i;
  7080. bonus = 100 + (sd->battle_status.vit<<1)
  7081. + pc_checkskill(sd,SM_RECOVERY)*10
  7082. + pc_checkskill(sd,AM_LEARNINGPOTION)*5;
  7083. // A potion produced by an Alchemist in the Fame Top 10 gets +50% effect [DracoRPG]
  7084. if (potion_flag > 1)
  7085. bonus += bonus*(potion_flag-1)*50/100;
  7086. //All item bonuses.
  7087. bonus += sd->bonus.itemhealrate2;
  7088. //Item Group bonuses
  7089. bonus += bonus*pc_get_itemgroup_bonus(sd, itemid)/100;
  7090. //Individual item bonuses.
  7091. for(i = 0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid; i++)
  7092. {
  7093. if (sd->itemhealrate[i].nameid == itemid) {
  7094. bonus += bonus*sd->itemhealrate[i].rate/100;
  7095. break;
  7096. }
  7097. }
  7098. tmp = hp * bonus / 100; // overflow check
  7099. if(bonus != 100 && tmp > hp)
  7100. hp = tmp;
  7101. // Recovery Potion
  7102. if( sd->sc.data[SC_INCHEALRATE] )
  7103. hp += (int)(hp * sd->sc.data[SC_INCHEALRATE]->val1/100.);
  7104. // 2014 Halloween Event : Pumpkin Bonus
  7105. if(sd->sc.data[SC_MTF_PUMPKIN] && itemid == ITEMID_PUMPKIN)
  7106. hp += (int)(hp * sd->sc.data[SC_MTF_PUMPKIN]->val1 / 100.);
  7107. }
  7108. if(sp) {
  7109. bonus = 100 + (sd->battle_status.int_<<1)
  7110. + pc_checkskill(sd,MG_SRECOVERY)*10
  7111. + pc_checkskill(sd,AM_LEARNINGPOTION)*5;
  7112. if (potion_flag > 1)
  7113. bonus += bonus*(potion_flag-1)*50/100;
  7114. tmp = sp * bonus / 100;
  7115. if(bonus != 100 && tmp > sp)
  7116. sp = tmp;
  7117. }
  7118. if (sd->sc.count) {
  7119. // Critical Wound and Death Hurt stack
  7120. if (sd->sc.data[SC_CRITICALWOUND])
  7121. penalty += sd->sc.data[SC_CRITICALWOUND]->val2;
  7122. if (sd->sc.data[SC_DEATHHURT])
  7123. penalty += 20;
  7124. if (sd->sc.data[SC_NORECOVER_STATE])
  7125. penalty = 100;
  7126. if (penalty > 0) {
  7127. hp -= hp * penalty / 100;
  7128. sp -= sp * penalty / 100;
  7129. }
  7130. if (sd->sc.data[SC_VITALITYACTIVATION]) {
  7131. hp += hp / 2; // 1.5 times
  7132. sp -= sp / 2;
  7133. }
  7134. if (sd->sc.data[SC_WATER_INSIGNIA] && sd->sc.data[SC_WATER_INSIGNIA]->val1 == 2) {
  7135. hp += hp / 10;
  7136. sp += sp / 10;
  7137. }
  7138. #ifdef RENEWAL
  7139. if (sd->sc.data[SC_EXTREMITYFIST2])
  7140. sp = 0;
  7141. #endif
  7142. }
  7143. return status_heal(&sd->bl, hp, sp, 1);
  7144. }
  7145. /*==========================================
  7146. * HP/SP Recovery
  7147. * Heal player hp nad/or sp by rate
  7148. *------------------------------------------*/
  7149. int pc_percentheal(struct map_session_data *sd,int hp,int sp)
  7150. {
  7151. nullpo_ret(sd);
  7152. if (hp > 100) hp = 100;
  7153. else if (hp <-100) hp = -100;
  7154. if (sp > 100) sp = 100;
  7155. else if (sp <-100) sp = -100;
  7156. if(hp >= 0 && sp >= 0) //Heal
  7157. return status_percent_heal(&sd->bl, hp, sp);
  7158. if(hp <= 0 && sp <= 0) //Damage (negative rates indicate % of max rather than current), and only kill target IF the specified amount is 100%
  7159. return status_percent_damage(NULL, &sd->bl, hp, sp, hp==-100);
  7160. //Crossed signs
  7161. if(hp) {
  7162. if(hp > 0)
  7163. status_percent_heal(&sd->bl, hp, 0);
  7164. else
  7165. status_percent_damage(NULL, &sd->bl, hp, 0, hp==-100);
  7166. }
  7167. if(sp) {
  7168. if(sp > 0)
  7169. status_percent_heal(&sd->bl, 0, sp);
  7170. else
  7171. status_percent_damage(NULL, &sd->bl, 0, sp, false);
  7172. }
  7173. return 0;
  7174. }
  7175. static int jobchange_killclone(struct block_list *bl, va_list ap)
  7176. {
  7177. struct mob_data *md;
  7178. int flag;
  7179. md = (struct mob_data *)bl;
  7180. nullpo_ret(md);
  7181. flag = va_arg(ap, int);
  7182. if (md->master_id && md->special_state.clone && md->master_id == flag)
  7183. status_kill(&md->bl);
  7184. return 1;
  7185. }
  7186. /**
  7187. * Called when player changes job
  7188. * Rewrote to make it tidider [Celest]
  7189. * @param sd
  7190. * @param job JOB ID. See enum e_job
  7191. * @param upper 1 - JOBL_UPPER; 2 - JOBL_BABY
  7192. * @return True if success, false if failed
  7193. **/
  7194. bool pc_jobchange(struct map_session_data *sd,int job, char upper)
  7195. {
  7196. int i, fame_flag = 0;
  7197. int b_class;
  7198. nullpo_retr(false,sd);
  7199. if (job < 0)
  7200. return false;
  7201. //Normalize job.
  7202. b_class = pc_jobid2mapid(job);
  7203. if (b_class == -1)
  7204. return false;
  7205. switch (upper) {
  7206. case 1:
  7207. b_class|= JOBL_UPPER;
  7208. break;
  7209. case 2:
  7210. b_class|= JOBL_BABY;
  7211. break;
  7212. }
  7213. //This will automatically adjust bard/dancer classes to the correct gender
  7214. //That is, if you try to jobchange into dancer, it will turn you to bard.
  7215. job = pc_mapid2jobid(b_class, sd->status.sex);
  7216. if (job == -1)
  7217. return false;
  7218. if ((unsigned short)b_class == sd->class_)
  7219. return false; //Nothing to change.
  7220. // changing from 1st to 2nd job
  7221. if ((b_class&JOBL_2) && !(sd->class_&JOBL_2) && (sd->class_&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE) {
  7222. sd->change_level_2nd = sd->status.job_level;
  7223. pc_setglobalreg(sd, add_str("jobchange_level"), sd->change_level_2nd);
  7224. }
  7225. // changing from 2nd to 3rd job
  7226. else if((b_class&JOBL_THIRD) && !(sd->class_&JOBL_THIRD)) {
  7227. sd->change_level_3rd = sd->status.job_level;
  7228. pc_setglobalreg(sd, add_str("jobchange_level_3rd"), sd->change_level_3rd);
  7229. }
  7230. if(sd->cloneskill_idx > 0) {
  7231. if( sd->status.skill[sd->cloneskill_idx].flag == SKILL_FLAG_PLAGIARIZED ) {
  7232. sd->status.skill[sd->cloneskill_idx].id = 0;
  7233. sd->status.skill[sd->cloneskill_idx].lv = 0;
  7234. sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PERMANENT;
  7235. clif_deleteskill(sd,pc_readglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM)));
  7236. }
  7237. sd->cloneskill_idx = 0;
  7238. pc_setglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM), 0);
  7239. pc_setglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM_LV), 0);
  7240. }
  7241. if(sd->reproduceskill_idx > 0) {
  7242. if( sd->status.skill[sd->reproduceskill_idx].flag == SKILL_FLAG_PLAGIARIZED ) {
  7243. sd->status.skill[sd->reproduceskill_idx].id = 0;
  7244. sd->status.skill[sd->reproduceskill_idx].lv = 0;
  7245. sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PERMANENT;
  7246. clif_deleteskill(sd,pc_readglobalreg(sd, add_str(SKILL_VAR_REPRODUCE)));
  7247. }
  7248. sd->reproduceskill_idx = 0;
  7249. pc_setglobalreg(sd, add_str(SKILL_VAR_REPRODUCE), 0);
  7250. pc_setglobalreg(sd, add_str(SKILL_VAR_REPRODUCE_LV), 0);
  7251. }
  7252. // Give or reduce transcendent status points
  7253. if( (b_class&JOBL_UPPER) && !(sd->class_&JOBL_UPPER) ){ // Change from a non t class to a t class -> give points
  7254. sd->status.status_point += battle_config.transcendent_status_points;
  7255. clif_updatestatus(sd,SP_STATUSPOINT);
  7256. }else if( !(b_class&JOBL_UPPER) && (sd->class_&JOBL_UPPER) ){ // Change from a t class to a non t class -> remove points
  7257. if( sd->status.status_point < battle_config.transcendent_status_points ){
  7258. // The player already used his bonus points, so we have to reset his status points
  7259. pc_resetstate(sd);
  7260. }
  7261. sd->status.status_point -= battle_config.transcendent_status_points;
  7262. clif_updatestatus(sd,SP_STATUSPOINT);
  7263. }
  7264. if ( (b_class&MAPID_UPPERMASK) != (sd->class_&MAPID_UPPERMASK) ) { //Things to remove when changing class tree.
  7265. const int class_ = pc_class2idx(sd->status.class_);
  7266. short id;
  7267. for(i = 0; i < MAX_SKILL_TREE && (id = skill_tree[class_][i].id) > 0; i++) {
  7268. //Remove status specific to your current tree skills.
  7269. enum sc_type sc = status_skill2sc(id);
  7270. if (sc > SC_COMMON_MAX && sd->sc.data[sc])
  7271. status_change_end(&sd->bl, sc, INVALID_TIMER);
  7272. }
  7273. }
  7274. if( (sd->class_&MAPID_UPPERMASK) == MAPID_STAR_GLADIATOR && (b_class&MAPID_UPPERMASK) != MAPID_STAR_GLADIATOR) {
  7275. /* going off star glad lineage, reset feel to not store no-longer-used vars in the database */
  7276. pc_resetfeel(sd);
  7277. }
  7278. // Reset body style to 0 before changing job to avoid
  7279. // errors since not every job has a alternate outfit.
  7280. sd->status.body = 0;
  7281. clif_changelook(&sd->bl,LOOK_BODY2,0);
  7282. sd->status.class_ = job;
  7283. fame_flag = pc_famerank(sd->status.char_id,sd->class_&MAPID_UPPERMASK);
  7284. sd->class_ = (unsigned short)b_class;
  7285. sd->status.job_level=1;
  7286. sd->status.job_exp=0;
  7287. if (sd->status.base_level > pc_maxbaselv(sd)) {
  7288. sd->status.base_level = pc_maxbaselv(sd);
  7289. sd->status.base_exp=0;
  7290. pc_resetstate(sd);
  7291. clif_updatestatus(sd,SP_STATUSPOINT);
  7292. clif_updatestatus(sd,SP_BASELEVEL);
  7293. clif_updatestatus(sd,SP_BASEEXP);
  7294. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7295. }
  7296. clif_updatestatus(sd,SP_JOBLEVEL);
  7297. clif_updatestatus(sd,SP_JOBEXP);
  7298. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7299. for(i=0;i<EQI_MAX;i++) {
  7300. if(sd->equip_index[i] >= 0)
  7301. if(pc_isequip(sd,sd->equip_index[i]))
  7302. pc_unequipitem(sd,sd->equip_index[i],2); // unequip invalid item for class
  7303. }
  7304. //Change look, if disguised, you need to undisguise
  7305. //to correctly calculate new job sprite without
  7306. if (sd->disguise)
  7307. pc_disguise(sd, 0);
  7308. status_set_viewdata(&sd->bl, job);
  7309. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_); // move sprite update to prevent client crashes with incompatible equipment [Valaris]
  7310. if(sd->vd.cloth_color)
  7311. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7312. /*
  7313. if(sd->vd.body_style)
  7314. clif_changelook(&sd->bl,LOOK_BODY2,sd->vd.body_style);
  7315. */
  7316. //Update skill tree.
  7317. pc_calc_skilltree(sd);
  7318. clif_skillinfoblock(sd);
  7319. if (sd->ed)
  7320. elemental_delete(sd->ed);
  7321. if (sd->state.vending)
  7322. vending_closevending(sd);
  7323. if (sd->state.buyingstore)
  7324. buyingstore_close(sd);
  7325. map_foreachinmap(jobchange_killclone, sd->bl.m, BL_MOB, sd->bl.id);
  7326. //Remove peco/cart/falcon
  7327. i = sd->sc.option;
  7328. if( i&OPTION_RIDING && !pc_checkskill(sd, KN_RIDING) )
  7329. i&=~OPTION_RIDING;
  7330. if( i&OPTION_FALCON && !pc_checkskill(sd, HT_FALCON) )
  7331. i&=~OPTION_FALCON;
  7332. if( i&OPTION_DRAGON && !pc_checkskill(sd,RK_DRAGONTRAINING) )
  7333. i&=~OPTION_DRAGON;
  7334. if( i&OPTION_WUGRIDER && !pc_checkskill(sd,RA_WUGMASTERY) )
  7335. i&=~OPTION_WUGRIDER;
  7336. if( i&OPTION_WUG && !pc_checkskill(sd,RA_WUGMASTERY) )
  7337. i&=~OPTION_WUG;
  7338. if( i&OPTION_MADOGEAR ) //You do not need a skill for this.
  7339. i&=~OPTION_MADOGEAR;
  7340. #ifndef NEW_CARTS
  7341. if( i&OPTION_CART && !pc_checkskill(sd, MC_PUSHCART) )
  7342. i&=~OPTION_CART;
  7343. #else
  7344. if( sd->sc.data[SC_PUSH_CART] && !pc_checkskill(sd, MC_PUSHCART) )
  7345. pc_setcart(sd, 0);
  7346. #endif
  7347. if(i != sd->sc.option)
  7348. pc_setoption(sd, i);
  7349. if(hom_is_active(sd->hd) && !pc_checkskill(sd, AM_CALLHOMUN))
  7350. hom_vaporize(sd, HOM_ST_ACTIVE);
  7351. if(sd->status.manner < 0)
  7352. clif_changestatus(sd,SP_MANNER,sd->status.manner);
  7353. status_calc_pc(sd,SCO_FORCE);
  7354. pc_checkallowskill(sd);
  7355. pc_equiplookall(sd);
  7356. pc_show_questinfo(sd);
  7357. //if you were previously famous, not anymore.
  7358. if (fame_flag) {
  7359. chrif_save(sd,0);
  7360. chrif_buildfamelist();
  7361. } else if (sd->status.fame > 0) {
  7362. //It may be that now they are famous?
  7363. switch (sd->class_&MAPID_UPPERMASK) {
  7364. case MAPID_BLACKSMITH:
  7365. case MAPID_ALCHEMIST:
  7366. case MAPID_TAEKWON:
  7367. chrif_save(sd,0);
  7368. chrif_buildfamelist();
  7369. break;
  7370. }
  7371. }
  7372. return true;
  7373. }
  7374. /*==========================================
  7375. * Tell client player sd has change equipement
  7376. *------------------------------------------*/
  7377. void pc_equiplookall(struct map_session_data *sd)
  7378. {
  7379. nullpo_retv(sd);
  7380. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7381. clif_changelook(&sd->bl,LOOK_SHOES,0);
  7382. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  7383. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  7384. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  7385. clif_changelook(&sd->bl,LOOK_ROBE, sd->status.robe);
  7386. }
  7387. /*==========================================
  7388. * Tell client player sd has change look (hair,equip...)
  7389. *------------------------------------------*/
  7390. void pc_changelook(struct map_session_data *sd,int type,int val) {
  7391. nullpo_retv(sd);
  7392. switch(type) {
  7393. case LOOK_HAIR: //Use the battle_config limits! [Skotlex]
  7394. val = cap_value(val, MIN_HAIR_STYLE, MAX_HAIR_STYLE);
  7395. if (sd->status.hair != val) {
  7396. sd->status.hair = val;
  7397. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  7398. intif_guild_change_memberinfo(sd->status.guild_id, sd->status.account_id, sd->status.char_id,
  7399. GMI_HAIR, &sd->status.hair, sizeof(sd->status.hair));
  7400. }
  7401. break;
  7402. case LOOK_WEAPON:
  7403. sd->status.weapon = val;
  7404. break;
  7405. case LOOK_HEAD_BOTTOM:
  7406. sd->status.head_bottom = val;
  7407. break;
  7408. case LOOK_HEAD_TOP:
  7409. sd->status.head_top = val;
  7410. break;
  7411. case LOOK_HEAD_MID:
  7412. sd->status.head_mid = val;
  7413. break;
  7414. case LOOK_HAIR_COLOR: //Use the battle_config limits! [Skotlex]
  7415. val = cap_value(val, MIN_HAIR_COLOR, MAX_HAIR_COLOR);
  7416. if (sd->status.hair_color != val) {
  7417. sd->status.hair_color = val;
  7418. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  7419. intif_guild_change_memberinfo(sd->status.guild_id, sd->status.account_id, sd->status.char_id,
  7420. GMI_HAIR_COLOR, &sd->status.hair_color, sizeof(sd->status.hair_color));
  7421. }
  7422. break;
  7423. case LOOK_CLOTHES_COLOR: //Use the battle_config limits! [Skotlex]
  7424. val = cap_value(val, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  7425. sd->status.clothes_color = val;
  7426. break;
  7427. case LOOK_SHIELD:
  7428. sd->status.shield = val;
  7429. break;
  7430. case LOOK_SHOES:
  7431. break;
  7432. case LOOK_ROBE:
  7433. sd->status.robe = val;
  7434. break;
  7435. case LOOK_BODY2:
  7436. val = cap_value(val, MIN_BODY_STYLE, MAX_BODY_STYLE);
  7437. sd->status.body = val;
  7438. break;
  7439. }
  7440. clif_changelook(&sd->bl, type, val);
  7441. }
  7442. /*==========================================
  7443. * Give an option (type) to player (sd) and display it to client
  7444. *------------------------------------------*/
  7445. void pc_setoption(struct map_session_data *sd,int type)
  7446. {
  7447. int p_type, new_look=0;
  7448. nullpo_retv(sd);
  7449. p_type = sd->sc.option;
  7450. //Option has to be changed client-side before the class sprite or it won't always work (eg: Wedding sprite) [Skotlex]
  7451. sd->sc.option=type;
  7452. clif_changeoption(&sd->bl);
  7453. if( (type&OPTION_RIDING && !(p_type&OPTION_RIDING)) || (type&OPTION_DRAGON && !(p_type&OPTION_DRAGON) && pc_checkskill(sd,RK_DRAGONTRAINING) > 0) )
  7454. { // Mounting
  7455. clif_status_load(&sd->bl,SI_RIDING,1);
  7456. status_calc_pc(sd,SCO_NONE);
  7457. }
  7458. else if( (!(type&OPTION_RIDING) && p_type&OPTION_RIDING) || (!(type&OPTION_DRAGON) && p_type&OPTION_DRAGON && pc_checkskill(sd,RK_DRAGONTRAINING) > 0) )
  7459. { // Dismount
  7460. clif_status_load(&sd->bl,SI_RIDING,0);
  7461. status_calc_pc(sd,SCO_NONE);
  7462. }
  7463. #ifndef NEW_CARTS
  7464. if( type&OPTION_CART && !( p_type&OPTION_CART ) ) { //Cart On
  7465. clif_cartlist(sd);
  7466. clif_updatestatus(sd, SP_CARTINFO);
  7467. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7468. status_calc_pc(sd,SCO_NONE); //Apply speed penalty.
  7469. } else if( !( type&OPTION_CART ) && p_type&OPTION_CART ){ //Cart Off
  7470. clif_clearcart(sd->fd);
  7471. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7472. status_calc_pc(sd,SCO_NONE); //Remove speed penalty.
  7473. }
  7474. #endif
  7475. if (type&OPTION_FALCON && !(p_type&OPTION_FALCON)) //Falcon ON
  7476. clif_status_load(&sd->bl,SI_FALCON,1);
  7477. else if (!(type&OPTION_FALCON) && p_type&OPTION_FALCON) //Falcon OFF
  7478. clif_status_load(&sd->bl,SI_FALCON,0);
  7479. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER ) {
  7480. if( type&OPTION_WUGRIDER && !(p_type&OPTION_WUGRIDER) ) { // Mounting
  7481. clif_status_load(&sd->bl,SI_WUGRIDER,1);
  7482. status_calc_pc(sd,SCO_NONE);
  7483. } else if( !(type&OPTION_WUGRIDER) && p_type&OPTION_WUGRIDER ) { // Dismount
  7484. clif_status_load(&sd->bl,SI_WUGRIDER,0);
  7485. status_calc_pc(sd,SCO_NONE);
  7486. }
  7487. }
  7488. if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  7489. if( type&OPTION_MADOGEAR && !(p_type&OPTION_MADOGEAR) ) {
  7490. status_calc_pc(sd,SCO_NONE);
  7491. status_change_end(&sd->bl,SC_MAXIMIZEPOWER,INVALID_TIMER);
  7492. status_change_end(&sd->bl,SC_OVERTHRUST,INVALID_TIMER);
  7493. status_change_end(&sd->bl,SC_WEAPONPERFECTION,INVALID_TIMER);
  7494. status_change_end(&sd->bl,SC_ADRENALINE,INVALID_TIMER);
  7495. status_change_end(&sd->bl,SC_CARTBOOST,INVALID_TIMER);
  7496. status_change_end(&sd->bl,SC_MELTDOWN,INVALID_TIMER);
  7497. status_change_end(&sd->bl,SC_MAXOVERTHRUST,INVALID_TIMER);
  7498. pc_bonus_script_clear(sd,BSF_REM_ON_MADOGEAR);
  7499. } else if( !(type&OPTION_MADOGEAR) && p_type&OPTION_MADOGEAR ) {
  7500. status_calc_pc(sd,SCO_NONE);
  7501. status_change_end(&sd->bl,SC_SHAPESHIFT,INVALID_TIMER);
  7502. status_change_end(&sd->bl,SC_HOVERING,INVALID_TIMER);
  7503. status_change_end(&sd->bl,SC_ACCELERATION,INVALID_TIMER);
  7504. status_change_end(&sd->bl,SC_OVERHEAT_LIMITPOINT,INVALID_TIMER);
  7505. status_change_end(&sd->bl,SC_OVERHEAT,INVALID_TIMER);
  7506. pc_bonus_script_clear(sd,BSF_REM_ON_MADOGEAR);
  7507. }
  7508. }
  7509. if (type&OPTION_FLYING && !(p_type&OPTION_FLYING))
  7510. new_look = JOB_STAR_GLADIATOR2;
  7511. else if (!(type&OPTION_FLYING) && p_type&OPTION_FLYING)
  7512. new_look = -1;
  7513. if (sd->disguise || !new_look)
  7514. return; //Disguises break sprite changes
  7515. if (new_look < 0) { //Restore normal look.
  7516. status_set_viewdata(&sd->bl, sd->status.class_);
  7517. new_look = sd->vd.class_;
  7518. }
  7519. pc_stop_attack(sd); //Stop attacking on new view change (to prevent wedding/santa attacks.
  7520. clif_changelook(&sd->bl,LOOK_BASE,new_look);
  7521. if (sd->vd.cloth_color)
  7522. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7523. if( sd->vd.body_style )
  7524. clif_changelook(&sd->bl,LOOK_BODY2,sd->vd.body_style);
  7525. clif_skillinfoblock(sd); // Skill list needs to be updated after base change.
  7526. }
  7527. /*==========================================
  7528. * Give player a cart
  7529. *------------------------------------------*/
  7530. bool pc_setcart(struct map_session_data *sd,int type) {
  7531. #ifndef NEW_CARTS
  7532. int cart[6] = {0x0000,OPTION_CART1,OPTION_CART2,OPTION_CART3,OPTION_CART4,OPTION_CART5};
  7533. int option;
  7534. #endif
  7535. nullpo_retr(false,sd);
  7536. if( type < 0 || type > MAX_CARTS )
  7537. return false;// Never trust the values sent by the client! [Skotlex]
  7538. if( pc_checkskill(sd,MC_PUSHCART) <= 0 && type != 0 )
  7539. return false;// Push cart is required
  7540. #ifdef NEW_CARTS
  7541. switch( type ) {
  7542. case 0:
  7543. if( !sd->sc.data[SC_PUSH_CART] )
  7544. return 0;
  7545. status_change_end(&sd->bl,SC_PUSH_CART,INVALID_TIMER);
  7546. clif_clearcart(sd->fd);
  7547. break;
  7548. default:/* everything else is an allowed ID so we can move on */
  7549. if( !sd->sc.data[SC_PUSH_CART] ) /* first time, so fill cart data */
  7550. clif_cartlist(sd);
  7551. clif_updatestatus(sd, SP_CARTINFO);
  7552. sc_start(&sd->bl,&sd->bl, SC_PUSH_CART, 100, type, 0);
  7553. clif_status_change2(&sd->bl, sd->bl.id, AREA, SI_ON_PUSH_CART, type, 0, 0);
  7554. if( sd->sc.data[SC_PUSH_CART] )/* forcefully update */
  7555. sd->sc.data[SC_PUSH_CART]->val1 = type;
  7556. break;
  7557. }
  7558. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  7559. status_calc_pc(sd,SCO_NONE); //Recalc speed penalty.
  7560. #else
  7561. // Update option
  7562. option = sd->sc.option;
  7563. option &= ~OPTION_CART;// clear cart bits
  7564. option |= cart[type]; // set cart
  7565. pc_setoption(sd, option);
  7566. #endif
  7567. return true;
  7568. }
  7569. /*==========================================
  7570. * Give player a falcon
  7571. *------------------------------------------*/
  7572. void pc_setfalcon(TBL_PC* sd, int flag)
  7573. {
  7574. if( flag ){
  7575. if( pc_checkskill(sd,HT_FALCON)>0 ) // add falcon if he have the skill
  7576. pc_setoption(sd,sd->sc.option|OPTION_FALCON);
  7577. } else if( pc_isfalcon(sd) ){
  7578. pc_setoption(sd,sd->sc.option&~OPTION_FALCON); // remove falcon
  7579. }
  7580. }
  7581. /*==========================================
  7582. * Set player riding
  7583. *------------------------------------------*/
  7584. void pc_setriding(TBL_PC* sd, int flag)
  7585. {
  7586. if( &sd->sc && sd->sc.data[SC_ALL_RIDING] )
  7587. return;
  7588. if( flag ){
  7589. if( pc_checkskill(sd,KN_RIDING) > 0 ) // add peco
  7590. pc_setoption(sd, sd->sc.option|OPTION_RIDING);
  7591. } else if( pc_isriding(sd) ){
  7592. pc_setoption(sd, sd->sc.option&~OPTION_RIDING);
  7593. }
  7594. }
  7595. /*==========================================
  7596. * Give player a mado
  7597. *------------------------------------------*/
  7598. void pc_setmadogear(TBL_PC* sd, int flag)
  7599. {
  7600. if( flag ){
  7601. if( pc_checkskill(sd,NC_MADOLICENCE) > 0 )
  7602. pc_setoption(sd, sd->sc.option|OPTION_MADOGEAR);
  7603. } else if( pc_ismadogear(sd) ){
  7604. pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR);
  7605. }
  7606. }
  7607. /*==========================================
  7608. * Check if player can drop an item
  7609. *------------------------------------------*/
  7610. bool pc_candrop(struct map_session_data *sd, struct item *item)
  7611. {
  7612. if( item && (item->expire_time || (item->bound && !pc_can_give_bounded_items(sd))) )
  7613. return false;
  7614. if( !pc_can_give_items(sd) || sd->sc.cant.drop) //check if this GM level can drop items
  7615. return false;
  7616. return (itemdb_isdropable(item, pc_get_group_level(sd)));
  7617. }
  7618. /**
  7619. * Determines whether a player can attack based on status changes
  7620. * Why not use status_check_skilluse?
  7621. * "src MAY be null to indicate we shouldn't check it, this is a ground-based skill attack."
  7622. * Even ground-based attacks should be blocked by these statuses
  7623. * Called from unit_attack and unit_attack_timer_sub
  7624. * @retval true Can attack
  7625. **/
  7626. bool pc_can_attack( struct map_session_data *sd, int target_id ) {
  7627. nullpo_retr(false, sd);
  7628. if (!&sd->sc)
  7629. return true;
  7630. if( sd->sc.data[SC_BASILICA] ||
  7631. sd->sc.data[SC__SHADOWFORM] ||
  7632. sd->sc.data[SC__MANHOLE] ||
  7633. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  7634. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ||
  7635. sd->sc.data[SC_CRYSTALIZE] ||
  7636. sd->sc.data[SC_ALL_RIDING] || // The client doesn't let you, this is to make cheat-safe
  7637. sd->sc.data[SC_TRICKDEAD] ||
  7638. (sd->sc.data[SC_VOICEOFSIREN] && sd->sc.data[SC_VOICEOFSIREN]->val2 == target_id) ||
  7639. sd->sc.data[SC_BLADESTOP] ||
  7640. sd->sc.data[SC_DEEPSLEEP] ||
  7641. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF) )
  7642. return false;
  7643. return true;
  7644. }
  7645. /*==========================================
  7646. * Read '@type' variables (temporary numeric char reg)
  7647. *------------------------------------------*/
  7648. int pc_readreg(struct map_session_data* sd, int64 reg)
  7649. {
  7650. return i64db_iget(sd->regs.vars, reg);
  7651. }
  7652. /*==========================================
  7653. * Set '@type' variables (temporary numeric char reg)
  7654. *------------------------------------------*/
  7655. bool pc_setreg(struct map_session_data* sd, int64 reg, int val)
  7656. {
  7657. unsigned int index = script_getvaridx(reg);
  7658. nullpo_retr(false, sd);
  7659. if( val ) {
  7660. i64db_iput(sd->regs.vars, reg, val);
  7661. if( index )
  7662. script_array_update(&sd->regs, reg, false);
  7663. } else {
  7664. i64db_remove(sd->regs.vars, reg);
  7665. if( index )
  7666. script_array_update(&sd->regs, reg, true);
  7667. }
  7668. return true;
  7669. }
  7670. /*==========================================
  7671. * Read '@type$' variables (temporary string char reg)
  7672. *------------------------------------------*/
  7673. char* pc_readregstr(struct map_session_data* sd, int64 reg)
  7674. {
  7675. struct script_reg_str *p = NULL;
  7676. p = (struct script_reg_str *)i64db_get(sd->regs.vars, reg);
  7677. return p ? p->value : NULL;
  7678. }
  7679. /*==========================================
  7680. * Set '@type$' variables (temporary string char reg)
  7681. *------------------------------------------*/
  7682. bool pc_setregstr(struct map_session_data* sd, int64 reg, const char* str)
  7683. {
  7684. struct script_reg_str *p = NULL;
  7685. unsigned int index = script_getvaridx(reg);
  7686. DBData prev;
  7687. nullpo_retr(false, sd);
  7688. if( str[0] ) {
  7689. p = ers_alloc(str_reg_ers, struct script_reg_str);
  7690. p->value = aStrdup(str);
  7691. p->flag.type = 1;
  7692. if (sd->regs.vars->put(sd->regs.vars, db_i642key(reg), db_ptr2data(p), &prev)) {
  7693. p = (struct script_reg_str *)db_data2ptr(&prev);
  7694. if( p->value )
  7695. aFree(p->value);
  7696. ers_free(str_reg_ers, p);
  7697. } else {
  7698. if( index )
  7699. script_array_update(&sd->regs, reg, false);
  7700. }
  7701. } else {
  7702. if (sd->regs.vars->remove(sd->regs.vars, db_i642key(reg), &prev)) {
  7703. p = (struct script_reg_str *)db_data2ptr(&prev);
  7704. if( p->value )
  7705. aFree(p->value);
  7706. ers_free(str_reg_ers, p);
  7707. if( index )
  7708. script_array_update(&sd->regs, reg, true);
  7709. }
  7710. }
  7711. return true;
  7712. }
  7713. /**
  7714. * Serves the following variable types:
  7715. * - 'type' (permanent numeric char reg)
  7716. * - '#type' (permanent numeric account reg)
  7717. * - '##type' (permanent numeric account reg2)
  7718. **/
  7719. int pc_readregistry(struct map_session_data *sd, int64 reg)
  7720. {
  7721. struct script_reg_num *p = NULL;
  7722. if (!sd->vars_ok) {
  7723. ShowError("pc_readregistry: Trying to read reg %s before it's been loaded!\n", get_str(script_getvarid(reg)));
  7724. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  7725. //intif->request_registry(sd,type==3?4:type);
  7726. set_eof(sd->fd);
  7727. return 0;
  7728. }
  7729. p = (struct script_reg_num *)i64db_get(sd->regs.vars, reg);
  7730. return p ? p->value : 0;
  7731. }
  7732. /**
  7733. * Serves the following variable types:
  7734. * - 'type$' (permanent str char reg)
  7735. * - '#type$' (permanent str account reg)
  7736. * - '##type$' (permanent str account reg2)
  7737. **/
  7738. char* pc_readregistry_str(struct map_session_data *sd, int64 reg)
  7739. {
  7740. struct script_reg_str *p = NULL;
  7741. if (!sd->vars_ok) {
  7742. ShowError("pc_readregistry_str: Trying to read reg %s before it's been loaded!\n", get_str(script_getvarid(reg)));
  7743. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  7744. //intif->request_registry(sd,type==3?4:type);
  7745. set_eof(sd->fd);
  7746. return NULL;
  7747. }
  7748. p = (struct script_reg_str *)i64db_get(sd->regs.vars, reg);
  7749. return p ? p->value : NULL;
  7750. }
  7751. /**
  7752. * Serves the following variable types:
  7753. * - 'type' (permanent numeric char reg)
  7754. * - '#type' (permanent numeric account reg)
  7755. * - '##type' (permanent numeric account reg2)
  7756. **/
  7757. int pc_setregistry(struct map_session_data *sd, int64 reg, int val)
  7758. {
  7759. struct script_reg_num *p = NULL;
  7760. const char *regname = get_str(script_getvarid(reg));
  7761. unsigned int index = script_getvaridx(reg);
  7762. // These should be stored elsewhere e.g. char ones in char table, the cash ones in account_data table!
  7763. switch( regname[0] ) {
  7764. default: //Char reg
  7765. if( !strcmp(regname,"PC_DIE_COUNTER") && sd->die_counter != val ) {
  7766. int i = (!sd->die_counter && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE);
  7767. sd->die_counter = val;
  7768. if( i )
  7769. status_calc_pc(sd,SCO_NONE); // Lost the bonus.
  7770. } else if( !strcmp(regname,"COOK_MASTERY") && sd->cook_mastery != val ) {
  7771. val = cap_value(val, 0, 1999);
  7772. sd->cook_mastery = val;
  7773. }
  7774. break;
  7775. case '#':
  7776. if( !strcmp(regname,"#CASHPOINTS") && sd->cashPoints != val ) {
  7777. val = cap_value(val, 0, MAX_ZENY);
  7778. sd->cashPoints = val;
  7779. } else if( !strcmp(regname,"#KAFRAPOINTS") && sd->kafraPoints != val ) {
  7780. val = cap_value(val, 0, MAX_ZENY);
  7781. sd->kafraPoints = val;
  7782. }
  7783. break;
  7784. }
  7785. if ( !reg_load && !sd->vars_ok ) {
  7786. ShowError("pc_setregistry : refusing to set %s until vars are received.\n", regname);
  7787. return 0;
  7788. }
  7789. if ((p = (struct script_reg_num *)i64db_get(sd->regs.vars, reg))) {
  7790. if( val ) {
  7791. if( !p->value && index ) /* its a entry that was deleted, so we reset array */
  7792. script_array_update(&sd->regs, reg, false);
  7793. p->value = val;
  7794. } else {
  7795. p->value = 0;
  7796. if( index )
  7797. script_array_update(&sd->regs, reg, true);
  7798. }
  7799. if (!reg_load)
  7800. p->flag.update = 1;/* either way, it will require either delete or replace */
  7801. } else if( val ) {
  7802. DBData prev;
  7803. if( index )
  7804. script_array_update(&sd->regs, reg, false);
  7805. p = ers_alloc(num_reg_ers, struct script_reg_num);
  7806. p->value = val;
  7807. if (!reg_load)
  7808. p->flag.update = 1;
  7809. if (sd->regs.vars->put(sd->regs.vars, db_i642key(reg), db_ptr2data(p), &prev)) {
  7810. p = (struct script_reg_num *)db_data2ptr(&prev);
  7811. ers_free(num_reg_ers, p);
  7812. }
  7813. }
  7814. if (!reg_load && p)
  7815. sd->vars_dirty = true;
  7816. return 1;
  7817. }
  7818. /**
  7819. * Serves the following variable types:
  7820. * - 'type$' (permanent str char reg)
  7821. * - '#type$' (permanent str account reg)
  7822. * - '##type$' (permanent str account reg2)
  7823. **/
  7824. int pc_setregistry_str(struct map_session_data *sd, int64 reg, const char *val)
  7825. {
  7826. struct script_reg_str *p = NULL;
  7827. const char *regname = get_str(script_getvarid(reg));
  7828. unsigned int index = script_getvaridx(reg);
  7829. if (!reg_load && !sd->vars_ok) {
  7830. ShowError("pc_setregistry_str : refusing to set %s until vars are received.\n", regname);
  7831. return 0;
  7832. }
  7833. if( (p = (struct script_reg_str *)i64db_get(sd->regs.vars, reg) ) ) {
  7834. if( val[0] ) {
  7835. if( p->value )
  7836. aFree(p->value);
  7837. else if ( index ) // an entry that was deleted, so we reset
  7838. script_array_update(&sd->regs, reg, false);
  7839. p->value = aStrdup(val);
  7840. } else {
  7841. p->value = NULL;
  7842. if( index )
  7843. script_array_update(&sd->regs, reg, true);
  7844. }
  7845. if( !reg_load )
  7846. p->flag.update = 1; // either way, it will require either delete or replace
  7847. } else if( val[0] ) {
  7848. DBData prev;
  7849. if( index )
  7850. script_array_update(&sd->regs, reg, false);
  7851. p = ers_alloc(str_reg_ers, struct script_reg_str);
  7852. p->value = aStrdup(val);
  7853. if( !reg_load )
  7854. p->flag.update = 1;
  7855. p->flag.type = 1;
  7856. if( sd->regs.vars->put(sd->regs.vars, db_i642key(reg), db_ptr2data(p), &prev) ) {
  7857. p = (struct script_reg_str *)db_data2ptr(&prev);
  7858. if( p->value )
  7859. aFree(p->value);
  7860. ers_free(str_reg_ers, p);
  7861. }
  7862. }
  7863. if( !reg_load && p )
  7864. sd->vars_dirty = true;
  7865. return 1;
  7866. }
  7867. /**
  7868. * Set value of player variable
  7869. * @param sd Player
  7870. * @param reg Variable name
  7871. * @param value
  7872. * @return True if success, false if failed.
  7873. **/
  7874. bool pc_setreg2(struct map_session_data *sd, const char *reg, int val) {
  7875. char prefix = reg[0];
  7876. nullpo_retr(false, sd);
  7877. if (reg[strlen(reg)-1] == '$') {
  7878. ShowError("pc_setreg2: Invalid variable scope '%s'\n", reg);
  7879. return false;
  7880. }
  7881. val = cap_value(val, INT_MIN, INT_MAX);
  7882. switch (prefix) {
  7883. case '.':
  7884. case '\'':
  7885. case '$':
  7886. ShowError("pc_setreg2: Invalid variable scope '%s'\n", reg);
  7887. return false;
  7888. case '@':
  7889. return pc_setreg(sd, add_str(reg), val);
  7890. case '#':
  7891. return (reg[1] == '#') ? pc_setaccountreg2(sd, add_str(reg), val) : pc_setaccountreg(sd, add_str(reg), val);
  7892. default:
  7893. return pc_setglobalreg(sd, add_str(reg), val);
  7894. }
  7895. return false;
  7896. }
  7897. /**
  7898. * Get value of player variable
  7899. * @param sd Player
  7900. * @param reg Variable name
  7901. * @return Variable value or 0 if failed.
  7902. **/
  7903. int pc_readreg2(struct map_session_data *sd, const char *reg) {
  7904. char prefix = reg[0];
  7905. nullpo_ret(sd);
  7906. if (reg[strlen(reg)-1] == '$') {
  7907. ShowError("pc_readreg2: Invalid variable scope '%s'\n", reg);
  7908. return 0;
  7909. }
  7910. switch (prefix) {
  7911. case '.':
  7912. case '\'':
  7913. case '$':
  7914. ShowError("pc_readreg2: Invalid variable scope '%s'\n", reg);
  7915. return 0;
  7916. case '@':
  7917. return pc_readreg(sd, add_str(reg));
  7918. case '#':
  7919. return (reg[1] == '#') ? pc_readaccountreg2(sd, add_str(reg)) : pc_readaccountreg(sd, add_str(reg));
  7920. default:
  7921. return pc_readglobalreg(sd, add_str(reg));
  7922. }
  7923. return 0;
  7924. }
  7925. /*==========================================
  7926. * Exec eventtimer for player sd (retrieved from map_session (id))
  7927. *------------------------------------------*/
  7928. static int pc_eventtimer(int tid, unsigned int tick, int id, intptr_t data)
  7929. {
  7930. struct map_session_data *sd=map_id2sd(id);
  7931. char *p = (char *)data;
  7932. int i;
  7933. if(sd==NULL)
  7934. return 0;
  7935. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == tid );
  7936. if( i < MAX_EVENTTIMER )
  7937. {
  7938. sd->eventtimer[i] = INVALID_TIMER;
  7939. sd->eventcount--;
  7940. npc_event(sd,p,0);
  7941. }
  7942. else
  7943. ShowError("pc_eventtimer: no such event timer\n");
  7944. if (p) aFree(p);
  7945. return 0;
  7946. }
  7947. /*==========================================
  7948. * Add eventtimer for player sd ?
  7949. *------------------------------------------*/
  7950. bool pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
  7951. {
  7952. int i;
  7953. nullpo_retr(false,sd);
  7954. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == INVALID_TIMER );
  7955. if( i == MAX_EVENTTIMER )
  7956. return false;
  7957. sd->eventtimer[i] = add_timer(gettick()+tick, pc_eventtimer, sd->bl.id, (intptr_t)aStrdup(name));
  7958. sd->eventcount++;
  7959. return true;
  7960. }
  7961. /*==========================================
  7962. * Del eventtimer for player sd ?
  7963. *------------------------------------------*/
  7964. bool pc_deleventtimer(struct map_session_data *sd,const char *name)
  7965. {
  7966. char* p = NULL;
  7967. int i;
  7968. nullpo_retr(false,sd);
  7969. if (sd->eventcount == 0)
  7970. return false;
  7971. // find the named event timer
  7972. ARR_FIND( 0, MAX_EVENTTIMER, i,
  7973. sd->eventtimer[i] != INVALID_TIMER &&
  7974. (p = (char *)(get_timer(sd->eventtimer[i])->data)) != NULL &&
  7975. strcmp(p, name) == 0
  7976. );
  7977. if( i == MAX_EVENTTIMER )
  7978. return false; // not found
  7979. delete_timer(sd->eventtimer[i],pc_eventtimer);
  7980. sd->eventtimer[i] = INVALID_TIMER;
  7981. if(sd->eventcount > 0)
  7982. sd->eventcount--;
  7983. aFree(p);
  7984. return true;
  7985. }
  7986. /*==========================================
  7987. * Update eventtimer count for player sd
  7988. *------------------------------------------*/
  7989. void pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick)
  7990. {
  7991. int i;
  7992. nullpo_retv(sd);
  7993. for(i=0;i<MAX_EVENTTIMER;i++)
  7994. if( sd->eventtimer[i] != INVALID_TIMER && strcmp(
  7995. (char *)(get_timer(sd->eventtimer[i])->data), name)==0 ){
  7996. addtick_timer(sd->eventtimer[i],tick);
  7997. break;
  7998. }
  7999. }
  8000. /*==========================================
  8001. * Remove all eventtimer for player sd
  8002. *------------------------------------------*/
  8003. void pc_cleareventtimer(struct map_session_data *sd)
  8004. {
  8005. int i;
  8006. nullpo_retv(sd);
  8007. if (sd->eventcount == 0)
  8008. return;
  8009. for(i=0;i<MAX_EVENTTIMER;i++){
  8010. if( sd->eventtimer[i] != INVALID_TIMER ){
  8011. char *p = (char *)(get_timer(sd->eventtimer[i])->data);
  8012. delete_timer(sd->eventtimer[i],pc_eventtimer);
  8013. sd->eventtimer[i] = INVALID_TIMER;
  8014. if(sd->eventcount > 0) //avoid looping to max val
  8015. sd->eventcount--;
  8016. if (p) aFree(p);
  8017. }
  8018. }
  8019. }
  8020. /**
  8021. * Called when an item with combo is worn
  8022. * @param *sd
  8023. * @param *data struct item_data
  8024. * @return success numbers of succeed combo
  8025. */
  8026. static int pc_checkcombo(struct map_session_data *sd, struct item_data *data) {
  8027. uint16 i;
  8028. int success = 0;
  8029. for( i = 0; i < data->combos_count; i++ ) {
  8030. struct itemchk {
  8031. int idx;
  8032. short card[MAX_SLOTS];
  8033. } *combo_idx;
  8034. int idx, j;
  8035. int nb_itemCombo;
  8036. unsigned int pos = 0;
  8037. /* ensure this isn't a duplicate combo */
  8038. if( sd->combos.bonus != NULL ) {
  8039. int x;
  8040. ARR_FIND( 0, sd->combos.count, x, sd->combos.id[x] == data->combos[i]->id );
  8041. /* found a match, skip this combo */
  8042. if( x < sd->combos.count )
  8043. continue;
  8044. }
  8045. nb_itemCombo = data->combos[i]->count;
  8046. if(nb_itemCombo<2) //a combo with less then 2 item ?? how that possible
  8047. continue;
  8048. CREATE(combo_idx,struct itemchk,nb_itemCombo);
  8049. for(j=0; j < nb_itemCombo; j++){
  8050. combo_idx[j].idx=-1;
  8051. memset(combo_idx[j].card,-1,MAX_SLOTS);
  8052. }
  8053. for( j = 0; j < nb_itemCombo; j++ ) {
  8054. uint16 id = data->combos[i]->nameid[j], k;
  8055. bool found = false;
  8056. for( k = 0; k < EQI_MAX; k++ ) {
  8057. short index = sd->equip_index[k];
  8058. if( index < 0 )
  8059. continue;
  8060. if( pc_is_same_equip_index((enum equip_index)k, sd->equip_index, index) )
  8061. continue;
  8062. if (!sd->inventory_data[index] )
  8063. continue;
  8064. if ( itemdb_type(id) != IT_CARD ) {
  8065. if ( sd->inventory_data[index]->nameid != id )
  8066. continue;
  8067. if(j>0){ //check if this item not already used
  8068. bool do_continue = false; //used to continue that specific loop with some check that also use some loop
  8069. uint8 z;
  8070. for (z = 0; z < nb_itemCombo-1; z++)
  8071. if(combo_idx[z].idx == index) //we already have that index recorded
  8072. do_continue=true;
  8073. if(do_continue)
  8074. continue;
  8075. }
  8076. combo_idx[j].idx = index;
  8077. pos |= sd->status.inventory[index].equip;
  8078. found = true;
  8079. break;
  8080. } else { //Cards
  8081. uint16 z;
  8082. if ( sd->inventory_data[index]->slot == 0 || itemdb_isspecial(sd->status.inventory[index].card[0]) )
  8083. continue;
  8084. for (z = 0; z < sd->inventory_data[index]->slot; z++) {
  8085. bool do_continue=false;
  8086. if (sd->status.inventory[index].card[z] != id)
  8087. continue;
  8088. if(j>0){
  8089. int c1, c2;
  8090. for (c1 = 0; c1 < nb_itemCombo-1; c1++){
  8091. if(combo_idx[c1].idx == index){
  8092. for (c2 = 0; c2 < sd->inventory_data[index]->slot; c2++){
  8093. if(combo_idx[c1].card[c2] == id){ //we already have that card recorded (at this same idx)
  8094. do_continue = true;
  8095. break;
  8096. }
  8097. }
  8098. }
  8099. }
  8100. }
  8101. if(do_continue)
  8102. continue;
  8103. combo_idx[j].idx = index;
  8104. combo_idx[j].card[z] = id;
  8105. pos |= sd->status.inventory[index].equip;
  8106. found = true;
  8107. break;
  8108. }
  8109. }
  8110. }
  8111. if( !found )
  8112. break;/* we haven't found all the ids for this combo, so we can return */
  8113. }
  8114. aFree(combo_idx);
  8115. /* means we broke out of the count loop w/o finding all ids, we can move to the next combo */
  8116. if( j < nb_itemCombo )
  8117. continue;
  8118. /* we got here, means all items in the combo are matching */
  8119. idx = sd->combos.count;
  8120. if( sd->combos.bonus == NULL ) {
  8121. CREATE(sd->combos.bonus, struct script_code *, 1);
  8122. CREATE(sd->combos.id, unsigned short, 1);
  8123. CREATE(sd->combos.pos, unsigned int, 1);
  8124. sd->combos.count = 1;
  8125. } else {
  8126. RECREATE(sd->combos.bonus, struct script_code *, ++sd->combos.count);
  8127. RECREATE(sd->combos.id, unsigned short, sd->combos.count);
  8128. RECREATE(sd->combos.pos, unsigned int, sd->combos.count);
  8129. }
  8130. /* we simply copy the pointer */
  8131. sd->combos.bonus[idx] = data->combos[i]->script;
  8132. /* save this combo's id */
  8133. sd->combos.id[idx] = data->combos[i]->id;
  8134. /* save pos of combo*/
  8135. sd->combos.pos[idx] = pos;
  8136. success++;
  8137. }
  8138. return success;
  8139. }
  8140. /**
  8141. * Called when an item with combo is removed
  8142. * @param *sd
  8143. * @param *data struct item_data
  8144. * @return retval numbers of removed combo
  8145. */
  8146. static int pc_removecombo(struct map_session_data *sd, struct item_data *data ) {
  8147. int i, retval = 0;
  8148. if( sd->combos.bonus == NULL )
  8149. return 0;/* nothing to do here, player has no combos */
  8150. for( i = 0; i < data->combos_count; i++ ) {
  8151. /* check if this combo exists in this user */
  8152. int x = 0, cursor = 0, j;
  8153. ARR_FIND( 0, sd->combos.count, x, sd->combos.id[x] == data->combos[i]->id );
  8154. /* no match, skip this combo */
  8155. if(x >= sd->combos.count)
  8156. continue;
  8157. sd->combos.bonus[x] = NULL;
  8158. sd->combos.id[x] = 0;
  8159. sd->combos.pos[x] = 0;
  8160. retval++;
  8161. /* check if combo requirements still fit */
  8162. if( pc_checkcombo( sd, data ) )
  8163. continue;
  8164. /* move next value to empty slot */
  8165. for( j = 0, cursor = 0; j < sd->combos.count; j++ ) {
  8166. if( sd->combos.bonus[j] == NULL )
  8167. continue;
  8168. if( cursor != j ) {
  8169. sd->combos.bonus[cursor] = sd->combos.bonus[j];
  8170. sd->combos.id[cursor] = sd->combos.id[j];
  8171. sd->combos.pos[cursor] = sd->combos.pos[j];
  8172. }
  8173. cursor++;
  8174. }
  8175. /* it's empty, we can clear all the memory */
  8176. if( (sd->combos.count = cursor) == 0 ) {
  8177. aFree(sd->combos.bonus);
  8178. aFree(sd->combos.id);
  8179. aFree(sd->combos.pos);
  8180. sd->combos.bonus = NULL;
  8181. sd->combos.id = NULL;
  8182. sd->combos.pos = NULL;
  8183. return retval; /* we also can return at this point for we have no more combos to check */
  8184. }
  8185. }
  8186. return retval;
  8187. }
  8188. /**
  8189. * Load combo data(s) of player
  8190. * @param *sd
  8191. * @return ret numbers of succeed combo
  8192. */
  8193. int pc_load_combo(struct map_session_data *sd) {
  8194. int i, ret = 0;
  8195. for( i = 0; i < EQI_MAX; i++ ) {
  8196. struct item_data *id = NULL;
  8197. short idx = sd->equip_index[i];
  8198. if( idx < 0 || !(id = sd->inventory_data[idx] ) )
  8199. continue;
  8200. if( id->combos_count )
  8201. ret += pc_checkcombo(sd,id);
  8202. if(!itemdb_isspecial(sd->status.inventory[idx].card[0])) {
  8203. struct item_data *data;
  8204. int j;
  8205. for( j = 0; j < id->slot; j++ ) {
  8206. if (!sd->status.inventory[idx].card[j])
  8207. continue;
  8208. if ( ( data = itemdb_exists(sd->status.inventory[idx].card[j]) ) != NULL ) {
  8209. if( data->combos_count )
  8210. ret += pc_checkcombo(sd,data);
  8211. }
  8212. }
  8213. }
  8214. }
  8215. return ret;
  8216. }
  8217. /*==========================================
  8218. * Equip item on player sd at req_pos from inventory index n
  8219. * return: false - fail; true - success
  8220. *------------------------------------------*/
  8221. bool pc_equipitem(struct map_session_data *sd,short n,int req_pos)
  8222. {
  8223. int i, pos, flag = 0, iflag;
  8224. struct item_data *id;
  8225. uint8 res = ITEM_EQUIP_ACK_OK;
  8226. nullpo_retr(false,sd);
  8227. if( n < 0 || n >= MAX_INVENTORY ) {
  8228. clif_equipitemack(sd,0,0,ITEM_EQUIP_ACK_FAIL);
  8229. return false;
  8230. }
  8231. if( DIFF_TICK(sd->canequip_tick,gettick()) > 0 ) {
  8232. clif_equipitemack(sd,n,0,ITEM_EQUIP_ACK_FAIL);
  8233. return false;
  8234. }
  8235. if (!(id = sd->inventory_data[n]))
  8236. return false;
  8237. pos = pc_equippoint(sd,n); //With a few exceptions, item should go in all specified slots.
  8238. if(battle_config.battle_log)
  8239. ShowInfo("equip %hu(%d) %x:%x\n",sd->status.inventory[n].nameid,n,id?id->equip:0,req_pos);
  8240. if((res = pc_isequip(sd,n))) {
  8241. clif_equipitemack(sd,n,0,res); // fail
  8242. return false;
  8243. }
  8244. if (!(pos&req_pos) || sd->status.inventory[n].equip != 0 || sd->status.inventory[n].attribute==1 ) { // [Valaris]
  8245. clif_equipitemack(sd,n,0,ITEM_EQUIP_ACK_FAIL); // fail
  8246. return false;
  8247. }
  8248. if( sd->sc.count && (sd->sc.data[SC_BERSERK] || sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  8249. sd->sc.data[SC_KYOUGAKU] || (sd->sc.data[SC_PYROCLASTIC] && sd->inventory_data[n]->type == IT_WEAPON)) ) {
  8250. clif_equipitemack(sd,n,0,ITEM_EQUIP_ACK_FAIL); //Fail
  8251. return false;
  8252. }
  8253. if (id->flag.bindOnEquip && !sd->status.inventory[n].bound) {
  8254. sd->status.inventory[n].bound = (char)battle_config.default_bind_on_equip;
  8255. clif_notify_bindOnEquip(sd,n);
  8256. }
  8257. if(pos == EQP_ACC) { //Accesories should only go in one of the two,
  8258. pos = req_pos&EQP_ACC;
  8259. if (pos == EQP_ACC) //User specified both slots..
  8260. pos = sd->equip_index[EQI_ACC_R] >= 0 ? EQP_ACC_L : EQP_ACC_R;
  8261. }
  8262. if(pos == EQP_SHADOW_ACC) { // Shadow System
  8263. pos = req_pos&EQP_SHADOW_ACC;
  8264. if (pos == EQP_SHADOW_ACC)
  8265. pos = sd->equip_index[EQI_SHADOW_ACC_L] >= 0 ? EQP_SHADOW_ACC_R : EQP_SHADOW_ACC_L;
  8266. }
  8267. if(pos == EQP_ARMS && id->equip == EQP_HAND_R) { //Dual wield capable weapon.
  8268. pos = (req_pos&EQP_ARMS);
  8269. if (pos == EQP_ARMS) //User specified both slots, pick one for them.
  8270. pos = sd->equip_index[EQI_HAND_R] >= 0 ? EQP_HAND_L : EQP_HAND_R;
  8271. }
  8272. if (pos&EQP_HAND_R && battle_config.use_weapon_skill_range&BL_PC) {
  8273. //Update skill-block range database when weapon range changes. [Skotlex]
  8274. i = sd->equip_index[EQI_HAND_R];
  8275. if (i < 0 || !sd->inventory_data[i]) //No data, or no weapon equipped
  8276. flag = 1;
  8277. else
  8278. flag = id->range != sd->inventory_data[i]->range;
  8279. }
  8280. for(i=0;i<EQI_MAX;i++) {
  8281. if(pos & equip_pos[i]) {
  8282. if(sd->equip_index[i] >= 0) //Slot taken, remove item from there.
  8283. pc_unequipitem(sd,sd->equip_index[i],2);
  8284. sd->equip_index[i] = n;
  8285. }
  8286. }
  8287. if(pos==EQP_AMMO) {
  8288. clif_arrowequip(sd,n);
  8289. clif_arrow_fail(sd,3);
  8290. }
  8291. else
  8292. clif_equipitemack(sd,n,pos,ITEM_EQUIP_ACK_OK);
  8293. sd->status.inventory[n].equip=pos;
  8294. if(pos & EQP_HAND_R) {
  8295. if(id)
  8296. sd->weapontype1 = id->look;
  8297. else
  8298. sd->weapontype1 = 0;
  8299. pc_calcweapontype(sd);
  8300. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8301. }
  8302. if(pos & EQP_HAND_L) {
  8303. if(id) {
  8304. if(id->type == IT_WEAPON) {
  8305. sd->status.shield = 0;
  8306. sd->weapontype2 = id->look;
  8307. }
  8308. else
  8309. if(id->type == IT_ARMOR) {
  8310. sd->status.shield = id->look;
  8311. sd->weapontype2 = 0;
  8312. }
  8313. }
  8314. else
  8315. sd->status.shield = sd->weapontype2 = 0;
  8316. pc_calcweapontype(sd);
  8317. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8318. }
  8319. //Added check to prevent sending the same look on multiple slots ->
  8320. //causes client to redraw item on top of itself. (suggested by Lupus)
  8321. if(pos & EQP_HEAD_LOW && pc_checkequip(sd,EQP_COSTUME_HEAD_LOW) == -1) {
  8322. if(id && !(pos&(EQP_HEAD_TOP|EQP_HEAD_MID)))
  8323. sd->status.head_bottom = id->look;
  8324. else
  8325. sd->status.head_bottom = 0;
  8326. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  8327. }
  8328. if(pos & EQP_HEAD_TOP && pc_checkequip(sd,EQP_COSTUME_HEAD_TOP) == -1) {
  8329. if(id)
  8330. sd->status.head_top = id->look;
  8331. else
  8332. sd->status.head_top = 0;
  8333. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  8334. }
  8335. if(pos & EQP_HEAD_MID && pc_checkequip(sd,EQP_COSTUME_HEAD_MID) == -1) {
  8336. if(id && !(pos&EQP_HEAD_TOP))
  8337. sd->status.head_mid = id->look;
  8338. else
  8339. sd->status.head_mid = 0;
  8340. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8341. }
  8342. if(pos & EQP_COSTUME_HEAD_TOP) {
  8343. if(id){
  8344. sd->status.head_top = id->look;
  8345. } else
  8346. sd->status.head_top = 0;
  8347. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  8348. }
  8349. if(pos & EQP_COSTUME_HEAD_MID) {
  8350. if(id && !(pos&EQP_HEAD_TOP)){
  8351. sd->status.head_mid = id->look;
  8352. } else
  8353. sd->status.head_mid = 0;
  8354. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8355. }
  8356. if(pos & EQP_COSTUME_HEAD_LOW) {
  8357. if(id && !(pos&(EQP_HEAD_TOP|EQP_HEAD_MID))){
  8358. sd->status.head_bottom = id->look;
  8359. } else
  8360. sd->status.head_bottom = 0;
  8361. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  8362. }
  8363. if(pos & EQP_SHOES)
  8364. clif_changelook(&sd->bl,LOOK_SHOES,0);
  8365. if(pos&EQP_GARMENT && pc_checkequip(sd,EQP_COSTUME_GARMENT) == -1) {
  8366. sd->status.robe = id ? id->look : 0;
  8367. clif_changelook(&sd->bl, LOOK_ROBE, sd->status.robe);
  8368. }
  8369. if(pos & EQP_COSTUME_GARMENT) {
  8370. sd->status.robe = id ? id->look : 0;
  8371. clif_changelook(&sd->bl,LOOK_ROBE,sd->status.robe);
  8372. }
  8373. pc_checkallowskill(sd); //Check if status changes should be halted.
  8374. iflag = sd->npc_item_flag;
  8375. /* check for combos (MUST be before status_calc_pc) */
  8376. if( id->combos_count )
  8377. pc_checkcombo(sd,id);
  8378. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  8379. ; //No cards
  8380. else {
  8381. for( i = 0; i < id->slot; i++ ) {
  8382. struct item_data *data;
  8383. if (!sd->status.inventory[n].card[i])
  8384. continue;
  8385. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  8386. if( data->combos_count )
  8387. pc_checkcombo(sd,data);
  8388. }
  8389. }
  8390. }
  8391. status_calc_pc(sd,SCO_NONE);
  8392. if (flag) //Update skill data
  8393. clif_skillinfoblock(sd);
  8394. //OnEquip script [Skotlex]
  8395. if (id) {
  8396. //only run the script if item isn't restricted
  8397. if (id->equip_script && (pc_has_permission(sd,PC_PERM_USE_ALL_EQUIPMENT) || !itemdb_isNoEquip(id,sd->bl.m)))
  8398. run_script(id->equip_script,0,sd->bl.id,fake_nd->bl.id);
  8399. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  8400. ; //No cards
  8401. else {
  8402. for( i = 0; i < id->slot; i++ ) {
  8403. struct item_data *data;
  8404. if (!sd->status.inventory[n].card[i])
  8405. continue;
  8406. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  8407. if (data->equip_script && (pc_has_permission(sd,PC_PERM_USE_ALL_EQUIPMENT) || !itemdb_isNoEquip(data,sd->bl.m)))
  8408. run_script(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
  8409. }
  8410. }
  8411. }
  8412. }
  8413. sd->npc_item_flag = iflag;
  8414. return true;
  8415. }
  8416. /*==========================================
  8417. * Called when attemting to unequip an item from player
  8418. * type:
  8419. * 0 - only unequip
  8420. * 1 - calculate status after unequipping
  8421. * 2 - force unequip
  8422. * return: false - fail; true - success
  8423. *------------------------------------------*/
  8424. bool pc_unequipitem(struct map_session_data *sd, int n, int flag) {
  8425. int i, iflag;
  8426. bool status_cacl = false;
  8427. nullpo_retr(false,sd);
  8428. if (n < 0 || n >= MAX_INVENTORY) {
  8429. clif_unequipitemack(sd,0,0,0);
  8430. return false;
  8431. }
  8432. if (!sd->status.inventory[n].equip) {
  8433. clif_unequipitemack(sd,n,0,0);
  8434. return false; //Nothing to unequip
  8435. }
  8436. // status change that makes player cannot unequip equipment
  8437. if (!(flag&2) && sd->sc.count &&
  8438. (sd->sc.data[SC_BERSERK] ||
  8439. sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  8440. sd->sc.data[SC__BLOODYLUST] ||
  8441. sd->sc.data[SC_KYOUGAKU] ||
  8442. (sd->sc.data[SC_PYROCLASTIC] &&
  8443. sd->inventory_data[n]->type == IT_WEAPON))) // can't switch weapon
  8444. {
  8445. clif_unequipitemack(sd,n,0,0);
  8446. return false;
  8447. }
  8448. if (battle_config.battle_log)
  8449. ShowInfo("unequip %d %x:%x\n",n,pc_equippoint(sd,n),sd->status.inventory[n].equip);
  8450. for(i = 0; i < EQI_MAX; i++) {
  8451. if (sd->status.inventory[n].equip & equip_pos[i])
  8452. sd->equip_index[i] = -1;
  8453. }
  8454. if(sd->status.inventory[n].equip & EQP_HAND_R) {
  8455. sd->weapontype1 = 0;
  8456. sd->status.weapon = sd->weapontype2;
  8457. pc_calcweapontype(sd);
  8458. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8459. if( !battle_config.dancing_weaponswitch_fix )
  8460. status_change_end(&sd->bl, SC_DANCING, INVALID_TIMER); // Unequipping => stop dancing.
  8461. }
  8462. if(sd->status.inventory[n].equip & EQP_HAND_L) {
  8463. sd->status.shield = sd->weapontype2 = 0;
  8464. pc_calcweapontype(sd);
  8465. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8466. }
  8467. if(sd->status.inventory[n].equip & EQP_HEAD_LOW && pc_checkequip(sd,EQP_COSTUME_HEAD_LOW) == -1 ) {
  8468. sd->status.head_bottom = 0;
  8469. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  8470. }
  8471. if(sd->status.inventory[n].equip & EQP_HEAD_TOP && pc_checkequip(sd,EQP_COSTUME_HEAD_TOP) == -1 ) {
  8472. sd->status.head_top = 0;
  8473. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  8474. }
  8475. if(sd->status.inventory[n].equip & EQP_HEAD_MID && pc_checkequip(sd,EQP_COSTUME_HEAD_MID) == -1 ) {
  8476. sd->status.head_mid = 0;
  8477. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8478. }
  8479. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_TOP) {
  8480. sd->status.head_top = ( pc_checkequip(sd,EQP_HEAD_TOP) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_TOP)]->look : 0;
  8481. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  8482. }
  8483. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_MID) {
  8484. sd->status.head_mid = ( pc_checkequip(sd,EQP_HEAD_MID) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_MID)]->look : 0;
  8485. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8486. }
  8487. if(sd->status.inventory[n].equip & EQP_COSTUME_HEAD_LOW) {
  8488. sd->status.head_bottom = ( pc_checkequip(sd,EQP_HEAD_LOW) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_HEAD_LOW)]->look : 0;
  8489. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  8490. }
  8491. if(sd->status.inventory[n].equip & EQP_SHOES)
  8492. clif_changelook(&sd->bl,LOOK_SHOES,0);
  8493. if(sd->status.inventory[n].equip&EQP_GARMENT && pc_checkequip(sd,EQP_COSTUME_GARMENT) == -1) {
  8494. sd->status.robe = 0;
  8495. clif_changelook(&sd->bl, LOOK_ROBE, 0);
  8496. }
  8497. if(sd->status.inventory[n].equip & EQP_COSTUME_GARMENT) {
  8498. sd->status.robe = ( pc_checkequip(sd,EQP_GARMENT) >= 0 ) ? sd->inventory_data[pc_checkequip(sd,EQP_GARMENT)]->look : 0;
  8499. clif_changelook(&sd->bl,LOOK_ROBE,sd->status.robe);
  8500. }
  8501. clif_unequipitemack(sd,n,sd->status.inventory[n].equip,1);
  8502. status_change_end(&sd->bl,SC_HEAT_BARREL,INVALID_TIMER);
  8503. // On weapon change (right and left hand)
  8504. if ((sd->status.inventory[n].equip & EQP_ARMS) && sd->inventory_data[n]->type == IT_WEAPON) {
  8505. if (!sd->sc.data[SC_SEVENWIND] || sd->sc.data[SC_ASPERSIO]) //Check for seven wind (but not level seven!)
  8506. skill_enchant_elemental_end(&sd->bl, SC_NONE);
  8507. status_change_end(&sd->bl, SC_FEARBREEZE, INVALID_TIMER);
  8508. status_change_end(&sd->bl, SC_EXEEDBREAK, INVALID_TIMER);
  8509. status_change_end(&sd->bl, SC_P_ALTER, INVALID_TIMER);
  8510. }
  8511. // On armor change
  8512. if (sd->status.inventory[n].equip & EQP_ARMOR) {
  8513. if (sd->sc.data[SC_HOVERING] && sd->inventory_data[n]->nameid == ITEMID_HOVERING_BOOSTER)
  8514. status_change_end(&sd->bl, SC_HOVERING, INVALID_TIMER);
  8515. //status_change_end(&sd->bl, SC_BENEDICTIO, INVALID_TIMER); // No longer is removed? Need confirmation
  8516. status_change_end(&sd->bl, SC_ARMOR_RESIST, INVALID_TIMER);
  8517. }
  8518. // On ammo change
  8519. if (sd->inventory_data[n]->type == IT_AMMO)
  8520. status_change_end(&sd->bl, SC_P_ALTER, INVALID_TIMER);
  8521. if( sd->state.autobonus&sd->status.inventory[n].equip )
  8522. sd->state.autobonus &= ~sd->status.inventory[n].equip; //Check for activated autobonus [Inkfish]
  8523. sd->status.inventory[n].equip = 0;
  8524. iflag = sd->npc_item_flag;
  8525. /* check for combos (MUST be before status_calc_pc) */
  8526. if ( sd->inventory_data[n] ) {
  8527. if( sd->inventory_data[n]->combos_count ) {
  8528. if( pc_removecombo(sd,sd->inventory_data[n]) )
  8529. status_cacl = true;
  8530. } if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  8531. ; //No cards
  8532. else {
  8533. for( i = 0; i < sd->inventory_data[n]->slot; i++ ) {
  8534. struct item_data *data;
  8535. if (!sd->status.inventory[n].card[i])
  8536. continue;
  8537. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  8538. if( data->combos_count ) {
  8539. if( pc_removecombo(sd,data) )
  8540. status_cacl = true;
  8541. }
  8542. }
  8543. }
  8544. }
  8545. }
  8546. if(flag&1 || status_cacl) {
  8547. pc_checkallowskill(sd);
  8548. status_calc_pc(sd,SCO_NONE);
  8549. }
  8550. if(sd->sc.data[SC_SIGNUMCRUCIS] && !battle_check_undead(sd->battle_status.race,sd->battle_status.def_ele))
  8551. status_change_end(&sd->bl, SC_SIGNUMCRUCIS, INVALID_TIMER);
  8552. //OnUnEquip script [Skotlex]
  8553. if (sd->inventory_data[n]) {
  8554. if (sd->inventory_data[n]->unequip_script)
  8555. run_script(sd->inventory_data[n]->unequip_script,0,sd->bl.id,fake_nd->bl.id);
  8556. if(itemdb_isspecial(sd->status.inventory[n].card[0]))
  8557. ; //No cards
  8558. else {
  8559. for( i = 0; i < sd->inventory_data[n]->slot; i++ ) {
  8560. struct item_data *data;
  8561. if (!sd->status.inventory[n].card[i])
  8562. continue;
  8563. if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) {
  8564. if( data->unequip_script )
  8565. run_script(data->unequip_script,0,sd->bl.id,fake_nd->bl.id);
  8566. }
  8567. }
  8568. }
  8569. }
  8570. sd->npc_item_flag = iflag;
  8571. return true;
  8572. }
  8573. /*==========================================
  8574. * Checking if player (sd) has an invalid item
  8575. * and is unequiped on map load (item_noequip)
  8576. *------------------------------------------*/
  8577. void pc_checkitem(struct map_session_data *sd) {
  8578. int i, calc_flag = 0;
  8579. struct item it;
  8580. nullpo_retv(sd);
  8581. if( sd->state.vending ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
  8582. return;
  8583. pc_check_available_item(sd); // Check for invalid(ated) items.
  8584. for( i = 0; i < MAX_INVENTORY; i++ ) {
  8585. it = sd->status.inventory[i];
  8586. if( it.nameid == 0 )
  8587. continue;
  8588. if( !it.equip )
  8589. continue;
  8590. if( it.equip&~pc_equippoint(sd,i) ) {
  8591. pc_unequipitem(sd, i, 2);
  8592. calc_flag = 1;
  8593. continue;
  8594. }
  8595. if( !pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT) && !battle_config.allow_equip_restricted_item && itemdb_isNoEquip(sd->inventory_data[i], sd->bl.m) ) {
  8596. pc_unequipitem(sd, i, 2);
  8597. calc_flag = 1;
  8598. continue;
  8599. }
  8600. }
  8601. if( calc_flag && sd->state.active ) {
  8602. pc_checkallowskill(sd);
  8603. status_calc_pc(sd,SCO_NONE);
  8604. }
  8605. }
  8606. /*==========================================
  8607. * Checks for unavailable items and removes them.
  8608. *------------------------------------------*/
  8609. void pc_check_available_item(struct map_session_data *sd)
  8610. {
  8611. int i;
  8612. unsigned short nameid;
  8613. char output[256];
  8614. nullpo_retv(sd);
  8615. if (battle_config.item_check&0x1) { // Check for invalid(ated) items in inventory.
  8616. for(i = 0; i < MAX_INVENTORY; i++) {
  8617. nameid = sd->status.inventory[i].nameid;
  8618. if (!nameid)
  8619. continue;
  8620. if (!itemdb_available(nameid)) {
  8621. sprintf(output, msg_txt(sd, 709), nameid); // Item %hu has been removed from your inventory.
  8622. clif_displaymessage(sd->fd, output);
  8623. ShowWarning("Removed invalid/disabled item id %hu from inventory (amount=%d, char_id=%d).\n", nameid, sd->status.inventory[i].amount, sd->status.char_id);
  8624. pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
  8625. continue;
  8626. }
  8627. if (!sd->status.inventory[i].unique_id && !itemdb_isstackable(nameid))
  8628. sd->status.inventory[i].unique_id = pc_generate_unique_id(sd);
  8629. }
  8630. }
  8631. if (battle_config.item_check&0x2) { // Check for invalid(ated) items in cart.
  8632. for(i = 0; i < MAX_CART; i++) {
  8633. nameid = sd->status.cart[i].nameid;
  8634. if (!nameid)
  8635. continue;
  8636. if (!itemdb_available(nameid)) {
  8637. sprintf(output, msg_txt(sd, 710), nameid); // Item %hu has been removed from your cart.
  8638. clif_displaymessage(sd->fd, output);
  8639. ShowWarning("Removed invalid/disabled item id %hu from cart (amount=%d, char_id=%d).\n", nameid, sd->status.cart[i].amount, sd->status.char_id);
  8640. pc_cart_delitem(sd, i, sd->status.cart[i].amount, 0, LOG_TYPE_OTHER);
  8641. continue;
  8642. }
  8643. if (!sd->status.cart[i].unique_id && !itemdb_isstackable(nameid))
  8644. sd->status.cart[i].unique_id = pc_generate_unique_id(sd);
  8645. }
  8646. }
  8647. if (battle_config.item_check&0x4) { // Check for invalid(ated) items in storage.
  8648. for(i = 0; i < sd->storage_size; i++) {
  8649. nameid = sd->status.storage.items[i].nameid;
  8650. if (!nameid)
  8651. continue;
  8652. if (!itemdb_available(nameid)) {
  8653. sprintf(output, msg_txt(sd, 711), nameid); // Item %hu has been removed from your storage.
  8654. clif_displaymessage(sd->fd, output);
  8655. ShowWarning("Removed invalid/disabled item id %hu from storage (amount=%d, char_id=%d).\n", nameid, sd->status.storage.items[i].amount, sd->status.char_id);
  8656. storage_delitem(sd, i, sd->status.storage.items[i].amount);
  8657. continue;
  8658. }
  8659. if (!sd->status.storage.items[i].unique_id && !itemdb_isstackable(nameid))
  8660. sd->status.storage.items[i].unique_id = pc_generate_unique_id(sd);
  8661. }
  8662. }
  8663. }
  8664. /*==========================================
  8665. * Update PVP rank for sd1 in cmp to sd2
  8666. *------------------------------------------*/
  8667. static int pc_calc_pvprank_sub(struct block_list *bl,va_list ap)
  8668. {
  8669. struct map_session_data *sd1,*sd2;
  8670. sd1=(struct map_session_data *)bl;
  8671. sd2=va_arg(ap,struct map_session_data *);
  8672. if( sd1->sc.option&OPTION_INVISIBLE || sd2->sc.option&OPTION_INVISIBLE )
  8673. {// cannot register pvp rank for hidden GMs
  8674. return 0;
  8675. }
  8676. if( sd1->pvp_point > sd2->pvp_point )
  8677. sd2->pvp_rank++;
  8678. return 0;
  8679. }
  8680. /*==========================================
  8681. * Calculate new rank beetween all present players (map_foreachinarea)
  8682. * and display result
  8683. *------------------------------------------*/
  8684. int pc_calc_pvprank(struct map_session_data *sd)
  8685. {
  8686. int old = sd->pvp_rank;
  8687. struct map_data *m = &map[sd->bl.m];
  8688. sd->pvp_rank=1;
  8689. map_foreachinmap(pc_calc_pvprank_sub,sd->bl.m,BL_PC,sd);
  8690. if(old!=sd->pvp_rank || sd->pvp_lastusers!=m->users_pvp)
  8691. clif_pvpset(sd,sd->pvp_rank,sd->pvp_lastusers=m->users_pvp,0);
  8692. return sd->pvp_rank;
  8693. }
  8694. /*==========================================
  8695. * Calculate next sd ranking calculation from config
  8696. *------------------------------------------*/
  8697. int pc_calc_pvprank_timer(int tid, unsigned int tick, int id, intptr_t data)
  8698. {
  8699. struct map_session_data *sd;
  8700. sd=map_id2sd(id);
  8701. if(sd==NULL)
  8702. return 0;
  8703. sd->pvp_timer = INVALID_TIMER;
  8704. if( sd->sc.option&OPTION_INVISIBLE )
  8705. {// do not calculate the pvp rank for a hidden GM
  8706. return 0;
  8707. }
  8708. if( pc_calc_pvprank(sd) > 0 )
  8709. sd->pvp_timer = add_timer(gettick()+PVP_CALCRANK_INTERVAL,pc_calc_pvprank_timer,id,data);
  8710. return 0;
  8711. }
  8712. /*==========================================
  8713. * Checking if sd is married
  8714. * Return:
  8715. * partner_id = yes
  8716. * 0 = no
  8717. *------------------------------------------*/
  8718. int pc_ismarried(struct map_session_data *sd)
  8719. {
  8720. if(sd == NULL)
  8721. return -1;
  8722. if(sd->status.partner_id > 0)
  8723. return sd->status.partner_id;
  8724. else
  8725. return 0;
  8726. }
  8727. /*==========================================
  8728. * Marry player sd to player dstsd
  8729. * Return:
  8730. * false = fail
  8731. * true = success
  8732. *------------------------------------------*/
  8733. bool pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd)
  8734. {
  8735. if(sd == NULL || dstsd == NULL ||
  8736. sd->status.partner_id > 0 || dstsd->status.partner_id > 0 ||
  8737. (sd->class_&JOBL_BABY) || (dstsd->class_&JOBL_BABY))
  8738. return false;
  8739. sd->status.partner_id = dstsd->status.char_id;
  8740. dstsd->status.partner_id = sd->status.char_id;
  8741. return true;
  8742. }
  8743. /*==========================================
  8744. * Divorce sd from its partner
  8745. * Return:
  8746. * false = fail
  8747. * true = success
  8748. *------------------------------------------*/
  8749. bool pc_divorce(struct map_session_data *sd)
  8750. {
  8751. struct map_session_data *p_sd;
  8752. int i;
  8753. if( sd == NULL || !pc_ismarried(sd) )
  8754. return false;
  8755. if( !sd->status.partner_id )
  8756. return false; // Char is not married
  8757. if( (p_sd = map_charid2sd(sd->status.partner_id)) == NULL )
  8758. { // Lets char server do the divorce
  8759. if( chrif_divorce(sd->status.char_id, sd->status.partner_id) )
  8760. return false; // No char server connected
  8761. return true;
  8762. }
  8763. // Both players online, lets do the divorce manually
  8764. sd->status.partner_id = 0;
  8765. p_sd->status.partner_id = 0;
  8766. for( i = 0; i < MAX_INVENTORY; i++ )
  8767. {
  8768. if( sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F )
  8769. pc_delitem(sd, i, 1, 0, 0, LOG_TYPE_OTHER);
  8770. if( p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F )
  8771. pc_delitem(p_sd, i, 1, 0, 0, LOG_TYPE_OTHER);
  8772. }
  8773. clif_divorced(sd, p_sd->status.name);
  8774. clif_divorced(p_sd, sd->status.name);
  8775. return true;
  8776. }
  8777. /**
  8778. * Get the partner map_session_data of a player
  8779. * @param sd : the husband|wife session
  8780. * @return partner session or NULL
  8781. */
  8782. struct map_session_data *pc_get_partner(struct map_session_data *sd){
  8783. if (!sd || !pc_ismarried(sd))
  8784. return NULL;
  8785. return map_charid2sd(sd->status.partner_id);
  8786. }
  8787. /**
  8788. * Get the father map_session_data of a player
  8789. * @param sd : the baby session
  8790. * @return father session or NULL
  8791. */
  8792. struct map_session_data *pc_get_father (struct map_session_data *sd){
  8793. if (!sd || !(sd->class_&JOBL_BABY) || !sd->status.father)
  8794. return NULL;
  8795. return map_charid2sd(sd->status.father);
  8796. }
  8797. /**
  8798. * Get the mother map_session_data of a player
  8799. * @param sd : the baby session
  8800. * @return mother session or NULL
  8801. */
  8802. struct map_session_data *pc_get_mother (struct map_session_data *sd){
  8803. if (!sd || !(sd->class_&JOBL_BABY) || !sd->status.mother)
  8804. return NULL;
  8805. return map_charid2sd(sd->status.mother);
  8806. }
  8807. /*==========================================
  8808. * Get sd children charid. (Need to be married)
  8809. *------------------------------------------*/
  8810. struct map_session_data *pc_get_child (struct map_session_data *sd)
  8811. {
  8812. if (!sd || !pc_ismarried(sd) || !sd->status.child)
  8813. // charid2sd returns NULL if not found
  8814. return NULL;
  8815. return map_charid2sd(sd->status.child);
  8816. }
  8817. /*==========================================
  8818. * Set player sd to bleed. (losing hp and/or sp each diff_tick)
  8819. *------------------------------------------*/
  8820. void pc_bleeding (struct map_session_data *sd, unsigned int diff_tick)
  8821. {
  8822. int hp = 0, sp = 0;
  8823. if( pc_isdead(sd) )
  8824. return;
  8825. if (sd->hp_loss.value) {
  8826. sd->hp_loss.tick += diff_tick;
  8827. while (sd->hp_loss.tick >= sd->hp_loss.rate) {
  8828. hp += sd->hp_loss.value;
  8829. sd->hp_loss.tick -= sd->hp_loss.rate;
  8830. }
  8831. if(hp >= sd->battle_status.hp)
  8832. hp = sd->battle_status.hp-1; //Script drains cannot kill you.
  8833. }
  8834. if (sd->sp_loss.value) {
  8835. sd->sp_loss.tick += diff_tick;
  8836. while (sd->sp_loss.tick >= sd->sp_loss.rate) {
  8837. sp += sd->sp_loss.value;
  8838. sd->sp_loss.tick -= sd->sp_loss.rate;
  8839. }
  8840. }
  8841. if (hp > 0 || sp > 0)
  8842. status_zap(&sd->bl, hp, sp);
  8843. }
  8844. //Character regen. Flag is used to know which types of regen can take place.
  8845. //&1: HP regen
  8846. //&2: SP regen
  8847. void pc_regen (struct map_session_data *sd, unsigned int diff_tick)
  8848. {
  8849. int hp = 0, sp = 0;
  8850. if (sd->hp_regen.value) {
  8851. sd->hp_regen.tick += diff_tick;
  8852. while (sd->hp_regen.tick >= sd->hp_regen.rate) {
  8853. hp += sd->hp_regen.value;
  8854. sd->hp_regen.tick -= sd->hp_regen.rate;
  8855. }
  8856. }
  8857. if (sd->sp_regen.value) {
  8858. sd->sp_regen.tick += diff_tick;
  8859. while (sd->sp_regen.tick >= sd->sp_regen.rate) {
  8860. sp += sd->sp_regen.value;
  8861. sd->sp_regen.tick -= sd->sp_regen.rate;
  8862. }
  8863. }
  8864. if (hp > 0 || sp > 0)
  8865. status_heal(&sd->bl, hp, sp, 0);
  8866. }
  8867. /*==========================================
  8868. * Memo player sd savepoint. (map,x,y)
  8869. *------------------------------------------*/
  8870. void pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y)
  8871. {
  8872. nullpo_retv(sd);
  8873. sd->status.save_point.map = mapindex;
  8874. sd->status.save_point.x = x;
  8875. sd->status.save_point.y = y;
  8876. }
  8877. /*==========================================
  8878. * Save 1 player data at autosave interval
  8879. *------------------------------------------*/
  8880. static int pc_autosave(int tid, unsigned int tick, int id, intptr_t data)
  8881. {
  8882. int interval;
  8883. struct s_mapiterator* iter;
  8884. struct map_session_data* sd;
  8885. static int last_save_id = 0, save_flag = 0;
  8886. if(save_flag == 2) //Someone was saved on last call, normal cycle
  8887. save_flag = 0;
  8888. else
  8889. save_flag = 1; //Noone was saved, so save first found char.
  8890. iter = mapit_getallusers();
  8891. for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
  8892. {
  8893. if(sd->bl.id == last_save_id && save_flag != 1) {
  8894. save_flag = 1;
  8895. continue;
  8896. }
  8897. if(save_flag != 1) //Not our turn to save yet.
  8898. continue;
  8899. //Save char.
  8900. last_save_id = sd->bl.id;
  8901. save_flag = 2;
  8902. #ifdef VIP_ENABLE
  8903. if(sd->vip.enabled) //check if we're still vip
  8904. chrif_req_login_operation(1, sd->status.name, 6, 0, 1, 0);
  8905. #endif
  8906. chrif_save(sd,0);
  8907. break;
  8908. }
  8909. mapit_free(iter);
  8910. interval = autosave_interval/(map_usercount()+1);
  8911. if(interval < minsave_interval)
  8912. interval = minsave_interval;
  8913. add_timer(gettick()+interval,pc_autosave,0,0);
  8914. return 0;
  8915. }
  8916. static int pc_daynight_timer_sub(struct map_session_data *sd,va_list ap)
  8917. {
  8918. if (sd->state.night != night_flag && map[sd->bl.m].flag.nightenabled)
  8919. { //Night/day state does not match.
  8920. clif_status_load(&sd->bl, SI_NIGHT, night_flag); //New night effect by dynamix [Skotlex]
  8921. sd->state.night = night_flag;
  8922. return 1;
  8923. }
  8924. return 0;
  8925. }
  8926. /*================================================
  8927. * timer to do the day [Yor]
  8928. * data: 0 = called by timer, 1 = gmcommand/script
  8929. *------------------------------------------------*/
  8930. int map_day_timer(int tid, unsigned int tick, int id, intptr_t data)
  8931. {
  8932. char tmp_soutput[1024];
  8933. if (data == 0 && battle_config.day_duration <= 0) // if we want a day
  8934. return 0;
  8935. if (!night_flag)
  8936. return 0; //Already day.
  8937. night_flag = 0; // 0=day, 1=night [Yor]
  8938. map_foreachpc(pc_daynight_timer_sub);
  8939. strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,502) : msg_txt(NULL,60)); // The day has arrived!
  8940. intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, BC_DEFAULT);
  8941. return 0;
  8942. }
  8943. /*================================================
  8944. * timer to do the night [Yor]
  8945. * data: 0 = called by timer, 1 = gmcommand/script
  8946. *------------------------------------------------*/
  8947. int map_night_timer(int tid, unsigned int tick, int id, intptr_t data)
  8948. {
  8949. char tmp_soutput[1024];
  8950. if (data == 0 && battle_config.night_duration <= 0) // if we want a night
  8951. return 0;
  8952. if (night_flag)
  8953. return 0; //Already nigth.
  8954. night_flag = 1; // 0=day, 1=night [Yor]
  8955. map_foreachpc(pc_daynight_timer_sub);
  8956. strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,503) : msg_txt(NULL,59)); // The night has fallen...
  8957. intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, BC_DEFAULT);
  8958. return 0;
  8959. }
  8960. /**
  8961. * Attempt to stand up a player
  8962. * @param sd
  8963. * @param force Ignore the check, ask player to stand up. Used in some cases like pc_damage(), pc_revive(), etc
  8964. * @return True if success, Fals if failed
  8965. */
  8966. bool pc_setstand(struct map_session_data *sd, bool force){
  8967. nullpo_ret(sd);
  8968. // Cannot stand yet
  8969. // TODO: Move to SCS_NOSTAND [Cydh]
  8970. if (!force && &sd->sc && (sd->sc.data[SC_SITDOWN_FORCE] || sd->sc.data[SC_BANANA_BOMB_SITDOWN]))
  8971. return false;
  8972. status_change_end(&sd->bl, SC_TENSIONRELAX, INVALID_TIMER);
  8973. clif_status_load(&sd->bl,SI_SIT,0);
  8974. clif_standing(&sd->bl); //Inform area PC is standing
  8975. //Reset sitting tick.
  8976. sd->ssregen.tick.hp = sd->ssregen.tick.sp = 0;
  8977. sd->state.dead_sit = sd->vd.dead_sit = 0;
  8978. return true;
  8979. }
  8980. /**
  8981. * Mechanic (MADO GEAR)
  8982. **/
  8983. void pc_overheat(struct map_session_data *sd, int val) {
  8984. int heat = val, skill,
  8985. limit[] = { 10, 20, 28, 46, 66 };
  8986. if( !pc_ismadogear(sd) || sd->sc.data[SC_OVERHEAT] )
  8987. return; // already burning
  8988. skill = cap_value(pc_checkskill(sd,NC_MAINFRAME),0,4);
  8989. if( sd->sc.data[SC_OVERHEAT_LIMITPOINT] ) {
  8990. heat += sd->sc.data[SC_OVERHEAT_LIMITPOINT]->val1;
  8991. status_change_end(&sd->bl,SC_OVERHEAT_LIMITPOINT,INVALID_TIMER);
  8992. }
  8993. heat = max(0,heat); // Avoid negative HEAT
  8994. if( heat >= limit[skill] )
  8995. sc_start(&sd->bl,&sd->bl,SC_OVERHEAT,100,0,1000);
  8996. else
  8997. sc_start(&sd->bl,&sd->bl,SC_OVERHEAT_LIMITPOINT,100,heat,30000);
  8998. return;
  8999. }
  9000. /**
  9001. * Check if player is autolooting given itemID.
  9002. */
  9003. bool pc_isautolooting(struct map_session_data *sd, unsigned short nameid)
  9004. {
  9005. uint8 i = 0;
  9006. if (sd->state.autoloottype && sd->state.autoloottype&(1<<itemdb_type(nameid)))
  9007. return true;
  9008. if (!sd->state.autolooting)
  9009. return false;
  9010. if (sd->state.autolooting)
  9011. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == nameid);
  9012. return (i != AUTOLOOTITEM_SIZE);
  9013. }
  9014. /**
  9015. * Checks if player can use @/#command
  9016. * @param sd Player map session data
  9017. * @param command Command name without @/# and params
  9018. * @param type is it atcommand or charcommand
  9019. */
  9020. bool pc_can_use_command(struct map_session_data *sd, const char *command, AtCommandType type)
  9021. {
  9022. return pc_group_can_use_command(pc_get_group_id(sd), command, type);
  9023. }
  9024. /**
  9025. * Checks if commands used by a player should be logged
  9026. * according to their group setting.
  9027. * @param sd Player map session data
  9028. */
  9029. bool pc_should_log_commands(struct map_session_data *sd)
  9030. {
  9031. return pc_group_should_log_commands(pc_get_group_id(sd));
  9032. }
  9033. /**
  9034. * Spirit Charm expiration timer.
  9035. * @see TimerFunc
  9036. */
  9037. static int pc_spiritcharm_timer(int tid, unsigned int tick, int id, intptr_t data)
  9038. {
  9039. struct map_session_data *sd;
  9040. int i;
  9041. if ((sd = (struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type != BL_PC)
  9042. return 1;
  9043. if (sd->spiritcharm <= 0) {
  9044. ShowError("pc_spiritcharm_timer: %d spiritcharm's available. (aid=%d cid=%d tid=%d)\n", sd->spiritcharm, sd->status.account_id, sd->status.char_id, tid);
  9045. sd->spiritcharm = 0;
  9046. sd->spiritcharm_type = CHARM_TYPE_NONE;
  9047. return 0;
  9048. }
  9049. ARR_FIND(0, sd->spiritcharm, i, sd->spiritcharm_timer[i] == tid);
  9050. if (i == sd->spiritcharm) {
  9051. ShowError("pc_spiritcharm_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
  9052. return 0;
  9053. }
  9054. sd->spiritcharm--;
  9055. if (i != sd->spiritcharm)
  9056. memmove(sd->spiritcharm_timer + i, sd->spiritcharm_timer + i + 1, (sd->spiritcharm - i) * sizeof(int));
  9057. sd->spiritcharm_timer[sd->spiritcharm] = INVALID_TIMER;
  9058. if (sd->spiritcharm <= 0)
  9059. sd->spiritcharm_type = CHARM_TYPE_NONE;
  9060. clif_spiritcharm(sd);
  9061. return 0;
  9062. }
  9063. /**
  9064. * Adds a spirit charm.
  9065. * @param sd: Target character
  9066. * @param interval: Duration
  9067. * @param max: Maximum amount of charms to add
  9068. * @param type: Charm type (@see spirit_charm_types)
  9069. */
  9070. void pc_addspiritcharm(struct map_session_data *sd, int interval, int max, int type)
  9071. {
  9072. int tid, i;
  9073. nullpo_retv(sd);
  9074. if (sd->spiritcharm_type != CHARM_TYPE_NONE && type != sd->spiritcharm_type)
  9075. pc_delspiritcharm(sd, sd->spiritcharm, sd->spiritcharm_type);
  9076. if (max > MAX_SPIRITCHARM)
  9077. max = MAX_SPIRITCHARM;
  9078. if (sd->spiritcharm < 0)
  9079. sd->spiritcharm = 0;
  9080. if (sd->spiritcharm && sd->spiritcharm >= max) {
  9081. if (sd->spiritcharm_timer[0] != INVALID_TIMER)
  9082. delete_timer(sd->spiritcharm_timer[0], pc_spiritcharm_timer);
  9083. sd->spiritcharm--;
  9084. if (sd->spiritcharm != 0)
  9085. memmove(sd->spiritcharm_timer + 0, sd->spiritcharm_timer + 1, (sd->spiritcharm) * sizeof(int));
  9086. sd->spiritcharm_timer[sd->spiritcharm] = INVALID_TIMER;
  9087. }
  9088. tid = add_timer(gettick() + interval, pc_spiritcharm_timer, sd->bl.id, 0);
  9089. ARR_FIND(0, sd->spiritcharm, i, sd->spiritcharm_timer[i] == INVALID_TIMER || DIFF_TICK(get_timer(tid)->tick, get_timer(sd->spiritcharm_timer[i])->tick) < 0);
  9090. if (i != sd->spiritcharm)
  9091. memmove(sd->spiritcharm_timer + i + 1, sd->spiritcharm_timer + i, (sd->spiritcharm - i) * sizeof(int));
  9092. sd->spiritcharm_timer[i] = tid;
  9093. sd->spiritcharm++;
  9094. sd->spiritcharm_type = type;
  9095. clif_spiritcharm(sd);
  9096. }
  9097. /**
  9098. * Removes one or more spirit charms.
  9099. * @param sd: The target character
  9100. * @param count: Amount of charms to remove
  9101. * @param type: Type of charm to remove
  9102. */
  9103. void pc_delspiritcharm(struct map_session_data *sd, int count, int type)
  9104. {
  9105. int i;
  9106. nullpo_retv(sd);
  9107. if (sd->spiritcharm_type != type)
  9108. return;
  9109. if (sd->spiritcharm <= 0) {
  9110. sd->spiritcharm = 0;
  9111. return;
  9112. }
  9113. if (count <= 0)
  9114. return;
  9115. if (count > sd->spiritcharm)
  9116. count = sd->spiritcharm;
  9117. sd->spiritcharm -= count;
  9118. if (count > MAX_SPIRITCHARM)
  9119. count = MAX_SPIRITCHARM;
  9120. for (i = 0; i < count; i++) {
  9121. if (sd->spiritcharm_timer[i] != INVALID_TIMER) {
  9122. delete_timer(sd->spiritcharm_timer[i], pc_spiritcharm_timer);
  9123. sd->spiritcharm_timer[i] = INVALID_TIMER;
  9124. }
  9125. }
  9126. for (i = count; i < MAX_SPIRITCHARM; i++) {
  9127. sd->spiritcharm_timer[i - count] = sd->spiritcharm_timer[i];
  9128. sd->spiritcharm_timer[i] = INVALID_TIMER;
  9129. }
  9130. if (sd->spiritcharm <= 0)
  9131. sd->spiritcharm_type = CHARM_TYPE_NONE;
  9132. clif_spiritcharm(sd);
  9133. }
  9134. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  9135. /*==========================================
  9136. * Renewal EXP/Itemdrop rate modifier base on level penalty
  9137. * 1=exp 2=itemdrop
  9138. *------------------------------------------*/
  9139. int pc_level_penalty_mod(struct map_session_data *sd, int mob_level, uint32 mob_class, int type)
  9140. {
  9141. int diff, rate = 100, i;
  9142. int tmp;
  9143. nullpo_ret(sd);
  9144. diff = mob_level - sd->status.base_level;
  9145. if( diff < 0 )
  9146. diff = MAX_LEVEL + ( ~diff + 1 );
  9147. if((tmp = level_penalty[type][mob_class][diff] ) > 0 ) //use mobclass directly
  9148. return tmp;
  9149. //wtf is that for ? if penalty not found use the 1st one we found ?? ̂[lighta]
  9150. for( i = 0; i < CLASS_ALL; i++ ) {
  9151. if( ( tmp = level_penalty[type][i][diff] ) > 0 ) {
  9152. rate = tmp;
  9153. break;
  9154. }
  9155. }
  9156. return rate;
  9157. }
  9158. #endif
  9159. int pc_split_str(char *str,char **val,int num)
  9160. {
  9161. int i;
  9162. for (i=0; i<num && str; i++){
  9163. val[i] = str;
  9164. str = strchr(str,',');
  9165. if (str && i<num-1) //Do not remove a trailing comma.
  9166. *str++=0;
  9167. }
  9168. return i;
  9169. }
  9170. int pc_split_atoi(char* str, int* val, char sep, int max)
  9171. {
  9172. int i,j;
  9173. for (i=0; i<max; i++) {
  9174. if (!str) break;
  9175. val[i] = atoi(str);
  9176. str = strchr(str,sep);
  9177. if (str)
  9178. *str++=0;
  9179. }
  9180. //Zero up the remaining.
  9181. for(j=i; j < max; j++)
  9182. val[j] = 0;
  9183. return i;
  9184. }
  9185. int pc_split_atoui(char* str, unsigned int* val, char sep, int max)
  9186. {
  9187. static int warning=0;
  9188. int i,j;
  9189. for (i=0; i<max; i++) {
  9190. double f;
  9191. if (!str) break;
  9192. f = atof(str);
  9193. if (f < 0)
  9194. val[i] = 0;
  9195. else if (f > UINT_MAX) {
  9196. val[i] = UINT_MAX;
  9197. if (!warning) {
  9198. warning = 1;
  9199. ShowWarning("pc_readdb (exp.txt): Required exp per level is capped to %u\n", UINT_MAX);
  9200. }
  9201. } else
  9202. val[i] = (unsigned int)f;
  9203. str = strchr(str,sep);
  9204. if (str)
  9205. *str++=0;
  9206. }
  9207. //Zero up the remaining.
  9208. for(j=i; j < max; j++)
  9209. val[j] = 0;
  9210. return i;
  9211. }
  9212. /*==========================================
  9213. * sub DB reading.
  9214. * Function used to read skill_tree.txt
  9215. *------------------------------------------*/
  9216. static bool pc_readdb_skilltree(char* fields[], int columns, int current)
  9217. {
  9218. unsigned char joblv = 0, skill_lv;
  9219. uint16 skill_id;
  9220. int idx, class_;
  9221. unsigned int i, offset = 3, skill_idx;
  9222. class_ = atoi(fields[0]);
  9223. skill_id = (uint16)atoi(fields[1]);
  9224. skill_lv = (unsigned char)atoi(fields[2]);
  9225. if(columns==4+MAX_PC_SKILL_REQUIRE*2)
  9226. {// job level requirement extra column
  9227. joblv = (unsigned char)atoi(fields[3]);
  9228. offset++;
  9229. }
  9230. if(!pcdb_checkid(class_))
  9231. {
  9232. ShowWarning("pc_readdb_skilltree: Invalid job class %d specified.\n", class_);
  9233. return false;
  9234. }
  9235. idx = pc_class2idx(class_);
  9236. //This is to avoid adding two lines for the same skill. [Skotlex]
  9237. ARR_FIND( 0, MAX_SKILL_TREE, skill_idx, skill_tree[idx][skill_idx].id == 0 || skill_tree[idx][skill_idx].id == skill_id );
  9238. if( skill_idx == MAX_SKILL_TREE )
  9239. {
  9240. ShowWarning("pc_readdb_skilltree: Unable to load skill %hu into job %d's tree. Maximum number of skills per class has been reached.\n", skill_id, class_);
  9241. return false;
  9242. }
  9243. else if(skill_tree[idx][skill_idx].id)
  9244. {
  9245. ShowNotice("pc_readdb_skilltree: Overwriting skill %hu for job class %d.\n", skill_id, class_);
  9246. }
  9247. skill_tree[idx][skill_idx].id = skill_id;
  9248. skill_tree[idx][skill_idx].max = skill_lv;
  9249. skill_tree[idx][skill_idx].joblv = joblv;
  9250. for(i = 0; i < MAX_PC_SKILL_REQUIRE; i++)
  9251. {
  9252. skill_tree[idx][skill_idx].need[i].id = atoi(fields[i*2+offset]);
  9253. skill_tree[idx][skill_idx].need[i].lv = atoi(fields[i*2+offset+1]);
  9254. }
  9255. return true;
  9256. }
  9257. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  9258. static bool pc_readdb_levelpenalty(char* fields[], int columns, int current)
  9259. {
  9260. int type, class_, diff;
  9261. type = atoi(fields[0]); //1=experience, 2=item drop
  9262. class_ = atoi(fields[1]);
  9263. diff = atoi(fields[2]);
  9264. if( type != 1 && type != 2 ){
  9265. ShowWarning("pc_readdb_levelpenalty: Invalid type %d specified.\n", type);
  9266. return false;
  9267. }
  9268. if( !CHK_CLASS(class_) ){
  9269. ShowWarning("pc_readdb_levelpenalty: Invalid class %d specified.\n", class_);
  9270. return false;
  9271. }
  9272. diff = min(diff, MAX_LEVEL);
  9273. if( diff < 0 )
  9274. diff = min(MAX_LEVEL + ( ~(diff) + 1 ), MAX_LEVEL*2);
  9275. level_penalty[type][class_][diff] = atoi(fields[3]);
  9276. return true;
  9277. }
  9278. #endif
  9279. /** [Cydh]
  9280. * Calculates base hp of player. Reference: http://irowiki.org/wiki/Max_HP
  9281. * @param level Base level of player
  9282. * @param class_ Job ID @see enum e_job
  9283. * @return base_hp
  9284. */
  9285. static unsigned int pc_calc_basehp(uint16 level, uint16 class_) {
  9286. double base_hp;
  9287. uint16 i, idx = pc_class2idx(class_);
  9288. base_hp = 35 + level * (job_info[idx].hp_multiplicator/100.);
  9289. #ifndef RENEWAL
  9290. if(level >= 10 && (class_ == JOB_NINJA || class_ == JOB_GUNSLINGER)) base_hp += 90;
  9291. #endif
  9292. for (i = 2; i <= level; i++)
  9293. base_hp += floor(((job_info[idx].hp_factor/100.) * i) + 0.5); //Don't have round()
  9294. return (unsigned int)base_hp;
  9295. }
  9296. /** [Playtester]
  9297. * Calculates base sp of player.
  9298. * @param level Base level of player
  9299. * @param class_ Job ID @see enum e_job
  9300. * @return base_sp
  9301. */
  9302. static unsigned int pc_calc_basesp(uint16 level, uint16 class_) {
  9303. double base_sp;
  9304. uint16 idx = pc_class2idx(class_);
  9305. base_sp = 10 + floor(level * (job_info[idx].sp_factor / 100.));
  9306. switch (class_) {
  9307. case JOB_NINJA:
  9308. if (level >= 10)
  9309. base_sp -= 22;
  9310. else
  9311. base_sp = 11 + 3*level;
  9312. break;
  9313. case JOB_GUNSLINGER:
  9314. if (level > 10)
  9315. base_sp -= 18;
  9316. else
  9317. base_sp = 9 + 3*level;
  9318. break;
  9319. }
  9320. return (unsigned int)base_sp;
  9321. }
  9322. //Reading job_db1.txt line, (class,weight,HPFactor,HPMultiplicator,SPFactor,aspd/lvl...)
  9323. static bool pc_readdb_job1(char* fields[], int columns, int current){
  9324. int idx, class_;
  9325. unsigned int i;
  9326. class_ = atoi(fields[0]);
  9327. if (!pcdb_checkid(class_)) {
  9328. ShowWarning("status_readdb_job1: Invalid job class %d specified.\n", class_);
  9329. return false;
  9330. }
  9331. idx = pc_class2idx(class_);
  9332. job_info[idx].max_weight_base = atoi(fields[1]);
  9333. job_info[idx].hp_factor = atoi(fields[2]);
  9334. job_info[idx].hp_multiplicator = atoi(fields[3]);
  9335. job_info[idx].sp_factor = atoi(fields[4]);
  9336. #ifdef RENEWAL_ASPD
  9337. for(i = 0; i <= MAX_WEAPON_TYPE; i++)
  9338. #else
  9339. for(i = 0; i < MAX_WEAPON_TYPE; i++)
  9340. #endif
  9341. {
  9342. job_info[idx].aspd_base[i] = atoi(fields[i+5]);
  9343. }
  9344. return true;
  9345. }
  9346. //Reading job_db2.txt line (class,JobLv1,JobLv2,JobLv3,...)
  9347. static bool pc_readdb_job2(char* fields[], int columns, int current)
  9348. {
  9349. int idx, class_, i;
  9350. class_ = atoi(fields[0]);
  9351. if(!pcdb_checkid(class_))
  9352. {
  9353. ShowWarning("status_readdb_job2: Invalid job class %d specified.\n", class_);
  9354. return false;
  9355. }
  9356. idx = pc_class2idx(class_);
  9357. for(i = 1; i < columns; i++)
  9358. {
  9359. job_info[idx].job_bonus[i-1] = atoi(fields[i]);
  9360. }
  9361. return true;
  9362. }
  9363. //Reading job_exp.txt line
  9364. //Max Level,Class list,Type (0 - Base Exp; 1 - Job Exp),Exp/lvl...
  9365. static bool pc_readdb_job_exp(char* fields[], int columns, int current)
  9366. {
  9367. int idx, i, type;
  9368. int job_id,job_count,jobs[CLASS_COUNT];
  9369. unsigned int ui, maxlvl;
  9370. maxlvl = atoi(fields[0]);
  9371. if(maxlvl > MAX_LEVEL || maxlvl<1){
  9372. ShowError("pc_readdb_job_exp: Invalid maxlevel %d specified.\n", maxlvl);
  9373. return false;
  9374. }
  9375. if((maxlvl+3) > columns){ //nb values = (maxlvl-startlvl)+1-index1stvalue
  9376. ShowError("pc_readdb_job_exp: Number of columns %d defined is too low for max level %d.\n",columns,maxlvl);
  9377. return false;
  9378. }
  9379. type = atoi(fields[2]);
  9380. if(type < 0 || type > 1){
  9381. ShowError("pc_readdb_job_exp: Invalid type %d specified.\n", type);
  9382. return false;
  9383. }
  9384. job_count = pc_split_atoi(fields[1],jobs,':',CLASS_COUNT);
  9385. if (job_count < 1)
  9386. return false;
  9387. job_id = jobs[0];
  9388. if(!pcdb_checkid(job_id)){
  9389. ShowError("pc_readdb_job_exp: Invalid job class %d specified.\n", job_id);
  9390. return false;
  9391. }
  9392. idx = pc_class2idx(job_id);
  9393. job_info[idx].max_level[type] = maxlvl;
  9394. for(i=0; i<maxlvl; i++)
  9395. job_info[idx].exp_table[type][i] = ((uint32) atoi(fields[3+i]));
  9396. //Reverse check in case the array has a bunch of trailing zeros... [Skotlex]
  9397. //The reasoning behind the -2 is this... if the max level is 5, then the array
  9398. //should look like this:
  9399. //0: x, 1: x, 2: x: 3: x 4: 0 <- last valid value is at 3.
  9400. while ((ui = job_info[idx].max_level[type]) >= 2 && job_info[idx].exp_table[type][ui-2] <= 0)
  9401. job_info[idx].max_level[type]--;
  9402. if (job_info[idx].max_level[type] < maxlvl) {
  9403. ShowWarning("pc_readdb_job_exp: Specified max %u for job %d, but that job's exp table only goes up to level %u.\n", maxlvl, job_id, job_info[idx].max_level[type]);
  9404. ShowInfo("Filling the missing values with the last exp entry.\n");
  9405. //Fill the requested values with the last entry.
  9406. ui = (job_info[idx].max_level[type] <= 2? 0: job_info[idx].max_level[type]-2);
  9407. for (; ui+2 < maxlvl; ui++)
  9408. job_info[idx].exp_table[type][ui] = job_info[idx].exp_table[type][ui-1];
  9409. job_info[idx].max_level[type] = maxlvl;
  9410. }
  9411. // ShowInfo("%s - Class %d: %d\n", type?"Job":"Base", job_id, job_info[idx].max_level[type]);
  9412. for (i = 1; i < job_count; i++) {
  9413. job_id = jobs[i];
  9414. if (!pcdb_checkid(job_id)) {
  9415. ShowError("pc_readdb_job_exp: Invalid job ID %d.\n", job_id);
  9416. continue;
  9417. }
  9418. idx = pc_class2idx(job_id);
  9419. memcpy(job_info[idx].exp_table[type], job_info[pc_class2idx(jobs[0])].exp_table[type], sizeof(job_info[pc_class2idx(jobs[0])].exp_table[type]));
  9420. job_info[idx].max_level[type] = maxlvl;
  9421. // ShowInfo("%s - Class %d: %u\n", type?"Job":"Base", job_id, job_info[idx].max_level[type]);
  9422. }
  9423. return true;
  9424. }
  9425. /**
  9426. * #ifdef HP_SP_TABLES, reads 'job_basehpsp_db.txt to replace hp/sp results from formula
  9427. * startlvl,endlvl,class,type,values...
  9428. */
  9429. #ifdef HP_SP_TABLES
  9430. static bool pc_readdb_job_basehpsp(char* fields[], int columns, int current)
  9431. {
  9432. int i, startlvl, endlvl;
  9433. int job_count,jobs[CLASS_COUNT];
  9434. short type;
  9435. startlvl = atoi(fields[0]);
  9436. if(startlvl<1){
  9437. ShowError("pc_readdb_job_basehpsp: Invalid start level %d specified.\n", startlvl);
  9438. return false;
  9439. }
  9440. endlvl = atoi(fields[1]);
  9441. if(endlvl<1 || endlvl<startlvl){
  9442. ShowError("pc_readdb_job_basehpsp: Invalid end level %d specified.\n", endlvl);
  9443. return false;
  9444. }
  9445. if((endlvl-startlvl+1+4) > columns){ //nb values = (maxlvl-startlvl)+1-index1stvalue
  9446. ShowError("pc_readdb_job_basehpsp: Number of columns %d (needs %d) defined is too low for start level %d, max level %d.\n",columns,(endlvl-startlvl+1+4),startlvl,endlvl);
  9447. return false;
  9448. }
  9449. type = atoi(fields[3]);
  9450. if(type < 0 || type > 1){
  9451. ShowError("pc_readdb_job_basehpsp: Invalid type %d specified.\n", type);
  9452. return false;
  9453. }
  9454. job_count = pc_split_atoi(fields[2],jobs,':',CLASS_COUNT);
  9455. if (job_count < 1)
  9456. return false;
  9457. for (i = 0; i < job_count; i++) {
  9458. int idx, job_id = jobs[i], use_endlvl;
  9459. if (!pcdb_checkid(job_id)) {
  9460. ShowError("pc_readdb_job_basehpsp: Invalid job class %d specified.\n", job_id);
  9461. return false;
  9462. }
  9463. idx = pc_class2idx(job_id);
  9464. if (startlvl > job_info[idx].max_level[0]) {
  9465. ShowError("pc_readdb_job_basehpsp: Invalid start level %d specified.\n", startlvl);
  9466. return false;
  9467. }
  9468. //Just read until available max level for this job, don't use MAX_LEVEL!
  9469. use_endlvl = endlvl;
  9470. if (use_endlvl > job_info[idx].max_level[0])
  9471. use_endlvl = job_info[idx].max_level[0];
  9472. if(type == 0) { //hp type
  9473. uint16 j;
  9474. for(j = 0; j < use_endlvl; j++) {
  9475. if (atoi(fields[j+4])) {
  9476. uint16 lvl_idx = startlvl-1+j;
  9477. job_info[idx].base_hp[lvl_idx] = atoi(fields[j+4]);
  9478. //Tells if this HP is lower than previous level (but not for 99->100)
  9479. if (lvl_idx-1 >= 0 && lvl_idx != 99 && job_info[idx].base_hp[lvl_idx] < job_info[idx].base_hp[lvl_idx-1])
  9480. ShowInfo("pc_readdb_job_basehpsp: HP value at entry %d col %d is lower than previous level (job=%d,lvl=%d,oldval=%d,val=%d).\n",
  9481. current,j+4,job_id,lvl_idx+1,job_info[idx].base_hp[lvl_idx-1],job_info[idx].base_hp[lvl_idx]);
  9482. }
  9483. }
  9484. }
  9485. else { //sp type
  9486. uint16 j;
  9487. for(j = 0; j < use_endlvl; j++) {
  9488. if (atoi(fields[j+4])) {
  9489. uint16 lvl_idx = startlvl-1+j;
  9490. job_info[idx].base_sp[lvl_idx] = atoi(fields[j+4]);
  9491. //Tells if this SP is lower than previous level (but not for 99->100)
  9492. if (lvl_idx-1 >= 0 && lvl_idx != 99 && job_info[idx].base_sp[lvl_idx] < job_info[idx].base_sp[lvl_idx-1])
  9493. ShowInfo("pc_readdb_job_basehpsp: SP value at entry %d col %d is lower than previous level (job=%d,lvl=%d,oldval=%d,val=%d).\n",
  9494. current,j+4,job_id,lvl_idx+1,job_info[idx].base_sp[lvl_idx-1],job_info[idx].base_sp[lvl_idx]);
  9495. }
  9496. }
  9497. }
  9498. }
  9499. return true;
  9500. }
  9501. #endif
  9502. /** [Cydh]
  9503. * Reads 'job_param_db.txt' to check max. param each job and store them to job_info[].max_param.*
  9504. */
  9505. static bool pc_readdb_job_param(char* fields[], int columns, int current)
  9506. {
  9507. int idx, class_;
  9508. uint16 str, agi, vit, int_, dex, luk;
  9509. script_get_constant(trim(fields[0]),&class_);
  9510. if ((idx = pc_class2idx(class_)) < 0) {
  9511. ShowError("pc_readdb_job_param: Invalid job '%s'. Skipping!",fields[0]);
  9512. return false;
  9513. }
  9514. str = cap_value(atoi(fields[1]),10,SHRT_MAX);
  9515. agi = atoi(fields[2]) ? cap_value(atoi(fields[2]),10,SHRT_MAX) : str;
  9516. vit = atoi(fields[3]) ? cap_value(atoi(fields[3]),10,SHRT_MAX) : str;
  9517. int_ = atoi(fields[4]) ? cap_value(atoi(fields[4]),10,SHRT_MAX) : str;
  9518. dex = atoi(fields[5]) ? cap_value(atoi(fields[5]),10,SHRT_MAX) : str;
  9519. luk = atoi(fields[6]) ? cap_value(atoi(fields[6]),10,SHRT_MAX) : str;
  9520. job_info[idx].max_param.str = str;
  9521. job_info[idx].max_param.agi = agi;
  9522. job_info[idx].max_param.vit = vit;
  9523. job_info[idx].max_param.int_ = int_;
  9524. job_info[idx].max_param.dex = dex;
  9525. job_info[idx].max_param.luk = luk;
  9526. return true;
  9527. }
  9528. static int pc_read_statsdb(const char *basedir, int last_s, bool silent){
  9529. int i=1;
  9530. char line[24000]; //FIXME this seem too big
  9531. FILE *fp;
  9532. sprintf(line, "%s/statpoint.txt", basedir);
  9533. fp=fopen(line,"r");
  9534. if(fp == NULL){
  9535. if(silent==0) ShowWarning("Can't read '"CL_WHITE"%s"CL_RESET"'... Generating DB.\n",line);
  9536. return max(last_s,i);
  9537. } else {
  9538. int entries=0;
  9539. while(fgets(line, sizeof(line), fp))
  9540. {
  9541. int stat;
  9542. trim(line);
  9543. if(line[0] == '\0' || (line[0]=='/' && line[1]=='/'))
  9544. continue;
  9545. if ((stat=strtoul(line,NULL,10))<0)
  9546. stat=0;
  9547. if (i > MAX_LEVEL)
  9548. break;
  9549. statp[i]=stat;
  9550. i++;
  9551. entries++;
  9552. }
  9553. fclose(fp);
  9554. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s/%s"CL_RESET"'.\n", entries, basedir,"statpoint.txt");
  9555. }
  9556. return max(last_s,i);
  9557. }
  9558. /*==========================================
  9559. * pc DB reading.
  9560. * job_exp.txt - required experience values
  9561. * skill_tree.txt - skill tree for every class
  9562. * attr_fix.txt - elemental adjustment table
  9563. * job_db1.txt - job,weight,hp_factor,hp_multiplicator,sp_factor,aspds/lvl
  9564. * job_db2.txt - job,stats bonuses/lvl
  9565. * job_maxhpsp_db.txt - strtlvl,maxlvl,job,type,values/lvl (values=hp|sp)
  9566. *------------------------------------------*/
  9567. void pc_readdb(void) {
  9568. int i, k, s = 1;
  9569. const char* dbsubpath[] = {
  9570. "",
  9571. "/"DBIMPORT,
  9572. //add other path here
  9573. };
  9574. //reset
  9575. memset(job_info,0,sizeof(job_info)); // job_info table
  9576. // Reset and read skilltree
  9577. memset(skill_tree,0,sizeof(skill_tree));
  9578. sv_readdb(db_path, DBPATH"skill_tree.txt", ',', 3+MAX_PC_SKILL_REQUIRE*2, 4+MAX_PC_SKILL_REQUIRE*2, -1, &pc_readdb_skilltree, 0);
  9579. sv_readdb(db_path, DBIMPORT"/skill_tree.txt", ',', 3+MAX_PC_SKILL_REQUIRE*2, 4+MAX_PC_SKILL_REQUIRE*2, -1, &pc_readdb_skilltree, 1);
  9580. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  9581. sv_readdb(db_path, "re/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty, 0);
  9582. sv_readdb(db_path, DBIMPORT"/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty, 1);
  9583. for( k=1; k < 3; k++ ){ // fill in the blanks
  9584. int j;
  9585. for( j = 0; j < CLASS_ALL; j++ ){
  9586. int tmp = 0;
  9587. for( i = 0; i < MAX_LEVEL*2; i++ ){
  9588. if( i == MAX_LEVEL+1 )
  9589. tmp = level_penalty[k][j][0];// reset
  9590. if( level_penalty[k][j][i] > 0 )
  9591. tmp = level_penalty[k][j][i];
  9592. else
  9593. level_penalty[k][j][i] = tmp;
  9594. }
  9595. }
  9596. }
  9597. #endif
  9598. // reset then read statspoint
  9599. memset(statp,0,sizeof(statp));
  9600. for(i=0; i<ARRAYLENGTH(dbsubpath); i++){
  9601. uint8 n1 = (uint8)(strlen(db_path)+strlen(dbsubpath[i])+1);
  9602. uint8 n2 = (uint8)(strlen(db_path)+strlen(DBPATH)+strlen(dbsubpath[i])+1);
  9603. char* dbsubpath1 = (char*)aMalloc(n1+1);
  9604. char* dbsubpath2 = (char*)aMalloc(n2+1);
  9605. if(i==0) {
  9606. safesnprintf(dbsubpath1,n1,"%s%s",db_path,dbsubpath[i]);
  9607. safesnprintf(dbsubpath2,n2,"%s/%s%s",db_path,DBPATH,dbsubpath[i]);
  9608. }
  9609. else {
  9610. safesnprintf(dbsubpath1,n1,"%s%s",db_path,dbsubpath[i]);
  9611. safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[i]);
  9612. }
  9613. s = pc_read_statsdb(dbsubpath2,s,i);
  9614. if (i == 0)
  9615. #ifdef RENEWAL_ASPD
  9616. sv_readdb(dbsubpath1, "re/job_db1.txt",',',6+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
  9617. #else
  9618. sv_readdb(dbsubpath1, "pre-re/job_db1.txt",',',5+MAX_WEAPON_TYPE,5+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
  9619. #endif
  9620. else
  9621. sv_readdb(dbsubpath1, "job_db1.txt",',',5+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
  9622. sv_readdb(dbsubpath1, "job_db2.txt",',',1,1+MAX_LEVEL,CLASS_COUNT,&pc_readdb_job2, i);
  9623. sv_readdb(dbsubpath2, "job_exp.txt",',',4,1000+3,CLASS_COUNT*2,&pc_readdb_job_exp, i); //support till 1000lvl
  9624. #ifdef HP_SP_TABLES
  9625. sv_readdb(dbsubpath2, "job_basehpsp_db.txt", ',', 4, 4+500, CLASS_COUNT*2, &pc_readdb_job_basehpsp, i); //Make it support until lvl 500!
  9626. #endif
  9627. sv_readdb(dbsubpath2, "job_param_db.txt", ',', 2, PARAM_MAX+1, CLASS_COUNT, &pc_readdb_job_param, i);
  9628. aFree(dbsubpath1);
  9629. aFree(dbsubpath2);
  9630. }
  9631. // generate the remaining parts of the db if necessary
  9632. k = battle_config.use_statpoint_table; //save setting
  9633. battle_config.use_statpoint_table = 0; //temporarily disable to force pc_gets_status_point use default values
  9634. statp[0] = 45; // seed value
  9635. for (; s <= MAX_LEVEL; s++)
  9636. statp[s] = statp[s-1] + pc_gets_status_point(s-1);
  9637. battle_config.use_statpoint_table = k; //restore setting
  9638. //Checking if all class have their data
  9639. for (i = 0; i < JOB_MAX; i++) {
  9640. int idx;
  9641. uint16 j;
  9642. if (!pcdb_checkid(i))
  9643. continue;
  9644. if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER || i == JOB_HANBOK || i == JOB_OKTOBERFEST)
  9645. continue; //Classes that do not need exp tables.
  9646. idx = pc_class2idx(i);
  9647. if (!job_info[idx].max_level[0])
  9648. ShowWarning("Class %s (%d) does not have a base exp table.\n", job_name(i), i);
  9649. if (!job_info[idx].max_level[1])
  9650. ShowWarning("Class %s (%d) does not have a job exp table.\n", job_name(i), i);
  9651. //Init and checking the empty value of Base HP/SP [Cydh]
  9652. for (j = 0; j < (job_info[idx].max_level[0] ? job_info[idx].max_level[0] : MAX_LEVEL); j++) {
  9653. if (job_info[idx].base_hp[j] == 0)
  9654. job_info[idx].base_hp[j] = pc_calc_basehp(j+1,i);
  9655. if (job_info[idx].base_sp[j] == 0)
  9656. job_info[idx].base_sp[j] = pc_calc_basesp(j+1,i);
  9657. }
  9658. }
  9659. }
  9660. // Read MOTD on startup. [Valaris]
  9661. int pc_read_motd(void)
  9662. {
  9663. FILE* fp;
  9664. // clear old MOTD
  9665. memset(motd_text, 0, sizeof(motd_text));
  9666. // read current MOTD
  9667. if( ( fp = fopen(motd_txt, "r") ) != NULL )
  9668. {
  9669. unsigned int entries = 0;
  9670. while( entries < MOTD_LINE_SIZE && fgets(motd_text[entries], sizeof(motd_text[entries]), fp) )
  9671. {
  9672. char* buf = motd_text[entries];
  9673. unsigned int lines = 0;
  9674. size_t len;
  9675. lines++;
  9676. if( buf[0] == '/' && buf[1] == '/' )
  9677. continue;
  9678. len = strlen(buf);
  9679. while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) ) // strip trailing EOL characters
  9680. len--;
  9681. if( len ) {
  9682. char * ptr;
  9683. buf[len] = 0;
  9684. if( ( ptr = strstr(buf, " :") ) != NULL && ptr-buf >= NAME_LENGTH ) // crashes newer clients
  9685. 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);
  9686. }
  9687. else {// empty line
  9688. buf[0] = ' ';
  9689. buf[1] = 0;
  9690. }
  9691. entries++;
  9692. }
  9693. fclose(fp);
  9694. ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, motd_txt);
  9695. }
  9696. else
  9697. ShowWarning("File '"CL_WHITE"%s"CL_RESET"' not found.\n", motd_txt);
  9698. return 0;
  9699. }
  9700. void pc_itemcd_do(struct map_session_data *sd, bool load) {
  9701. int i,cursor = 0;
  9702. struct item_cd* cd = NULL;
  9703. if( load ) {
  9704. if( !(cd = (struct item_cd*)idb_get(itemcd_db, sd->status.char_id)) ) {
  9705. // no item cooldown is associated with this character
  9706. return;
  9707. }
  9708. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  9709. if( cd->nameid[i] && DIFF_TICK(gettick(),cd->tick[i]) < 0 ) {
  9710. sd->item_delay[cursor].tick = cd->tick[i];
  9711. sd->item_delay[cursor].nameid = cd->nameid[i];
  9712. cursor++;
  9713. }
  9714. }
  9715. idb_remove(itemcd_db,sd->status.char_id);
  9716. } else {
  9717. if( !(cd = (struct item_cd*)idb_get(itemcd_db,sd->status.char_id)) ) {
  9718. // create a new skill cooldown object for map storage
  9719. CREATE( cd, struct item_cd, 1 );
  9720. idb_put( itemcd_db, sd->status.char_id, cd );
  9721. }
  9722. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  9723. if( sd->item_delay[i].nameid && DIFF_TICK(gettick(),sd->item_delay[i].tick) < 0 ) {
  9724. cd->tick[cursor] = sd->item_delay[i].tick;
  9725. cd->nameid[cursor] = sd->item_delay[i].nameid;
  9726. cursor++;
  9727. }
  9728. }
  9729. }
  9730. return;
  9731. }
  9732. /**
  9733. * Add item delay to player's item delay data
  9734. * @param sd Player
  9735. * @param id Item data
  9736. * @param tick Current tick
  9737. * @param n Item index in inventory
  9738. * @return 0: No delay, can consume item.
  9739. * 1: Has delay, cancel consumption.
  9740. **/
  9741. uint8 pc_itemcd_add(struct map_session_data *sd, struct item_data *id, unsigned int tick, unsigned short n) {
  9742. int i;
  9743. ARR_FIND(0, MAX_ITEMDELAYS, i, sd->item_delay[i].nameid == id->nameid );
  9744. if( i == MAX_ITEMDELAYS ) /* item not found. try first empty now */
  9745. ARR_FIND(0, MAX_ITEMDELAYS, i, !sd->item_delay[i].nameid );
  9746. if( i < MAX_ITEMDELAYS ) {
  9747. if( sd->item_delay[i].nameid ) {// found
  9748. if( DIFF_TICK(sd->item_delay[i].tick, tick) > 0 ) {
  9749. int e_tick = DIFF_TICK(sd->item_delay[i].tick, tick)/1000;
  9750. char e_msg[CHAT_SIZE_MAX];
  9751. if( e_tick > 99 )
  9752. sprintf(e_msg,msg_txt(sd,379), // Item Failed. [%s] is cooling down. Wait %.1f minutes.
  9753. itemdb_jname(sd->item_delay[i].nameid), (double)e_tick / 60);
  9754. else
  9755. sprintf(e_msg,msg_txt(sd,380), // Item Failed. [%s] is cooling down. Wait %d seconds.
  9756. itemdb_jname(sd->item_delay[i].nameid), e_tick+1);
  9757. clif_colormes(sd->fd,color_table[COLOR_YELLOW],e_msg);
  9758. return 1; // Delay has not expired yet
  9759. }
  9760. } else {// not yet used item (all slots are initially empty)
  9761. sd->item_delay[i].nameid = id->nameid;
  9762. }
  9763. if( !(id->nameid == ITEMID_REINS_OF_MOUNT && sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR)) )
  9764. sd->item_delay[i].tick = tick + sd->inventory_data[n]->delay;
  9765. } else {// should not happen
  9766. ShowError("pc_itemcd_add: Exceeded item delay array capacity! (nameid=%hu, char_id=%d)\n", id->nameid, sd->status.char_id);
  9767. }
  9768. //clean up used delays so we can give room for more
  9769. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  9770. if( DIFF_TICK(sd->item_delay[i].tick, tick) <= 0 ) {
  9771. sd->item_delay[i].tick = 0;
  9772. sd->item_delay[i].nameid = 0;
  9773. }
  9774. }
  9775. return 0;
  9776. }
  9777. /**
  9778. * Check if player has delay to reuse item
  9779. * @param sd Player
  9780. * @param id Item data
  9781. * @param tick Current tick
  9782. * @param n Item index in inventory
  9783. * @return 0: No delay, can consume item.
  9784. * 1: Has delay, cancel consumption.
  9785. **/
  9786. uint8 pc_itemcd_check(struct map_session_data *sd, struct item_data *id, unsigned int tick, unsigned short n) {
  9787. struct status_change *sc = NULL;
  9788. nullpo_retr(0, sd);
  9789. nullpo_retr(0, id);
  9790. // Do normal delay assignment
  9791. if (id->delay_sc <= SC_NONE || id->delay_sc >= SC_MAX || !(sc = &sd->sc))
  9792. return pc_itemcd_add(sd, id, tick, n);
  9793. // Send reply of delay remains
  9794. if (sc->data[id->delay_sc]) {
  9795. const struct TimerData *timer = get_timer(sc->data[id->delay_sc]->timer);
  9796. clif_msg_value(sd, ITEM_REUSE_LIMIT, timer ? DIFF_TICK(timer->tick, tick) / 1000 : 99);
  9797. return 1;
  9798. }
  9799. sc_start(&sd->bl, &sd->bl, (sc_type)id->delay_sc, 100, id->nameid, id->delay);
  9800. return 0;
  9801. }
  9802. /**
  9803. * Clear the dmglog data from player
  9804. * @param sd
  9805. * @param md
  9806. **/
  9807. static void pc_clear_log_damage_sub(uint32 char_id, struct mob_data *md)
  9808. {
  9809. uint8 i;
  9810. ARR_FIND(0,DAMAGELOG_SIZE,i,md->dmglog[i].id == char_id);
  9811. if (i < DAMAGELOG_SIZE) {
  9812. md->dmglog[i].id = 0;
  9813. md->dmglog[i].dmg = 0;
  9814. md->dmglog[i].flag = 0;
  9815. }
  9816. }
  9817. /**
  9818. * Add log to player's dmglog
  9819. * @param sd
  9820. * @param id Monster's GID
  9821. **/
  9822. void pc_damage_log_add(struct map_session_data *sd, int id)
  9823. {
  9824. uint8 i = 0;
  9825. if (!sd || !id)
  9826. return;
  9827. //Only store new data, don't need to renew the old one with same id
  9828. ARR_FIND(0, DAMAGELOG_SIZE_PC, i, sd->dmglog[i] == id);
  9829. if (i < DAMAGELOG_SIZE_PC)
  9830. return;
  9831. for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
  9832. if (sd->dmglog[i] == 0) {
  9833. sd->dmglog[i] = id;
  9834. return;
  9835. }
  9836. }
  9837. }
  9838. /**
  9839. * Clear dmglog data from player
  9840. * @param sd
  9841. * @param id Monster's id
  9842. **/
  9843. void pc_damage_log_clear(struct map_session_data *sd, int id)
  9844. {
  9845. uint8 i;
  9846. struct mob_data *md = NULL;
  9847. if (!sd)
  9848. return;
  9849. if (!id) {
  9850. for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
  9851. if( !sd->dmglog[i] ) //skip the empty value
  9852. continue;
  9853. if ((md = map_id2md(sd->dmglog[i])))
  9854. pc_clear_log_damage_sub(sd->status.char_id,md);
  9855. sd->dmglog[i] = 0;
  9856. }
  9857. }
  9858. else {
  9859. if ((md = map_id2md(id)))
  9860. pc_clear_log_damage_sub(sd->status.char_id,md);
  9861. ARR_FIND(0,DAMAGELOG_SIZE_PC,i,sd->dmglog[i] == id); // find the id position
  9862. if (i < DAMAGELOG_SIZE_PC)
  9863. sd->dmglog[i] = 0;
  9864. }
  9865. }
  9866. /* Status change data arrived from char-server */
  9867. void pc_scdata_received(struct map_session_data *sd) {
  9868. // Nothing todo yet
  9869. return;
  9870. }
  9871. /** Check expiration time and rental items
  9872. * @param sd
  9873. */
  9874. void pc_check_expiration(struct map_session_data *sd) {
  9875. pc_inventory_rentals(sd);
  9876. if (sd->expiration_time != 0) { //Don't display if it's unlimited or unknow value
  9877. time_t exp_time = sd->expiration_time;
  9878. char tmpstr[1024];
  9879. strftime(tmpstr,sizeof(tmpstr) - 1,msg_txt(sd,501),localtime(&exp_time)); // "Your account time limit is: %d-%m-%Y %H:%M:%S."
  9880. clif_wis_message(sd->fd,wisp_server_name,tmpstr,strlen(tmpstr) + 1);
  9881. pc_expire_check(sd);
  9882. }
  9883. }
  9884. int pc_expiration_timer(int tid, unsigned int tick, int id, intptr_t data) {
  9885. struct map_session_data *sd = map_id2sd(id);
  9886. if( !sd ) return 0;
  9887. sd->expiration_tid = INVALID_TIMER;
  9888. if( sd->fd )
  9889. clif_authfail_fd(sd->fd,10);
  9890. map_quit(sd);
  9891. return 0;
  9892. }
  9893. int pc_autotrade_timer(int tid, unsigned int tick, int id, intptr_t data) {
  9894. struct map_session_data *sd = map_id2sd(id);
  9895. if (!sd)
  9896. return 0;
  9897. sd->autotrade_tid = INVALID_TIMER;
  9898. if (sd->state.autotrade&2)
  9899. vending_reopen(sd);
  9900. if (sd->state.autotrade&4)
  9901. buyingstore_reopen(sd);
  9902. if (!sd->vender_id && !sd->buyer_id) {
  9903. sd->state.autotrade = 0;
  9904. map_quit(sd);
  9905. }
  9906. return 0;
  9907. }
  9908. /* this timer exists only when a character with a expire timer > 24h is online */
  9909. /* it loops thru online players once an hour to check whether a new < 24h is available */
  9910. int pc_global_expiration_timer(int tid, unsigned int tick, int id, intptr_t data) {
  9911. struct s_mapiterator* iter;
  9912. struct map_session_data* sd;
  9913. iter = mapit_getallusers();
  9914. for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
  9915. if( sd->expiration_time )
  9916. pc_expire_check(sd);
  9917. mapit_free(iter);
  9918. return 0;
  9919. }
  9920. void pc_expire_check(struct map_session_data *sd) {
  9921. /* ongoing timer */
  9922. if( sd->expiration_tid != INVALID_TIMER )
  9923. return;
  9924. /* not within the next 24h, enable the global check */
  9925. if( sd->expiration_time > (time(NULL) + ((60 * 60) * 24)) ) {
  9926. /* global check not running, enable */
  9927. if( pc_expiration_tid == INVALID_TIMER ) /* Starts in 1h, repeats every hour */
  9928. pc_expiration_tid = add_timer_interval(gettick() + ((1000 * 60) * 60), pc_global_expiration_timer, 0, 0, ((1000 * 60) * 60));
  9929. return;
  9930. }
  9931. sd->expiration_tid = add_timer(gettick() + (unsigned int)(sd->expiration_time - time(NULL)) * 1000, pc_expiration_timer, sd->bl.id, 0);
  9932. }
  9933. /**
  9934. * Deposit some money to bank
  9935. * @param sd
  9936. * @param money Amount of money to deposit
  9937. **/
  9938. enum e_BANKING_DEPOSIT_ACK pc_bank_deposit(struct map_session_data *sd, int money) {
  9939. unsigned int limit_check = money + sd->bank_vault;
  9940. if( money <= 0 || limit_check > MAX_BANK_ZENY ) {
  9941. return BDA_OVERFLOW;
  9942. } else if ( money > sd->status.zeny ) {
  9943. return BDA_NO_MONEY;
  9944. }
  9945. if( pc_payzeny(sd,money, LOG_TYPE_BANK, NULL) )
  9946. return BDA_NO_MONEY;
  9947. sd->bank_vault += money;
  9948. pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
  9949. if( save_settings&CHARSAVE_BANK )
  9950. chrif_save(sd,0);
  9951. return BDA_SUCCESS;
  9952. }
  9953. /**
  9954. * Withdraw money from bank
  9955. * @param sd
  9956. * @param money Amount of money that will be withdrawn
  9957. **/
  9958. enum e_BANKING_WITHDRAW_ACK pc_bank_withdraw(struct map_session_data *sd, int money) {
  9959. unsigned int limit_check = money + sd->status.zeny;
  9960. if( money <= 0 ) {
  9961. return BWA_UNKNOWN_ERROR;
  9962. } else if ( money > sd->bank_vault ) {
  9963. return BWA_NO_MONEY;
  9964. } else if ( limit_check > MAX_ZENY ) {
  9965. /* no official response for this scenario exists. */
  9966. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1495)); //You can't withdraw that much money
  9967. return BWA_UNKNOWN_ERROR;
  9968. }
  9969. if( pc_getzeny(sd,money, LOG_TYPE_BANK, NULL) )
  9970. return BWA_NO_MONEY;
  9971. sd->bank_vault -= money;
  9972. pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
  9973. if( save_settings&CHARSAVE_BANK )
  9974. chrif_save(sd,0);
  9975. return BWA_SUCCESS;
  9976. }
  9977. /**
  9978. * Clear Crimson Marker data from caster
  9979. * @param sd: Player
  9980. **/
  9981. void pc_crimson_marker_clear(struct map_session_data *sd) {
  9982. uint8 i;
  9983. if (!sd)
  9984. return;
  9985. for (i = 0; i < MAX_SKILL_CRIMSON_MARKER; i++) {
  9986. struct block_list *bl = NULL;
  9987. if (sd->c_marker[i] && (bl = map_id2bl(sd->c_marker[i])))
  9988. status_change_end(bl,SC_C_MARKER,INVALID_TIMER);
  9989. sd->c_marker[i] = 0;
  9990. }
  9991. }
  9992. /**
  9993. * Show version to player
  9994. * @param sd: Player
  9995. **/
  9996. void pc_show_version(struct map_session_data *sd) {
  9997. const char* svn = get_svn_revision();
  9998. char buf[CHAT_SIZE_MAX];
  9999. if( svn[0] != UNKNOWN_VERSION )
  10000. sprintf(buf,msg_txt(sd,1295),"SVN: r",svn); //rAthena Version SVN: r%s
  10001. else {
  10002. const char* git = get_git_hash();
  10003. if( git[0] != UNKNOWN_VERSION )
  10004. sprintf(buf,msg_txt(sd,1295),"Git Hash: ",git); //rAthena Version Git Hash: %s
  10005. else
  10006. sprintf(buf,"%s",msg_txt(sd,1296)); //Cannot determine SVN/Git version.
  10007. }
  10008. clif_displaymessage(sd->fd,buf);
  10009. }
  10010. /**
  10011. * Run bonus_script on player
  10012. * @param sd
  10013. * @author [Cydh]
  10014. **/
  10015. void pc_bonus_script(struct map_session_data *sd) {
  10016. int now = gettick();
  10017. struct linkdb_node *node = NULL, *next = NULL;
  10018. if (!sd || !(node = sd->bonus_script.head))
  10019. return;
  10020. while (node) {
  10021. struct s_bonus_script_entry *entry = NULL;
  10022. next = node->next;
  10023. if ((entry = (struct s_bonus_script_entry *)node->data)) {
  10024. // Only start timer for new bonus_script
  10025. if (entry->tid == INVALID_TIMER) {
  10026. if (entry->icon != SI_BLANK) // Gives status icon if exist
  10027. clif_status_change(&sd->bl, entry->icon, 1, entry->tick, 1, 0, 0);
  10028. entry->tick += now;
  10029. entry->tid = add_timer(entry->tick, pc_bonus_script_timer, sd->bl.id, (intptr_t)entry);
  10030. }
  10031. if (entry->script)
  10032. run_script(entry->script, 0, sd->bl.id, 0);
  10033. else
  10034. ShowError("pc_bonus_script: The script has been removed somewhere. \"%s\"\n", StringBuf_Value(entry->script_buf));
  10035. }
  10036. node = next;
  10037. }
  10038. }
  10039. /**
  10040. * Add bonus_script to player
  10041. * @param sd Player
  10042. * @param script_str Script string
  10043. * @param dur Duration in ms
  10044. * @param icon SI
  10045. * @param flag Flags @see enum e_bonus_script_flags
  10046. * @param type 0 - None, 1 - Buff, 2 - Debuff
  10047. * @return New created entry pointer or NULL if failed or NULL if duplicate fail
  10048. * @author [Cydh]
  10049. **/
  10050. struct s_bonus_script_entry *pc_bonus_script_add(struct map_session_data *sd, const char *script_str, uint32 dur, enum si_type icon, uint16 flag, uint8 type) {
  10051. struct script_code *script = NULL;
  10052. struct linkdb_node *node = NULL;
  10053. struct s_bonus_script_entry *entry = NULL;
  10054. if (!sd)
  10055. return NULL;
  10056. if (!(script = parse_script(script_str, "bonus_script", 0, SCRIPT_IGNORE_EXTERNAL_BRACKETS))) {
  10057. ShowError("pc_bonus_script_add: Failed to parse script '%s' (CID:%d).\n", script_str, sd->status.char_id);
  10058. return NULL;
  10059. }
  10060. // Duplication checks
  10061. if ((node = sd->bonus_script.head)) {
  10062. while (node) {
  10063. entry = (struct s_bonus_script_entry *)node->data;
  10064. if (strcmpi(script_str, StringBuf_Value(entry->script_buf)) == 0) {
  10065. int newdur = gettick() + dur;
  10066. if (flag&BSF_FORCE_REPLACE && entry->tick < newdur) { // Change duration
  10067. settick_timer(entry->tid, newdur);
  10068. script_free_code(script);
  10069. return NULL;
  10070. }
  10071. else if (flag&BSF_FORCE_DUPLICATE) // Allow duplicate
  10072. break;
  10073. else { // No duplicate bonus
  10074. script_free_code(script);
  10075. return NULL;
  10076. }
  10077. }
  10078. node = node->next;
  10079. }
  10080. }
  10081. CREATE(entry, struct s_bonus_script_entry, 1);
  10082. entry->script_buf = StringBuf_Malloc();
  10083. StringBuf_AppendStr(entry->script_buf, script_str);
  10084. entry->tid = INVALID_TIMER;
  10085. entry->flag = flag;
  10086. entry->icon = icon;
  10087. entry->tick = dur; // Use duration first, on run change to expire time
  10088. entry->type = type;
  10089. entry->script = script;
  10090. sd->bonus_script.count++;
  10091. return entry;
  10092. }
  10093. /**
  10094. * Remove bonus_script data from player
  10095. * @param sd: Target player
  10096. * @param list: Bonus script entry from player
  10097. * @author [Cydh]
  10098. **/
  10099. void pc_bonus_script_free_entry(struct map_session_data *sd, struct s_bonus_script_entry *entry) {
  10100. if (entry->tid != INVALID_TIMER)
  10101. delete_timer(entry->tid, pc_bonus_script_timer);
  10102. if (entry->script)
  10103. script_free_code(entry->script);
  10104. if (entry->script_buf)
  10105. StringBuf_Free(entry->script_buf);
  10106. if (sd) {
  10107. if (entry->icon != SI_BLANK)
  10108. clif_status_load(&sd->bl, entry->icon, 0);
  10109. if (sd->bonus_script.count > 0)
  10110. sd->bonus_script.count--;
  10111. }
  10112. aFree(entry);
  10113. }
  10114. /**
  10115. * Do final process if no entry left
  10116. * @param sd
  10117. **/
  10118. static void inline pc_bonus_script_check_final(struct map_session_data *sd) {
  10119. if (sd->bonus_script.count == 0) {
  10120. if (sd->bonus_script.head && sd->bonus_script.head->data)
  10121. pc_bonus_script_free_entry(sd, (struct s_bonus_script_entry *)sd->bonus_script.head->data);
  10122. linkdb_final(&sd->bonus_script.head);
  10123. }
  10124. }
  10125. /**
  10126. * Timer for bonus_script
  10127. * @param tid
  10128. * @param tick
  10129. * @param id
  10130. * @param data
  10131. * @author [Cydh]
  10132. **/
  10133. int pc_bonus_script_timer(int tid, unsigned int tick, int id, intptr_t data) {
  10134. struct map_session_data *sd;
  10135. struct s_bonus_script_entry *entry = (struct s_bonus_script_entry *)data;
  10136. sd = map_id2sd(id);
  10137. if (!sd) {
  10138. ShowError("pc_bonus_script_timer: Null pointer id: %d tid: %d\n", id, tid);
  10139. return 0;
  10140. }
  10141. if (tid == INVALID_TIMER)
  10142. return 0;
  10143. if (!sd->bonus_script.head || entry == NULL) {
  10144. ShowError("pc_bonus_script_timer: Invalid entry pointer 0x%08X!\n", entry);
  10145. return 0;
  10146. }
  10147. linkdb_erase(&sd->bonus_script.head, (void *)((intptr_t)entry));
  10148. pc_bonus_script_free_entry(sd, entry);
  10149. pc_bonus_script_check_final(sd);
  10150. status_calc_pc(sd,SCO_NONE);
  10151. return 0;
  10152. }
  10153. /**
  10154. * Check then clear all active timer(s) of bonus_script data from player based on reason
  10155. * @param sd: Target player
  10156. * @param flag: Reason to remove the bonus_script. e_bonus_script_flags or e_bonus_script_types
  10157. * @author [Cydh]
  10158. **/
  10159. void pc_bonus_script_clear(struct map_session_data *sd, uint16 flag) {
  10160. struct linkdb_node *node = NULL;
  10161. uint16 count = 0;
  10162. if (!sd || !(node = sd->bonus_script.head))
  10163. return;
  10164. while (node) {
  10165. struct linkdb_node *next = node->next;
  10166. struct s_bonus_script_entry *entry = (struct s_bonus_script_entry *)node->data;
  10167. if (entry && (
  10168. (flag == BSF_PERMANENT) || // Remove all with permanent bonus
  10169. (!flag && !(entry->flag&BSF_PERMANENT)) || // Remove all WITHOUT permanent bonus
  10170. (flag&entry->flag) || // Matched flag
  10171. (flag&BSF_REM_BUFF && entry->type == 1) || // Remove buff
  10172. (flag&BSF_REM_DEBUFF && entry->type == 2) // Remove debuff
  10173. )
  10174. )
  10175. {
  10176. linkdb_erase(&sd->bonus_script.head, (void *)((intptr_t)entry));
  10177. pc_bonus_script_free_entry(sd, entry);
  10178. count++;
  10179. }
  10180. node = next;
  10181. }
  10182. pc_bonus_script_check_final(sd);
  10183. if (count && !(flag&BSF_REM_ON_LOGOUT)) //Don't need to do this if log out
  10184. status_calc_pc(sd,SCO_NONE);
  10185. }
  10186. /** [Cydh]
  10187. * Gives/removes SC_BASILICA when player steps in/out the cell with 'cell_basilica'
  10188. * @param sd: Target player
  10189. */
  10190. void pc_cell_basilica(struct map_session_data *sd) {
  10191. nullpo_retv(sd);
  10192. if (!map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKBASILICA)) {
  10193. if (&sd->sc && sd->sc.data[SC_BASILICA])
  10194. status_change_end(&sd->bl,SC_BASILICA,INVALID_TIMER);
  10195. }
  10196. else if (!(&sd->sc) || !sd->sc.data[SC_BASILICA])
  10197. sc_start(&sd->bl,&sd->bl,SC_BASILICA,100,0,-1);
  10198. }
  10199. /** [Cydh]
  10200. * Get maximum specified parameter for specified class
  10201. * @param class_: sd->class
  10202. * @param sex: sd->status.sex
  10203. * @param flag: parameter will be checked
  10204. * @return max_param
  10205. */
  10206. short pc_maxparameter(struct map_session_data *sd, enum e_params param) {
  10207. int idx = -1, class_ = sd->class_;
  10208. if ((idx = pc_class2idx(pc_mapid2jobid(class_,sd->status.sex))) >= 0) {
  10209. short max_param = 0;
  10210. switch (param) {
  10211. case PARAM_STR: max_param = job_info[idx].max_param.str; break;
  10212. case PARAM_AGI: max_param = job_info[idx].max_param.agi; break;
  10213. case PARAM_VIT: max_param = job_info[idx].max_param.vit; break;
  10214. case PARAM_INT: max_param = job_info[idx].max_param.int_; break;
  10215. case PARAM_DEX: max_param = job_info[idx].max_param.dex; break;
  10216. case PARAM_LUK: max_param = job_info[idx].max_param.luk; break;
  10217. }
  10218. if (max_param > 0)
  10219. return max_param;
  10220. }
  10221. return ((class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO || (class_&MAPID_UPPERMASK) == MAPID_REBELLION) ? battle_config.max_extended_parameter :
  10222. ((class_&JOBL_THIRD) ? ((class_&JOBL_UPPER) ? battle_config.max_third_trans_parameter : ((class_&JOBL_BABY) ? battle_config.max_baby_third_parameter : battle_config.max_third_parameter)) :
  10223. ((class_&JOBL_BABY) ? battle_config.max_baby_parameter :
  10224. ((class_&JOBL_UPPER) ? battle_config.max_trans_parameter : battle_config.max_parameter)));
  10225. }
  10226. /**
  10227. * Get max ASPD for player based on Class
  10228. * @param sd Player
  10229. * @return ASPD
  10230. */
  10231. short pc_maxaspd(struct map_session_data *sd) {
  10232. nullpo_ret(sd);
  10233. return (( sd->class_&JOBL_THIRD) ? battle_config.max_third_aspd : (
  10234. ((sd->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO || (sd->class_&MAPID_UPPERMASK) == MAPID_REBELLION) ? battle_config.max_extended_aspd :
  10235. battle_config.max_aspd ));
  10236. }
  10237. /**
  10238. * Calculates total item-group related bonuses for the given item
  10239. * @param sd Player
  10240. * @param nameid Item ID
  10241. * @return Heal rate
  10242. **/
  10243. short pc_get_itemgroup_bonus(struct map_session_data* sd, unsigned short nameid) {
  10244. short bonus = 0;
  10245. uint8 i;
  10246. if (!sd->itemgrouphealrate_count)
  10247. return bonus;
  10248. for (i = 0; i < sd->itemgrouphealrate_count; i++) {
  10249. uint16 group_id = sd->itemgrouphealrate[i]->group_id, j;
  10250. struct s_item_group_db *group = NULL;
  10251. if (!group_id || !(group = itemdb_group_exists(group_id)))
  10252. continue;
  10253. for (j = 0; j < group->random[0].data_qty; j++) {
  10254. if (group->random[0].data[j].nameid == nameid) {
  10255. bonus += sd->itemgrouphealrate[i]->rate;
  10256. break;
  10257. }
  10258. }
  10259. }
  10260. return bonus;
  10261. }
  10262. /**
  10263. * Calculates total item-group related bonuses for the given item group
  10264. * @param sd Player
  10265. * @param group_id Item Group ID
  10266. * @return Heal rate
  10267. **/
  10268. short pc_get_itemgroup_bonus_group(struct map_session_data* sd, uint16 group_id) {
  10269. short bonus = 0;
  10270. uint8 i;
  10271. if (!sd->itemgrouphealrate_count)
  10272. return bonus;
  10273. for (i = 0; i < sd->itemgrouphealrate_count; i++) {
  10274. if (sd->itemgrouphealrate[i]->group_id == group_id)
  10275. return sd->itemgrouphealrate[i]->rate;
  10276. }
  10277. return bonus;
  10278. }
  10279. /**
  10280. * Check if player's equip index in same specified position, like for 2-Handed weapon & Heagdear (inc. costume)
  10281. * @param eqi Item EQI of enum equip_index
  10282. * @param *equip_index Player's equip_index[]
  10283. * @param index Known index item in inventory from sd->equip_index[] to compare with specified EQI in *equip_index
  10284. * @return True if item in same inventory index, False if doesn't
  10285. */
  10286. bool pc_is_same_equip_index(enum equip_index eqi, short *equip_index, short index) {
  10287. if (index < 0 || index >= MAX_INVENTORY)
  10288. return true;
  10289. // Dual weapon checks
  10290. if (eqi == EQI_HAND_R && equip_index[EQI_HAND_L] == index)
  10291. return true;
  10292. // Headgear with Mid & Low location
  10293. if (eqi == EQI_HEAD_MID && equip_index[EQI_HEAD_LOW] == index)
  10294. return true;
  10295. // Headgear with Top & Mid or Low location
  10296. if (eqi == EQI_HEAD_TOP && (equip_index[EQI_HEAD_MID] == index || equip_index[EQI_HEAD_LOW] == index))
  10297. return true;
  10298. // Headgear with Mid & Low location
  10299. if (eqi == EQI_COSTUME_HEAD_MID && equip_index[EQI_COSTUME_HEAD_LOW] == index)
  10300. return true;
  10301. // Headgear with Top & Mid or Low location
  10302. if (eqi == EQI_COSTUME_HEAD_TOP && (equip_index[EQI_COSTUME_HEAD_MID] == index || equip_index[EQI_COSTUME_HEAD_LOW] == index))
  10303. return true;
  10304. return false;
  10305. }
  10306. /**
  10307. * Generate Unique item ID for player
  10308. * @param sd : Player
  10309. * @return A generated Unique item ID
  10310. */
  10311. uint64 pc_generate_unique_id(struct map_session_data *sd) {
  10312. nullpo_ret(sd);
  10313. return ((uint64)sd->status.char_id << 32) | sd->status.uniqueitem_counter++;
  10314. }
  10315. /**
  10316. * Validating skill from player after logged on
  10317. * @param sd
  10318. **/
  10319. void pc_validate_skill(struct map_session_data *sd) {
  10320. if (sd) {
  10321. uint16 i = 0, count = 0;
  10322. struct s_skill tmp_skills[MAX_SKILL] = {{ 0 }};
  10323. memcpy(tmp_skills, sd->status.skill, sizeof(sd->status.skill));
  10324. memset(sd->status.skill, 0, sizeof(sd->status.skill));
  10325. for (i = 0; i < MAX_SKILL; i++) {
  10326. uint16 idx = 0;
  10327. if (tmp_skills[i].id == 0 || tmp_skills[i].lv == 0)
  10328. continue;
  10329. if ((idx = skill_get_index(tmp_skills[i].id))) {
  10330. memcpy(&sd->status.skill[idx], &tmp_skills[i], sizeof(tmp_skills[i]));
  10331. count++;
  10332. }
  10333. else
  10334. ShowWarning("pc_validate_skill: Removing invalid skill '%d' from player (AID=%d CID=%d).\n", tmp_skills[i].id, sd->status.account_id, sd->status.char_id);
  10335. }
  10336. }
  10337. }
  10338. /**
  10339. * Toggle to remember if the questinfo is displayed yet or not.
  10340. * @param qi_display Display flag
  10341. * @param show If show is true and qi_display is 0, set qi_display to 1 and show the event bubble.
  10342. * If show is false and qi_display is 1, set qi_display to 0 and hide the event bubble.
  10343. **/
  10344. static void pc_show_questinfo_sub(struct map_session_data *sd, bool *qi_display, struct questinfo *qi, bool show) {
  10345. if (show) {
  10346. // Check if need to be displayed
  10347. if ((*qi_display) != 1) {
  10348. (*qi_display) = 1;
  10349. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  10350. }
  10351. }
  10352. else {
  10353. // Check if need to be hide
  10354. if ((*qi_display) != 0) {
  10355. (*qi_display) = 0;
  10356. #if PACKETVER >= 20120410
  10357. clif_quest_show_event(sd, &qi->nd->bl, 9999, 0);
  10358. #else
  10359. clif_quest_show_event(sd, &qi->nd->bl, 0, 0);
  10360. #endif
  10361. }
  10362. }
  10363. }
  10364. /**
  10365. * Show available NPC Quest / Event Icon Check [Kisuka]
  10366. * @param sd Player
  10367. **/
  10368. void pc_show_questinfo(struct map_session_data *sd) {
  10369. #if PACKETVER >= 20090218
  10370. struct questinfo *qi = NULL;
  10371. unsigned short i;
  10372. uint8 j;
  10373. int8 mystate = 0;
  10374. bool failed = false;
  10375. nullpo_retv(sd);
  10376. if (sd->bl.m < 0 || sd->bl.m >= MAX_MAPINDEX)
  10377. return;
  10378. if (!map[sd->bl.m].qi_count || !map[sd->bl.m].qi_data)
  10379. return;
  10380. for(i = 0; i < map[sd->bl.m].qi_count; i++) {
  10381. qi = &map[sd->bl.m].qi_data[i];
  10382. if (!qi)
  10383. continue;
  10384. if (quest_check(sd, qi->quest_id, HAVEQUEST) != -1) { // Check if quest is not started
  10385. pc_show_questinfo_sub(sd, &sd->qi_display[i], qi, false);
  10386. continue;
  10387. }
  10388. // Level range checks
  10389. if (sd->status.base_level < qi->min_level || sd->status.base_level > qi->max_level) {
  10390. pc_show_questinfo_sub(sd, &sd->qi_display[i], qi, false);
  10391. continue;
  10392. }
  10393. // Quest requirements
  10394. if (qi->req_count) {
  10395. failed = false;
  10396. for (j = 0; j < qi->req_count; j++) {
  10397. mystate = quest_check(sd, qi->req[j].quest_id, HAVEQUEST);
  10398. mystate = mystate + (mystate < 1);
  10399. if (mystate != qi->req[j].state) {
  10400. failed = true;
  10401. break;
  10402. }
  10403. }
  10404. if (failed) {
  10405. pc_show_questinfo_sub(sd, &sd->qi_display[i], qi, false);
  10406. continue;
  10407. }
  10408. }
  10409. // Job requirements
  10410. if (qi->jobid_count) {
  10411. failed = true;
  10412. for (j = 0; j < qi->jobid_count; j++) {
  10413. if (pc_mapid2jobid(sd->class_,sd->status.sex) == qi->jobid[j]) {
  10414. pc_show_questinfo_sub(sd, &sd->qi_display[i], qi, true);
  10415. failed = false;
  10416. break;
  10417. }
  10418. }
  10419. if (!failed)
  10420. continue;
  10421. pc_show_questinfo_sub(sd, &sd->qi_display[i], qi, false);
  10422. }
  10423. else {
  10424. pc_show_questinfo_sub(sd, &sd->qi_display[i], qi, true);
  10425. }
  10426. }
  10427. #endif
  10428. }
  10429. /**
  10430. * Reinit the questinfo for player when changing map
  10431. * @param sd Player
  10432. **/
  10433. void pc_show_questinfo_reinit(struct map_session_data *sd) {
  10434. #if PACKETVER >= 20090218
  10435. nullpo_retv(sd);
  10436. if (sd->qi_display) {
  10437. aFree(sd->qi_display);
  10438. sd->qi_display = NULL;
  10439. }
  10440. sd->qi_count = 0;
  10441. if (sd->bl.m < 0 || sd->bl.m >= MAX_MAPINDEX)
  10442. return;
  10443. if (!map[sd->bl.m].qi_count || !map[sd->bl.m].qi_data)
  10444. return;
  10445. CREATE(sd->qi_display, bool, (sd->qi_count = map[sd->bl.m].qi_count));
  10446. #endif
  10447. }
  10448. /*==========================================
  10449. * pc Init/Terminate
  10450. *------------------------------------------*/
  10451. void do_final_pc(void) {
  10452. db_destroy(itemcd_db);
  10453. do_final_pc_groups();
  10454. ers_destroy(pc_sc_display_ers);
  10455. ers_destroy(pc_itemgrouphealrate_ers);
  10456. ers_destroy(num_reg_ers);
  10457. ers_destroy(str_reg_ers);
  10458. }
  10459. void do_init_pc(void) {
  10460. itemcd_db = idb_alloc(DB_OPT_RELEASE_DATA);
  10461. pc_readdb();
  10462. pc_read_motd(); // Read MOTD [Valaris]
  10463. add_timer_func_list(pc_invincible_timer, "pc_invincible_timer");
  10464. add_timer_func_list(pc_eventtimer, "pc_eventtimer");
  10465. add_timer_func_list(pc_inventory_rental_end, "pc_inventory_rental_end");
  10466. add_timer_func_list(pc_calc_pvprank_timer, "pc_calc_pvprank_timer");
  10467. add_timer_func_list(pc_autosave, "pc_autosave");
  10468. add_timer_func_list(pc_spiritball_timer, "pc_spiritball_timer");
  10469. add_timer_func_list(pc_follow_timer, "pc_follow_timer");
  10470. add_timer_func_list(pc_endautobonus, "pc_endautobonus");
  10471. add_timer_func_list(pc_spiritcharm_timer, "pc_spiritcharm_timer");
  10472. add_timer_func_list(pc_global_expiration_timer, "pc_global_expiration_timer");
  10473. add_timer_func_list(pc_expiration_timer, "pc_expiration_timer");
  10474. add_timer_func_list(pc_autotrade_timer, "pc_autotrade_timer");
  10475. add_timer(gettick() + autosave_interval, pc_autosave, 0, 0);
  10476. // 0=day, 1=night [Yor]
  10477. night_flag = battle_config.night_at_start ? 1 : 0;
  10478. if (battle_config.day_duration > 0 && battle_config.night_duration > 0) {
  10479. int day_duration = battle_config.day_duration;
  10480. int night_duration = battle_config.night_duration;
  10481. // add night/day timer [Yor]
  10482. add_timer_func_list(map_day_timer, "map_day_timer");
  10483. add_timer_func_list(map_night_timer, "map_night_timer");
  10484. day_timer_tid = add_timer_interval(gettick() + (night_flag ? 0 : day_duration) + night_duration, map_day_timer, 0, 0, day_duration + night_duration);
  10485. night_timer_tid = add_timer_interval(gettick() + day_duration + (night_flag ? night_duration : 0), map_night_timer, 0, 0, day_duration + night_duration);
  10486. }
  10487. do_init_pc_groups();
  10488. pc_sc_display_ers = ers_new(sizeof(struct sc_display_entry), "pc.c:pc_sc_display_ers", ERS_OPT_FLEX_CHUNK);
  10489. pc_itemgrouphealrate_ers = ers_new(sizeof(struct s_pc_itemgrouphealrate), "pc.c:pc_itemgrouphealrate_ers", ERS_OPT_NONE);
  10490. num_reg_ers = ers_new(sizeof(struct script_reg_num), "pc.c:num_reg_ers", ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK);
  10491. str_reg_ers = ers_new(sizeof(struct script_reg_str), "pc.c:str_reg_ers", ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK);
  10492. ers_chunk_size(pc_sc_display_ers, 150);
  10493. ers_chunk_size(num_reg_ers, 300);
  10494. ers_chunk_size(str_reg_ers, 50);
  10495. }