pc.cpp 411 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "pc.hpp"
  4. #include <map>
  5. #include <math.h>
  6. #include <stdlib.h>
  7. #include <yaml-cpp/yaml.h>
  8. #include "../common/cbasetypes.hpp"
  9. #include "../common/core.hpp" // get_svn_revision()
  10. #include "../common/database.hpp"
  11. #include "../common/ers.hpp" // ers_destroy
  12. #include "../common/malloc.hpp"
  13. #include "../common/mmo.hpp" //NAME_LENGTH
  14. #include "../common/nullpo.hpp"
  15. #include "../common/random.hpp"
  16. #include "../common/showmsg.hpp"
  17. #include "../common/socket.hpp" // session[]
  18. #include "../common/strlib.hpp" // safestrncpy()
  19. #include "../common/timer.hpp"
  20. #include "../common/utilities.hpp"
  21. #include "../common/utils.hpp"
  22. #include "achievement.hpp"
  23. #include "atcommand.hpp" // get_atcommand_level()
  24. #include "battle.hpp" // battle_config
  25. #include "battleground.hpp"
  26. #include "buyingstore.hpp" // struct s_buyingstore
  27. #include "channel.hpp"
  28. #include "chat.hpp"
  29. #include "chrif.hpp"
  30. #include "clan.hpp"
  31. #include "clif.hpp"
  32. #include "date.hpp" // is_day_of_*()
  33. #include "duel.hpp"
  34. #include "elemental.hpp"
  35. #include "guild.hpp"
  36. #include "homunculus.hpp"
  37. #include "instance.hpp"
  38. #include "intif.hpp"
  39. #include "itemdb.hpp" // MAX_ITEMGROUP
  40. #include "log.hpp"
  41. #include "map.hpp"
  42. #include "mercenary.hpp"
  43. #include "mob.hpp"
  44. #include "npc.hpp"
  45. #include "party.hpp" // party_search()
  46. #include "pc_groups.hpp"
  47. #include "pet.hpp" // pet_unlocktarget()
  48. #include "quest.hpp"
  49. #include "script.hpp" // struct script_reg, struct script_regstr
  50. #include "searchstore.hpp" // struct s_search_store_info
  51. #include "status.hpp" // OPTION_*, struct weapon_atk
  52. #include "storage.hpp"
  53. #include "unit.hpp" // unit_stop_attack(), unit_stop_walking()
  54. #include "vending.hpp" // struct s_vending
  55. using namespace rathena;
  56. int pc_split_atoui(char* str, unsigned int* val, char sep, int max);
  57. static inline bool pc_attendance_rewarded_today( struct map_session_data* sd );
  58. #define PVP_CALCRANK_INTERVAL 1000 // PVP calculation interval
  59. #define MAX_LEVEL_BASE_EXP 99999999 ///< Max Base EXP for player on Max Base Level
  60. #define MAX_LEVEL_JOB_EXP 999999999 ///< Max Job EXP for player on Max Job Level
  61. static unsigned int statp[MAX_LEVEL+1];
  62. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  63. static unsigned int level_penalty[3][CLASS_MAX][MAX_LEVEL*2+1];
  64. #endif
  65. // h-files are for declarations, not for implementations... [Shinomori]
  66. struct skill_tree_entry skill_tree[CLASS_COUNT][MAX_SKILL_TREE];
  67. // timer for night.day implementation
  68. int day_timer_tid = INVALID_TIMER;
  69. int night_timer_tid = INVALID_TIMER;
  70. struct eri *pc_sc_display_ers = NULL;
  71. struct eri *num_reg_ers;
  72. struct eri *str_reg_ers;
  73. int pc_expiration_tid = INVALID_TIMER;
  74. struct fame_list smith_fame_list[MAX_FAME_LIST];
  75. struct fame_list chemist_fame_list[MAX_FAME_LIST];
  76. struct fame_list taekwon_fame_list[MAX_FAME_LIST];
  77. struct s_job_info job_info[CLASS_COUNT];
  78. const std::string AttendanceDatabase::getDefaultLocation(){
  79. return std::string(db_path) + "/attendance.yml";
  80. }
  81. /**
  82. * Reads and parses an entry from the attendance_db.
  83. * @param node: YAML node containing the entry.
  84. * @return count of successfully parsed rows
  85. */
  86. uint64 AttendanceDatabase::parseBodyNode(const YAML::Node &node){
  87. uint32 start;
  88. if( !this->asUInt32( node, "Start", start ) ){
  89. return 0;
  90. }
  91. std::shared_ptr<s_attendance_period> attendance_period = this->find( start );
  92. bool exists = attendance_period != nullptr;
  93. if( !exists ){
  94. if( !this->nodeExists( node, "End" ) ){
  95. this->invalidWarning( node, "Node \"End\" is missing.\n" );
  96. return 0;
  97. }
  98. if( !this->nodeExists( node, "Rewards" ) ){
  99. this->invalidWarning( node, "Node \"Rewards\" is missing.\n" );
  100. return 0;
  101. }
  102. attendance_period = std::make_shared<s_attendance_period>();
  103. attendance_period->start = start;
  104. }
  105. // If it does not exist yet, we need to check it for sure
  106. bool requiresCollisionDetection = !exists;
  107. if( this->nodeExists( node, "End" ) ){
  108. uint32 end;
  109. if( !this->asUInt32( node, "End", end ) ){
  110. return 0;
  111. }
  112. // If the period is outdated already, we do not even bother parsing
  113. if( end < date_get( DT_YYYYMMDD ) ){
  114. this->invalidWarning( node, "Node \"End\" date %u has already passed, skipping.\n", end );
  115. return 0;
  116. }
  117. if( !exists || attendance_period->end != end ){
  118. requiresCollisionDetection = true;
  119. attendance_period->end = end;
  120. }
  121. }
  122. // Collision detection
  123. if( requiresCollisionDetection ){
  124. bool collision = false;
  125. for( std::pair<const uint32,std::shared_ptr<s_attendance_period>>& pair : *this ){
  126. std::shared_ptr<s_attendance_period> period = pair.second;
  127. if( exists && period->start == attendance_period->start ){
  128. // Dont compare to yourself
  129. continue;
  130. }
  131. // Check if start is inside another period
  132. if( period->start <= attendance_period->start && start <= period->end ){
  133. this->invalidWarning( node, "Node \"Start\" period %u intersects with period %u-%u, skipping.\n", attendance_period->start, period->start, period->end );
  134. collision = true;
  135. break;
  136. }
  137. // Check if end is inside another period
  138. if( period->start <= attendance_period->end && attendance_period->end <= period->end ){
  139. this->invalidWarning( node, "Node \"End\" period %u intersects with period %u-%u.\n", attendance_period->start, period->start, period->end );
  140. collision = true;
  141. break;
  142. }
  143. }
  144. if( collision ){
  145. return 0;
  146. }
  147. }
  148. if( this->nodeExists( node, "Rewards" ) ){
  149. const YAML::Node& rewardsNode = node["Rewards"];
  150. for( const YAML::Node& rewardNode : rewardsNode ){
  151. uint32 day;
  152. if( !this->asUInt32( rewardNode, "Day", day ) ){
  153. continue;
  154. }
  155. day -= 1;
  156. std::shared_ptr<s_attendance_reward> reward = util::map_find( attendance_period->rewards, day );
  157. bool reward_exists = reward != nullptr;
  158. if( !reward_exists ){
  159. if( !this->nodeExists( rewardNode, "ItemId" ) ){
  160. this->invalidWarning( rewardNode, "Node \"ItemId\" is missing.\n" );
  161. return 0;
  162. }
  163. reward = std::make_shared<s_attendance_reward>();
  164. }
  165. if( this->nodeExists( rewardNode, "ItemId" ) ){
  166. uint16 item_id;
  167. if( !this->asUInt16( rewardNode, "ItemId", item_id ) ){
  168. continue;
  169. }
  170. if( item_id == 0 || !itemdb_exists( item_id ) ){
  171. ShowError( "pc_attendance_load: Unknown item ID %hu for day %d.\n", item_id, day + 1 );
  172. continue;
  173. }
  174. reward->item_id = item_id;
  175. }
  176. if( this->nodeExists( rewardNode, "Amount" ) ){
  177. uint16 amount;
  178. if( !this->asUInt16( rewardNode, "Amount", amount ) ){
  179. continue;
  180. }
  181. if( amount == 0 ){
  182. ShowWarning( "pc_attendance_load: Invalid reward count %hu for day %d. Defaulting to 1...\n", amount, day + 1 );
  183. amount = 1;
  184. }else if( amount > MAX_AMOUNT ){
  185. ShowError( "pc_attendance_load: Reward count %hu above maximum %hu for day %d. Defaulting to %hu...\n", amount, MAX_AMOUNT, day + 1, MAX_AMOUNT );
  186. amount = MAX_AMOUNT;
  187. }
  188. reward->amount = amount;
  189. }else{
  190. if( !reward_exists ){
  191. reward->amount = 1;
  192. }
  193. }
  194. if( !reward_exists ){
  195. attendance_period->rewards[day] = reward;
  196. }
  197. }
  198. bool missing_day = false;
  199. for( int day = 0; day < attendance_period->rewards.size(); day++ ){
  200. if( attendance_period->rewards.find( day ) == attendance_period->rewards.end() ){
  201. ShowError( "pc_attendance_load: Reward for day %d is missing.\n", day + 1 );
  202. missing_day = true;
  203. break;
  204. }
  205. }
  206. if( missing_day ){
  207. return 0;
  208. }
  209. }
  210. if( !exists ){
  211. this->put( start, attendance_period );
  212. }
  213. return 1;
  214. }
  215. AttendanceDatabase attendance_db;
  216. #define MOTD_LINE_SIZE 128
  217. static char motd_text[MOTD_LINE_SIZE][CHAT_SIZE_MAX]; // Message of the day buffer [Valaris]
  218. bool reg_load;
  219. /**
  220. * Translation table from athena equip index to aegis bitmask
  221. */
  222. unsigned int equip_bitmask[EQI_MAX] = {
  223. EQP_ACC_L, // EQI_ACC_L
  224. EQP_ACC_R, // EQI_ACC_R
  225. EQP_SHOES, // EQI_SHOES
  226. EQP_GARMENT, // EQI_GARMENT
  227. EQP_HEAD_LOW, // EQI_HEAD_LOW
  228. EQP_HEAD_MID, // EQI_HEAD_MID
  229. EQP_HEAD_TOP, // EQI_HEAD_TOP
  230. EQP_ARMOR, // EQI_ARMOR
  231. EQP_HAND_L, // EQI_HAND_L
  232. EQP_HAND_R, // EQI_HAND_R
  233. EQP_COSTUME_HEAD_TOP, // EQI_COSTUME_HEAD_TOP
  234. EQP_COSTUME_HEAD_MID, // EQI_COSTUME_HEAD_MID
  235. EQP_COSTUME_HEAD_LOW, // EQI_COSTUME_HEAD_LOW
  236. EQP_COSTUME_GARMENT, // EQI_COSTUME_GARMENT
  237. EQP_AMMO, // EQI_AMMO
  238. EQP_SHADOW_ARMOR, // EQI_SHADOW_ARMOR
  239. EQP_SHADOW_WEAPON, // EQI_SHADOW_WEAPON
  240. EQP_SHADOW_SHIELD, // EQI_SHADOW_SHIELD
  241. EQP_SHADOW_SHOES, // EQI_SHADOW_SHOES
  242. EQP_SHADOW_ACC_R, // EQI_SHADOW_ACC_R
  243. EQP_SHADOW_ACC_L // EQI_SHADOW_ACC_L
  244. };
  245. //Links related info to the sd->hate_mob[]/sd->feel_map[] entries
  246. const struct sg_data sg_info[MAX_PC_FEELHATE] = {
  247. { SG_SUN_ANGER, SG_SUN_BLESS, SG_SUN_COMFORT, "PC_FEEL_SUN", "PC_HATE_MOB_SUN", is_day_of_sun },
  248. { SG_MOON_ANGER, SG_MOON_BLESS, SG_MOON_COMFORT, "PC_FEEL_MOON", "PC_HATE_MOB_MOON", is_day_of_moon },
  249. { SG_STAR_ANGER, SG_STAR_BLESS, SG_STAR_COMFORT, "PC_FEEL_STAR", "PC_HATE_MOB_STAR", is_day_of_star }
  250. };
  251. void pc_set_reg_load( bool val ){
  252. reg_load = val;
  253. }
  254. /**
  255. * Item Cool Down Delay Saving
  256. * Struct item_cd is not a member of struct map_session_data
  257. * to keep cooldowns in memory between player log-ins.
  258. * All cooldowns are reset when server is restarted.
  259. **/
  260. DBMap* itemcd_db = NULL; // char_id -> struct item_cd
  261. struct item_cd {
  262. t_tick tick[MAX_ITEMDELAYS]; //tick
  263. unsigned short nameid[MAX_ITEMDELAYS]; //item id
  264. };
  265. /**
  266. * Converts a class to its array index for CLASS_COUNT defined arrays.
  267. * Note that it does not do a validity check for speed purposes, where parsing
  268. * player input make sure to use a pcdb_checkid first!
  269. * @param class_ Job ID see enum e_job
  270. * @return Class Index
  271. */
  272. int pc_class2idx(int class_) {
  273. if (class_ >= JOB_NOVICE_HIGH)
  274. return class_- JOB_NOVICE_HIGH+JOB_MAX_BASIC;
  275. return class_;
  276. }
  277. /**
  278. * Get player's group ID
  279. * @param sd
  280. * @return Group ID
  281. */
  282. int pc_get_group_id(struct map_session_data *sd) {
  283. return sd->group_id;
  284. }
  285. /** Get player's group Level
  286. * @param sd
  287. * @return Group Level
  288. */
  289. int pc_get_group_level(struct map_session_data *sd) {
  290. return sd->group_level;
  291. }
  292. static TIMER_FUNC(pc_invincible_timer){
  293. struct map_session_data *sd;
  294. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  295. return 1;
  296. if(sd->invincible_timer != tid){
  297. ShowError("invincible_timer %d != %d\n",sd->invincible_timer,tid);
  298. return 0;
  299. }
  300. sd->invincible_timer = INVALID_TIMER;
  301. skill_unit_move(&sd->bl,tick,1);
  302. return 0;
  303. }
  304. void pc_setinvincibletimer(struct map_session_data* sd, int val) {
  305. nullpo_retv(sd);
  306. if( sd->invincible_timer != INVALID_TIMER )
  307. delete_timer(sd->invincible_timer,pc_invincible_timer);
  308. sd->invincible_timer = add_timer(gettick()+val,pc_invincible_timer,sd->bl.id,0);
  309. }
  310. void pc_delinvincibletimer(struct map_session_data* sd)
  311. {
  312. nullpo_retv(sd);
  313. if( sd->invincible_timer != INVALID_TIMER )
  314. {
  315. delete_timer(sd->invincible_timer,pc_invincible_timer);
  316. sd->invincible_timer = INVALID_TIMER;
  317. skill_unit_move(&sd->bl,gettick(),1);
  318. }
  319. }
  320. static TIMER_FUNC(pc_spiritball_timer){
  321. struct map_session_data *sd;
  322. int i;
  323. if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
  324. return 1;
  325. if( sd->spiritball <= 0 )
  326. {
  327. 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);
  328. sd->spiritball = 0;
  329. return 0;
  330. }
  331. ARR_FIND(0, sd->spiritball, i, sd->spirit_timer[i] == tid);
  332. if( i == sd->spiritball )
  333. {
  334. ShowError("pc_spiritball_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
  335. return 0;
  336. }
  337. sd->spiritball--;
  338. if( i != sd->spiritball )
  339. memmove(sd->spirit_timer+i, sd->spirit_timer+i+1, (sd->spiritball-i)*sizeof(int));
  340. sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
  341. clif_spiritball(&sd->bl);
  342. return 0;
  343. }
  344. /**
  345. * Adds a spiritball to player for 'interval' ms
  346. * @param sd
  347. * @param interval
  348. * @param max
  349. */
  350. void pc_addspiritball(struct map_session_data *sd,int interval,int max)
  351. {
  352. int tid;
  353. uint8 i;
  354. nullpo_retv(sd);
  355. if(max > MAX_SPIRITBALL)
  356. max = MAX_SPIRITBALL;
  357. if(sd->spiritball < 0)
  358. sd->spiritball = 0;
  359. if( sd->spiritball && sd->spiritball >= max )
  360. {
  361. if(sd->spirit_timer[0] != INVALID_TIMER)
  362. delete_timer(sd->spirit_timer[0],pc_spiritball_timer);
  363. sd->spiritball--;
  364. if( sd->spiritball != 0 )
  365. memmove(sd->spirit_timer+0, sd->spirit_timer+1, (sd->spiritball)*sizeof(int));
  366. sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
  367. }
  368. tid = add_timer(gettick()+interval, pc_spiritball_timer, sd->bl.id, 0);
  369. 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);
  370. if( i != sd->spiritball )
  371. memmove(sd->spirit_timer+i+1, sd->spirit_timer+i, (sd->spiritball-i)*sizeof(int));
  372. sd->spirit_timer[i] = tid;
  373. sd->spiritball++;
  374. if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
  375. clif_millenniumshield(&sd->bl,sd->spiritball);
  376. else
  377. clif_spiritball(&sd->bl);
  378. }
  379. /**
  380. * Removes number of spiritball from player
  381. * @param sd
  382. * @param count
  383. * @param type 1 = doesn't give client effect
  384. */
  385. void pc_delspiritball(struct map_session_data *sd,int count,int type)
  386. {
  387. uint8 i;
  388. nullpo_retv(sd);
  389. if(sd->spiritball <= 0) {
  390. sd->spiritball = 0;
  391. return;
  392. }
  393. if(count == 0)
  394. return;
  395. if(count > sd->spiritball)
  396. count = sd->spiritball;
  397. sd->spiritball -= count;
  398. if(count > MAX_SPIRITBALL)
  399. count = MAX_SPIRITBALL;
  400. for(i=0;i<count;i++) {
  401. if(sd->spirit_timer[i] != INVALID_TIMER) {
  402. delete_timer(sd->spirit_timer[i],pc_spiritball_timer);
  403. sd->spirit_timer[i] = INVALID_TIMER;
  404. }
  405. }
  406. for(i=count;i<MAX_SPIRITBALL;i++) {
  407. sd->spirit_timer[i-count] = sd->spirit_timer[i];
  408. sd->spirit_timer[i] = INVALID_TIMER;
  409. }
  410. if(!type) {
  411. if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
  412. clif_millenniumshield(&sd->bl,sd->spiritball);
  413. else
  414. clif_spiritball(&sd->bl);
  415. }
  416. }
  417. static TIMER_FUNC(pc_soulball_timer)
  418. {
  419. struct map_session_data *sd;
  420. if ((sd = (struct map_session_data *)map_id2sd(id)) == nullptr || sd->bl.type != BL_PC)
  421. return 1;
  422. if (sd->soulball <= 0) {
  423. ShowError("pc_soulball_timer: %d soulball's available. (aid=%d tid=%d)\n", sd->soulball, sd->status.account_id, tid);
  424. sd->soulball = 0;
  425. return 0;
  426. }
  427. int i;
  428. ARR_FIND(0, sd->soulball, i, sd->soul_timer[i] == tid);
  429. if (i == sd->soulball) {
  430. ShowError("pc_soulball_timer: timer not found (aid=%d tid=%d)\n", sd->status.account_id, tid);
  431. return 0;
  432. }
  433. sd->soulball--;
  434. if (i != sd->soulball)
  435. memmove(sd->soul_timer + i, sd->soul_timer + i + 1, (sd->soulball - i) * sizeof(int));
  436. sd->soul_timer[sd->soulball] = INVALID_TIMER;
  437. clif_soulball(sd);
  438. return 0;
  439. }
  440. /**
  441. * Adds a soulball to player for 'interval' ms
  442. * @param sd: Player data
  443. * @param interval: Duration
  444. * @param max: Max amount of soulballs
  445. */
  446. int pc_addsoulball(struct map_session_data *sd, int interval, int max)
  447. {
  448. nullpo_ret(sd);
  449. max = min(max, MAX_SOUL_BALL);
  450. sd->soulball = cap_value(sd->soulball, 0, MAX_SOUL_BALL);
  451. if (sd->soulball && sd->soulball >= max) {
  452. if (sd->soul_timer[0] != INVALID_TIMER)
  453. delete_timer(sd->soul_timer[0], pc_soulball_timer);
  454. sd->soulball--;
  455. if (sd->soulball != 0)
  456. memmove(sd->soul_timer + 0, sd->soul_timer + 1, (sd->soulball) * sizeof(int));
  457. sd->soul_timer[sd->soulball] = INVALID_TIMER;
  458. }
  459. if (interval > 0) {
  460. int tid = add_timer(gettick() + interval, pc_soulball_timer, sd->bl.id, 0), i;
  461. ARR_FIND(0, sd->soulball, i, sd->soul_timer[i] == INVALID_TIMER || DIFF_TICK(get_timer(tid)->tick, get_timer(sd->soul_timer[i])->tick) < 0);
  462. if (i != sd->soulball)
  463. memmove(sd->soul_timer + i + 1, sd->soul_timer + i, (sd->soulball - i) * sizeof(int));
  464. sd->soul_timer[i] = tid;
  465. }
  466. sd->soulball++;
  467. clif_soulball(sd);
  468. return 0;
  469. }
  470. /**
  471. * Removes number of soulball from player
  472. * @param sd: Player data
  473. * @param count: Amount to remove
  474. * @param type: 1 = doesn't give client effect
  475. */
  476. int pc_delsoulball(struct map_session_data *sd, int count, int type)
  477. {
  478. nullpo_ret(sd);
  479. if (sd->soulball <= 0) {
  480. sd->soulball = 0;
  481. return 0;
  482. }
  483. if (count <= 0)
  484. return 0;
  485. if (count > sd->soulball)
  486. count = sd->soulball;
  487. sd->soulball -= count;
  488. if (count > MAX_SKILL_LEVEL)
  489. count = MAX_SKILL_LEVEL;
  490. for (int i = 0; i < count; i++) {
  491. if (sd->soul_timer[i] != INVALID_TIMER) {
  492. delete_timer(sd->soul_timer[i], pc_soulball_timer);
  493. sd->soul_timer[i] = INVALID_TIMER;
  494. }
  495. }
  496. for (int i = count; i < MAX_SKILL_LEVEL; i++) {
  497. sd->soul_timer[i - count] = sd->soul_timer[i];
  498. sd->soul_timer[i] = INVALID_TIMER;
  499. }
  500. if (!type)
  501. clif_soulball(sd);
  502. return 0;
  503. }
  504. /**
  505. * Increases a player's fame points and displays a notice to him
  506. * @param sd Player
  507. * @param count Fame point
  508. */
  509. void pc_addfame(struct map_session_data *sd,int count)
  510. {
  511. enum e_rank ranktype;
  512. nullpo_retv(sd);
  513. sd->status.fame += count;
  514. if(sd->status.fame > MAX_FAME)
  515. sd->status.fame = MAX_FAME;
  516. switch(sd->class_&MAPID_UPPERMASK){
  517. case MAPID_BLACKSMITH: ranktype = RANK_BLACKSMITH; break;
  518. case MAPID_ALCHEMIST: ranktype = RANK_ALCHEMIST; break;
  519. case MAPID_TAEKWON: ranktype = RANK_TAEKWON; break;
  520. default:
  521. ShowWarning( "pc_addfame: Trying to add fame to class '%s'(%d).\n", job_name(sd->class_), sd->class_ );
  522. return;
  523. }
  524. clif_update_rankingpoint(sd,ranktype,count);
  525. chrif_updatefamelist(sd);
  526. }
  527. /**
  528. * Check whether a player ID is in the fame rankers list of its job, returns his/her position if so, 0 else
  529. * @param sd
  530. * @param job Job use enum e_mapid
  531. * @return Rank
  532. */
  533. unsigned char pc_famerank(uint32 char_id, int job)
  534. {
  535. uint8 i;
  536. switch(job){
  537. case MAPID_BLACKSMITH: // Blacksmith
  538. for(i = 0; i < MAX_FAME_LIST; i++){
  539. if(smith_fame_list[i].id == char_id)
  540. return i + 1;
  541. }
  542. break;
  543. case MAPID_ALCHEMIST: // Alchemist
  544. for(i = 0; i < MAX_FAME_LIST; i++){
  545. if(chemist_fame_list[i].id == char_id)
  546. return i + 1;
  547. }
  548. break;
  549. case MAPID_TAEKWON: // Taekwon
  550. for(i = 0; i < MAX_FAME_LIST; i++){
  551. if(taekwon_fame_list[i].id == char_id)
  552. return i + 1;
  553. }
  554. break;
  555. }
  556. return 0;
  557. }
  558. /**
  559. * Restart player's HP & SP value
  560. * @param sd
  561. * @param type Restart type: 1 - Normal Resurection
  562. */
  563. void pc_setrestartvalue(struct map_session_data *sd, char type) {
  564. struct status_data *status, *b_status;
  565. nullpo_retv(sd);
  566. b_status = &sd->base_status;
  567. status = &sd->battle_status;
  568. if (type&1) { //Normal resurrection
  569. status->hp = 1; //Otherwise status_heal may fail if dead.
  570. status_heal(&sd->bl, b_status->hp, 0, 1);
  571. if( status->sp < b_status->sp )
  572. status_set_sp(&sd->bl, b_status->sp, 1);
  573. } else { //Just for saving on the char-server (with values as if respawned)
  574. sd->status.hp = b_status->hp;
  575. sd->status.sp = (status->sp < b_status->sp)?b_status->sp:status->sp;
  576. }
  577. }
  578. /*==========================================
  579. Rental System
  580. *------------------------------------------*/
  581. /**
  582. * Ends a rental and removes the item/effect
  583. * @param tid: Tick ID
  584. * @param tick: Timer
  585. * @param id: Timer ID
  586. * @param data: Data
  587. * @return false - failure, true - success
  588. */
  589. TIMER_FUNC(pc_inventory_rental_end){
  590. struct map_session_data *sd = map_id2sd(id);
  591. if( sd == NULL )
  592. return 0;
  593. if( tid != sd->rental_timer ) {
  594. ShowError("pc_inventory_rental_end: invalid timer id.\n");
  595. return 0;
  596. }
  597. pc_inventory_rentals(sd);
  598. return 1;
  599. }
  600. /**
  601. * Removes the rental timer from the player
  602. * @param sd: Player data
  603. */
  604. void pc_inventory_rental_clear(struct map_session_data *sd)
  605. {
  606. if( sd->rental_timer != INVALID_TIMER ) {
  607. delete_timer(sd->rental_timer, pc_inventory_rental_end);
  608. sd->rental_timer = INVALID_TIMER;
  609. }
  610. }
  611. /**
  612. * Check for items in the player's inventory that are rental type
  613. * @param sd: Player data
  614. */
  615. void pc_inventory_rentals(struct map_session_data *sd)
  616. {
  617. int i, c = 0;
  618. unsigned int next_tick = UINT_MAX;
  619. for( i = 0; i < MAX_INVENTORY; i++ ) { // Check for Rentals on Inventory
  620. if( sd->inventory.u.items_inventory[i].nameid == 0 )
  621. continue; // Nothing here
  622. if( sd->inventory.u.items_inventory[i].expire_time == 0 )
  623. continue;
  624. if( sd->inventory.u.items_inventory[i].expire_time <= time(NULL) ) {
  625. if (sd->inventory_data[i]->unequip_script)
  626. run_script(sd->inventory_data[i]->unequip_script, 0, sd->bl.id, fake_nd->bl.id);
  627. clif_rental_expired(sd->fd, i, sd->inventory.u.items_inventory[i].nameid);
  628. pc_delitem(sd, i, sd->inventory.u.items_inventory[i].amount, 0, 0, LOG_TYPE_OTHER);
  629. } else {
  630. unsigned int expire_tick = (unsigned int)(sd->inventory.u.items_inventory[i].expire_time - time(NULL));
  631. clif_rental_time(sd->fd, sd->inventory.u.items_inventory[i].nameid, (int)expire_tick);
  632. next_tick = umin(expire_tick * 1000U, next_tick);
  633. c++;
  634. }
  635. }
  636. 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
  637. sd->rental_timer = add_timer(gettick() + umin(next_tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
  638. else
  639. sd->rental_timer = INVALID_TIMER;
  640. }
  641. /**
  642. * Add a rental item to the player and adjusts the rental timer appropriately
  643. * @param sd: Player data
  644. * @param seconds: Rental time
  645. */
  646. void pc_inventory_rental_add(struct map_session_data *sd, unsigned int seconds)
  647. {
  648. t_tick tick = seconds * 1000;
  649. if( sd == NULL )
  650. return;
  651. if( sd->rental_timer != INVALID_TIMER ) {
  652. const struct TimerData * td;
  653. td = get_timer(sd->rental_timer);
  654. if( DIFF_TICK(td->tick, gettick()) > tick ) { // Update Timer as this one ends first than the current one
  655. pc_inventory_rental_clear(sd);
  656. sd->rental_timer = add_timer(gettick() + tick, pc_inventory_rental_end, sd->bl.id, 0);
  657. }
  658. } else
  659. sd->rental_timer = add_timer(gettick() + i64min(tick,3600000), pc_inventory_rental_end, sd->bl.id, 0);
  660. }
  661. /**
  662. * Check if the player can sell the current item
  663. * @param sd: map_session_data of the player
  664. * @param item: struct of the checking item
  665. * @param shoptype: NPC's sub type see enum npc_subtype
  666. * @return bool 'true' is sellable, 'false' otherwise
  667. */
  668. bool pc_can_sell_item(struct map_session_data *sd, struct item *item, enum npc_subtype shoptype) {
  669. if (sd == NULL || item == NULL)
  670. return false;
  671. if (item->equip > 0 || item->amount < 0)
  672. return false;
  673. if (battle_config.hide_fav_sell && item->favorite)
  674. return false; //Cannot sell favs (optional config)
  675. if (!battle_config.rental_transaction && item->expire_time)
  676. return false; // Cannot Sell Rental Items
  677. if( item->equipSwitch ){
  678. return false;
  679. }
  680. if (itemdb_ishatched_egg(item))
  681. return false;
  682. switch (shoptype) {
  683. case NPCTYPE_SHOP:
  684. if (item->bound && battle_config.allow_bound_sell&ISR_BOUND_SELLABLE && (
  685. item->bound != BOUND_GUILD ||
  686. (sd->guild && sd->status.char_id == sd->guild->member[0].char_id) ||
  687. (item->bound == BOUND_GUILD && !(battle_config.allow_bound_sell&ISR_BOUND_GUILDLEADER_ONLY))
  688. ))
  689. return true;
  690. break;
  691. case NPCTYPE_ITEMSHOP:
  692. if (item->bound && battle_config.allow_bound_sell&ISR_BOUND && (
  693. item->bound != BOUND_GUILD ||
  694. (sd->guild && sd->status.char_id == sd->guild->member[0].char_id) ||
  695. (item->bound == BOUND_GUILD && !(battle_config.allow_bound_sell&ISR_BOUND_GUILDLEADER_ONLY))
  696. ))
  697. return true;
  698. else if (!item->bound) {
  699. struct item_data *itd = itemdb_search(item->nameid);
  700. if (itd && itd->flag.trade_restriction&8 && battle_config.allow_bound_sell&ISR_SELLABLE)
  701. return true;
  702. }
  703. break;
  704. }
  705. if (!itemdb_cansell(item, pc_get_group_level(sd)))
  706. return false;
  707. if (item->bound && !pc_can_give_bounded_items(sd))
  708. return false; // Don't allow sale of bound items
  709. return true;
  710. }
  711. /**
  712. * Determines if player can give / drop / trade / vend items
  713. */
  714. bool pc_can_give_items(struct map_session_data *sd)
  715. {
  716. return pc_has_permission(sd, PC_PERM_TRADE);
  717. }
  718. /**
  719. * Determines if player can give / drop / trade / vend bounded items
  720. */
  721. bool pc_can_give_bounded_items(struct map_session_data *sd)
  722. {
  723. return pc_has_permission(sd, PC_PERM_TRADE_BOUNDED);
  724. }
  725. /*==========================================
  726. * Prepares character for saving.
  727. * @param sd
  728. *------------------------------------------*/
  729. void pc_makesavestatus(struct map_session_data *sd) {
  730. nullpo_retv(sd);
  731. if(!battle_config.save_clothcolor)
  732. sd->status.clothes_color = 0;
  733. if(!battle_config.save_body_style)
  734. sd->status.body = 0;
  735. //Only copy the Cart/Peco/Falcon options, the rest are handled via
  736. //status change load/saving. [Skotlex]
  737. #ifdef NEW_CARTS
  738. sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
  739. #else
  740. sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_CART|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
  741. #endif
  742. if (sd->sc.data[SC_JAILED]) { //When Jailed, do not move last point.
  743. if(pc_isdead(sd)){
  744. pc_setrestartvalue(sd, 0);
  745. } else {
  746. sd->status.hp = sd->battle_status.hp;
  747. sd->status.sp = sd->battle_status.sp;
  748. }
  749. sd->status.last_point.map = sd->mapindex;
  750. sd->status.last_point.x = sd->bl.x;
  751. sd->status.last_point.y = sd->bl.y;
  752. return;
  753. }
  754. if(pc_isdead(sd)) {
  755. pc_setrestartvalue(sd, 0);
  756. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  757. } else {
  758. sd->status.hp = sd->battle_status.hp;
  759. sd->status.sp = sd->battle_status.sp;
  760. sd->status.last_point.map = sd->mapindex;
  761. sd->status.last_point.x = sd->bl.x;
  762. sd->status.last_point.y = sd->bl.y;
  763. }
  764. if(map_getmapflag(sd->bl.m, MF_NOSAVE)) {
  765. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  766. if(mapdata->save.map)
  767. memcpy(&sd->status.last_point,&mapdata->save,sizeof(sd->status.last_point));
  768. else
  769. memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
  770. }
  771. }
  772. /*==========================================
  773. * Off init ? Connection?
  774. *------------------------------------------*/
  775. void pc_setnewpc(struct map_session_data *sd, uint32 account_id, uint32 char_id, int login_id1, t_tick client_tick, int sex, int fd) {
  776. nullpo_retv(sd);
  777. sd->bl.id = account_id;
  778. sd->status.account_id = account_id;
  779. sd->status.char_id = char_id;
  780. sd->status.sex = sex;
  781. sd->login_id1 = login_id1;
  782. sd->login_id2 = 0; // at this point, we can not know the value :(
  783. sd->client_tick = client_tick;
  784. sd->state.active = 0; //to be set to 1 after player is fully authed and loaded.
  785. sd->bl.type = BL_PC;
  786. if(battle_config.prevent_logout_trigger&PLT_LOGIN)
  787. sd->canlog_tick = gettick();
  788. //Required to prevent homunculus copuing a base speed of 0.
  789. sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
  790. }
  791. /**
  792. * Get equip point for an equip
  793. * @param sd
  794. * @param id
  795. */
  796. int pc_equippoint_sub(struct map_session_data *sd,struct item_data* id){
  797. int ep = 0;
  798. nullpo_ret(sd);
  799. nullpo_ret(id);
  800. if (!itemdb_isequip2(id))
  801. return 0; //Not equippable by players.
  802. ep = id->equip;
  803. if(id->look == W_DAGGER || id->look == W_1HSWORD || id->look == W_1HAXE) {
  804. if(pc_checkskill(sd,AS_LEFT) > 0 || (sd->class_&MAPID_UPPERMASK) == MAPID_ASSASSIN || (sd->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO) { //Kagerou and Oboro can dual wield daggers. [Rytech]
  805. if (ep == EQP_WEAPON)
  806. return EQP_ARMS;
  807. if (ep == EQP_SHADOW_WEAPON)
  808. return EQP_SHADOW_ARMS;
  809. }
  810. }
  811. return ep;
  812. }
  813. /**
  814. * Get equip point for an equip
  815. * @param sd
  816. * @param n Equip index in inventory
  817. */
  818. int pc_equippoint(struct map_session_data *sd,int n){
  819. nullpo_ret(sd);
  820. return pc_equippoint_sub(sd,sd->inventory_data[n]);
  821. }
  822. /**
  823. * Fill inventory_data with struct *item_data through inventory (fill with struct *item)
  824. * @param sd : player session
  825. * @return 0 sucess, 1:invalid sd
  826. */
  827. void pc_setinventorydata(struct map_session_data *sd)
  828. {
  829. uint8 i;
  830. nullpo_retv(sd);
  831. for(i = 0; i < MAX_INVENTORY; i++) {
  832. unsigned short id = sd->inventory.u.items_inventory[i].nameid;
  833. sd->inventory_data[i] = id?itemdb_search(id):NULL;
  834. }
  835. }
  836. /**
  837. * 'Calculates' weapon type
  838. * @param sd : Player
  839. */
  840. void pc_calcweapontype(struct map_session_data *sd)
  841. {
  842. nullpo_retv(sd);
  843. // single-hand
  844. if(sd->weapontype2 == W_FIST) {
  845. sd->status.weapon = sd->weapontype1;
  846. return;
  847. }
  848. if(sd->weapontype1 == W_FIST) {
  849. sd->status.weapon = sd->weapontype2;
  850. return;
  851. }
  852. // dual-wield
  853. sd->status.weapon = 0;
  854. switch (sd->weapontype1){
  855. case W_DAGGER:
  856. switch (sd->weapontype2) {
  857. case W_DAGGER: sd->status.weapon = W_DOUBLE_DD; break;
  858. case W_1HSWORD: sd->status.weapon = W_DOUBLE_DS; break;
  859. case W_1HAXE: sd->status.weapon = W_DOUBLE_DA; break;
  860. }
  861. break;
  862. case W_1HSWORD:
  863. switch (sd->weapontype2) {
  864. case W_DAGGER: sd->status.weapon = W_DOUBLE_DS; break;
  865. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SS; break;
  866. case W_1HAXE: sd->status.weapon = W_DOUBLE_SA; break;
  867. }
  868. break;
  869. case W_1HAXE:
  870. switch (sd->weapontype2) {
  871. case W_DAGGER: sd->status.weapon = W_DOUBLE_DA; break;
  872. case W_1HSWORD: sd->status.weapon = W_DOUBLE_SA; break;
  873. case W_1HAXE: sd->status.weapon = W_DOUBLE_AA; break;
  874. }
  875. }
  876. // unknown, default to right hand type
  877. if (!sd->status.weapon)
  878. sd->status.weapon = sd->weapontype1;
  879. }
  880. /**
  881. * Set equip index
  882. * @param sd : Player
  883. */
  884. void pc_setequipindex(struct map_session_data *sd)
  885. {
  886. uint16 i;
  887. nullpo_retv(sd);
  888. for (i = 0; i < EQI_MAX; i++){
  889. sd->equip_index[i] = -1;
  890. sd->equip_switch_index[i] = -1;
  891. }
  892. for (i = 0; i < MAX_INVENTORY; i++) {
  893. if (sd->inventory.u.items_inventory[i].nameid <= 0)
  894. continue;
  895. if (sd->inventory.u.items_inventory[i].equip) {
  896. uint8 j;
  897. for (j = 0; j < EQI_MAX; j++)
  898. if (sd->inventory.u.items_inventory[i].equip & equip_bitmask[j])
  899. sd->equip_index[j] = i;
  900. if (sd->inventory.u.items_inventory[i].equip & EQP_HAND_R) {
  901. if (sd->inventory_data[i])
  902. sd->weapontype1 = sd->inventory_data[i]->look;
  903. else
  904. sd->weapontype1 = 0;
  905. }
  906. if( sd->inventory.u.items_inventory[i].equip & EQP_HAND_L ) {
  907. if( sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON )
  908. sd->weapontype2 = sd->inventory_data[i]->look;
  909. else
  910. sd->weapontype2 = 0;
  911. }
  912. }
  913. if (sd->inventory.u.items_inventory[i].equipSwitch) {
  914. for (uint8 j = 0; j < EQI_MAX; j++) {
  915. if (sd->inventory.u.items_inventory[i].equipSwitch & equip_bitmask[j]) {
  916. sd->equip_switch_index[j] = i;
  917. }
  918. }
  919. }
  920. }
  921. pc_calcweapontype(sd);
  922. }
  923. //static int pc_isAllowedCardOn(struct map_session_data *sd,int s,int eqindex,int flag)
  924. //{
  925. // int i;
  926. // struct item *item = &sd->inventory.u.items_inventory[eqindex];
  927. // struct item_data *data;
  928. //
  929. // //Crafted/made/hatched items.
  930. // if (itemdb_isspecial(item->card[0]))
  931. // return 1;
  932. //
  933. // /* scan for enchant armor gems */
  934. // if( item->card[MAX_SLOTS - 1] && s < MAX_SLOTS - 1 )
  935. // s = MAX_SLOTS - 1;
  936. //
  937. // ARR_FIND( 0, s, i, item->card[i] && (data = itemdb_exists(item->card[i])) != NULL && data->flag.no_equip&flag );
  938. // return( i < s ) ? 0 : 1;
  939. //}
  940. /**
  941. * Check if an item is equiped by player
  942. * (Check if the itemid is equiped then search if that match the index in inventory (should be))
  943. * @param sd : player session
  944. * @param nameid : itemid
  945. * @return 1:yes, 0:no
  946. */
  947. bool pc_isequipped(struct map_session_data *sd, unsigned short nameid)
  948. {
  949. uint8 i;
  950. for( i = 0; i < EQI_MAX; i++ )
  951. {
  952. short index = sd->equip_index[i], j;
  953. if( index < 0 )
  954. continue;
  955. if( pc_is_same_equip_index((enum equip_index)i, sd->equip_index, index) )
  956. continue;
  957. if( !sd->inventory_data[index] )
  958. continue;
  959. if( sd->inventory_data[index]->nameid == nameid )
  960. return true;
  961. for( j = 0; j < sd->inventory_data[index]->slot; j++ ){
  962. if( sd->inventory.u.items_inventory[index].card[j] == nameid )
  963. return true;
  964. }
  965. }
  966. return false;
  967. }
  968. /**
  969. * Check adoption rules
  970. * @param p1_sd: Player 1
  971. * @param p2_sd: Player 2
  972. * @param b_sd: Player that will be adopted
  973. * @return ADOPT_ALLOWED - Sent message to Baby to accept or deny
  974. * ADOPT_ALREADY_ADOPTED - Already adopted
  975. * ADOPT_MARRIED_AND_PARTY - Need to be married and in the same party
  976. * ADOPT_EQUIP_RINGS - Need wedding rings equipped
  977. * ADOPT_NOT_NOVICE - Adoptee is not a Novice
  978. * ADOPT_CHARACTER_NOT_FOUND - Parent or Baby not found
  979. * ADOPT_MORE_CHILDREN - Cannot adopt more than 1 Baby (client message)
  980. * ADOPT_LEVEL_70 - Parents need to be level 70+ (client message)
  981. * ADOPT_MARRIED - Cannot adopt a married person (client message)
  982. */
  983. enum adopt_responses pc_try_adopt(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
  984. {
  985. if( !p1_sd || !p2_sd || !b_sd )
  986. return ADOPT_CHARACTER_NOT_FOUND;
  987. if( b_sd->status.father || b_sd->status.mother || b_sd->adopt_invite )
  988. return ADOPT_ALREADY_ADOPTED; // already adopted baby / in adopt request
  989. if( !p1_sd->status.partner_id || !p1_sd->status.party_id || p1_sd->status.party_id != b_sd->status.party_id )
  990. return ADOPT_MARRIED_AND_PARTY; // You need to be married and in party with baby to adopt
  991. if( p1_sd->status.partner_id != p2_sd->status.char_id || p2_sd->status.partner_id != p1_sd->status.char_id )
  992. return ADOPT_MARRIED_AND_PARTY; // Not married, wrong married
  993. if( p2_sd->status.party_id != p1_sd->status.party_id )
  994. return ADOPT_MARRIED_AND_PARTY; // Both parents need to be in the same party
  995. // Parents need to have their ring equipped
  996. if( !pc_isequipped(p1_sd, WEDDING_RING_M) && !pc_isequipped(p1_sd, WEDDING_RING_F) )
  997. return ADOPT_EQUIP_RINGS;
  998. if( !pc_isequipped(p2_sd, WEDDING_RING_M) && !pc_isequipped(p2_sd, WEDDING_RING_F) )
  999. return ADOPT_EQUIP_RINGS;
  1000. // Already adopted a baby
  1001. if( p1_sd->status.child || p2_sd->status.child ) {
  1002. clif_Adopt_reply(p1_sd, ADOPT_REPLY_MORE_CHILDREN);
  1003. return ADOPT_MORE_CHILDREN;
  1004. }
  1005. // Parents need at least lvl 70 to adopt
  1006. if( p1_sd->status.base_level < 70 || p2_sd->status.base_level < 70 ) {
  1007. clif_Adopt_reply(p1_sd, ADOPT_REPLY_LEVEL_70);
  1008. return ADOPT_LEVEL_70;
  1009. }
  1010. if( b_sd->status.partner_id ) {
  1011. clif_Adopt_reply(p1_sd, ADOPT_REPLY_MARRIED);
  1012. return ADOPT_MARRIED;
  1013. }
  1014. 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 ) )
  1015. return ADOPT_NOT_NOVICE;
  1016. return ADOPT_ALLOWED;
  1017. }
  1018. /*==========================================
  1019. * Adoption Process
  1020. *------------------------------------------*/
  1021. bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
  1022. {
  1023. int job, joblevel;
  1024. unsigned int jobexp;
  1025. if( pc_try_adopt(p1_sd, p2_sd, b_sd) != ADOPT_ALLOWED )
  1026. return false;
  1027. // Preserve current job levels and progress
  1028. joblevel = b_sd->status.job_level;
  1029. jobexp = b_sd->status.job_exp;
  1030. job = pc_mapid2jobid(b_sd->class_|JOBL_BABY, b_sd->status.sex);
  1031. if( job != -1 && pc_jobchange(b_sd, job, 0) )
  1032. { // Success, proceed to configure parents and baby skills
  1033. p1_sd->status.child = b_sd->status.char_id;
  1034. p2_sd->status.child = b_sd->status.char_id;
  1035. b_sd->status.father = p1_sd->status.char_id;
  1036. b_sd->status.mother = p2_sd->status.char_id;
  1037. // Restore progress
  1038. b_sd->status.job_level = joblevel;
  1039. clif_updatestatus(b_sd, SP_JOBLEVEL);
  1040. b_sd->status.job_exp = jobexp;
  1041. clif_updatestatus(b_sd, SP_JOBEXP);
  1042. // Baby Skills
  1043. pc_skill(b_sd, WE_BABY, 1, ADDSKILL_PERMANENT);
  1044. pc_skill(b_sd, WE_CALLPARENT, 1, ADDSKILL_PERMANENT);
  1045. pc_skill(b_sd, WE_CHEERUP, 1, ADDSKILL_PERMANENT);
  1046. // Parents Skills
  1047. pc_skill(p1_sd, WE_CALLBABY, 1, ADDSKILL_PERMANENT);
  1048. pc_skill(p2_sd, WE_CALLBABY, 1, ADDSKILL_PERMANENT);
  1049. chrif_save(p1_sd, CSAVE_NORMAL);
  1050. chrif_save(p2_sd, CSAVE_NORMAL);
  1051. chrif_save(b_sd, CSAVE_NORMAL);
  1052. achievement_update_objective(b_sd, AG_BABY, 1, 1);
  1053. achievement_update_objective(p1_sd, AG_BABY, 1, 2);
  1054. achievement_update_objective(p2_sd, AG_BABY, 1, 2);
  1055. return true;
  1056. }
  1057. return false; // Job Change Fail
  1058. }
  1059. /*==========================================
  1060. * Check if player can use/equip selected item. Used by pc_isUseitem and pc_isequip
  1061. Returns:
  1062. false : Cannot use/equip
  1063. true : Can use/equip
  1064. * Credits:
  1065. [Inkfish] for first idea
  1066. [Haru] for third-classes extension
  1067. [Cydh] finishing :D
  1068. *------------------------------------------*/
  1069. static bool pc_isItemClass (struct map_session_data *sd, struct item_data* item) {
  1070. while (1) {
  1071. if (item->class_upper&ITEMJ_NORMAL && !(sd->class_&(JOBL_UPPER|JOBL_THIRD|JOBL_BABY))) //normal classes (no upper, no baby, no third)
  1072. break;
  1073. #ifndef RENEWAL
  1074. //allow third classes to use trans. class items
  1075. if (item->class_upper&ITEMJ_UPPER && sd->class_&(JOBL_UPPER|JOBL_THIRD)) //trans. classes
  1076. break;
  1077. //third-baby classes can use same item too
  1078. if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY) //baby classes
  1079. break;
  1080. //don't need to decide specific rules for third-classes?
  1081. //items for third classes can be used for all third classes
  1082. if (item->class_upper&(ITEMJ_THIRD|ITEMJ_THIRD_TRANS|ITEMJ_THIRD_BABY) && sd->class_&JOBL_THIRD)
  1083. break;
  1084. #else
  1085. //trans. classes (exl. third-trans.)
  1086. if (item->class_upper&ITEMJ_UPPER && sd->class_&JOBL_UPPER && !(sd->class_&JOBL_THIRD))
  1087. break;
  1088. //baby classes (exl. third-baby)
  1089. if (item->class_upper&ITEMJ_BABY && sd->class_&JOBL_BABY && !(sd->class_&JOBL_THIRD))
  1090. break;
  1091. //third classes (exl. third-trans. and baby-third)
  1092. if (item->class_upper&ITEMJ_THIRD && sd->class_&JOBL_THIRD && !(sd->class_&(JOBL_UPPER|JOBL_BABY)))
  1093. break;
  1094. //trans-third classes
  1095. if (item->class_upper&ITEMJ_THIRD_TRANS && sd->class_&JOBL_THIRD && sd->class_&JOBL_UPPER)
  1096. break;
  1097. //third-baby classes
  1098. if (item->class_upper&ITEMJ_THIRD_BABY && sd->class_&JOBL_THIRD && sd->class_&JOBL_BABY)
  1099. break;
  1100. #endif
  1101. return false;
  1102. }
  1103. return true;
  1104. }
  1105. /*=================================================
  1106. * Checks if the player can equip the item at index n in inventory.
  1107. * @param sd
  1108. * @param n Item index in inventory
  1109. * @return ITEM_EQUIP_ACK_OK(0) if can be equipped, or ITEM_EQUIP_ACK_FAIL(1)/ITEM_EQUIP_ACK_FAILLEVEL(2) if can't
  1110. *------------------------------------------------*/
  1111. uint8 pc_isequip(struct map_session_data *sd,int n)
  1112. {
  1113. struct item_data *item;
  1114. nullpo_retr(ITEM_EQUIP_ACK_FAIL, sd);
  1115. item = sd->inventory_data[n];
  1116. if(pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT))
  1117. return ITEM_EQUIP_ACK_OK;
  1118. if(item == NULL)
  1119. return ITEM_EQUIP_ACK_FAIL;
  1120. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  1121. return ITEM_EQUIP_ACK_FAILLEVEL;
  1122. if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
  1123. return ITEM_EQUIP_ACK_FAILLEVEL;
  1124. if(item->sex != 2 && sd->status.sex != item->sex)
  1125. return ITEM_EQUIP_ACK_FAIL;
  1126. //fail to equip if item is restricted
  1127. if (!battle_config.allow_equip_restricted_item && itemdb_isNoEquip(item, sd->bl.m))
  1128. return ITEM_EQUIP_ACK_FAIL;
  1129. if (item->equip&EQP_AMMO) {
  1130. switch (item->look) {
  1131. case AMMO_ARROW:
  1132. if (battle_config.ammo_check_weapon && sd->status.weapon != W_BOW && sd->status.weapon != W_MUSICAL && sd->status.weapon != W_WHIP) {
  1133. clif_msg(sd, ITEM_NEED_BOW);
  1134. return ITEM_EQUIP_ACK_FAIL;
  1135. }
  1136. break;
  1137. case AMMO_THROWABLE_DAGGER:
  1138. if (!pc_checkskill(sd, AS_VENOMKNIFE))
  1139. return ITEM_EQUIP_ACK_FAIL;
  1140. break;
  1141. case AMMO_BULLET:
  1142. case AMMO_SHELL:
  1143. if (battle_config.ammo_check_weapon && sd->status.weapon != W_REVOLVER && sd->status.weapon != W_RIFLE && sd->status.weapon != W_GATLING && sd->status.weapon != W_SHOTGUN
  1144. #ifdef RENEWAL
  1145. && sd->status.weapon != W_GRENADE
  1146. #endif
  1147. ) {
  1148. clif_msg(sd, ITEM_BULLET_EQUIP_FAIL);
  1149. return ITEM_EQUIP_ACK_FAIL;
  1150. }
  1151. break;
  1152. #ifndef RENEWAL
  1153. case AMMO_GRENADE:
  1154. if (battle_config.ammo_check_weapon && sd->status.weapon != W_GRENADE) {
  1155. clif_msg(sd, ITEM_BULLET_EQUIP_FAIL);
  1156. return ITEM_EQUIP_ACK_FAIL;
  1157. }
  1158. break;
  1159. #endif
  1160. case AMMO_CANNONBALL:
  1161. if (!pc_ismadogear(sd) && (sd->status.class_ == JOB_MECHANIC_T || sd->status.class_ == JOB_MECHANIC)) {
  1162. clif_msg(sd, ITEM_NEED_MADOGEAR); // Item can only be used when Mado Gear is mounted.
  1163. return ITEM_EQUIP_ACK_FAIL;
  1164. }
  1165. if (sd->state.active && !pc_iscarton(sd) && //Check if sc data is already loaded
  1166. (sd->status.class_ == JOB_GENETIC_T || sd->status.class_ == JOB_GENETIC)) {
  1167. clif_msg(sd, ITEM_NEED_CART); // Only available when cart is mounted.
  1168. return ITEM_EQUIP_ACK_FAIL;
  1169. }
  1170. break;
  1171. }
  1172. }
  1173. if (sd->sc.count) {
  1174. if(item->equip & EQP_ARMS && item->type == IT_WEAPON && sd->sc.data[SC_STRIPWEAPON]) // Also works with left-hand weapons [DracoRPG]
  1175. return ITEM_EQUIP_ACK_FAIL;
  1176. if(item->equip & EQP_SHIELD && item->type == IT_ARMOR && sd->sc.data[SC_STRIPSHIELD])
  1177. return ITEM_EQUIP_ACK_FAIL;
  1178. if(item->equip & EQP_ARMOR && sd->sc.data[SC_STRIPARMOR])
  1179. return ITEM_EQUIP_ACK_FAIL;
  1180. if(item->equip & EQP_HEAD_TOP && sd->sc.data[SC_STRIPHELM])
  1181. return ITEM_EQUIP_ACK_FAIL;
  1182. if(item->equip & EQP_ACC && sd->sc.data[SC__STRIPACCESSORY])
  1183. return ITEM_EQUIP_ACK_FAIL;
  1184. if (item->equip & EQP_ARMS && sd->sc.data[SC__WEAKNESS])
  1185. return ITEM_EQUIP_ACK_FAIL;
  1186. if(item->equip && (sd->sc.data[SC_KYOUGAKU] || sd->sc.data[SC_SUHIDE]))
  1187. return ITEM_EQUIP_ACK_FAIL;
  1188. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_SUPERNOVICE) {
  1189. //Spirit of Super Novice equip bonuses. [Skotlex]
  1190. if (sd->status.base_level > 90 && item->equip & EQP_HELM)
  1191. return ITEM_EQUIP_ACK_OK; //Can equip all helms
  1192. if (sd->status.base_level > 96 && item->equip & EQP_ARMS && item->type == IT_WEAPON && item->wlv == 4)
  1193. switch(item->look) { //In weapons, the look determines type of weapon.
  1194. case W_DAGGER: //All level 4 - Daggers
  1195. case W_1HSWORD: //All level 4 - 1H Swords
  1196. case W_1HAXE: //All level 4 - 1H Axes
  1197. case W_MACE: //All level 4 - 1H Maces
  1198. case W_STAFF: //All level 4 - 1H Staves
  1199. case W_2HSTAFF: //All level 4 - 2H Staves
  1200. return ITEM_EQUIP_ACK_OK;
  1201. }
  1202. }
  1203. }
  1204. //Not equipable by class. [Skotlex]
  1205. if (!(1ULL << (sd->class_&MAPID_BASEMASK)&item->class_base[(sd->class_&JOBL_2_1) ? 1 : ((sd->class_&JOBL_2_2) ? 2 : 0)]))
  1206. return ITEM_EQUIP_ACK_FAIL;
  1207. if (!pc_isItemClass(sd, item))
  1208. return ITEM_EQUIP_ACK_FAIL;
  1209. return ITEM_EQUIP_ACK_OK;
  1210. }
  1211. /*==========================================
  1212. * No problem with the session id
  1213. * set the status that has been sent from char server
  1214. *------------------------------------------*/
  1215. 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)
  1216. {
  1217. int i;
  1218. t_tick tick = gettick();
  1219. uint32 ip = session[sd->fd]->client_addr;
  1220. sd->login_id2 = login_id2;
  1221. sd->group_id = group_id;
  1222. /* load user permissions */
  1223. pc_group_pc_load(sd);
  1224. memcpy(&sd->status, st, sizeof(*st));
  1225. if (st->sex != sd->status.sex) {
  1226. clif_authfail_fd(sd->fd, 0);
  1227. return false;
  1228. }
  1229. //Set the map-server used job id. [Skotlex]
  1230. i = pc_jobid2mapid(sd->status.class_);
  1231. if (i == -1) { //Invalid class?
  1232. 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);
  1233. sd->status.class_ = JOB_NOVICE;
  1234. sd->class_ = MAPID_NOVICE;
  1235. } else
  1236. sd->class_ = i;
  1237. // Checks and fixes to character status data, that are required
  1238. // in case of configuration change or stuff, which cannot be
  1239. // checked on char-server.
  1240. sd->status.hair = cap_value(sd->status.hair,MIN_HAIR_STYLE,MAX_HAIR_STYLE);
  1241. sd->status.hair_color = cap_value(sd->status.hair_color,MIN_HAIR_COLOR,MAX_HAIR_COLOR);
  1242. sd->status.clothes_color = cap_value(sd->status.clothes_color,MIN_CLOTH_COLOR,MAX_CLOTH_COLOR);
  1243. sd->status.body = cap_value(sd->status.body,MIN_BODY_STYLE,MAX_BODY_STYLE);
  1244. //Initializations to null/0 unneeded since map_session_data was filled with 0 upon allocation.
  1245. sd->state.connect_new = 1;
  1246. sd->followtimer = INVALID_TIMER; // [MouseJstr]
  1247. sd->invincible_timer = INVALID_TIMER;
  1248. sd->npc_timer_id = INVALID_TIMER;
  1249. sd->pvp_timer = INVALID_TIMER;
  1250. sd->expiration_tid = INVALID_TIMER;
  1251. sd->autotrade_tid = INVALID_TIMER;
  1252. sd->respawn_tid = INVALID_TIMER;
  1253. #ifdef SECURE_NPCTIMEOUT
  1254. // Initialize to defaults/expected
  1255. sd->npc_idle_timer = INVALID_TIMER;
  1256. sd->npc_idle_tick = tick;
  1257. sd->npc_idle_type = NPCT_INPUT;
  1258. sd->state.ignoretimeout = false;
  1259. #endif
  1260. sd->canuseitem_tick = tick;
  1261. sd->canusecashfood_tick = tick;
  1262. sd->canequip_tick = tick;
  1263. sd->cantalk_tick = tick;
  1264. sd->canskill_tick = tick;
  1265. sd->cansendmail_tick = tick;
  1266. sd->idletime = last_tick;
  1267. for(i = 0; i < MAX_SPIRITBALL; i++)
  1268. sd->spirit_timer[i] = INVALID_TIMER;
  1269. for (i = 0; i < MAX_SOUL_BALL; i++)
  1270. sd->soul_timer[i] = INVALID_TIMER;
  1271. if (battle_config.item_auto_get)
  1272. sd->state.autoloot = 10000;
  1273. if (battle_config.disp_experience)
  1274. sd->state.showexp = 1;
  1275. if (battle_config.disp_zeny)
  1276. sd->state.showzeny = 1;
  1277. #ifdef VIP_ENABLE
  1278. if (!battle_config.vip_disp_rate)
  1279. sd->vip.disableshowrate = 1;
  1280. #endif
  1281. if (!(battle_config.display_skill_fail&2))
  1282. sd->state.showdelay = 1;
  1283. memset(&sd->inventory, 0, sizeof(struct s_storage));
  1284. memset(&sd->cart, 0, sizeof(struct s_storage));
  1285. memset(&sd->storage, 0, sizeof(struct s_storage));
  1286. memset(&sd->premiumStorage, 0, sizeof(struct s_storage));
  1287. memset(&sd->equip_index, -1, sizeof(sd->equip_index));
  1288. memset(&sd->equip_switch_index, -1, sizeof(sd->equip_switch_index));
  1289. if( pc_isinvisible(sd) && !pc_can_use_command( sd, "hide", COMMAND_ATCOMMAND ) ){
  1290. sd->status.option &= ~OPTION_INVISIBLE;
  1291. }
  1292. status_change_init(&sd->bl);
  1293. sd->sc.option = sd->status.option; //This is the actual option used in battle.
  1294. unit_dataset(&sd->bl);
  1295. sd->guild_x = -1;
  1296. sd->guild_y = -1;
  1297. sd->delayed_damage = 0;
  1298. // Event Timers
  1299. for( i = 0; i < MAX_EVENTTIMER; i++ )
  1300. sd->eventtimer[i] = INVALID_TIMER;
  1301. // Rental Timer
  1302. sd->rental_timer = INVALID_TIMER;
  1303. for( i = 0; i < 3; i++ )
  1304. sd->hate_mob[i] = -1;
  1305. sd->quest_log = NULL;
  1306. sd->num_quests = 0;
  1307. sd->avail_quests = 0;
  1308. sd->save_quest = false;
  1309. sd->count_rewarp = 0;
  1310. sd->regs.vars = i64db_alloc(DB_OPT_BASE);
  1311. sd->regs.arrays = NULL;
  1312. sd->vars_dirty = false;
  1313. sd->vars_ok = false;
  1314. sd->vars_received = 0x0;
  1315. sd->qi_display = nullptr;
  1316. sd->qi_count = 0;
  1317. //warp player
  1318. if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != SETPOS_OK) {
  1319. 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);
  1320. // try warping to a default map instead (church graveyard)
  1321. if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != SETPOS_OK) {
  1322. // if we fail again
  1323. clif_authfail_fd(sd->fd, 0);
  1324. return false;
  1325. }
  1326. }
  1327. clif_authok(sd);
  1328. //Prevent S. Novices from getting the no-death bonus just yet. [Skotlex]
  1329. sd->die_counter=-1;
  1330. //display login notice
  1331. ShowInfo("'" CL_WHITE "%s" CL_RESET "' logged in."
  1332. " (AID/CID: '" CL_WHITE "%d/%d" CL_RESET "',"
  1333. " IP: '" CL_WHITE "%d.%d.%d.%d" CL_RESET "',"
  1334. " Group '" CL_WHITE "%d" CL_RESET "').\n",
  1335. sd->status.name, sd->status.account_id, sd->status.char_id,
  1336. CONVIP(ip), sd->group_id);
  1337. // Send friends list
  1338. clif_friendslist_send(sd);
  1339. if( !changing_mapservers ) {
  1340. if (battle_config.display_version == 1)
  1341. pc_show_version(sd);
  1342. // Message of the Day [Valaris]
  1343. for(i=0; i < MOTD_LINE_SIZE && motd_text[i][0]; i++) {
  1344. if (battle_config.motd_type)
  1345. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], motd_text[i], false, SELF);
  1346. else
  1347. clif_displaymessage(sd->fd, motd_text[i]);
  1348. }
  1349. if (expiration_time != 0)
  1350. sd->expiration_time = expiration_time;
  1351. /**
  1352. * Fixes login-without-aura glitch (the screen won't blink at this point, don't worry :P)
  1353. **/
  1354. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  1355. }
  1356. pc_validate_skill(sd);
  1357. /* [Ind] */
  1358. sd->sc_display = NULL;
  1359. sd->sc_display_count = 0;
  1360. // Player has not yet received the CashShop list
  1361. sd->status.cashshop_sent = false;
  1362. sd->last_addeditem_index = -1;
  1363. sd->bonus_script.head = NULL;
  1364. sd->bonus_script.count = 0;
  1365. // Initialize BG queue pointer
  1366. sd->bg_queue = nullptr;
  1367. sd->bg_queue_accept_state = false;
  1368. #if PACKETVER >= 20150513
  1369. sd->hatEffectIDs = NULL;
  1370. sd->hatEffectCount = 0;
  1371. #endif
  1372. sd->catch_target_class = PET_CATCH_FAIL;
  1373. // Check EXP overflow, since in previous revision EXP on Max Level can be more than 'official' Max EXP
  1374. if (pc_is_maxbaselv(sd) && sd->status.base_exp > MAX_LEVEL_BASE_EXP) {
  1375. sd->status.base_exp = MAX_LEVEL_BASE_EXP;
  1376. clif_updatestatus(sd, SP_BASEEXP);
  1377. }
  1378. if (pc_is_maxjoblv(sd) && sd->status.job_exp > MAX_LEVEL_JOB_EXP) {
  1379. sd->status.job_exp = MAX_LEVEL_JOB_EXP;
  1380. clif_updatestatus(sd, SP_JOBEXP);
  1381. }
  1382. // Request all registries (auth is considered completed whence they arrive)
  1383. intif_request_registry(sd,7);
  1384. return true;
  1385. }
  1386. /*==========================================
  1387. * Closes a connection because it failed to be authenticated from the char server.
  1388. *------------------------------------------*/
  1389. void pc_authfail(struct map_session_data *sd)
  1390. {
  1391. clif_authfail_fd(sd->fd, 0);
  1392. return;
  1393. }
  1394. /**
  1395. * Player register a bl as hatred
  1396. * @param sd : player session
  1397. * @param pos : hate position [0;2]
  1398. * @param bl : target bl
  1399. * @return false:failed, true:success
  1400. */
  1401. bool pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl)
  1402. {
  1403. int class_;
  1404. if (!sd || !bl || pos < 0 || pos > 2)
  1405. return false;
  1406. if (sd->hate_mob[pos] != -1)
  1407. { //Can't change hate targets.
  1408. clif_hate_info(sd, pos, sd->hate_mob[pos], 0); //Display current
  1409. return false;
  1410. }
  1411. class_ = status_get_class(bl);
  1412. if (!pcdb_checkid(class_)) {
  1413. unsigned int max_hp = status_get_max_hp(bl);
  1414. if ((pos == 1 && max_hp < 6000) || (pos == 2 && max_hp < 20000))
  1415. return false;
  1416. if (pos != status_get_size(bl))
  1417. return false; //Wrong size
  1418. }
  1419. sd->hate_mob[pos] = class_;
  1420. pc_setglobalreg(sd, add_str(sg_info[pos].hate_var), class_+1);
  1421. clif_hate_info(sd, pos, class_, 1);
  1422. return true;
  1423. }
  1424. /*==========================================
  1425. * Invoked once after the char/account/account2 registry variables are received. [Skotlex]
  1426. * We didn't receive item information at this point so DO NOT attempt to do item operations here.
  1427. * See intif_parse_StorageReceived() for item operations [lighta]
  1428. *------------------------------------------*/
  1429. void pc_reg_received(struct map_session_data *sd)
  1430. {
  1431. uint8 i;
  1432. sd->vars_ok = true;
  1433. sd->change_level_2nd = static_cast<unsigned char>(pc_readglobalreg(sd, add_str(JOBCHANGE2ND_VAR)));
  1434. sd->change_level_3rd = static_cast<unsigned char>(pc_readglobalreg(sd, add_str(JOBCHANGE3RD_VAR)));
  1435. sd->die_counter = static_cast<int>(pc_readglobalreg(sd, add_str(PCDIECOUNTER_VAR)));
  1436. sd->langtype = static_cast<int>(pc_readaccountreg(sd, add_str(LANGTYPE_VAR)));
  1437. if (msg_checklangtype(sd->langtype,true) < 0)
  1438. sd->langtype = 0; //invalid langtype reset to default
  1439. // Cash shop
  1440. sd->cashPoints = static_cast<int>(pc_readaccountreg(sd, add_str(CASHPOINT_VAR)));
  1441. sd->kafraPoints = static_cast<int>(pc_readaccountreg(sd, add_str(KAFRAPOINT_VAR)));
  1442. // Cooking Exp
  1443. sd->cook_mastery = static_cast<short>(pc_readglobalreg(sd, add_str(COOKMASTERY_VAR)));
  1444. if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON )
  1445. { // Better check for class rather than skill to prevent "skill resets" from unsetting this
  1446. sd->mission_mobid = static_cast<short>(pc_readglobalreg(sd, add_str(TKMISSIONID_VAR)));
  1447. sd->mission_count = static_cast<unsigned char>(pc_readglobalreg(sd, add_str(TKMISSIONCOUNT_VAR)));
  1448. }
  1449. if (battle_config.feature_banking)
  1450. sd->bank_vault = static_cast<int>(pc_readreg2(sd, BANK_VAULT_VAR));
  1451. if (battle_config.feature_roulette) {
  1452. sd->roulette_point.bronze = static_cast<int>(pc_readreg2(sd, ROULETTE_BRONZE_VAR));
  1453. sd->roulette_point.silver = static_cast<int>(pc_readreg2(sd, ROULETTE_SILVER_VAR));
  1454. sd->roulette_point.gold = static_cast<int>(pc_readreg2(sd, ROULETTE_GOLD_VAR));
  1455. }
  1456. sd->roulette.prizeIdx = -1;
  1457. //SG map and mob read [Komurka]
  1458. for(i=0;i<MAX_PC_FEELHATE;i++) { //for now - someone need to make reading from txt/sql
  1459. uint16 j;
  1460. if ((j = static_cast<uint16>(pc_readglobalreg(sd, add_str(sg_info[i].feel_var)))) != 0) {
  1461. sd->feel_map[i].index = j;
  1462. sd->feel_map[i].m = map_mapindex2mapid(j);
  1463. } else {
  1464. sd->feel_map[i].index = 0;
  1465. sd->feel_map[i].m = -1;
  1466. }
  1467. sd->hate_mob[i] = static_cast<short>(pc_readglobalreg(sd, add_str(sg_info[i].hate_var)))-1;
  1468. }
  1469. if ((i = pc_checkskill(sd,RG_PLAGIARISM)) > 0) {
  1470. unsigned short skid = static_cast<unsigned short>(pc_readglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM)));
  1471. sd->cloneskill_idx = skill_get_index(skid);
  1472. if (sd->cloneskill_idx > 0) {
  1473. sd->status.skill[sd->cloneskill_idx].id = skid;
  1474. sd->status.skill[sd->cloneskill_idx].lv = static_cast<uint8>(pc_readglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM_LV)));
  1475. if (sd->status.skill[sd->cloneskill_idx].lv > i)
  1476. sd->status.skill[sd->cloneskill_idx].lv = i;
  1477. sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
  1478. }
  1479. }
  1480. if ((i = pc_checkskill(sd,SC_REPRODUCE)) > 0) {
  1481. unsigned short skid = static_cast<unsigned short>(pc_readglobalreg(sd, add_str(SKILL_VAR_REPRODUCE)));
  1482. sd->reproduceskill_idx = skill_get_index(skid);
  1483. if (sd->reproduceskill_idx > 0) {
  1484. sd->status.skill[sd->reproduceskill_idx].id = skid;
  1485. sd->status.skill[sd->reproduceskill_idx].lv = static_cast<uint8>(pc_readglobalreg(sd, add_str(SKILL_VAR_REPRODUCE_LV)));
  1486. if (i < sd->status.skill[sd->reproduceskill_idx].lv)
  1487. sd->status.skill[sd->reproduceskill_idx].lv = i;
  1488. sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PLAGIARIZED;
  1489. }
  1490. }
  1491. //Weird... maybe registries were reloaded?
  1492. if (sd->state.active)
  1493. return;
  1494. sd->state.active = 1;
  1495. sd->state.pc_loaded = false; // Ensure inventory data and status data is loaded before we calculate player stats
  1496. intif_storage_request(sd,TABLE_STORAGE, 0, STOR_MODE_ALL); // Request storage data
  1497. intif_storage_request(sd,TABLE_CART, 0, STOR_MODE_ALL); // Request cart data
  1498. intif_storage_request(sd,TABLE_INVENTORY, 0, STOR_MODE_ALL); // Request inventory data
  1499. if (sd->status.party_id)
  1500. party_member_joined(sd);
  1501. if (sd->status.guild_id)
  1502. guild_member_joined(sd);
  1503. if( sd->status.clan_id )
  1504. clan_member_joined(sd);
  1505. // pet
  1506. if (sd->status.pet_id > 0)
  1507. intif_request_petdata(sd->status.account_id, sd->status.char_id, sd->status.pet_id);
  1508. // Homunculus [albator]
  1509. if( sd->status.hom_id > 0 )
  1510. intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id);
  1511. if( sd->status.mer_id > 0 )
  1512. intif_mercenary_request(sd->status.mer_id, sd->status.char_id);
  1513. if( sd->status.ele_id > 0 )
  1514. intif_elemental_request(sd->status.ele_id, sd->status.char_id);
  1515. map_addiddb(&sd->bl);
  1516. map_delnickdb(sd->status.char_id, sd->status.name);
  1517. if (!chrif_auth_finished(sd))
  1518. ShowError("pc_reg_received: Failed to properly remove player %d:%d from logging db!\n", sd->status.account_id, sd->status.char_id);
  1519. chrif_skillcooldown_request(sd->status.account_id, sd->status.char_id);
  1520. chrif_bsdata_request(sd->status.char_id);
  1521. #ifdef VIP_ENABLE
  1522. sd->vip.time = 0;
  1523. sd->vip.enabled = 0;
  1524. chrif_req_login_operation(sd->status.account_id, sd->status.name, CHRIF_OP_LOGIN_VIP, 0, 1|8, 0); // request VIP information
  1525. #endif
  1526. intif_Mail_requestinbox(sd->status.char_id, 0, MAIL_INBOX_NORMAL); // MAIL SYSTEM - Request Mail Inbox
  1527. intif_request_questlog(sd);
  1528. if (battle_config.feature_achievement) {
  1529. sd->achievement_data.total_score = 0;
  1530. sd->achievement_data.level = 0;
  1531. sd->achievement_data.save = false;
  1532. sd->achievement_data.count = 0;
  1533. sd->achievement_data.incompleteCount = 0;
  1534. sd->achievement_data.achievements = NULL;
  1535. intif_request_achievements(sd->status.char_id);
  1536. }
  1537. if (sd->state.connect_new == 0 && sd->fd) { //Character already loaded map! Gotta trigger LoadEndAck manually.
  1538. sd->state.connect_new = 1;
  1539. clif_parse_LoadEndAck(sd->fd, sd);
  1540. if( pc_isinvisible( sd ) ){
  1541. sd->vd.class_ = JT_INVISIBLE;
  1542. clif_displaymessage( sd->fd, msg_txt( sd, 11 ) ); // Invisible: On
  1543. // decrement the number of pvp players on the map
  1544. map_getmapdata( sd->bl.m )->users_pvp--;
  1545. if( map_getmapflag( sd->bl.m, MF_PVP ) && !map_getmapflag( sd->bl.m, MF_PVP_NOCALCRANK ) && sd->pvp_timer != INVALID_TIMER ){
  1546. // unregister the player for ranking
  1547. delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  1548. sd->pvp_timer = INVALID_TIMER;
  1549. }
  1550. clif_changeoption( &sd->bl );
  1551. }
  1552. }
  1553. channel_autojoin(sd);
  1554. }
  1555. static int pc_calc_skillpoint(struct map_session_data* sd)
  1556. {
  1557. uint16 i, skill_point = 0;
  1558. nullpo_ret(sd);
  1559. for(i = 1; i < MAX_SKILL; i++) {
  1560. if( sd->status.skill[i].id && sd->status.skill[i].lv > 0) {
  1561. std::shared_ptr<s_skill_db> skill = skill_db.find(sd->status.skill[i].id);
  1562. if ((!skill->inf2[INF2_ISQUEST] || battle_config.quest_skill_learn) &&
  1563. (!skill->inf2[INF2_ISWEDDING] || skill->inf2[INF2_ISSPIRIT]) //Do not count wedding/link skills. [Skotlex]
  1564. )
  1565. {
  1566. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  1567. skill_point += sd->status.skill[i].lv;
  1568. else if(sd->status.skill[i].flag >= SKILL_FLAG_REPLACED_LV_0)
  1569. skill_point += (sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0);
  1570. }
  1571. }
  1572. }
  1573. return skill_point;
  1574. }
  1575. static bool pc_grant_allskills(struct map_session_data *sd, bool addlv) {
  1576. if (!sd || !pc_has_permission(sd, PC_PERM_ALL_SKILL))
  1577. return false;
  1578. /**
  1579. * Dummy skills must NOT be added here otherwise they'll be displayed in the,
  1580. * skill tree and since they have no icons they'll give resource errors
  1581. * Get ALL skills except npc/guild ones. [Skotlex]
  1582. * Don't add SG_DEVIL [Komurka] and MO_TRIPLEATTACK and RG_SNATCHER [ultramage]
  1583. **/
  1584. for (const auto &skill : skill_db) {
  1585. uint16 skill_id = skill.second->nameid;
  1586. if (skill_id == 0 || skill.second->inf2[INF2_ISNPC]|| skill.second->inf2[INF2_ISGUILD])
  1587. continue;
  1588. switch (skill_id) {
  1589. case SM_SELFPROVOKE:
  1590. case AB_DUPLELIGHT_MELEE:
  1591. case AB_DUPLELIGHT_MAGIC:
  1592. case WL_CHAINLIGHTNING_ATK:
  1593. case WL_TETRAVORTEX_FIRE:
  1594. case WL_TETRAVORTEX_WATER:
  1595. case WL_TETRAVORTEX_WIND:
  1596. case WL_TETRAVORTEX_GROUND:
  1597. case WL_SUMMON_ATK_FIRE:
  1598. case WL_SUMMON_ATK_WIND:
  1599. case WL_SUMMON_ATK_WATER:
  1600. case WL_SUMMON_ATK_GROUND:
  1601. case LG_OVERBRAND_BRANDISH:
  1602. case LG_OVERBRAND_PLUSATK:
  1603. case WM_SEVERE_RAINSTORM_MELEE:
  1604. case RL_R_TRIP_PLUSATK:
  1605. case SG_DEVIL:
  1606. case MO_TRIPLEATTACK:
  1607. case RG_SNATCHER:
  1608. continue;
  1609. default:
  1610. {
  1611. uint8 lv = (uint8)skill_get_max(skill_id);
  1612. if (lv > 0) {
  1613. uint16 idx = skill_get_index(skill_id);
  1614. sd->status.skill[idx].id = skill_id;
  1615. if (addlv)
  1616. sd->status.skill[idx].lv = lv;
  1617. }
  1618. }
  1619. break;
  1620. }
  1621. }
  1622. return true;
  1623. }
  1624. /*==========================================
  1625. * Calculation of skill level.
  1626. * @param sd
  1627. *------------------------------------------*/
  1628. void pc_calc_skilltree(struct map_session_data *sd)
  1629. {
  1630. nullpo_retv(sd);
  1631. int job = pc_calc_skilltree_normalize_job(sd);
  1632. int class_ = pc_mapid2jobid(job, sd->status.sex);
  1633. if( class_ == -1 )
  1634. { //Unable to normalize job??
  1635. ShowError("pc_calc_skilltree: Unable to normalize job %d for character %s (%d:%d)\n", job, sd->status.name, sd->status.account_id, sd->status.char_id);
  1636. return;
  1637. }
  1638. class_ = pc_class2idx(class_);
  1639. for (const auto &skill : skill_db) {
  1640. uint16 skill_id = skill.second->nameid;
  1641. uint16 idx = skill_get_index(skill_id);
  1642. if( sd->status.skill[idx].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[idx].flag != SKILL_FLAG_PERM_GRANTED ) //Don't touch these
  1643. sd->status.skill[idx].id = 0; //First clear skills.
  1644. /* permanent skills that must be re-checked */
  1645. if( sd->status.skill[idx].flag == SKILL_FLAG_PERM_GRANTED ) {
  1646. if (skill_id == 0) {
  1647. sd->status.skill[idx].id = 0;
  1648. sd->status.skill[idx].lv = 0;
  1649. sd->status.skill[idx].flag = SKILL_FLAG_PERMANENT;
  1650. continue;
  1651. }
  1652. switch (skill_id) {
  1653. case NV_TRICKDEAD:
  1654. if( (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ) {
  1655. sd->status.skill[idx].id = 0;
  1656. sd->status.skill[idx].lv = 0;
  1657. sd->status.skill[idx].flag = SKILL_FLAG_PERMANENT;
  1658. }
  1659. break;
  1660. }
  1661. }
  1662. }
  1663. for (const auto &skill : skill_db) {
  1664. uint16 skill_id = skill.second->nameid;
  1665. uint16 idx = skill_get_index(skill_id);
  1666. // Restore original level of skills after deleting earned skills.
  1667. if( sd->status.skill[idx].flag != SKILL_FLAG_PERMANENT && sd->status.skill[idx].flag != SKILL_FLAG_PERM_GRANTED && sd->status.skill[idx].flag != SKILL_FLAG_PLAGIARIZED ) {
  1668. sd->status.skill[idx].lv = (sd->status.skill[idx].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[idx].flag - SKILL_FLAG_REPLACED_LV_0;
  1669. sd->status.skill[idx].flag = SKILL_FLAG_PERMANENT;
  1670. }
  1671. //Enable Bard/Dancer spirit linked skills.
  1672. if (skill_id < DC_HUMMING || skill_id > DC_SERVICEFORYOU)
  1673. continue;
  1674. if( sd->sc.count && sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_BARDDANCER ) {
  1675. //Link Dancer skills to bard.
  1676. if( sd->status.sex ) {
  1677. if( sd->status.skill[idx - 8].lv < 10 )
  1678. continue;
  1679. sd->status.skill[idx].id = skill_id;
  1680. sd->status.skill[idx].lv = sd->status.skill[idx - 8].lv; // Set the level to the same as the linking skill
  1681. sd->status.skill[idx].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
  1682. }
  1683. //Link Bard skills to dancer.
  1684. else {
  1685. if( sd->status.skill[idx].lv < 10 )
  1686. continue;
  1687. sd->status.skill[idx - 8].id = skill_id - 8;
  1688. sd->status.skill[idx - 8].lv = sd->status.skill[idx].lv; // Set the level to the same as the linking skill
  1689. sd->status.skill[idx - 8].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
  1690. }
  1691. }
  1692. }
  1693. // Removes Taekwon Ranker skill bonus
  1694. if ((sd->class_&MAPID_UPPERMASK) != MAPID_TAEKWON) {
  1695. uint16 c_ = pc_class2idx(JOB_TAEKWON);
  1696. for (uint16 i = 0; i < MAX_SKILL_TREE; i++) {
  1697. uint16 sk_id = skill_tree[c_][i].skill_id;
  1698. uint16 sk_idx = 0;
  1699. if (!sk_id || !(sk_idx = skill_get_index(skill_tree[c_][i].skill_id)))
  1700. continue;
  1701. if (sd->status.skill[sk_idx].flag != SKILL_FLAG_PLAGIARIZED && sd->status.skill[sk_idx].flag != SKILL_FLAG_PERM_GRANTED) {
  1702. if (sk_id == NV_BASIC || sk_id == NV_FIRSTAID || sk_id == WE_CALLBABY)
  1703. continue;
  1704. sd->status.skill[sk_idx].id = 0;
  1705. }
  1706. }
  1707. }
  1708. // Grant all skills
  1709. pc_grant_allskills(sd, false);
  1710. int flag;
  1711. do {
  1712. uint16 skid = 0;
  1713. flag = 0;
  1714. for (uint16 i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[class_][i].skill_id) > 0; i++) {
  1715. bool fail = false;
  1716. uint16 sk_idx = skill_get_index(skid);
  1717. if (sd->status.skill[sk_idx].id)
  1718. continue; //Skill already known.
  1719. if (!battle_config.skillfree) {
  1720. // Checking required skills
  1721. for(uint8 j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
  1722. uint16 sk_need_id = skill_tree[class_][i].need[j].skill_id;
  1723. uint16 sk_need_idx = 0;
  1724. if (sk_need_id && (sk_need_idx = skill_get_index(sk_need_id))) {
  1725. short sk_need = sk_need_id;
  1726. 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)
  1727. sk_need = 0; //Not learned.
  1728. else if (sd->status.skill[sk_need_idx].flag >= SKILL_FLAG_REPLACED_LV_0) //Real learned level
  1729. sk_need = sd->status.skill[sk_need_idx].flag - SKILL_FLAG_REPLACED_LV_0;
  1730. else
  1731. sk_need = pc_checkskill(sd,sk_need_id);
  1732. if (sk_need < skill_tree[class_][i].need[j].skill_lv) {
  1733. fail = true;
  1734. break;
  1735. }
  1736. }
  1737. }
  1738. if (sd->status.base_level < skill_tree[class_][i].baselv) { //We need to get the actual class in this case
  1739. int c_ = pc_mapid2jobid(sd->class_, sd->status.sex);
  1740. c_ = pc_class2idx(c_);
  1741. if (class_ == c_ || (class_ != c_ && sd->status.base_level < skill_tree[class_][i].baselv))
  1742. fail = true; // base level requirement wasn't satisfied
  1743. }
  1744. if (sd->status.job_level < skill_tree[class_][i].joblv) { //We need to get the actual class in this case
  1745. int c_ = pc_mapid2jobid(sd->class_, sd->status.sex);
  1746. c_ = pc_class2idx(c_);
  1747. if (class_ == c_ || (class_ != c_ && sd->status.job_level < skill_tree[class_][i].joblv))
  1748. fail = true; // job level requirement wasn't satisfied
  1749. }
  1750. }
  1751. if (!fail) {
  1752. std::shared_ptr<s_skill_db> skill = skill_db.find(skid);
  1753. if (!sd->status.skill[sk_idx].lv && (
  1754. (skill->inf2[INF2_ISQUEST] && !battle_config.quest_skill_learn) ||
  1755. skill->inf2[INF2_ISWEDDING] ||
  1756. (skill->inf2[INF2_ISSPIRIT] && !sd->sc.data[SC_SPIRIT])
  1757. ))
  1758. continue; //Cannot be learned via normal means. Note this check DOES allows raising already known skills.
  1759. sd->status.skill[sk_idx].id = skid;
  1760. if(skill->inf2[INF2_ISSPIRIT]) { //Spirit skills cannot be learned, they will only show up on your tree when you get buffed.
  1761. sd->status.skill[sk_idx].lv = 1; // need to manually specify a skill level
  1762. sd->status.skill[sk_idx].flag = SKILL_FLAG_TEMPORARY; //So it is not saved, and tagged as a "bonus" skill.
  1763. }
  1764. flag = 1; // skill list has changed, perform another pass
  1765. }
  1766. }
  1767. } while(flag);
  1768. if( class_ > 0 && sd->status.skill_point == 0 && pc_is_taekwon_ranker(sd) ) {
  1769. uint16 skid = 0;
  1770. /* Taekwon Ranker Bonus Skill Tree
  1771. ============================================
  1772. - Grant All Taekwon Tree, but only as Bonus Skills in case they drop from ranking.
  1773. - (c > 0) to avoid grant Novice Skill Tree in case of Skill Reset (need more logic)
  1774. - (sd->status.skill_point == 0) to wait until all skill points are assigned to avoid problems with Job Change quest. */
  1775. for( uint16 i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[class_][i].skill_id) > 0; i++ ) {
  1776. uint16 sk_idx = skill_get_index(skid);
  1777. if (sk_idx == 0)
  1778. continue;
  1779. if( skill_get_inf2_(skid, { INF2_ISQUEST, INF2_ISWEDDING }) )
  1780. continue; //Do not include Quest/Wedding skills.
  1781. if( sd->status.skill[sk_idx].id == 0 ) {
  1782. sd->status.skill[sk_idx].id = skid;
  1783. sd->status.skill[sk_idx].flag = SKILL_FLAG_TEMPORARY; // So it is not saved, and tagged as a "bonus" skill.
  1784. } else if( skid != NV_BASIC )
  1785. sd->status.skill[sk_idx].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[sk_idx].lv; // Remember original level
  1786. sd->status.skill[sk_idx].lv = skill_tree_get_max(skid, sd->status.class_);
  1787. }
  1788. }
  1789. }
  1790. //Checks if you can learn a new skill after having leveled up a skill.
  1791. static void pc_check_skilltree(struct map_session_data *sd)
  1792. {
  1793. int i, flag = 0;
  1794. int c = 0;
  1795. if (battle_config.skillfree)
  1796. return; //Function serves no purpose if this is set
  1797. i = pc_calc_skilltree_normalize_job(sd);
  1798. c = pc_mapid2jobid(i, sd->status.sex);
  1799. if (c == -1) { //Unable to normalize job??
  1800. 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);
  1801. return;
  1802. }
  1803. c = pc_class2idx(c);
  1804. do {
  1805. uint16 skid = 0;
  1806. flag = 0;
  1807. for (i = 0; i < MAX_SKILL_TREE && (skid = skill_tree[c][i].skill_id) > 0; i++ ) {
  1808. uint16 sk_idx = skill_get_index(skid);
  1809. bool fail = false;
  1810. uint8 j = 0;
  1811. if (sd->status.skill[sk_idx].id) //Already learned
  1812. continue;
  1813. // Checking required skills
  1814. for (j = 0; j < MAX_PC_SKILL_REQUIRE; j++) {
  1815. uint16 sk_need_id = skill_tree[c][i].need[j].skill_id;
  1816. uint16 sk_need_idx = 0;
  1817. if (sk_need_id && (sk_need_idx = skill_get_index(sk_need_id))) {
  1818. short sk_need = sk_need_id;
  1819. 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)
  1820. sk_need = 0; //Not learned.
  1821. else if (sd->status.skill[sk_need_idx].flag >= SKILL_FLAG_REPLACED_LV_0) //Real lerned level
  1822. sk_need = sd->status.skill[sk_need_idx].flag - SKILL_FLAG_REPLACED_LV_0;
  1823. else
  1824. sk_need = pc_checkskill(sd,sk_need_id);
  1825. if (sk_need < skill_tree[c][i].need[j].skill_lv) {
  1826. fail = true;
  1827. break;
  1828. }
  1829. }
  1830. }
  1831. if( fail )
  1832. continue;
  1833. if (sd->status.base_level < skill_tree[c][i].baselv || sd->status.job_level < skill_tree[c][i].joblv)
  1834. continue;
  1835. std::shared_ptr<s_skill_db> skill = skill_db.find(skid);
  1836. if( !sd->status.skill[sk_idx].lv && (
  1837. (skill->inf2[INF2_ISQUEST] && !battle_config.quest_skill_learn) ||
  1838. skill->inf2[INF2_ISWEDDING] ||
  1839. (skill->inf2[INF2_ISSPIRIT] && !sd->sc.data[SC_SPIRIT])
  1840. ) )
  1841. continue; //Cannot be learned via normal means.
  1842. sd->status.skill[sk_idx].id = skid;
  1843. flag = 1;
  1844. }
  1845. } while(flag);
  1846. }
  1847. // Make sure all the skills are in the correct condition
  1848. // before persisting to the backend.. [MouseJstr]
  1849. void pc_clean_skilltree(struct map_session_data *sd)
  1850. {
  1851. uint16 i;
  1852. for (i = 0; i < MAX_SKILL; i++){
  1853. if (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED) {
  1854. sd->status.skill[i].id = 0;
  1855. sd->status.skill[i].lv = 0;
  1856. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1857. }
  1858. else if (sd->status.skill[i].flag >= SKILL_FLAG_REPLACED_LV_0){
  1859. sd->status.skill[i].lv = sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  1860. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  1861. }
  1862. }
  1863. }
  1864. int pc_calc_skilltree_normalize_job(struct map_session_data *sd)
  1865. {
  1866. int skill_point, novice_skills;
  1867. int c = sd->class_;
  1868. if (!battle_config.skillup_limit || pc_has_permission(sd, PC_PERM_ALL_SKILL))
  1869. return c;
  1870. skill_point = pc_calc_skillpoint(sd);
  1871. novice_skills = job_info[pc_class2idx(JOB_NOVICE)].max_level[1] - 1;
  1872. // limit 1st class and above to novice job levels
  1873. if(skill_point < novice_skills && (sd->class_&MAPID_BASEMASK) != MAPID_SUMMONER)
  1874. {
  1875. c = MAPID_NOVICE;
  1876. }
  1877. // limit 2nd class and above to first class job levels (super novices are exempt)
  1878. else if (sd->class_&JOBL_2 && (sd->class_&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE)
  1879. {
  1880. // regenerate change_level_2nd
  1881. if (!sd->change_level_2nd)
  1882. {
  1883. if (sd->class_&JOBL_THIRD)
  1884. {
  1885. // if neither 2nd nor 3rd jobchange levels are known, we have to assume a default for 2nd
  1886. if (!sd->change_level_3rd)
  1887. sd->change_level_2nd = job_info[pc_class2idx(pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex))].max_level[1];
  1888. else
  1889. sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
  1890. - (sd->status.job_level - 1)
  1891. - (sd->change_level_3rd - 1)
  1892. - novice_skills;
  1893. }
  1894. else
  1895. {
  1896. sd->change_level_2nd = 1 + skill_point + sd->status.skill_point
  1897. - (sd->status.job_level - 1)
  1898. - novice_skills;
  1899. }
  1900. pc_setglobalreg(sd, add_str(JOBCHANGE2ND_VAR), sd->change_level_2nd);
  1901. }
  1902. if (skill_point < novice_skills + (sd->change_level_2nd - 1))
  1903. {
  1904. c &= MAPID_BASEMASK;
  1905. }
  1906. // limit 3rd class to 2nd class/trans job levels
  1907. else if(sd->class_&JOBL_THIRD)
  1908. {
  1909. // regenerate change_level_3rd
  1910. if (!sd->change_level_3rd)
  1911. {
  1912. sd->change_level_3rd = 1 + skill_point + sd->status.skill_point
  1913. - (sd->status.job_level - 1)
  1914. - (sd->change_level_2nd - 1)
  1915. - novice_skills;
  1916. pc_setglobalreg(sd, add_str(JOBCHANGE3RD_VAR), sd->change_level_3rd);
  1917. }
  1918. if (skill_point < novice_skills + (sd->change_level_2nd - 1) + (sd->change_level_3rd - 1))
  1919. c &= MAPID_UPPERMASK;
  1920. }
  1921. }
  1922. // restore non-limiting flags
  1923. c |= sd->class_&(JOBL_UPPER|JOBL_BABY);
  1924. return c;
  1925. }
  1926. /*==========================================
  1927. * Updates the weight status
  1928. *------------------------------------------
  1929. * 1: overweight 50% for pre-renewal and 70% for renewal
  1930. * 2: overweight 90%
  1931. * It's assumed that SC_WEIGHT50 and SC_WEIGHT90 are only started/stopped here.
  1932. */
  1933. void pc_updateweightstatus(struct map_session_data *sd)
  1934. {
  1935. int old_overweight;
  1936. int new_overweight;
  1937. nullpo_retv(sd);
  1938. old_overweight = (sd->sc.data[SC_WEIGHT90]) ? 2 : (sd->sc.data[SC_WEIGHT50]) ? 1 : 0;
  1939. #ifdef RENEWAL
  1940. new_overweight = (pc_is90overweight(sd)) ? 2 : (pc_is70overweight(sd)) ? 1 : 0;
  1941. #else
  1942. new_overweight = (pc_is90overweight(sd)) ? 2 : (pc_is50overweight(sd)) ? 1 : 0;
  1943. #endif
  1944. if( old_overweight == new_overweight )
  1945. return; // no change
  1946. // stop old status change
  1947. if( old_overweight == 1 )
  1948. status_change_end(&sd->bl, SC_WEIGHT50, INVALID_TIMER);
  1949. else if( old_overweight == 2 )
  1950. status_change_end(&sd->bl, SC_WEIGHT90, INVALID_TIMER);
  1951. // start new status change
  1952. if( new_overweight == 1 )
  1953. sc_start(&sd->bl,&sd->bl, SC_WEIGHT50, 100, 0, 0);
  1954. else if( new_overweight == 2 )
  1955. sc_start(&sd->bl,&sd->bl, SC_WEIGHT90, 100, 0, 0);
  1956. // update overweight status
  1957. sd->regen.state.overweight = new_overweight;
  1958. }
  1959. int pc_disguise(struct map_session_data *sd, int class_)
  1960. {
  1961. if (!class_ && !sd->disguise)
  1962. return 0;
  1963. if (class_ && sd->disguise == class_)
  1964. return 0;
  1965. if(pc_isinvisible(sd))
  1966. { //Character is invisible. Stealth class-change. [Skotlex]
  1967. sd->disguise = class_; //viewdata is set on uncloaking.
  1968. return 2;
  1969. }
  1970. if (sd->bl.prev != NULL) {
  1971. pc_stop_walking(sd, 0);
  1972. clif_clearunit_area(&sd->bl, CLR_OUTSIGHT);
  1973. }
  1974. if (!class_) {
  1975. sd->disguise = 0;
  1976. class_ = sd->status.class_;
  1977. } else
  1978. sd->disguise=class_;
  1979. status_set_viewdata(&sd->bl, class_);
  1980. clif_changeoption(&sd->bl);
  1981. if (sd->bl.prev != NULL) {
  1982. clif_spawn(&sd->bl);
  1983. if (class_ == sd->status.class_ && pc_iscarton(sd))
  1984. { //It seems the cart info is lost on undisguise.
  1985. clif_cartlist(sd);
  1986. clif_updatestatus(sd,SP_CARTINFO);
  1987. }
  1988. if (sd->chatID) {
  1989. struct chat_data* cd;
  1990. if ((cd = (struct chat_data*)map_id2bl(sd->chatID)) != NULL)
  1991. clif_dispchat(cd,0);
  1992. }
  1993. }
  1994. return 1;
  1995. }
  1996. /// Show error message
  1997. #define PC_BONUS_SHOW_ERROR(type,type2,val) { ShowError("%s: %s: Invalid %s %d.\n",__FUNCTION__,#type,#type2,(val)); break; }
  1998. /// Check for valid Element, break & show error message if invalid Element
  1999. #define PC_BONUS_CHK_ELEMENT(ele,bonus) { if (!CHK_ELEMENT((ele))) { PC_BONUS_SHOW_ERROR((bonus),Element,(ele)); }}
  2000. /// Check for valid Race, break & show error message if invalid Race
  2001. #define PC_BONUS_CHK_RACE(rc,bonus) { if (!CHK_RACE((rc))) { PC_BONUS_SHOW_ERROR((bonus),Race,(rc)); }}
  2002. /// Check for valid Race2, break & show error message if invalid Race2
  2003. #define PC_BONUS_CHK_RACE2(rc2,bonus) { if (!CHK_RACE2((rc2))) { PC_BONUS_SHOW_ERROR((bonus),Race2,(rc2)); }}
  2004. /// Check for valid Class, break & show error message if invalid Class
  2005. #define PC_BONUS_CHK_CLASS(cl,bonus) { if (!CHK_CLASS((cl))) { PC_BONUS_SHOW_ERROR((bonus),Class,(cl)); }}
  2006. /// Check for valid Size, break & show error message if invalid Size
  2007. #define PC_BONUS_CHK_SIZE(sz,bonus) { if (!CHK_MOBSIZE((sz))) { PC_BONUS_SHOW_ERROR((bonus),Size,(sz)); }}
  2008. /// Check for valid SC, break & show error message if invalid SC
  2009. #define PC_BONUS_CHK_SC(sc,bonus) { if ((sc) <= SC_NONE || (sc) >= SC_MAX) { PC_BONUS_SHOW_ERROR((bonus),Effect,(sc)); }}
  2010. /**
  2011. * Add auto spell bonus for player while attacking/attacked
  2012. * @param spell: Spell array
  2013. * @param id: Skill to cast
  2014. * @param lv: Skill level
  2015. * @param rate: Success chance
  2016. * @param flag: Battle flag
  2017. * @param card_id: Used to prevent card stacking
  2018. */
  2019. static void pc_bonus_autospell(std::vector<s_autospell> &spell, short id, short lv, short rate, short flag, unsigned short card_id)
  2020. {
  2021. if (spell.size() == MAX_PC_BONUS) {
  2022. ShowWarning("pc_bonus_autospell: Reached max (%d) number of autospells per character!\n", MAX_PC_BONUS);
  2023. return;
  2024. }
  2025. if (!rate)
  2026. return;
  2027. if (!(flag&BF_RANGEMASK))
  2028. flag |= BF_SHORT | BF_LONG; //No range defined? Use both.
  2029. if (!(flag&BF_WEAPONMASK))
  2030. flag |= BF_WEAPON; //No attack type defined? Use weapon.
  2031. if (!(flag&BF_SKILLMASK)) {
  2032. if (flag&(BF_MAGIC | BF_MISC))
  2033. flag |= BF_SKILL; //These two would never trigger without BF_SKILL
  2034. if (flag&BF_WEAPON)
  2035. flag |= BF_NORMAL; //By default autospells should only trigger on normal weapon attacks.
  2036. }
  2037. for (auto &it : spell) {
  2038. if ((it.card_id == card_id || it.rate < 0 || rate < 0) && it.id == id && it.lv == lv && it.flag == flag) {
  2039. if (!battle_config.autospell_stacking && it.rate > 0 && rate > 0) // Stacking disabled
  2040. return;
  2041. it.rate = cap_value(it.rate + rate, -10000, 10000);
  2042. return;
  2043. }
  2044. }
  2045. struct s_autospell entry = {};
  2046. if (rate < -10000 || rate > 10000)
  2047. ShowWarning("pc_bonus_autospell: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2048. entry.id = id;
  2049. entry.lv = lv;
  2050. entry.rate = cap_value(rate, -10000, 10000);
  2051. entry.flag = flag;
  2052. entry.card_id = card_id;
  2053. spell.push_back(entry);
  2054. }
  2055. /**
  2056. * Add auto spell bonus for player while using skills
  2057. * @param spell: Spell array
  2058. * @param src_skill: Trigger skill
  2059. * @param id: Support or target type
  2060. * @param lv: Skill level
  2061. * @param rate: Success chance
  2062. * @param card_id: Used to prevent card stacking
  2063. */
  2064. static void pc_bonus_autospell_onskill(std::vector<s_autospell> &spell, short src_skill, short id, short lv, short rate, unsigned short card_id)
  2065. {
  2066. if (spell.size() == MAX_PC_BONUS) {
  2067. ShowWarning("pc_bonus_autospell_onskill: Reached max (%d) number of autospells per character!\n", MAX_PC_BONUS);
  2068. return;
  2069. }
  2070. if (!rate)
  2071. return;
  2072. struct s_autospell entry = {};
  2073. if (rate < -10000 || rate > 10000)
  2074. ShowWarning("pc_bonus_onskill: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2075. entry.flag = src_skill;
  2076. entry.id = id;
  2077. entry.lv = lv;
  2078. entry.rate = cap_value(rate, -10000, 10000);
  2079. entry.card_id = card_id;
  2080. spell.push_back(entry);
  2081. }
  2082. /**
  2083. * Add inflict effect bonus for player while attacking/attacked
  2084. * @param effect: Effect array
  2085. * @param sc: SC/Effect type
  2086. * @param rate: Success chance
  2087. * @param arrow_rate: success chance if bonus comes from arrow-type item
  2088. * @param flag: Target flag
  2089. * @param duration: Duration. If 0 use default duration lookup for associated skill with level 7
  2090. */
  2091. static void pc_bonus_addeff(std::vector<s_addeffect> &effect, enum sc_type sc, short rate, short arrow_rate, unsigned char flag, unsigned int duration)
  2092. {
  2093. if (effect.size() == MAX_PC_BONUS) {
  2094. ShowWarning("pc_bonus_addeff: Reached max (%d) number of add effects per character!\n", MAX_PC_BONUS);
  2095. return;
  2096. }
  2097. if (!(flag&(ATF_SHORT | ATF_LONG)))
  2098. flag |= ATF_SHORT | ATF_LONG; //Default range: both
  2099. if (!(flag&(ATF_TARGET | ATF_SELF)))
  2100. flag |= ATF_TARGET; //Default target: enemy.
  2101. if (!(flag&(ATF_WEAPON | ATF_MAGIC | ATF_MISC)))
  2102. flag |= ATF_WEAPON; //Default type: weapon.
  2103. if (!duration)
  2104. duration = (unsigned int)skill_get_time2(status_sc2skill(sc), 7);
  2105. for (auto &it : effect) {
  2106. if (it.sc == sc && it.flag == flag) {
  2107. it.rate = cap_value(it.rate + rate, -10000, 10000);
  2108. it.arrow_rate += arrow_rate;
  2109. it.duration = umax(it.duration, duration);
  2110. return;
  2111. }
  2112. }
  2113. struct s_addeffect entry = {};
  2114. if (rate < -10000 || rate > 10000)
  2115. ShowWarning("pc_bonus_addeff: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2116. entry.sc = sc;
  2117. entry.rate = cap_value(rate, -10000, 10000);
  2118. entry.arrow_rate = arrow_rate;
  2119. entry.flag = flag;
  2120. entry.duration = duration;
  2121. effect.push_back(entry);
  2122. }
  2123. /**
  2124. * Add inflict effect bonus for player while attacking using skill
  2125. * @param effect: Effect array
  2126. * @param sc: SC/Effect type
  2127. * @param rate: Success chance
  2128. * @param skill_id: Skill to cast
  2129. * @param target: Target type
  2130. * @param duration: Duration. If 0 use default duration lookup for associated skill with level 7
  2131. */
  2132. static void pc_bonus_addeff_onskill(std::vector<s_addeffectonskill> &effect, enum sc_type sc, short rate, short skill_id, unsigned char target, unsigned int duration)
  2133. {
  2134. if (effect.size() == MAX_PC_BONUS) {
  2135. ShowWarning("pc_bonus_addeff_onskill: Reached max (%d) number of add effects per character!\n", MAX_PC_BONUS);
  2136. return;
  2137. }
  2138. if (!duration)
  2139. duration = (unsigned int)skill_get_time2(status_sc2skill(sc), 7);
  2140. for (auto &it : effect) {
  2141. if (it.sc == sc && it.skill_id == skill_id && it.target == target) {
  2142. it.rate = cap_value(it.rate + rate, -10000, 10000);
  2143. it.duration = umax(it.duration, duration);
  2144. return;
  2145. }
  2146. }
  2147. struct s_addeffectonskill entry = {};
  2148. if (rate < -10000 || rate > 10000)
  2149. ShowWarning("pc_bonus_addeff_onskill: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2150. entry.sc = sc;
  2151. entry.rate = cap_value(rate, -10000, 10000);
  2152. entry.skill_id = skill_id;
  2153. entry.target = target;
  2154. entry.duration = duration;
  2155. effect.push_back(entry);
  2156. }
  2157. /**
  2158. * Adjust/add drop rate modifier for player
  2159. * @param drop: Player's sd->add_drop (struct s_add_drop)
  2160. * @param nameid: item id that will be dropped
  2161. * @param group: group id
  2162. * @param class_: target class
  2163. * @param race: target race. if < 0, means monster_id
  2164. * @param rate: rate value: 1 ~ 10000. If < 0, it will be multiplied with mob level/10
  2165. */
  2166. static void pc_bonus_item_drop(std::vector<s_add_drop> &drop, unsigned short nameid, uint16 group, int class_, short race, int rate)
  2167. {
  2168. if (!nameid && !group) {
  2169. ShowWarning("pc_bonus_item_drop: No Item ID nor Item Group ID specified.\n");
  2170. return;
  2171. }
  2172. if (nameid && !itemdb_exists(nameid)) {
  2173. ShowWarning("pc_bonus_item_drop: Invalid item id %hu\n",nameid);
  2174. return;
  2175. }
  2176. if (group && !itemdb_group_exists(group)) {
  2177. ShowWarning("pc_bonus_item_drop: Invalid Item Group %hu\n",group);
  2178. return;
  2179. }
  2180. if (drop.size() == MAX_PC_BONUS) {
  2181. 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_PC_BONUS, nameid, group, class_, race, rate);
  2182. return;
  2183. }
  2184. //Apply config rate adjustment settings.
  2185. if (rate >= 0) { //Absolute drop.
  2186. if (battle_config.item_rate_adddrop != 100)
  2187. rate = rate*battle_config.item_rate_adddrop/100;
  2188. if (rate < battle_config.item_drop_adddrop_min)
  2189. rate = battle_config.item_drop_adddrop_min;
  2190. else if (rate > battle_config.item_drop_adddrop_max)
  2191. rate = battle_config.item_drop_adddrop_max;
  2192. } else { //Relative drop, max/min limits are applied at drop time.
  2193. if (battle_config.item_rate_adddrop != 100)
  2194. rate = rate*battle_config.item_rate_adddrop/100;
  2195. if (rate > -1)
  2196. rate = -1;
  2197. }
  2198. for (auto &it : drop) {
  2199. if (it.nameid == nameid && it.group == group && it.race == race && it.class_ == class_) {
  2200. if ((rate < 0 && it.rate < 0) || (rate > 0 && it.rate > 0)) //Adjust the rate if it has same classification
  2201. it.rate = cap_value(it.rate + rate, -10000, 10000);
  2202. return;
  2203. }
  2204. }
  2205. struct s_add_drop entry = {};
  2206. if (rate < -10000 || rate > 10000)
  2207. ShowWarning("pc_bonus_item_drop: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2208. entry.nameid = nameid;
  2209. entry.group = group;
  2210. entry.race = race;
  2211. entry.class_ = class_;
  2212. entry.rate = cap_value(rate, -10000, 10000);
  2213. drop.push_back(entry);
  2214. }
  2215. /**
  2216. * Add autobonus to player when attacking/attacked
  2217. * @param bonus: Bonus array
  2218. * @param script: Script to execute
  2219. * @param rate: Success chance
  2220. * @param dur: Duration
  2221. * @param flag: Battle flag/skill
  2222. * @param other_script: Secondary script to execute
  2223. * @param pos: Item equip position
  2224. * @param onskill: Skill used to trigger autobonus
  2225. * @return True on success or false otherwise
  2226. */
  2227. bool pc_addautobonus(std::vector<s_autobonus> &bonus, const char *script, short rate, unsigned int dur, uint16 flag, const char *other_script, unsigned int pos, bool onskill)
  2228. {
  2229. if (bonus.size() == MAX_PC_BONUS) {
  2230. ShowWarning("pc_addautobonus: Reached max (%d) number of autobonus per character!\n", MAX_PC_BONUS);
  2231. return false;
  2232. }
  2233. if (!onskill) {
  2234. if (!(flag&BF_RANGEMASK))
  2235. flag |= BF_SHORT | BF_LONG; //No range defined? Use both.
  2236. if (!(flag&BF_WEAPONMASK))
  2237. flag |= BF_WEAPON; //No attack type defined? Use weapon.
  2238. if (!(flag&BF_SKILLMASK)) {
  2239. if (flag&(BF_MAGIC | BF_MISC))
  2240. flag |= BF_SKILL; //These two would never trigger without BF_SKILL
  2241. if (flag&BF_WEAPON)
  2242. flag |= BF_NORMAL | BF_SKILL;
  2243. }
  2244. }
  2245. struct s_autobonus entry = {};
  2246. if (rate < -10000 || rate > 10000)
  2247. ShowWarning("pc_addautobonus: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2248. entry.rate = cap_value(rate, -10000, 10000);
  2249. entry.duration = dur;
  2250. entry.active = INVALID_TIMER;
  2251. entry.atk_type = flag;
  2252. entry.pos = pos;
  2253. entry.bonus_script = aStrdup(script);
  2254. entry.other_script = (other_script ? aStrdup(other_script) : NULL);
  2255. bonus.push_back(entry);
  2256. return true;
  2257. }
  2258. /**
  2259. * Remove an autobonus from player
  2260. * @param sd: Player data
  2261. * @param bonus: Autobonus array
  2262. * @param restore: Run script on clearing or not
  2263. */
  2264. void pc_delautobonus(struct map_session_data* sd, std::vector<s_autobonus> &bonus, bool restore)
  2265. {
  2266. nullpo_retv(sd);
  2267. std::vector<s_autobonus>::iterator it = bonus.begin();
  2268. while( it != bonus.end() ){
  2269. s_autobonus b = *it;
  2270. if (b.active != INVALID_TIMER) {
  2271. if (restore && (sd->state.autobonus&b.pos) == b.pos) {
  2272. if (b.bonus_script) {
  2273. unsigned int equip_pos_idx = 0;
  2274. // Create a list of all equipped positions to see if all items needed for the autobonus are still present [Playtester]
  2275. for (uint8 j = 0; j < EQI_MAX; j++) {
  2276. if (sd->equip_index[j] >= 0)
  2277. equip_pos_idx |= sd->inventory.u.items_inventory[sd->equip_index[j]].equip;
  2278. }
  2279. if ((equip_pos_idx&b.pos) == b.pos)
  2280. script_run_autobonus(b.bonus_script, sd, b.pos);
  2281. }
  2282. it++;
  2283. continue;
  2284. } else { // Logout / Unequipped an item with an activated bonus
  2285. delete_timer(b.active, pc_endautobonus);
  2286. b.active = INVALID_TIMER;
  2287. }
  2288. }
  2289. if (b.bonus_script)
  2290. aFree(b.bonus_script);
  2291. if (b.other_script)
  2292. aFree(b.other_script);
  2293. it = bonus.erase(it);
  2294. }
  2295. }
  2296. /**
  2297. * Execute autobonus on player
  2298. * @param sd: Player data
  2299. * @param autobonus: Autobonus to run
  2300. */
  2301. void pc_exeautobonus(struct map_session_data *sd, std::vector<s_autobonus> *bonus, struct s_autobonus *autobonus)
  2302. {
  2303. nullpo_retv(sd);
  2304. nullpo_retv(autobonus);
  2305. if (autobonus->active != INVALID_TIMER)
  2306. delete_timer(autobonus->active, pc_endautobonus);
  2307. if( autobonus->other_script )
  2308. {
  2309. int j;
  2310. unsigned int equip_pos_idx = 0;
  2311. //Create a list of all equipped positions to see if all items needed for the autobonus are still present [Playtester]
  2312. for(j = 0; j < EQI_MAX; j++) {
  2313. if(sd->equip_index[j] >= 0)
  2314. equip_pos_idx |= sd->inventory.u.items_inventory[sd->equip_index[j]].equip;
  2315. }
  2316. if((equip_pos_idx&autobonus->pos) == autobonus->pos)
  2317. script_run_autobonus(autobonus->other_script,sd,autobonus->pos);
  2318. }
  2319. autobonus->active = add_timer(gettick()+autobonus->duration, pc_endautobonus, sd->bl.id, (intptr_t)bonus);
  2320. sd->state.autobonus |= autobonus->pos;
  2321. status_calc_pc(sd,SCO_NONE);
  2322. }
  2323. /**
  2324. * Remove autobonus timer from player
  2325. */
  2326. TIMER_FUNC(pc_endautobonus){
  2327. struct map_session_data *sd = map_id2sd(id);
  2328. std::vector<s_autobonus> *bonus = (std::vector<s_autobonus> *)data;
  2329. nullpo_ret(sd);
  2330. nullpo_ret(bonus);
  2331. for( struct s_autobonus& autobonus : *bonus ){
  2332. if( autobonus.active == tid ){
  2333. autobonus.active = INVALID_TIMER;
  2334. sd->state.autobonus &= ~autobonus.pos;
  2335. break;
  2336. }
  2337. }
  2338. status_calc_pc(sd,SCO_NONE);
  2339. return 0;
  2340. }
  2341. /**
  2342. * Add element bonus to player when attacking
  2343. * @param sd: Player data
  2344. * @param ele: Element to adjust
  2345. * @param rate: Success chance
  2346. * @param flag: Battle flag
  2347. */
  2348. static void pc_bonus_addele(struct map_session_data* sd, unsigned char ele, short rate, short flag)
  2349. {
  2350. nullpo_retv(sd);
  2351. struct weapon_data *wd = (sd->state.lr_flag ? &sd->left_weapon : &sd->right_weapon);
  2352. if (wd->addele2.size() == MAX_PC_BONUS) {
  2353. ShowWarning("pc_bonus_addele: Reached max (%d) number of add element damage bonuses per character!\n", MAX_PC_BONUS);
  2354. return;
  2355. }
  2356. if (!(flag&BF_RANGEMASK))
  2357. flag |= BF_SHORT | BF_LONG;
  2358. if (!(flag&BF_WEAPONMASK))
  2359. flag |= BF_WEAPON;
  2360. if (!(flag&BF_SKILLMASK)) {
  2361. if (flag&(BF_MAGIC | BF_MISC))
  2362. flag |= BF_SKILL;
  2363. if (flag&BF_WEAPON)
  2364. flag |= BF_NORMAL | BF_SKILL;
  2365. }
  2366. for (auto &it : wd->addele2) {
  2367. if (it.ele == ele && it.flag == flag) {
  2368. it.rate = cap_value(it.rate + rate, -10000, 10000);
  2369. return;
  2370. }
  2371. }
  2372. struct s_addele2 entry = {};
  2373. if (rate < -10000 || rate > 10000)
  2374. ShowWarning("pc_bonus_addele: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2375. entry.ele = ele;
  2376. entry.rate = cap_value(rate, -10000, 10000);
  2377. entry.flag = flag;
  2378. wd->addele2.push_back(entry);
  2379. }
  2380. /**
  2381. * Reduce element bonus to player when attacking
  2382. * @param sd: Player data
  2383. * @param ele: Element to adjust
  2384. * @param rate: Success chance
  2385. * @param flag: Battle flag
  2386. */
  2387. static void pc_bonus_subele(struct map_session_data* sd, unsigned char ele, short rate, short flag)
  2388. {
  2389. nullpo_retv(sd);
  2390. if (sd->subele2.size() == MAX_PC_BONUS) {
  2391. ShowWarning("pc_bonus_subele: Reached max (%d) number of resist element damage bonuses per character!\n", MAX_PC_BONUS);
  2392. return;
  2393. }
  2394. if (!(flag&BF_RANGEMASK))
  2395. flag |= BF_SHORT | BF_LONG;
  2396. if (!(flag&BF_WEAPONMASK))
  2397. flag |= BF_WEAPON;
  2398. if (!(flag&BF_SKILLMASK)) {
  2399. if (flag&(BF_MAGIC | BF_MISC))
  2400. flag |= BF_SKILL;
  2401. if (flag&BF_WEAPON)
  2402. flag |= BF_NORMAL | BF_SKILL;
  2403. }
  2404. for (auto &it : sd->subele2) {
  2405. if (it.ele == ele && it.flag == flag) {
  2406. it.rate = cap_value(it.rate + rate, -10000, 10000);
  2407. return;
  2408. }
  2409. }
  2410. struct s_addele2 entry = {};
  2411. if (rate < -10000 || rate > 10000)
  2412. ShowWarning("pc_bonus_subele: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2413. entry.ele = ele;
  2414. entry.rate = cap_value(rate, -10000, 10000);
  2415. entry.flag = flag;
  2416. sd->subele2.push_back(entry);
  2417. }
  2418. /**
  2419. * General item bonus for player
  2420. * @param bonus: Bonus array
  2421. * @param id: Key
  2422. * @param val: Value
  2423. * @param cap_rate: If Value is a rate value that needs to be capped
  2424. */
  2425. static void pc_bonus_itembonus(std::vector<s_item_bonus> &bonus, uint16 id, int val, bool cap_rate)
  2426. {
  2427. for (auto &it : bonus) {
  2428. if (it.id == id) {
  2429. if (cap_rate)
  2430. it.val = cap_value(it.val + val, -10000, 10000);
  2431. else
  2432. it.val += val;
  2433. return;
  2434. }
  2435. }
  2436. struct s_item_bonus entry = {};
  2437. if (cap_rate && (val < -10000 || val > 10000)) {
  2438. ShowWarning("pc_bonus_itembonus: Item bonus val %d exceeds -10000~10000 range, capping.\n", val);
  2439. val = cap_value(val, -10000, 10000);
  2440. }
  2441. entry.id = id;
  2442. entry.val = val;
  2443. bonus.push_back(entry);
  2444. }
  2445. /**
  2446. * Remove HP/SP to player when attacking
  2447. * @param bonus: Bonus array
  2448. * @param rate: Success chance
  2449. * @param per: Percentage of HP/SP to vanish
  2450. * @param flag: Battle flag
  2451. */
  2452. static void pc_bonus_addvanish(std::vector<s_vanish_bonus> &bonus, int16 rate, int16 per, int flag) {
  2453. if (bonus.size() == MAX_PC_BONUS) {
  2454. ShowWarning("pc_bonus_addvanish: Reached max (%d) number of vanish damage bonuses per character!\n", MAX_PC_BONUS);
  2455. return;
  2456. }
  2457. if (!(flag&BF_RANGEMASK))
  2458. flag |= BF_SHORT | BF_LONG;
  2459. if (!(flag&BF_WEAPONMASK))
  2460. flag |= BF_WEAPON;
  2461. if (!(flag&BF_SKILLMASK)) {
  2462. if (flag&(BF_MAGIC | BF_MISC))
  2463. flag |= BF_SKILL;
  2464. if (flag&BF_WEAPON)
  2465. flag |= BF_NORMAL | BF_SKILL;
  2466. }
  2467. for (auto &it : bonus) {
  2468. if (it.flag == flag) {
  2469. it.rate = cap_value(it.rate + rate, -10000, 10000);
  2470. it.per += per;
  2471. return;
  2472. }
  2473. }
  2474. struct s_vanish_bonus entry = {};
  2475. if (rate < -10000 || rate > 10000)
  2476. ShowWarning("pc_bonus_addvanish: Item bonus rate %d exceeds -10000~10000 range, capping.\n", rate);
  2477. entry.rate = cap_value(rate, -10000, 10000);
  2478. entry.per = per;
  2479. entry.flag = flag;
  2480. bonus.push_back(entry);
  2481. }
  2482. /*==========================================
  2483. * Add a bonus(type) to player sd
  2484. * format: bonus bBonusName,val;
  2485. * @param sd
  2486. * @param type Bonus type used by bBonusName
  2487. * @param val Value that usually for rate or fixed value
  2488. *------------------------------------------*/
  2489. void pc_bonus(struct map_session_data *sd,int type,int val)
  2490. {
  2491. struct status_data *status;
  2492. int bonus;
  2493. nullpo_retv(sd);
  2494. status = &sd->base_status;
  2495. switch(type){
  2496. case SP_STR:
  2497. case SP_AGI:
  2498. case SP_VIT:
  2499. case SP_INT:
  2500. case SP_DEX:
  2501. case SP_LUK:
  2502. if(sd->state.lr_flag != 2)
  2503. sd->param_bonus[type-SP_STR]+=val;
  2504. break;
  2505. case SP_ATK1:
  2506. if(!sd->state.lr_flag) {
  2507. bonus = status->rhw.atk + val;
  2508. status->rhw.atk = cap_value(bonus, 0, USHRT_MAX);
  2509. }
  2510. else if(sd->state.lr_flag == 1) {
  2511. bonus = status->lhw.atk + val;
  2512. status->lhw.atk = cap_value(bonus, 0, USHRT_MAX);
  2513. }
  2514. break;
  2515. case SP_ATK2:
  2516. if(!sd->state.lr_flag) {
  2517. bonus = status->rhw.atk2 + val;
  2518. status->rhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
  2519. }
  2520. else if(sd->state.lr_flag == 1) {
  2521. bonus = status->lhw.atk2 + val;
  2522. status->lhw.atk2 = cap_value(bonus, 0, USHRT_MAX);
  2523. }
  2524. break;
  2525. case SP_BASE_ATK:
  2526. if(sd->state.lr_flag != 2) {
  2527. #ifdef RENEWAL
  2528. bonus = sd->bonus.eatk + val;
  2529. sd->bonus.eatk = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2530. #else
  2531. bonus = status->batk + val;
  2532. status->batk = cap_value(bonus, 0, USHRT_MAX);
  2533. #endif
  2534. }
  2535. break;
  2536. case SP_DEF1:
  2537. if(sd->state.lr_flag != 2) {
  2538. bonus = status->def + val;
  2539. #ifdef RENEWAL
  2540. status->def = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2541. #else
  2542. status->def = cap_value(bonus, CHAR_MIN, CHAR_MAX);
  2543. #endif
  2544. }
  2545. break;
  2546. case SP_DEF2:
  2547. if(sd->state.lr_flag != 2) {
  2548. bonus = status->def2 + val;
  2549. status->def2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2550. }
  2551. break;
  2552. case SP_MDEF1:
  2553. if(sd->state.lr_flag != 2) {
  2554. bonus = status->mdef + val;
  2555. #ifdef RENEWAL
  2556. status->mdef = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2557. #else
  2558. status->mdef = cap_value(bonus, CHAR_MIN, CHAR_MAX);
  2559. #endif
  2560. if( sd->state.lr_flag == 3 ) {//Shield, used for royal guard
  2561. sd->bonus.shieldmdef += bonus;
  2562. }
  2563. }
  2564. break;
  2565. case SP_MDEF2:
  2566. if(sd->state.lr_flag != 2) {
  2567. bonus = status->mdef2 + val;
  2568. status->mdef2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2569. }
  2570. break;
  2571. case SP_HIT:
  2572. if(sd->state.lr_flag != 2) {
  2573. bonus = status->hit + val;
  2574. status->hit = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2575. } else
  2576. sd->bonus.arrow_hit+=val;
  2577. break;
  2578. case SP_FLEE1:
  2579. if(sd->state.lr_flag != 2) {
  2580. bonus = status->flee + val;
  2581. status->flee = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2582. }
  2583. break;
  2584. case SP_FLEE2:
  2585. if(sd->state.lr_flag != 2) {
  2586. bonus = status->flee2 + val*10;
  2587. status->flee2 = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2588. }
  2589. break;
  2590. case SP_CRITICAL:
  2591. if(sd->state.lr_flag != 2) {
  2592. bonus = status->cri + val*10;
  2593. status->cri = cap_value(bonus, SHRT_MIN, SHRT_MAX);
  2594. } else
  2595. sd->bonus.arrow_cri += val*10;
  2596. break;
  2597. case SP_ATKELE:
  2598. PC_BONUS_CHK_ELEMENT(val,SP_ATKELE);
  2599. switch (sd->state.lr_flag)
  2600. {
  2601. case 2:
  2602. switch (sd->status.weapon) {
  2603. case W_BOW:
  2604. case W_REVOLVER:
  2605. case W_RIFLE:
  2606. case W_GATLING:
  2607. case W_SHOTGUN:
  2608. case W_GRENADE:
  2609. //Become weapon element.
  2610. status->rhw.ele=val;
  2611. break;
  2612. default: //Become arrow element.
  2613. sd->bonus.arrow_ele=val;
  2614. break;
  2615. }
  2616. break;
  2617. case 1:
  2618. status->lhw.ele=val;
  2619. break;
  2620. default:
  2621. status->rhw.ele=val;
  2622. break;
  2623. }
  2624. break;
  2625. case SP_DEFELE:
  2626. PC_BONUS_CHK_ELEMENT(val,SP_DEFELE);
  2627. if(sd->state.lr_flag != 2)
  2628. status->def_ele=val;
  2629. break;
  2630. case SP_MAXHP:
  2631. if(sd->state.lr_flag == 2)
  2632. break;
  2633. sd->bonus.hp += val;
  2634. break;
  2635. case SP_MAXSP:
  2636. if(sd->state.lr_flag == 2)
  2637. break;
  2638. sd->bonus.sp += val;
  2639. break;
  2640. case SP_MAXHPRATE:
  2641. if(sd->state.lr_flag != 2)
  2642. sd->hprate+=val;
  2643. break;
  2644. case SP_MAXSPRATE:
  2645. if(sd->state.lr_flag != 2)
  2646. sd->sprate+=val;
  2647. break;
  2648. case SP_SPRATE:
  2649. if(sd->state.lr_flag != 2)
  2650. sd->dsprate+=val;
  2651. break;
  2652. case SP_ATTACKRANGE:
  2653. switch (sd->state.lr_flag) {
  2654. case 2:
  2655. switch (sd->status.weapon) {
  2656. case W_BOW:
  2657. case W_REVOLVER:
  2658. case W_RIFLE:
  2659. case W_GATLING:
  2660. case W_SHOTGUN:
  2661. case W_GRENADE:
  2662. status->rhw.range += val;
  2663. }
  2664. break;
  2665. case 1:
  2666. status->lhw.range += val;
  2667. break;
  2668. default:
  2669. status->rhw.range += val;
  2670. break;
  2671. }
  2672. break;
  2673. case SP_SPEED_RATE: //Non stackable increase
  2674. if(sd->state.lr_flag != 2)
  2675. sd->bonus.speed_rate = min(sd->bonus.speed_rate, -val);
  2676. break;
  2677. case SP_SPEED_ADDRATE: //Stackable increase
  2678. if(sd->state.lr_flag != 2)
  2679. sd->bonus.speed_add_rate -= val;
  2680. break;
  2681. case SP_ASPD: //Raw increase
  2682. if(sd->state.lr_flag != 2)
  2683. sd->bonus.aspd_add -= 10*val;
  2684. break;
  2685. case SP_ASPD_RATE: //Stackable increase - Made it linear as per rodatazone
  2686. if(sd->state.lr_flag != 2)
  2687. #ifndef RENEWAL_ASPD
  2688. status->aspd_rate -= 10*val;
  2689. #else
  2690. status->aspd_rate2 += val;
  2691. #endif
  2692. break;
  2693. case SP_HP_RECOV_RATE:
  2694. if(sd->state.lr_flag != 2)
  2695. sd->hprecov_rate += val;
  2696. break;
  2697. case SP_SP_RECOV_RATE:
  2698. if(sd->state.lr_flag != 2)
  2699. sd->sprecov_rate += val;
  2700. break;
  2701. case SP_CRITICAL_DEF:
  2702. if(sd->state.lr_flag != 2)
  2703. sd->bonus.critical_def += val;
  2704. break;
  2705. case SP_NEAR_ATK_DEF:
  2706. if(sd->state.lr_flag != 2)
  2707. sd->bonus.near_attack_def_rate += val;
  2708. break;
  2709. case SP_LONG_ATK_DEF:
  2710. if(sd->state.lr_flag != 2)
  2711. sd->bonus.long_attack_def_rate += val;
  2712. break;
  2713. case SP_DOUBLE_RATE:
  2714. if(sd->state.lr_flag == 0 && sd->bonus.double_rate < val)
  2715. sd->bonus.double_rate = val;
  2716. break;
  2717. case SP_DOUBLE_ADD_RATE:
  2718. if(sd->state.lr_flag == 0)
  2719. sd->bonus.double_add_rate += val;
  2720. break;
  2721. case SP_MATK_RATE:
  2722. if(sd->state.lr_flag != 2)
  2723. sd->matk_rate += val;
  2724. break;
  2725. case SP_IGNORE_DEF_ELE:
  2726. PC_BONUS_CHK_ELEMENT(val,SP_IGNORE_DEF_ELE);
  2727. if(!sd->state.lr_flag)
  2728. sd->right_weapon.ignore_def_ele |= 1<<val;
  2729. else if(sd->state.lr_flag == 1)
  2730. sd->left_weapon.ignore_def_ele |= 1<<val;
  2731. break;
  2732. case SP_IGNORE_DEF_RACE:
  2733. PC_BONUS_CHK_RACE(val,SP_IGNORE_DEF_RACE);
  2734. if(!sd->state.lr_flag)
  2735. sd->right_weapon.ignore_def_race |= 1<<val;
  2736. else if(sd->state.lr_flag == 1)
  2737. sd->left_weapon.ignore_def_race |= 1<<val;
  2738. break;
  2739. case SP_IGNORE_DEF_CLASS:
  2740. PC_BONUS_CHK_CLASS(val,SP_IGNORE_DEF_CLASS);
  2741. if(!sd->state.lr_flag)
  2742. sd->right_weapon.ignore_def_class |= 1<<val;
  2743. else if(sd->state.lr_flag == 1)
  2744. sd->left_weapon.ignore_def_class |= 1<<val;
  2745. break;
  2746. case SP_ATK_RATE:
  2747. if(sd->state.lr_flag != 2)
  2748. sd->bonus.atk_rate += val;
  2749. break;
  2750. case SP_MAGIC_ATK_DEF:
  2751. if(sd->state.lr_flag != 2)
  2752. sd->bonus.magic_def_rate += val;
  2753. break;
  2754. case SP_MISC_ATK_DEF:
  2755. if(sd->state.lr_flag != 2)
  2756. sd->bonus.misc_def_rate += val;
  2757. break;
  2758. case SP_IGNORE_MDEF_ELE:
  2759. PC_BONUS_CHK_ELEMENT(val,SP_IGNORE_MDEF_ELE);
  2760. if(sd->state.lr_flag != 2)
  2761. sd->bonus.ignore_mdef_ele |= 1<<val;
  2762. break;
  2763. case SP_IGNORE_MDEF_RACE:
  2764. PC_BONUS_CHK_RACE(val,SP_IGNORE_MDEF_RACE);
  2765. if(sd->state.lr_flag != 2)
  2766. sd->bonus.ignore_mdef_race |= 1<<val;
  2767. break;
  2768. case SP_PERFECT_HIT_RATE:
  2769. if(sd->state.lr_flag != 2 && sd->bonus.perfect_hit < val)
  2770. sd->bonus.perfect_hit = val;
  2771. break;
  2772. case SP_PERFECT_HIT_ADD_RATE:
  2773. if(sd->state.lr_flag != 2)
  2774. sd->bonus.perfect_hit_add += val;
  2775. break;
  2776. case SP_CRITICAL_RATE:
  2777. if(sd->state.lr_flag != 2)
  2778. sd->critical_rate+=val;
  2779. break;
  2780. case SP_DEF_RATIO_ATK_ELE:
  2781. PC_BONUS_CHK_ELEMENT(val,SP_DEF_RATIO_ATK_ELE);
  2782. if(!sd->state.lr_flag)
  2783. sd->right_weapon.def_ratio_atk_ele |= 1<<val;
  2784. else if(sd->state.lr_flag == 1)
  2785. sd->left_weapon.def_ratio_atk_ele |= 1<<val;
  2786. break;
  2787. case SP_DEF_RATIO_ATK_RACE:
  2788. PC_BONUS_CHK_RACE(val,SP_DEF_RATIO_ATK_RACE);
  2789. if(!sd->state.lr_flag)
  2790. sd->right_weapon.def_ratio_atk_race |= 1<<val;
  2791. else if(sd->state.lr_flag == 1)
  2792. sd->left_weapon.def_ratio_atk_race |= 1<<val;
  2793. break;
  2794. case SP_DEF_RATIO_ATK_CLASS:
  2795. PC_BONUS_CHK_CLASS(val,SP_DEF_RATIO_ATK_CLASS);
  2796. if(!sd->state.lr_flag)
  2797. sd->right_weapon.def_ratio_atk_class |= 1<<val;
  2798. else if(sd->state.lr_flag == 1)
  2799. sd->left_weapon.def_ratio_atk_class |= 1<<val;
  2800. break;
  2801. case SP_HIT_RATE:
  2802. if(sd->state.lr_flag != 2)
  2803. sd->hit_rate += val;
  2804. break;
  2805. case SP_FLEE_RATE:
  2806. if(sd->state.lr_flag != 2)
  2807. sd->flee_rate += val;
  2808. break;
  2809. case SP_FLEE2_RATE:
  2810. if(sd->state.lr_flag != 2)
  2811. sd->flee2_rate += val;
  2812. break;
  2813. case SP_DEF_RATE:
  2814. if(sd->state.lr_flag != 2)
  2815. sd->def_rate += val;
  2816. break;
  2817. case SP_DEF2_RATE:
  2818. if(sd->state.lr_flag != 2)
  2819. sd->def2_rate += val;
  2820. break;
  2821. case SP_MDEF_RATE:
  2822. if(sd->state.lr_flag != 2)
  2823. sd->mdef_rate += val;
  2824. break;
  2825. case SP_MDEF2_RATE:
  2826. if(sd->state.lr_flag != 2)
  2827. sd->mdef2_rate += val;
  2828. break;
  2829. case SP_RESTART_FULL_RECOVER:
  2830. if(sd->state.lr_flag != 2)
  2831. sd->special_state.restart_full_recover = 1;
  2832. break;
  2833. case SP_NO_CASTCANCEL:
  2834. if(sd->state.lr_flag != 2)
  2835. sd->special_state.no_castcancel = 1;
  2836. break;
  2837. case SP_NO_CASTCANCEL2:
  2838. if(sd->state.lr_flag != 2)
  2839. sd->special_state.no_castcancel2 = 1;
  2840. break;
  2841. case SP_NO_SIZEFIX:
  2842. if(sd->state.lr_flag != 2)
  2843. sd->special_state.no_sizefix = 1;
  2844. break;
  2845. case SP_NO_MAGIC_DAMAGE:
  2846. if(sd->state.lr_flag == 2)
  2847. break;
  2848. val+= sd->special_state.no_magic_damage;
  2849. sd->special_state.no_magic_damage = cap_value(val,0,100);
  2850. break;
  2851. case SP_NO_WEAPON_DAMAGE:
  2852. if(sd->state.lr_flag == 2)
  2853. break;
  2854. val+= sd->special_state.no_weapon_damage;
  2855. sd->special_state.no_weapon_damage = cap_value(val,0,100);
  2856. break;
  2857. case SP_NO_MISC_DAMAGE:
  2858. if(sd->state.lr_flag == 2)
  2859. break;
  2860. val+= sd->special_state.no_misc_damage;
  2861. sd->special_state.no_misc_damage = cap_value(val,0,100);
  2862. break;
  2863. case SP_NO_GEMSTONE:
  2864. if(sd->state.lr_flag != 2 && sd->special_state.no_gemstone != 2)
  2865. sd->special_state.no_gemstone = 1;
  2866. break;
  2867. case SP_INTRAVISION: // Maya Purple Card effect allowing to see Hiding/Cloaking people [DracoRPG]
  2868. if(sd->state.lr_flag != 2) {
  2869. sd->special_state.intravision = 1;
  2870. clif_status_load(&sd->bl, EFST_CLAIRVOYANCE, 1);
  2871. }
  2872. break;
  2873. case SP_NO_KNOCKBACK:
  2874. if(sd->state.lr_flag != 2)
  2875. sd->special_state.no_knockback = 1;
  2876. break;
  2877. case SP_SPLASH_RANGE:
  2878. if(sd->bonus.splash_range < val)
  2879. sd->bonus.splash_range = val;
  2880. break;
  2881. case SP_SPLASH_ADD_RANGE:
  2882. sd->bonus.splash_add_range += val;
  2883. break;
  2884. case SP_SHORT_WEAPON_DAMAGE_RETURN:
  2885. if(sd->state.lr_flag != 2)
  2886. sd->bonus.short_weapon_damage_return += val;
  2887. break;
  2888. case SP_LONG_WEAPON_DAMAGE_RETURN:
  2889. if(sd->state.lr_flag != 2)
  2890. sd->bonus.long_weapon_damage_return += val;
  2891. break;
  2892. case SP_MAGIC_DAMAGE_RETURN: //AppleGirl Was Here
  2893. if(sd->state.lr_flag != 2)
  2894. sd->bonus.magic_damage_return += val;
  2895. break;
  2896. case SP_ALL_STATS: // [Valaris]
  2897. if(sd->state.lr_flag!=2) {
  2898. sd->param_bonus[SP_STR-SP_STR]+=val;
  2899. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2900. sd->param_bonus[SP_VIT-SP_STR]+=val;
  2901. sd->param_bonus[SP_INT-SP_STR]+=val;
  2902. sd->param_bonus[SP_DEX-SP_STR]+=val;
  2903. sd->param_bonus[SP_LUK-SP_STR]+=val;
  2904. }
  2905. break;
  2906. case SP_AGI_VIT: // [Valaris]
  2907. if(sd->state.lr_flag!=2) {
  2908. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2909. sd->param_bonus[SP_VIT-SP_STR]+=val;
  2910. }
  2911. break;
  2912. case SP_AGI_DEX_STR: // [Valaris]
  2913. if(sd->state.lr_flag!=2) {
  2914. sd->param_bonus[SP_AGI-SP_STR]+=val;
  2915. sd->param_bonus[SP_DEX-SP_STR]+=val;
  2916. sd->param_bonus[SP_STR-SP_STR]+=val;
  2917. }
  2918. break;
  2919. case SP_PERFECT_HIDE: // [Valaris]
  2920. if(sd->state.lr_flag!=2)
  2921. sd->special_state.perfect_hiding=1;
  2922. break;
  2923. case SP_UNBREAKABLE:
  2924. if(sd->state.lr_flag!=2)
  2925. sd->bonus.unbreakable += val;
  2926. break;
  2927. case SP_UNBREAKABLE_WEAPON:
  2928. if(sd->state.lr_flag != 2)
  2929. sd->bonus.unbreakable_equip |= EQP_WEAPON;
  2930. break;
  2931. case SP_UNBREAKABLE_ARMOR:
  2932. if(sd->state.lr_flag != 2)
  2933. sd->bonus.unbreakable_equip |= EQP_ARMOR;
  2934. break;
  2935. case SP_UNBREAKABLE_HELM:
  2936. if(sd->state.lr_flag != 2)
  2937. sd->bonus.unbreakable_equip |= EQP_HELM;
  2938. break;
  2939. case SP_UNBREAKABLE_SHIELD:
  2940. if(sd->state.lr_flag != 2)
  2941. sd->bonus.unbreakable_equip |= EQP_SHIELD;
  2942. break;
  2943. case SP_UNBREAKABLE_GARMENT:
  2944. if(sd->state.lr_flag != 2)
  2945. sd->bonus.unbreakable_equip |= EQP_GARMENT;
  2946. break;
  2947. case SP_UNBREAKABLE_SHOES:
  2948. if(sd->state.lr_flag != 2)
  2949. sd->bonus.unbreakable_equip |= EQP_SHOES;
  2950. break;
  2951. case SP_CLASSCHANGE: // [Valaris]
  2952. if(sd->state.lr_flag !=2)
  2953. sd->bonus.classchange=val;
  2954. break;
  2955. case SP_LONG_ATK_RATE:
  2956. if(sd->state.lr_flag != 2) //[Lupus] it should stack, too. As any other cards rate bonuses
  2957. sd->bonus.long_attack_atk_rate+=val;
  2958. break;
  2959. case SP_BREAK_WEAPON_RATE:
  2960. if(sd->state.lr_flag != 2)
  2961. sd->bonus.break_weapon_rate+=val;
  2962. break;
  2963. case SP_BREAK_ARMOR_RATE:
  2964. if(sd->state.lr_flag != 2)
  2965. sd->bonus.break_armor_rate+=val;
  2966. break;
  2967. case SP_ADD_STEAL_RATE:
  2968. if(sd->state.lr_flag != 2)
  2969. sd->bonus.add_steal_rate+=val;
  2970. break;
  2971. case SP_DELAYRATE:
  2972. if(sd->state.lr_flag != 2)
  2973. sd->delayrate+=val;
  2974. break;
  2975. case SP_CRIT_ATK_RATE:
  2976. if(sd->state.lr_flag != 2)
  2977. sd->bonus.crit_atk_rate += val;
  2978. break;
  2979. case SP_NO_REGEN:
  2980. if(sd->state.lr_flag != 2)
  2981. sd->regen.state.block|=val;
  2982. break;
  2983. case SP_UNSTRIPABLE_WEAPON:
  2984. if(sd->state.lr_flag != 2)
  2985. sd->bonus.unstripable_equip |= EQP_WEAPON;
  2986. break;
  2987. case SP_UNSTRIPABLE:
  2988. case SP_UNSTRIPABLE_ARMOR:
  2989. if(sd->state.lr_flag != 2)
  2990. sd->bonus.unstripable_equip |= EQP_ARMOR;
  2991. break;
  2992. case SP_UNSTRIPABLE_HELM:
  2993. if(sd->state.lr_flag != 2)
  2994. sd->bonus.unstripable_equip |= EQP_HELM;
  2995. break;
  2996. case SP_UNSTRIPABLE_SHIELD:
  2997. if(sd->state.lr_flag != 2)
  2998. sd->bonus.unstripable_equip |= EQP_SHIELD;
  2999. break;
  3000. case SP_HP_DRAIN_VALUE: // bonus bHPDrainValue,n;
  3001. if(!sd->state.lr_flag) {
  3002. sd->right_weapon.hp_drain_class[CLASS_NORMAL] += val;
  3003. sd->right_weapon.hp_drain_class[CLASS_BOSS] += val;
  3004. } else if(sd->state.lr_flag == 1) {
  3005. sd->left_weapon.hp_drain_class[CLASS_NORMAL] += val;
  3006. sd->left_weapon.hp_drain_class[CLASS_BOSS] += val;
  3007. }
  3008. break;
  3009. case SP_SP_DRAIN_VALUE: // bonus bSPDrainValue,n;
  3010. if(!sd->state.lr_flag) {
  3011. sd->right_weapon.sp_drain_class[CLASS_NORMAL] += val;
  3012. sd->right_weapon.sp_drain_class[CLASS_BOSS] += val;
  3013. } else if(sd->state.lr_flag == 1) {
  3014. sd->left_weapon.sp_drain_class[CLASS_NORMAL] += val;
  3015. sd->left_weapon.sp_drain_class[CLASS_BOSS] += val;
  3016. }
  3017. break;
  3018. case SP_SP_GAIN_VALUE:
  3019. if(!sd->state.lr_flag)
  3020. sd->bonus.sp_gain_value += val;
  3021. break;
  3022. case SP_HP_GAIN_VALUE:
  3023. if(!sd->state.lr_flag)
  3024. sd->bonus.hp_gain_value += val;
  3025. break;
  3026. case SP_LONG_SP_GAIN_VALUE:
  3027. if(!sd->state.lr_flag)
  3028. sd->bonus.long_sp_gain_value += val;
  3029. case SP_LONG_HP_GAIN_VALUE:
  3030. if(!sd->state.lr_flag)
  3031. sd->bonus.long_hp_gain_value += val;
  3032. break;
  3033. case SP_MAGIC_SP_GAIN_VALUE:
  3034. if(!sd->state.lr_flag)
  3035. sd->bonus.magic_sp_gain_value += val;
  3036. break;
  3037. case SP_MAGIC_HP_GAIN_VALUE:
  3038. if(!sd->state.lr_flag)
  3039. sd->bonus.magic_hp_gain_value += val;
  3040. break;
  3041. case SP_ADD_HEAL_RATE:
  3042. if(sd->state.lr_flag != 2)
  3043. sd->bonus.add_heal_rate += val;
  3044. break;
  3045. case SP_ADD_HEAL2_RATE:
  3046. if(sd->state.lr_flag != 2)
  3047. sd->bonus.add_heal2_rate += val;
  3048. break;
  3049. case SP_ADD_ITEM_HEAL_RATE:
  3050. if(sd->state.lr_flag != 2)
  3051. sd->bonus.itemhealrate2 += val;
  3052. break;
  3053. case SP_EMATK:
  3054. if(sd->state.lr_flag != 2)
  3055. sd->bonus.ematk += val;
  3056. break;
  3057. case SP_ADD_VARIABLECAST:
  3058. if (sd->state.lr_flag != 2)
  3059. sd->bonus.add_varcast += val;
  3060. break;
  3061. #ifdef RENEWAL_CAST
  3062. case SP_FIXCASTRATE:
  3063. if(sd->state.lr_flag != 2)
  3064. sd->bonus.fixcastrate = min(sd->bonus.fixcastrate,val);
  3065. break;
  3066. case SP_ADD_FIXEDCAST:
  3067. if(sd->state.lr_flag != 2)
  3068. sd->bonus.add_fixcast += val;
  3069. break;
  3070. case SP_CASTRATE:
  3071. case SP_VARCASTRATE:
  3072. if(sd->state.lr_flag != 2)
  3073. sd->bonus.varcastrate -= val;
  3074. break;
  3075. #else
  3076. case SP_ADD_FIXEDCAST:
  3077. case SP_FIXCASTRATE:
  3078. //ShowWarning("pc_bonus: non-RENEWAL_CAST doesn't support this bonus %d.\n", type);
  3079. break;
  3080. case SP_VARCASTRATE:
  3081. case SP_CASTRATE:
  3082. if(sd->state.lr_flag != 2)
  3083. sd->castrate += val;
  3084. break;
  3085. #endif
  3086. case SP_ADDMAXWEIGHT:
  3087. if (sd->state.lr_flag != 2)
  3088. sd->add_max_weight += val;
  3089. break;
  3090. case SP_ABSORB_DMG_MAXHP: // bonus bAbsorbDmgMaxHP,n;
  3091. sd->bonus.absorb_dmg_maxhp = max(sd->bonus.absorb_dmg_maxhp, val);
  3092. break;
  3093. case SP_CRITICAL_RANGEATK: // bonus bCriticalLong,n;
  3094. if (sd->state.lr_flag != 2)
  3095. sd->bonus.critical_rangeatk += val*10;
  3096. else
  3097. sd->bonus.arrow_cri += val*10;
  3098. break;
  3099. case SP_WEAPON_ATK_RATE:
  3100. if (sd->state.lr_flag != 2)
  3101. sd->bonus.weapon_atk_rate += val;
  3102. break;
  3103. case SP_WEAPON_MATK_RATE:
  3104. if (sd->state.lr_flag != 2)
  3105. sd->bonus.weapon_matk_rate += val;
  3106. break;
  3107. case SP_NO_MADO_FUEL:
  3108. if (sd->state.lr_flag != 2)
  3109. sd->special_state.no_mado_fuel = 1;
  3110. break;
  3111. case SP_NO_WALK_DELAY:
  3112. if (sd->state.lr_flag != 2)
  3113. sd->special_state.no_walk_delay = 1;
  3114. break;
  3115. default:
  3116. if (current_equip_combo_pos > 0) {
  3117. ShowWarning("pc_bonus: unknown bonus type %d %d in a combo with item #%d\n", type, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid);
  3118. }
  3119. else if (current_equip_card_id > 0 || current_equip_item_index > 0) {
  3120. ShowWarning("pc_bonus: unknown bonus type %d %d in item #%d\n", type, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid);
  3121. }
  3122. else {
  3123. ShowWarning("pc_bonus: unknown bonus type %d %d in unknown usage. Report this!\n", type, val);
  3124. }
  3125. break;
  3126. }
  3127. }
  3128. /*==========================================
  3129. * Player bonus (type) with args type2 and val, called trough bonus2 (npc)
  3130. * format: bonus2 bBonusName,type2,val;
  3131. * @param sd
  3132. * @param type Bonus type used by bBonusName
  3133. * @param type2
  3134. * @param val Value that usually for rate or fixed value
  3135. *------------------------------------------*/
  3136. void pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
  3137. {
  3138. nullpo_retv(sd);
  3139. switch(type){
  3140. case SP_ADDELE: // bonus2 bAddEle,e,x;
  3141. PC_BONUS_CHK_ELEMENT(type2,SP_ADDELE);
  3142. if(!sd->state.lr_flag || sd->state.lr_flag == 3)
  3143. sd->right_weapon.addele[type2]+=val;
  3144. else if(sd->state.lr_flag == 1)
  3145. sd->left_weapon.addele[type2]+=val;
  3146. else if(sd->state.lr_flag == 2)
  3147. sd->arrow_addele[type2]+=val;
  3148. break;
  3149. case SP_ADDRACE: // bonus2 bAddRace,r,x;
  3150. PC_BONUS_CHK_RACE(type2,SP_ADDRACE);
  3151. if(!sd->state.lr_flag || sd->state.lr_flag == 3)
  3152. sd->right_weapon.addrace[type2]+=val;
  3153. else if(sd->state.lr_flag == 1)
  3154. sd->left_weapon.addrace[type2]+=val;
  3155. else if(sd->state.lr_flag == 2)
  3156. sd->arrow_addrace[type2]+=val;
  3157. break;
  3158. case SP_ADDCLASS: // bonus2 bAddClass,c,x;
  3159. PC_BONUS_CHK_CLASS(type2,SP_ADDCLASS);
  3160. if(!sd->state.lr_flag || sd->state.lr_flag == 3)
  3161. sd->right_weapon.addclass[type2]+=val;
  3162. else if(sd->state.lr_flag == 1)
  3163. sd->left_weapon.addclass[type2]+=val;
  3164. else if(sd->state.lr_flag == 2)
  3165. sd->arrow_addclass[type2]+=val;
  3166. break;
  3167. case SP_ADDSIZE: // bonus2 bAddSize,s,x;
  3168. PC_BONUS_CHK_SIZE(type2,SP_ADDSIZE);
  3169. if(!sd->state.lr_flag || sd->state.lr_flag == 3)
  3170. sd->right_weapon.addsize[type2]+=val;
  3171. else if(sd->state.lr_flag == 1)
  3172. sd->left_weapon.addsize[type2]+=val;
  3173. else if(sd->state.lr_flag == 2)
  3174. sd->arrow_addsize[type2]+=val;
  3175. break;
  3176. case SP_SUBELE: // bonus2 bSubEle,e,x;
  3177. PC_BONUS_CHK_ELEMENT(type2,SP_SUBELE);
  3178. if(sd->state.lr_flag != 2)
  3179. sd->subele_script[type2] += val;
  3180. break;
  3181. case SP_SUBRACE: // bonus2 bSubRace,r,x;
  3182. PC_BONUS_CHK_RACE(type2,SP_SUBRACE);
  3183. if(sd->state.lr_flag != 2)
  3184. sd->subrace[type2]+=val;
  3185. break;
  3186. case SP_SUBCLASS: // bonus2 bSubClass,c,x;
  3187. PC_BONUS_CHK_CLASS(type2,SP_SUBCLASS);
  3188. if(sd->state.lr_flag != 2)
  3189. sd->subclass[type2]+=val;
  3190. break;
  3191. case SP_ADDEFF: // bonus2 bAddEff,eff,n;
  3192. PC_BONUS_CHK_SC(type2,SP_ADDEFF);
  3193. pc_bonus_addeff(sd->addeff, (sc_type)type2, sd->state.lr_flag != 2 ? val : 0, sd->state.lr_flag == 2 ? val : 0, 0, 0);
  3194. break;
  3195. case SP_ADDEFF2: // bonus2 bAddEff2,eff,n;
  3196. PC_BONUS_CHK_SC(type2,SP_ADDEFF2);
  3197. pc_bonus_addeff(sd->addeff, (sc_type)type2, sd->state.lr_flag != 2 ? val : 0, sd->state.lr_flag == 2 ? val : 0, ATF_SELF, 0);
  3198. break;
  3199. case SP_RESEFF: // bonus2 bResEff,eff,n;
  3200. if(sd->state.lr_flag == 2)
  3201. break;
  3202. if (sd->reseff.size() == MAX_PC_BONUS) {
  3203. ShowWarning("pc_bonus2: SP_RESEFF: Reached max (%d) number of resistance bonuses per character!\n", MAX_PC_BONUS);
  3204. break;
  3205. }
  3206. pc_bonus_itembonus(sd->reseff, type2, val, true);
  3207. break;
  3208. case SP_MAGIC_ADDELE: // bonus2 bMagicAddEle,e,x;
  3209. PC_BONUS_CHK_ELEMENT(type2,SP_MAGIC_ADDELE);
  3210. if(sd->state.lr_flag != 2)
  3211. sd->magic_addele_script[type2] += val;
  3212. break;
  3213. case SP_MAGIC_ADDRACE: // bonus2 bMagicAddRace,r,x;
  3214. PC_BONUS_CHK_RACE(type2,SP_MAGIC_ADDRACE);
  3215. if(sd->state.lr_flag != 2)
  3216. sd->magic_addrace[type2]+=val;
  3217. break;
  3218. case SP_MAGIC_ADDCLASS: // bonus2 bMagicAddClass,c,x;
  3219. PC_BONUS_CHK_CLASS(type2,SP_MAGIC_ADDCLASS);
  3220. if(sd->state.lr_flag != 2)
  3221. sd->magic_addclass[type2]+=val;
  3222. break;
  3223. case SP_MAGIC_ADDSIZE: // bonus2 bMagicAddSize,s,x;
  3224. PC_BONUS_CHK_SIZE(type2,SP_MAGIC_ADDSIZE);
  3225. if(sd->state.lr_flag != 2)
  3226. sd->magic_addsize[type2]+=val;
  3227. break;
  3228. case SP_MAGIC_ATK_ELE: // bonus2 bMagicAtkEle,e,x;
  3229. PC_BONUS_CHK_ELEMENT(type2,SP_MAGIC_ATK_ELE);
  3230. if(sd->state.lr_flag != 2)
  3231. sd->magic_atk_ele[type2]+=val;
  3232. break;
  3233. case SP_ADD_DAMAGE_CLASS: { // bonus2 bAddDamageClass,mid,x;
  3234. struct weapon_data *wd = (sd->state.lr_flag ? &sd->left_weapon : &sd->right_weapon);
  3235. if (wd->add_dmg.size() == MAX_PC_BONUS) {
  3236. ShowWarning("pc_bonus2: SP_ADD_DAMAGE_CLASS: Reached max (%d) number of add class damage bonuses per character!\n", MAX_PC_BONUS);
  3237. break;
  3238. }
  3239. pc_bonus_itembonus(wd->add_dmg, type2, val, false);
  3240. }
  3241. break;
  3242. case SP_ADD_MAGIC_DAMAGE_CLASS: // bonus2 bAddMagicDamageClass,mid,x;
  3243. if(sd->state.lr_flag == 2)
  3244. break;
  3245. if (sd->add_mdmg.size() == MAX_PC_BONUS) {
  3246. ShowWarning("pc_bonus2: SP_ADD_MAGIC_DAMAGE_CLASS: Reached max (%d) number of add class magic dmg bonuses per character!\n", MAX_PC_BONUS);
  3247. break;
  3248. }
  3249. pc_bonus_itembonus(sd->add_mdmg, type2, val, false);
  3250. break;
  3251. case SP_ADD_DEF_MONSTER: // bonus2 bAddDefMonster,mid,x;
  3252. if(sd->state.lr_flag == 2)
  3253. break;
  3254. if (sd->add_def.size() == MAX_PC_BONUS) {
  3255. ShowWarning("pc_bonus2: SP_ADD_DEF_MONSTER: Reached max (%d) number of add class def bonuses per character!\n", MAX_PC_BONUS);
  3256. break;
  3257. }
  3258. pc_bonus_itembonus(sd->add_def, type2, val, false);
  3259. break;
  3260. case SP_ADD_MDEF_MONSTER: // bonus2 bAddMDefMonster,mid,x;
  3261. if(sd->state.lr_flag == 2)
  3262. break;
  3263. if (sd->add_mdef.size() == MAX_PC_BONUS) {
  3264. ShowWarning("pc_bonus2: SP_ADD_MDEF_MONSTER: Reached max (%d) number of add class mdef bonuses per character!\n", MAX_PC_BONUS);
  3265. break;
  3266. }
  3267. pc_bonus_itembonus(sd->add_mdef, type2, val, false);
  3268. break;
  3269. case SP_HP_DRAIN_RATE: // bonus2 bHPDrainRate,x,n;
  3270. if(!sd->state.lr_flag) {
  3271. sd->right_weapon.hp_drain_rate.rate += type2;
  3272. sd->right_weapon.hp_drain_rate.per += val;
  3273. }
  3274. else if(sd->state.lr_flag == 1) {
  3275. sd->left_weapon.hp_drain_rate.rate += type2;
  3276. sd->left_weapon.hp_drain_rate.per += val;
  3277. }
  3278. break;
  3279. case SP_SP_DRAIN_RATE: // bonus2 bSPDrainRate,x,n;
  3280. if(!sd->state.lr_flag) {
  3281. sd->right_weapon.sp_drain_rate.rate += type2;
  3282. sd->right_weapon.sp_drain_rate.per += val;
  3283. }
  3284. else if(sd->state.lr_flag == 1) {
  3285. sd->left_weapon.sp_drain_rate.rate += type2;
  3286. sd->left_weapon.sp_drain_rate.per += val;
  3287. }
  3288. break;
  3289. case SP_SP_VANISH_RATE: // bonus2 bSPVanishRate,x,n;
  3290. if(sd->state.lr_flag != 2) {
  3291. pc_bonus_addvanish(sd->sp_vanish, type2, val, BF_NORMAL);
  3292. }
  3293. break;
  3294. case SP_HP_VANISH_RATE: // bonus2 bHPVanishRate,x,n;
  3295. if(sd->state.lr_flag != 2) {
  3296. pc_bonus_addvanish(sd->hp_vanish, type2, val, BF_NORMAL);
  3297. }
  3298. break;
  3299. case SP_GET_ZENY_NUM: // bonus2 bGetZenyNum,x,n;
  3300. if(sd->state.lr_flag != 2 && sd->bonus.get_zeny_rate < val) {
  3301. sd->bonus.get_zeny_rate = val;
  3302. sd->bonus.get_zeny_num = type2;
  3303. }
  3304. break;
  3305. case SP_ADD_GET_ZENY_NUM: // bonus2 bAddGetZenyNum,x,n;
  3306. if(sd->state.lr_flag != 2) {
  3307. sd->bonus.get_zeny_rate += val;
  3308. sd->bonus.get_zeny_num += type2;
  3309. }
  3310. break;
  3311. case SP_WEAPON_COMA_ELE: // bonus2 bWeaponComaEle,e,n;
  3312. PC_BONUS_CHK_ELEMENT(type2,SP_WEAPON_COMA_ELE);
  3313. if(sd->state.lr_flag == 2)
  3314. break;
  3315. sd->weapon_coma_ele[type2] += val;
  3316. sd->special_state.bonus_coma = 1;
  3317. break;
  3318. case SP_WEAPON_COMA_RACE: // bonus2 bWeaponComaRace,r,n;
  3319. PC_BONUS_CHK_RACE(type2,SP_WEAPON_COMA_RACE);
  3320. if(sd->state.lr_flag == 2)
  3321. break;
  3322. sd->weapon_coma_race[type2] += val;
  3323. sd->special_state.bonus_coma = 1;
  3324. break;
  3325. case SP_WEAPON_COMA_CLASS: // bonus2 bWeaponComaClass,c,n;
  3326. PC_BONUS_CHK_CLASS(type2,SP_WEAPON_COMA_CLASS);
  3327. if(sd->state.lr_flag == 2)
  3328. break;
  3329. sd->weapon_coma_class[type2] += val;
  3330. sd->special_state.bonus_coma = 1;
  3331. break;
  3332. case SP_WEAPON_ATK: // bonus2 bWeaponAtk,w,n;
  3333. if(sd->state.lr_flag != 2)
  3334. sd->weapon_atk[type2]+=val;
  3335. break;
  3336. case SP_WEAPON_DAMAGE_RATE: // bonus2 bWeaponDamageRate,w,n;
  3337. if(sd->state.lr_flag != 2)
  3338. sd->weapon_damage_rate[type2]+=val;
  3339. break;
  3340. case SP_CRITICAL_ADDRACE: // bonus2 bCriticalAddRace,r,n;
  3341. PC_BONUS_CHK_RACE(type2,SP_CRITICAL_ADDRACE);
  3342. if(sd->state.lr_flag != 2)
  3343. sd->critaddrace[type2] += val*10;
  3344. break;
  3345. case SP_ADDEFF_WHENHIT: // bonus2 bAddEffWhenHit,eff,n;
  3346. PC_BONUS_CHK_SC(type2,SP_ADDEFF_WHENHIT);
  3347. if(sd->state.lr_flag != 2)
  3348. pc_bonus_addeff(sd->addeff_atked, (sc_type)type2, val, 0, 0, 0);
  3349. break;
  3350. case SP_SKILL_ATK: // bonus2 bSkillAtk,sk,n;
  3351. if(sd->state.lr_flag == 2)
  3352. break;
  3353. if (sd->skillatk.size() == MAX_PC_BONUS) {
  3354. ShowWarning("pc_bonus2: SP_SKILL_ATK: Reached max (%d) number of skills per character, bonus skill %d (+%d%%) lost.\n", MAX_PC_BONUS, type2, val);
  3355. break;
  3356. }
  3357. pc_bonus_itembonus(sd->skillatk, type2, val, false);
  3358. break;
  3359. case SP_SKILL_HEAL: // bonus2 bSkillHeal,sk,n;
  3360. if(sd->state.lr_flag == 2)
  3361. break;
  3362. if (sd->skillheal.size() == MAX_PC_BONUS) { // Better mention this so the array length can be updated. [Skotlex]
  3363. ShowWarning("pc_bonus2: SP_SKILL_HEAL: Reached max (%d) number of skills per character, bonus skill %d (+%d%%) lost.\n", MAX_PC_BONUS, type2, val);
  3364. break;
  3365. }
  3366. pc_bonus_itembonus(sd->skillheal, type2, val, false);
  3367. break;
  3368. case SP_SKILL_HEAL2: // bonus2 bSkillHeal2,sk,n;
  3369. if(sd->state.lr_flag == 2)
  3370. break;
  3371. if (sd->skillheal2.size() == MAX_PC_BONUS) { // Better mention this so the array length can be updated. [Skotlex]
  3372. ShowWarning("pc_bonus2: SP_SKILL_HEAL2: Reached max (%d) number of skills per character, bonus skill %d (+%d%%) lost.\n", MAX_PC_BONUS, type2, val);
  3373. break;
  3374. }
  3375. pc_bonus_itembonus(sd->skillheal2, type2, val, false);
  3376. break;
  3377. case SP_ADD_SKILL_BLOW: // bonus2 bAddSkillBlow,sk,n;
  3378. if(sd->state.lr_flag == 2)
  3379. break;
  3380. if (sd->skillblown.size() == MAX_PC_BONUS) { //Better mention this so the array length can be updated. [Skotlex]
  3381. ShowWarning("pc_bonus2: SP_ADD_SKILL_BLOW: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", MAX_PC_BONUS, type2, val);
  3382. break;
  3383. }
  3384. pc_bonus_itembonus(sd->skillblown, type2, val, false);
  3385. break;
  3386. case SP_HP_LOSS_RATE: // bonus2 bHPLossRate,n,t;
  3387. if(sd->state.lr_flag != 2) {
  3388. sd->hp_loss.value = type2;
  3389. sd->hp_loss.rate = val;
  3390. }
  3391. break;
  3392. case SP_HP_REGEN_RATE: // bonus2 bHPRegenRate,n,t;
  3393. if(sd->state.lr_flag != 2) {
  3394. sd->hp_regen.value = type2;
  3395. sd->hp_regen.rate = val;
  3396. }
  3397. break;
  3398. case SP_REGEN_PERCENT_HP: // bonus2 bRegenPercentHP,n,t;
  3399. if (sd->state.lr_flag != 2) {
  3400. sd->percent_hp_regen.value = type2;
  3401. sd->percent_hp_regen.rate = val;
  3402. }
  3403. break;
  3404. case SP_REGEN_PERCENT_SP: // bonus2 bRegenPercentSP,n,t;
  3405. if (sd->state.lr_flag != 2) {
  3406. sd->percent_sp_regen.value = type2;
  3407. sd->percent_sp_regen.rate = val;
  3408. }
  3409. break;
  3410. case SP_ADDRACE2: // bonus2 bAddRace2,mr,x;
  3411. PC_BONUS_CHK_RACE2(type2,SP_ADDRACE2);
  3412. if(sd->state.lr_flag != 2)
  3413. sd->right_weapon.addrace2[type2] += val;
  3414. else
  3415. sd->left_weapon.addrace2[type2] += val;
  3416. break;
  3417. case SP_SUBSIZE: // bonus2 bSubSize,s,x;
  3418. PC_BONUS_CHK_SIZE(type2,SP_SUBSIZE);
  3419. if(sd->state.lr_flag != 2)
  3420. sd->subsize[type2]+=val;
  3421. break;
  3422. case SP_SUBRACE2: // bonus2 bSubRace2,mr,x;
  3423. PC_BONUS_CHK_RACE2(type2,SP_SUBRACE2);
  3424. if(sd->state.lr_flag != 2)
  3425. sd->subrace2[type2]+=val;
  3426. break;
  3427. case SP_ADD_ITEM_HEAL_RATE: // bonus2 bAddItemHealRate,iid,n;
  3428. if(sd->state.lr_flag == 2)
  3429. break;
  3430. if (!itemdb_exists(type2)) {
  3431. ShowWarning("pc_bonus2: SP_ADD_ITEM_HEAL_RATE Invalid item with id %d\n", type2);
  3432. break;
  3433. }
  3434. if (sd->itemhealrate.size() == MAX_PC_BONUS) {
  3435. ShowWarning("pc_bonus2: SP_ADD_ITEM_HEAL_RATE: Reached max (%d) number of item heal bonuses per character!\n", MAX_PC_BONUS);
  3436. break;
  3437. }
  3438. pc_bonus_itembonus(sd->itemhealrate, type2, val, false);
  3439. break;
  3440. case SP_ADD_ITEMGROUP_HEAL_RATE: // bonus2 bAddItemGroupHealRate,ig,n;
  3441. if (sd->state.lr_flag == 2)
  3442. break;
  3443. if (!type2 || !itemdb_group_exists(type2)) {
  3444. ShowWarning("pc_bonus2: SP_ADD_ITEMGROUP_HEAL_RATE: Invalid item group with id %d\n", type2);
  3445. break;
  3446. }
  3447. if (sd->itemhealrate.size() == MAX_PC_BONUS) {
  3448. ShowWarning("pc_bonus2: SP_ADD_ITEMGROUP_HEAL_RATE: Reached max (%d) number of item heal bonuses per character!\n", MAX_PC_BONUS);
  3449. break;
  3450. }
  3451. pc_bonus_itembonus(sd->itemgrouphealrate, type2, val, false);
  3452. break;
  3453. case SP_EXP_ADDRACE: // bonus2 bExpAddRace,r,x;
  3454. PC_BONUS_CHK_RACE(type2,SP_EXP_ADDRACE);
  3455. if(sd->state.lr_flag != 2)
  3456. sd->expaddrace[type2]+=val;
  3457. break;
  3458. case SP_EXP_ADDCLASS: // bonus2 bExpAddClass,c,x;
  3459. PC_BONUS_CHK_CLASS(type2,SP_EXP_ADDCLASS);
  3460. if(sd->state.lr_flag != 2)
  3461. sd->expaddclass[type2]+=val;
  3462. break;
  3463. case SP_SP_GAIN_RACE: // bonus2 bSPGainRace,r,n;
  3464. PC_BONUS_CHK_RACE(type2,SP_SP_GAIN_RACE);
  3465. if(sd->state.lr_flag != 2)
  3466. sd->sp_gain_race[type2]+=val;
  3467. break;
  3468. case SP_ADD_MONSTER_DROP_ITEM: // bonus2 bAddMonsterDropItem,iid,n;
  3469. if (sd->state.lr_flag != 2)
  3470. pc_bonus_item_drop(sd->add_drop, type2, 0, CLASS_ALL, RC_NONE_, val);
  3471. break;
  3472. case SP_ADD_MONSTER_DROP_ITEMGROUP: // bonus2 bAddMonsterDropItemGroup,ig,n;
  3473. if (sd->state.lr_flag != 2)
  3474. pc_bonus_item_drop(sd->add_drop, 0, type2, CLASS_ALL, RC_NONE_, val);
  3475. break;
  3476. case SP_SP_LOSS_RATE: // bonus2 bSPLossRate,n,t;
  3477. if(sd->state.lr_flag != 2) {
  3478. sd->sp_loss.value = type2;
  3479. sd->sp_loss.rate = val;
  3480. }
  3481. break;
  3482. case SP_SP_REGEN_RATE: // bonus2 bSPRegenRate,n,t;
  3483. if(sd->state.lr_flag != 2) {
  3484. sd->sp_regen.value = type2;
  3485. sd->sp_regen.rate = val;
  3486. }
  3487. break;
  3488. case SP_HP_DRAIN_VALUE_RACE: // bonus2 bHPDrainValueRace,r,n;
  3489. PC_BONUS_CHK_RACE(type2,SP_HP_DRAIN_VALUE_RACE);
  3490. if(!sd->state.lr_flag) {
  3491. sd->right_weapon.hp_drain_race[type2] += val;
  3492. }
  3493. else if(sd->state.lr_flag == 1) {
  3494. sd->left_weapon.hp_drain_race[type2] += val;
  3495. }
  3496. break;
  3497. case SP_SP_DRAIN_VALUE_RACE: // bonus2 bSPDrainValueRace,r,n;
  3498. PC_BONUS_CHK_RACE(type2,SP_SP_DRAIN_VALUE_RACE);
  3499. if(!sd->state.lr_flag) {
  3500. sd->right_weapon.sp_drain_race[type2] += val;
  3501. }
  3502. else if(sd->state.lr_flag == 1) {
  3503. sd->left_weapon.sp_drain_race[type2] += val;
  3504. }
  3505. break;
  3506. case SP_HP_DRAIN_VALUE_CLASS: // bonus2 bHPDrainValueClass,c,n;
  3507. PC_BONUS_CHK_CLASS(type2,SP_HP_DRAIN_VALUE_CLASS);
  3508. if(!sd->state.lr_flag) {
  3509. sd->right_weapon.hp_drain_class[type2] += val;
  3510. }
  3511. else if(sd->state.lr_flag == 1) {
  3512. sd->left_weapon.hp_drain_class[type2] += val;
  3513. }
  3514. break;
  3515. case SP_SP_DRAIN_VALUE_CLASS: // bonus2 bSPDrainValueClass,c,n;
  3516. PC_BONUS_CHK_CLASS(type2,SP_SP_DRAIN_VALUE_CLASS);
  3517. if(!sd->state.lr_flag) {
  3518. sd->right_weapon.sp_drain_class[type2] += val;
  3519. }
  3520. else if(sd->state.lr_flag == 1) {
  3521. sd->left_weapon.sp_drain_class[type2] += val;
  3522. }
  3523. break;
  3524. case SP_IGNORE_MDEF_RACE_RATE: // bonus2 bIgnoreMdefRaceRate,r,n;
  3525. PC_BONUS_CHK_RACE(type2,SP_IGNORE_MDEF_RACE_RATE);
  3526. if(sd->state.lr_flag != 2)
  3527. sd->ignore_mdef_by_race[type2] += val;
  3528. break;
  3529. case SP_IGNORE_MDEF_CLASS_RATE: // bonus2 bIgnoreMdefClassRate,c,n;
  3530. PC_BONUS_CHK_CLASS(type2,SP_IGNORE_MDEF_CLASS_RATE);
  3531. if(sd->state.lr_flag != 2)
  3532. sd->ignore_mdef_by_class[type2] += val;
  3533. break;
  3534. case SP_IGNORE_DEF_RACE_RATE: // bonus2 bIgnoreDefRaceRate,r,n;
  3535. PC_BONUS_CHK_RACE(type2,SP_IGNORE_DEF_RACE_RATE);
  3536. if(sd->state.lr_flag != 2)
  3537. sd->ignore_def_by_race[type2] += val;
  3538. break;
  3539. case SP_IGNORE_DEF_CLASS_RATE: // bonus2 bIgnoreDefClassRate,r,n;
  3540. PC_BONUS_CHK_CLASS(type2, SP_IGNORE_DEF_CLASS_RATE);
  3541. if (sd->state.lr_flag != 2)
  3542. sd->ignore_def_by_class[type2] += val;
  3543. break;
  3544. case SP_SKILL_USE_SP_RATE: // bonus2 bSkillUseSPrate,sk,n;
  3545. if(sd->state.lr_flag == 2)
  3546. break;
  3547. if (sd->skillusesprate.size() == MAX_PC_BONUS) {
  3548. ShowWarning("pc_bonus2: SP_SKILL_USE_SP_RATE: Reached max (%d) number of skills per character, bonus skill %d (+%d%%) lost.\n", MAX_PC_BONUS, type2, val);
  3549. break;
  3550. }
  3551. pc_bonus_itembonus(sd->skillusesprate, type2, val, true);
  3552. break;
  3553. case SP_SKILL_DELAY:
  3554. if(sd->state.lr_flag == 2)
  3555. break;
  3556. if (sd->skilldelay.size() == MAX_PC_BONUS) {
  3557. ShowWarning("pc_bonus2: SP_SKILL_DELAY: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", MAX_PC_BONUS, type2, val);
  3558. break;
  3559. }
  3560. pc_bonus_itembonus(sd->skilldelay, type2, val, false);
  3561. break;
  3562. case SP_SKILL_COOLDOWN: // bonus2 bSkillCooldown,sk,t;
  3563. if(sd->state.lr_flag == 2)
  3564. break;
  3565. if (sd->skillcooldown.size() == MAX_PC_BONUS) {
  3566. ShowWarning("pc_bonus2: SP_SKILL_COOLDOWN: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", MAX_PC_BONUS, type2, val);
  3567. break;
  3568. }
  3569. pc_bonus_itembonus(sd->skillcooldown, type2, val, false);
  3570. break;
  3571. case SP_SKILL_VARIABLECAST: // bonus2 bSkillVariableCast,sk,t;
  3572. if (sd->state.lr_flag == 2)
  3573. break;
  3574. if (sd->skillvarcast.size() == MAX_PC_BONUS) {
  3575. ShowWarning("pc_bonus2: SP_SKILL_VARIABLECAST: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", MAX_PC_BONUS, type2, val);
  3576. break;
  3577. }
  3578. pc_bonus_itembonus(sd->skillvarcast, type2, val, false);
  3579. break;
  3580. #ifdef RENEWAL_CAST
  3581. case SP_SKILL_FIXEDCAST: // bonus2 bSkillFixedCast,sk,t;
  3582. if(sd->state.lr_flag == 2)
  3583. break;
  3584. if (sd->skillfixcast.size() == MAX_PC_BONUS) {
  3585. ShowWarning("pc_bonus2: SP_SKILL_FIXEDCAST: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", MAX_PC_BONUS, type2, val);
  3586. break;
  3587. }
  3588. pc_bonus_itembonus(sd->skillfixcast, type2, val, false);
  3589. break;
  3590. case SP_CASTRATE: // bonus2 bCastrate,sk,n;
  3591. case SP_VARCASTRATE: // bonus2 bVariableCastrate,sk,n;
  3592. if(sd->state.lr_flag == 2)
  3593. break;
  3594. if (sd->skillcastrate.size() == MAX_PC_BONUS) {
  3595. ShowWarning("pc_bonus2: SP_VARCASTRATE: Reached max (%d) number of skills per character, bonus skill %d (%d%%) lost.\n", MAX_PC_BONUS, type2, val);
  3596. break;
  3597. }
  3598. pc_bonus_itembonus(sd->skillcastrate, type2, -val, true); // Send inversed value here
  3599. break;
  3600. case SP_FIXCASTRATE: // bonus2 bFixedCastrate,sk,n;
  3601. if(sd->state.lr_flag == 2)
  3602. break;
  3603. if (sd->skillfixcastrate.size() == MAX_PC_BONUS) {
  3604. ShowWarning("pc_bonus2: SP_FIXCASTRATE: Reached max (%d) number of skills per character, bonus skill %d (%d%%) lost.\n", MAX_PC_BONUS, type2, val);
  3605. break;
  3606. }
  3607. pc_bonus_itembonus(sd->skillfixcastrate, type2, -val, true); // Send inversed value here
  3608. break;
  3609. #else
  3610. case SP_SKILL_FIXEDCAST: // bonus2 bSkillFixedCast,sk,t;
  3611. case SP_FIXCASTRATE: // bonus2 bFixedCastrate,sk,n;
  3612. //ShowWarning("pc_bonus2: Non-RENEWAL_CAST doesn't support this bonus %d.\n", type);
  3613. break;
  3614. case SP_VARCASTRATE: // bonus2 bVariableCastrate,sk,n;
  3615. case SP_CASTRATE: // bonus2 bCastrate,sk,n;
  3616. if(sd->state.lr_flag == 2)
  3617. break;
  3618. if (sd->skillcastrate.size() == MAX_PC_BONUS) { //Better mention this so the array length can be updated. [Skotlex]
  3619. ShowWarning("pc_bonus2: %s: Reached max (%d) number of skills per character, bonus skill %d (%d%%) lost.\n", (type == SP_CASTRATE) ? "SP_CASTRATE" : "SP_VARCASTRATE", MAX_PC_BONUS, type2, val);
  3620. break;
  3621. }
  3622. pc_bonus_itembonus(sd->skillcastrate, type2, val, true);
  3623. break;
  3624. #endif
  3625. case SP_SKILL_USE_SP: // bonus2 bSkillUseSP,sk,n;
  3626. if(sd->state.lr_flag == 2)
  3627. break;
  3628. if (sd->skillusesp.size() == MAX_PC_BONUS) {
  3629. ShowWarning("pc_bonus2: SP_SKILL_USE_SP: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", MAX_PC_BONUS, type2, val);
  3630. break;
  3631. }
  3632. pc_bonus_itembonus(sd->skillusesp, type2, val, false);
  3633. break;
  3634. case SP_SUB_SKILL: // bonus2 bSubSkill,sk,n;
  3635. if (sd->subskill.size() == MAX_PC_BONUS) {
  3636. ShowWarning("pc_bonus2: SP_SUB_SKILL: Reached max (%d) number of skills per character, bonus skill %d (%d) lost.\n", MAX_PC_BONUS, type2, val);
  3637. break;
  3638. }
  3639. pc_bonus_itembonus(sd->subskill, type2, val, false);
  3640. break;
  3641. case SP_SUBDEF_ELE: // bonus2 bSubDefEle,e,x;
  3642. PC_BONUS_CHK_ELEMENT(type2,SP_SUBDEF_ELE);
  3643. sd->subdefele[type2] += val;
  3644. break;
  3645. case SP_COMA_CLASS: // bonus2 bComaClass,c,n;
  3646. PC_BONUS_CHK_CLASS(type2,SP_COMA_CLASS);
  3647. sd->coma_class[type2] += val;
  3648. sd->special_state.bonus_coma = 1;
  3649. break;
  3650. case SP_COMA_RACE: // bonus2 bComaRace,r,n;
  3651. PC_BONUS_CHK_RACE(type2,SP_COMA_RACE);
  3652. sd->coma_race[type2] += val;
  3653. sd->special_state.bonus_coma = 1;
  3654. break;
  3655. case SP_MAGIC_ADDRACE2: // bonus2 bMagicAddRace2,mr,n;
  3656. PC_BONUS_CHK_RACE2(type2, SP_MAGIC_ADDRACE2);
  3657. if(sd->state.lr_flag != 2)
  3658. sd->magic_addrace2[type2] += val;
  3659. break;
  3660. case SP_IGNORE_MDEF_RACE2_RATE: //bonus2 bIgnoreMdefRace2Rate,mr,n;
  3661. PC_BONUS_CHK_RACE2(type2, SP_IGNORE_MDEF_RACE2);
  3662. if (sd->state.lr_flag != 2)
  3663. sd->ignore_mdef_by_race2[type2] += val;
  3664. break;
  3665. case SP_DROP_ADDRACE: // bonus2 bDropAddRace,r,x;
  3666. PC_BONUS_CHK_RACE(type2, SP_DROP_ADDRACE);
  3667. if (sd->state.lr_flag != 2)
  3668. sd->dropaddrace[type2] += val;
  3669. break;
  3670. case SP_DROP_ADDCLASS: // bonus2 bDropAddClass,c,x;
  3671. PC_BONUS_CHK_CLASS(type2, SP_DROP_ADDCLASS);
  3672. if (sd->state.lr_flag != 2)
  3673. sd->dropaddclass[type2] += val;
  3674. break;
  3675. default:
  3676. if (current_equip_combo_pos > 0) {
  3677. ShowWarning("pc_bonus2: unknown bonus type %d %d %d in a combo with item #%d\n", type, type2, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid);
  3678. }
  3679. else if (current_equip_card_id > 0 || current_equip_item_index > 0) {
  3680. ShowWarning("pc_bonus2: unknown bonus type %d %d %d in item #%d\n", type, type2, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid);
  3681. }
  3682. else {
  3683. ShowWarning("pc_bonus2: unknown bonus type %d %d %d in unknown usage. Report this!\n", type, type2, val);
  3684. }
  3685. break;
  3686. }
  3687. }
  3688. /**
  3689. * Gives item bonus to player for format: bonus3 bBonusName,type2,type3,val;
  3690. * @param sd
  3691. * @param type Bonus type used by bBonusName
  3692. * @param type2
  3693. * @param type3
  3694. * @param val Value that usually for rate or fixed value
  3695. */
  3696. void pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
  3697. {
  3698. nullpo_retv(sd);
  3699. switch(type){
  3700. case SP_ADD_MONSTER_DROP_ITEM: // bonus3 bAddMonsterDropItem,iid,r,n;
  3701. if(sd->state.lr_flag != 2)
  3702. pc_bonus_item_drop(sd->add_drop, type2, 0, CLASS_NONE, type3, val);
  3703. break;
  3704. case SP_ADD_MONSTER_ID_DROP_ITEM: // bonus3 bAddMonsterIdDropItem,iid,mid,n;
  3705. if(sd->state.lr_flag != 2)
  3706. pc_bonus_item_drop(sd->add_drop, type2, 0, CLASS_NONE, -type3, val);
  3707. break;
  3708. case SP_ADD_CLASS_DROP_ITEM: // bonus3 bAddClassDropItem,iid,c,n;
  3709. if(sd->state.lr_flag != 2)
  3710. pc_bonus_item_drop(sd->add_drop, type2, 0, type3, RC_NONE_, val);
  3711. break;
  3712. case SP_AUTOSPELL: // bonus3 bAutoSpell,sk,y,n;
  3713. if(sd->state.lr_flag != 2)
  3714. {
  3715. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3716. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !skill_get_inf2(type2, INF2_NOTARGETSELF));
  3717. pc_bonus_autospell(sd->autospell, target?-type2:type2, type3, val, 0, current_equip_card_id);
  3718. }
  3719. break;
  3720. case SP_AUTOSPELL_WHENHIT: // bonus3 bAutoSpellWhenHit,sk,y,n;
  3721. if(sd->state.lr_flag != 2)
  3722. {
  3723. int target = skill_get_inf(type2); //Support or Self (non-auto-target) skills should pick self.
  3724. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !skill_get_inf2(type2, INF2_NOTARGETSELF));
  3725. pc_bonus_autospell(sd->autospell2, target?-type2:type2, type3, val, BF_NORMAL|BF_SKILL, current_equip_card_id);
  3726. }
  3727. break;
  3728. case SP_ADD_MONSTER_DROP_ITEMGROUP: // bonus3 bAddMonsterDropItemGroup,ig,r,n;
  3729. if (sd->state.lr_flag != 2)
  3730. pc_bonus_item_drop(sd->add_drop, 0, type2, CLASS_NONE, type3, val);
  3731. break;
  3732. case SP_ADD_CLASS_DROP_ITEMGROUP: // bonus3 bAddClassDropItemGroup,ig,c,n;
  3733. if (sd->state.lr_flag != 2)
  3734. pc_bonus_item_drop(sd->add_drop, 0, type2, type3, RC_NONE_, val);
  3735. break;
  3736. case SP_ADDEFF: // bonus3 bAddEff,eff,n,y;
  3737. PC_BONUS_CHK_SC(type2,SP_ADDEFF);
  3738. pc_bonus_addeff(sd->addeff, (sc_type)type2, sd->state.lr_flag != 2 ? type3 : 0, sd->state.lr_flag == 2 ? type3 : 0, val, 0);
  3739. break;
  3740. case SP_ADDEFF_WHENHIT: // bonus3 bAddEffWhenHit,eff,n,y;
  3741. PC_BONUS_CHK_SC(type2,SP_ADDEFF_WHENHIT);
  3742. if(sd->state.lr_flag != 2)
  3743. pc_bonus_addeff(sd->addeff_atked, (sc_type)type2, type3, 0, val, 0);
  3744. break;
  3745. case SP_ADDEFF_ONSKILL: // bonus3 bAddEffOnSkill,sk,eff,n;
  3746. PC_BONUS_CHK_SC(type2,SP_ADDEFF_ONSKILL);
  3747. if( sd->state.lr_flag != 2 )
  3748. pc_bonus_addeff_onskill(sd->addeff_onskill, (sc_type)type3, val, type2, ATF_TARGET, 0);
  3749. break;
  3750. case SP_ADDELE: // bonus3 bAddEle,e,x,bf;
  3751. PC_BONUS_CHK_ELEMENT(type2,SP_ADDELE);
  3752. if (sd->state.lr_flag != 2)
  3753. pc_bonus_addele(sd, (unsigned char)type2, type3, val);
  3754. break;
  3755. case SP_SUBELE: // bonus3 bSubEle,e,x,bf;
  3756. PC_BONUS_CHK_ELEMENT(type2,SP_SUBELE);
  3757. if (sd->state.lr_flag != 2)
  3758. pc_bonus_subele(sd, (unsigned char)type2, type3, val);
  3759. break;
  3760. case SP_SP_VANISH_RACE_RATE: // bonus3 bSPVanishRaceRate,r,x,n;
  3761. PC_BONUS_CHK_RACE(type2,SP_SP_VANISH_RACE_RATE);
  3762. if(sd->state.lr_flag != 2) {
  3763. sd->sp_vanish_race[type2].rate += type3;
  3764. sd->sp_vanish_race[type2].per += val;
  3765. }
  3766. break;
  3767. case SP_HP_VANISH_RACE_RATE: // bonus3 bHPVanishRaceRate,r,x,n;
  3768. PC_BONUS_CHK_RACE(type2,SP_HP_VANISH_RACE_RATE);
  3769. if(sd->state.lr_flag != 2) {
  3770. sd->hp_vanish_race[type2].rate += type3;
  3771. sd->hp_vanish_race[type2].per += val;
  3772. }
  3773. break;
  3774. case SP_SP_VANISH_RATE: // bonus3 bSPVanishRate,x,n,bf;
  3775. if(sd->state.lr_flag != 2) {
  3776. pc_bonus_addvanish(sd->sp_vanish, type2, type3, val);
  3777. }
  3778. break;
  3779. case SP_HP_VANISH_RATE: // bonus3 bHPVanishRate,x,n,bf;
  3780. if(sd->state.lr_flag != 2) {
  3781. pc_bonus_addvanish(sd->hp_vanish, type2, type3, val);
  3782. }
  3783. break;
  3784. case SP_STATE_NORECOVER_RACE: // bonus3 bStateNoRecoverRace,r,x,t;
  3785. PC_BONUS_CHK_RACE(type2, SP_STATE_NORECOVER_RACE);
  3786. if (sd->state.lr_flag == 2)
  3787. break;
  3788. //! CONFIRM: Is it not stackable? Does not check max or min value?
  3789. //if (type3 > sd->norecover_state_race[type2].rate) {
  3790. // sd->norecover_state_race[type2].rate = type3;
  3791. // sd->norecover_state_race[type2].tick = val;
  3792. // break;
  3793. //}
  3794. sd->norecover_state_race[type2].rate = type3;
  3795. sd->norecover_state_race[type2].tick = val;
  3796. break;
  3797. default:
  3798. if (current_equip_combo_pos > 0) {
  3799. ShowWarning("pc_bonus3: unknown bonus type %d %d %d %d in a combo with item #%d\n", type, type2, type3, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid);
  3800. }
  3801. else if (current_equip_card_id > 0 || current_equip_item_index > 0) {
  3802. ShowWarning("pc_bonus3: unknown bonus type %d %d %d %d in item #%d\n", type, type2, type3, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid);
  3803. }
  3804. else {
  3805. ShowWarning("pc_bonus3: unknown bonus type %d %d %d %d in unknown usage. Report this!\n", type, type2, type3, val);
  3806. }
  3807. break;
  3808. }
  3809. }
  3810. /**
  3811. * Gives item bonus to player for format: bonus4 bBonusName,type2,type3,type4,val;
  3812. * @param sd
  3813. * @param type Bonus type used by bBonusName
  3814. * @param type2
  3815. * @param type3
  3816. * @param type4
  3817. * @param val Value that usually for rate or fixed value
  3818. */
  3819. void pc_bonus4(struct map_session_data *sd,int type,int type2,int type3,int type4,int val)
  3820. {
  3821. nullpo_retv(sd);
  3822. switch(type){
  3823. case SP_AUTOSPELL: // bonus4 bAutoSpell,sk,y,n,i;
  3824. if(sd->state.lr_flag != 2)
  3825. pc_bonus_autospell(sd->autospell, (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
  3826. break;
  3827. case SP_AUTOSPELL_WHENHIT: // bonus4 bAutoSpellWhenHit,sk,y,n,i;
  3828. if(sd->state.lr_flag != 2)
  3829. pc_bonus_autospell(sd->autospell2, (val&1?type2:-type2), (val&2?-type3:type3), type4, BF_NORMAL|BF_SKILL, current_equip_card_id);
  3830. break;
  3831. case SP_AUTOSPELL_ONSKILL: // bonus4 bAutoSpellOnSkill,sk,x,y,n;
  3832. if(sd->state.lr_flag != 2)
  3833. {
  3834. int target = skill_get_inf(type3); //Support or Self (non-auto-target) skills should pick self.
  3835. target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !skill_get_inf2(type3, INF2_NOTARGETSELF));
  3836. pc_bonus_autospell_onskill(sd->autospell3, type2, target?-type3:type3, type4, val, current_equip_card_id);
  3837. }
  3838. break;
  3839. case SP_ADDEFF: // bonus4 bAddEff,eff,n,y,t;
  3840. PC_BONUS_CHK_SC(type2,SP_ADDEFF);
  3841. pc_bonus_addeff(sd->addeff, (sc_type)type2, sd->state.lr_flag != 2 ? type3 : 0, sd->state.lr_flag == 2 ? type3 : 0, type4, val);
  3842. break;
  3843. case SP_ADDEFF_WHENHIT: // bonus4 bAddEffWhenHit,eff,n,y,t;
  3844. PC_BONUS_CHK_SC(type2,SP_ADDEFF_WHENHIT);
  3845. if (sd->state.lr_flag != 2)
  3846. pc_bonus_addeff(sd->addeff_atked, (sc_type)type2, type3, 0, type4, val);
  3847. break;
  3848. case SP_ADDEFF_ONSKILL: // bonus4 bAddEffOnSkill,sk,eff,n,y;
  3849. PC_BONUS_CHK_SC(type3,SP_ADDEFF_ONSKILL);
  3850. if( sd->state.lr_flag != 2 )
  3851. pc_bonus_addeff_onskill(sd->addeff_onskill, (sc_type)type3, type4, type2, val, 0);
  3852. break;
  3853. case SP_SET_DEF_RACE: // bonus4 bSetDefRace,r,n,t,y;
  3854. PC_BONUS_CHK_RACE(type2,SP_SET_DEF_RACE);
  3855. if(sd->state.lr_flag == 2)
  3856. break;
  3857. sd->def_set_race[type2].rate = type3;
  3858. sd->def_set_race[type2].tick = type4;
  3859. sd->def_set_race[type2].value = val;
  3860. break;
  3861. case SP_SET_MDEF_RACE: // bonus4 bSetMDefRace,r,n,t,y;
  3862. PC_BONUS_CHK_RACE(type2,SP_SET_MDEF_RACE);
  3863. if(sd->state.lr_flag == 2)
  3864. break;
  3865. sd->mdef_set_race[type2].rate = type3;
  3866. sd->mdef_set_race[type2].tick = type4;
  3867. sd->mdef_set_race[type2].value = val;
  3868. break;
  3869. default:
  3870. if (current_equip_combo_pos > 0) {
  3871. ShowWarning("pc_bonus4: unknown bonus type %d %d %d %d %d in a combo with item #%d\n", type, type2, type3, type4, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid);
  3872. }
  3873. else if (current_equip_card_id > 0 || current_equip_item_index > 0) {
  3874. ShowWarning("pc_bonus4: unknown bonus type %d %d %d %d %d in item #%d\n", type, type2, type3, type4, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid);
  3875. }
  3876. else {
  3877. ShowWarning("pc_bonus4: unknown bonus type %d %d %d %d %d in unknown usage. Report this!\n", type, type2, type3, type4, val);
  3878. }
  3879. break;
  3880. }
  3881. }
  3882. /**
  3883. * Gives item bonus to player for format: bonus5 bBonusName,type2,type3,type4,val;
  3884. * @param sd
  3885. * @param type Bonus type used by bBonusName
  3886. * @param type2
  3887. * @param type3
  3888. * @param type4
  3889. * @param val Value that usually for rate or fixed value
  3890. */
  3891. void pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4,int type5,int val)
  3892. {
  3893. nullpo_retv(sd);
  3894. switch(type){
  3895. case SP_AUTOSPELL: // bonus5 bAutoSpell,sk,y,n,bf,i;
  3896. if(sd->state.lr_flag != 2)
  3897. pc_bonus_autospell(sd->autospell, (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  3898. break;
  3899. case SP_AUTOSPELL_WHENHIT: // bonus5 bAutoSpellWhenHit,sk,y,n,bf,i;
  3900. if(sd->state.lr_flag != 2)
  3901. pc_bonus_autospell(sd->autospell2, (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
  3902. break;
  3903. case SP_AUTOSPELL_ONSKILL: // bonus5 bAutoSpellOnSkill,sk,x,y,n,i;
  3904. if(sd->state.lr_flag != 2)
  3905. pc_bonus_autospell_onskill(sd->autospell3, type2, (val&1?-type3:type3), (val&2?-type4:type4), type5, current_equip_card_id);
  3906. break;
  3907. case SP_ADDEFF_ONSKILL: // bonus5 bAddEffOnSkill,sk,eff,n,y,t;
  3908. PC_BONUS_CHK_SC(type3,SP_ADDEFF_ONSKILL);
  3909. if( sd->state.lr_flag != 2 )
  3910. pc_bonus_addeff_onskill(sd->addeff_onskill, (sc_type)type3, type4, type2, type5, val);
  3911. break;
  3912. default:
  3913. if (current_equip_combo_pos > 0) {
  3914. ShowWarning("pc_bonus5: unknown bonus type %d %d %d %d %d %d in a combo with item #%d\n", type, type2, type3, type4, type5, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid);
  3915. }
  3916. else if (current_equip_card_id > 0 || current_equip_item_index > 0) {
  3917. ShowWarning("pc_bonus5: unknown bonus type %d %d %d %d %d %d in item #%d\n", type, type2, type3, type4, type5, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid);
  3918. }
  3919. else {
  3920. ShowWarning("pc_bonus5: unknown bonus type %d %d %d %d %d %d in unknown usage. Report this!\n", type, type2, type3, type4, type5, val);
  3921. }
  3922. break;
  3923. }
  3924. }
  3925. /*==========================================
  3926. * Grants a player a given skill. Flag values are:
  3927. * 0 - Grant permanent skill to be bound to skill tree
  3928. * 1 - Grant an item skill (temporary)
  3929. * 2 - Like 1, except the level granted can stack with previously learned level.
  3930. * 4 - Like 0, except the skill will ignore skill tree (saves through job changes and resets).
  3931. *------------------------------------------*/
  3932. bool pc_skill(struct map_session_data* sd, uint16 skill_id, int level, enum e_addskill_type type) {
  3933. uint16 idx = 0;
  3934. nullpo_ret(sd);
  3935. if (!skill_id || !(idx = skill_get_index(skill_id))) {
  3936. ShowError("pc_skill: Skill with id %d does not exist in the skill database\n", skill_id);
  3937. return false;
  3938. }
  3939. if (level > MAX_SKILL_LEVEL) {
  3940. ShowError("pc_skill: Skill level %d too high. Max lv supported is %d\n", level, MAX_SKILL_LEVEL);
  3941. return false;
  3942. }
  3943. if (type == ADDSKILL_TEMP_ADDLEVEL && sd->status.skill[idx].lv + level > MAX_SKILL_LEVEL) {
  3944. 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);
  3945. level = MAX_SKILL_LEVEL - sd->status.skill[idx].lv;
  3946. }
  3947. switch (type) {
  3948. case ADDSKILL_PERMANENT: //Set skill data overwriting whatever was there before.
  3949. sd->status.skill[idx].id = skill_id;
  3950. sd->status.skill[idx].lv = level;
  3951. sd->status.skill[idx].flag = SKILL_FLAG_PERMANENT;
  3952. if (level == 0) { //Remove skill.
  3953. sd->status.skill[idx].id = 0;
  3954. clif_deleteskill(sd,skill_id);
  3955. } else
  3956. clif_addskill(sd,skill_id);
  3957. if (!skill_get_inf(skill_id)) //Only recalculate for passive skills.
  3958. status_calc_pc(sd, SCO_NONE);
  3959. break;
  3960. case ADDSKILL_TEMP: //Item bonus skill.
  3961. if (sd->status.skill[idx].id != 0) {
  3962. if (sd->status.skill[idx].lv >= level)
  3963. return true;
  3964. if (sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT) //Non-granted skill, store it's level.
  3965. sd->status.skill[idx].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[idx].lv;
  3966. } else {
  3967. sd->status.skill[idx].id = skill_id;
  3968. sd->status.skill[idx].flag = SKILL_FLAG_TEMPORARY;
  3969. }
  3970. sd->status.skill[idx].lv = level;
  3971. break;
  3972. case ADDSKILL_TEMP_ADDLEVEL: //Add skill bonus on top of what you had.
  3973. if (sd->status.skill[idx].id != 0) {
  3974. if (sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT)
  3975. sd->status.skill[idx].flag = SKILL_FLAG_REPLACED_LV_0 + sd->status.skill[idx].lv; // Store previous level.
  3976. } else {
  3977. sd->status.skill[idx].id = skill_id;
  3978. sd->status.skill[idx].flag = SKILL_FLAG_TEMPORARY; //Set that this is a bonus skill.
  3979. }
  3980. sd->status.skill[idx].lv += level;
  3981. break;
  3982. case ADDSKILL_PERMANENT_GRANTED: //Permanent granted skills ignore the skill tree
  3983. sd->status.skill[idx].id = skill_id;
  3984. sd->status.skill[idx].lv = level;
  3985. sd->status.skill[idx].flag = SKILL_FLAG_PERM_GRANTED;
  3986. if (level == 0) { //Remove skill.
  3987. sd->status.skill[idx].id = 0;
  3988. clif_deleteskill(sd,skill_id);
  3989. } else
  3990. clif_addskill(sd,skill_id);
  3991. if (!skill_get_inf(skill_id)) //Only recalculate for passive skills.
  3992. status_calc_pc(sd, SCO_NONE);
  3993. break;
  3994. default:
  3995. return false;
  3996. }
  3997. return true;
  3998. }
  3999. /*==========================================
  4000. * Append a card to an item ?
  4001. *------------------------------------------*/
  4002. int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip)
  4003. {
  4004. int i;
  4005. unsigned short nameid;
  4006. nullpo_ret(sd);
  4007. if( idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL )
  4008. return 0; //Invalid item index.
  4009. if( idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL )
  4010. return 0; //Invalid card index.
  4011. if( sd->inventory.u.items_inventory[idx_equip].nameid <= 0 || sd->inventory.u.items_inventory[idx_equip].amount < 1 )
  4012. return 0; // target item missing
  4013. if( sd->inventory.u.items_inventory[idx_card].nameid <= 0 || sd->inventory.u.items_inventory[idx_card].amount < 1 )
  4014. return 0; // target card missing
  4015. if( sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR )
  4016. return 0; // only weapons and armor are allowed
  4017. if( sd->inventory_data[idx_card]->type != IT_CARD )
  4018. return 0; // must be a card
  4019. if( sd->inventory.u.items_inventory[idx_equip].identify == 0 )
  4020. return 0; // target must be identified
  4021. if( itemdb_isspecial(sd->inventory.u.items_inventory[idx_equip].card[0]) )
  4022. return 0; // card slots reserved for other purposes
  4023. if( (sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0 )
  4024. return 0; // card cannot be compounded on this item type
  4025. if( sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD )
  4026. return 0; // attempted to place shield card on left-hand weapon.
  4027. if( sd->inventory.u.items_inventory[idx_equip].equip != 0 )
  4028. return 0; // item must be unequipped
  4029. ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->inventory.u.items_inventory[idx_equip].card[i] == 0 );
  4030. if( i == sd->inventory_data[idx_equip]->slot )
  4031. return 0; // no free slots
  4032. // remember the card id to insert
  4033. nameid = sd->inventory.u.items_inventory[idx_card].nameid;
  4034. if( pc_delitem(sd,idx_card,1,1,0,LOG_TYPE_OTHER) == 1 )
  4035. {// failed
  4036. clif_insert_card(sd,idx_equip,idx_card,1);
  4037. }
  4038. else
  4039. {// success
  4040. log_pick_pc(sd, LOG_TYPE_OTHER, -1, &sd->inventory.u.items_inventory[idx_equip]);
  4041. sd->inventory.u.items_inventory[idx_equip].card[i] = nameid;
  4042. log_pick_pc(sd, LOG_TYPE_OTHER, 1, &sd->inventory.u.items_inventory[idx_equip]);
  4043. clif_insert_card(sd,idx_equip,idx_card,0);
  4044. }
  4045. return 0;
  4046. }
  4047. /**
  4048. * Returns the count of unidentified items with the option to identify too.
  4049. * @param sd: Player data
  4050. * @param identify_item: Whether or not to identify any unidentified items
  4051. * @return Unidentified items count
  4052. */
  4053. int pc_identifyall(struct map_session_data *sd, bool identify_item)
  4054. {
  4055. int unidentified_count = 0;
  4056. for (int i = 0; i < MAX_INVENTORY; i++) {
  4057. if (sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].identify != 1) {
  4058. if (identify_item == true) {
  4059. sd->inventory.u.items_inventory[i].identify = 1;
  4060. clif_item_identified(sd,i,0);
  4061. }
  4062. unidentified_count++;
  4063. }
  4064. }
  4065. return unidentified_count;
  4066. }
  4067. //
  4068. // Items
  4069. //
  4070. /*==========================================
  4071. * Update buying value by skills
  4072. *------------------------------------------*/
  4073. int pc_modifybuyvalue(struct map_session_data *sd,int orig_value)
  4074. {
  4075. int skill,val = orig_value,rate1 = 0,rate2 = 0;
  4076. if((skill=pc_checkskill(sd,MC_DISCOUNT))>0) // merchant discount
  4077. rate1 = 5+skill*2-((skill==10)? 1:0);
  4078. if((skill=pc_checkskill(sd,RG_COMPULSION))>0) // rogue discount
  4079. rate2 = 5+skill*4;
  4080. if(rate1 < rate2) rate1 = rate2;
  4081. if(rate1)
  4082. val = (int)((double)orig_value*(double)(100-rate1)/100.);
  4083. if(val < battle_config.min_shop_buy)
  4084. val = battle_config.min_shop_buy;
  4085. return val;
  4086. }
  4087. /*==========================================
  4088. * Update selling value by skills
  4089. *------------------------------------------*/
  4090. int pc_modifysellvalue(struct map_session_data *sd,int orig_value)
  4091. {
  4092. int skill,val = orig_value,rate = 0;
  4093. if((skill=pc_checkskill(sd,MC_OVERCHARGE))>0) //OverCharge
  4094. rate = 5+skill*2-((skill==10)? 1:0);
  4095. if(rate)
  4096. val = (int)((double)orig_value*(double)(100+rate)/100.);
  4097. if (val < battle_config.min_shop_sell)
  4098. val = battle_config.min_shop_sell;
  4099. return val;
  4100. }
  4101. /*==========================================
  4102. * Checking if we have enough place on inventory for new item
  4103. * Make sure to take 30k as limit (for client I guess)
  4104. * @param sd
  4105. * @param nameid
  4106. * @param amount
  4107. * @return e_chkitem_result
  4108. *------------------------------------------*/
  4109. char pc_checkadditem(struct map_session_data *sd, unsigned short nameid, int amount)
  4110. {
  4111. int i;
  4112. struct item_data* data;
  4113. nullpo_ret(sd);
  4114. if(amount > MAX_AMOUNT)
  4115. return CHKADDITEM_OVERAMOUNT;
  4116. data = itemdb_search(nameid);
  4117. if(!itemdb_isstackable2(data))
  4118. return CHKADDITEM_NEW;
  4119. if( data->stack.inventory && amount > data->stack.amount )
  4120. return CHKADDITEM_OVERAMOUNT;
  4121. if (data->flag.guid)
  4122. return CHKADDITEM_NEW;
  4123. for(i=0;i<MAX_INVENTORY;i++){
  4124. // FIXME: This does not consider the checked item's cards, thus could check a wrong slot for stackability.
  4125. if(sd->inventory.u.items_inventory[i].nameid == nameid){
  4126. if( amount > MAX_AMOUNT - sd->inventory.u.items_inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->inventory.u.items_inventory[i].amount ) )
  4127. return CHKADDITEM_OVERAMOUNT;
  4128. return CHKADDITEM_EXIST;
  4129. }
  4130. }
  4131. return CHKADDITEM_NEW;
  4132. }
  4133. /*==========================================
  4134. * Return number of available place in inventory
  4135. * Each non stackable item will reduce place by 1
  4136. * @param sd
  4137. * @return Number of empty slots
  4138. *------------------------------------------*/
  4139. uint8 pc_inventoryblank(struct map_session_data *sd)
  4140. {
  4141. uint8 i, b;
  4142. nullpo_ret(sd);
  4143. for(i = 0, b = 0; i < MAX_INVENTORY; i++){
  4144. if(sd->inventory.u.items_inventory[i].nameid == 0)
  4145. b++;
  4146. }
  4147. return b;
  4148. }
  4149. /**
  4150. * Attempts to remove zeny from player
  4151. * @param sd: Player
  4152. * @param zeny: Zeny removed
  4153. * @param type: Log type
  4154. * @param tsd: (optional) From who to log (if null take sd)
  4155. * @return 0: Success, 1: Failed (Removing negative Zeny or not enough Zeny), 2: Player not found
  4156. */
  4157. char pc_payzeny(struct map_session_data *sd, int zeny, enum e_log_pick_type type, struct map_session_data *tsd)
  4158. {
  4159. nullpo_retr(2,sd);
  4160. zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
  4161. if( zeny < 0 )
  4162. {
  4163. ShowError("pc_payzeny: Paying negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
  4164. return 1;
  4165. }
  4166. if( sd->status.zeny < zeny )
  4167. return 1; //Not enough.
  4168. sd->status.zeny -= zeny;
  4169. clif_updatestatus(sd,SP_ZENY);
  4170. if(!tsd) tsd = sd;
  4171. log_zeny(sd, type, tsd, -zeny);
  4172. if( zeny > 0 && sd->state.showzeny ) {
  4173. char output[255];
  4174. sprintf(output, "Removed %dz.", zeny);
  4175. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  4176. }
  4177. return 0;
  4178. }
  4179. /**
  4180. * Attempts to give zeny to player
  4181. * @param sd: Player
  4182. * @param type: Log type
  4183. * @param tsd: (optional) From who to log (if null take sd)
  4184. * @return -1: Player not found, 0: Success, 1: Giving negative Zeny
  4185. */
  4186. char pc_getzeny(struct map_session_data *sd, int zeny, enum e_log_pick_type type, struct map_session_data *tsd)
  4187. {
  4188. nullpo_retr(-1,sd);
  4189. zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
  4190. if( zeny < 0 )
  4191. {
  4192. ShowError("pc_getzeny: Obtaining negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
  4193. return 1;
  4194. }
  4195. if( zeny > MAX_ZENY - sd->status.zeny )
  4196. zeny = MAX_ZENY - sd->status.zeny;
  4197. sd->status.zeny += zeny;
  4198. clif_updatestatus(sd,SP_ZENY);
  4199. if(!tsd) tsd = sd;
  4200. log_zeny(sd, type, tsd, zeny);
  4201. if( zeny > 0 && sd->state.showzeny ) {
  4202. char output[255];
  4203. sprintf(output, "Gained %dz.", zeny);
  4204. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  4205. }
  4206. achievement_update_objective(sd, AG_GET_ZENY, 1, sd->status.zeny);
  4207. return 0;
  4208. }
  4209. /**
  4210. * Attempts to remove Cash Points from player
  4211. * @param sd: Player
  4212. * @param price: Total points (cash + kafra) the player has to pay
  4213. * @param points: Kafra points the player has to pay
  4214. * @param type: Log type
  4215. * @return -1: Not enough points, otherwise success (cash+points)
  4216. */
  4217. int pc_paycash(struct map_session_data *sd, int price, int points, e_log_pick_type type)
  4218. {
  4219. int cash;
  4220. nullpo_retr(-1,sd);
  4221. points = cap_value(points, 0, MAX_ZENY); //prevent command UB
  4222. cash = price-points;
  4223. if( sd->cashPoints < cash || sd->kafraPoints < points )
  4224. {
  4225. 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);
  4226. return -1;
  4227. }
  4228. if( cash ){
  4229. pc_setaccountreg(sd, add_str(CASHPOINT_VAR), sd->cashPoints - cash);
  4230. sd->cashPoints -= cash;
  4231. log_cash( sd, type, LOG_CASH_TYPE_CASH, -cash );
  4232. }
  4233. if( points ){
  4234. pc_setaccountreg(sd, add_str(KAFRAPOINT_VAR), sd->kafraPoints - points);
  4235. sd->kafraPoints -= points;
  4236. log_cash( sd, type, LOG_CASH_TYPE_KAFRA, -points );
  4237. }
  4238. if( battle_config.cashshop_show_points )
  4239. {
  4240. char output[CHAT_SIZE_MAX];
  4241. sprintf(output, msg_txt(sd,504), points, cash, sd->kafraPoints, sd->cashPoints); // Used %d kafra points and %d cash points. %d kafra and %d cash points remaining.
  4242. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  4243. }
  4244. return cash+points;
  4245. }
  4246. /**
  4247. * Attempts to give Cash Points to player
  4248. * @param sd: Player
  4249. * @param cash: Cash points the player gets
  4250. * @param points: Kafra points the player gets
  4251. * @param type: Log type
  4252. * @return -1: Error, otherwise success (cash or points)
  4253. */
  4254. int pc_getcash(struct map_session_data *sd, int cash, int points, e_log_pick_type type)
  4255. {
  4256. char output[CHAT_SIZE_MAX];
  4257. nullpo_retr(-1,sd);
  4258. cash = cap_value(cash, 0, MAX_ZENY); //prevent command UB
  4259. points = cap_value(points, 0, MAX_ZENY); //prevent command UB
  4260. if( cash > 0 )
  4261. {
  4262. if( cash > MAX_ZENY-sd->cashPoints )
  4263. {
  4264. 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);
  4265. cash = MAX_ZENY-sd->cashPoints;
  4266. }
  4267. pc_setaccountreg(sd, add_str(CASHPOINT_VAR), sd->cashPoints+cash);
  4268. sd->cashPoints += cash;
  4269. log_cash( sd, type, LOG_CASH_TYPE_CASH, cash );
  4270. if( battle_config.cashshop_show_points )
  4271. {
  4272. sprintf(output, msg_txt(sd,505), cash, sd->cashPoints);
  4273. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  4274. }
  4275. return cash;
  4276. }
  4277. if( points > 0 )
  4278. {
  4279. if( points > MAX_ZENY-sd->kafraPoints )
  4280. {
  4281. 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);
  4282. points = MAX_ZENY-sd->kafraPoints;
  4283. }
  4284. pc_setaccountreg(sd, add_str(KAFRAPOINT_VAR), sd->kafraPoints+points);
  4285. sd->kafraPoints += points;
  4286. log_cash( sd, type, LOG_CASH_TYPE_KAFRA, points );
  4287. if( battle_config.cashshop_show_points )
  4288. {
  4289. sprintf(output, msg_txt(sd,506), points, sd->kafraPoints);
  4290. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  4291. }
  4292. return points;
  4293. }
  4294. return -1; //shouldn't happen but just in case
  4295. }
  4296. /**
  4297. * Searching a specified itemid in inventory and return his stored index
  4298. * @param sd Player
  4299. * @param nameid Find this Item!
  4300. * @return Stored index in inventory, or -1 if not found.
  4301. **/
  4302. short pc_search_inventory(struct map_session_data *sd, unsigned short nameid) {
  4303. short i;
  4304. nullpo_retr(-1, sd);
  4305. ARR_FIND( 0, MAX_INVENTORY, i, sd->inventory.u.items_inventory[i].nameid == nameid && (sd->inventory.u.items_inventory[i].amount > 0 || nameid == 0) );
  4306. return ( i < MAX_INVENTORY ) ? i : -1;
  4307. }
  4308. /** Attempt to add a new item to player inventory
  4309. * @param sd
  4310. * @param item_data
  4311. * @param amount
  4312. * @param log_type
  4313. * @return
  4314. * 0 = success
  4315. * 1 = invalid itemid not found or negative amount
  4316. * 2 = overweight
  4317. * 3 = ?
  4318. * 4 = no free place found
  4319. * 5 = max amount reached
  4320. * 6 = ?
  4321. * 7 = stack limitation
  4322. */
  4323. enum e_additem_result pc_additem(struct map_session_data *sd,struct item *item,int amount,e_log_pick_type log_type) {
  4324. struct item_data *id;
  4325. int16 i;
  4326. unsigned int w;
  4327. nullpo_retr(ADDITEM_INVALID, sd);
  4328. nullpo_retr(ADDITEM_INVALID, item);
  4329. if( item->nameid == 0 || amount <= 0 )
  4330. return ADDITEM_INVALID;
  4331. if( amount > MAX_AMOUNT )
  4332. return ADDITEM_OVERAMOUNT;
  4333. id = itemdb_search(item->nameid);
  4334. if( id->stack.inventory && amount > id->stack.amount )
  4335. {// item stack limitation
  4336. return ADDITEM_STACKLIMIT;
  4337. }
  4338. w = id->weight*amount;
  4339. if(sd->weight + w > sd->max_weight)
  4340. return ADDITEM_OVERWEIGHT;
  4341. i = MAX_INVENTORY;
  4342. if (id->flag.guid && !item->unique_id)
  4343. item->unique_id = pc_generate_unique_id(sd);
  4344. // Stackable | Non Rental
  4345. if( itemdb_isstackable2(id) && item->expire_time == 0 ) {
  4346. for( i = 0; i < MAX_INVENTORY; i++ ) {
  4347. if( sd->inventory.u.items_inventory[i].nameid == item->nameid &&
  4348. sd->inventory.u.items_inventory[i].bound == item->bound &&
  4349. sd->inventory.u.items_inventory[i].expire_time == 0 &&
  4350. sd->inventory.u.items_inventory[i].unique_id == item->unique_id &&
  4351. memcmp(&sd->inventory.u.items_inventory[i].card, &item->card, sizeof(item->card)) == 0 ) {
  4352. if( amount > MAX_AMOUNT - sd->inventory.u.items_inventory[i].amount || ( id->stack.inventory && amount > id->stack.amount - sd->inventory.u.items_inventory[i].amount ) )
  4353. return ADDITEM_OVERAMOUNT;
  4354. sd->inventory.u.items_inventory[i].amount += amount;
  4355. clif_additem(sd,i,amount,0);
  4356. break;
  4357. }
  4358. }
  4359. }
  4360. if (i >= MAX_INVENTORY) {
  4361. i = pc_search_inventory(sd,0);
  4362. if( i < 0 )
  4363. return ADDITEM_OVERITEM;
  4364. memcpy(&sd->inventory.u.items_inventory[i], item, sizeof(sd->inventory.u.items_inventory[0]));
  4365. // clear equip and favorite fields first, just in case
  4366. if( item->equip )
  4367. sd->inventory.u.items_inventory[i].equip = 0;
  4368. if( item->favorite )
  4369. sd->inventory.u.items_inventory[i].favorite = 0;
  4370. if( item->equipSwitch )
  4371. sd->inventory.u.items_inventory[i].equipSwitch = 0;
  4372. sd->inventory.u.items_inventory[i].amount = amount;
  4373. sd->inventory_data[i] = id;
  4374. sd->last_addeditem_index = i;
  4375. if (!itemdb_isstackable2(id) || id->flag.guid)
  4376. sd->inventory.u.items_inventory[i].unique_id = item->unique_id ? item->unique_id : pc_generate_unique_id(sd);
  4377. clif_additem(sd,i,amount,0);
  4378. }
  4379. log_pick_pc(sd, log_type, amount, &sd->inventory.u.items_inventory[i]);
  4380. sd->weight += w;
  4381. clif_updatestatus(sd,SP_WEIGHT);
  4382. //Auto-equip
  4383. if(id->flag.autoequip)
  4384. pc_equipitem(sd, i, id->equip);
  4385. /* rental item check */
  4386. if( item->expire_time ) {
  4387. if( time(NULL) > item->expire_time ) {
  4388. clif_rental_expired(sd->fd, i, sd->inventory.u.items_inventory[i].nameid);
  4389. pc_delitem(sd, i, sd->inventory.u.items_inventory[i].amount, 1, 0, LOG_TYPE_OTHER);
  4390. } else {
  4391. unsigned int seconds = (unsigned int)( item->expire_time - time(NULL) );
  4392. clif_rental_time(sd->fd, sd->inventory.u.items_inventory[i].nameid, seconds);
  4393. pc_inventory_rental_add(sd, seconds);
  4394. }
  4395. }
  4396. achievement_update_objective(sd, AG_GET_ITEM, 1, id->value_sell);
  4397. pc_show_questinfo(sd);
  4398. return ADDITEM_SUCCESS;
  4399. }
  4400. /*==========================================
  4401. * Remove an item at index n from inventory by amount.
  4402. * @param sd
  4403. * @param n Item index in inventory
  4404. * @param amount
  4405. * @param type &1: Don't notify deletion; &2 Don't notify weight change; &4 Don't calculate status
  4406. * @param reason Delete reason
  4407. * @param log_type e_log_pick_type
  4408. * @return 1 - invalid itemid or negative amount; 0 - Success
  4409. *------------------------------------------*/
  4410. char pc_delitem(struct map_session_data *sd,int n,int amount,int type, short reason, e_log_pick_type log_type)
  4411. {
  4412. nullpo_retr(1, sd);
  4413. if(n < 0 || sd->inventory.u.items_inventory[n].nameid == 0 || amount <= 0 || sd->inventory.u.items_inventory[n].amount<amount || sd->inventory_data[n] == NULL)
  4414. return 1;
  4415. log_pick_pc(sd, log_type, -amount, &sd->inventory.u.items_inventory[n]);
  4416. sd->inventory.u.items_inventory[n].amount -= amount;
  4417. sd->weight -= sd->inventory_data[n]->weight*amount ;
  4418. if( sd->inventory.u.items_inventory[n].amount <= 0 ){
  4419. if(sd->inventory.u.items_inventory[n].equip)
  4420. pc_unequipitem(sd,n,2|(!(type&4) ? 1 : 0));
  4421. memset(&sd->inventory.u.items_inventory[n],0,sizeof(sd->inventory.u.items_inventory[0]));
  4422. sd->inventory_data[n] = NULL;
  4423. }
  4424. if(!(type&1))
  4425. clif_delitem(sd,n,amount,reason);
  4426. if(!(type&2))
  4427. clif_updatestatus(sd,SP_WEIGHT);
  4428. pc_show_questinfo(sd);
  4429. return 0;
  4430. }
  4431. /*==========================================
  4432. * Attempt to drop an item.
  4433. * @param sd
  4434. * @param n Item index in inventory
  4435. * @param amount Amount of item
  4436. * @return False = fail; True = success
  4437. *------------------------------------------*/
  4438. bool pc_dropitem(struct map_session_data *sd,int n,int amount)
  4439. {
  4440. nullpo_retr(1, sd);
  4441. if(n < 0 || n >= MAX_INVENTORY)
  4442. return false;
  4443. if(amount <= 0)
  4444. return false;
  4445. if(sd->inventory.u.items_inventory[n].nameid <= 0 ||
  4446. sd->inventory.u.items_inventory[n].amount <= 0 ||
  4447. sd->inventory.u.items_inventory[n].amount < amount ||
  4448. sd->state.trading || sd->state.vending ||
  4449. !sd->inventory_data[n] //pc_delitem would fail on this case.
  4450. )
  4451. return false;
  4452. if( sd->inventory.u.items_inventory[n].equipSwitch )
  4453. return false;
  4454. if( map_getmapflag(sd->bl.m, MF_NODROP) )
  4455. {
  4456. clif_displaymessage (sd->fd, msg_txt(sd,271));
  4457. return false; //Can't drop items in nodrop mapflag maps.
  4458. }
  4459. if( !pc_candrop(sd,&sd->inventory.u.items_inventory[n]) )
  4460. {
  4461. clif_displaymessage (sd->fd, msg_txt(sd,263));
  4462. return false;
  4463. }
  4464. if (!map_addflooritem(&sd->inventory.u.items_inventory[n], amount, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 2, 0))
  4465. return false;
  4466. pc_delitem(sd, n, amount, 1, 0, LOG_TYPE_PICKDROP_PLAYER);
  4467. clif_dropitem(sd, n, amount);
  4468. return true;
  4469. }
  4470. /*==========================================
  4471. * Attempt to pick up an item.
  4472. * @param sd
  4473. * @param fitem Item that will be picked
  4474. * @return False = fail; True = success
  4475. *------------------------------------------*/
  4476. bool pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem)
  4477. {
  4478. int flag = 0;
  4479. t_tick tick = gettick();
  4480. struct party_data *p = NULL;
  4481. nullpo_ret(sd);
  4482. nullpo_ret(fitem);
  4483. if (!check_distance_bl(&fitem->bl, &sd->bl, 2) && sd->ud.skill_id!=BS_GREED)
  4484. return false; // Distance is too far
  4485. if (sd->sc.cant.pickup)
  4486. return false;
  4487. if (sd->status.party_id)
  4488. p = party_search(sd->status.party_id);
  4489. if (fitem->first_get_charid > 0 && fitem->first_get_charid != sd->status.char_id) {
  4490. struct map_session_data *first_sd = map_charid2sd(fitem->first_get_charid);
  4491. if (DIFF_TICK(tick,fitem->first_get_tick) < 0) {
  4492. if (!(p && p->party.item&1 &&
  4493. first_sd && first_sd->status.party_id == sd->status.party_id
  4494. ))
  4495. return false;
  4496. }
  4497. else if (fitem->second_get_charid > 0 && fitem->second_get_charid != sd->status.char_id) {
  4498. struct map_session_data *second_sd = map_charid2sd(fitem->second_get_charid);
  4499. if (DIFF_TICK(tick, fitem->second_get_tick) < 0) {
  4500. if (!(p && p->party.item&1 &&
  4501. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  4502. (second_sd && second_sd->status.party_id == sd->status.party_id))
  4503. ))
  4504. return false;
  4505. }
  4506. else if (fitem->third_get_charid > 0 && fitem->third_get_charid != sd->status.char_id){
  4507. struct map_session_data *third_sd = map_charid2sd(fitem->third_get_charid);
  4508. if (DIFF_TICK(tick,fitem->third_get_tick) < 0) {
  4509. if(!(p && p->party.item&1 &&
  4510. ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
  4511. (second_sd && second_sd->status.party_id == sd->status.party_id) ||
  4512. (third_sd && third_sd->status.party_id == sd->status.party_id))
  4513. ))
  4514. return false;
  4515. }
  4516. }
  4517. }
  4518. }
  4519. //This function takes care of giving the item to whoever should have it, considering party-share options.
  4520. if ((flag = party_share_loot(p,sd,&fitem->item, fitem->first_get_charid))) {
  4521. clif_additem(sd,0,0,flag);
  4522. return true;
  4523. }
  4524. //Display pickup animation.
  4525. pc_stop_attack(sd);
  4526. clif_takeitem(&sd->bl,&fitem->bl);
  4527. if (fitem->mob_id &&
  4528. (itemdb_search(fitem->item.nameid))->flag.broadcast &&
  4529. (!p || !(p->party.item&2)) // Somehow, if party's pickup distribution is 'Even Share', no announcemet
  4530. )
  4531. intif_broadcast_obtain_special_item(sd, fitem->item.nameid, fitem->mob_id, ITEMOBTAIN_TYPE_MONSTER_ITEM);
  4532. map_clearflooritem(&fitem->bl);
  4533. return true;
  4534. }
  4535. /*==========================================
  4536. * Check if item is usable.
  4537. * Return:
  4538. * false = no
  4539. * true = yes
  4540. *------------------------------------------*/
  4541. bool pc_isUseitem(struct map_session_data *sd,int n)
  4542. {
  4543. struct item_data *item;
  4544. unsigned short nameid;
  4545. nullpo_ret(sd);
  4546. item = sd->inventory_data[n];
  4547. nameid = sd->inventory.u.items_inventory[n].nameid;
  4548. if( item == NULL )
  4549. return false;
  4550. //Not consumable item
  4551. if( item->type != IT_HEALING && item->type != IT_USABLE && item->type != IT_CASH )
  4552. return false;
  4553. if (pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL))
  4554. return true;
  4555. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  4556. if(mapdata->flag[MF_NOITEMCONSUMPTION]) //consumable but mapflag prevent it
  4557. return false;
  4558. //Prevent mass item usage. [Skotlex]
  4559. if( DIFF_TICK(sd->canuseitem_tick,gettick()) > 0 ||
  4560. (itemdb_group_item_exists(IG_CASH_FOOD, nameid) && DIFF_TICK(sd->canusecashfood_tick,gettick()) > 0)
  4561. )
  4562. return false;
  4563. if( (item->item_usage.flag&NOUSE_SITTING) && (pc_issit(sd) == 1) && (pc_get_group_level(sd) < item->item_usage.override) ) {
  4564. clif_msg(sd,ITEM_NOUSE_SITTING);
  4565. return false; // You cannot use this item while sitting.
  4566. }
  4567. if (sd->state.storage_flag && item->type != IT_CASH) {
  4568. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd,388), false, SELF);
  4569. return false; // You cannot use this item while storage is open.
  4570. }
  4571. if (item->flag.dead_branch && (mapdata->flag[MF_NOBRANCH] || mapdata_flag_gvg2(mapdata)))
  4572. return false;
  4573. switch( nameid ) {
  4574. case ITEMID_WING_OF_FLY:
  4575. case ITEMID_GIANT_FLY_WING:
  4576. case ITEMID_N_FLY_WING:
  4577. if( mapdata->flag[MF_NOTELEPORT] || mapdata_flag_gvg2(mapdata) ) {
  4578. clif_skill_teleportmessage(sd,0);
  4579. return false;
  4580. }
  4581. if (nameid == ITEMID_GIANT_FLY_WING) {
  4582. struct party_data *pd = party_search(sd->status.party_id);
  4583. if (pd) {
  4584. int i;
  4585. ARR_FIND(0, MAX_PARTY, i, pd->data[i].sd == sd && pd->party.member[i].leader);
  4586. if (i == MAX_PARTY) { // User is not party leader
  4587. clif_msg(sd, ITEM_PARTY_MEMBER_NOT_SUMMONED);
  4588. break;
  4589. }
  4590. ARR_FIND(0, MAX_PARTY, i, pd->data[i].sd && pd->data[i].sd != sd && pd->data[i].sd->bl.m == sd->bl.m && !pc_isdead(pd->data[i].sd));
  4591. if (i == MAX_PARTY) { // No party members found on same map
  4592. clif_msg(sd, ITEM_PARTY_NO_MEMBER_IN_MAP);
  4593. break;
  4594. }
  4595. } else {
  4596. clif_msg(sd, ITEM_PARTY_MEMBER_NOT_SUMMONED);
  4597. break;
  4598. }
  4599. }
  4600. // Fall through
  4601. case ITEMID_WING_OF_BUTTERFLY:
  4602. case ITEMID_N_BUTTERFLY_WING:
  4603. case ITEMID_DUN_TELE_SCROLL1:
  4604. case ITEMID_DUN_TELE_SCROLL2:
  4605. case ITEMID_DUN_TELE_SCROLL3:
  4606. case ITEMID_WOB_RUNE:
  4607. case ITEMID_WOB_SCHWALTZ:
  4608. case ITEMID_WOB_RACHEL:
  4609. case ITEMID_WOB_LOCAL:
  4610. case ITEMID_SIEGE_TELEPORT_SCROLL:
  4611. if( sd->duel_group && !battle_config.duel_allow_teleport ) {
  4612. clif_displaymessage(sd->fd, msg_txt(sd,663));
  4613. return false;
  4614. }
  4615. if( mapdata->flag[MF_NORETURN] && nameid != ITEMID_WING_OF_FLY && nameid != ITEMID_GIANT_FLY_WING && nameid != ITEMID_N_FLY_WING )
  4616. return false;
  4617. break;
  4618. case ITEMID_MERCENARY_RED_POTION:
  4619. case ITEMID_MERCENARY_BLUE_POTION:
  4620. case ITEMID_M_CENTER_POTION:
  4621. case ITEMID_M_AWAKENING_POTION:
  4622. case ITEMID_M_BERSERK_POTION:
  4623. if( sd->md == NULL || sd->md->db == NULL )
  4624. return false;
  4625. if( sd->md->sc.data[SC_BERSERK] )
  4626. return false;
  4627. if( nameid == ITEMID_M_AWAKENING_POTION && sd->md->db->lv < 40 )
  4628. return false;
  4629. if( nameid == ITEMID_M_BERSERK_POTION && sd->md->db->lv < 80 )
  4630. return false;
  4631. break;
  4632. case ITEMID_NEURALIZER:
  4633. if( !mapdata->flag[MF_RESET] )
  4634. return false;
  4635. break;
  4636. }
  4637. if( itemdb_group_item_exists(IG_MERCENARY, nameid) && sd->md != NULL )
  4638. return false; // Mercenary Scrolls
  4639. if( item->flag.group || item->type == IT_CASH) { //safe check type cash disappear when overweight [Napster]
  4640. if( pc_is90overweight(sd) ) {
  4641. clif_msg(sd, ITEM_CANT_OBTAIN_WEIGHT);
  4642. return false;
  4643. }
  4644. if( !pc_inventoryblank(sd) ) {
  4645. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 732), false, SELF); //Item cannot be open when inventory is full
  4646. return false;
  4647. }
  4648. }
  4649. //Gender check
  4650. if(item->sex != 2 && sd->status.sex != item->sex)
  4651. return false;
  4652. //Required level check
  4653. if(item->elv && sd->status.base_level < (unsigned int)item->elv)
  4654. return false;
  4655. if(item->elvmax && sd->status.base_level > (unsigned int)item->elvmax)
  4656. return false;
  4657. //Not equipable by class. [Skotlex]
  4658. if (!(
  4659. (1ULL<<(sd->class_&MAPID_BASEMASK)) &
  4660. (item->class_base[sd->class_&JOBL_2_1?1:(sd->class_&JOBL_2_2?2:0)])
  4661. ))
  4662. return false;
  4663. if (sd->sc.count && (
  4664. sd->sc.data[SC_BERSERK] || sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  4665. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF) ||
  4666. sd->sc.data[SC_TRICKDEAD] ||
  4667. sd->sc.data[SC_HIDING] ||
  4668. sd->sc.data[SC__SHADOWFORM] ||
  4669. sd->sc.data[SC__INVISIBILITY] ||
  4670. sd->sc.data[SC__MANHOLE] ||
  4671. sd->sc.data[SC_DEEPSLEEP] ||
  4672. sd->sc.data[SC_CRYSTALIZE] ||
  4673. sd->sc.data[SC_KAGEHUMI] ||
  4674. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM) ||
  4675. sd->sc.data[SC_KINGS_GRACE] ||
  4676. sd->sc.data[SC_SUHIDE]))
  4677. return false;
  4678. if (!pc_isItemClass(sd,item))
  4679. return false;
  4680. //Dead Branch items
  4681. if( item->flag.dead_branch )
  4682. log_branch(sd);
  4683. return true;
  4684. }
  4685. /*==========================================
  4686. * Last checks to use an item.
  4687. * Return:
  4688. * 0 = fail
  4689. * 1 = success
  4690. *------------------------------------------*/
  4691. int pc_useitem(struct map_session_data *sd,int n)
  4692. {
  4693. t_tick tick = gettick();
  4694. int amount;
  4695. unsigned short nameid;
  4696. struct script_code *script;
  4697. struct item item;
  4698. struct item_data *id;
  4699. nullpo_ret(sd);
  4700. if (sd->state.mail_writing)
  4701. return 0;
  4702. if (sd->npc_id) {
  4703. if (sd->progressbar.npc_id) {
  4704. clif_progressbar_abort(sd);
  4705. return 0; // First item use attempt cancels the progress bar
  4706. }
  4707. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag ){
  4708. #ifdef RENEWAL
  4709. clif_msg( sd, WORK_IN_PROGRESS );
  4710. #endif
  4711. return 0;
  4712. }
  4713. }
  4714. item = sd->inventory.u.items_inventory[n];
  4715. id = sd->inventory_data[n];
  4716. if (item.nameid == 0 || item.amount <= 0)
  4717. return 0;
  4718. if( !pc_isUseitem(sd,n) )
  4719. return 0;
  4720. // Store information for later use before it is lost (via pc_delitem) [Paradox924X]
  4721. nameid = id->nameid;
  4722. if (nameid != ITEMID_NAUTHIZ && sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  4723. return 0;
  4724. /* Items with delayed consume are not meant to work while in mounts except reins of mount(12622) */
  4725. if( id->flag.delay_consume ) {
  4726. if( nameid != ITEMID_REINS_OF_MOUNT && sd->sc.data[SC_ALL_RIDING] )
  4727. return 0;
  4728. else if( pc_issit(sd) )
  4729. return 0;
  4730. }
  4731. //Since most delay-consume items involve using a "skill-type" target cursor,
  4732. //perform a skill-use check before going through. [Skotlex]
  4733. //resurrection was picked as testing skill, as a non-offensive, generic skill, it will do.
  4734. //FIXME: Is this really needed here? It'll be checked in unit.cpp after all and this prevents skill items using when silenced [Inkfish]
  4735. if( id->flag.delay_consume && ( sd->ud.skilltimer != INVALID_TIMER /*|| !status_check_skilluse(&sd->bl, &sd->bl, ALL_RESURRECTION, 0)*/ ) )
  4736. return 0;
  4737. if( id->delay > 0 && !pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL) && pc_itemcd_check(sd, id, tick, n))
  4738. return 0;
  4739. /* on restricted maps the item is consumed but the effect is not used */
  4740. if (!pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL) && itemdb_isNoEquip(id,sd->bl.m)) {
  4741. clif_msg(sd,ITEM_CANT_USE_AREA); // This item cannot be used within this area
  4742. if( battle_config.allow_consume_restricted_item && !id->flag.delay_consume ) { //need confirmation for delayed consumption items
  4743. clif_useitemack(sd,n,item.amount-1,true);
  4744. pc_delitem(sd,n,1,1,0,LOG_TYPE_CONSUME);
  4745. }
  4746. return 0;/* regardless, effect is not run */
  4747. }
  4748. sd->itemid = item.nameid;
  4749. sd->itemindex = n;
  4750. if(sd->catch_target_class != PET_CATCH_FAIL) //Abort pet catching.
  4751. sd->catch_target_class = PET_CATCH_FAIL;
  4752. amount = item.amount;
  4753. script = id->script;
  4754. //Check if the item is to be consumed immediately [Skotlex]
  4755. if (id->flag.delay_consume)
  4756. clif_useitemack(sd, n, amount, true);
  4757. else
  4758. {
  4759. if( item.expire_time == 0 && nameid != ITEMID_REINS_OF_MOUNT )
  4760. {
  4761. clif_useitemack(sd, n, amount - 1, true);
  4762. pc_delitem(sd, n, 1, 1, 0, LOG_TYPE_CONSUME); // Rental Usable Items are not deleted until expiration
  4763. }
  4764. else
  4765. clif_useitemack(sd, n, 0, false);
  4766. }
  4767. if (item.card[0]==CARD0_CREATE && pc_famerank(MakeDWord(item.card[2],item.card[3]), MAPID_ALCHEMIST))
  4768. potion_flag = 2; // Famous player's potions have 50% more efficiency
  4769. //Update item use time.
  4770. sd->canuseitem_tick = tick + battle_config.item_use_interval;
  4771. if( itemdb_group_item_exists(IG_CASH_FOOD, nameid) )
  4772. sd->canusecashfood_tick = tick + battle_config.cashfood_use_interval;
  4773. run_script(script,0,sd->bl.id,fake_nd->bl.id);
  4774. potion_flag = 0;
  4775. return 1;
  4776. }
  4777. /**
  4778. * Add item on cart for given index.
  4779. * @param sd
  4780. * @param item
  4781. * @param amount
  4782. * @param log_type
  4783. * @return See pc.hpp::e_additem_result
  4784. */
  4785. enum e_additem_result pc_cart_additem(struct map_session_data *sd,struct item *item,int amount,e_log_pick_type log_type)
  4786. {
  4787. struct item_data *data;
  4788. int i,w;
  4789. nullpo_retr(ADDITEM_INVALID, sd);
  4790. nullpo_retr(ADDITEM_INVALID, item);
  4791. if(item->nameid == 0 || amount <= 0)
  4792. return ADDITEM_INVALID;
  4793. if (itemdb_ishatched_egg(item))
  4794. return ADDITEM_INVALID;
  4795. data = itemdb_search(item->nameid);
  4796. if( data->stack.cart && amount > data->stack.amount )
  4797. {// item stack limitation
  4798. return ADDITEM_STACKLIMIT;
  4799. }
  4800. if( !itemdb_cancartstore(item, pc_get_group_level(sd)) || (item->bound > BOUND_ACCOUNT && !pc_can_give_bounded_items(sd)))
  4801. { // Check item trade restrictions [Skotlex]
  4802. clif_displaymessage (sd->fd, msg_txt(sd,264));
  4803. return ADDITEM_INVALID;
  4804. }
  4805. if( (w = data->weight*amount) + sd->cart_weight > sd->cart_weight_max )
  4806. return ADDITEM_OVERWEIGHT;
  4807. i = MAX_CART;
  4808. if( itemdb_isstackable2(data) && !item->expire_time )
  4809. {
  4810. for (i = 0; i < MAX_CART; i++) {
  4811. if (sd->cart.u.items_cart[i].nameid == item->nameid
  4812. && sd->cart.u.items_cart[i].bound == item->bound
  4813. && sd->cart.u.items_cart[i].unique_id == item->unique_id
  4814. && memcmp(sd->cart.u.items_cart[i].card, item->card, sizeof(item->card)) == 0
  4815. )
  4816. break;
  4817. }
  4818. }
  4819. if( i < MAX_CART )
  4820. {// item already in cart, stack it
  4821. if( amount > MAX_AMOUNT - sd->cart.u.items_cart[i].amount || ( data->stack.cart && amount > data->stack.amount - sd->cart.u.items_cart[i].amount ) )
  4822. return ADDITEM_OVERAMOUNT; // no slot
  4823. sd->cart.u.items_cart[i].amount += amount;
  4824. clif_cart_additem(sd,i,amount,0);
  4825. }
  4826. else
  4827. {// item not stackable or not present, add it
  4828. ARR_FIND( 0, MAX_CART, i, sd->cart.u.items_cart[i].nameid == 0 );
  4829. if( i == MAX_CART )
  4830. return ADDITEM_OVERAMOUNT; // no slot
  4831. memcpy(&sd->cart.u.items_cart[i],item,sizeof(sd->cart.u.items_cart[0]));
  4832. sd->cart.u.items_cart[i].id = 0;
  4833. sd->cart.u.items_cart[i].amount = amount;
  4834. sd->cart_num++;
  4835. clif_cart_additem(sd,i,amount,0);
  4836. }
  4837. sd->cart.u.items_cart[i].favorite = 0; // clear
  4838. sd->cart.u.items_cart[i].equipSwitch = 0;
  4839. log_pick_pc(sd, log_type, amount, &sd->cart.u.items_cart[i]);
  4840. sd->cart_weight += w;
  4841. clif_updatestatus(sd,SP_CARTINFO);
  4842. return ADDITEM_SUCCESS;
  4843. }
  4844. /*==========================================
  4845. * Delete item on cart for given index.
  4846. *------------------------------------------*/
  4847. void pc_cart_delitem(struct map_session_data *sd,int n,int amount,int type,e_log_pick_type log_type)
  4848. {
  4849. nullpo_retv(sd);
  4850. if(sd->cart.u.items_cart[n].nameid == 0 ||
  4851. sd->cart.u.items_cart[n].amount < amount)
  4852. return;
  4853. log_pick_pc(sd, log_type, -amount, &sd->cart.u.items_cart[n]);
  4854. sd->cart.u.items_cart[n].amount -= amount;
  4855. sd->cart_weight -= itemdb_weight(sd->cart.u.items_cart[n].nameid) * amount;
  4856. if(sd->cart.u.items_cart[n].amount <= 0) {
  4857. memset(&sd->cart.u.items_cart[n],0,sizeof(sd->cart.u.items_cart[0]));
  4858. sd->cart_num--;
  4859. }
  4860. if(!type) {
  4861. clif_cart_delitem(sd,n,amount);
  4862. clif_updatestatus(sd,SP_CARTINFO);
  4863. }
  4864. }
  4865. /*==========================================
  4866. * Transfer item from inventory to cart.
  4867. *------------------------------------------*/
  4868. void pc_putitemtocart(struct map_session_data *sd,int idx,int amount)
  4869. {
  4870. nullpo_retv(sd);
  4871. if (idx < 0 || idx >= MAX_INVENTORY) //Invalid index check [Skotlex]
  4872. return;
  4873. struct item *item_data = &sd->inventory.u.items_inventory[idx];
  4874. if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending || sd->state.prevend )
  4875. return;
  4876. if( item_data->equipSwitch ){
  4877. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  4878. return;
  4879. }
  4880. enum e_additem_result flag = pc_cart_additem(sd,item_data,amount,LOG_TYPE_NONE);
  4881. if (flag == ADDITEM_SUCCESS)
  4882. pc_delitem(sd,idx,amount,0,5,LOG_TYPE_NONE);
  4883. else {
  4884. clif_cart_additem_ack(sd, (flag == ADDITEM_OVERAMOUNT) ? ADDITEM_TO_CART_FAIL_COUNT : ADDITEM_TO_CART_FAIL_WEIGHT);
  4885. clif_additem(sd, idx, amount, 0);
  4886. clif_delitem(sd, idx, amount, 0);
  4887. }
  4888. }
  4889. /*==========================================
  4890. * Get number of item in cart.
  4891. * Return:
  4892. -1 = itemid not found or no amount found
  4893. x = remaining itemid on cart after get
  4894. *------------------------------------------*/
  4895. int pc_cartitem_amount(struct map_session_data* sd, int idx, int amount)
  4896. {
  4897. struct item* item_data;
  4898. nullpo_retr(-1, sd);
  4899. item_data = &sd->cart.u.items_cart[idx];
  4900. if( item_data->nameid == 0 || item_data->amount == 0 )
  4901. return -1;
  4902. return item_data->amount - amount;
  4903. }
  4904. /*==========================================
  4905. * Retrieve an item at index idx from cart.
  4906. *------------------------------------------*/
  4907. void pc_getitemfromcart(struct map_session_data *sd,int idx,int amount)
  4908. {
  4909. nullpo_retv(sd);
  4910. if (idx < 0 || idx >= MAX_CART) //Invalid index check [Skotlex]
  4911. return;
  4912. struct item *item_data=&sd->cart.u.items_cart[idx];
  4913. if (item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending || sd->state.prevend)
  4914. return;
  4915. enum e_additem_result flag = pc_additem(sd, item_data, amount, LOG_TYPE_NONE);
  4916. if (flag == ADDITEM_SUCCESS)
  4917. pc_cart_delitem(sd, idx, amount, 0, LOG_TYPE_NONE);
  4918. else {
  4919. clif_cart_delitem(sd, idx, amount);
  4920. clif_additem(sd, idx, amount, flag);
  4921. clif_cart_additem(sd, idx, amount, 0);
  4922. }
  4923. }
  4924. /*==========================================
  4925. * Bound Item Check
  4926. * Type:
  4927. * 1 Account Bound
  4928. * 2 Guild Bound
  4929. * 3 Party Bound
  4930. * 4 Character Bound
  4931. *------------------------------------------*/
  4932. int pc_bound_chk(TBL_PC *sd,enum bound_type type,int *idxlist)
  4933. {
  4934. int i = 0, j = 0;
  4935. for(i = 0; i < MAX_INVENTORY; i++) {
  4936. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].amount > 0 && sd->inventory.u.items_inventory[i].bound == type) {
  4937. idxlist[j] = i;
  4938. j++;
  4939. }
  4940. }
  4941. return j;
  4942. }
  4943. /*==========================================
  4944. * Display item stolen msg to player sd
  4945. *------------------------------------------*/
  4946. int pc_show_steal(struct block_list *bl,va_list ap)
  4947. {
  4948. struct map_session_data *sd;
  4949. int itemid;
  4950. struct item_data *item=NULL;
  4951. char output[100];
  4952. sd=va_arg(ap,struct map_session_data *);
  4953. itemid=va_arg(ap,int);
  4954. if((item=itemdb_exists(itemid))==NULL)
  4955. sprintf(output,"%s stole an Unknown Item (id: %i).",sd->status.name, itemid);
  4956. else
  4957. sprintf(output,"%s stole %s.",sd->status.name,item->jname);
  4958. clif_displaymessage( ((struct map_session_data *)bl)->fd, output);
  4959. return 0;
  4960. }
  4961. /**
  4962. * Steal an item from bl (mob).
  4963. * @param sd: Player data
  4964. * @param bl: Object to steal from
  4965. * @param skill_lv: Level of skill used
  4966. * @return True on success or false otherwise
  4967. */
  4968. bool pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv)
  4969. {
  4970. int i,itemid;
  4971. double rate;
  4972. unsigned char flag = 0;
  4973. struct status_data *sd_status, *md_status;
  4974. struct mob_data *md;
  4975. struct item tmp_item;
  4976. if(!sd || !bl || bl->type!=BL_MOB)
  4977. return false;
  4978. md = (TBL_MOB *)bl;
  4979. if(md->state.steal_flag == UCHAR_MAX || ( md->sc.opt1 && md->sc.opt1 != OPT1_BURNING ) ) //already stolen from / status change check
  4980. return false;
  4981. sd_status= status_get_status_data(&sd->bl);
  4982. md_status= status_get_status_data(bl);
  4983. if (md->master_id || status_has_mode(md_status, MD_STATUS_IMMUNE) || status_get_race2(&md->bl) == RC2_TREASURE ||
  4984. map_getmapflag(bl->m, MF_NOMOBLOOT) || // check noloot map flag [Lorky]
  4985. (battle_config.skill_steal_max_tries && //Reached limit of steal attempts. [Lupus]
  4986. md->state.steal_flag++ >= battle_config.skill_steal_max_tries)
  4987. ) { //Can't steal from
  4988. md->state.steal_flag = UCHAR_MAX;
  4989. return false;
  4990. }
  4991. // base skill success chance (percentual)
  4992. rate = (sd_status->dex - md_status->dex)/2 + skill_lv*6 + 4;
  4993. rate += sd->bonus.add_steal_rate;
  4994. if( rate < 1
  4995. #ifdef RENEWAL
  4996. || rnd()%100 >= rate
  4997. #endif
  4998. )
  4999. return false;
  5000. // Try dropping one item, in the order from first to last possible slot.
  5001. // Droprate is affected by the skill success rate.
  5002. for( i = 0; i < MAX_STEAL_DROP; i++ )
  5003. if( md->db->dropitem[i].nameid > 0 && !md->db->dropitem[i].steal_protected && itemdb_exists(md->db->dropitem[i].nameid) && rnd() % 10000 < md->db->dropitem[i].p
  5004. #ifndef RENEWAL
  5005. * rate/100.
  5006. #endif
  5007. )
  5008. break;
  5009. if( i == MAX_STEAL_DROP )
  5010. return false;
  5011. itemid = md->db->dropitem[i].nameid;
  5012. memset(&tmp_item,0,sizeof(tmp_item));
  5013. tmp_item.nameid = itemid;
  5014. tmp_item.amount = 1;
  5015. tmp_item.identify = itemdb_isidentified(itemid);
  5016. mob_setdropitem_option(&tmp_item, &md->db->dropitem[i]);
  5017. flag = pc_additem(sd,&tmp_item,1,LOG_TYPE_PICKDROP_PLAYER);
  5018. //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?
  5019. md->state.steal_flag = UCHAR_MAX; //you can't steal from this mob any more
  5020. if(flag) { //Failed to steal due to overweight
  5021. clif_additem(sd,0,0,flag);
  5022. return false;
  5023. }
  5024. if(battle_config.show_steal_in_same_party)
  5025. party_foreachsamemap(pc_show_steal,sd,AREA_SIZE,sd,tmp_item.nameid);
  5026. //Logs items, Stolen from mobs [Lupus]
  5027. log_pick_mob(md, LOG_TYPE_STEAL, -1, &tmp_item);
  5028. //A Rare Steal Global Announce by Lupus
  5029. if(md->db->dropitem[i].p<=battle_config.rare_drop_announce) {
  5030. struct item_data *i_data;
  5031. char message[128];
  5032. i_data = itemdb_search(itemid);
  5033. sprintf (message, msg_txt(sd,542), (sd->status.name[0])?sd->status.name :"GM", md->db->jname, i_data->jname, (float)md->db->dropitem[i].p/100);
  5034. //MSG: "'%s' stole %s's %s (chance: %0.02f%%)"
  5035. intif_broadcast(message, strlen(message) + 1, BC_DEFAULT);
  5036. }
  5037. return true;
  5038. }
  5039. /*==========================================
  5040. * Stole zeny from bl (mob)
  5041. * return
  5042. * 0 = fail
  5043. * 1 = success
  5044. *------------------------------------------*/
  5045. int pc_steal_coin(struct map_session_data *sd,struct block_list *target)
  5046. {
  5047. int rate, target_lv;
  5048. struct mob_data *md;
  5049. if(!sd || !target || target->type != BL_MOB)
  5050. return 0;
  5051. md = (TBL_MOB*)target;
  5052. target_lv = status_get_lv(target);
  5053. if (md->state.steal_coin_flag || md->sc.data[SC_STONE] || md->sc.data[SC_FREEZE] || status_bl_has_mode(target,MD_STATUS_IMMUNE) || status_get_race2(&md->bl) == RC2_TREASURE)
  5054. return 0;
  5055. rate = sd->battle_status.dex / 2 + 2 * (sd->status.base_level - target_lv) + (10 * pc_checkskill(sd, RG_STEALCOIN)) + sd->battle_status.luk / 2;
  5056. if(rnd()%1000 < rate)
  5057. {
  5058. // Zeny Steal Amount: (rnd() % (10 * target_lv + 1 - 8 * target_lv)) + 8 * target_lv
  5059. int amount = (rnd() % (2 * target_lv + 1)) + 8 * target_lv; // Reduced formula
  5060. pc_getzeny(sd, amount, LOG_TYPE_STEAL, NULL);
  5061. md->state.steal_coin_flag = 1;
  5062. return 1;
  5063. }
  5064. return 0;
  5065. }
  5066. /*==========================================
  5067. * Set's a player position.
  5068. * @param sd
  5069. * @param mapindex
  5070. * @param x
  5071. * @param y
  5072. * @param clrtype
  5073. * @return SETPOS_OK Success
  5074. * SETPOS_MAPINDEX Invalid map index
  5075. * SETPOS_NO_MAPSERVER Map not in this map-server, and failed to locate alternate map-server.
  5076. * SETPOS_AUTOTRADE Player is in autotrade state
  5077. *------------------------------------------*/
  5078. enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype)
  5079. {
  5080. nullpo_retr(SETPOS_OK,sd);
  5081. if( !mapindex || !mapindex_id2name(mapindex) ) {
  5082. ShowDebug("pc_setpos: Passed mapindex(%d) is invalid!\n", mapindex);
  5083. return SETPOS_MAPINDEX;
  5084. }
  5085. if ( sd->state.autotrade && (sd->vender_id || sd->buyer_id) ) // Player with autotrade just causes clif glitch! @ FIXME
  5086. return SETPOS_AUTOTRADE;
  5087. if( battle_config.revive_onwarp && pc_isdead(sd) ) { //Revive dead people before warping them
  5088. pc_setstand(sd, true);
  5089. pc_setrestartvalue(sd,1);
  5090. }
  5091. int16 m = map_mapindex2mapid(mapindex);
  5092. struct map_data *mapdata = map_getmapdata(m);
  5093. status_change *sc = status_get_sc(&sd->bl);
  5094. sd->state.changemap = (sd->mapindex != mapindex);
  5095. sd->state.warping = 1;
  5096. sd->state.workinprogress = WIP_DISABLE_NONE;
  5097. if( sd->state.changemap ) { // Misc map-changing settings
  5098. unsigned short curr_map_instance_id = map_getmapdata(sd->bl.m)->instance_id, new_map_instance_id = (mapdata ? mapdata->instance_id : 0);
  5099. if (curr_map_instance_id != new_map_instance_id) {
  5100. if (curr_map_instance_id) // Update instance timer for the map on leave
  5101. instance_delusers(curr_map_instance_id);
  5102. if (new_map_instance_id) // Update instance timer for the map on enter
  5103. instance_addusers(new_map_instance_id);
  5104. }
  5105. if (sd->bg_id && !mapdata->flag[MF_BATTLEGROUND]) // Moving to a map that isn't a Battlegrounds
  5106. bg_team_leave(sd, false, true);
  5107. sd->state.pmap = sd->bl.m;
  5108. if (sc && sc->count) { // Cancel some map related stuff.
  5109. if (sc->data[SC_JAILED])
  5110. return SETPOS_MAPINDEX; //You may not get out!
  5111. status_change_end(&sd->bl, SC_BOSSMAPINFO, INVALID_TIMER);
  5112. status_change_end(&sd->bl, SC_WARM, INVALID_TIMER);
  5113. status_change_end(&sd->bl, SC_SUN_COMFORT, INVALID_TIMER);
  5114. status_change_end(&sd->bl, SC_MOON_COMFORT, INVALID_TIMER);
  5115. status_change_end(&sd->bl, SC_STAR_COMFORT, INVALID_TIMER);
  5116. status_change_end(&sd->bl, SC_MIRACLE, INVALID_TIMER);
  5117. if (sc->data[SC_KNOWLEDGE]) {
  5118. struct status_change_entry *sce = sc->data[SC_KNOWLEDGE];
  5119. if (sce->timer != INVALID_TIMER)
  5120. delete_timer(sce->timer, status_change_timer);
  5121. sce->timer = add_timer(gettick() + skill_get_time(SG_KNOWLEDGE, sce->val1), status_change_timer, sd->bl.id, SC_KNOWLEDGE);
  5122. }
  5123. status_change_end(&sd->bl, SC_PROPERTYWALK, INVALID_TIMER);
  5124. status_change_end(&sd->bl, SC_CLOAKING, INVALID_TIMER);
  5125. status_change_end(&sd->bl, SC_CLOAKINGEXCEED, INVALID_TIMER);
  5126. }
  5127. for(int i = 0; i < EQI_MAX; i++ ) {
  5128. if( sd->equip_index[i] >= 0 )
  5129. if( pc_isequip(sd,sd->equip_index[i]) )
  5130. pc_unequipitem(sd,sd->equip_index[i],2);
  5131. }
  5132. if (battle_config.clear_unit_onwarp&BL_PC)
  5133. skill_clear_unitgroup(&sd->bl);
  5134. party_send_dot_remove(sd); //minimap dot fix [Kevin]
  5135. guild_send_dot_remove(sd);
  5136. bg_send_dot_remove(sd);
  5137. if (sd->regen.state.gc)
  5138. sd->regen.state.gc = 0;
  5139. // make sure vending is allowed here
  5140. if (sd->state.vending && mapdata->flag[MF_NOVENDING]) {
  5141. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  5142. vending_closevending(sd);
  5143. }
  5144. channel_pcquit(sd,4); //quit map chan
  5145. // Remove Cloaked NPC if changing to another map
  5146. for (auto it = sd->cloaked_npc.begin(); it != sd->cloaked_npc.end(); ++it) {
  5147. block_list *npc_bl = map_id2bl(*it);
  5148. if (npc_bl && npc_bl->m != m) {
  5149. sd->cloaked_npc.erase(it);
  5150. break;
  5151. }
  5152. }
  5153. }
  5154. if( m < 0 )
  5155. {
  5156. uint32 ip;
  5157. uint16 port;
  5158. struct script_state *st;
  5159. //if can't find any map-servers, just abort setting position.
  5160. if(!sd->mapindex || map_mapname2ipport(mapindex,&ip,&port))
  5161. return SETPOS_NO_MAPSERVER;
  5162. if (sd->npc_id){
  5163. npc_event_dequeue(sd,false);
  5164. st = sd->st;
  5165. }else{
  5166. st = nullptr;
  5167. }
  5168. npc_script_event(sd, NPCE_LOGOUT);
  5169. //remove from map, THEN change x/y coordinates
  5170. unit_remove_map_pc(sd,clrtype);
  5171. sd->mapindex = mapindex;
  5172. sd->bl.x=x;
  5173. sd->bl.y=y;
  5174. pc_clean_skilltree(sd);
  5175. chrif_save(sd, CSAVE_CHANGE_MAPSERV|CSAVE_INVENTORY|CSAVE_CART);
  5176. chrif_changemapserver(sd, ip, (short)port);
  5177. //Free session data from this map server [Kevin]
  5178. unit_free_pc(sd);
  5179. if( st ){
  5180. // Has to be done here, because otherwise unit_free_pc will free the stack already
  5181. st->state = END;
  5182. }
  5183. return SETPOS_OK;
  5184. }
  5185. if( x < 0 || x >= mapdata->xs || y < 0 || y >= mapdata->ys )
  5186. {
  5187. 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);
  5188. x = y = 0; // make it random
  5189. }
  5190. if( x == 0 && y == 0 ) { // pick a random walkable cell
  5191. int c=0;
  5192. do {
  5193. x = rnd()%(mapdata->xs-2)+1;
  5194. y = rnd()%(mapdata->ys-2)+1;
  5195. c++;
  5196. if(c > (mapdata->xs * mapdata->ys)*3){ //force out
  5197. 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));
  5198. return SETPOS_OK; //preventing warp
  5199. //break; //allow warp anyway
  5200. }
  5201. } while(map_getcell(m,x,y,CELL_CHKNOPASS) || (!battle_config.teleport_on_portal && npc_check_areanpc(1,m,x,y,1)));
  5202. }
  5203. if (sd->state.vending && map_getcell(m,x,y,CELL_CHKNOVENDING)) {
  5204. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  5205. vending_closevending(sd);
  5206. }
  5207. if(sd->bl.prev != NULL){
  5208. unit_remove_map_pc(sd,clrtype);
  5209. clif_changemap(sd,m,x,y); // [MouseJstr]
  5210. } else if(sd->state.active) //Tag player for rewarping after map-loading is done. [Skotlex]
  5211. sd->state.rewarp = 1;
  5212. if (sc && sc->data[SC_HELLS_PLANT])
  5213. skill_unit_move_unit_group(skill_id2group(sc->data[SC_HELLS_PLANT]->val4), m, x - sd->bl.x, y - sd->bl.y);
  5214. sd->mapindex = mapindex;
  5215. sd->bl.m = m;
  5216. sd->bl.x = sd->ud.to_x = x;
  5217. sd->bl.y = sd->ud.to_y = y;
  5218. if( sd->status.guild_id > 0 && mapdata->flag[MF_GVG_CASTLE] )
  5219. { // Increased guild castle regen [Valaris]
  5220. struct guild_castle *gc = guild_mapindex2gc(sd->mapindex);
  5221. if(gc && gc->guild_id == sd->status.guild_id)
  5222. sd->regen.state.gc = 1;
  5223. }
  5224. if( sd->status.pet_id > 0 && sd->pd && sd->pd->pet.intimate > 0 )
  5225. {
  5226. sd->pd->bl.m = m;
  5227. sd->pd->bl.x = sd->pd->ud.to_x = x;
  5228. sd->pd->bl.y = sd->pd->ud.to_y = y;
  5229. sd->pd->ud.dir = sd->ud.dir;
  5230. }
  5231. if( hom_is_active(sd->hd) )
  5232. {
  5233. sd->hd->bl.m = m;
  5234. sd->hd->bl.x = sd->hd->ud.to_x = x;
  5235. sd->hd->bl.y = sd->hd->ud.to_y = y;
  5236. sd->hd->ud.dir = sd->ud.dir;
  5237. }
  5238. if( sd->md )
  5239. {
  5240. sd->md->bl.m = m;
  5241. sd->md->bl.x = sd->md->ud.to_x = x;
  5242. sd->md->bl.y = sd->md->ud.to_y = y;
  5243. sd->md->ud.dir = sd->ud.dir;
  5244. }
  5245. if( sd->ed ) {
  5246. sd->ed->bl.m = m;
  5247. sd->ed->bl.x = sd->ed->ud.to_x = x;
  5248. sd->ed->bl.y = sd->ed->ud.to_y = y;
  5249. sd->ed->ud.dir = sd->ud.dir;
  5250. }
  5251. pc_cell_basilica(sd);
  5252. //check if we gonna be rewarped [lighta]
  5253. if(npc_check_areanpc(1,m,x,y,0)){
  5254. sd->count_rewarp++;
  5255. }
  5256. else
  5257. sd->count_rewarp = 0;
  5258. return SETPOS_OK;
  5259. }
  5260. /*==========================================
  5261. * Warp player sd to random location on current map.
  5262. * May fail if no walkable cell found (1000 attempts).
  5263. * Return:
  5264. * 0 = Success
  5265. * 1,2,3 = Fail
  5266. *------------------------------------------*/
  5267. char pc_randomwarp(struct map_session_data *sd, clr_type type)
  5268. {
  5269. int x,y,i=0;
  5270. nullpo_ret(sd);
  5271. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  5272. if (mapdata->flag[MF_NOTELEPORT]) //Teleport forbidden
  5273. return 3;
  5274. do {
  5275. x = rnd()%(mapdata->xs-2)+1;
  5276. y = rnd()%(mapdata->ys-2)+1;
  5277. } while((map_getcell(sd->bl.m,x,y,CELL_CHKNOPASS) || (!battle_config.teleport_on_portal && npc_check_areanpc(1,sd->bl.m,x,y,1))) && (i++) < 1000);
  5278. if (i < 1000)
  5279. return pc_setpos(sd,mapdata->index,x,y,type);
  5280. return 3;
  5281. }
  5282. /*==========================================
  5283. * Records a memo point at sd's current position
  5284. * pos - entry to replace, (-1: shift oldest entry out)
  5285. *------------------------------------------*/
  5286. bool pc_memo(struct map_session_data* sd, int pos)
  5287. {
  5288. int skill;
  5289. nullpo_ret(sd);
  5290. // check mapflags
  5291. if( sd->bl.m >= 0 && (map_getmapflag(sd->bl.m, MF_NOMEMO) || map_getmapflag(sd->bl.m, MF_NOWARPTO)) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE) ) {
  5292. clif_skill_teleportmessage(sd, 1); // "Saved point cannot be memorized."
  5293. return false;
  5294. }
  5295. // check inputs
  5296. if( pos < -1 || pos >= MAX_MEMOPOINTS )
  5297. return false; // invalid input
  5298. // check required skill level
  5299. skill = pc_checkskill(sd, AL_WARP);
  5300. if( skill < 1 ) {
  5301. clif_skill_memomessage(sd,2); // "You haven't learned Warp."
  5302. return false;
  5303. }
  5304. if( skill < 2 || skill - 2 < pos ) {
  5305. clif_skill_memomessage(sd,1); // "Skill Level is not high enough."
  5306. return false;
  5307. }
  5308. if( pos == -1 )
  5309. {
  5310. uint8 i;
  5311. // prevent memo-ing the same map multiple times
  5312. ARR_FIND( 0, MAX_MEMOPOINTS, i, sd->status.memo_point[i].map == map_id2index(sd->bl.m) );
  5313. memmove(&sd->status.memo_point[1], &sd->status.memo_point[0], (u8min(i,MAX_MEMOPOINTS-1))*sizeof(struct point));
  5314. pos = 0;
  5315. }
  5316. if( map_getmapdata(sd->bl.m)->instance_id ) {
  5317. clif_displaymessage( sd->fd, msg_txt(sd,384) ); // You cannot create a memo in an instance.
  5318. return false;
  5319. }
  5320. sd->status.memo_point[pos].map = map_id2index(sd->bl.m);
  5321. sd->status.memo_point[pos].x = sd->bl.x;
  5322. sd->status.memo_point[pos].y = sd->bl.y;
  5323. clif_skill_memomessage(sd, 0);
  5324. return true;
  5325. }
  5326. //
  5327. // Skills
  5328. //
  5329. /**
  5330. * Get the skill current cooldown for player.
  5331. * (get the db base cooldown for skill + player specific cooldown)
  5332. * @param sd : player pointer
  5333. * @param id : skill id
  5334. * @param lv : skill lv
  5335. * @return player skill cooldown
  5336. */
  5337. int pc_get_skillcooldown(struct map_session_data *sd, uint16 skill_id, uint16 skill_lv) {
  5338. if (skill_id == SJ_NOVAEXPLOSING) {
  5339. struct status_change *sc = status_get_sc(&sd->bl);
  5340. if (sc && sc->data[SC_DIMENSION])
  5341. return 0;
  5342. }
  5343. int cooldown = skill_get_cooldown(skill_id, skill_lv);
  5344. if (cooldown == 0)
  5345. return 0;
  5346. if (skill_id == SU_TUNABELLY && pc_checkskill(sd, SU_SPIRITOFSEA))
  5347. cooldown -= skill_get_time(SU_TUNABELLY, skill_lv);
  5348. for (auto &it : sd->skillcooldown) {
  5349. if (it.id == skill_id) {
  5350. cooldown += it.val;
  5351. cooldown = max(0, cooldown);
  5352. break;
  5353. }
  5354. }
  5355. return cooldown;
  5356. }
  5357. /*==========================================
  5358. * Return player sd skill_lv learned for given skill
  5359. *------------------------------------------*/
  5360. uint8 pc_checkskill(struct map_session_data *sd, uint16 skill_id)
  5361. {
  5362. uint16 idx = 0;
  5363. if (sd == NULL)
  5364. return 0;
  5365. if ((idx = skill_get_index(skill_id)) == 0) {
  5366. ShowError("pc_checkskill: Invalid skill id %d (char_id=%d).\n", skill_id, sd->status.char_id);
  5367. return 0;
  5368. }
  5369. if (SKILL_CHK_GUILD(skill_id) ) {
  5370. struct guild *g;
  5371. if( sd->status.guild_id>0 && (g=sd->guild)!=NULL)
  5372. return guild_checkskill(g,skill_id);
  5373. return 0;
  5374. }
  5375. return (sd->status.skill[idx].id == skill_id) ? sd->status.skill[idx].lv : 0;
  5376. }
  5377. /**
  5378. * Check if we still have the correct weapon to continue the skill (actually status)
  5379. * If not ending it
  5380. * @param sd
  5381. * @return 0:error, 1:check done
  5382. */
  5383. static void pc_checkallowskill(struct map_session_data *sd)
  5384. {
  5385. const enum sc_type scw_list[] = {
  5386. SC_TWOHANDQUICKEN,
  5387. SC_ONEHAND,
  5388. SC_AURABLADE,
  5389. SC_PARRYING,
  5390. SC_SPEARQUICKEN,
  5391. SC_ADRENALINE,
  5392. SC_ADRENALINE2,
  5393. SC_DANCING,
  5394. SC_GATLINGFEVER,
  5395. };
  5396. uint8 i;
  5397. nullpo_retv(sd);
  5398. if(!sd->sc.count)
  5399. return;
  5400. for (i = 0; i < ARRAYLENGTH(scw_list); i++)
  5401. { // Skills requiring specific weapon types
  5402. if( scw_list[i] == SC_DANCING && !battle_config.dancing_weaponswitch_fix )
  5403. continue;
  5404. if(sd->sc.data[scw_list[i]] &&
  5405. !pc_check_weapontype(sd,skill_get_weapontype(status_sc2skill(scw_list[i]))))
  5406. status_change_end(&sd->bl, scw_list[i], INVALID_TIMER);
  5407. }
  5408. if(sd->sc.data[SC_SPURT] && sd->status.weapon)
  5409. // Spurt requires bare hands (feet, in fact xD)
  5410. status_change_end(&sd->bl, SC_SPURT, INVALID_TIMER);
  5411. if(sd->status.shield <= 0) { // Skills requiring a shield
  5412. const enum sc_type scs_list[] = {
  5413. SC_AUTOGUARD,
  5414. SC_DEFENDER,
  5415. SC_REFLECTSHIELD,
  5416. SC_REFLECTDAMAGE
  5417. };
  5418. for (i = 0; i < ARRAYLENGTH(scs_list); i++)
  5419. if(sd->sc.data[scs_list[i]])
  5420. status_change_end(&sd->bl, scs_list[i], INVALID_TIMER);
  5421. }
  5422. }
  5423. /*==========================================
  5424. * Return equipped index of item on player sd at pos
  5425. * Return
  5426. * -1 : Nothing equipped
  5427. * idx : (this index could be used in inventory to found item_data)
  5428. *------------------------------------------*/
  5429. short pc_checkequip(struct map_session_data *sd,int pos, bool checkall)
  5430. {
  5431. uint8 i;
  5432. nullpo_retr(-1, sd);
  5433. for(i=0;i<EQI_MAX;i++){
  5434. if(pos & equip_bitmask[i]){
  5435. if( checkall && ( pos&~equip_bitmask[i] ) != 0 && sd->equip_index[i] == -1 ){
  5436. // Check all if any match is found
  5437. continue;
  5438. }
  5439. return sd->equip_index[i];
  5440. }
  5441. }
  5442. return -1;
  5443. }
  5444. /*==========================================
  5445. * Check if sd has nameid equipped somewhere
  5446. * @sd : the player session
  5447. * @nameid : id of the item to check
  5448. * @min : : see pc.hpp enum equip_index from ? to @max
  5449. * @max : see pc.hpp enum equip_index for @min to ?
  5450. * -return true,false
  5451. *------------------------------------------*/
  5452. bool pc_checkequip2(struct map_session_data *sd, unsigned short nameid, int min, int max)
  5453. {
  5454. int i;
  5455. for(i = min; i < max; i++) {
  5456. if(equip_bitmask[i]) {
  5457. int idx = sd->equip_index[i];
  5458. if (sd->inventory.u.items_inventory[idx].nameid == nameid)
  5459. return true;
  5460. }
  5461. }
  5462. return false;
  5463. }
  5464. /*==========================================
  5465. * Convert's from the client's lame Job ID system
  5466. * to the map server's 'makes sense' system. [Skotlex]
  5467. *------------------------------------------*/
  5468. int pc_jobid2mapid(unsigned short b_class)
  5469. {
  5470. switch(b_class)
  5471. {
  5472. //Novice And 1-1 Jobs
  5473. case JOB_NOVICE: return MAPID_NOVICE;
  5474. case JOB_SWORDMAN: return MAPID_SWORDMAN;
  5475. case JOB_MAGE: return MAPID_MAGE;
  5476. case JOB_ARCHER: return MAPID_ARCHER;
  5477. case JOB_ACOLYTE: return MAPID_ACOLYTE;
  5478. case JOB_MERCHANT: return MAPID_MERCHANT;
  5479. case JOB_THIEF: return MAPID_THIEF;
  5480. case JOB_TAEKWON: return MAPID_TAEKWON;
  5481. case JOB_WEDDING: return MAPID_WEDDING;
  5482. case JOB_GUNSLINGER: return MAPID_GUNSLINGER;
  5483. case JOB_NINJA: return MAPID_NINJA;
  5484. case JOB_XMAS: return MAPID_XMAS;
  5485. case JOB_SUMMER: return MAPID_SUMMER;
  5486. case JOB_HANBOK: return MAPID_HANBOK;
  5487. case JOB_GANGSI: return MAPID_GANGSI;
  5488. case JOB_OKTOBERFEST: return MAPID_OKTOBERFEST;
  5489. case JOB_SUMMER2: return MAPID_SUMMER2;
  5490. //2-1 Jobs
  5491. case JOB_SUPER_NOVICE: return MAPID_SUPER_NOVICE;
  5492. case JOB_KNIGHT: return MAPID_KNIGHT;
  5493. case JOB_WIZARD: return MAPID_WIZARD;
  5494. case JOB_HUNTER: return MAPID_HUNTER;
  5495. case JOB_PRIEST: return MAPID_PRIEST;
  5496. case JOB_BLACKSMITH: return MAPID_BLACKSMITH;
  5497. case JOB_ASSASSIN: return MAPID_ASSASSIN;
  5498. case JOB_STAR_GLADIATOR: return MAPID_STAR_GLADIATOR;
  5499. case JOB_KAGEROU:
  5500. case JOB_OBORO: return MAPID_KAGEROUOBORO;
  5501. case JOB_REBELLION: return MAPID_REBELLION;
  5502. case JOB_DEATH_KNIGHT: return MAPID_DEATH_KNIGHT;
  5503. //2-2 Jobs
  5504. case JOB_CRUSADER: return MAPID_CRUSADER;
  5505. case JOB_SAGE: return MAPID_SAGE;
  5506. case JOB_BARD:
  5507. case JOB_DANCER: return MAPID_BARDDANCER;
  5508. case JOB_MONK: return MAPID_MONK;
  5509. case JOB_ALCHEMIST: return MAPID_ALCHEMIST;
  5510. case JOB_ROGUE: return MAPID_ROGUE;
  5511. case JOB_SOUL_LINKER: return MAPID_SOUL_LINKER;
  5512. case JOB_DARK_COLLECTOR: return MAPID_DARK_COLLECTOR;
  5513. //Trans Novice And Trans 1-1 Jobs
  5514. case JOB_NOVICE_HIGH: return MAPID_NOVICE_HIGH;
  5515. case JOB_SWORDMAN_HIGH: return MAPID_SWORDMAN_HIGH;
  5516. case JOB_MAGE_HIGH: return MAPID_MAGE_HIGH;
  5517. case JOB_ARCHER_HIGH: return MAPID_ARCHER_HIGH;
  5518. case JOB_ACOLYTE_HIGH: return MAPID_ACOLYTE_HIGH;
  5519. case JOB_MERCHANT_HIGH: return MAPID_MERCHANT_HIGH;
  5520. case JOB_THIEF_HIGH: return MAPID_THIEF_HIGH;
  5521. //Trans 2-1 Jobs
  5522. case JOB_LORD_KNIGHT: return MAPID_LORD_KNIGHT;
  5523. case JOB_HIGH_WIZARD: return MAPID_HIGH_WIZARD;
  5524. case JOB_SNIPER: return MAPID_SNIPER;
  5525. case JOB_HIGH_PRIEST: return MAPID_HIGH_PRIEST;
  5526. case JOB_WHITESMITH: return MAPID_WHITESMITH;
  5527. case JOB_ASSASSIN_CROSS: return MAPID_ASSASSIN_CROSS;
  5528. //Trans 2-2 Jobs
  5529. case JOB_PALADIN: return MAPID_PALADIN;
  5530. case JOB_PROFESSOR: return MAPID_PROFESSOR;
  5531. case JOB_CLOWN:
  5532. case JOB_GYPSY: return MAPID_CLOWNGYPSY;
  5533. case JOB_CHAMPION: return MAPID_CHAMPION;
  5534. case JOB_CREATOR: return MAPID_CREATOR;
  5535. case JOB_STALKER: return MAPID_STALKER;
  5536. //Baby Novice And Baby 1-1 Jobs
  5537. case JOB_BABY: return MAPID_BABY;
  5538. case JOB_BABY_SWORDMAN: return MAPID_BABY_SWORDMAN;
  5539. case JOB_BABY_MAGE: return MAPID_BABY_MAGE;
  5540. case JOB_BABY_ARCHER: return MAPID_BABY_ARCHER;
  5541. case JOB_BABY_ACOLYTE: return MAPID_BABY_ACOLYTE;
  5542. case JOB_BABY_MERCHANT: return MAPID_BABY_MERCHANT;
  5543. case JOB_BABY_THIEF: return MAPID_BABY_THIEF;
  5544. case JOB_BABY_TAEKWON: return MAPID_BABY_TAEKWON;
  5545. case JOB_BABY_GUNSLINGER: return MAPID_BABY_GUNSLINGER;
  5546. case JOB_BABY_NINJA: return MAPID_BABY_NINJA;
  5547. case JOB_BABY_SUMMONER: return MAPID_BABY_SUMMONER;
  5548. //Baby 2-1 Jobs
  5549. case JOB_SUPER_BABY: return MAPID_SUPER_BABY;
  5550. case JOB_BABY_KNIGHT: return MAPID_BABY_KNIGHT;
  5551. case JOB_BABY_WIZARD: return MAPID_BABY_WIZARD;
  5552. case JOB_BABY_HUNTER: return MAPID_BABY_HUNTER;
  5553. case JOB_BABY_PRIEST: return MAPID_BABY_PRIEST;
  5554. case JOB_BABY_BLACKSMITH: return MAPID_BABY_BLACKSMITH;
  5555. case JOB_BABY_ASSASSIN: return MAPID_BABY_ASSASSIN;
  5556. case JOB_BABY_STAR_GLADIATOR: return MAPID_BABY_STAR_GLADIATOR;
  5557. case JOB_BABY_REBELLION: return MAPID_BABY_REBELLION;
  5558. case JOB_BABY_KAGEROU:
  5559. case JOB_BABY_OBORO: return MAPID_BABY_KAGEROUOBORO;
  5560. //Baby 2-2 Jobs
  5561. case JOB_BABY_CRUSADER: return MAPID_BABY_CRUSADER;
  5562. case JOB_BABY_SAGE: return MAPID_BABY_SAGE;
  5563. case JOB_BABY_BARD:
  5564. case JOB_BABY_DANCER: return MAPID_BABY_BARDDANCER;
  5565. case JOB_BABY_MONK: return MAPID_BABY_MONK;
  5566. case JOB_BABY_ALCHEMIST: return MAPID_BABY_ALCHEMIST;
  5567. case JOB_BABY_ROGUE: return MAPID_BABY_ROGUE;
  5568. case JOB_BABY_SOUL_LINKER: return MAPID_BABY_SOUL_LINKER;
  5569. //3-1 Jobs
  5570. case JOB_SUPER_NOVICE_E: return MAPID_SUPER_NOVICE_E;
  5571. case JOB_RUNE_KNIGHT: return MAPID_RUNE_KNIGHT;
  5572. case JOB_WARLOCK: return MAPID_WARLOCK;
  5573. case JOB_RANGER: return MAPID_RANGER;
  5574. case JOB_ARCH_BISHOP: return MAPID_ARCH_BISHOP;
  5575. case JOB_MECHANIC: return MAPID_MECHANIC;
  5576. case JOB_GUILLOTINE_CROSS: return MAPID_GUILLOTINE_CROSS;
  5577. case JOB_STAR_EMPEROR: return MAPID_STAR_EMPEROR;
  5578. //3-2 Jobs
  5579. case JOB_ROYAL_GUARD: return MAPID_ROYAL_GUARD;
  5580. case JOB_SORCERER: return MAPID_SORCERER;
  5581. case JOB_MINSTREL:
  5582. case JOB_WANDERER: return MAPID_MINSTRELWANDERER;
  5583. case JOB_SURA: return MAPID_SURA;
  5584. case JOB_GENETIC: return MAPID_GENETIC;
  5585. case JOB_SHADOW_CHASER: return MAPID_SHADOW_CHASER;
  5586. case JOB_SOUL_REAPER: return MAPID_SOUL_REAPER;
  5587. //Trans 3-1 Jobs
  5588. case JOB_RUNE_KNIGHT_T: return MAPID_RUNE_KNIGHT_T;
  5589. case JOB_WARLOCK_T: return MAPID_WARLOCK_T;
  5590. case JOB_RANGER_T: return MAPID_RANGER_T;
  5591. case JOB_ARCH_BISHOP_T: return MAPID_ARCH_BISHOP_T;
  5592. case JOB_MECHANIC_T: return MAPID_MECHANIC_T;
  5593. case JOB_GUILLOTINE_CROSS_T: return MAPID_GUILLOTINE_CROSS_T;
  5594. //Trans 3-2 Jobs
  5595. case JOB_ROYAL_GUARD_T: return MAPID_ROYAL_GUARD_T;
  5596. case JOB_SORCERER_T: return MAPID_SORCERER_T;
  5597. case JOB_MINSTREL_T:
  5598. case JOB_WANDERER_T: return MAPID_MINSTRELWANDERER_T;
  5599. case JOB_SURA_T: return MAPID_SURA_T;
  5600. case JOB_GENETIC_T: return MAPID_GENETIC_T;
  5601. case JOB_SHADOW_CHASER_T: return MAPID_SHADOW_CHASER_T;
  5602. //Baby 3-1 Jobs
  5603. case JOB_SUPER_BABY_E: return MAPID_SUPER_BABY_E;
  5604. case JOB_BABY_RUNE_KNIGHT: return MAPID_BABY_RUNE_KNIGHT;
  5605. case JOB_BABY_WARLOCK: return MAPID_BABY_WARLOCK;
  5606. case JOB_BABY_RANGER: return MAPID_BABY_RANGER;
  5607. case JOB_BABY_ARCH_BISHOP: return MAPID_BABY_ARCH_BISHOP;
  5608. case JOB_BABY_MECHANIC: return MAPID_BABY_MECHANIC;
  5609. case JOB_BABY_GUILLOTINE_CROSS: return MAPID_BABY_GUILLOTINE_CROSS;
  5610. case JOB_BABY_STAR_EMPEROR: return MAPID_BABY_STAR_EMPEROR;
  5611. //Baby 3-2 Jobs
  5612. case JOB_BABY_ROYAL_GUARD: return MAPID_BABY_ROYAL_GUARD;
  5613. case JOB_BABY_SORCERER: return MAPID_BABY_SORCERER;
  5614. case JOB_BABY_MINSTREL:
  5615. case JOB_BABY_WANDERER: return MAPID_BABY_MINSTRELWANDERER;
  5616. case JOB_BABY_SURA: return MAPID_BABY_SURA;
  5617. case JOB_BABY_GENETIC: return MAPID_BABY_GENETIC;
  5618. case JOB_BABY_SHADOW_CHASER: return MAPID_BABY_SHADOW_CHASER;
  5619. case JOB_BABY_SOUL_REAPER: return MAPID_BABY_SOUL_REAPER;
  5620. //Doram Jobs
  5621. case JOB_SUMMONER: return MAPID_SUMMONER;
  5622. default:
  5623. return -1;
  5624. }
  5625. }
  5626. //Reverts the map-style class id to the client-style one.
  5627. int pc_mapid2jobid(unsigned short class_, int sex)
  5628. {
  5629. switch(class_) {
  5630. //Novice And 1-1 Jobs
  5631. case MAPID_NOVICE: return JOB_NOVICE;
  5632. case MAPID_SWORDMAN: return JOB_SWORDMAN;
  5633. case MAPID_MAGE: return JOB_MAGE;
  5634. case MAPID_ARCHER: return JOB_ARCHER;
  5635. case MAPID_ACOLYTE: return JOB_ACOLYTE;
  5636. case MAPID_MERCHANT: return JOB_MERCHANT;
  5637. case MAPID_THIEF: return JOB_THIEF;
  5638. case MAPID_TAEKWON: return JOB_TAEKWON;
  5639. case MAPID_WEDDING: return JOB_WEDDING;
  5640. case MAPID_GUNSLINGER: return JOB_GUNSLINGER;
  5641. case MAPID_NINJA: return JOB_NINJA;
  5642. case MAPID_XMAS: return JOB_XMAS;
  5643. case MAPID_SUMMER: return JOB_SUMMER;
  5644. case MAPID_HANBOK: return JOB_HANBOK;
  5645. case MAPID_GANGSI: return JOB_GANGSI;
  5646. case MAPID_OKTOBERFEST: return JOB_OKTOBERFEST;
  5647. case MAPID_SUMMER2: return JOB_SUMMER2;
  5648. //2-1 Jobs
  5649. case MAPID_SUPER_NOVICE: return JOB_SUPER_NOVICE;
  5650. case MAPID_KNIGHT: return JOB_KNIGHT;
  5651. case MAPID_WIZARD: return JOB_WIZARD;
  5652. case MAPID_HUNTER: return JOB_HUNTER;
  5653. case MAPID_PRIEST: return JOB_PRIEST;
  5654. case MAPID_BLACKSMITH: return JOB_BLACKSMITH;
  5655. case MAPID_ASSASSIN: return JOB_ASSASSIN;
  5656. case MAPID_STAR_GLADIATOR: return JOB_STAR_GLADIATOR;
  5657. case MAPID_KAGEROUOBORO: return sex?JOB_KAGEROU:JOB_OBORO;
  5658. case MAPID_REBELLION: return JOB_REBELLION;
  5659. case MAPID_DEATH_KNIGHT: return JOB_DEATH_KNIGHT;
  5660. //2-2 Jobs
  5661. case MAPID_CRUSADER: return JOB_CRUSADER;
  5662. case MAPID_SAGE: return JOB_SAGE;
  5663. case MAPID_BARDDANCER: return sex?JOB_BARD:JOB_DANCER;
  5664. case MAPID_MONK: return JOB_MONK;
  5665. case MAPID_ALCHEMIST: return JOB_ALCHEMIST;
  5666. case MAPID_ROGUE: return JOB_ROGUE;
  5667. case MAPID_SOUL_LINKER: return JOB_SOUL_LINKER;
  5668. case MAPID_DARK_COLLECTOR: return JOB_DARK_COLLECTOR;
  5669. //Trans Novice And Trans 2-1 Jobs
  5670. case MAPID_NOVICE_HIGH: return JOB_NOVICE_HIGH;
  5671. case MAPID_SWORDMAN_HIGH: return JOB_SWORDMAN_HIGH;
  5672. case MAPID_MAGE_HIGH: return JOB_MAGE_HIGH;
  5673. case MAPID_ARCHER_HIGH: return JOB_ARCHER_HIGH;
  5674. case MAPID_ACOLYTE_HIGH: return JOB_ACOLYTE_HIGH;
  5675. case MAPID_MERCHANT_HIGH: return JOB_MERCHANT_HIGH;
  5676. case MAPID_THIEF_HIGH: return JOB_THIEF_HIGH;
  5677. //Trans 2-1 Jobs
  5678. case MAPID_LORD_KNIGHT: return JOB_LORD_KNIGHT;
  5679. case MAPID_HIGH_WIZARD: return JOB_HIGH_WIZARD;
  5680. case MAPID_SNIPER: return JOB_SNIPER;
  5681. case MAPID_HIGH_PRIEST: return JOB_HIGH_PRIEST;
  5682. case MAPID_WHITESMITH: return JOB_WHITESMITH;
  5683. case MAPID_ASSASSIN_CROSS: return JOB_ASSASSIN_CROSS;
  5684. //Trans 2-2 Jobs
  5685. case MAPID_PALADIN: return JOB_PALADIN;
  5686. case MAPID_PROFESSOR: return JOB_PROFESSOR;
  5687. case MAPID_CLOWNGYPSY: return sex?JOB_CLOWN:JOB_GYPSY;
  5688. case MAPID_CHAMPION: return JOB_CHAMPION;
  5689. case MAPID_CREATOR: return JOB_CREATOR;
  5690. case MAPID_STALKER: return JOB_STALKER;
  5691. //Baby Novice And Baby 1-1 Jobs
  5692. case MAPID_BABY: return JOB_BABY;
  5693. case MAPID_BABY_SWORDMAN: return JOB_BABY_SWORDMAN;
  5694. case MAPID_BABY_MAGE: return JOB_BABY_MAGE;
  5695. case MAPID_BABY_ARCHER: return JOB_BABY_ARCHER;
  5696. case MAPID_BABY_ACOLYTE: return JOB_BABY_ACOLYTE;
  5697. case MAPID_BABY_MERCHANT: return JOB_BABY_MERCHANT;
  5698. case MAPID_BABY_THIEF: return JOB_BABY_THIEF;
  5699. case MAPID_BABY_TAEKWON: return JOB_BABY_TAEKWON;
  5700. case MAPID_BABY_GUNSLINGER: return JOB_BABY_GUNSLINGER;
  5701. case MAPID_BABY_NINJA: return JOB_BABY_NINJA;
  5702. case MAPID_BABY_SUMMONER: return JOB_BABY_SUMMONER;
  5703. //Baby 2-1 Jobs
  5704. case MAPID_SUPER_BABY: return JOB_SUPER_BABY;
  5705. case MAPID_BABY_KNIGHT: return JOB_BABY_KNIGHT;
  5706. case MAPID_BABY_WIZARD: return JOB_BABY_WIZARD;
  5707. case MAPID_BABY_HUNTER: return JOB_BABY_HUNTER;
  5708. case MAPID_BABY_PRIEST: return JOB_BABY_PRIEST;
  5709. case MAPID_BABY_BLACKSMITH: return JOB_BABY_BLACKSMITH;
  5710. case MAPID_BABY_ASSASSIN: return JOB_BABY_ASSASSIN;
  5711. case MAPID_BABY_STAR_GLADIATOR: return JOB_BABY_STAR_GLADIATOR;
  5712. case MAPID_BABY_REBELLION: return JOB_BABY_REBELLION;
  5713. case MAPID_BABY_KAGEROUOBORO: return sex?JOB_BABY_KAGEROU:JOB_BABY_OBORO;
  5714. //Baby 2-2 Jobs
  5715. case MAPID_BABY_CRUSADER: return JOB_BABY_CRUSADER;
  5716. case MAPID_BABY_SAGE: return JOB_BABY_SAGE;
  5717. case MAPID_BABY_BARDDANCER: return sex?JOB_BABY_BARD:JOB_BABY_DANCER;
  5718. case MAPID_BABY_MONK: return JOB_BABY_MONK;
  5719. case MAPID_BABY_ALCHEMIST: return JOB_BABY_ALCHEMIST;
  5720. case MAPID_BABY_ROGUE: return JOB_BABY_ROGUE;
  5721. case MAPID_BABY_SOUL_LINKER: return JOB_BABY_SOUL_LINKER;
  5722. //3-1 Jobs
  5723. case MAPID_SUPER_NOVICE_E: return JOB_SUPER_NOVICE_E;
  5724. case MAPID_RUNE_KNIGHT: return JOB_RUNE_KNIGHT;
  5725. case MAPID_WARLOCK: return JOB_WARLOCK;
  5726. case MAPID_RANGER: return JOB_RANGER;
  5727. case MAPID_ARCH_BISHOP: return JOB_ARCH_BISHOP;
  5728. case MAPID_MECHANIC: return JOB_MECHANIC;
  5729. case MAPID_GUILLOTINE_CROSS: return JOB_GUILLOTINE_CROSS;
  5730. case MAPID_STAR_EMPEROR: return JOB_STAR_EMPEROR;
  5731. //3-2 Jobs
  5732. case MAPID_ROYAL_GUARD: return JOB_ROYAL_GUARD;
  5733. case MAPID_SORCERER: return JOB_SORCERER;
  5734. case MAPID_MINSTRELWANDERER: return sex?JOB_MINSTREL:JOB_WANDERER;
  5735. case MAPID_SURA: return JOB_SURA;
  5736. case MAPID_GENETIC: return JOB_GENETIC;
  5737. case MAPID_SHADOW_CHASER: return JOB_SHADOW_CHASER;
  5738. case MAPID_SOUL_REAPER: return JOB_SOUL_REAPER;
  5739. //Trans 3-1 Jobs
  5740. case MAPID_RUNE_KNIGHT_T: return JOB_RUNE_KNIGHT_T;
  5741. case MAPID_WARLOCK_T: return JOB_WARLOCK_T;
  5742. case MAPID_RANGER_T: return JOB_RANGER_T;
  5743. case MAPID_ARCH_BISHOP_T: return JOB_ARCH_BISHOP_T;
  5744. case MAPID_MECHANIC_T: return JOB_MECHANIC_T;
  5745. case MAPID_GUILLOTINE_CROSS_T: return JOB_GUILLOTINE_CROSS_T;
  5746. //Trans 3-2 Jobs
  5747. case MAPID_ROYAL_GUARD_T: return JOB_ROYAL_GUARD_T;
  5748. case MAPID_SORCERER_T: return JOB_SORCERER_T;
  5749. case MAPID_MINSTRELWANDERER_T: return sex?JOB_MINSTREL_T:JOB_WANDERER_T;
  5750. case MAPID_SURA_T: return JOB_SURA_T;
  5751. case MAPID_GENETIC_T: return JOB_GENETIC_T;
  5752. case MAPID_SHADOW_CHASER_T: return JOB_SHADOW_CHASER_T;
  5753. //Baby 3-1 Jobs
  5754. case MAPID_SUPER_BABY_E: return JOB_SUPER_BABY_E;
  5755. case MAPID_BABY_RUNE_KNIGHT: return JOB_BABY_RUNE_KNIGHT;
  5756. case MAPID_BABY_WARLOCK: return JOB_BABY_WARLOCK;
  5757. case MAPID_BABY_RANGER: return JOB_BABY_RANGER;
  5758. case MAPID_BABY_ARCH_BISHOP: return JOB_BABY_ARCH_BISHOP;
  5759. case MAPID_BABY_MECHANIC: return JOB_BABY_MECHANIC;
  5760. case MAPID_BABY_GUILLOTINE_CROSS: return JOB_BABY_GUILLOTINE_CROSS;
  5761. case MAPID_BABY_STAR_EMPEROR: return JOB_BABY_STAR_EMPEROR;
  5762. //Baby 3-2 Jobs
  5763. case MAPID_BABY_ROYAL_GUARD: return JOB_BABY_ROYAL_GUARD;
  5764. case MAPID_BABY_SORCERER: return JOB_BABY_SORCERER;
  5765. case MAPID_BABY_MINSTRELWANDERER: return sex?JOB_BABY_MINSTREL:JOB_BABY_WANDERER;
  5766. case MAPID_BABY_SURA: return JOB_BABY_SURA;
  5767. case MAPID_BABY_GENETIC: return JOB_BABY_GENETIC;
  5768. case MAPID_BABY_SHADOW_CHASER: return JOB_BABY_SHADOW_CHASER;
  5769. case MAPID_BABY_SOUL_REAPER: return JOB_BABY_SOUL_REAPER;
  5770. //Doram Jobs
  5771. case MAPID_SUMMONER: return JOB_SUMMONER;
  5772. default:
  5773. return -1;
  5774. }
  5775. }
  5776. /*====================================================
  5777. * This function return the name of the job (by [Yor])
  5778. *----------------------------------------------------*/
  5779. const char* job_name(int class_)
  5780. {
  5781. switch (class_) {
  5782. case JOB_NOVICE:
  5783. case JOB_SWORDMAN:
  5784. case JOB_MAGE:
  5785. case JOB_ARCHER:
  5786. case JOB_ACOLYTE:
  5787. case JOB_MERCHANT:
  5788. case JOB_THIEF:
  5789. return msg_txt(NULL,550 - JOB_NOVICE+class_);
  5790. case JOB_KNIGHT:
  5791. case JOB_PRIEST:
  5792. case JOB_WIZARD:
  5793. case JOB_BLACKSMITH:
  5794. case JOB_HUNTER:
  5795. case JOB_ASSASSIN:
  5796. return msg_txt(NULL,557 - JOB_KNIGHT+class_);
  5797. case JOB_KNIGHT2:
  5798. return msg_txt(NULL,557);
  5799. case JOB_CRUSADER:
  5800. case JOB_MONK:
  5801. case JOB_SAGE:
  5802. case JOB_ROGUE:
  5803. case JOB_ALCHEMIST:
  5804. case JOB_BARD:
  5805. case JOB_DANCER:
  5806. return msg_txt(NULL,563 - JOB_CRUSADER+class_);
  5807. case JOB_CRUSADER2:
  5808. return msg_txt(NULL,563);
  5809. case JOB_WEDDING:
  5810. case JOB_SUPER_NOVICE:
  5811. case JOB_GUNSLINGER:
  5812. case JOB_NINJA:
  5813. case JOB_XMAS:
  5814. return msg_txt(NULL,570 - JOB_WEDDING+class_);
  5815. case JOB_SUMMER:
  5816. case JOB_SUMMER2:
  5817. return msg_txt(NULL,621);
  5818. case JOB_HANBOK:
  5819. return msg_txt(NULL,694);
  5820. case JOB_OKTOBERFEST:
  5821. return msg_txt(NULL,696);
  5822. case JOB_NOVICE_HIGH:
  5823. case JOB_SWORDMAN_HIGH:
  5824. case JOB_MAGE_HIGH:
  5825. case JOB_ARCHER_HIGH:
  5826. case JOB_ACOLYTE_HIGH:
  5827. case JOB_MERCHANT_HIGH:
  5828. case JOB_THIEF_HIGH:
  5829. return msg_txt(NULL,575 - JOB_NOVICE_HIGH+class_);
  5830. case JOB_LORD_KNIGHT:
  5831. case JOB_HIGH_PRIEST:
  5832. case JOB_HIGH_WIZARD:
  5833. case JOB_WHITESMITH:
  5834. case JOB_SNIPER:
  5835. case JOB_ASSASSIN_CROSS:
  5836. return msg_txt(NULL,582 - JOB_LORD_KNIGHT+class_);
  5837. case JOB_LORD_KNIGHT2:
  5838. return msg_txt(NULL,582);
  5839. case JOB_PALADIN:
  5840. case JOB_CHAMPION:
  5841. case JOB_PROFESSOR:
  5842. case JOB_STALKER:
  5843. case JOB_CREATOR:
  5844. case JOB_CLOWN:
  5845. case JOB_GYPSY:
  5846. return msg_txt(NULL,588 - JOB_PALADIN + class_);
  5847. case JOB_PALADIN2:
  5848. return msg_txt(NULL,588);
  5849. case JOB_BABY:
  5850. case JOB_BABY_SWORDMAN:
  5851. case JOB_BABY_MAGE:
  5852. case JOB_BABY_ARCHER:
  5853. case JOB_BABY_ACOLYTE:
  5854. case JOB_BABY_MERCHANT:
  5855. case JOB_BABY_THIEF:
  5856. return msg_txt(NULL,595 - JOB_BABY + class_);
  5857. case JOB_BABY_KNIGHT:
  5858. case JOB_BABY_PRIEST:
  5859. case JOB_BABY_WIZARD:
  5860. case JOB_BABY_BLACKSMITH:
  5861. case JOB_BABY_HUNTER:
  5862. case JOB_BABY_ASSASSIN:
  5863. return msg_txt(NULL,602 - JOB_BABY_KNIGHT + class_);
  5864. case JOB_BABY_KNIGHT2:
  5865. return msg_txt(NULL,602);
  5866. case JOB_BABY_CRUSADER:
  5867. case JOB_BABY_MONK:
  5868. case JOB_BABY_SAGE:
  5869. case JOB_BABY_ROGUE:
  5870. case JOB_BABY_ALCHEMIST:
  5871. case JOB_BABY_BARD:
  5872. case JOB_BABY_DANCER:
  5873. return msg_txt(NULL,608 - JOB_BABY_CRUSADER + class_);
  5874. case JOB_BABY_CRUSADER2:
  5875. return msg_txt(NULL,608);
  5876. case JOB_SUPER_BABY:
  5877. return msg_txt(NULL,615);
  5878. case JOB_TAEKWON:
  5879. return msg_txt(NULL,616);
  5880. case JOB_STAR_GLADIATOR:
  5881. case JOB_STAR_GLADIATOR2:
  5882. return msg_txt(NULL,617);
  5883. case JOB_SOUL_LINKER:
  5884. return msg_txt(NULL,618);
  5885. case JOB_GANGSI:
  5886. case JOB_DEATH_KNIGHT:
  5887. case JOB_DARK_COLLECTOR:
  5888. return msg_txt(NULL,622 - JOB_GANGSI+class_);
  5889. case JOB_RUNE_KNIGHT:
  5890. case JOB_WARLOCK:
  5891. case JOB_RANGER:
  5892. case JOB_ARCH_BISHOP:
  5893. case JOB_MECHANIC:
  5894. case JOB_GUILLOTINE_CROSS:
  5895. return msg_txt(NULL,625 - JOB_RUNE_KNIGHT+class_);
  5896. case JOB_RUNE_KNIGHT_T:
  5897. case JOB_WARLOCK_T:
  5898. case JOB_RANGER_T:
  5899. case JOB_ARCH_BISHOP_T:
  5900. case JOB_MECHANIC_T:
  5901. case JOB_GUILLOTINE_CROSS_T:
  5902. return msg_txt(NULL,681 - JOB_RUNE_KNIGHT_T+class_);
  5903. case JOB_ROYAL_GUARD:
  5904. case JOB_SORCERER:
  5905. case JOB_MINSTREL:
  5906. case JOB_WANDERER:
  5907. case JOB_SURA:
  5908. case JOB_GENETIC:
  5909. case JOB_SHADOW_CHASER:
  5910. return msg_txt(NULL,631 - JOB_ROYAL_GUARD+class_);
  5911. case JOB_ROYAL_GUARD_T:
  5912. case JOB_SORCERER_T:
  5913. case JOB_MINSTREL_T:
  5914. case JOB_WANDERER_T:
  5915. case JOB_SURA_T:
  5916. case JOB_GENETIC_T:
  5917. case JOB_SHADOW_CHASER_T:
  5918. return msg_txt(NULL,687 - JOB_ROYAL_GUARD_T+class_);
  5919. case JOB_RUNE_KNIGHT2:
  5920. case JOB_RUNE_KNIGHT_T2:
  5921. return msg_txt(NULL,625);
  5922. case JOB_ROYAL_GUARD2:
  5923. case JOB_ROYAL_GUARD_T2:
  5924. return msg_txt(NULL,631);
  5925. case JOB_RANGER2:
  5926. case JOB_RANGER_T2:
  5927. return msg_txt(NULL,627);
  5928. case JOB_MECHANIC2:
  5929. case JOB_MECHANIC_T2:
  5930. return msg_txt(NULL,629);
  5931. case JOB_BABY_RUNE_KNIGHT:
  5932. case JOB_BABY_WARLOCK:
  5933. case JOB_BABY_RANGER:
  5934. case JOB_BABY_ARCH_BISHOP:
  5935. case JOB_BABY_MECHANIC:
  5936. case JOB_BABY_GUILLOTINE_CROSS:
  5937. case JOB_BABY_ROYAL_GUARD:
  5938. case JOB_BABY_SORCERER:
  5939. case JOB_BABY_MINSTREL:
  5940. case JOB_BABY_WANDERER:
  5941. case JOB_BABY_SURA:
  5942. case JOB_BABY_GENETIC:
  5943. case JOB_BABY_SHADOW_CHASER:
  5944. return msg_txt(NULL,638 - JOB_BABY_RUNE_KNIGHT+class_);
  5945. case JOB_BABY_RUNE_KNIGHT2:
  5946. return msg_txt(NULL,638);
  5947. case JOB_BABY_ROYAL_GUARD2:
  5948. return msg_txt(NULL,644);
  5949. case JOB_BABY_RANGER2:
  5950. return msg_txt(NULL,640);
  5951. case JOB_BABY_MECHANIC2:
  5952. return msg_txt(NULL,642);
  5953. case JOB_SUPER_NOVICE_E:
  5954. case JOB_SUPER_BABY_E:
  5955. return msg_txt(NULL,651 - JOB_SUPER_NOVICE_E+class_);
  5956. case JOB_KAGEROU:
  5957. case JOB_OBORO:
  5958. return msg_txt(NULL,653 - JOB_KAGEROU+class_);
  5959. case JOB_REBELLION:
  5960. return msg_txt(NULL,695);
  5961. case JOB_SUMMONER:
  5962. return msg_txt(NULL,697);
  5963. case JOB_BABY_SUMMONER:
  5964. return msg_txt(NULL,698);
  5965. case JOB_BABY_NINJA:
  5966. return msg_txt(NULL,699);
  5967. case JOB_BABY_KAGEROU:
  5968. case JOB_BABY_OBORO:
  5969. case JOB_BABY_TAEKWON:
  5970. case JOB_BABY_STAR_GLADIATOR:
  5971. case JOB_BABY_SOUL_LINKER:
  5972. case JOB_BABY_GUNSLINGER:
  5973. case JOB_BABY_REBELLION:
  5974. return msg_txt(NULL,753 - JOB_BABY_KAGEROU+class_);
  5975. case JOB_BABY_STAR_GLADIATOR2:
  5976. return msg_txt(NULL,756);
  5977. case JOB_STAR_EMPEROR:
  5978. case JOB_SOUL_REAPER:
  5979. case JOB_BABY_STAR_EMPEROR:
  5980. case JOB_BABY_SOUL_REAPER:
  5981. return msg_txt(NULL,782 - JOB_STAR_EMPEROR + class_);
  5982. case JOB_STAR_EMPEROR2:
  5983. return msg_txt(NULL,782);
  5984. case JOB_BABY_STAR_EMPEROR2:
  5985. return msg_txt(NULL,784);
  5986. default:
  5987. return msg_txt(NULL,655);
  5988. }
  5989. }
  5990. /*====================================================
  5991. * Timered function to make id follow a target.
  5992. * @id = bl.id (player only atm)
  5993. * target is define in sd->followtarget (bl.id)
  5994. * used by pc_follow
  5995. *----------------------------------------------------*/
  5996. TIMER_FUNC(pc_follow_timer){
  5997. struct map_session_data *sd;
  5998. struct block_list *tbl;
  5999. sd = map_id2sd(id);
  6000. nullpo_ret(sd);
  6001. if (sd->followtimer != tid){
  6002. ShowError("pc_follow_timer %d != %d\n",sd->followtimer,tid);
  6003. sd->followtimer = INVALID_TIMER;
  6004. return 0;
  6005. }
  6006. sd->followtimer = INVALID_TIMER;
  6007. tbl = map_id2bl(sd->followtarget);
  6008. if (tbl == NULL || pc_isdead(sd))
  6009. {
  6010. pc_stop_following(sd);
  6011. return 0;
  6012. }
  6013. // either player or target is currently detached from map blocks (could be teleporting),
  6014. // but still connected to this map, so we'll just increment the timer and check back later
  6015. if (sd->bl.prev != NULL && tbl->prev != NULL &&
  6016. sd->ud.skilltimer == INVALID_TIMER && sd->ud.attacktimer == INVALID_TIMER && sd->ud.walktimer == INVALID_TIMER)
  6017. {
  6018. if((sd->bl.m == tbl->m) && unit_can_reach_bl(&sd->bl,tbl, AREA_SIZE, 0, NULL, NULL)) {
  6019. if (!check_distance_bl(&sd->bl, tbl, 5))
  6020. unit_walktobl(&sd->bl, tbl, 5, 0);
  6021. } else
  6022. pc_setpos(sd, map_id2index(tbl->m), tbl->x, tbl->y, CLR_TELEPORT);
  6023. }
  6024. sd->followtimer = add_timer(
  6025. tick + 1000, // increase time a bit to loosen up map's load
  6026. pc_follow_timer, sd->bl.id, 0);
  6027. return 0;
  6028. }
  6029. int pc_stop_following (struct map_session_data *sd)
  6030. {
  6031. nullpo_ret(sd);
  6032. if (sd->followtimer != INVALID_TIMER) {
  6033. delete_timer(sd->followtimer,pc_follow_timer);
  6034. sd->followtimer = INVALID_TIMER;
  6035. }
  6036. sd->followtarget = -1;
  6037. sd->ud.target_to = 0;
  6038. unit_stop_walking(&sd->bl, 1);
  6039. return 0;
  6040. }
  6041. int pc_follow(struct map_session_data *sd,int target_id)
  6042. {
  6043. struct block_list *bl = map_id2bl(target_id);
  6044. if (bl == NULL /*|| bl->type != BL_PC*/)
  6045. return 1;
  6046. if (sd->followtimer != INVALID_TIMER)
  6047. pc_stop_following(sd);
  6048. sd->followtarget = target_id;
  6049. pc_follow_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
  6050. return 0;
  6051. }
  6052. int pc_checkbaselevelup(struct map_session_data *sd) {
  6053. unsigned int next = pc_nextbaseexp(sd);
  6054. if (!next || sd->status.base_exp < next || pc_is_maxbaselv(sd))
  6055. return 0;
  6056. do {
  6057. sd->status.base_exp -= next;
  6058. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  6059. if( ( !battle_config.multi_level_up || ( battle_config.multi_level_up_base > 0 && sd->status.base_level >= battle_config.multi_level_up_base ) ) && sd->status.base_exp > next-1 )
  6060. sd->status.base_exp = next-1;
  6061. next = pc_gets_status_point(sd->status.base_level);
  6062. sd->status.base_level++;
  6063. sd->status.status_point += next;
  6064. if( pc_is_maxbaselv(sd) ){
  6065. sd->status.base_exp = u32min(sd->status.base_exp,MAX_LEVEL_BASE_EXP);
  6066. break;
  6067. }
  6068. } while ((next=pc_nextbaseexp(sd)) > 0 && sd->status.base_exp >= next);
  6069. if (battle_config.pet_lv_rate && sd->pd) //<Skotlex> update pet's level
  6070. status_calc_pet(sd->pd,SCO_NONE);
  6071. clif_updatestatus(sd,SP_STATUSPOINT);
  6072. clif_updatestatus(sd,SP_BASELEVEL);
  6073. clif_updatestatus(sd,SP_BASEEXP);
  6074. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6075. status_calc_pc(sd,SCO_FORCE);
  6076. status_percent_heal(&sd->bl,100,100);
  6077. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) {
  6078. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_KYRIE),100,1,skill_get_time(PR_KYRIE,1));
  6079. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_IMPOSITIO),100,1,skill_get_time(PR_IMPOSITIO,1));
  6080. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_MAGNIFICAT),100,1,skill_get_time(PR_MAGNIFICAT,1));
  6081. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_GLORIA),100,1,skill_get_time(PR_GLORIA,1));
  6082. sc_start(&sd->bl,&sd->bl,status_skill2sc(PR_SUFFRAGIUM),100,1,skill_get_time(PR_SUFFRAGIUM,1));
  6083. if (sd->state.snovice_dead_flag)
  6084. sd->state.snovice_dead_flag = 0; //Reenable steelbody resurrection on dead.
  6085. } else if( (sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON ) {
  6086. sc_start(&sd->bl,&sd->bl,status_skill2sc(AL_INCAGI),100,10,600000);
  6087. sc_start(&sd->bl,&sd->bl,status_skill2sc(AL_BLESSING),100,10,600000);
  6088. }
  6089. clif_misceffect(&sd->bl,0);
  6090. npc_script_event(sd, NPCE_BASELVUP); //LORDALFA - LVLUPEVENT
  6091. if(sd->status.party_id)
  6092. party_send_levelup(sd);
  6093. pc_baselevelchanged(sd);
  6094. achievement_update_objective(sd, AG_GOAL_LEVEL, 1, sd->status.base_level);
  6095. achievement_update_objective(sd, AG_GOAL_STATUS, 2, sd->status.base_level, sd->status.class_);
  6096. return 1;
  6097. }
  6098. void pc_baselevelchanged(struct map_session_data *sd) {
  6099. uint8 i;
  6100. for( i = 0; i < EQI_MAX; i++ ) {
  6101. if( sd->equip_index[i] >= 0 ) {
  6102. if( sd->inventory_data[ sd->equip_index[i] ]->elvmax && sd->status.base_level > (unsigned int)sd->inventory_data[ sd->equip_index[i] ]->elvmax )
  6103. pc_unequipitem(sd, sd->equip_index[i], 3);
  6104. }
  6105. }
  6106. pc_show_questinfo(sd);
  6107. }
  6108. int pc_checkjoblevelup(struct map_session_data *sd)
  6109. {
  6110. unsigned int next = pc_nextjobexp(sd);
  6111. nullpo_ret(sd);
  6112. if(!next || sd->status.job_exp < next || pc_is_maxjoblv(sd))
  6113. return 0;
  6114. do {
  6115. sd->status.job_exp -= next;
  6116. //Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
  6117. if( ( !battle_config.multi_level_up || ( battle_config.multi_level_up_job > 0 && sd->status.job_level >= battle_config.multi_level_up_job ) ) && sd->status.job_exp > next-1 )
  6118. sd->status.job_exp = next-1;
  6119. sd->status.job_level ++;
  6120. sd->status.skill_point ++;
  6121. if( pc_is_maxjoblv(sd) ){
  6122. sd->status.job_exp = u32min(sd->status.job_exp,MAX_LEVEL_JOB_EXP);
  6123. break;
  6124. }
  6125. } while ((next=pc_nextjobexp(sd)) > 0 && sd->status.job_exp >= next);
  6126. clif_updatestatus(sd,SP_JOBLEVEL);
  6127. clif_updatestatus(sd,SP_JOBEXP);
  6128. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6129. clif_updatestatus(sd,SP_SKILLPOINT);
  6130. status_calc_pc(sd,SCO_FORCE);
  6131. clif_misceffect(&sd->bl,1);
  6132. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)) )
  6133. clif_status_change(&sd->bl, EFST_DEVIL1, 1, 0, 0, 0, 1); //Permanent blind effect from SG_DEVIL.
  6134. npc_script_event(sd, NPCE_JOBLVUP);
  6135. achievement_update_objective(sd, AG_GOAL_LEVEL, 1, sd->status.job_level);
  6136. pc_show_questinfo(sd);
  6137. return 1;
  6138. }
  6139. /** Alters experiences calculation based on self bonuses that do not get even shared to the party.
  6140. * @param sd Player
  6141. * @param base_exp Base EXP before peronal bonuses
  6142. * @param job_exp Job EXP before peronal bonuses
  6143. * @param src Block list that affecting the exp calculation
  6144. */
  6145. static void pc_calcexp(struct map_session_data *sd, unsigned int *base_exp, unsigned int *job_exp, struct block_list *src)
  6146. {
  6147. int bonus = 0, vip_bonus_base = 0, vip_bonus_job = 0;
  6148. if (src) {
  6149. struct status_data *status = status_get_status_data(src);
  6150. if( sd->expaddrace[status->race] )
  6151. bonus += sd->expaddrace[status->race];
  6152. if( sd->expaddrace[RC_ALL] )
  6153. bonus += sd->expaddrace[RC_ALL];
  6154. if( sd->expaddclass[status->class_] )
  6155. bonus += sd->expaddclass[status->class_];
  6156. if( sd->expaddclass[CLASS_ALL] )
  6157. bonus += sd->expaddclass[CLASS_ALL];
  6158. if (battle_config.pk_mode &&
  6159. (int)(status_get_lv(src) - sd->status.base_level) >= 20)
  6160. bonus += 15; // pk_mode additional exp if monster >20 levels [Valaris]
  6161. if (src && src->type == BL_MOB && pc_isvip(sd)) { // EXP bonus for VIP player
  6162. vip_bonus_base = battle_config.vip_base_exp_increase;
  6163. vip_bonus_job = battle_config.vip_job_exp_increase;
  6164. }
  6165. }
  6166. // Give EXPBOOST for quests even if src is NULL.
  6167. if (sd->sc.data[SC_EXPBOOST]) {
  6168. bonus += sd->sc.data[SC_EXPBOOST]->val1;
  6169. if (battle_config.vip_bm_increase && pc_isvip(sd)) // Increase Battle Manual EXP rate for VIP
  6170. bonus += (sd->sc.data[SC_EXPBOOST]->val1 / battle_config.vip_bm_increase);
  6171. }
  6172. if (*base_exp) {
  6173. unsigned int exp = (unsigned int)(*base_exp + (double)*base_exp * (bonus + vip_bonus_base)/100.);
  6174. *base_exp = cap_value(exp, 1, UINT_MAX);
  6175. }
  6176. // Give JEXPBOOST for quests even if src is NULL.
  6177. if (sd->sc.data[SC_JEXPBOOST])
  6178. bonus += sd->sc.data[SC_JEXPBOOST]->val1;
  6179. if (*job_exp) {
  6180. unsigned int exp = (unsigned int)(*job_exp + (double)*job_exp * (bonus + vip_bonus_job)/100.);
  6181. *job_exp = cap_value(exp, 1, UINT_MAX);
  6182. }
  6183. return;
  6184. }
  6185. /**
  6186. * Show EXP gained by player in percentage by @showexp
  6187. * @param sd Player
  6188. * @param base_exp Base EXP gained/loss
  6189. * @param next_base_exp Base EXP needed for next base level
  6190. * @param job_exp Job EXP gained/loss
  6191. * @param next_job_exp Job EXP needed for next job level
  6192. * @param lost True:EXP penalty, lose EXP
  6193. **/
  6194. void pc_gainexp_disp(struct map_session_data *sd, unsigned int base_exp, unsigned int next_base_exp, unsigned int job_exp, unsigned int next_job_exp, bool lost) {
  6195. char output[CHAT_SIZE_MAX];
  6196. nullpo_retv(sd);
  6197. sprintf(output, msg_txt(sd,743), // Experience %s Base:%ld (%0.2f%%) Job:%ld (%0.2f%%)
  6198. (lost) ? msg_txt(sd,742) : msg_txt(sd,741),
  6199. (long)base_exp * (lost ? -1 : 1), (base_exp / (float)next_base_exp * 100 * (lost ? -1 : 1)),
  6200. (long)job_exp * (lost ? -1 : 1), (job_exp / (float)next_job_exp * 100 * (lost ? -1 : 1)));
  6201. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  6202. }
  6203. /**
  6204. * Give Base or Job EXP to player, then calculate remaining exp for next lvl
  6205. * @param sd Player
  6206. * @param src EXP source
  6207. * @param base_exp Base EXP gained
  6208. * @param base_exp Job EXP gained
  6209. * @param exp_flag 1: Quest EXP; 2: Param Exp (Ignore Guild EXP tax, EXP adjustments)
  6210. * @return
  6211. **/
  6212. void pc_gainexp(struct map_session_data *sd, struct block_list *src, unsigned int base_exp, unsigned int job_exp, uint8 exp_flag)
  6213. {
  6214. unsigned int nextb = 0, nextj = 0;
  6215. uint8 flag = 0; ///< 1: Base EXP given, 2: Job EXP given, 4: Max Base level, 8: Max Job Level
  6216. nullpo_retv(sd);
  6217. if(sd->bl.prev == NULL || pc_isdead(sd))
  6218. return;
  6219. if (!(exp_flag&2)) {
  6220. if (!battle_config.pvp_exp && map_getmapflag(sd->bl.m, MF_PVP)) // [MouseJstr]
  6221. return; // no exp on pvp maps
  6222. if (sd->status.guild_id>0)
  6223. base_exp -= guild_payexp(sd,base_exp);
  6224. }
  6225. flag = ((base_exp) ? 1 : 0) |
  6226. ((job_exp) ? 2 : 0) |
  6227. ((pc_is_maxbaselv(sd)) ? 4 : 0) |
  6228. ((pc_is_maxjoblv(sd)) ? 8 : 0);
  6229. if (!(exp_flag&2))
  6230. pc_calcexp(sd, &base_exp, &job_exp, src);
  6231. nextb = pc_nextbaseexp(sd);
  6232. nextj = pc_nextjobexp(sd);
  6233. if (flag&4){
  6234. if( sd->status.base_exp >= MAX_LEVEL_BASE_EXP )
  6235. base_exp = 0;
  6236. else if( sd->status.base_exp + base_exp >= MAX_LEVEL_BASE_EXP )
  6237. base_exp = MAX_LEVEL_BASE_EXP - sd->status.base_exp;
  6238. }
  6239. if (flag&8){
  6240. if( sd->status.job_exp >= MAX_LEVEL_JOB_EXP )
  6241. job_exp = 0;
  6242. else if( sd->status.job_exp + job_exp >= MAX_LEVEL_JOB_EXP )
  6243. job_exp = MAX_LEVEL_JOB_EXP - sd->status.job_exp;
  6244. }
  6245. if (!(exp_flag&2) && battle_config.max_exp_gain_rate && (base_exp || job_exp)) {
  6246. //Note that this value should never be greater than the original
  6247. //therefore no overflow checks are needed. [Skotlex]
  6248. if (nextb > 0) {
  6249. float nextbp = (float) base_exp / (float) nextb;
  6250. if (nextbp > battle_config.max_exp_gain_rate/1000.)
  6251. base_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextb);
  6252. }
  6253. if (nextj > 0) {
  6254. float nextjp = (float) job_exp / (float) nextj;
  6255. if (nextjp > battle_config.max_exp_gain_rate/1000.)
  6256. job_exp = (unsigned int)(battle_config.max_exp_gain_rate/1000.*nextj);
  6257. }
  6258. }
  6259. // Give EXP for Base Level
  6260. if (base_exp) {
  6261. if ((uint64)sd->status.base_exp + base_exp > UINT32_MAX)
  6262. sd->status.base_exp = UINT32_MAX;
  6263. else
  6264. sd->status.base_exp += base_exp;
  6265. if (!pc_checkbaselevelup(sd))
  6266. clif_updatestatus(sd,SP_BASEEXP);
  6267. }
  6268. // Give EXP for Job Level
  6269. if (job_exp) {
  6270. if ((uint64)sd->status.job_exp + job_exp > UINT32_MAX)
  6271. sd->status.job_exp = UINT32_MAX;
  6272. else
  6273. sd->status.job_exp += job_exp;
  6274. if (!pc_checkjoblevelup(sd))
  6275. clif_updatestatus(sd,SP_JOBEXP);
  6276. }
  6277. if (flag&1)
  6278. clif_displayexp(sd, (flag&4) ? 0 : base_exp, SP_BASEEXP, exp_flag&1, false);
  6279. if (flag&2)
  6280. clif_displayexp(sd, (flag&8) ? 0 : job_exp, SP_JOBEXP, exp_flag&1, false);
  6281. if (sd->state.showexp && (base_exp || job_exp))
  6282. pc_gainexp_disp(sd, base_exp, nextb, job_exp, nextj, false);
  6283. }
  6284. /**
  6285. * Lost Base/Job EXP from a player
  6286. * @param sd Player
  6287. * @param base_exp Base EXP lost
  6288. * @param job_exp Job EXP lost
  6289. **/
  6290. void pc_lostexp(struct map_session_data *sd, unsigned int base_exp, unsigned int job_exp) {
  6291. nullpo_retv(sd);
  6292. if (base_exp) {
  6293. base_exp = u32min(sd->status.base_exp, base_exp);
  6294. sd->status.base_exp -= base_exp;
  6295. clif_displayexp(sd, base_exp, SP_BASEEXP, false, true);
  6296. clif_updatestatus(sd, SP_BASEEXP);
  6297. }
  6298. if (job_exp) {
  6299. job_exp = u32min(sd->status.job_exp, job_exp);
  6300. sd->status.job_exp -= job_exp;
  6301. clif_displayexp(sd, job_exp, SP_JOBEXP, false, true);
  6302. clif_updatestatus(sd, SP_JOBEXP);
  6303. }
  6304. if (sd->state.showexp && (base_exp || job_exp))
  6305. pc_gainexp_disp(sd, base_exp, pc_nextbaseexp(sd), job_exp, pc_nextjobexp(sd), true);
  6306. }
  6307. /**
  6308. * Returns max base level for this character's class.
  6309. * @param class_: Player's class
  6310. * @return Max Base Level
  6311. */
  6312. static unsigned int pc_class_maxbaselv(unsigned short class_) {
  6313. return job_info[pc_class2idx(class_)].max_level[0];
  6314. }
  6315. /**
  6316. * Returns max base level for this character.
  6317. * @param sd Player
  6318. * @return Max Base Level
  6319. **/
  6320. unsigned int pc_maxbaselv(struct map_session_data *sd){
  6321. return pc_class_maxbaselv(sd->status.class_);
  6322. }
  6323. /**
  6324. * Returns max job level for this character's class.
  6325. * @param class_: Player's class
  6326. * @return Max Job Level
  6327. */
  6328. static unsigned int pc_class_maxjoblv(unsigned short class_) {
  6329. return job_info[pc_class2idx(class_)].max_level[1];
  6330. }
  6331. /**
  6332. * Returns max job level for this character.
  6333. * @param sd Player
  6334. * @return Max Job Level
  6335. **/
  6336. unsigned int pc_maxjoblv(struct map_session_data *sd){
  6337. return pc_class_maxjoblv(sd->status.class_);
  6338. }
  6339. /**
  6340. * Check if player is reached max base level
  6341. * @param sd
  6342. * @return True if reached max level
  6343. **/
  6344. bool pc_is_maxbaselv(struct map_session_data *sd) {
  6345. nullpo_retr(false, sd);
  6346. return (sd->status.base_level >= pc_maxbaselv(sd));
  6347. }
  6348. /**
  6349. * Check if player is reached max base level
  6350. * @param sd
  6351. * @return True if reached max level
  6352. **/
  6353. bool pc_is_maxjoblv(struct map_session_data *sd) {
  6354. nullpo_retr(false, sd);
  6355. return (sd->status.job_level >= pc_maxjoblv(sd));
  6356. }
  6357. /**
  6358. * Base exp needed for player to level up.
  6359. * @param sd
  6360. * @return Base EXP needed for next base level
  6361. **/
  6362. unsigned int pc_nextbaseexp(struct map_session_data *sd){
  6363. nullpo_ret(sd);
  6364. if (sd->status.base_level == 0) // Is this something that possible?
  6365. return 0;
  6366. if (pc_is_maxbaselv(sd))
  6367. return MAX_LEVEL_BASE_EXP; // On max level, player's base EXP limit is 99,999,999
  6368. return job_info[pc_class2idx(sd->status.class_)].exp_table[0][sd->status.base_level-1];
  6369. }
  6370. /**
  6371. * Job exp needed for player to level up.
  6372. * @param sd
  6373. * @return Job EXP needed for next job level
  6374. **/
  6375. unsigned int pc_nextjobexp(struct map_session_data *sd){
  6376. nullpo_ret(sd);
  6377. if (sd->status.job_level == 0) // Is this something that possible?
  6378. return 0;
  6379. if (pc_is_maxjoblv(sd))
  6380. return MAX_LEVEL_JOB_EXP; // On max level, player's job EXP limit is 999,999,999
  6381. return job_info[pc_class2idx(sd->status.class_)].exp_table[1][sd->status.job_level-1];
  6382. }
  6383. /// Returns the value of the specified stat.
  6384. static int pc_getstat(struct map_session_data* sd, int type)
  6385. {
  6386. nullpo_retr(-1, sd);
  6387. switch( type ) {
  6388. case SP_STR: return sd->status.str;
  6389. case SP_AGI: return sd->status.agi;
  6390. case SP_VIT: return sd->status.vit;
  6391. case SP_INT: return sd->status.int_;
  6392. case SP_DEX: return sd->status.dex;
  6393. case SP_LUK: return sd->status.luk;
  6394. default:
  6395. return -1;
  6396. }
  6397. }
  6398. /// Sets the specified stat to the specified value.
  6399. /// Returns the new value.
  6400. static int pc_setstat(struct map_session_data* sd, int type, int val)
  6401. {
  6402. nullpo_retr(-1, sd);
  6403. switch( type ) {
  6404. case SP_STR: sd->status.str = val; break;
  6405. case SP_AGI: sd->status.agi = val; break;
  6406. case SP_VIT: sd->status.vit = val; break;
  6407. case SP_INT: sd->status.int_ = val; break;
  6408. case SP_DEX: sd->status.dex = val; break;
  6409. case SP_LUK: sd->status.luk = val; break;
  6410. default:
  6411. return -1;
  6412. }
  6413. return val;
  6414. }
  6415. // Calculates the number of status points PC gets when leveling up (from level to level+1)
  6416. int pc_gets_status_point(int level)
  6417. {
  6418. if (battle_config.use_statpoint_table) //Use values from "db/statpoint.txt"
  6419. return (statp[level+1] - statp[level]);
  6420. else //Default increase
  6421. return ((level+15) / 5);
  6422. }
  6423. #ifdef RENEWAL_STAT
  6424. /// Renewal status point cost formula
  6425. #define PC_STATUS_POINT_COST(low) (((low) < 100) ? (2 + ((low) - 1) / 10) : (16 + 4 * (((low) - 100) / 5)))
  6426. #else
  6427. /// Pre-Renewal status point cost formula
  6428. #define PC_STATUS_POINT_COST(low) (( 1 + ((low) + 9) / 10 ))
  6429. #endif
  6430. /// Returns the number of stat points needed to change the specified stat by val.
  6431. /// If val is negative, returns the number of stat points that would be needed to
  6432. /// raise the specified stat from (current value - val) to current value.
  6433. int pc_need_status_point(struct map_session_data* sd, int type, int val)
  6434. {
  6435. int low, high, sp = 0, max = 0;
  6436. if ( val == 0 )
  6437. return 0;
  6438. low = pc_getstat(sd,type);
  6439. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR));
  6440. if ( low >= max && val > 0 )
  6441. return 0; // Official servers show '0' when max is reached
  6442. high = low + val;
  6443. if ( val < 0 )
  6444. SWAP(low, high);
  6445. for ( ; low < high; low++ )
  6446. sp += PC_STATUS_POINT_COST(low);
  6447. return sp;
  6448. }
  6449. /**
  6450. * Returns the value the specified stat can be increased by with the current
  6451. * amount of available status points for the current character's class.
  6452. *
  6453. * @param sd The target character.
  6454. * @param type Stat to verify.
  6455. * @return Maximum value the stat could grow by.
  6456. */
  6457. int pc_maxparameterincrease(struct map_session_data* sd, int type)
  6458. {
  6459. int base, final_val, status_points, max_param;
  6460. nullpo_ret(sd);
  6461. base = final_val = pc_getstat(sd, type);
  6462. status_points = sd->status.status_point;
  6463. max_param = pc_maxparameter(sd, (enum e_params)(type-SP_STR));
  6464. while (final_val <= max_param && status_points >= 0) {
  6465. status_points -= PC_STATUS_POINT_COST(final_val);
  6466. final_val++;
  6467. }
  6468. final_val--;
  6469. return (final_val > base ? final_val-base : 0);
  6470. }
  6471. /**
  6472. * Raises a stat by the specified amount.
  6473. *
  6474. * Obeys max_parameter limits.
  6475. * Subtracts status points according to the cost of the increased stat points.
  6476. *
  6477. * @param sd The target character.
  6478. * @param type The stat to change (see enum _sp)
  6479. * @param increase The stat increase (strictly positive) amount.
  6480. * @retval true if the stat was increased by any amount.
  6481. * @retval false if there were no changes.
  6482. */
  6483. bool pc_statusup(struct map_session_data* sd, int type, int increase)
  6484. {
  6485. int max_increase = 0, current = 0, needed_points = 0, final_value = 0;
  6486. nullpo_ret(sd);
  6487. // check conditions
  6488. if (type < SP_STR || type > SP_LUK || increase <= 0) {
  6489. clif_statusupack(sd, type, 0, 0);
  6490. return false;
  6491. }
  6492. // check limits
  6493. current = pc_getstat(sd, type);
  6494. max_increase = pc_maxparameterincrease(sd, type);
  6495. increase = cap_value(increase, 0, max_increase); // cap to the maximum status points available
  6496. if (increase <= 0 || current + increase > pc_maxparameter(sd, (enum e_params)(type-SP_STR))) {
  6497. clif_statusupack(sd, type, 0, 0);
  6498. return false;
  6499. }
  6500. // check status points
  6501. needed_points = pc_need_status_point(sd, type, increase);
  6502. if (needed_points < 0 || needed_points > sd->status.status_point) { // Sanity check
  6503. clif_statusupack(sd, type, 0, 0);
  6504. return false;
  6505. }
  6506. // set new values
  6507. final_value = pc_setstat(sd, type, current + increase);
  6508. sd->status.status_point -= needed_points;
  6509. status_calc_pc(sd,SCO_NONE);
  6510. // update increase cost indicator
  6511. clif_updatestatus(sd, SP_USTR + type-SP_STR);
  6512. // update statpoint count
  6513. clif_updatestatus(sd, SP_STATUSPOINT);
  6514. // update stat value
  6515. clif_statusupack(sd, type, 1, final_value); // required
  6516. if( final_value > 255 )
  6517. clif_updatestatus(sd, type); // send after the 'ack' to override the truncated value
  6518. achievement_update_objective(sd, AG_GOAL_STATUS, 1, final_value);
  6519. return true;
  6520. }
  6521. /**
  6522. * Raises a stat by the specified amount.
  6523. *
  6524. * Obeys max_parameter limits.
  6525. * Does not subtract status points for the cost of the modified stat points.
  6526. *
  6527. * @param sd The target character.
  6528. * @param type The stat to change (see enum _sp)
  6529. * @param val The stat increase (or decrease) amount.
  6530. * @return the stat increase amount.
  6531. * @retval 0 if no changes were made.
  6532. */
  6533. int pc_statusup2(struct map_session_data* sd, int type, int val)
  6534. {
  6535. int max, need;
  6536. nullpo_ret(sd);
  6537. if( type < SP_STR || type > SP_LUK )
  6538. {
  6539. clif_statusupack(sd,type,0,0);
  6540. return 0;
  6541. }
  6542. need = pc_need_status_point(sd,type,1);
  6543. max = pc_maxparameter(sd,(enum e_params)(type-SP_STR)); // set new value
  6544. val = pc_setstat(sd, type, cap_value(pc_getstat(sd,type) + val, 1, max));
  6545. status_calc_pc(sd,SCO_NONE);
  6546. // update increase cost indicator
  6547. if( need != pc_need_status_point(sd,type,1) )
  6548. clif_updatestatus(sd, SP_USTR + type-SP_STR);
  6549. // update stat value
  6550. clif_statusupack(sd,type,1,val); // required
  6551. if( val > 255 )
  6552. clif_updatestatus(sd,type); // send after the 'ack' to override the truncated value
  6553. return val;
  6554. }
  6555. /*==========================================
  6556. * Update skill_lv for player sd
  6557. * Skill point allocation
  6558. *------------------------------------------*/
  6559. void pc_skillup(struct map_session_data *sd,uint16 skill_id)
  6560. {
  6561. uint16 idx = skill_get_index(skill_id);
  6562. nullpo_retv(sd);
  6563. if (!idx) {
  6564. if (skill_id)
  6565. ShowError("pc_skillup: Player attempts to level up invalid skill '%d'\n", skill_id);
  6566. return;
  6567. }
  6568. // Level up guild skill
  6569. if (SKILL_CHK_GUILD(skill_id)) {
  6570. guild_skillup(sd, skill_id);
  6571. return;
  6572. }
  6573. // Level up homunculus skill
  6574. else if (sd->hd && SKILL_CHK_HOMUN(skill_id)) {
  6575. hom_skillup(sd->hd, skill_id);
  6576. return;
  6577. }
  6578. else {
  6579. if( sd->status.skill_point > 0 &&
  6580. sd->status.skill[idx].id &&
  6581. sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT && //Don't allow raising while you have granted skills. [Skotlex]
  6582. sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_) )
  6583. {
  6584. int lv, range, upgradable;
  6585. sd->status.skill[idx].lv++;
  6586. sd->status.skill_point--;
  6587. if( !skill_get_inf(skill_id) )
  6588. status_calc_pc(sd,SCO_NONE); // Only recalculate for passive skills.
  6589. else if( sd->status.skill_point == 0 && pc_is_taekwon_ranker(sd) )
  6590. pc_calc_skilltree(sd); // Required to grant all TK Ranker skills.
  6591. else
  6592. pc_check_skilltree(sd); // Check if a new skill can Lvlup
  6593. lv = sd->status.skill[idx].lv;
  6594. range = skill_get_range2(&sd->bl, skill_id, lv, false);
  6595. upgradable = (lv < skill_tree_get_max(sd->status.skill[idx].id, sd->status.class_)) ? 1 : 0;
  6596. clif_skillup(sd,skill_id,lv,range,upgradable);
  6597. clif_updatestatus(sd,SP_SKILLPOINT);
  6598. if( skill_id == GN_REMODELING_CART ) /* cart weight info was updated by status_calc_pc */
  6599. clif_updatestatus(sd,SP_CARTINFO);
  6600. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  6601. clif_status_change(&sd->bl, EFST_DEVIL1, 1, 0, 0, 0, 1); //Permanent blind effect from SG_DEVIL.
  6602. if (!pc_has_permission(sd, PC_PERM_ALL_SKILL)) // may skill everything at any time anyways, and this would cause a huge slowdown
  6603. clif_skillinfoblock(sd);
  6604. }
  6605. //else
  6606. // 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);
  6607. }
  6608. }
  6609. /*==========================================
  6610. * /allskill
  6611. *------------------------------------------*/
  6612. int pc_allskillup(struct map_session_data *sd)
  6613. {
  6614. int i;
  6615. nullpo_ret(sd);
  6616. for (i = 0; i < MAX_SKILL; i++) {
  6617. 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) {
  6618. sd->status.skill[i].lv = (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY) ? 0 : sd->status.skill[i].flag - SKILL_FLAG_REPLACED_LV_0;
  6619. sd->status.skill[i].flag = SKILL_FLAG_PERMANENT;
  6620. if (sd->status.skill[i].lv == 0)
  6621. sd->status.skill[i].id = 0;
  6622. }
  6623. }
  6624. if (!pc_grant_allskills(sd, true)) {
  6625. uint16 sk_id;
  6626. for (i = 0; i < MAX_SKILL_TREE && (sk_id = skill_tree[pc_class2idx(sd->status.class_)][i].skill_id) > 0;i++){
  6627. uint16 sk_idx = skill_get_index(sk_id);
  6628. if (sk_id == 0 || sk_idx == 0)
  6629. continue;
  6630. std::shared_ptr<s_skill_db> skill = skill_db.find(sk_id);
  6631. if (
  6632. (skill->inf2[INF2_ISQUEST] && !battle_config.quest_skill_learn) ||
  6633. ((skill->inf2[INF2_ISWEDDING] || skill->inf2[INF2_ISSPIRIT])) ||
  6634. sk_id == SG_DEVIL
  6635. )
  6636. continue; //Cannot be learned normally.
  6637. sd->status.skill[sk_idx].id = sk_id;
  6638. sd->status.skill[sk_idx].lv = skill_tree_get_max(sk_id, sd->status.class_); // celest
  6639. }
  6640. }
  6641. status_calc_pc(sd,SCO_NONE);
  6642. //Required because if you could level up all skills previously,
  6643. //the update will not be sent as only the lv variable changes.
  6644. clif_skillinfoblock(sd);
  6645. return 0;
  6646. }
  6647. /*==========================================
  6648. * /resetlvl
  6649. *------------------------------------------*/
  6650. int pc_resetlvl(struct map_session_data* sd,int type)
  6651. {
  6652. int i;
  6653. nullpo_ret(sd);
  6654. if (type != 3) //Also reset skills
  6655. pc_resetskill(sd, 0);
  6656. if(type == 1){
  6657. sd->status.skill_point=0;
  6658. sd->status.base_level=1;
  6659. sd->status.job_level=1;
  6660. sd->status.base_exp=0;
  6661. sd->status.job_exp=0;
  6662. if(sd->sc.option !=0)
  6663. sd->sc.option = 0;
  6664. sd->status.str=1;
  6665. sd->status.agi=1;
  6666. sd->status.vit=1;
  6667. sd->status.int_=1;
  6668. sd->status.dex=1;
  6669. sd->status.luk=1;
  6670. if(sd->status.class_ == JOB_NOVICE_HIGH) {
  6671. sd->status.status_point=100; // not 88 [celest]
  6672. // give platinum skills upon changing
  6673. pc_skill(sd,NV_FIRSTAID,1,ADDSKILL_PERMANENT);
  6674. pc_skill(sd,NV_TRICKDEAD,1,ADDSKILL_PERMANENT);
  6675. }
  6676. }
  6677. if(type == 2){
  6678. sd->status.skill_point=0;
  6679. sd->status.base_level=1;
  6680. sd->status.job_level=1;
  6681. sd->status.base_exp=0;
  6682. sd->status.job_exp=0;
  6683. }
  6684. if(type == 3){
  6685. sd->status.base_level=1;
  6686. sd->status.base_exp=0;
  6687. }
  6688. if(type == 4){
  6689. sd->status.job_level=1;
  6690. sd->status.job_exp=0;
  6691. }
  6692. clif_updatestatus(sd,SP_STATUSPOINT);
  6693. clif_updatestatus(sd,SP_STR);
  6694. clif_updatestatus(sd,SP_AGI);
  6695. clif_updatestatus(sd,SP_VIT);
  6696. clif_updatestatus(sd,SP_INT);
  6697. clif_updatestatus(sd,SP_DEX);
  6698. clif_updatestatus(sd,SP_LUK);
  6699. clif_updatestatus(sd,SP_BASELEVEL);
  6700. clif_updatestatus(sd,SP_JOBLEVEL);
  6701. clif_updatestatus(sd,SP_STATUSPOINT);
  6702. clif_updatestatus(sd,SP_BASEEXP);
  6703. clif_updatestatus(sd,SP_JOBEXP);
  6704. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6705. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6706. clif_updatestatus(sd,SP_SKILLPOINT);
  6707. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  6708. clif_updatestatus(sd,SP_UAGI);
  6709. clif_updatestatus(sd,SP_UVIT);
  6710. clif_updatestatus(sd,SP_UINT);
  6711. clif_updatestatus(sd,SP_UDEX);
  6712. clif_updatestatus(sd,SP_ULUK); // End Addition
  6713. for(i=0;i<EQI_MAX;i++) { // unequip items that can't be equipped by base 1 [Valaris]
  6714. if(sd->equip_index[i] >= 0)
  6715. if(pc_isequip(sd,sd->equip_index[i]))
  6716. pc_unequipitem(sd,sd->equip_index[i],2);
  6717. }
  6718. if ((type == 1 || type == 2 || type == 3) && sd->status.party_id)
  6719. party_send_levelup(sd);
  6720. status_calc_pc(sd, SCO_FORCE);
  6721. clif_skillinfoblock(sd);
  6722. return 0;
  6723. }
  6724. /*==========================================
  6725. * /resetstate
  6726. *------------------------------------------*/
  6727. int pc_resetstate(struct map_session_data* sd)
  6728. {
  6729. nullpo_ret(sd);
  6730. if (battle_config.use_statpoint_table)
  6731. { // New statpoint table used here - Dexity
  6732. if (sd->status.base_level > MAX_LEVEL)
  6733. { //statp[] goes out of bounds, can't reset!
  6734. ShowError("pc_resetstate: Can't reset stats of %d:%d, the base level (%d) is greater than the max level supported (%d)\n",
  6735. sd->status.account_id, sd->status.char_id, sd->status.base_level, MAX_LEVEL);
  6736. return 0;
  6737. }
  6738. sd->status.status_point = statp[sd->status.base_level] + ( sd->class_&JOBL_UPPER ? 52 : 0 ); // extra 52+48=100 stat points
  6739. }
  6740. else
  6741. {
  6742. int add=0;
  6743. add += pc_need_status_point(sd, SP_STR, 1-pc_getstat(sd, SP_STR));
  6744. add += pc_need_status_point(sd, SP_AGI, 1-pc_getstat(sd, SP_AGI));
  6745. add += pc_need_status_point(sd, SP_VIT, 1-pc_getstat(sd, SP_VIT));
  6746. add += pc_need_status_point(sd, SP_INT, 1-pc_getstat(sd, SP_INT));
  6747. add += pc_need_status_point(sd, SP_DEX, 1-pc_getstat(sd, SP_DEX));
  6748. add += pc_need_status_point(sd, SP_LUK, 1-pc_getstat(sd, SP_LUK));
  6749. sd->status.status_point+=add;
  6750. }
  6751. pc_setstat(sd, SP_STR, 1);
  6752. pc_setstat(sd, SP_AGI, 1);
  6753. pc_setstat(sd, SP_VIT, 1);
  6754. pc_setstat(sd, SP_INT, 1);
  6755. pc_setstat(sd, SP_DEX, 1);
  6756. pc_setstat(sd, SP_LUK, 1);
  6757. clif_updatestatus(sd,SP_STR);
  6758. clif_updatestatus(sd,SP_AGI);
  6759. clif_updatestatus(sd,SP_VIT);
  6760. clif_updatestatus(sd,SP_INT);
  6761. clif_updatestatus(sd,SP_DEX);
  6762. clif_updatestatus(sd,SP_LUK);
  6763. clif_updatestatus(sd,SP_USTR); // Updates needed stat points - Valaris
  6764. clif_updatestatus(sd,SP_UAGI);
  6765. clif_updatestatus(sd,SP_UVIT);
  6766. clif_updatestatus(sd,SP_UINT);
  6767. clif_updatestatus(sd,SP_UDEX);
  6768. clif_updatestatus(sd,SP_ULUK); // End Addition
  6769. clif_updatestatus(sd,SP_STATUSPOINT);
  6770. if( sd->mission_mobid ) { //bugreport:2200
  6771. sd->mission_mobid = 0;
  6772. sd->mission_count = 0;
  6773. pc_setglobalreg(sd, add_str(TKMISSIONID_VAR), 0);
  6774. }
  6775. status_calc_pc(sd, SCO_NONE);
  6776. return 1;
  6777. }
  6778. /*==========================================
  6779. * /resetskill
  6780. * if flag&1, perform block resync and status_calc call.
  6781. * if flag&2, just count total amount of skill points used by player, do not really reset.
  6782. * if flag&4, just reset the skills if the player class is a bard/dancer type (for changesex.)
  6783. *------------------------------------------*/
  6784. int pc_resetskill(struct map_session_data* sd, int flag)
  6785. {
  6786. int i, skill_point=0;
  6787. nullpo_ret(sd);
  6788. if( flag&4 && (sd->class_&MAPID_UPPERMASK) != MAPID_BARDDANCER )
  6789. return 0;
  6790. if( !(flag&2) ) { //Remove stuff lost when resetting skills.
  6791. /**
  6792. * 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)
  6793. **/
  6794. if( pc_is_taekwon_ranker(sd) )
  6795. return 0;
  6796. if( pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)) )
  6797. clif_status_load(&sd->bl, EFST_DEVIL1, 0); //Remove perma blindness due to skill-reset. [Skotlex]
  6798. i = sd->sc.option;
  6799. if( i&OPTION_RIDING && pc_checkskill(sd, KN_RIDING) )
  6800. i &= ~OPTION_RIDING;
  6801. if( i&OPTION_FALCON && pc_checkskill(sd, HT_FALCON) )
  6802. i &= ~OPTION_FALCON;
  6803. if( i&OPTION_DRAGON && pc_checkskill(sd, RK_DRAGONTRAINING) )
  6804. i &= ~OPTION_DRAGON;
  6805. if( i&OPTION_WUG && pc_checkskill(sd, RA_WUGMASTERY) )
  6806. i &= ~OPTION_WUG;
  6807. if( i&OPTION_WUGRIDER && pc_checkskill(sd, RA_WUGRIDER) )
  6808. i &= ~OPTION_WUGRIDER;
  6809. if( i&OPTION_MADOGEAR && ( sd->class_&MAPID_THIRDMASK ) == MAPID_MECHANIC )
  6810. i &= ~OPTION_MADOGEAR;
  6811. #ifndef NEW_CARTS
  6812. if( i&OPTION_CART && pc_checkskill(sd, MC_PUSHCART) )
  6813. i &= ~OPTION_CART;
  6814. #else
  6815. if( sd->sc.data[SC_PUSH_CART] )
  6816. pc_setcart(sd, 0);
  6817. #endif
  6818. if( i != sd->sc.option )
  6819. pc_setoption(sd, i);
  6820. if( hom_is_active(sd->hd) && pc_checkskill(sd, AM_CALLHOMUN) )
  6821. hom_vaporize(sd, HOM_ST_ACTIVE);
  6822. if (sd->sc.data[SC_SPRITEMABLE] && pc_checkskill(sd, SU_SPRITEMABLE))
  6823. status_change_end(&sd->bl, SC_SPRITEMABLE, INVALID_TIMER);
  6824. }
  6825. for (const auto &skill : skill_db) {
  6826. uint16 skill_id = skill.second->nameid, idx = skill_get_index(skill_id);
  6827. uint8 lv = sd->status.skill[idx].lv;
  6828. if (lv == 0 || skill_id == 0)
  6829. continue;
  6830. if( skill.second->inf2[INF2_ISWEDDING] || skill.second->inf2[INF2_ISSPIRIT] ) //Avoid reseting wedding/linker skills.
  6831. continue;
  6832. // Don't reset trick dead if not a novice/baby
  6833. if( skill_id == NV_TRICKDEAD && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE )
  6834. {
  6835. sd->status.skill[idx].lv = 0;
  6836. sd->status.skill[idx].flag = SKILL_FLAG_PERMANENT;
  6837. continue;
  6838. }
  6839. // do not reset basic skill
  6840. if (skill_id == NV_BASIC && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE )
  6841. continue;
  6842. if( sd->status.skill[idx].flag == SKILL_FLAG_PERM_GRANTED )
  6843. continue;
  6844. if( flag&4 && !skill_ischangesex(skill_id) )
  6845. continue;
  6846. if( skill.second->inf2[INF2_ISQUEST] && !battle_config.quest_skill_learn )
  6847. { //Only handle quest skills in a special way when you can't learn them manually
  6848. if( battle_config.quest_skill_reset && !(flag&2) )
  6849. { //Wipe them
  6850. sd->status.skill[idx].lv = 0;
  6851. sd->status.skill[idx].flag = SKILL_FLAG_PERMANENT;
  6852. }
  6853. continue;
  6854. }
  6855. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  6856. skill_point += lv;
  6857. else
  6858. if( sd->status.skill[idx].flag >= SKILL_FLAG_REPLACED_LV_0 )
  6859. skill_point += (sd->status.skill[idx].flag - SKILL_FLAG_REPLACED_LV_0);
  6860. if( !(flag&2) )
  6861. {// reset
  6862. sd->status.skill[idx].lv = 0;
  6863. sd->status.skill[idx].flag = SKILL_FLAG_PERMANENT;
  6864. }
  6865. }
  6866. if( flag&2 || !skill_point ) return skill_point;
  6867. sd->status.skill_point += skill_point;
  6868. if (flag&1) {
  6869. clif_updatestatus(sd,SP_SKILLPOINT);
  6870. clif_skillinfoblock(sd);
  6871. status_calc_pc(sd, SCO_FORCE);
  6872. }
  6873. return skill_point;
  6874. }
  6875. /*==========================================
  6876. * /resetfeel [Komurka]
  6877. *------------------------------------------*/
  6878. int pc_resetfeel(struct map_session_data* sd)
  6879. {
  6880. int i;
  6881. nullpo_ret(sd);
  6882. for (i=0; i<MAX_PC_FEELHATE; i++)
  6883. {
  6884. sd->feel_map[i].m = -1;
  6885. sd->feel_map[i].index = 0;
  6886. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), 0);
  6887. }
  6888. return 0;
  6889. }
  6890. int pc_resethate(struct map_session_data* sd)
  6891. {
  6892. int i;
  6893. nullpo_ret(sd);
  6894. for (i=0; i<MAX_PC_FEELHATE; i++)
  6895. {
  6896. sd->hate_mob[i] = -1;
  6897. pc_setglobalreg(sd, add_str(sg_info[i].hate_var), 0);
  6898. }
  6899. return 0;
  6900. }
  6901. int pc_skillatk_bonus(struct map_session_data *sd, uint16 skill_id)
  6902. {
  6903. int bonus = 0;
  6904. nullpo_ret(sd);
  6905. skill_id = skill_dummy2skill_id(skill_id);
  6906. for (auto &it : sd->skillatk) {
  6907. if (it.id == skill_id) {
  6908. bonus += it.val;
  6909. break;
  6910. }
  6911. }
  6912. return bonus;
  6913. }
  6914. int pc_sub_skillatk_bonus(struct map_session_data *sd, uint16 skill_id)
  6915. {
  6916. int bonus = 0;
  6917. nullpo_ret(sd);
  6918. skill_id = skill_dummy2skill_id(skill_id);
  6919. for (auto &it : sd->subskill) {
  6920. if (it.id == skill_id) {
  6921. bonus += it.val;
  6922. break;
  6923. }
  6924. }
  6925. return bonus;
  6926. }
  6927. int pc_skillheal_bonus(struct map_session_data *sd, uint16 skill_id) {
  6928. int bonus = sd->bonus.add_heal_rate;
  6929. nullpo_ret(sd);
  6930. skill_id = skill_dummy2skill_id(skill_id);
  6931. if( bonus ) {
  6932. switch( skill_id ) {
  6933. case AL_HEAL: if( !(battle_config.skill_add_heal_rate&1) ) bonus = 0; break;
  6934. case PR_SANCTUARY: if( !(battle_config.skill_add_heal_rate&2) ) bonus = 0; break;
  6935. case AM_POTIONPITCHER: if( !(battle_config.skill_add_heal_rate&4) ) bonus = 0; break;
  6936. case CR_SLIMPITCHER: if( !(battle_config.skill_add_heal_rate&8) ) bonus = 0; break;
  6937. case BA_APPLEIDUN: if( !(battle_config.skill_add_heal_rate&16)) bonus = 0; break;
  6938. }
  6939. }
  6940. for (auto &it : sd->skillheal) {
  6941. if (it.id == skill_id) {
  6942. bonus += it.val;
  6943. break;
  6944. }
  6945. }
  6946. return bonus;
  6947. }
  6948. int pc_skillheal2_bonus(struct map_session_data *sd, uint16 skill_id) {
  6949. int bonus = sd->bonus.add_heal2_rate;
  6950. skill_id = skill_dummy2skill_id(skill_id);
  6951. for (auto &it : sd->skillheal2) {
  6952. if (it.id == skill_id) {
  6953. bonus += it.val;
  6954. break;
  6955. }
  6956. }
  6957. return bonus;
  6958. }
  6959. void pc_respawn(struct map_session_data* sd, clr_type clrtype)
  6960. {
  6961. if( !pc_isdead(sd) )
  6962. return; // not applicable
  6963. if( sd->bg_id && bg_member_respawn(sd) )
  6964. return; // member revived by battleground
  6965. pc_setstand(sd, true);
  6966. pc_setrestartvalue(sd,3);
  6967. if( pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype) != SETPOS_OK )
  6968. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  6969. }
  6970. static TIMER_FUNC(pc_respawn_timer){
  6971. struct map_session_data *sd = map_id2sd(id);
  6972. if( sd != NULL )
  6973. {
  6974. sd->pvp_point=0;
  6975. sd->respawn_tid = INVALID_TIMER;
  6976. pc_respawn(sd,CLR_OUTSIGHT);
  6977. }
  6978. return 0;
  6979. }
  6980. /*==========================================
  6981. * Invoked when a player has received damage
  6982. *------------------------------------------*/
  6983. void pc_damage(struct map_session_data *sd,struct block_list *src,unsigned int hp, unsigned int sp)
  6984. {
  6985. if (sp) clif_updatestatus(sd,SP_SP);
  6986. if (hp) clif_updatestatus(sd,SP_HP);
  6987. else return;
  6988. if (!src)
  6989. return;
  6990. if( pc_issit(sd) ) {
  6991. pc_setstand(sd, true);
  6992. skill_sit(sd,0);
  6993. }
  6994. if (sd->progressbar.npc_id)
  6995. clif_progressbar_abort(sd);
  6996. if( sd->status.pet_id > 0 && sd->pd && battle_config.pet_damage_support )
  6997. pet_target_check(sd->pd,src,1);
  6998. if( sd->status.ele_id > 0 )
  6999. elemental_set_target(sd,src);
  7000. if(battle_config.prevent_logout_trigger&PLT_DAMAGE)
  7001. sd->canlog_tick = gettick();
  7002. }
  7003. TIMER_FUNC(pc_close_npc_timer){
  7004. TBL_PC *sd = map_id2sd(id);
  7005. if(sd) pc_close_npc(sd,data);
  7006. return 0;
  7007. }
  7008. /**
  7009. * Method to properly close a NPC for player and clear anything related.
  7010. * @param sd: Player attached
  7011. * @param flag: Method of closure
  7012. * 1: Produce a close button and end the NPC
  7013. * 2: End the NPC (best for no dialog windows)
  7014. */
  7015. void pc_close_npc(struct map_session_data *sd,int flag)
  7016. {
  7017. nullpo_retv(sd);
  7018. if (sd->npc_id || sd->npc_shopid) {
  7019. if (sd->state.using_fake_npc) {
  7020. clif_clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd);
  7021. sd->state.using_fake_npc = 0;
  7022. }
  7023. if (sd->st) {
  7024. if(sd->st->state == RUN){ //wait ending code execution
  7025. add_timer(gettick()+500,pc_close_npc_timer,sd->bl.id,flag);
  7026. return;
  7027. }
  7028. sd->st->state = ((flag==1 && sd->st->mes_active)?CLOSE:END);
  7029. sd->st->mes_active = 0;
  7030. }
  7031. sd->state.menu_or_input = 0;
  7032. sd->npc_menu = 0;
  7033. sd->npc_shopid = 0;
  7034. #ifdef SECURE_NPCTIMEOUT
  7035. sd->npc_idle_timer = INVALID_TIMER;
  7036. #endif
  7037. if (sd->st) {
  7038. if (sd->st->state == CLOSE) {
  7039. clif_scriptclose(sd, sd->npc_id);
  7040. clif_scriptclear(sd, sd->npc_id); // [Ind/Hercules]
  7041. sd->st->state = END; // Force to end now
  7042. }
  7043. if (sd->st->state == END) { // free attached scripts that are waiting
  7044. script_free_state(sd->st);
  7045. sd->st = NULL;
  7046. sd->npc_id = 0;
  7047. }
  7048. }
  7049. }
  7050. }
  7051. /*==========================================
  7052. * Invoked when a player has negative current hp
  7053. *------------------------------------------*/
  7054. int pc_dead(struct map_session_data *sd,struct block_list *src)
  7055. {
  7056. int i=0,k=0;
  7057. t_tick tick = gettick();
  7058. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  7059. // Activate Steel body if a super novice dies at 99+% exp [celest]
  7060. // Super Novices have no kill or die functions attached when saved by their angel
  7061. if (!sd->state.snovice_dead_flag && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) {
  7062. unsigned int exp = pc_nextbaseexp(sd);
  7063. if( exp && get_percentage(sd->status.base_exp,exp) >= 99 ) {
  7064. sd->state.snovice_dead_flag = 1;
  7065. pc_setrestartvalue(sd,1);
  7066. status_percent_heal(&sd->bl, 100, 100);
  7067. clif_resurrection(&sd->bl, 1);
  7068. if(battle_config.pc_invincible_time)
  7069. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  7070. sc_start(&sd->bl,&sd->bl,status_skill2sc(MO_STEELBODY),100,5,skill_get_time(MO_STEELBODY,5));
  7071. if(mapdata_flag_gvg2(mapdata))
  7072. pc_respawn_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
  7073. return 0;
  7074. }
  7075. }
  7076. for(k = 0; k < MAX_DEVOTION; k++) {
  7077. if (sd->devotion[k]){
  7078. struct map_session_data *devsd = map_id2sd(sd->devotion[k]);
  7079. if (devsd)
  7080. status_change_end(&devsd->bl, SC_DEVOTION, INVALID_TIMER);
  7081. sd->devotion[k] = 0;
  7082. }
  7083. }
  7084. for (k = 0; k < MAX_STELLAR_MARKS; k++) {
  7085. if (sd->stellar_mark[k]) {
  7086. struct map_session_data *smarksd = map_id2sd(sd->stellar_mark[k]);
  7087. if (smarksd)
  7088. status_change_end(&smarksd->bl, SC_FLASHKICK, INVALID_TIMER);
  7089. sd->stellar_mark[k] = 0;
  7090. }
  7091. }
  7092. for (k = 0; k < MAX_UNITED_SOULS; k++) {
  7093. if (sd->united_soul[k]) {
  7094. struct map_session_data *usoulsd = map_id2sd(sd->united_soul[k]);
  7095. if (usoulsd)
  7096. status_change_end(&usoulsd->bl, SC_SOULUNITY, INVALID_TIMER);
  7097. sd->united_soul[k] = 0;
  7098. }
  7099. }
  7100. if(sd->shadowform_id) { //if we were target of shadowform
  7101. status_change_end(map_id2bl(sd->shadowform_id), SC__SHADOWFORM, INVALID_TIMER);
  7102. sd->shadowform_id = 0; //should be remove on status end anyway
  7103. }
  7104. if(sd->status.pet_id > 0 && sd->pd) {
  7105. struct pet_data *pd = sd->pd;
  7106. if( !mapdata->flag[MF_NOEXPPENALTY] ) {
  7107. pet_set_intimate(pd, pd->pet.intimate + pd->get_pet_db()->die);
  7108. if( pd->pet.intimate <= PET_INTIMATE_NONE )
  7109. pet_set_intimate(pd, PET_INTIMATE_NONE);
  7110. clif_send_petdata(sd,sd->pd,1,pd->pet.intimate);
  7111. }
  7112. if( sd->pd->target_id ) // Unlock all targets...
  7113. pet_unlocktarget(sd->pd);
  7114. }
  7115. if (hom_is_active(sd->hd) && battle_config.homunculus_auto_vapor && get_percentage(sd->hd->battle_status.hp, sd->hd->battle_status.max_hp) >= battle_config.homunculus_auto_vapor)
  7116. hom_vaporize(sd, HOM_ST_ACTIVE);
  7117. if( sd->md )
  7118. mercenary_delete(sd->md, 3); // Your mercenary soldier has ran away.
  7119. if( sd->ed )
  7120. elemental_delete(sd->ed);
  7121. // Leave duel if you die [LuzZza]
  7122. if(battle_config.duel_autoleave_when_die) {
  7123. if(sd->duel_group > 0)
  7124. duel_leave(sd->duel_group, sd);
  7125. if(sd->duel_invite > 0)
  7126. duel_reject(sd->duel_invite, sd);
  7127. }
  7128. pc_close_npc(sd,2); //close npc if we were using one
  7129. /* e.g. not killed thru pc_damage */
  7130. if( pc_issit(sd) ) {
  7131. clif_status_load(&sd->bl,EFST_SIT,0);
  7132. }
  7133. pc_setdead(sd);
  7134. clif_party_dead( sd );
  7135. pc_setglobalreg(sd, add_str(PCDIECOUNTER_VAR), sd->die_counter+1);
  7136. pc_setparam(sd, SP_KILLERRID, src?src->id:0);
  7137. //Reset menu skills/item skills
  7138. if ((sd->skillitem) != 0)
  7139. sd->skillitem = sd->skillitemlv = 0;
  7140. if ((sd->menuskill_id) != 0)
  7141. sd->menuskill_id = sd->menuskill_val = 0;
  7142. //Reset ticks.
  7143. sd->hp_loss.tick = sd->sp_loss.tick = sd->hp_regen.tick = sd->sp_regen.tick = 0;
  7144. if ( sd->spiritball !=0 )
  7145. pc_delspiritball(sd,sd->spiritball,0);
  7146. if (sd->soulball != 0)
  7147. pc_delsoulball(sd, sd->soulball, 0);
  7148. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  7149. pc_delspiritcharm(sd,sd->spiritcharm,sd->spiritcharm_type);
  7150. if (src)
  7151. switch (src->type) {
  7152. case BL_MOB:
  7153. {
  7154. struct mob_data *md=(struct mob_data *)src;
  7155. if(md->target_id==sd->bl.id)
  7156. mob_unlocktarget(md,tick);
  7157. if(battle_config.mobs_level_up && md->status.hp &&
  7158. (unsigned int)md->level < pc_maxbaselv(sd) &&
  7159. !md->guardian_data && !md->special_state.ai// Guardians/summons should not level. [Skotlex]
  7160. ) { // monster level up [Valaris]
  7161. clif_misceffect(&md->bl,0);
  7162. md->level++;
  7163. status_calc_mob(md, SCO_NONE);
  7164. status_percent_heal(src,10,0);
  7165. if( battle_config.show_mob_info&4 )
  7166. {// update name with new level
  7167. clif_name_area(&md->bl);
  7168. }
  7169. }
  7170. src = battle_get_master(src); // Maybe Player Summon
  7171. }
  7172. break;
  7173. case BL_PET: //Pass on to master...
  7174. case BL_HOM:
  7175. case BL_MER:
  7176. src = battle_get_master(src);
  7177. break;
  7178. }
  7179. if (src && src->type == BL_PC) {
  7180. struct map_session_data *ssd = (struct map_session_data *)src;
  7181. pc_setparam(ssd, SP_KILLEDRID, sd->bl.id);
  7182. npc_script_event(ssd, NPCE_KILLPC);
  7183. if (battle_config.pk_mode&2) {
  7184. ssd->status.manner -= 5;
  7185. if(ssd->status.manner < 0)
  7186. sc_start(&sd->bl,src,SC_NOCHAT,100,0,0);
  7187. #if 0
  7188. // PK/Karma system code (not enabled yet) [celest]
  7189. // originally from Kade Online, so i don't know if any of these is correct ^^;
  7190. // note: karma is measured REVERSE, so more karma = more 'evil' / less honourable,
  7191. // karma going down = more 'good' / more honourable.
  7192. // The Karma System way...
  7193. if (sd->status.karma > ssd->status.karma) { // If player killed was more evil
  7194. sd->status.karma--;
  7195. ssd->status.karma--;
  7196. }
  7197. else if (sd->status.karma < ssd->status.karma) // If player killed was more good
  7198. ssd->status.karma++;
  7199. // or the PK System way...
  7200. if (sd->status.karma > 0) // player killed is dishonourable?
  7201. ssd->status.karma--; // honour points earned
  7202. sd->status.karma++; // honour points lost
  7203. // To-do: Receive exp on certain occasions
  7204. #endif
  7205. }
  7206. }
  7207. if(battle_config.bone_drop==2
  7208. || (battle_config.bone_drop==1 && mapdata->flag[MF_PVP]))
  7209. {
  7210. struct item item_tmp;
  7211. memset(&item_tmp,0,sizeof(item_tmp));
  7212. item_tmp.nameid=ITEMID_SKULL_;
  7213. item_tmp.identify=1;
  7214. item_tmp.card[0]=CARD0_CREATE;
  7215. item_tmp.card[1]=0;
  7216. item_tmp.card[2]=GetWord(sd->status.char_id,0); // CharId
  7217. item_tmp.card[3]=GetWord(sd->status.char_id,1);
  7218. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0,0);
  7219. }
  7220. //Remove bonus_script when dead
  7221. pc_bonus_script_clear(sd,BSF_REM_ON_DEAD);
  7222. // changed penalty options, added death by player if pk_mode [Valaris]
  7223. if(battle_config.death_penalty_type
  7224. && (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE // only novices will receive no penalty
  7225. && !sd->sc.data[SC_BABY] && !sd->sc.data[SC_LIFEINSURANCE]
  7226. && !mapdata->flag[MF_NOEXPPENALTY] && !mapdata_flag_gvg2(mapdata))
  7227. {
  7228. uint32 base_penalty = 0;
  7229. uint32 job_penalty = 0;
  7230. uint32 zeny_penalty = 0;
  7231. if (pc_isvip(sd)) { // EXP penalty for VIP
  7232. base_penalty = battle_config.vip_exp_penalty_base;
  7233. job_penalty = battle_config.vip_exp_penalty_job;
  7234. zeny_penalty = battle_config.vip_zeny_penalty;
  7235. } else {
  7236. base_penalty = battle_config.death_penalty_base;
  7237. job_penalty = battle_config.death_penalty_job;
  7238. zeny_penalty = battle_config.zeny_penalty;
  7239. }
  7240. if ((battle_config.death_penalty_maxlv&1 || !pc_is_maxbaselv(sd)) && base_penalty > 0) {
  7241. switch (battle_config.death_penalty_type) {
  7242. case 1: base_penalty = (uint32) ( pc_nextbaseexp(sd) * ( base_penalty / 10000. ) ); break;
  7243. case 2: base_penalty = (uint32) ( sd->status.base_exp * ( base_penalty / 10000. ) ); break;
  7244. }
  7245. if (base_penalty){ //recheck after altering to speedup
  7246. if (battle_config.pk_mode && src && src->type==BL_PC)
  7247. base_penalty *= 2;
  7248. base_penalty = u32min(sd->status.base_exp, base_penalty);
  7249. }
  7250. }
  7251. else
  7252. base_penalty = 0;
  7253. if ((battle_config.death_penalty_maxlv&2 || !pc_is_maxjoblv(sd)) && job_penalty > 0) {
  7254. switch (battle_config.death_penalty_type) {
  7255. case 1: job_penalty = (uint32) ( pc_nextjobexp(sd) * ( job_penalty / 10000. ) ); break;
  7256. case 2: job_penalty = (uint32) ( sd->status.job_exp * ( job_penalty /10000. ) ); break;
  7257. }
  7258. if (job_penalty) {
  7259. if (battle_config.pk_mode && src && src->type==BL_PC)
  7260. job_penalty *= 2;
  7261. job_penalty = u32min(sd->status.job_exp, job_penalty);
  7262. }
  7263. }
  7264. else
  7265. job_penalty = 0;
  7266. if (base_penalty || job_penalty)
  7267. pc_lostexp(sd, base_penalty, job_penalty);
  7268. if( zeny_penalty > 0 && !mapdata->flag[MF_NOZENYPENALTY]) {
  7269. zeny_penalty = (uint32)( sd->status.zeny * ( zeny_penalty / 10000. ) );
  7270. if(zeny_penalty)
  7271. pc_payzeny(sd, zeny_penalty, LOG_TYPE_PICKDROP_PLAYER, NULL);
  7272. }
  7273. }
  7274. if( mapdata->flag[MF_PVP_NIGHTMAREDROP] ) { // Moved this outside so it works when PVP isn't enabled and during pk mode [Ancyker]
  7275. for (const auto &it : mapdata->drop_list) {
  7276. int id = it.drop_id, per = it.drop_per;
  7277. enum e_nightmare_drop_type type = it.drop_type;
  7278. if(id == 0)
  7279. continue;
  7280. if(id == -1){
  7281. int eq_num=0,eq_n[MAX_INVENTORY];
  7282. memset(eq_n,0,sizeof(eq_n));
  7283. for(i=0;i<MAX_INVENTORY;i++) {
  7284. if( (type&NMDT_INVENTORY && !sd->inventory.u.items_inventory[i].equip)
  7285. || (type&NMDT_EQUIP && sd->inventory.u.items_inventory[i].equip)
  7286. || type&NMDT_ALL)
  7287. {
  7288. int l;
  7289. ARR_FIND( 0, MAX_INVENTORY, l, eq_n[l] <= 0 );
  7290. if( l < MAX_INVENTORY )
  7291. eq_n[l] = i;
  7292. eq_num++;
  7293. }
  7294. }
  7295. if(eq_num > 0){
  7296. int n = eq_n[rnd()%eq_num];
  7297. if(rnd()%10000 < per) {
  7298. if(sd->inventory.u.items_inventory[n].equip)
  7299. pc_unequipitem(sd,n,3);
  7300. pc_dropitem(sd,n,1);
  7301. }
  7302. }
  7303. }
  7304. else if(id > 0) {
  7305. for(i=0;i<MAX_INVENTORY;i++){
  7306. if(sd->inventory.u.items_inventory[i].nameid == id
  7307. && rnd()%10000 < per
  7308. && ((type&NMDT_INVENTORY && !sd->inventory.u.items_inventory[i].equip)
  7309. || (type&NMDT_EQUIP && sd->inventory.u.items_inventory[i].equip)
  7310. || type&NMDT_ALL) ){
  7311. if(sd->inventory.u.items_inventory[i].equip)
  7312. pc_unequipitem(sd,i,3);
  7313. pc_dropitem(sd,i,1);
  7314. break;
  7315. }
  7316. }
  7317. }
  7318. }
  7319. }
  7320. // pvp
  7321. // disable certain pvp functions on pk_mode [Valaris]
  7322. if( !battle_config.pk_mode && mapdata->flag[MF_PVP] && !mapdata->flag[MF_PVP_NOCALCRANK] ) {
  7323. sd->pvp_point -= 5;
  7324. sd->pvp_lost++;
  7325. if( src && src->type == BL_PC ) {
  7326. struct map_session_data *ssd = (struct map_session_data *)src;
  7327. ssd->pvp_point++;
  7328. ssd->pvp_won++;
  7329. }
  7330. if( sd->pvp_point < 0 ) {
  7331. sd->respawn_tid = add_timer(tick+1000, pc_respawn_timer,sd->bl.id,0);
  7332. return 1|8;
  7333. }
  7334. }
  7335. //GvG
  7336. if( mapdata_flag_gvg2(mapdata) ) {
  7337. sd->respawn_tid = add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
  7338. return 1|8;
  7339. }
  7340. else if( sd->bg_id ) {
  7341. std::shared_ptr<s_battleground_data> bg = util::umap_find(bg_team_db, sd->bg_id);
  7342. if (bg) {
  7343. if (bg->cemetery.map > 0) { // Respawn by BG
  7344. sd->respawn_tid = add_timer(tick + 1000, pc_respawn_timer, sd->bl.id, 0);
  7345. return 1|8;
  7346. }
  7347. }
  7348. }
  7349. //Reset "can log out" tick.
  7350. if( battle_config.prevent_logout )
  7351. sd->canlog_tick = gettick() - battle_config.prevent_logout;
  7352. return 1;
  7353. }
  7354. void pc_revive(struct map_session_data *sd,unsigned int hp, unsigned int sp) {
  7355. if(hp) clif_updatestatus(sd,SP_HP);
  7356. if(sp) clif_updatestatus(sd,SP_SP);
  7357. pc_setstand(sd, true);
  7358. if(battle_config.pc_invincible_time > 0)
  7359. pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
  7360. if( sd->state.gmaster_flag ) {
  7361. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  7362. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  7363. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  7364. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  7365. }
  7366. }
  7367. bool pc_revive_item(struct map_session_data *sd) {
  7368. nullpo_retr(false, sd);
  7369. if (!pc_isdead(sd) || sd->respawn_tid != INVALID_TIMER)
  7370. return false;
  7371. if (sd->sc.data[SC_HELLPOWER]) // Cannot resurrect while under the effect of SC_HELLPOWER.
  7372. return false;
  7373. int16 item_position = itemdb_group_item_exists_pc(sd, IG_TOKEN_OF_SIEGFRIED);
  7374. uint8 hp = 100, sp = 100;
  7375. if (item_position < 0) {
  7376. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  7377. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  7378. sp = 0;
  7379. }
  7380. else
  7381. return false;
  7382. }
  7383. if (!status_revive(&sd->bl, hp, sp))
  7384. return false;
  7385. if (item_position < 0)
  7386. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  7387. else
  7388. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  7389. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  7390. return true;
  7391. }
  7392. // script
  7393. //
  7394. /*==========================================
  7395. * script reading pc status registry
  7396. *------------------------------------------*/
  7397. int64 pc_readparam(struct map_session_data* sd,int64 type)
  7398. {
  7399. int64 val = 0;
  7400. nullpo_ret(sd);
  7401. switch(type) {
  7402. case SP_SKILLPOINT: val = sd->status.skill_point; break;
  7403. case SP_STATUSPOINT: val = sd->status.status_point; break;
  7404. case SP_ZENY: val = sd->status.zeny; break;
  7405. case SP_BASELEVEL: val = sd->status.base_level; break;
  7406. case SP_JOBLEVEL: val = sd->status.job_level; break;
  7407. case SP_CLASS: val = sd->status.class_; break;
  7408. case SP_BASEJOB: val = pc_mapid2jobid(sd->class_&MAPID_UPPERMASK, sd->status.sex); break; //Base job, extracting upper type.
  7409. case SP_UPPER: val = sd->class_&JOBL_UPPER?1:(sd->class_&JOBL_BABY?2:0); break;
  7410. case SP_BASECLASS: val = pc_mapid2jobid(sd->class_&MAPID_BASEMASK, sd->status.sex); break; //Extract base class tree. [Skotlex]
  7411. case SP_SEX: val = sd->status.sex; break;
  7412. case SP_WEIGHT: val = sd->weight; break;
  7413. case SP_MAXWEIGHT: val = sd->max_weight; break;
  7414. case SP_BASEEXP: val = sd->status.base_exp; break;
  7415. case SP_JOBEXP: val = sd->status.job_exp; break;
  7416. case SP_NEXTBASEEXP: val = pc_nextbaseexp(sd); break;
  7417. case SP_NEXTJOBEXP: val = pc_nextjobexp(sd); break;
  7418. case SP_HP: val = sd->battle_status.hp; break;
  7419. case SP_MAXHP: val = sd->battle_status.max_hp; break;
  7420. case SP_SP: val = sd->battle_status.sp; break;
  7421. case SP_MAXSP: val = sd->battle_status.max_sp; break;
  7422. case SP_STR: val = sd->status.str; break;
  7423. case SP_AGI: val = sd->status.agi; break;
  7424. case SP_VIT: val = sd->status.vit; break;
  7425. case SP_INT: val = sd->status.int_; break;
  7426. case SP_DEX: val = sd->status.dex; break;
  7427. case SP_LUK: val = sd->status.luk; break;
  7428. case SP_KARMA: val = sd->status.karma; break;
  7429. case SP_MANNER: val = sd->status.manner; break;
  7430. case SP_FAME: val = sd->status.fame; break;
  7431. case SP_KILLERRID: val = sd->killerrid; break;
  7432. case SP_KILLEDRID: val = sd->killedrid; break;
  7433. case SP_KILLEDGID: val = sd->killedgid; break;
  7434. case SP_SITTING: val = pc_issit(sd)?1:0; break;
  7435. case SP_CHARMOVE: val = sd->status.character_moves; break;
  7436. case SP_CHARRENAME: val = sd->status.rename; break;
  7437. case SP_CHARFONT: val = sd->status.font; break;
  7438. case SP_BANK_VAULT: val = sd->bank_vault; break;
  7439. case SP_CASHPOINTS: val = sd->cashPoints; break;
  7440. case SP_KAFRAPOINTS: val = sd->kafraPoints; break;
  7441. case SP_ROULETTE_BRONZE: val = sd->roulette_point.bronze; break;
  7442. case SP_ROULETTE_SILVER: val = sd->roulette_point.silver; break;
  7443. case SP_ROULETTE_GOLD: val = sd->roulette_point.gold; break;
  7444. case SP_PCDIECOUNTER: val = sd->die_counter; break;
  7445. case SP_COOKMASTERY: val = sd->cook_mastery; break;
  7446. case SP_ACHIEVEMENT_LEVEL: val = sd->achievement_data.level; break;
  7447. case SP_CRITICAL: val = sd->battle_status.cri/10; break;
  7448. case SP_ASPD: val = (2000-sd->battle_status.amotion)/10; break;
  7449. case SP_BASE_ATK:
  7450. #ifdef RENEWAL
  7451. val = sd->bonus.eatk;
  7452. #else
  7453. val = sd->battle_status.batk;
  7454. #endif
  7455. break;
  7456. case SP_DEF1: val = sd->battle_status.def; break;
  7457. case SP_DEF2: val = sd->battle_status.def2; break;
  7458. case SP_MDEF1: val = sd->battle_status.mdef; break;
  7459. case SP_MDEF2: val = sd->battle_status.mdef2; break;
  7460. case SP_HIT: val = sd->battle_status.hit; break;
  7461. case SP_FLEE1: val = sd->battle_status.flee; break;
  7462. case SP_FLEE2: val = sd->battle_status.flee2; break;
  7463. case SP_DEFELE: val = sd->battle_status.def_ele; break;
  7464. case SP_MAXHPRATE: val = sd->hprate; break;
  7465. case SP_MAXSPRATE: val = sd->sprate; break;
  7466. case SP_SPRATE: val = sd->dsprate; break;
  7467. case SP_SPEED_RATE: val = sd->bonus.speed_rate; break;
  7468. case SP_SPEED_ADDRATE: val = sd->bonus.speed_add_rate; break;
  7469. case SP_ASPD_RATE:
  7470. #ifndef RENEWAL_ASPD
  7471. val = sd->battle_status.aspd_rate;
  7472. #else
  7473. val = sd->battle_status.aspd_rate2;
  7474. #endif
  7475. break;
  7476. case SP_HP_RECOV_RATE: val = sd->hprecov_rate; break;
  7477. case SP_SP_RECOV_RATE: val = sd->sprecov_rate; break;
  7478. case SP_CRITICAL_DEF: val = sd->bonus.critical_def; break;
  7479. case SP_NEAR_ATK_DEF: val = sd->bonus.near_attack_def_rate; break;
  7480. case SP_LONG_ATK_DEF: val = sd->bonus.long_attack_def_rate; break;
  7481. case SP_DOUBLE_RATE: val = sd->bonus.double_rate; break;
  7482. case SP_DOUBLE_ADD_RATE: val = sd->bonus.double_add_rate; break;
  7483. case SP_MATK_RATE: val = sd->matk_rate; break;
  7484. case SP_ATK_RATE: val = sd->bonus.atk_rate; break;
  7485. case SP_MAGIC_ATK_DEF: val = sd->bonus.magic_def_rate; break;
  7486. case SP_MISC_ATK_DEF: val = sd->bonus.misc_def_rate; break;
  7487. case SP_PERFECT_HIT_RATE:val = sd->bonus.perfect_hit; break;
  7488. case SP_PERFECT_HIT_ADD_RATE: val = sd->bonus.perfect_hit_add; break;
  7489. case SP_CRITICAL_RATE: val = sd->critical_rate; break;
  7490. case SP_HIT_RATE: val = sd->hit_rate; break;
  7491. case SP_FLEE_RATE: val = sd->flee_rate; break;
  7492. case SP_FLEE2_RATE: val = sd->flee2_rate; break;
  7493. case SP_DEF_RATE: val = sd->def_rate; break;
  7494. case SP_DEF2_RATE: val = sd->def2_rate; break;
  7495. case SP_MDEF_RATE: val = sd->mdef_rate; break;
  7496. case SP_MDEF2_RATE: val = sd->mdef2_rate; break;
  7497. case SP_RESTART_FULL_RECOVER: val = sd->special_state.restart_full_recover?1:0; break;
  7498. case SP_NO_CASTCANCEL: val = sd->special_state.no_castcancel?1:0; break;
  7499. case SP_NO_CASTCANCEL2: val = sd->special_state.no_castcancel2?1:0; break;
  7500. case SP_NO_SIZEFIX: val = sd->special_state.no_sizefix?1:0; break;
  7501. case SP_NO_MAGIC_DAMAGE: val = sd->special_state.no_magic_damage; break;
  7502. case SP_NO_WEAPON_DAMAGE:val = sd->special_state.no_weapon_damage; break;
  7503. case SP_NO_MISC_DAMAGE: val = sd->special_state.no_misc_damage; break;
  7504. case SP_NO_GEMSTONE: val = sd->special_state.no_gemstone?1:0; break;
  7505. case SP_INTRAVISION: val = sd->special_state.intravision?1:0; break;
  7506. case SP_NO_KNOCKBACK: val = sd->special_state.no_knockback?1:0; break;
  7507. case SP_NO_MADO_FUEL: val = sd->special_state.no_mado_fuel?1:0; break;
  7508. case SP_NO_WALK_DELAY: val = sd->special_state.no_walk_delay?1:0; break;
  7509. case SP_SPLASH_RANGE: val = sd->bonus.splash_range; break;
  7510. case SP_SPLASH_ADD_RANGE:val = sd->bonus.splash_add_range; break;
  7511. case SP_SHORT_WEAPON_DAMAGE_RETURN: val = sd->bonus.short_weapon_damage_return; break;
  7512. case SP_LONG_WEAPON_DAMAGE_RETURN: val = sd->bonus.long_weapon_damage_return; break;
  7513. case SP_MAGIC_DAMAGE_RETURN: val = sd->bonus.magic_damage_return; break;
  7514. case SP_PERFECT_HIDE: val = sd->special_state.perfect_hiding?1:0; break;
  7515. case SP_UNBREAKABLE: val = sd->bonus.unbreakable; break;
  7516. case SP_UNBREAKABLE_WEAPON: val = (sd->bonus.unbreakable_equip&EQP_WEAPON)?1:0; break;
  7517. case SP_UNBREAKABLE_ARMOR: val = (sd->bonus.unbreakable_equip&EQP_ARMOR)?1:0; break;
  7518. case SP_UNBREAKABLE_HELM: val = (sd->bonus.unbreakable_equip&EQP_HELM)?1:0; break;
  7519. case SP_UNBREAKABLE_SHIELD: val = (sd->bonus.unbreakable_equip&EQP_SHIELD)?1:0; break;
  7520. case SP_UNBREAKABLE_GARMENT: val = (sd->bonus.unbreakable_equip&EQP_GARMENT)?1:0; break;
  7521. case SP_UNBREAKABLE_SHOES: val = (sd->bonus.unbreakable_equip&EQP_SHOES)?1:0; break;
  7522. case SP_CLASSCHANGE: val = sd->bonus.classchange; break;
  7523. case SP_LONG_ATK_RATE: val = sd->bonus.long_attack_atk_rate; break;
  7524. case SP_BREAK_WEAPON_RATE: val = sd->bonus.break_weapon_rate; break;
  7525. case SP_BREAK_ARMOR_RATE: val = sd->bonus.break_armor_rate; break;
  7526. case SP_ADD_STEAL_RATE: val = sd->bonus.add_steal_rate; break;
  7527. case SP_DELAYRATE: val = sd->delayrate; break;
  7528. case SP_CRIT_ATK_RATE: val = sd->bonus.crit_atk_rate; break;
  7529. case SP_UNSTRIPABLE_WEAPON: val = (sd->bonus.unstripable_equip&EQP_WEAPON)?1:0; break;
  7530. case SP_UNSTRIPABLE:
  7531. case SP_UNSTRIPABLE_ARMOR:
  7532. val = (sd->bonus.unstripable_equip&EQP_ARMOR)?1:0;
  7533. break;
  7534. case SP_UNSTRIPABLE_HELM: val = (sd->bonus.unstripable_equip&EQP_HELM)?1:0; break;
  7535. case SP_UNSTRIPABLE_SHIELD: val = (sd->bonus.unstripable_equip&EQP_SHIELD)?1:0; break;
  7536. case SP_SP_GAIN_VALUE: val = sd->bonus.sp_gain_value; break;
  7537. case SP_HP_GAIN_VALUE: val = sd->bonus.hp_gain_value; break;
  7538. case SP_LONG_SP_GAIN_VALUE: val = sd->bonus.long_sp_gain_value; break;
  7539. case SP_LONG_HP_GAIN_VALUE: val = sd->bonus.long_hp_gain_value; break;
  7540. case SP_MAGIC_SP_GAIN_VALUE: val = sd->bonus.magic_sp_gain_value; break;
  7541. case SP_MAGIC_HP_GAIN_VALUE: val = sd->bonus.magic_hp_gain_value; break;
  7542. case SP_ADD_HEAL_RATE: val = sd->bonus.add_heal_rate; break;
  7543. case SP_ADD_HEAL2_RATE: val = sd->bonus.add_heal2_rate; break;
  7544. case SP_ADD_ITEM_HEAL_RATE: val = sd->bonus.itemhealrate2; break;
  7545. case SP_EMATK: val = sd->bonus.ematk; break;
  7546. case SP_FIXCASTRATE: val = sd->bonus.fixcastrate; break;
  7547. case SP_ADD_FIXEDCAST: val = sd->bonus.add_fixcast; break;
  7548. case SP_ADD_VARIABLECAST: val = sd->bonus.add_varcast; break;
  7549. case SP_CASTRATE:
  7550. case SP_VARCASTRATE:
  7551. #ifdef RENEWAL_CAST
  7552. val = sd->bonus.varcastrate; break;
  7553. #else
  7554. val = sd->castrate; break;
  7555. #endif
  7556. default:
  7557. ShowError("pc_readparam: Attempt to read unknown parameter '%lld'.\n", type);
  7558. return -1;
  7559. }
  7560. return val;
  7561. }
  7562. /*==========================================
  7563. * script set pc status registry
  7564. *------------------------------------------*/
  7565. bool pc_setparam(struct map_session_data *sd,int64 type,int64 val_tmp)
  7566. {
  7567. nullpo_retr(false,sd);
  7568. int val = static_cast<unsigned int>(val_tmp);
  7569. switch(type){
  7570. case SP_BASELEVEL:
  7571. if (val > pc_maxbaselv(sd)) //Capping to max
  7572. val = pc_maxbaselv(sd);
  7573. if (val > sd->status.base_level) {
  7574. int i = 0;
  7575. int stat=0;
  7576. for (i = 0; i < (int)(val - sd->status.base_level); i++)
  7577. stat += pc_gets_status_point(sd->status.base_level + i);
  7578. sd->status.status_point += stat;
  7579. }
  7580. sd->status.base_level = val;
  7581. sd->status.base_exp = 0;
  7582. // clif_updatestatus(sd, SP_BASELEVEL); // Gets updated at the bottom
  7583. clif_updatestatus(sd, SP_NEXTBASEEXP);
  7584. clif_updatestatus(sd, SP_STATUSPOINT);
  7585. clif_updatestatus(sd, SP_BASEEXP);
  7586. status_calc_pc(sd, SCO_FORCE);
  7587. if(sd->status.party_id)
  7588. party_send_levelup(sd);
  7589. break;
  7590. case SP_JOBLEVEL:
  7591. if (val >= sd->status.job_level) {
  7592. if (val > pc_maxjoblv(sd)) val = pc_maxjoblv(sd);
  7593. sd->status.skill_point += val - sd->status.job_level;
  7594. clif_updatestatus(sd, SP_SKILLPOINT);
  7595. }
  7596. sd->status.job_level = val;
  7597. sd->status.job_exp = 0;
  7598. // clif_updatestatus(sd, SP_JOBLEVEL); // Gets updated at the bottom
  7599. clif_updatestatus(sd, SP_NEXTJOBEXP);
  7600. clif_updatestatus(sd, SP_JOBEXP);
  7601. status_calc_pc(sd, SCO_FORCE);
  7602. break;
  7603. case SP_SKILLPOINT:
  7604. sd->status.skill_point = val;
  7605. break;
  7606. case SP_STATUSPOINT:
  7607. sd->status.status_point = val;
  7608. break;
  7609. case SP_ZENY:
  7610. if( val < 0 )
  7611. return false;// can't set negative zeny
  7612. log_zeny(sd, LOG_TYPE_SCRIPT, sd, -(sd->status.zeny - cap_value(val, 0, MAX_ZENY)));
  7613. sd->status.zeny = cap_value(val, 0, MAX_ZENY);
  7614. break;
  7615. case SP_BASEEXP:
  7616. {
  7617. val = cap_value(val, 0, INT_MAX);
  7618. if (val < sd->status.base_exp) // Lost
  7619. pc_lostexp(sd, sd->status.base_exp - val, 0);
  7620. else // Gained
  7621. pc_gainexp(sd, NULL, val - sd->status.base_exp, 0, 2);
  7622. }
  7623. return true;
  7624. case SP_JOBEXP:
  7625. {
  7626. val = cap_value(val, 0, INT_MAX);
  7627. if (val < sd->status.job_exp) // Lost
  7628. pc_lostexp(sd, 0, sd->status.job_exp - val);
  7629. else // Gained
  7630. pc_gainexp(sd, NULL, 0, val - sd->status.job_exp, 2);
  7631. }
  7632. return true;
  7633. case SP_SEX:
  7634. sd->status.sex = val ? SEX_MALE : SEX_FEMALE;
  7635. break;
  7636. case SP_WEIGHT:
  7637. sd->weight = val;
  7638. break;
  7639. case SP_MAXWEIGHT:
  7640. sd->max_weight = val;
  7641. break;
  7642. case SP_HP:
  7643. sd->battle_status.hp = cap_value(val, 1, (int)sd->battle_status.max_hp);
  7644. break;
  7645. case SP_MAXHP:
  7646. if (sd->status.base_level < 100)
  7647. sd->battle_status.max_hp = cap_value(val, 1, battle_config.max_hp_lv99);
  7648. else if (sd->status.base_level < 151)
  7649. sd->battle_status.max_hp = cap_value(val, 1, battle_config.max_hp_lv150);
  7650. else
  7651. sd->battle_status.max_hp = cap_value(val, 1, battle_config.max_hp);
  7652. if( sd->battle_status.max_hp < sd->battle_status.hp )
  7653. {
  7654. sd->battle_status.hp = sd->battle_status.max_hp;
  7655. clif_updatestatus(sd, SP_HP);
  7656. }
  7657. break;
  7658. case SP_SP:
  7659. sd->battle_status.sp = cap_value(val, 0, (int)sd->battle_status.max_sp);
  7660. break;
  7661. case SP_MAXSP:
  7662. sd->battle_status.max_sp = cap_value(val, 1, battle_config.max_sp);
  7663. if( sd->battle_status.max_sp < sd->battle_status.sp )
  7664. {
  7665. sd->battle_status.sp = sd->battle_status.max_sp;
  7666. clif_updatestatus(sd, SP_SP);
  7667. }
  7668. break;
  7669. case SP_STR:
  7670. sd->status.str = cap_value(val, 1, pc_maxparameter(sd,PARAM_STR));
  7671. break;
  7672. case SP_AGI:
  7673. sd->status.agi = cap_value(val, 1, pc_maxparameter(sd,PARAM_AGI));
  7674. break;
  7675. case SP_VIT:
  7676. sd->status.vit = cap_value(val, 1, pc_maxparameter(sd,PARAM_VIT));
  7677. break;
  7678. case SP_INT:
  7679. sd->status.int_ = cap_value(val, 1, pc_maxparameter(sd,PARAM_INT));
  7680. break;
  7681. case SP_DEX:
  7682. sd->status.dex = cap_value(val, 1, pc_maxparameter(sd,PARAM_DEX));
  7683. break;
  7684. case SP_LUK:
  7685. sd->status.luk = cap_value(val, 1, pc_maxparameter(sd,PARAM_LUK));
  7686. break;
  7687. case SP_KARMA:
  7688. sd->status.karma = val;
  7689. break;
  7690. case SP_MANNER:
  7691. sd->status.manner = val;
  7692. if( val < 0 )
  7693. sc_start(NULL, &sd->bl, SC_NOCHAT, 100, 0, 0);
  7694. else {
  7695. status_change_end(&sd->bl, SC_NOCHAT, INVALID_TIMER);
  7696. clif_manner_message(sd, 5);
  7697. }
  7698. return true; // status_change_start/status_change_end already sends packets warning the client
  7699. case SP_FAME:
  7700. sd->status.fame = val;
  7701. break;
  7702. case SP_KILLERRID:
  7703. sd->killerrid = val;
  7704. return true;
  7705. case SP_KILLEDRID:
  7706. sd->killedrid = val;
  7707. return true;
  7708. case SP_KILLEDGID:
  7709. sd->killedgid = val;
  7710. return true;
  7711. case SP_CHARMOVE:
  7712. sd->status.character_moves = val;
  7713. return true;
  7714. case SP_CHARRENAME:
  7715. sd->status.rename = val;
  7716. return true;
  7717. case SP_CHARFONT:
  7718. sd->status.font = val;
  7719. clif_font(sd);
  7720. return true;
  7721. case SP_BANK_VAULT:
  7722. if (val < 0)
  7723. return false;
  7724. log_zeny(sd, LOG_TYPE_BANK, sd, -(sd->bank_vault - cap_value(val, 0, MAX_BANK_ZENY)));
  7725. sd->bank_vault = cap_value(val, 0, MAX_BANK_ZENY);
  7726. pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
  7727. return true;
  7728. case SP_ROULETTE_BRONZE:
  7729. sd->roulette_point.bronze = val;
  7730. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  7731. return true;
  7732. case SP_ROULETTE_SILVER:
  7733. sd->roulette_point.silver = val;
  7734. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  7735. return true;
  7736. case SP_ROULETTE_GOLD:
  7737. sd->roulette_point.gold = val;
  7738. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  7739. return true;
  7740. case SP_CASHPOINTS:
  7741. if (val < 0)
  7742. return false;
  7743. if (!sd->state.connect_new)
  7744. log_cash(sd, LOG_TYPE_SCRIPT, LOG_CASH_TYPE_CASH, -(sd->cashPoints - cap_value(val, 0, MAX_ZENY)));
  7745. sd->cashPoints = cap_value(val, 0, MAX_ZENY);
  7746. pc_setaccountreg(sd, add_str(CASHPOINT_VAR), sd->cashPoints);
  7747. return true;
  7748. case SP_KAFRAPOINTS:
  7749. if (val < 0)
  7750. return false;
  7751. if (!sd->state.connect_new)
  7752. log_cash(sd, LOG_TYPE_SCRIPT, LOG_CASH_TYPE_KAFRA, -(sd->kafraPoints - cap_value(val, 0, MAX_ZENY)));
  7753. sd->kafraPoints = cap_value(val, 0, MAX_ZENY);
  7754. pc_setaccountreg(sd, add_str(KAFRAPOINT_VAR), sd->kafraPoints);
  7755. return true;
  7756. case SP_PCDIECOUNTER:
  7757. if (val < 0)
  7758. return false;
  7759. if (sd->die_counter == val)
  7760. return true;
  7761. sd->die_counter = val;
  7762. if (!sd->die_counter && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE)
  7763. status_calc_pc(sd, SCO_NONE); // Lost the bonus.
  7764. pc_setglobalreg(sd, add_str(PCDIECOUNTER_VAR), sd->die_counter);
  7765. return true;
  7766. case SP_COOKMASTERY:
  7767. if (val < 0)
  7768. return false;
  7769. if (sd->cook_mastery == val)
  7770. return true;
  7771. val = cap_value(val, 0, 1999);
  7772. sd->cook_mastery = val;
  7773. pc_setglobalreg(sd, add_str(COOKMASTERY_VAR), sd->cook_mastery);
  7774. return true;
  7775. default:
  7776. ShowError("pc_setparam: Attempted to set unknown parameter '%lld'.\n", type);
  7777. return false;
  7778. }
  7779. clif_updatestatus(sd,static_cast<int>(type));
  7780. return true;
  7781. }
  7782. /*==========================================
  7783. * HP/SP Healing. If flag is passed, the heal type is through clif_heal, otherwise update status.
  7784. *------------------------------------------*/
  7785. void pc_heal(struct map_session_data *sd,unsigned int hp,unsigned int sp, int type)
  7786. {
  7787. if (type&2) {
  7788. if (hp || type&4)
  7789. clif_heal(sd->fd,SP_HP,hp);
  7790. if (sp)
  7791. clif_heal(sd->fd,SP_SP,sp);
  7792. } else {
  7793. if(hp)
  7794. clif_updatestatus(sd,SP_HP);
  7795. if(sp)
  7796. clif_updatestatus(sd,SP_SP);
  7797. }
  7798. return;
  7799. }
  7800. /**
  7801. * Heal player HP and/or SP linearly. Calculate any bonus based on active statuses.
  7802. * @param sd: Player data
  7803. * @param itemid: Item ID
  7804. * @param hp: HP to heal
  7805. * @param sp: SP to heal
  7806. * @return Amount healed to an object
  7807. */
  7808. int pc_itemheal(struct map_session_data *sd, int itemid, int hp, int sp)
  7809. {
  7810. int bonus, tmp, penalty = 0;
  7811. if (hp) {
  7812. bonus = 100 + (sd->battle_status.vit << 1) + pc_checkskill(sd, SM_RECOVERY) * 10 + pc_checkskill(sd, AM_LEARNINGPOTION) * 5;
  7813. // A potion produced by an Alchemist in the Fame Top 10 gets +50% effect [DracoRPG]
  7814. if (potion_flag == 2) {
  7815. bonus += bonus * 50 / 100;
  7816. if (sd->sc.data[SC_SPIRIT] && sd->sc.data[SC_SPIRIT]->val2 == SL_ROGUE)
  7817. bonus += bonus; // Receive an additional +100% effect from ranked potions to HP only
  7818. }
  7819. //All item bonuses.
  7820. bonus += sd->bonus.itemhealrate2;
  7821. //Item Group bonuses
  7822. bonus += bonus * pc_get_itemgroup_bonus(sd, itemid) / 100;
  7823. //Individual item bonuses.
  7824. for(const auto &it : sd->itemhealrate) {
  7825. if (it.id == itemid) {
  7826. bonus += bonus * it.val / 100;
  7827. break;
  7828. }
  7829. }
  7830. // Recovery Potion
  7831. if (sd->sc.data[SC_INCHEALRATE])
  7832. bonus += bonus * sd->sc.data[SC_INCHEALRATE]->val1 / 100;
  7833. // 2014 Halloween Event : Pumpkin Bonus
  7834. if (sd->sc.data[SC_MTF_PUMPKIN] && itemid == ITEMID_PUMPKIN)
  7835. bonus += bonus * sd->sc.data[SC_MTF_PUMPKIN]->val1 / 100;
  7836. tmp = hp * bonus / 100; // Overflow check
  7837. if (bonus != 100 && tmp > hp)
  7838. hp = tmp;
  7839. }
  7840. if (sp) {
  7841. bonus = 100 + (sd->battle_status.int_ << 1) + pc_checkskill(sd, MG_SRECOVERY) * 10 + pc_checkskill(sd, AM_LEARNINGPOTION) * 5;
  7842. // A potion produced by an Alchemist in the Fame Top 10 gets +50% effect [DracoRPG]
  7843. if (potion_flag == 2)
  7844. bonus += bonus * 50 / 100;
  7845. tmp = sp * bonus / 100; // Overflow check
  7846. if (bonus != 100 && tmp > sp)
  7847. sp = tmp;
  7848. }
  7849. if (sd->sc.count) {
  7850. // Critical Wound and Death Hurt stack
  7851. if (sd->sc.data[SC_CRITICALWOUND])
  7852. penalty += sd->sc.data[SC_CRITICALWOUND]->val2;
  7853. if (sd->sc.data[SC_DEATHHURT] && sd->sc.data[SC_DEATHHURT]->val3 == 1)
  7854. penalty += 20;
  7855. if (sd->sc.data[SC_NORECOVER_STATE])
  7856. penalty = 100;
  7857. if (sd->sc.data[SC_VITALITYACTIVATION]) {
  7858. hp += hp / 2; // 1.5 times
  7859. sp -= sp / 2;
  7860. }
  7861. if (sd->sc.data[SC_WATER_INSIGNIA] && sd->sc.data[SC_WATER_INSIGNIA]->val1 == 2) {
  7862. hp += hp / 10;
  7863. sp += sp / 10;
  7864. }
  7865. #ifdef RENEWAL
  7866. if (sd->sc.data[SC_APPLEIDUN])
  7867. hp += sd->sc.data[SC_APPLEIDUN]->val3 / 100;
  7868. #endif
  7869. if (penalty > 0) {
  7870. hp -= hp * penalty / 100;
  7871. sp -= sp * penalty / 100;
  7872. }
  7873. #ifdef RENEWAL
  7874. if (sd->sc.data[SC_EXTREMITYFIST2])
  7875. sp = 0;
  7876. #endif
  7877. if (sd->sc.data[SC_BITESCAR])
  7878. hp = 0;
  7879. }
  7880. return status_heal(&sd->bl, hp, sp, 1);
  7881. }
  7882. /*==========================================
  7883. * HP/SP Recovery
  7884. * Heal player hp nad/or sp by rate
  7885. *------------------------------------------*/
  7886. int pc_percentheal(struct map_session_data *sd,int hp,int sp)
  7887. {
  7888. nullpo_ret(sd);
  7889. if (hp > 100) hp = 100;
  7890. else if (hp <-100) hp = -100;
  7891. if (sp > 100) sp = 100;
  7892. else if (sp <-100) sp = -100;
  7893. if(hp >= 0 && sp >= 0) //Heal
  7894. return status_percent_heal(&sd->bl, hp, sp);
  7895. if(hp <= 0 && sp <= 0) //Damage (negative rates indicate % of max rather than current), and only kill target IF the specified amount is 100%
  7896. return status_percent_damage(NULL, &sd->bl, hp, sp, hp==-100);
  7897. //Crossed signs
  7898. if(hp) {
  7899. if(hp > 0)
  7900. status_percent_heal(&sd->bl, hp, 0);
  7901. else
  7902. status_percent_damage(NULL, &sd->bl, hp, 0, hp==-100);
  7903. }
  7904. if(sp) {
  7905. if(sp > 0)
  7906. status_percent_heal(&sd->bl, 0, sp);
  7907. else
  7908. status_percent_damage(NULL, &sd->bl, 0, sp, false);
  7909. }
  7910. return 0;
  7911. }
  7912. static int jobchange_killclone(struct block_list *bl, va_list ap)
  7913. {
  7914. struct mob_data *md;
  7915. int flag;
  7916. md = (struct mob_data *)bl;
  7917. nullpo_ret(md);
  7918. flag = va_arg(ap, int);
  7919. if (md->master_id && md->special_state.clone && md->master_id == flag)
  7920. status_kill(&md->bl);
  7921. return 1;
  7922. }
  7923. /**
  7924. * Called when player changes job
  7925. * Rewrote to make it tidider [Celest]
  7926. * @param sd
  7927. * @param job JOB ID. See enum e_job
  7928. * @param upper 1 - JOBL_UPPER; 2 - JOBL_BABY
  7929. * @return True if success, false if failed
  7930. **/
  7931. bool pc_jobchange(struct map_session_data *sd,int job, char upper)
  7932. {
  7933. int i, fame_flag = 0;
  7934. int b_class;
  7935. nullpo_retr(false,sd);
  7936. if (job < 0)
  7937. return false;
  7938. //Normalize job.
  7939. b_class = pc_jobid2mapid(job);
  7940. if (b_class == -1)
  7941. return false;
  7942. switch (upper) {
  7943. case 1:
  7944. b_class|= JOBL_UPPER;
  7945. break;
  7946. case 2:
  7947. b_class|= JOBL_BABY;
  7948. break;
  7949. }
  7950. //This will automatically adjust bard/dancer classes to the correct gender
  7951. //That is, if you try to jobchange into dancer, it will turn you to bard.
  7952. job = pc_mapid2jobid(b_class, sd->status.sex);
  7953. if (job == -1)
  7954. return false;
  7955. if ((unsigned short)b_class == sd->class_)
  7956. return false; //Nothing to change.
  7957. // changing from 1st to 2nd job
  7958. if ((b_class&JOBL_2) && !(sd->class_&JOBL_2) && (sd->class_&MAPID_UPPERMASK) != MAPID_SUPER_NOVICE) {
  7959. sd->change_level_2nd = sd->status.job_level;
  7960. pc_setglobalreg(sd, add_str(JOBCHANGE2ND_VAR), sd->change_level_2nd);
  7961. }
  7962. // changing from 2nd to 3rd job
  7963. else if((b_class&JOBL_THIRD) && !(sd->class_&JOBL_THIRD)) {
  7964. sd->change_level_3rd = sd->status.job_level;
  7965. pc_setglobalreg(sd, add_str(JOBCHANGE3RD_VAR), sd->change_level_3rd);
  7966. }
  7967. if(sd->cloneskill_idx > 0) {
  7968. if( sd->status.skill[sd->cloneskill_idx].flag == SKILL_FLAG_PLAGIARIZED ) {
  7969. sd->status.skill[sd->cloneskill_idx].id = 0;
  7970. sd->status.skill[sd->cloneskill_idx].lv = 0;
  7971. sd->status.skill[sd->cloneskill_idx].flag = SKILL_FLAG_PERMANENT;
  7972. clif_deleteskill(sd, static_cast<int>(pc_readglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM))));
  7973. }
  7974. sd->cloneskill_idx = 0;
  7975. pc_setglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM), 0);
  7976. pc_setglobalreg(sd, add_str(SKILL_VAR_PLAGIARISM_LV), 0);
  7977. }
  7978. if(sd->reproduceskill_idx > 0) {
  7979. if( sd->status.skill[sd->reproduceskill_idx].flag == SKILL_FLAG_PLAGIARIZED ) {
  7980. sd->status.skill[sd->reproduceskill_idx].id = 0;
  7981. sd->status.skill[sd->reproduceskill_idx].lv = 0;
  7982. sd->status.skill[sd->reproduceskill_idx].flag = SKILL_FLAG_PERMANENT;
  7983. clif_deleteskill(sd, static_cast<int>(pc_readglobalreg(sd, add_str(SKILL_VAR_REPRODUCE))));
  7984. }
  7985. sd->reproduceskill_idx = 0;
  7986. pc_setglobalreg(sd, add_str(SKILL_VAR_REPRODUCE), 0);
  7987. pc_setglobalreg(sd, add_str(SKILL_VAR_REPRODUCE_LV), 0);
  7988. }
  7989. // Give or reduce transcendent status points
  7990. if( (b_class&JOBL_UPPER) && !(sd->class_&JOBL_UPPER) ){ // Change from a non t class to a t class -> give points
  7991. sd->status.status_point += battle_config.transcendent_status_points;
  7992. clif_updatestatus(sd,SP_STATUSPOINT);
  7993. }else if( !(b_class&JOBL_UPPER) && (sd->class_&JOBL_UPPER) ){ // Change from a t class to a non t class -> remove points
  7994. if( sd->status.status_point < battle_config.transcendent_status_points ){
  7995. // The player already used his bonus points, so we have to reset his status points
  7996. pc_resetstate(sd);
  7997. }
  7998. sd->status.status_point -= battle_config.transcendent_status_points;
  7999. clif_updatestatus(sd,SP_STATUSPOINT);
  8000. }
  8001. if ( (b_class&MAPID_UPPERMASK) != (sd->class_&MAPID_UPPERMASK) ) { //Things to remove when changing class tree.
  8002. const int class_ = pc_class2idx(sd->status.class_);
  8003. uint16 skill_id;
  8004. for(i = 0; i < MAX_SKILL_TREE && (skill_id = skill_tree[class_][i].skill_id) > 0; i++) {
  8005. //Remove status specific to your current tree skills.
  8006. enum sc_type sc = status_skill2sc(skill_id);
  8007. if (sc > SC_COMMON_MAX && sd->sc.data[sc])
  8008. status_change_end(&sd->bl, sc, INVALID_TIMER);
  8009. }
  8010. }
  8011. if( (sd->class_&MAPID_UPPERMASK) == MAPID_STAR_GLADIATOR && (b_class&MAPID_UPPERMASK) != MAPID_STAR_GLADIATOR) {
  8012. /* going off star glad lineage, reset feel to not store no-longer-used vars in the database */
  8013. pc_resetfeel(sd);
  8014. }
  8015. // Reset body style to 0 before changing job to avoid
  8016. // errors since not every job has a alternate outfit.
  8017. sd->status.body = 0;
  8018. clif_changelook(&sd->bl,LOOK_BODY2,0);
  8019. sd->status.class_ = job;
  8020. fame_flag = pc_famerank(sd->status.char_id,sd->class_&MAPID_UPPERMASK);
  8021. sd->class_ = (unsigned short)b_class;
  8022. sd->status.job_level=1;
  8023. sd->status.job_exp=0;
  8024. if (sd->status.base_level > pc_maxbaselv(sd)) {
  8025. sd->status.base_level = pc_maxbaselv(sd);
  8026. sd->status.base_exp=0;
  8027. pc_resetstate(sd);
  8028. clif_updatestatus(sd,SP_STATUSPOINT);
  8029. clif_updatestatus(sd,SP_BASELEVEL);
  8030. clif_updatestatus(sd,SP_BASEEXP);
  8031. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8032. }
  8033. clif_updatestatus(sd,SP_JOBLEVEL);
  8034. clif_updatestatus(sd,SP_JOBEXP);
  8035. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8036. for(i=0;i<EQI_MAX;i++) {
  8037. if(sd->equip_index[i] >= 0)
  8038. if(pc_isequip(sd,sd->equip_index[i]))
  8039. pc_unequipitem(sd,sd->equip_index[i],2); // unequip invalid item for class
  8040. }
  8041. //Change look, if disguised, you need to undisguise
  8042. //to correctly calculate new job sprite without
  8043. if (sd->disguise)
  8044. pc_disguise(sd, 0);
  8045. status_set_viewdata(&sd->bl, job);
  8046. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_); // move sprite update to prevent client crashes with incompatible equipment [Valaris]
  8047. #if PACKETVER >= 20151001
  8048. clif_changelook(&sd->bl, LOOK_HAIR, sd->vd.hair_style); // Update player's head (only matters when switching to or from Doram)
  8049. #endif
  8050. if(sd->vd.cloth_color)
  8051. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  8052. /*
  8053. if(sd->vd.body_style)
  8054. clif_changelook(&sd->bl,LOOK_BODY2,sd->vd.body_style);
  8055. */
  8056. //Update skill tree.
  8057. pc_calc_skilltree(sd);
  8058. clif_skillinfoblock(sd);
  8059. if (sd->ed)
  8060. elemental_delete(sd->ed);
  8061. if (sd->state.vending)
  8062. vending_closevending(sd);
  8063. if (sd->state.buyingstore)
  8064. buyingstore_close(sd);
  8065. map_foreachinmap(jobchange_killclone, sd->bl.m, BL_MOB, sd->bl.id);
  8066. //Remove peco/cart/falcon
  8067. i = sd->sc.option;
  8068. if( i&OPTION_RIDING && !pc_checkskill(sd, KN_RIDING) )
  8069. i&=~OPTION_RIDING;
  8070. if( i&OPTION_FALCON && !pc_checkskill(sd, HT_FALCON) )
  8071. i&=~OPTION_FALCON;
  8072. if( i&OPTION_DRAGON && !pc_checkskill(sd,RK_DRAGONTRAINING) )
  8073. i&=~OPTION_DRAGON;
  8074. if( i&OPTION_WUGRIDER && !pc_checkskill(sd,RA_WUGMASTERY) )
  8075. i&=~OPTION_WUGRIDER;
  8076. if( i&OPTION_WUG && !pc_checkskill(sd,RA_WUGMASTERY) )
  8077. i&=~OPTION_WUG;
  8078. if( i&OPTION_MADOGEAR ) //You do not need a skill for this.
  8079. i&=~OPTION_MADOGEAR;
  8080. #ifndef NEW_CARTS
  8081. if( i&OPTION_CART && !pc_checkskill(sd, MC_PUSHCART) )
  8082. i&=~OPTION_CART;
  8083. #else
  8084. if( sd->sc.data[SC_PUSH_CART] && !pc_checkskill(sd, MC_PUSHCART) )
  8085. pc_setcart(sd, 0);
  8086. #endif
  8087. if(i != sd->sc.option)
  8088. pc_setoption(sd, i);
  8089. if(hom_is_active(sd->hd) && !pc_checkskill(sd, AM_CALLHOMUN))
  8090. hom_vaporize(sd, HOM_ST_ACTIVE);
  8091. if (sd->sc.data[SC_SPRITEMABLE] && !pc_checkskill(sd, SU_SPRITEMABLE))
  8092. status_change_end(&sd->bl, SC_SPRITEMABLE, INVALID_TIMER);
  8093. if(sd->status.manner < 0)
  8094. clif_changestatus(sd,SP_MANNER,sd->status.manner);
  8095. status_calc_pc(sd,SCO_FORCE);
  8096. pc_checkallowskill(sd);
  8097. pc_equiplookall(sd);
  8098. pc_show_questinfo(sd);
  8099. achievement_update_objective(sd, AG_JOB_CHANGE, 2, sd->status.base_level, job);
  8100. if( sd->status.party_id ){
  8101. struct party_data* p;
  8102. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  8103. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  8104. if( i < MAX_PARTY ){
  8105. p->party.member[i].class_ = sd->status.class_;
  8106. clif_party_job_and_level(sd);
  8107. }
  8108. }
  8109. }
  8110. chrif_save(sd, CSAVE_NORMAL);
  8111. //if you were previously famous, not anymore.
  8112. if (fame_flag)
  8113. chrif_buildfamelist();
  8114. else if (sd->status.fame > 0) {
  8115. //It may be that now they are famous?
  8116. switch (sd->class_&MAPID_UPPERMASK) {
  8117. case MAPID_BLACKSMITH:
  8118. case MAPID_ALCHEMIST:
  8119. case MAPID_TAEKWON:
  8120. chrif_buildfamelist();
  8121. break;
  8122. }
  8123. }
  8124. return true;
  8125. }
  8126. /*==========================================
  8127. * Tell client player sd has change equipement
  8128. *------------------------------------------*/
  8129. void pc_equiplookall(struct map_session_data *sd)
  8130. {
  8131. nullpo_retv(sd);
  8132. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8133. clif_changelook(&sd->bl,LOOK_SHOES,0);
  8134. clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
  8135. clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
  8136. clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
  8137. clif_changelook(&sd->bl,LOOK_ROBE, sd->status.robe);
  8138. }
  8139. /*==========================================
  8140. * Tell client player sd has change look (hair,equip...)
  8141. *------------------------------------------*/
  8142. void pc_changelook(struct map_session_data *sd,int type,int val) {
  8143. nullpo_retv(sd);
  8144. switch(type) {
  8145. case LOOK_HAIR: //Use the battle_config limits! [Skotlex]
  8146. val = cap_value(val, MIN_HAIR_STYLE, MAX_HAIR_STYLE);
  8147. if (sd->status.hair != val) {
  8148. sd->status.hair = val;
  8149. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  8150. intif_guild_change_memberinfo(sd->status.guild_id, sd->status.account_id, sd->status.char_id,
  8151. GMI_HAIR, &sd->status.hair, sizeof(sd->status.hair));
  8152. }
  8153. break;
  8154. case LOOK_WEAPON:
  8155. sd->status.weapon = val;
  8156. break;
  8157. case LOOK_HEAD_BOTTOM:
  8158. sd->status.head_bottom = val;
  8159. sd->setlook_head_bottom = val;
  8160. break;
  8161. case LOOK_HEAD_TOP:
  8162. sd->status.head_top = val;
  8163. sd->setlook_head_top = val;
  8164. break;
  8165. case LOOK_HEAD_MID:
  8166. sd->status.head_mid = val;
  8167. sd->setlook_head_mid = val;
  8168. break;
  8169. case LOOK_HAIR_COLOR: //Use the battle_config limits! [Skotlex]
  8170. val = cap_value(val, MIN_HAIR_COLOR, MAX_HAIR_COLOR);
  8171. if (sd->status.hair_color != val) {
  8172. sd->status.hair_color = val;
  8173. if (sd->status.guild_id) //Update Guild Window. [Skotlex]
  8174. intif_guild_change_memberinfo(sd->status.guild_id, sd->status.account_id, sd->status.char_id,
  8175. GMI_HAIR_COLOR, &sd->status.hair_color, sizeof(sd->status.hair_color));
  8176. }
  8177. break;
  8178. case LOOK_CLOTHES_COLOR: //Use the battle_config limits! [Skotlex]
  8179. val = cap_value(val, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  8180. sd->status.clothes_color = val;
  8181. break;
  8182. case LOOK_SHIELD:
  8183. sd->status.shield = val;
  8184. break;
  8185. case LOOK_SHOES:
  8186. break;
  8187. case LOOK_ROBE:
  8188. sd->status.robe = val;
  8189. sd->setlook_robe = val;
  8190. break;
  8191. case LOOK_BODY2:
  8192. val = cap_value(val, MIN_BODY_STYLE, MAX_BODY_STYLE);
  8193. sd->status.body = val;
  8194. break;
  8195. }
  8196. clif_changelook(&sd->bl, type, val);
  8197. }
  8198. /*==========================================
  8199. * Give an option (type) to player (sd) and display it to client
  8200. *------------------------------------------*/
  8201. void pc_setoption(struct map_session_data *sd,int type)
  8202. {
  8203. int p_type, new_look=0;
  8204. nullpo_retv(sd);
  8205. p_type = sd->sc.option;
  8206. //Option has to be changed client-side before the class sprite or it won't always work (eg: Wedding sprite) [Skotlex]
  8207. sd->sc.option=type;
  8208. clif_changeoption(&sd->bl);
  8209. if( (type&OPTION_RIDING && !(p_type&OPTION_RIDING)) || (type&OPTION_DRAGON && !(p_type&OPTION_DRAGON) && pc_checkskill(sd,RK_DRAGONTRAINING) > 0) )
  8210. { // Mounting
  8211. clif_status_load(&sd->bl,EFST_RIDING,1);
  8212. status_calc_pc(sd,SCO_NONE);
  8213. }
  8214. else if( (!(type&OPTION_RIDING) && p_type&OPTION_RIDING) || (!(type&OPTION_DRAGON) && p_type&OPTION_DRAGON && pc_checkskill(sd,RK_DRAGONTRAINING) > 0) )
  8215. { // Dismount
  8216. clif_status_load(&sd->bl,EFST_RIDING,0);
  8217. status_calc_pc(sd,SCO_NONE);
  8218. }
  8219. #ifndef NEW_CARTS
  8220. if( type&OPTION_CART && !( p_type&OPTION_CART ) ) { //Cart On
  8221. clif_cartlist(sd);
  8222. clif_updatestatus(sd, SP_CARTINFO);
  8223. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  8224. status_calc_pc(sd,SCO_NONE); //Apply speed penalty.
  8225. } else if( !( type&OPTION_CART ) && p_type&OPTION_CART ){ //Cart Off
  8226. clif_clearcart(sd->fd);
  8227. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  8228. status_calc_pc(sd,SCO_NONE); //Remove speed penalty.
  8229. }
  8230. #endif
  8231. if (type&OPTION_FALCON && !(p_type&OPTION_FALCON)) //Falcon ON
  8232. clif_status_load(&sd->bl,EFST_FALCON,1);
  8233. else if (!(type&OPTION_FALCON) && p_type&OPTION_FALCON) //Falcon OFF
  8234. clif_status_load(&sd->bl,EFST_FALCON,0);
  8235. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER ) {
  8236. if( type&OPTION_WUGRIDER && !(p_type&OPTION_WUGRIDER) ) { // Mounting
  8237. clif_status_load(&sd->bl,EFST_WUGRIDER,1);
  8238. status_calc_pc(sd,SCO_NONE);
  8239. } else if( !(type&OPTION_WUGRIDER) && p_type&OPTION_WUGRIDER ) { // Dismount
  8240. clif_status_load(&sd->bl,EFST_WUGRIDER,0);
  8241. status_calc_pc(sd,SCO_NONE);
  8242. }
  8243. }
  8244. if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  8245. if( type&OPTION_MADOGEAR && !(p_type&OPTION_MADOGEAR) ) {
  8246. static const sc_type statuses [] = { SC_MAXIMIZEPOWER, SC_OVERTHRUST, SC_WEAPONPERFECTION, SC_ADRENALINE, SC_CARTBOOST, SC_MELTDOWN, SC_MAXOVERTHRUST };
  8247. status_calc_pc(sd,SCO_NONE);
  8248. for (uint8 i = 0; i < ARRAYLENGTH(statuses); i++) {
  8249. int skill_id = status_sc2skill(statuses[i]);
  8250. if (skill_id > 0 && !skill_get_inf2(skill_id, INF2_ALLOWONMADO))
  8251. status_change_end(&sd->bl,statuses[i],INVALID_TIMER);
  8252. }
  8253. pc_bonus_script_clear(sd,BSF_REM_ON_MADOGEAR);
  8254. } else if( !(type&OPTION_MADOGEAR) && p_type&OPTION_MADOGEAR ) {
  8255. status_calc_pc(sd,SCO_NONE);
  8256. status_change_end(&sd->bl,SC_SHAPESHIFT,INVALID_TIMER);
  8257. status_change_end(&sd->bl,SC_HOVERING,INVALID_TIMER);
  8258. status_change_end(&sd->bl,SC_ACCELERATION,INVALID_TIMER);
  8259. status_change_end(&sd->bl,SC_OVERHEAT_LIMITPOINT,INVALID_TIMER);
  8260. status_change_end(&sd->bl,SC_OVERHEAT,INVALID_TIMER);
  8261. status_change_end(&sd->bl,SC_MAGNETICFIELD,INVALID_TIMER);
  8262. status_change_end(&sd->bl,SC_NEUTRALBARRIER_MASTER,INVALID_TIMER);
  8263. status_change_end(&sd->bl,SC_STEALTHFIELD_MASTER,INVALID_TIMER);
  8264. pc_bonus_script_clear(sd,BSF_REM_ON_MADOGEAR);
  8265. }
  8266. }
  8267. if (type&OPTION_FLYING && !(p_type&OPTION_FLYING))
  8268. new_look = JOB_STAR_GLADIATOR2;
  8269. else if (!(type&OPTION_FLYING) && p_type&OPTION_FLYING)
  8270. new_look = -1;
  8271. if (sd->disguise || !new_look)
  8272. return; //Disguises break sprite changes
  8273. if (new_look < 0) { //Restore normal look.
  8274. status_set_viewdata(&sd->bl, sd->status.class_);
  8275. new_look = sd->vd.class_;
  8276. }
  8277. pc_stop_attack(sd); //Stop attacking on new view change (to prevent wedding/santa attacks.
  8278. clif_changelook(&sd->bl,LOOK_BASE,new_look);
  8279. if (sd->vd.cloth_color)
  8280. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  8281. if( sd->vd.body_style )
  8282. clif_changelook(&sd->bl,LOOK_BODY2,sd->vd.body_style);
  8283. clif_skillinfoblock(sd); // Skill list needs to be updated after base change.
  8284. }
  8285. /**
  8286. * Give player a cart
  8287. * @param sd Player
  8288. * @param type 0:Remove cart, 1 ~ MAX_CARTS: Cart type
  8289. **/
  8290. bool pc_setcart(struct map_session_data *sd,int type) {
  8291. #ifndef NEW_CARTS
  8292. int cart[6] = {0x0000,OPTION_CART1,OPTION_CART2,OPTION_CART3,OPTION_CART4,OPTION_CART5};
  8293. int option;
  8294. #endif
  8295. nullpo_retr(false,sd);
  8296. if( type < 0 || type > MAX_CARTS )
  8297. return false;// Never trust the values sent by the client! [Skotlex]
  8298. if( pc_checkskill(sd,MC_PUSHCART) <= 0 && type != 0 )
  8299. return false;// Push cart is required
  8300. #ifdef NEW_CARTS
  8301. switch( type ) {
  8302. case 0:
  8303. if( !sd->sc.data[SC_PUSH_CART] )
  8304. return 0;
  8305. status_change_end(&sd->bl,SC_PUSH_CART,INVALID_TIMER);
  8306. clif_clearcart(sd->fd);
  8307. break;
  8308. default:/* everything else is an allowed ID so we can move on */
  8309. if( !sd->sc.data[SC_PUSH_CART] ) { /* first time, so fill cart data */
  8310. clif_cartlist(sd);
  8311. status_calc_cart_weight(sd, (e_status_calc_weight_opt)(CALCWT_ITEM|CALCWT_MAXBONUS|CALCWT_CARTSTATE));
  8312. }
  8313. clif_updatestatus(sd, SP_CARTINFO);
  8314. sc_start(&sd->bl, &sd->bl, SC_PUSH_CART, 100, type, 0);
  8315. break;
  8316. }
  8317. if(pc_checkskill(sd, MC_PUSHCART) < 10)
  8318. status_calc_pc(sd,SCO_NONE); //Recalc speed penalty.
  8319. #else
  8320. // Update option
  8321. option = sd->sc.option;
  8322. option &= ~OPTION_CART;// clear cart bits
  8323. option |= cart[type]; // set cart
  8324. pc_setoption(sd, option);
  8325. #endif
  8326. return true;
  8327. }
  8328. /*==========================================
  8329. * Give player a falcon
  8330. *------------------------------------------*/
  8331. void pc_setfalcon(struct map_session_data* sd, int flag)
  8332. {
  8333. if( flag ){
  8334. if( pc_checkskill(sd,HT_FALCON)>0 ) // add falcon if he have the skill
  8335. pc_setoption(sd,sd->sc.option|OPTION_FALCON);
  8336. } else if( pc_isfalcon(sd) ){
  8337. pc_setoption(sd,sd->sc.option&~OPTION_FALCON); // remove falcon
  8338. }
  8339. }
  8340. /*==========================================
  8341. * Set player riding
  8342. *------------------------------------------*/
  8343. void pc_setriding(struct map_session_data* sd, int flag)
  8344. {
  8345. if( sd->sc.data[SC_ALL_RIDING] )
  8346. return;
  8347. if( flag ){
  8348. if( pc_checkskill(sd,KN_RIDING) > 0 ) // add peco
  8349. pc_setoption(sd, sd->sc.option|OPTION_RIDING);
  8350. } else if( pc_isriding(sd) ){
  8351. pc_setoption(sd, sd->sc.option&~OPTION_RIDING);
  8352. }
  8353. }
  8354. /*==========================================
  8355. * Give player a mado
  8356. *------------------------------------------*/
  8357. void pc_setmadogear(struct map_session_data* sd, int flag)
  8358. {
  8359. if( flag ){
  8360. if( pc_checkskill(sd,NC_MADOLICENCE) > 0 )
  8361. pc_setoption(sd, sd->sc.option|OPTION_MADOGEAR);
  8362. } else if( pc_ismadogear(sd) ){
  8363. pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR);
  8364. }
  8365. }
  8366. /*==========================================
  8367. * Check if player can drop an item
  8368. *------------------------------------------*/
  8369. bool pc_candrop(struct map_session_data *sd, struct item *item)
  8370. {
  8371. if( item && ((item->expire_time || (item->bound && !pc_can_give_bounded_items(sd))) || (itemdb_ishatched_egg(item))) )
  8372. return false;
  8373. if( !pc_can_give_items(sd) || sd->sc.cant.drop) //check if this GM level can drop items
  8374. return false;
  8375. return (itemdb_isdropable(item, pc_get_group_level(sd)));
  8376. }
  8377. /**
  8378. * Determines whether a player can attack based on status changes
  8379. * Why not use status_check_skilluse?
  8380. * "src MAY be null to indicate we shouldn't check it, this is a ground-based skill attack."
  8381. * Even ground-based attacks should be blocked by these statuses
  8382. * Called from unit_attack and unit_attack_timer_sub
  8383. * @retval true Can attack
  8384. **/
  8385. bool pc_can_attack( struct map_session_data *sd, int target_id ) {
  8386. nullpo_retr(false, sd);
  8387. if( pc_is90overweight(sd) || pc_isridingwug(sd) )
  8388. return false;
  8389. if (sd->state.block_action & PCBLOCK_ATTACK)
  8390. return false;
  8391. if(
  8392. #ifdef RENEWAL
  8393. sd->sc.data[SC_BASILICA_CELL] ||
  8394. #else
  8395. sd->sc.data[SC_BASILICA] ||
  8396. #endif
  8397. sd->sc.data[SC__SHADOWFORM] ||
  8398. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8399. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ||
  8400. sd->sc.data[SC_CRYSTALIZE] ||
  8401. sd->sc.data[SC_ALL_RIDING] || // The client doesn't let you, this is to make cheat-safe
  8402. sd->sc.data[SC_TRICKDEAD] ||
  8403. (sd->sc.data[SC_VOICEOFSIREN] && sd->sc.data[SC_VOICEOFSIREN]->val2 == target_id) ||
  8404. sd->sc.data[SC_BLADESTOP] ||
  8405. sd->sc.data[SC_DEEPSLEEP] ||
  8406. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF) ||
  8407. sd->sc.data[SC_KINGS_GRACE] )
  8408. return false;
  8409. return true;
  8410. }
  8411. /*==========================================
  8412. * Read '@type' variables (temporary numeric char reg)
  8413. *------------------------------------------*/
  8414. int64 pc_readreg(struct map_session_data* sd, int64 reg)
  8415. {
  8416. return i64db_i64get(sd->regs.vars, reg);
  8417. }
  8418. /*==========================================
  8419. * Set '@type' variables (temporary numeric char reg)
  8420. *------------------------------------------*/
  8421. bool pc_setreg(struct map_session_data* sd, int64 reg, int64 val)
  8422. {
  8423. uint32 index = script_getvaridx(reg);
  8424. nullpo_retr(false, sd);
  8425. if( val ) {
  8426. i64db_i64put(sd->regs.vars, reg, val);
  8427. if( index )
  8428. script_array_update(&sd->regs, reg, false);
  8429. } else {
  8430. i64db_remove(sd->regs.vars, reg);
  8431. if( index )
  8432. script_array_update(&sd->regs, reg, true);
  8433. }
  8434. return true;
  8435. }
  8436. /*==========================================
  8437. * Read '@type$' variables (temporary string char reg)
  8438. *------------------------------------------*/
  8439. char* pc_readregstr(struct map_session_data* sd, int64 reg)
  8440. {
  8441. struct script_reg_str *p = NULL;
  8442. p = (struct script_reg_str *)i64db_get(sd->regs.vars, reg);
  8443. return p ? p->value : NULL;
  8444. }
  8445. /*==========================================
  8446. * Set '@type$' variables (temporary string char reg)
  8447. *------------------------------------------*/
  8448. bool pc_setregstr(struct map_session_data* sd, int64 reg, const char* str)
  8449. {
  8450. struct script_reg_str *p = NULL;
  8451. unsigned int index = script_getvaridx(reg);
  8452. DBData prev;
  8453. nullpo_retr(false, sd);
  8454. if( str[0] ) {
  8455. p = ers_alloc(str_reg_ers, struct script_reg_str);
  8456. p->value = aStrdup(str);
  8457. p->flag.type = 1;
  8458. if (sd->regs.vars->put(sd->regs.vars, db_i642key(reg), db_ptr2data(p), &prev)) {
  8459. p = (struct script_reg_str *)db_data2ptr(&prev);
  8460. if( p->value )
  8461. aFree(p->value);
  8462. ers_free(str_reg_ers, p);
  8463. } else {
  8464. if( index )
  8465. script_array_update(&sd->regs, reg, false);
  8466. }
  8467. } else {
  8468. if (sd->regs.vars->remove(sd->regs.vars, db_i642key(reg), &prev)) {
  8469. p = (struct script_reg_str *)db_data2ptr(&prev);
  8470. if( p->value )
  8471. aFree(p->value);
  8472. ers_free(str_reg_ers, p);
  8473. if( index )
  8474. script_array_update(&sd->regs, reg, true);
  8475. }
  8476. }
  8477. return true;
  8478. }
  8479. /**
  8480. * Serves the following variable types:
  8481. * - 'type' (permanent numeric char reg)
  8482. * - '#type' (permanent numeric account reg)
  8483. * - '##type' (permanent numeric account reg2)
  8484. **/
  8485. int64 pc_readregistry(struct map_session_data *sd, int64 reg)
  8486. {
  8487. struct script_reg_num *p = NULL;
  8488. if (!sd->vars_ok) {
  8489. ShowError("pc_readregistry: Trying to read reg %s before it's been loaded!\n", get_str(script_getvarid(reg)));
  8490. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  8491. //intif->request_registry(sd,type==3?4:type);
  8492. set_eof(sd->fd);
  8493. return 0;
  8494. }
  8495. p = (struct script_reg_num *)i64db_get(sd->regs.vars, reg);
  8496. return p ? p->value : 0;
  8497. }
  8498. /**
  8499. * Serves the following variable types:
  8500. * - 'type$' (permanent str char reg)
  8501. * - '#type$' (permanent str account reg)
  8502. * - '##type$' (permanent str account reg2)
  8503. **/
  8504. char* pc_readregistry_str(struct map_session_data *sd, int64 reg)
  8505. {
  8506. struct script_reg_str *p = NULL;
  8507. if (!sd->vars_ok) {
  8508. ShowError("pc_readregistry_str: Trying to read reg %s before it's been loaded!\n", get_str(script_getvarid(reg)));
  8509. //This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
  8510. //intif->request_registry(sd,type==3?4:type);
  8511. set_eof(sd->fd);
  8512. return NULL;
  8513. }
  8514. p = (struct script_reg_str *)i64db_get(sd->regs.vars, reg);
  8515. return p ? p->value : NULL;
  8516. }
  8517. /**
  8518. * Serves the following variable types:
  8519. * - 'type' (permanent numeric char reg)
  8520. * - '#type' (permanent numeric account reg)
  8521. * - '##type' (permanent numeric account reg2)
  8522. **/
  8523. bool pc_setregistry(struct map_session_data *sd, int64 reg, int64 val)
  8524. {
  8525. struct script_reg_num *p = NULL;
  8526. const char *regname = get_str(script_getvarid(reg));
  8527. uint32 index = script_getvaridx(reg);
  8528. if ( !reg_load && !sd->vars_ok ) {
  8529. ShowError("pc_setregistry : refusing to set %s until vars are received.\n", regname);
  8530. return false;
  8531. }
  8532. if ((p = (struct script_reg_num *)i64db_get(sd->regs.vars, reg))) {
  8533. if( val ) {
  8534. if( !p->value && index ) /* its a entry that was deleted, so we reset array */
  8535. script_array_update(&sd->regs, reg, false);
  8536. p->value = val;
  8537. } else {
  8538. p->value = 0;
  8539. if( index )
  8540. script_array_update(&sd->regs, reg, true);
  8541. }
  8542. if (!reg_load)
  8543. p->flag.update = 1;/* either way, it will require either delete or replace */
  8544. } else if( val ) {
  8545. DBData prev;
  8546. if( index )
  8547. script_array_update(&sd->regs, reg, false);
  8548. p = ers_alloc(num_reg_ers, struct script_reg_num);
  8549. p->value = val;
  8550. if (!reg_load)
  8551. p->flag.update = 1;
  8552. if (sd->regs.vars->put(sd->regs.vars, db_i642key(reg), db_ptr2data(p), &prev)) {
  8553. p = (struct script_reg_num *)db_data2ptr(&prev);
  8554. ers_free(num_reg_ers, p);
  8555. }
  8556. }
  8557. if (!reg_load && p)
  8558. sd->vars_dirty = true;
  8559. return true;
  8560. }
  8561. /**
  8562. * Serves the following variable types:
  8563. * - 'type$' (permanent str char reg)
  8564. * - '#type$' (permanent str account reg)
  8565. * - '##type$' (permanent str account reg2)
  8566. **/
  8567. bool pc_setregistry_str(struct map_session_data *sd, int64 reg, const char *val)
  8568. {
  8569. struct script_reg_str *p = NULL;
  8570. const char *regname = get_str(script_getvarid(reg));
  8571. unsigned int index = script_getvaridx(reg);
  8572. size_t vlen = 0;
  8573. if (!reg_load && !sd->vars_ok) {
  8574. ShowError("pc_setregistry_str : refusing to set %s until vars are received.\n", regname);
  8575. return false;
  8576. }
  8577. if ( !script_check_RegistryVariableLength(1, val, &vlen ) )
  8578. {
  8579. ShowError("pc_check_RegistryVariableLength: Variable value length is too long (aid: %d, cid: %d): '%s' sz=%zu\n", sd->status.account_id, sd->status.char_id, val, vlen);
  8580. return false;
  8581. }
  8582. if( (p = (struct script_reg_str *)i64db_get(sd->regs.vars, reg) ) ) {
  8583. if( val[0] ) {
  8584. if( p->value )
  8585. aFree(p->value);
  8586. else if ( index ) // an entry that was deleted, so we reset
  8587. script_array_update(&sd->regs, reg, false);
  8588. p->value = aStrdup(val);
  8589. } else {
  8590. if (p->value)
  8591. aFree(p->value);
  8592. p->value = NULL;
  8593. if( index )
  8594. script_array_update(&sd->regs, reg, true);
  8595. }
  8596. if( !reg_load )
  8597. p->flag.update = 1; // either way, it will require either delete or replace
  8598. } else if( val[0] ) {
  8599. DBData prev;
  8600. if( index )
  8601. script_array_update(&sd->regs, reg, false);
  8602. p = ers_alloc(str_reg_ers, struct script_reg_str);
  8603. p->value = aStrdup(val);
  8604. if( !reg_load )
  8605. p->flag.update = 1;
  8606. p->flag.type = 1;
  8607. if( sd->regs.vars->put(sd->regs.vars, db_i642key(reg), db_ptr2data(p), &prev) ) {
  8608. p = (struct script_reg_str *)db_data2ptr(&prev);
  8609. if( p->value )
  8610. aFree(p->value);
  8611. ers_free(str_reg_ers, p);
  8612. }
  8613. }
  8614. if( !reg_load && p )
  8615. sd->vars_dirty = true;
  8616. return true;
  8617. }
  8618. /**
  8619. * Set value of player variable
  8620. * @param sd Player
  8621. * @param reg Variable name
  8622. * @param value
  8623. * @return True if success, false if failed.
  8624. **/
  8625. bool pc_setreg2(struct map_session_data *sd, const char *reg, int64 val) {
  8626. char prefix = reg[0];
  8627. nullpo_retr(false, sd);
  8628. if (reg[strlen(reg)-1] == '$') {
  8629. ShowError("pc_setreg2: Invalid variable scope '%s'\n", reg);
  8630. return false;
  8631. }
  8632. val = cap_value(val, INT_MIN, INT_MAX);
  8633. switch (prefix) {
  8634. case '.':
  8635. case '\'':
  8636. case '$':
  8637. ShowError("pc_setreg2: Invalid variable scope '%s'\n", reg);
  8638. return false;
  8639. case '@':
  8640. return pc_setreg(sd, add_str(reg), val);
  8641. case '#':
  8642. return (reg[1] == '#') ? pc_setaccountreg2(sd, add_str(reg), val) : pc_setaccountreg(sd, add_str(reg), val);
  8643. default:
  8644. return pc_setglobalreg(sd, add_str(reg), val);
  8645. }
  8646. return false;
  8647. }
  8648. /**
  8649. * Get value of player variable
  8650. * @param sd Player
  8651. * @param reg Variable name
  8652. * @return Variable value or 0 if failed.
  8653. **/
  8654. int64 pc_readreg2(struct map_session_data *sd, const char *reg) {
  8655. char prefix = reg[0];
  8656. nullpo_ret(sd);
  8657. if (reg[strlen(reg)-1] == '$') {
  8658. ShowError("pc_readreg2: Invalid variable scope '%s'\n", reg);
  8659. return 0;
  8660. }
  8661. switch (prefix) {
  8662. case '.':
  8663. case '\'':
  8664. case '$':
  8665. ShowError("pc_readreg2: Invalid variable scope '%s'\n", reg);
  8666. return 0;
  8667. case '@':
  8668. return pc_readreg(sd, add_str(reg));
  8669. case '#':
  8670. return (reg[1] == '#') ? pc_readaccountreg2(sd, add_str(reg)) : pc_readaccountreg(sd, add_str(reg));
  8671. default:
  8672. return pc_readglobalreg(sd, add_str(reg));
  8673. }
  8674. return 0;
  8675. }
  8676. /*==========================================
  8677. * Exec eventtimer for player sd (retrieved from map_session (id))
  8678. *------------------------------------------*/
  8679. static TIMER_FUNC(pc_eventtimer){
  8680. struct map_session_data *sd=map_id2sd(id);
  8681. char *p = (char *)data;
  8682. int i;
  8683. if(sd==NULL)
  8684. return 0;
  8685. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == tid );
  8686. if( i < MAX_EVENTTIMER )
  8687. {
  8688. sd->eventtimer[i] = INVALID_TIMER;
  8689. sd->eventcount--;
  8690. npc_event(sd,p,0);
  8691. }
  8692. else
  8693. ShowError("pc_eventtimer: no such event timer\n");
  8694. if (p) aFree(p);
  8695. return 0;
  8696. }
  8697. /*==========================================
  8698. * Add eventtimer for player sd ?
  8699. *------------------------------------------*/
  8700. bool pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
  8701. {
  8702. int i;
  8703. nullpo_retr(false,sd);
  8704. ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == INVALID_TIMER );
  8705. if( i == MAX_EVENTTIMER )
  8706. return false;
  8707. sd->eventtimer[i] = add_timer(gettick()+tick, pc_eventtimer, sd->bl.id, (intptr_t)aStrdup(name));
  8708. sd->eventcount++;
  8709. return true;
  8710. }
  8711. /*==========================================
  8712. * Del eventtimer for player sd ?
  8713. *------------------------------------------*/
  8714. bool pc_deleventtimer(struct map_session_data *sd,const char *name)
  8715. {
  8716. char* p = NULL;
  8717. int i;
  8718. nullpo_retr(false,sd);
  8719. if (sd->eventcount == 0)
  8720. return false;
  8721. // find the named event timer
  8722. ARR_FIND( 0, MAX_EVENTTIMER, i,
  8723. sd->eventtimer[i] != INVALID_TIMER &&
  8724. (p = (char *)(get_timer(sd->eventtimer[i])->data)) != NULL &&
  8725. strcmp(p, name) == 0
  8726. );
  8727. if( i == MAX_EVENTTIMER )
  8728. return false; // not found
  8729. delete_timer(sd->eventtimer[i],pc_eventtimer);
  8730. sd->eventtimer[i] = INVALID_TIMER;
  8731. if(sd->eventcount > 0)
  8732. sd->eventcount--;
  8733. aFree(p);
  8734. return true;
  8735. }
  8736. /*==========================================
  8737. * Update eventtimer count for player sd
  8738. *------------------------------------------*/
  8739. void pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick)
  8740. {
  8741. int i;
  8742. nullpo_retv(sd);
  8743. for(i=0;i<MAX_EVENTTIMER;i++)
  8744. if( sd->eventtimer[i] != INVALID_TIMER && strcmp(
  8745. (char *)(get_timer(sd->eventtimer[i])->data), name)==0 ){
  8746. addt_tickimer(sd->eventtimer[i],tick);
  8747. break;
  8748. }
  8749. }
  8750. /*==========================================
  8751. * Remove all eventtimer for player sd
  8752. *------------------------------------------*/
  8753. void pc_cleareventtimer(struct map_session_data *sd)
  8754. {
  8755. int i;
  8756. nullpo_retv(sd);
  8757. if (sd->eventcount == 0)
  8758. return;
  8759. for(i=0;i<MAX_EVENTTIMER;i++){
  8760. if( sd->eventtimer[i] != INVALID_TIMER ){
  8761. char *p = (char *)(get_timer(sd->eventtimer[i])->data);
  8762. delete_timer(sd->eventtimer[i],pc_eventtimer);
  8763. sd->eventtimer[i] = INVALID_TIMER;
  8764. if(sd->eventcount > 0) //avoid looping to max val
  8765. sd->eventcount--;
  8766. if (p) aFree(p);
  8767. }
  8768. }
  8769. }
  8770. /**
  8771. * Called when an item with combo is worn
  8772. * @param *sd
  8773. * @param *data struct item_data
  8774. * @return success numbers of succeed combo
  8775. */
  8776. static int pc_checkcombo(struct map_session_data *sd, struct item_data *data) {
  8777. uint16 i;
  8778. int success = 0;
  8779. for( i = 0; i < data->combos_count; i++ ) {
  8780. struct itemchk {
  8781. int idx;
  8782. unsigned short nameid;
  8783. short card[MAX_SLOTS];
  8784. } *combo_idx;
  8785. int idx, j;
  8786. int nb_itemCombo;
  8787. unsigned int pos = 0;
  8788. /* ensure this isn't a duplicate combo */
  8789. if( sd->combos.bonus != NULL ) {
  8790. int x;
  8791. ARR_FIND( 0, sd->combos.count, x, sd->combos.id[x] == data->combos[i]->id );
  8792. /* found a match, skip this combo */
  8793. if( x < sd->combos.count )
  8794. continue;
  8795. }
  8796. nb_itemCombo = data->combos[i]->count;
  8797. if(nb_itemCombo<2) //a combo with less then 2 item ?? how that possible
  8798. continue;
  8799. CREATE(combo_idx,struct itemchk,nb_itemCombo);
  8800. for(j=0; j < nb_itemCombo; j++){
  8801. combo_idx[j].idx=-1;
  8802. combo_idx[j].nameid=-1;
  8803. memset(combo_idx[j].card,-1,MAX_SLOTS);
  8804. }
  8805. for( j = 0; j < nb_itemCombo; j++ ) {
  8806. uint16 id = data->combos[i]->nameid[j], k;
  8807. bool found = false;
  8808. for( k = 0; k < EQI_MAX; k++ ) {
  8809. short index = sd->equip_index[k];
  8810. if( index < 0 )
  8811. continue;
  8812. if( pc_is_same_equip_index((enum equip_index)k, sd->equip_index, index) )
  8813. continue;
  8814. if (!sd->inventory_data[index] )
  8815. continue;
  8816. if ( itemdb_type(id) != IT_CARD ) {
  8817. if ( sd->inventory_data[index]->nameid != id )
  8818. continue;
  8819. if(j>0){ //check if this item not already used
  8820. bool do_continue = false; //used to continue that specific loop with some check that also use some loop
  8821. uint8 z;
  8822. for (z = 0; z < nb_itemCombo-1; z++)
  8823. if(combo_idx[z].idx == index && combo_idx[z].nameid == id) //we already have that index recorded
  8824. do_continue=true;
  8825. if(do_continue)
  8826. continue;
  8827. }
  8828. combo_idx[j].nameid = id;
  8829. combo_idx[j].idx = index;
  8830. pos |= sd->inventory.u.items_inventory[index].equip;
  8831. found = true;
  8832. break;
  8833. } else { //Cards and enchants
  8834. uint16 z;
  8835. if ( itemdb_isspecial(sd->inventory.u.items_inventory[index].card[0]) )
  8836. continue;
  8837. for (z = 0; z < MAX_SLOTS; z++) {
  8838. bool do_continue=false;
  8839. if (sd->inventory.u.items_inventory[index].card[z] != id)
  8840. continue;
  8841. if(j>0){
  8842. int c1, c2;
  8843. for (c1 = 0; c1 < nb_itemCombo-1; c1++){
  8844. if(combo_idx[c1].idx == index && combo_idx[c1].nameid == id){
  8845. for (c2 = 0; c2 < MAX_SLOTS; c2++){
  8846. if(combo_idx[c1].card[c2] == id){ //we already have that card recorded (at this same idx)
  8847. do_continue = true;
  8848. break;
  8849. }
  8850. }
  8851. }
  8852. }
  8853. }
  8854. if(do_continue)
  8855. continue;
  8856. combo_idx[j].nameid = id;
  8857. combo_idx[j].idx = index;
  8858. combo_idx[j].card[z] = id;
  8859. pos |= sd->inventory.u.items_inventory[index].equip;
  8860. found = true;
  8861. break;
  8862. }
  8863. }
  8864. }
  8865. if( !found )
  8866. break;/* we haven't found all the ids for this combo, so we can return */
  8867. }
  8868. aFree(combo_idx);
  8869. /* means we broke out of the count loop w/o finding all ids, we can move to the next combo */
  8870. if( j < nb_itemCombo )
  8871. continue;
  8872. /* we got here, means all items in the combo are matching */
  8873. idx = sd->combos.count;
  8874. if( sd->combos.bonus == NULL ) {
  8875. CREATE(sd->combos.bonus, struct script_code *, 1);
  8876. CREATE(sd->combos.id, unsigned short, 1);
  8877. CREATE(sd->combos.pos, unsigned int, 1);
  8878. sd->combos.count = 1;
  8879. } else {
  8880. RECREATE(sd->combos.bonus, struct script_code *, ++sd->combos.count);
  8881. RECREATE(sd->combos.id, unsigned short, sd->combos.count);
  8882. RECREATE(sd->combos.pos, unsigned int, sd->combos.count);
  8883. }
  8884. /* we simply copy the pointer */
  8885. sd->combos.bonus[idx] = data->combos[i]->script;
  8886. /* save this combo's id */
  8887. sd->combos.id[idx] = data->combos[i]->id;
  8888. /* save pos of combo*/
  8889. sd->combos.pos[idx] = pos;
  8890. success++;
  8891. }
  8892. return success;
  8893. }
  8894. /**
  8895. * Called when an item with combo is removed
  8896. * @param *sd
  8897. * @param *data struct item_data
  8898. * @return retval numbers of removed combo
  8899. */
  8900. static int pc_removecombo(struct map_session_data *sd, struct item_data *data ) {
  8901. int i, retval = 0;
  8902. if( sd->combos.bonus == NULL )
  8903. return 0;/* nothing to do here, player has no combos */
  8904. for( i = 0; i < data->combos_count; i++ ) {
  8905. /* check if this combo exists in this user */
  8906. int x = 0, cursor = 0, j;
  8907. ARR_FIND( 0, sd->combos.count, x, sd->combos.id[x] == data->combos[i]->id );
  8908. /* no match, skip this combo */
  8909. if(x >= sd->combos.count)
  8910. continue;
  8911. sd->combos.bonus[x] = NULL;
  8912. sd->combos.id[x] = 0;
  8913. sd->combos.pos[x] = 0;
  8914. retval++;
  8915. /* check if combo requirements still fit */
  8916. if( pc_checkcombo( sd, data ) )
  8917. continue;
  8918. /* move next value to empty slot */
  8919. for( j = 0, cursor = 0; j < sd->combos.count; j++ ) {
  8920. if( sd->combos.bonus[j] == NULL )
  8921. continue;
  8922. if( cursor != j ) {
  8923. sd->combos.bonus[cursor] = sd->combos.bonus[j];
  8924. sd->combos.id[cursor] = sd->combos.id[j];
  8925. sd->combos.pos[cursor] = sd->combos.pos[j];
  8926. }
  8927. cursor++;
  8928. }
  8929. /* it's empty, we can clear all the memory */
  8930. if( (sd->combos.count = cursor) == 0 ) {
  8931. aFree(sd->combos.bonus);
  8932. aFree(sd->combos.id);
  8933. aFree(sd->combos.pos);
  8934. sd->combos.bonus = NULL;
  8935. sd->combos.id = NULL;
  8936. sd->combos.pos = NULL;
  8937. return retval; /* we also can return at this point for we have no more combos to check */
  8938. }
  8939. }
  8940. return retval;
  8941. }
  8942. /**
  8943. * Load combo data(s) of player
  8944. * @param *sd
  8945. * @return ret numbers of succeed combo
  8946. */
  8947. int pc_load_combo(struct map_session_data *sd) {
  8948. int i, ret = 0;
  8949. for( i = 0; i < EQI_MAX; i++ ) {
  8950. struct item_data *id = NULL;
  8951. short idx = sd->equip_index[i];
  8952. if( idx < 0 || !(id = sd->inventory_data[idx] ) )
  8953. continue;
  8954. if( id->combos_count )
  8955. ret += pc_checkcombo(sd,id);
  8956. if(!itemdb_isspecial(sd->inventory.u.items_inventory[idx].card[0])) {
  8957. struct item_data *data;
  8958. int j;
  8959. for( j = 0; j < MAX_SLOTS; j++ ) {
  8960. if (!sd->inventory.u.items_inventory[idx].card[j])
  8961. continue;
  8962. if ( ( data = itemdb_exists(sd->inventory.u.items_inventory[idx].card[j]) ) != NULL ) {
  8963. if( data->combos_count )
  8964. ret += pc_checkcombo(sd,data);
  8965. }
  8966. }
  8967. }
  8968. }
  8969. return ret;
  8970. }
  8971. /*==========================================
  8972. * Equip item on player sd at req_pos from inventory index n
  8973. * return: false - fail; true - success
  8974. *------------------------------------------*/
  8975. bool pc_equipitem(struct map_session_data *sd,short n,int req_pos,bool equipswitch)
  8976. {
  8977. int i, pos, flag = 0, iflag;
  8978. struct item_data *id;
  8979. uint8 res = ITEM_EQUIP_ACK_OK;
  8980. short* equip_index;
  8981. nullpo_retr(false,sd);
  8982. if( n < 0 || n >= MAX_INVENTORY ) {
  8983. if( equipswitch ){
  8984. clif_equipswitch_add( sd, n, req_pos, ITEM_EQUIP_ACK_FAIL );
  8985. }else{
  8986. clif_equipitemack(sd,0,0,ITEM_EQUIP_ACK_FAIL);
  8987. }
  8988. return false;
  8989. }
  8990. if( DIFF_TICK(sd->canequip_tick,gettick()) > 0 ) {
  8991. if( equipswitch ){
  8992. clif_equipswitch_add( sd, n, req_pos, ITEM_EQUIP_ACK_FAIL );
  8993. }else{
  8994. clif_equipitemack(sd,n,0,ITEM_EQUIP_ACK_FAIL);
  8995. }
  8996. return false;
  8997. }
  8998. if (!(id = sd->inventory_data[n]))
  8999. return false;
  9000. pos = pc_equippoint(sd,n); //With a few exceptions, item should go in all specified slots.
  9001. if(battle_config.battle_log && !equipswitch)
  9002. ShowInfo("equip %hu (%d) %x:%x\n",sd->inventory.u.items_inventory[n].nameid,n,id?id->equip:0,req_pos);
  9003. if((res = pc_isequip(sd,n))) {
  9004. if( equipswitch ){
  9005. clif_equipswitch_add( sd, n, req_pos, res );
  9006. }else{
  9007. clif_equipitemack(sd,n,0,res); // fail
  9008. }
  9009. return false;
  9010. }
  9011. if( equipswitch && id->type == IT_AMMO ){
  9012. clif_equipswitch_add( sd, n, req_pos, ITEM_EQUIP_ACK_FAIL );
  9013. return false;
  9014. }
  9015. if (!(pos&req_pos) || sd->inventory.u.items_inventory[n].equip != 0 || sd->inventory.u.items_inventory[n].attribute==1 ) { // [Valaris]
  9016. if( equipswitch ){
  9017. clif_equipswitch_add( sd, n, req_pos, ITEM_EQUIP_ACK_FAIL );
  9018. }else{
  9019. clif_equipitemack(sd,n,0,ITEM_EQUIP_ACK_FAIL); // fail
  9020. }
  9021. return false;
  9022. }
  9023. if( sd->sc.count && (sd->sc.data[SC_BERSERK] || sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  9024. sd->sc.data[SC_KYOUGAKU] || (sd->sc.data[SC_PYROCLASTIC] && sd->inventory_data[n]->type == IT_WEAPON)) ) {
  9025. if( equipswitch ){
  9026. clif_equipswitch_add( sd, n, req_pos, ITEM_EQUIP_ACK_FAIL );
  9027. }else{
  9028. clif_equipitemack(sd,n,0,ITEM_EQUIP_ACK_FAIL); //Fail
  9029. }
  9030. return false;
  9031. }
  9032. equip_index = equipswitch ? sd->equip_switch_index : sd->equip_index;
  9033. if ( !equipswitch && id->flag.bindOnEquip && !sd->inventory.u.items_inventory[n].bound) {
  9034. sd->inventory.u.items_inventory[n].bound = (char)battle_config.default_bind_on_equip;
  9035. clif_notify_bindOnEquip(sd,n);
  9036. }
  9037. if(pos == EQP_ACC) { //Accessories should only go in one of the two.
  9038. pos = req_pos&EQP_ACC;
  9039. if (pos == EQP_ACC) //User specified both slots.
  9040. pos = equip_index[EQI_ACC_R] >= 0 ? EQP_ACC_L : EQP_ACC_R;
  9041. for (i = 0; i < sd->inventory_data[n]->slot; i++) { // Accessories that have cards that force equip location
  9042. if (!sd->inventory.u.items_inventory[n].card[i])
  9043. continue;
  9044. struct item_data *card_data = itemdb_exists(sd->inventory.u.items_inventory[n].card[i]);
  9045. if (card_data) {
  9046. int card_pos = card_data->equip;
  9047. if (card_pos == EQP_ACC_L || card_pos == EQP_ACC_R) {
  9048. pos = card_pos; // Use the card's equip position
  9049. break;
  9050. }
  9051. }
  9052. }
  9053. } else if(pos == EQP_ARMS && id->equip == EQP_HAND_R) { //Dual wield capable weapon.
  9054. pos = (req_pos&EQP_ARMS);
  9055. if (pos == EQP_ARMS) //User specified both slots, pick one for them.
  9056. pos = equip_index[EQI_HAND_R] >= 0 ? EQP_HAND_L : EQP_HAND_R;
  9057. } else if(pos == EQP_SHADOW_ACC) { // Shadow System
  9058. pos = req_pos&EQP_SHADOW_ACC;
  9059. if (pos == EQP_SHADOW_ACC)
  9060. pos = equip_index[EQI_SHADOW_ACC_L] >= 0 ? EQP_SHADOW_ACC_R : EQP_SHADOW_ACC_L;
  9061. } else if(pos == EQP_SHADOW_ARMS && id->equip == EQP_SHADOW_WEAPON) {
  9062. pos = (req_pos&EQP_SHADOW_ARMS);
  9063. if( pos == EQP_SHADOW_ARMS )
  9064. pos = (equip_index[EQI_SHADOW_WEAPON] >= 0 ? EQP_SHADOW_SHIELD : EQP_SHADOW_WEAPON);
  9065. }
  9066. if (pos&EQP_HAND_R && battle_config.use_weapon_skill_range&BL_PC) {
  9067. //Update skill-block range database when weapon range changes. [Skotlex]
  9068. i = equip_index[EQI_HAND_R];
  9069. if (i < 0 || !sd->inventory_data[i]) //No data, or no weapon equipped
  9070. flag = 1;
  9071. else
  9072. flag = id->range != sd->inventory_data[i]->range;
  9073. }
  9074. if( equipswitch ){
  9075. for( i = 0; i < EQI_MAX; i++ ){
  9076. if( pos&equip_bitmask[i] ){
  9077. // If there was already an item assigned to this slot
  9078. if( sd->equip_switch_index[i] >= 0 ){
  9079. pc_equipswitch_remove( sd, sd->equip_switch_index[i] );
  9080. }
  9081. // Assign the new index to it
  9082. sd->equip_switch_index[i] = n;
  9083. }
  9084. }
  9085. sd->inventory.u.items_inventory[n].equipSwitch = pos;
  9086. clif_equipswitch_add( sd, n, pos, ITEM_EQUIP_ACK_OK );
  9087. return true;
  9088. }else{
  9089. for(i=0;i<EQI_MAX;i++) {
  9090. if(pos & equip_bitmask[i]) {
  9091. if(sd->equip_index[i] >= 0) //Slot taken, remove item from there.
  9092. pc_unequipitem(sd,sd->equip_index[i],2 | 4);
  9093. sd->equip_index[i] = n;
  9094. }
  9095. }
  9096. pc_equipswitch_remove(sd, n);
  9097. if(pos==EQP_AMMO) {
  9098. clif_arrowequip(sd,n);
  9099. clif_arrow_fail(sd,3);
  9100. }
  9101. else
  9102. clif_equipitemack(sd,n,pos,ITEM_EQUIP_ACK_OK);
  9103. sd->inventory.u.items_inventory[n].equip = pos;
  9104. }
  9105. if(pos & EQP_HAND_R) {
  9106. if(id)
  9107. sd->weapontype1 = id->look;
  9108. else
  9109. sd->weapontype1 = 0;
  9110. pc_calcweapontype(sd);
  9111. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9112. }
  9113. if(pos & EQP_HAND_L) {
  9114. if(id) {
  9115. if(id->type == IT_WEAPON) {
  9116. sd->status.shield = 0;
  9117. sd->weapontype2 = id->look;
  9118. }
  9119. else
  9120. if(id->type == IT_ARMOR) {
  9121. sd->status.shield = id->look;
  9122. sd->weapontype2 = 0;
  9123. }
  9124. }
  9125. else
  9126. sd->status.shield = sd->weapontype2 = 0;
  9127. pc_calcweapontype(sd);
  9128. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9129. }
  9130. if(pos & EQP_SHOES)
  9131. clif_changelook(&sd->bl,LOOK_SHOES,0);
  9132. if (battle_config.ammo_unequip && (pos&EQP_ARMS) && id->type == IT_WEAPON) {
  9133. short idx = sd->equip_index[EQI_AMMO];
  9134. if (idx >= 0) {
  9135. switch (sd->inventory_data[idx]->look) {
  9136. case AMMO_ARROW:
  9137. if (id->look != W_BOW && id->look != W_MUSICAL && id->look != W_WHIP)
  9138. pc_unequipitem(sd, idx, 2 | 4);
  9139. break;
  9140. case AMMO_BULLET:
  9141. case AMMO_SHELL:
  9142. if (id->look != W_REVOLVER && id->look != W_RIFLE && id->look != W_GATLING && id->look != W_SHOTGUN
  9143. #ifdef RENEWAL
  9144. && id->look != W_GRENADE
  9145. #endif
  9146. )
  9147. pc_unequipitem(sd, idx, 2 | 4);
  9148. break;
  9149. #ifndef RENEWAL
  9150. case AMMO_GRENADE:
  9151. if (id->look != W_GRENADE)
  9152. pc_unequipitem(sd, idx, 2 | 4);
  9153. break;
  9154. #endif
  9155. }
  9156. }
  9157. }
  9158. pc_set_costume_view(sd);
  9159. pc_checkallowskill(sd); //Check if status changes should be halted.
  9160. iflag = sd->npc_item_flag;
  9161. /* check for combos (MUST be before status_calc_pc) */
  9162. if( id->combos_count )
  9163. pc_checkcombo(sd,id);
  9164. if(itemdb_isspecial(sd->inventory.u.items_inventory[n].card[0]))
  9165. ; //No cards
  9166. else {
  9167. for( i = 0; i < MAX_SLOTS; i++ ) {
  9168. struct item_data *data;
  9169. if (!sd->inventory.u.items_inventory[n].card[i])
  9170. continue;
  9171. if ( ( data = itemdb_exists(sd->inventory.u.items_inventory[n].card[i]) ) != NULL ) {
  9172. if( data->combos_count )
  9173. pc_checkcombo(sd,data);
  9174. }
  9175. }
  9176. }
  9177. status_calc_pc(sd,SCO_NONE);
  9178. if (flag) //Update skill data
  9179. clif_skillinfoblock(sd);
  9180. //OnEquip script [Skotlex]
  9181. if (id) {
  9182. //only run the script if item isn't restricted
  9183. if (id->equip_script && (pc_has_permission(sd,PC_PERM_USE_ALL_EQUIPMENT) || !itemdb_isNoEquip(id,sd->bl.m)))
  9184. run_script(id->equip_script,0,sd->bl.id,fake_nd->bl.id);
  9185. if(itemdb_isspecial(sd->inventory.u.items_inventory[n].card[0]))
  9186. ; //No cards
  9187. else {
  9188. for( i = 0; i < MAX_SLOTS; i++ ) {
  9189. struct item_data *data;
  9190. if (!sd->inventory.u.items_inventory[n].card[i])
  9191. continue;
  9192. if ( ( data = itemdb_exists(sd->inventory.u.items_inventory[n].card[i]) ) != NULL ) {
  9193. if (data->equip_script && (pc_has_permission(sd,PC_PERM_USE_ALL_EQUIPMENT) || !itemdb_isNoEquip(data,sd->bl.m)))
  9194. run_script(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
  9195. }
  9196. }
  9197. }
  9198. }
  9199. sd->npc_item_flag = iflag;
  9200. return true;
  9201. }
  9202. /**
  9203. * Recalculate player status on unequip
  9204. * @param sd: Player data
  9205. * @param n: Item inventory index
  9206. * @param flag: Whether to recalculate a player's status or not
  9207. * @return True on success or false on failure
  9208. */
  9209. static void pc_unequipitem_sub(struct map_session_data *sd, int n, int flag) {
  9210. int i, iflag;
  9211. bool status_calc = false;
  9212. if (sd->state.autobonus&sd->inventory.u.items_inventory[n].equip)
  9213. sd->state.autobonus &= ~sd->inventory.u.items_inventory[n].equip; //Check for activated autobonus [Inkfish]
  9214. sd->inventory.u.items_inventory[n].equip = 0;
  9215. if (!(flag & 4))
  9216. pc_checkallowskill(sd);
  9217. iflag = sd->npc_item_flag;
  9218. /* check for combos (MUST be before status_calc_pc) */
  9219. if (sd->inventory_data[n]) {
  9220. if (sd->inventory_data[n]->combos_count) {
  9221. if (pc_removecombo(sd, sd->inventory_data[n]))
  9222. status_calc = true;
  9223. }
  9224. if (itemdb_isspecial(sd->inventory.u.items_inventory[n].card[0]))
  9225. ; //No cards
  9226. else {
  9227. for (i = 0; i < MAX_SLOTS; i++) {
  9228. struct item_data *data;
  9229. if (!sd->inventory.u.items_inventory[n].card[i])
  9230. continue;
  9231. if ((data = itemdb_exists(sd->inventory.u.items_inventory[n].card[i])) != NULL) {
  9232. if (data->combos_count) {
  9233. if (pc_removecombo(sd, data))
  9234. status_calc = true;
  9235. }
  9236. }
  9237. }
  9238. }
  9239. }
  9240. if (flag & 1 || status_calc) {
  9241. pc_checkallowskill(sd);
  9242. status_calc_pc(sd, SCO_NONE);
  9243. }
  9244. if (sd->sc.data[SC_SIGNUMCRUCIS] && !battle_check_undead(sd->battle_status.race, sd->battle_status.def_ele))
  9245. status_change_end(&sd->bl, SC_SIGNUMCRUCIS, INVALID_TIMER);
  9246. //OnUnEquip script [Skotlex]
  9247. if (sd->inventory_data[n]) {
  9248. if (sd->inventory_data[n]->unequip_script)
  9249. run_script(sd->inventory_data[n]->unequip_script, 0, sd->bl.id, fake_nd->bl.id);
  9250. if (itemdb_isspecial(sd->inventory.u.items_inventory[n].card[0]))
  9251. ; //No cards
  9252. else {
  9253. for (i = 0; i < MAX_SLOTS; i++) {
  9254. struct item_data *data;
  9255. if (!sd->inventory.u.items_inventory[n].card[i])
  9256. continue;
  9257. if ((data = itemdb_exists(sd->inventory.u.items_inventory[n].card[i])) != NULL) {
  9258. if (data->unequip_script)
  9259. run_script(data->unequip_script, 0, sd->bl.id, fake_nd->bl.id);
  9260. }
  9261. }
  9262. }
  9263. }
  9264. sd->npc_item_flag = iflag;
  9265. }
  9266. /**
  9267. * Called when attempting to unequip an item from a player
  9268. * @param sd: Player data
  9269. * @param n: Item inventory index
  9270. * @param flag: Type of unequip
  9271. * 0 - only unequip
  9272. * 1 - calculate status after unequipping
  9273. * 2 - force unequip
  9274. * 4 - unequip by switching equipment
  9275. * @return True on success or false on failure
  9276. */
  9277. bool pc_unequipitem(struct map_session_data *sd, int n, int flag) {
  9278. int i, pos;
  9279. nullpo_retr(false,sd);
  9280. if (n < 0 || n >= MAX_INVENTORY) {
  9281. clif_unequipitemack(sd,0,0,0);
  9282. return false;
  9283. }
  9284. if (!(pos = sd->inventory.u.items_inventory[n].equip)) {
  9285. clif_unequipitemack(sd,n,0,0);
  9286. return false; //Nothing to unequip
  9287. }
  9288. // status change that makes player cannot unequip equipment
  9289. if (!(flag&2) && sd->sc.count &&
  9290. (sd->sc.data[SC_BERSERK] ||
  9291. sd->sc.data[SC_SATURDAYNIGHTFEVER] ||
  9292. sd->sc.data[SC__BLOODYLUST] ||
  9293. sd->sc.data[SC_KYOUGAKU] ||
  9294. (sd->sc.data[SC_PYROCLASTIC] &&
  9295. sd->inventory_data[n]->type == IT_WEAPON))) // can't switch weapon
  9296. {
  9297. clif_unequipitemack(sd,n,0,0);
  9298. return false;
  9299. }
  9300. if (battle_config.battle_log)
  9301. ShowInfo("unequip %d %x:%x\n",n,pc_equippoint(sd,n),pos);
  9302. for(i = 0; i < EQI_MAX; i++) {
  9303. if (pos & equip_bitmask[i])
  9304. sd->equip_index[i] = -1;
  9305. }
  9306. if(pos & EQP_HAND_R) {
  9307. sd->weapontype1 = 0;
  9308. sd->status.weapon = sd->weapontype2;
  9309. pc_calcweapontype(sd);
  9310. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9311. if( !battle_config.dancing_weaponswitch_fix )
  9312. status_change_end(&sd->bl, SC_DANCING, INVALID_TIMER); // Unequipping => stop dancing.
  9313. #ifdef RENEWAL
  9314. if (battle_config.switch_remove_edp&2) {
  9315. #else
  9316. if (battle_config.switch_remove_edp&1) {
  9317. #endif
  9318. status_change_end(&sd->bl, SC_EDP, INVALID_TIMER);
  9319. }
  9320. }
  9321. if(pos & EQP_HAND_L) {
  9322. if (sd->status.shield && battle_getcurrentskill(&sd->bl) == LG_SHIELDSPELL)
  9323. unit_skillcastcancel(&sd->bl, 0); // Cancel Shield Spell if player swaps shields.
  9324. sd->status.shield = sd->weapontype2 = 0;
  9325. pc_calcweapontype(sd);
  9326. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9327. }
  9328. if(pos & EQP_SHOES)
  9329. clif_changelook(&sd->bl,LOOK_SHOES,0);
  9330. clif_unequipitemack(sd,n,pos,1);
  9331. pc_set_costume_view(sd);
  9332. status_change_end(&sd->bl,SC_HEAT_BARREL,INVALID_TIMER);
  9333. // On weapon change (right and left hand)
  9334. if ((pos & EQP_ARMS) && sd->inventory_data[n]->type == IT_WEAPON) {
  9335. if (battle_config.ammo_unequip && !(flag & 4)) {
  9336. switch (sd->inventory_data[n]->look) {
  9337. case W_BOW:
  9338. case W_MUSICAL:
  9339. case W_WHIP:
  9340. case W_REVOLVER:
  9341. case W_RIFLE:
  9342. case W_GATLING:
  9343. case W_SHOTGUN:
  9344. case W_GRENADE: {
  9345. short idx = sd->equip_index[EQI_AMMO];
  9346. if (idx >= 0) {
  9347. sd->equip_index[EQI_AMMO] = -1;
  9348. clif_unequipitemack(sd, idx, sd->inventory.u.items_inventory[idx].equip, 1);
  9349. pc_unequipitem_sub(sd, idx, 0);
  9350. }
  9351. }
  9352. break;
  9353. }
  9354. }
  9355. if (!sd->sc.data[SC_SEVENWIND] || sd->sc.data[SC_ASPERSIO]) //Check for seven wind (but not level seven!)
  9356. skill_enchant_elemental_end(&sd->bl, SC_NONE);
  9357. status_change_end(&sd->bl, SC_FEARBREEZE, INVALID_TIMER);
  9358. status_change_end(&sd->bl, SC_EXEEDBREAK, INVALID_TIMER);
  9359. }
  9360. // On armor change
  9361. if (pos & EQP_ARMOR) {
  9362. if (sd->sc.data[SC_HOVERING] && sd->inventory_data[n]->nameid == ITEMID_HOVERING_BOOSTER)
  9363. status_change_end(&sd->bl, SC_HOVERING, INVALID_TIMER);
  9364. //status_change_end(&sd->bl, SC_BENEDICTIO, INVALID_TIMER); // No longer is removed? Need confirmation
  9365. status_change_end(&sd->bl, SC_ARMOR_RESIST, INVALID_TIMER);
  9366. }
  9367. // On equipment change
  9368. #ifndef RENEWAL
  9369. if (!(flag&4))
  9370. status_change_end(&sd->bl, SC_CONCENTRATION, INVALID_TIMER);
  9371. #endif
  9372. // On ammo change
  9373. if (sd->inventory_data[n]->type == IT_AMMO && (sd->inventory_data[n]->nameid != ITEMID_SILVER_BULLET || sd->inventory_data[n]->nameid != ITEMID_PURIFICATION_BULLET || sd->inventory_data[n]->nameid != ITEMID_SILVER_BULLET_))
  9374. status_change_end(&sd->bl, SC_P_ALTER, INVALID_TIMER);
  9375. pc_unequipitem_sub(sd, n, flag);
  9376. return true;
  9377. }
  9378. int pc_equipswitch( struct map_session_data* sd, int index ){
  9379. // Get the target equip mask
  9380. int position = sd->inventory.u.items_inventory[index].equipSwitch;
  9381. // Get the currently equipped item
  9382. short equippedItem = pc_checkequip( sd, position, true );
  9383. // No item equipped at the target
  9384. if( equippedItem == -1 ){
  9385. // Remove it from the equip switch
  9386. pc_equipswitch_remove( sd, index );
  9387. pc_equipitem( sd, index, position );
  9388. return position;
  9389. }else{
  9390. std::map<int, int> unequipped;
  9391. int unequipped_position = 0;
  9392. // Unequip all items that interfere
  9393. for( int i = 0; i < EQI_MAX; i++ ){
  9394. int unequip_index = sd->equip_index[i];
  9395. if( unequip_index >= 0 && position & equip_bitmask[i] ){
  9396. struct item* unequip_item = &sd->inventory.u.items_inventory[unequip_index];
  9397. // Store the unequipped index and position mask for later
  9398. unequipped[unequip_index] = unequip_item->equip;
  9399. // Keep the position for later
  9400. unequipped_position |= unequip_item->equip;
  9401. // Unequip the item
  9402. pc_unequipitem( sd, unequip_index, 0 );
  9403. }
  9404. }
  9405. int all_position = position | unequipped_position;
  9406. // Equip everything that is hit by the mask
  9407. for( int i = 0; i < EQI_MAX; i++ ){
  9408. int exchange_index = sd->equip_switch_index[i];
  9409. if( exchange_index >= 0 && all_position & equip_bitmask[i] ){
  9410. struct item* exchange_item = &sd->inventory.u.items_inventory[exchange_index];
  9411. // Store the target position
  9412. int exchange_position = exchange_item->equipSwitch;
  9413. // Remove the item from equip switch
  9414. pc_equipswitch_remove( sd, exchange_index );
  9415. // Equip the item at the destinated position
  9416. pc_equipitem( sd, exchange_index, exchange_position );
  9417. }
  9418. }
  9419. // Place all unequipped items into the equip switch window
  9420. for( std::pair<int, int> pair : unequipped ){
  9421. int unequipped_index = pair.first;
  9422. int unequipped_position = pair.second;
  9423. // Rebuild the index cache
  9424. for( int i = 0; i < EQI_MAX; i++ ){
  9425. if( unequipped_position & equip_bitmask[i] ){
  9426. sd->equip_switch_index[i] = unequipped_index;
  9427. }
  9428. }
  9429. // Set the correct position mask
  9430. sd->inventory.u.items_inventory[unequipped_index].equipSwitch = unequipped_position;
  9431. // Notify the client
  9432. clif_equipswitch_add( sd, unequipped_index, unequipped_position, ITEM_EQUIP_ACK_OK );
  9433. }
  9434. return all_position;
  9435. }
  9436. }
  9437. void pc_equipswitch_remove( struct map_session_data* sd, int index ){
  9438. struct item* item = &sd->inventory.u.items_inventory[index];
  9439. if( !item->equipSwitch ){
  9440. return;
  9441. }
  9442. for( int i = 0; i < EQI_MAX; i++ ){
  9443. // If a match is found
  9444. if( sd->equip_switch_index[i] == index ){
  9445. // Remove it from the slot
  9446. sd->equip_switch_index[i] = -1;
  9447. }
  9448. }
  9449. // Send out one packet for all slots using the current item's mask
  9450. clif_equipswitch_remove( sd, index, item->equipSwitch, false );
  9451. item->equipSwitch = 0;
  9452. }
  9453. /*==========================================
  9454. * Checking if player (sd) has an invalid item
  9455. * and is unequiped on map load (item_noequip)
  9456. *------------------------------------------*/
  9457. void pc_checkitem(struct map_session_data *sd) {
  9458. int i, calc_flag = 0;
  9459. struct item* it;
  9460. nullpo_retv(sd);
  9461. if( sd->state.vending ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam)
  9462. return;
  9463. pc_check_available_item(sd, ITMCHK_NONE); // Check for invalid(ated) items.
  9464. for( i = 0; i < MAX_INVENTORY; i++ ) {
  9465. it = &sd->inventory.u.items_inventory[i];
  9466. if( it->nameid == 0 )
  9467. continue;
  9468. if( !it->equip )
  9469. continue;
  9470. if( it->equip&~pc_equippoint(sd,i) ) {
  9471. pc_unequipitem(sd, i, 2);
  9472. calc_flag = 1;
  9473. continue;
  9474. }
  9475. 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) ) {
  9476. pc_unequipitem(sd, i, 2);
  9477. calc_flag = 1;
  9478. continue;
  9479. }
  9480. }
  9481. for( i = 0; i < MAX_INVENTORY; i++ ) {
  9482. it = &sd->inventory.u.items_inventory[i];
  9483. if( it->nameid == 0 )
  9484. continue;
  9485. if( !it->equipSwitch )
  9486. continue;
  9487. if( it->equipSwitch&~pc_equippoint(sd,i) ||
  9488. ( !pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT) && !battle_config.allow_equip_restricted_item && itemdb_isNoEquip(sd->inventory_data[i], sd->bl.m) ) ){
  9489. for( int j = 0; j < EQI_MAX; j++ ){
  9490. if( sd->equip_switch_index[j] == i ){
  9491. sd->equip_switch_index[j] = -1;
  9492. }
  9493. }
  9494. sd->inventory.u.items_inventory[i].equipSwitch = 0;
  9495. continue;
  9496. }
  9497. }
  9498. if( calc_flag && sd->state.active ) {
  9499. pc_checkallowskill(sd);
  9500. status_calc_pc(sd,SCO_NONE);
  9501. }
  9502. }
  9503. /*==========================================
  9504. * Checks for unavailable items and removes them.
  9505. * @param sd: Player data
  9506. * @param type Forced check:
  9507. * 1 - Inventory
  9508. * 2 - Cart
  9509. * 4 - Storage
  9510. *------------------------------------------*/
  9511. void pc_check_available_item(struct map_session_data *sd, uint8 type)
  9512. {
  9513. int i;
  9514. unsigned short nameid;
  9515. char output[256];
  9516. nullpo_retv(sd);
  9517. if (battle_config.item_check&ITMCHK_INVENTORY && type&ITMCHK_INVENTORY) { // Check for invalid(ated) items in inventory.
  9518. for(i = 0; i < MAX_INVENTORY; i++) {
  9519. nameid = sd->inventory.u.items_inventory[i].nameid;
  9520. if (!nameid)
  9521. continue;
  9522. if (!itemdb_available(nameid)) {
  9523. sprintf(output, msg_txt(sd, 709), nameid); // Item %hu has been removed from your inventory.
  9524. clif_displaymessage(sd->fd, output);
  9525. ShowWarning("Removed invalid/disabled item (ID: %hu, amount: %d) from inventory (char_id: %d).\n", nameid, sd->inventory.u.items_inventory[i].amount, sd->status.char_id);
  9526. pc_delitem(sd, i, sd->inventory.u.items_inventory[i].amount, 4, 0, LOG_TYPE_OTHER);
  9527. continue;
  9528. }
  9529. if (!sd->inventory.u.items_inventory[i].unique_id && !itemdb_isstackable(nameid))
  9530. sd->inventory.u.items_inventory[i].unique_id = pc_generate_unique_id(sd);
  9531. }
  9532. }
  9533. if (battle_config.item_check&ITMCHK_CART && type&ITMCHK_CART) { // Check for invalid(ated) items in cart.
  9534. for(i = 0; i < MAX_CART; i++) {
  9535. nameid = sd->cart.u.items_cart[i].nameid;
  9536. if (!nameid)
  9537. continue;
  9538. if (!itemdb_available(nameid)) {
  9539. sprintf(output, msg_txt(sd, 710), nameid); // Item %hu has been removed from your cart.
  9540. clif_displaymessage(sd->fd, output);
  9541. ShowWarning("Removed invalid/disabled item (ID: %hu, amount: %d) from cart (char_id: %d).\n", nameid, sd->cart.u.items_cart[i].amount, sd->status.char_id);
  9542. pc_cart_delitem(sd, i, sd->cart.u.items_cart[i].amount, 0, LOG_TYPE_OTHER);
  9543. continue;
  9544. }
  9545. if (!sd->cart.u.items_cart[i].unique_id && !itemdb_isstackable(nameid))
  9546. sd->cart.u.items_cart[i].unique_id = pc_generate_unique_id(sd);
  9547. }
  9548. }
  9549. if (battle_config.item_check&ITMCHK_STORAGE && type&ITMCHK_STORAGE) { // Check for invalid(ated) items in storage.
  9550. for(i = 0; i < sd->storage.max_amount; i++) {
  9551. nameid = sd->storage.u.items_storage[i].nameid;
  9552. if (!nameid)
  9553. continue;
  9554. if (!itemdb_available(nameid)) {
  9555. sprintf(output, msg_txt(sd, 711), nameid); // Item %hu has been removed from your storage.
  9556. clif_displaymessage(sd->fd, output);
  9557. ShowWarning("Removed invalid/disabled item (ID: %hu, amount: %d) from storage (char_id: %d).\n", nameid, sd->storage.u.items_storage[i].amount, sd->status.char_id);
  9558. storage_delitem(sd, &sd->storage, i, sd->storage.u.items_storage[i].amount);
  9559. continue;
  9560. }
  9561. if (!sd->storage.u.items_storage[i].unique_id && !itemdb_isstackable(nameid))
  9562. sd->storage.u.items_storage[i].unique_id = pc_generate_unique_id(sd);
  9563. }
  9564. }
  9565. }
  9566. /*==========================================
  9567. * Update PVP rank for sd1 in cmp to sd2
  9568. *------------------------------------------*/
  9569. static int pc_calc_pvprank_sub(struct block_list *bl,va_list ap)
  9570. {
  9571. struct map_session_data *sd1,*sd2;
  9572. sd1=(struct map_session_data *)bl;
  9573. sd2=va_arg(ap,struct map_session_data *);
  9574. if( pc_isinvisible(sd1) || pc_isinvisible(sd2) )
  9575. {// cannot register pvp rank for hidden GMs
  9576. return 0;
  9577. }
  9578. if( sd1->pvp_point > sd2->pvp_point )
  9579. sd2->pvp_rank++;
  9580. return 0;
  9581. }
  9582. /*==========================================
  9583. * Calculate new rank beetween all present players (map_foreachinallarea)
  9584. * and display result
  9585. *------------------------------------------*/
  9586. int pc_calc_pvprank(struct map_session_data *sd)
  9587. {
  9588. int old = sd->pvp_rank;
  9589. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9590. sd->pvp_rank=1;
  9591. map_foreachinmap(pc_calc_pvprank_sub,sd->bl.m,BL_PC,sd);
  9592. if(old!=sd->pvp_rank || sd->pvp_lastusers!=mapdata->users_pvp)
  9593. clif_pvpset(sd,sd->pvp_rank,sd->pvp_lastusers=mapdata->users_pvp,0);
  9594. return sd->pvp_rank;
  9595. }
  9596. /*==========================================
  9597. * Calculate next sd ranking calculation from config
  9598. *------------------------------------------*/
  9599. TIMER_FUNC(pc_calc_pvprank_timer){
  9600. struct map_session_data *sd;
  9601. sd=map_id2sd(id);
  9602. if(sd==NULL)
  9603. return 0;
  9604. sd->pvp_timer = INVALID_TIMER;
  9605. if( pc_isinvisible(sd) )
  9606. {// do not calculate the pvp rank for a hidden GM
  9607. return 0;
  9608. }
  9609. if( pc_calc_pvprank(sd) > 0 )
  9610. sd->pvp_timer = add_timer(gettick()+PVP_CALCRANK_INTERVAL,pc_calc_pvprank_timer,id,data);
  9611. return 0;
  9612. }
  9613. /*==========================================
  9614. * Checking if sd is married
  9615. * Return:
  9616. * partner_id = yes
  9617. * 0 = no
  9618. *------------------------------------------*/
  9619. int pc_ismarried(struct map_session_data *sd)
  9620. {
  9621. if(sd == NULL)
  9622. return -1;
  9623. if(sd->status.partner_id > 0)
  9624. return sd->status.partner_id;
  9625. else
  9626. return 0;
  9627. }
  9628. /*==========================================
  9629. * Marry player sd to player dstsd
  9630. * Return:
  9631. * false = fail
  9632. * true = success
  9633. *------------------------------------------*/
  9634. bool pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd)
  9635. {
  9636. if(sd == NULL || dstsd == NULL ||
  9637. sd->status.partner_id > 0 || dstsd->status.partner_id > 0 ||
  9638. (sd->class_&JOBL_BABY) || (dstsd->class_&JOBL_BABY))
  9639. return false;
  9640. sd->status.partner_id = dstsd->status.char_id;
  9641. dstsd->status.partner_id = sd->status.char_id;
  9642. achievement_update_objective(sd, AG_MARRY, 1, 1);
  9643. achievement_update_objective(dstsd, AG_MARRY, 1, 1);
  9644. return true;
  9645. }
  9646. /*==========================================
  9647. * Divorce sd from its partner
  9648. * Return:
  9649. * false = fail
  9650. * true = success
  9651. *------------------------------------------*/
  9652. bool pc_divorce(struct map_session_data *sd)
  9653. {
  9654. struct map_session_data *p_sd;
  9655. int i;
  9656. if( sd == NULL || !pc_ismarried(sd) )
  9657. return false;
  9658. if( !sd->status.partner_id )
  9659. return false; // Char is not married
  9660. if( (p_sd = map_charid2sd(sd->status.partner_id)) == NULL )
  9661. { // Lets char server do the divorce
  9662. if( chrif_divorce(sd->status.char_id, sd->status.partner_id) )
  9663. return false; // No char server connected
  9664. return true;
  9665. }
  9666. // Both players online, lets do the divorce manually
  9667. sd->status.partner_id = 0;
  9668. p_sd->status.partner_id = 0;
  9669. for( i = 0; i < MAX_INVENTORY; i++ )
  9670. {
  9671. if( sd->inventory.u.items_inventory[i].nameid == WEDDING_RING_M || sd->inventory.u.items_inventory[i].nameid == WEDDING_RING_F )
  9672. pc_delitem(sd, i, 1, 0, 0, LOG_TYPE_OTHER);
  9673. if( p_sd->inventory.u.items_inventory[i].nameid == WEDDING_RING_M || p_sd->inventory.u.items_inventory[i].nameid == WEDDING_RING_F )
  9674. pc_delitem(p_sd, i, 1, 0, 0, LOG_TYPE_OTHER);
  9675. }
  9676. clif_divorced(sd, p_sd->status.name);
  9677. clif_divorced(p_sd, sd->status.name);
  9678. return true;
  9679. }
  9680. /**
  9681. * Get the partner map_session_data of a player
  9682. * @param sd : the husband|wife session
  9683. * @return partner session or NULL
  9684. */
  9685. struct map_session_data *pc_get_partner(struct map_session_data *sd){
  9686. if (!sd || !pc_ismarried(sd))
  9687. return NULL;
  9688. return map_charid2sd(sd->status.partner_id);
  9689. }
  9690. /**
  9691. * Get the father map_session_data of a player
  9692. * @param sd : the baby session
  9693. * @return father session or NULL
  9694. */
  9695. struct map_session_data *pc_get_father (struct map_session_data *sd){
  9696. if (!sd || !(sd->class_&JOBL_BABY) || !sd->status.father)
  9697. return NULL;
  9698. return map_charid2sd(sd->status.father);
  9699. }
  9700. /**
  9701. * Get the mother map_session_data of a player
  9702. * @param sd : the baby session
  9703. * @return mother session or NULL
  9704. */
  9705. struct map_session_data *pc_get_mother (struct map_session_data *sd){
  9706. if (!sd || !(sd->class_&JOBL_BABY) || !sd->status.mother)
  9707. return NULL;
  9708. return map_charid2sd(sd->status.mother);
  9709. }
  9710. /*==========================================
  9711. * Get sd children charid. (Need to be married)
  9712. *------------------------------------------*/
  9713. struct map_session_data *pc_get_child (struct map_session_data *sd)
  9714. {
  9715. if (!sd || !pc_ismarried(sd) || !sd->status.child)
  9716. // charid2sd returns NULL if not found
  9717. return NULL;
  9718. return map_charid2sd(sd->status.child);
  9719. }
  9720. /*==========================================
  9721. * Set player sd to bleed. (losing hp and/or sp each diff_tick)
  9722. *------------------------------------------*/
  9723. void pc_bleeding (struct map_session_data *sd, t_tick diff_tick)
  9724. {
  9725. int hp = 0, sp = 0;
  9726. if( pc_isdead(sd) )
  9727. return;
  9728. if (sd->hp_loss.value) {
  9729. sd->hp_loss.tick += diff_tick;
  9730. while (sd->hp_loss.tick >= sd->hp_loss.rate) {
  9731. hp += sd->hp_loss.value;
  9732. sd->hp_loss.tick -= sd->hp_loss.rate;
  9733. }
  9734. if(hp >= sd->battle_status.hp)
  9735. hp = sd->battle_status.hp-1; //Script drains cannot kill you.
  9736. }
  9737. if (sd->sp_loss.value) {
  9738. sd->sp_loss.tick += diff_tick;
  9739. while (sd->sp_loss.tick >= sd->sp_loss.rate) {
  9740. sp += sd->sp_loss.value;
  9741. sd->sp_loss.tick -= sd->sp_loss.rate;
  9742. }
  9743. }
  9744. if (hp > 0 || sp > 0)
  9745. status_zap(&sd->bl, hp, sp);
  9746. }
  9747. //Character regen. Flag is used to know which types of regen can take place.
  9748. //&1: HP regen
  9749. //&2: SP regen
  9750. void pc_regen (struct map_session_data *sd, t_tick diff_tick)
  9751. {
  9752. int hp = 0, sp = 0;
  9753. if (sd->hp_regen.value) {
  9754. sd->hp_regen.tick += diff_tick;
  9755. while (sd->hp_regen.tick >= sd->hp_regen.rate) {
  9756. hp += sd->hp_regen.value;
  9757. sd->hp_regen.tick -= sd->hp_regen.rate;
  9758. }
  9759. }
  9760. if (sd->sp_regen.value) {
  9761. sd->sp_regen.tick += diff_tick;
  9762. while (sd->sp_regen.tick >= sd->sp_regen.rate) {
  9763. sp += sd->sp_regen.value;
  9764. sd->sp_regen.tick -= sd->sp_regen.rate;
  9765. }
  9766. }
  9767. if (sd->percent_hp_regen.value) {
  9768. sd->percent_hp_regen.tick += diff_tick;
  9769. while (sd->percent_hp_regen.tick >= sd->percent_hp_regen.rate) {
  9770. hp += sd->status.max_hp * sd->percent_hp_regen.value / 100;
  9771. sd->percent_hp_regen.tick -= sd->percent_hp_regen.rate;
  9772. }
  9773. }
  9774. if (sd->percent_sp_regen.value) {
  9775. sd->percent_sp_regen.tick += diff_tick;
  9776. while (sd->percent_sp_regen.tick >= sd->percent_sp_regen.rate) {
  9777. sp += sd->status.max_sp * sd->percent_sp_regen.value / 100;
  9778. sd->percent_sp_regen.tick -= sd->percent_sp_regen.rate;
  9779. }
  9780. }
  9781. if (hp > 0 || sp > 0)
  9782. status_heal(&sd->bl, hp, sp, 0);
  9783. }
  9784. /*==========================================
  9785. * Memo player sd savepoint. (map,x,y)
  9786. *------------------------------------------*/
  9787. void pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y)
  9788. {
  9789. nullpo_retv(sd);
  9790. sd->status.save_point.map = mapindex;
  9791. sd->status.save_point.x = x;
  9792. sd->status.save_point.y = y;
  9793. }
  9794. /*==========================================
  9795. * Save 1 player data at autosave interval
  9796. *------------------------------------------*/
  9797. static TIMER_FUNC(pc_autosave){
  9798. int interval;
  9799. struct s_mapiterator* iter;
  9800. struct map_session_data* sd;
  9801. static int last_save_id = 0, save_flag = 0;
  9802. if(save_flag == 2) //Someone was saved on last call, normal cycle
  9803. save_flag = 0;
  9804. else
  9805. save_flag = 1; //Noone was saved, so save first found char.
  9806. iter = mapit_getallusers();
  9807. for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
  9808. {
  9809. if (!sd->state.pc_loaded) // Player data hasn't fully loaded
  9810. continue;
  9811. if(sd->bl.id == last_save_id && save_flag != 1) {
  9812. save_flag = 1;
  9813. continue;
  9814. }
  9815. if(save_flag != 1) //Not our turn to save yet.
  9816. continue;
  9817. //Save char.
  9818. last_save_id = sd->bl.id;
  9819. save_flag = 2;
  9820. if (pc_isvip(sd)) // Check if we're still VIP
  9821. chrif_req_login_operation(1, sd->status.name, CHRIF_OP_LOGIN_VIP, 0, 1, 0);
  9822. chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
  9823. break;
  9824. }
  9825. mapit_free(iter);
  9826. interval = autosave_interval/(map_usercount()+1);
  9827. if(interval < minsave_interval)
  9828. interval = minsave_interval;
  9829. add_timer(gettick()+interval,pc_autosave,0,0);
  9830. return 0;
  9831. }
  9832. static int pc_daynight_timer_sub(struct map_session_data *sd,va_list ap)
  9833. {
  9834. if (sd->state.night != night_flag && map_getmapflag(sd->bl.m, MF_NIGHTENABLED))
  9835. { //Night/day state does not match.
  9836. clif_status_load(&sd->bl, EFST_SKE, night_flag); //New night effect by dynamix [Skotlex]
  9837. sd->state.night = night_flag;
  9838. return 1;
  9839. }
  9840. return 0;
  9841. }
  9842. /*================================================
  9843. * timer to do the day [Yor]
  9844. * data: 0 = called by timer, 1 = gmcommand/script
  9845. *------------------------------------------------*/
  9846. TIMER_FUNC(map_day_timer){
  9847. char tmp_soutput[1024];
  9848. if (data == 0 && battle_config.day_duration <= 0) // if we want a day
  9849. return 0;
  9850. if (!night_flag)
  9851. return 0; //Already day.
  9852. night_flag = 0; // 0=day, 1=night [Yor]
  9853. map_foreachpc(pc_daynight_timer_sub);
  9854. strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,502) : msg_txt(NULL,60)); // The day has arrived!
  9855. intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, BC_DEFAULT);
  9856. return 0;
  9857. }
  9858. /*================================================
  9859. * timer to do the night [Yor]
  9860. * data: 0 = called by timer, 1 = gmcommand/script
  9861. *------------------------------------------------*/
  9862. TIMER_FUNC(map_night_timer){
  9863. char tmp_soutput[1024];
  9864. if (data == 0 && battle_config.night_duration <= 0) // if we want a night
  9865. return 0;
  9866. if (night_flag)
  9867. return 0; //Already nigth.
  9868. night_flag = 1; // 0=day, 1=night [Yor]
  9869. map_foreachpc(pc_daynight_timer_sub);
  9870. strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,503) : msg_txt(NULL,59)); // The night has fallen...
  9871. intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, BC_DEFAULT);
  9872. return 0;
  9873. }
  9874. /**
  9875. * Attempt to stand up a player
  9876. * @param sd
  9877. * @param force Ignore the check, ask player to stand up. Used in some cases like pc_damage(), pc_revive(), etc
  9878. * @return True if success, Fals if failed
  9879. */
  9880. bool pc_setstand(struct map_session_data *sd, bool force){
  9881. nullpo_ret(sd);
  9882. // Cannot stand yet
  9883. // TODO: Move to SCS_NOSTAND [Cydh]
  9884. if (!force && (sd->sc.data[SC_SITDOWN_FORCE] || sd->sc.data[SC_BANANA_BOMB_SITDOWN]))
  9885. return false;
  9886. status_change_end(&sd->bl, SC_TENSIONRELAX, INVALID_TIMER);
  9887. clif_status_load(&sd->bl,EFST_SIT,0);
  9888. clif_standing(&sd->bl); //Inform area PC is standing
  9889. //Reset sitting tick.
  9890. sd->ssregen.tick.hp = sd->ssregen.tick.sp = 0;
  9891. if( pc_isdead( sd ) ){
  9892. sd->state.dead_sit = sd->vd.dead_sit = 0;
  9893. clif_party_dead( sd );
  9894. }else{
  9895. sd->state.dead_sit = sd->vd.dead_sit = 0;
  9896. }
  9897. return true;
  9898. }
  9899. /**
  9900. * Calculate Overheat value
  9901. * @param sd: Player data
  9902. * @param heat: Amount of Heat to adjust
  9903. **/
  9904. void pc_overheat(struct map_session_data *sd, int16 heat) {
  9905. struct status_change_entry *sce = NULL;
  9906. int16 limit[] = { 150, 200, 280, 360, 450 };
  9907. uint16 skill_lv;
  9908. nullpo_retv(sd);
  9909. skill_lv = cap_value(pc_checkskill(sd, NC_MAINFRAME), 0, 4);
  9910. if ((sce = sd->sc.data[SC_OVERHEAT_LIMITPOINT])) {
  9911. sce->val1 += heat;
  9912. sce->val1 = cap_value(sce->val1, 0, 1000);
  9913. if (sd->sc.data[SC_OVERHEAT])
  9914. status_change_end(&sd->bl, SC_OVERHEAT, INVALID_TIMER);
  9915. if (sce->val1 > limit[skill_lv])
  9916. sc_start(&sd->bl, &sd->bl, SC_OVERHEAT, 100, sce->val1, 1000);
  9917. } else if (heat > 0)
  9918. sc_start(&sd->bl, &sd->bl, SC_OVERHEAT_LIMITPOINT, 100, heat, 1000);
  9919. }
  9920. /**
  9921. * Check if player is autolooting given itemID.
  9922. */
  9923. bool pc_isautolooting(struct map_session_data *sd, unsigned short nameid)
  9924. {
  9925. uint8 i = 0;
  9926. if (sd->state.autoloottype && sd->state.autoloottype&(1<<itemdb_type(nameid)))
  9927. return true;
  9928. if (!sd->state.autolooting)
  9929. return false;
  9930. if (sd->state.autolooting)
  9931. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == nameid);
  9932. return (i != AUTOLOOTITEM_SIZE);
  9933. }
  9934. /**
  9935. * Checks if player can use @/#command
  9936. * @param sd Player map session data
  9937. * @param command Command name without @/# and params
  9938. * @param type is it atcommand or charcommand
  9939. */
  9940. bool pc_can_use_command(struct map_session_data *sd, const char *command, AtCommandType type)
  9941. {
  9942. return pc_group_can_use_command(pc_get_group_id(sd), command, type);
  9943. }
  9944. /**
  9945. * Checks if commands used by a player should be logged
  9946. * according to their group setting.
  9947. * @param sd Player map session data
  9948. */
  9949. bool pc_should_log_commands(struct map_session_data *sd)
  9950. {
  9951. return pc_group_should_log_commands(pc_get_group_id(sd));
  9952. }
  9953. /**
  9954. * Spirit Charm expiration timer.
  9955. * @see TimerFunc
  9956. */
  9957. static TIMER_FUNC(pc_spiritcharm_timer){
  9958. struct map_session_data *sd;
  9959. int i;
  9960. if ((sd = (struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type != BL_PC)
  9961. return 1;
  9962. if (sd->spiritcharm <= 0) {
  9963. 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);
  9964. sd->spiritcharm = 0;
  9965. sd->spiritcharm_type = CHARM_TYPE_NONE;
  9966. return 0;
  9967. }
  9968. ARR_FIND(0, sd->spiritcharm, i, sd->spiritcharm_timer[i] == tid);
  9969. if (i == sd->spiritcharm) {
  9970. ShowError("pc_spiritcharm_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
  9971. return 0;
  9972. }
  9973. sd->spiritcharm--;
  9974. if (i != sd->spiritcharm)
  9975. memmove(sd->spiritcharm_timer + i, sd->spiritcharm_timer + i + 1, (sd->spiritcharm - i) * sizeof(int));
  9976. sd->spiritcharm_timer[sd->spiritcharm] = INVALID_TIMER;
  9977. if (sd->spiritcharm <= 0)
  9978. sd->spiritcharm_type = CHARM_TYPE_NONE;
  9979. clif_spiritcharm(sd);
  9980. return 0;
  9981. }
  9982. /**
  9983. * Adds a spirit charm.
  9984. * @param sd: Target character
  9985. * @param interval: Duration
  9986. * @param max: Maximum amount of charms to add
  9987. * @param type: Charm type (@see spirit_charm_types)
  9988. */
  9989. void pc_addspiritcharm(struct map_session_data *sd, int interval, int max, int type)
  9990. {
  9991. int tid, i;
  9992. nullpo_retv(sd);
  9993. if (sd->spiritcharm_type != CHARM_TYPE_NONE && type != sd->spiritcharm_type)
  9994. pc_delspiritcharm(sd, sd->spiritcharm, sd->spiritcharm_type);
  9995. if (max > MAX_SPIRITCHARM)
  9996. max = MAX_SPIRITCHARM;
  9997. if (sd->spiritcharm < 0)
  9998. sd->spiritcharm = 0;
  9999. if (sd->spiritcharm && sd->spiritcharm >= max) {
  10000. if (sd->spiritcharm_timer[0] != INVALID_TIMER)
  10001. delete_timer(sd->spiritcharm_timer[0], pc_spiritcharm_timer);
  10002. sd->spiritcharm--;
  10003. if (sd->spiritcharm != 0)
  10004. memmove(sd->spiritcharm_timer + 0, sd->spiritcharm_timer + 1, (sd->spiritcharm) * sizeof(int));
  10005. sd->spiritcharm_timer[sd->spiritcharm] = INVALID_TIMER;
  10006. }
  10007. tid = add_timer(gettick() + interval, pc_spiritcharm_timer, sd->bl.id, 0);
  10008. 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);
  10009. if (i != sd->spiritcharm)
  10010. memmove(sd->spiritcharm_timer + i + 1, sd->spiritcharm_timer + i, (sd->spiritcharm - i) * sizeof(int));
  10011. sd->spiritcharm_timer[i] = tid;
  10012. sd->spiritcharm++;
  10013. sd->spiritcharm_type = type;
  10014. clif_spiritcharm(sd);
  10015. }
  10016. /**
  10017. * Removes one or more spirit charms.
  10018. * @param sd: The target character
  10019. * @param count: Amount of charms to remove
  10020. * @param type: Type of charm to remove
  10021. */
  10022. void pc_delspiritcharm(struct map_session_data *sd, int count, int type)
  10023. {
  10024. int i;
  10025. nullpo_retv(sd);
  10026. if (sd->spiritcharm_type != type)
  10027. return;
  10028. if (sd->spiritcharm <= 0) {
  10029. sd->spiritcharm = 0;
  10030. return;
  10031. }
  10032. if (count <= 0)
  10033. return;
  10034. if (count > sd->spiritcharm)
  10035. count = sd->spiritcharm;
  10036. sd->spiritcharm -= count;
  10037. if (count > MAX_SPIRITCHARM)
  10038. count = MAX_SPIRITCHARM;
  10039. for (i = 0; i < count; i++) {
  10040. if (sd->spiritcharm_timer[i] != INVALID_TIMER) {
  10041. delete_timer(sd->spiritcharm_timer[i], pc_spiritcharm_timer);
  10042. sd->spiritcharm_timer[i] = INVALID_TIMER;
  10043. }
  10044. }
  10045. for (i = count; i < MAX_SPIRITCHARM; i++) {
  10046. sd->spiritcharm_timer[i - count] = sd->spiritcharm_timer[i];
  10047. sd->spiritcharm_timer[i] = INVALID_TIMER;
  10048. }
  10049. if (sd->spiritcharm <= 0)
  10050. sd->spiritcharm_type = CHARM_TYPE_NONE;
  10051. clif_spiritcharm(sd);
  10052. }
  10053. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  10054. /**
  10055. * Renewal EXP/Item Drop rate modifier based on level penalty
  10056. * @param level_diff: Monster and Player level difference
  10057. * @param mob_class: Monster class
  10058. * @param mode: Monster mode
  10059. * @param type: 1 - EXP, 2 - Item Drop
  10060. * @return Penalty rate
  10061. */
  10062. int pc_level_penalty_mod(int level_diff, uint32 mob_class, enum e_mode mode, int type)
  10063. {
  10064. int rate = 100;
  10065. if (type == 2 && (mode&MD_FIXED_ITEMDROP))
  10066. return rate;
  10067. if (level_diff < 0)
  10068. level_diff = MAX_LEVEL + (~level_diff + 1);
  10069. if ((rate = level_penalty[type][mob_class][level_diff]) > 0) // Monster class found, return rate
  10070. return rate;
  10071. return 100; // Penalty not found, return default
  10072. }
  10073. #endif
  10074. int pc_split_str(char *str,char **val,int num)
  10075. {
  10076. int i;
  10077. for (i=0; i<num && str; i++){
  10078. val[i] = str;
  10079. str = strchr(str,',');
  10080. if (str && i<num-1) //Do not remove a trailing comma.
  10081. *str++=0;
  10082. }
  10083. return i;
  10084. }
  10085. int pc_split_atoi(char* str, int* val, char sep, int max)
  10086. {
  10087. int i,j;
  10088. for (i=0; i<max; i++) {
  10089. if (!str) break;
  10090. val[i] = atoi(str);
  10091. str = strchr(str,sep);
  10092. if (str)
  10093. *str++=0;
  10094. }
  10095. //Zero up the remaining.
  10096. for(j=i; j < max; j++)
  10097. val[j] = 0;
  10098. return i;
  10099. }
  10100. int pc_split_atoui(char* str, unsigned int* val, char sep, int max)
  10101. {
  10102. static int warning=0;
  10103. int i,j;
  10104. for (i=0; i<max; i++) {
  10105. double f;
  10106. if (!str) break;
  10107. f = atof(str);
  10108. if (f < 0)
  10109. val[i] = 0;
  10110. else if (f > UINT_MAX) {
  10111. val[i] = UINT_MAX;
  10112. if (!warning) {
  10113. warning = 1;
  10114. ShowWarning("pc_readdb (exp.txt): Required exp per level is capped to %u\n", UINT_MAX);
  10115. }
  10116. } else
  10117. val[i] = (unsigned int)f;
  10118. str = strchr(str,sep);
  10119. if (str)
  10120. *str++=0;
  10121. }
  10122. //Zero up the remaining.
  10123. for(j=i; j < max; j++)
  10124. val[j] = 0;
  10125. return i;
  10126. }
  10127. /*==========================================
  10128. * sub DB reading.
  10129. * Function used to read skill_tree.txt
  10130. *------------------------------------------*/
  10131. static bool pc_readdb_skilltree(char* fields[], int columns, int current)
  10132. {
  10133. uint32 baselv, joblv, baselv_max, joblv_max;
  10134. uint16 skill_id, skill_lv, skill_lv_max;
  10135. int idx, class_;
  10136. unsigned int i, offset, skill_idx;
  10137. class_ = atoi(fields[0]);
  10138. skill_id = (uint16)atoi(fields[1]);
  10139. skill_lv = (uint16)atoi(fields[2]);
  10140. if (columns == 5 + MAX_PC_SKILL_REQUIRE * 2) { // Base/Job level requirement extra columns
  10141. baselv = (uint32)atoi(fields[3]);
  10142. joblv = (uint32)atoi(fields[4]);
  10143. offset = 5;
  10144. }
  10145. else if (columns == 3 + MAX_PC_SKILL_REQUIRE * 2) {
  10146. baselv = joblv = 0;
  10147. offset = 3;
  10148. }
  10149. else {
  10150. ShowWarning("pc_readdb_skilltree: Invalid number of colums in skill %hu of job %d's tree.\n", skill_id, class_);
  10151. return false;
  10152. }
  10153. if(!pcdb_checkid(class_))
  10154. {
  10155. ShowWarning("pc_readdb_skilltree: Invalid job class %d specified.\n", class_);
  10156. return false;
  10157. }
  10158. idx = pc_class2idx(class_);
  10159. if (!skill_get_index(skill_id)) {
  10160. ShowWarning("pc_readdb_skilltree: Unable to load skill %hu into job %d's tree.\n", skill_id, class_);
  10161. return false;
  10162. }
  10163. if (skill_lv > (skill_lv_max = skill_get_max(skill_id))) {
  10164. ShowWarning("pc_readdb_skilltree: Skill %hu's level %hu exceeds job %d's max level %hu. Capping skill level.\n", skill_id, skill_lv, class_, skill_lv_max);
  10165. skill_lv = skill_lv_max;
  10166. }
  10167. if (baselv > (baselv_max = pc_class_maxbaselv(class_))) {
  10168. ShowWarning("pc_readdb_skilltree: Skill %hu's base level requirement %d exceeds job %d's max base level %d. Capping skill base level.\n", skill_id, baselv, class_, baselv_max);
  10169. baselv = baselv_max;
  10170. }
  10171. if (joblv > (joblv_max = pc_class_maxjoblv(class_))) {
  10172. ShowWarning("pc_readdb_skilltree: Skill %hu's job level requirement %d exceeds job %d's max job level %d. Capping skill job level.\n", skill_id, joblv, class_, joblv_max);
  10173. joblv = joblv_max;
  10174. }
  10175. //This is to avoid adding two lines for the same skill. [Skotlex]
  10176. ARR_FIND( 0, MAX_SKILL_TREE, skill_idx, skill_tree[idx][skill_idx].skill_id == 0 || skill_tree[idx][skill_idx].skill_id == skill_id );
  10177. if( skill_idx == MAX_SKILL_TREE )
  10178. {
  10179. ShowWarning("pc_readdb_skilltree: Unable to load skill %hu into job %d's tree. Maximum number of skills per job has been reached.\n", skill_id, class_);
  10180. return false;
  10181. }
  10182. else if(skill_tree[idx][skill_idx].skill_id)
  10183. {
  10184. ShowNotice("pc_readdb_skilltree: Overwriting skill %hu for job %d.\n", skill_id, class_);
  10185. }
  10186. skill_tree[idx][skill_idx].skill_id = skill_id;
  10187. skill_tree[idx][skill_idx].skill_lv = skill_lv;
  10188. skill_tree[idx][skill_idx].baselv = baselv;
  10189. skill_tree[idx][skill_idx].joblv = joblv;
  10190. for(i = 0; i < MAX_PC_SKILL_REQUIRE; i++)
  10191. {
  10192. skill_id = (uint16)atoi(fields[i * 2 + offset]);
  10193. skill_lv = (uint16)atoi(fields[i * 2 + offset + 1]);
  10194. if (skill_id == 0) {
  10195. if (skill_tree[idx][skill_idx].need[i].skill_id > 0) { // Remove pre-requisite
  10196. skill_tree[idx][skill_idx].need[i].skill_id = 0;
  10197. skill_tree[idx][skill_idx].need[i].skill_lv = 0;
  10198. }
  10199. continue;
  10200. }
  10201. if (skill_id > MAX_SKILL_ID || !skill_get_index(skill_id)) {
  10202. ShowWarning("pc_readdb_skilltree: Unable to load requirement skill %hu into job %d's tree.", skill_id, class_);
  10203. return false;
  10204. }
  10205. if (skill_lv > (skill_lv_max = skill_get_max(skill_id))) {
  10206. ShowWarning("pc_readdb_skilltree: Skill %hu's level %hu exceeds job %d's max level %hu. Capping skill level.\n", skill_id, skill_lv, class_, skill_lv_max);
  10207. skill_lv = skill_lv_max;
  10208. }
  10209. skill_tree[idx][skill_idx].need[i].skill_id = skill_id;
  10210. skill_tree[idx][skill_idx].need[i].skill_lv = skill_lv;
  10211. }
  10212. return true;
  10213. }
  10214. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  10215. static bool pc_readdb_levelpenalty(char* fields[], int columns, int current)
  10216. {
  10217. int type, class_, diff;
  10218. type = atoi(fields[0]); //1=experience, 2=item drop
  10219. class_ = atoi(fields[1]);
  10220. diff = atoi(fields[2]);
  10221. if( type != 1 && type != 2 ){
  10222. ShowWarning("pc_readdb_levelpenalty: Invalid type %d specified.\n", type);
  10223. return false;
  10224. }
  10225. if( !CHK_CLASS(class_) ){
  10226. ShowWarning("pc_readdb_levelpenalty: Invalid class %d specified.\n", class_);
  10227. return false;
  10228. }
  10229. diff = min(diff, MAX_LEVEL);
  10230. if( diff < 0 )
  10231. diff = min(MAX_LEVEL + ( ~(diff) + 1 ), MAX_LEVEL*2);
  10232. level_penalty[type][class_][diff] = atoi(fields[3]);
  10233. return true;
  10234. }
  10235. #endif
  10236. /** [Cydh]
  10237. * Calculates base hp of player. Reference: http://irowiki.org/wiki/Max_HP
  10238. * @param level Base level of player
  10239. * @param class_ Job ID @see enum e_job
  10240. * @return base_hp
  10241. */
  10242. static unsigned int pc_calc_basehp(uint16 level, uint16 class_) {
  10243. double base_hp;
  10244. uint16 i, idx = pc_class2idx(class_);
  10245. base_hp = 35 + level * (job_info[idx].hp_multiplicator/100.);
  10246. #ifndef RENEWAL
  10247. if(level >= 10 && (class_ == JOB_NINJA || class_ == JOB_GUNSLINGER)) base_hp += 90;
  10248. #endif
  10249. for (i = 2; i <= level; i++)
  10250. base_hp += floor(((job_info[idx].hp_factor/100.) * i) + 0.5); //Don't have round()
  10251. if (class_ == JOB_SUMMONER)
  10252. base_hp += floor((base_hp / 2) + 0.5);
  10253. return (unsigned int)base_hp;
  10254. }
  10255. /** [Playtester]
  10256. * Calculates base sp of player.
  10257. * @param level Base level of player
  10258. * @param class_ Job ID @see enum e_job
  10259. * @return base_sp
  10260. */
  10261. static unsigned int pc_calc_basesp(uint16 level, uint16 class_) {
  10262. double base_sp;
  10263. uint16 idx = pc_class2idx(class_);
  10264. base_sp = 10 + floor(level * (job_info[idx].sp_factor / 100.));
  10265. switch (class_) {
  10266. case JOB_NINJA:
  10267. if (level >= 10)
  10268. base_sp -= 22;
  10269. else
  10270. base_sp = 11 + 3*level;
  10271. break;
  10272. case JOB_GUNSLINGER:
  10273. if (level > 10)
  10274. base_sp -= 18;
  10275. else
  10276. base_sp = 9 + 3*level;
  10277. break;
  10278. case JOB_SUMMONER:
  10279. base_sp -= floor(base_sp / 2);
  10280. break;
  10281. }
  10282. return (unsigned int)base_sp;
  10283. }
  10284. //Reading job_db1.txt line, (class,weight,HPFactor,HPMultiplicator,SPFactor,aspd/lvl...)
  10285. static bool pc_readdb_job1(char* fields[], int columns, int current){
  10286. int idx, class_;
  10287. unsigned int i;
  10288. class_ = atoi(fields[0]);
  10289. if (!pcdb_checkid(class_)) {
  10290. ShowWarning("status_readdb_job1: Invalid job class %d specified.\n", class_);
  10291. return false;
  10292. }
  10293. idx = pc_class2idx(class_);
  10294. job_info[idx].max_weight_base = atoi(fields[1]);
  10295. job_info[idx].hp_factor = atoi(fields[2]);
  10296. job_info[idx].hp_multiplicator = atoi(fields[3]);
  10297. job_info[idx].sp_factor = atoi(fields[4]);
  10298. #ifdef RENEWAL_ASPD
  10299. for(i = 0; i <= MAX_WEAPON_TYPE; i++)
  10300. #else
  10301. for(i = 0; i < MAX_WEAPON_TYPE; i++)
  10302. #endif
  10303. {
  10304. job_info[idx].aspd_base[i] = atoi(fields[i+5]);
  10305. }
  10306. return true;
  10307. }
  10308. //Reading job_db2.txt line (class,JobLv1,JobLv2,JobLv3,...)
  10309. static bool pc_readdb_job2(char* fields[], int columns, int current)
  10310. {
  10311. int idx, class_, i;
  10312. class_ = atoi(fields[0]);
  10313. if(!pcdb_checkid(class_))
  10314. {
  10315. ShowWarning("status_readdb_job2: Invalid job class %d specified.\n", class_);
  10316. return false;
  10317. }
  10318. idx = pc_class2idx(class_);
  10319. for(i = 1; i < columns; i++)
  10320. {
  10321. job_info[idx].job_bonus[i-1] = atoi(fields[i]);
  10322. }
  10323. return true;
  10324. }
  10325. //Reading job_exp.txt line
  10326. //Max Level,Class list,Type (0 - Base Exp; 1 - Job Exp),Exp/lvl...
  10327. static bool pc_readdb_job_exp(char* fields[], int columns, int current)
  10328. {
  10329. int idx, i, type;
  10330. int job_id,job_count,jobs[CLASS_COUNT];
  10331. unsigned int ui, maxlvl;
  10332. maxlvl = atoi(fields[0]);
  10333. if(maxlvl > MAX_LEVEL || maxlvl<1){
  10334. ShowError("pc_readdb_job_exp: Invalid maxlevel %d specified.\n", maxlvl);
  10335. return false;
  10336. }
  10337. if((maxlvl+3) > columns){ //nb values = (maxlvl-startlvl)+1-index1stvalue
  10338. ShowError("pc_readdb_job_exp: Number of columns %d defined is too low for max level %d.\n",columns,maxlvl);
  10339. return false;
  10340. }
  10341. type = atoi(fields[2]);
  10342. if(type < 0 || type > 1){
  10343. ShowError("pc_readdb_job_exp: Invalid type %d specified.\n", type);
  10344. return false;
  10345. }
  10346. job_count = pc_split_atoi(fields[1],jobs,':',CLASS_COUNT);
  10347. if (job_count < 1)
  10348. return false;
  10349. job_id = jobs[0];
  10350. if(!pcdb_checkid(job_id)){
  10351. ShowError("pc_readdb_job_exp: Invalid job class %d specified.\n", job_id);
  10352. return false;
  10353. }
  10354. idx = pc_class2idx(job_id);
  10355. job_info[idx].max_level[type] = maxlvl;
  10356. for(i=0; i<maxlvl; i++)
  10357. job_info[idx].exp_table[type][i] = ((uint32) atoi(fields[3+i]));
  10358. //Reverse check in case the array has a bunch of trailing zeros... [Skotlex]
  10359. //The reasoning behind the -2 is this... if the max level is 5, then the array
  10360. //should look like this:
  10361. //0: x, 1: x, 2: x: 3: x 4: 0 <- last valid value is at 3.
  10362. while ((ui = job_info[idx].max_level[type]) >= 2 && job_info[idx].exp_table[type][ui-2] <= 0)
  10363. job_info[idx].max_level[type]--;
  10364. if (job_info[idx].max_level[type] < maxlvl) {
  10365. 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]);
  10366. ShowInfo("Filling the missing values with the last exp entry.\n");
  10367. //Fill the requested values with the last entry.
  10368. ui = (job_info[idx].max_level[type] <= 2? 0: job_info[idx].max_level[type]-2);
  10369. for (; ui+2 < maxlvl; ui++)
  10370. job_info[idx].exp_table[type][ui] = job_info[idx].exp_table[type][ui-1];
  10371. job_info[idx].max_level[type] = maxlvl;
  10372. }
  10373. // ShowInfo("%s - Class %d: %d\n", type?"Job":"Base", job_id, job_info[idx].max_level[type]);
  10374. for (i = 1; i < job_count; i++) {
  10375. job_id = jobs[i];
  10376. if (!pcdb_checkid(job_id)) {
  10377. ShowError("pc_readdb_job_exp: Invalid job ID %d.\n", job_id);
  10378. continue;
  10379. }
  10380. idx = pc_class2idx(job_id);
  10381. 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]));
  10382. job_info[idx].max_level[type] = maxlvl;
  10383. // ShowInfo("%s - Class %d: %u\n", type?"Job":"Base", job_id, job_info[idx].max_level[type]);
  10384. }
  10385. return true;
  10386. }
  10387. /**
  10388. * #ifdef HP_SP_TABLES, reads 'job_basehpsp_db.txt to replace hp/sp results from formula
  10389. * startlvl,endlvl,class,type,values...
  10390. */
  10391. #ifdef HP_SP_TABLES
  10392. static bool pc_readdb_job_basehpsp(char* fields[], int columns, int current)
  10393. {
  10394. int i, startlvl, endlvl;
  10395. int job_count,jobs[CLASS_COUNT];
  10396. short type;
  10397. startlvl = atoi(fields[0]);
  10398. if(startlvl<1){
  10399. ShowError("pc_readdb_job_basehpsp: Invalid start level %d specified.\n", startlvl);
  10400. return false;
  10401. }
  10402. endlvl = atoi(fields[1]);
  10403. if(endlvl<1 || endlvl<startlvl){
  10404. ShowError("pc_readdb_job_basehpsp: Invalid end level %d specified.\n", endlvl);
  10405. return false;
  10406. }
  10407. if((endlvl-startlvl+1+4) > columns){ //nb values = (maxlvl-startlvl)+1-index1stvalue
  10408. 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);
  10409. return false;
  10410. }
  10411. type = atoi(fields[3]);
  10412. if(type < 0 || type > 1){
  10413. ShowError("pc_readdb_job_basehpsp: Invalid type %d specified.\n", type);
  10414. return false;
  10415. }
  10416. job_count = pc_split_atoi(fields[2],jobs,':',CLASS_COUNT);
  10417. if (job_count < 1)
  10418. return false;
  10419. for (i = 0; i < job_count; i++) {
  10420. int idx, job_id = jobs[i], use_endlvl;
  10421. if (!pcdb_checkid(job_id)) {
  10422. ShowError("pc_readdb_job_basehpsp: Invalid job class %d specified.\n", job_id);
  10423. return false;
  10424. }
  10425. idx = pc_class2idx(job_id);
  10426. if (startlvl > job_info[idx].max_level[0]) {
  10427. ShowError("pc_readdb_job_basehpsp: Invalid start level %d specified.\n", startlvl);
  10428. return false;
  10429. }
  10430. //Just read until available max level for this job, don't use MAX_LEVEL!
  10431. use_endlvl = endlvl;
  10432. if (use_endlvl > job_info[idx].max_level[0])
  10433. use_endlvl = job_info[idx].max_level[0];
  10434. if(type == 0) { //hp type
  10435. uint16 j;
  10436. for(j = 0; j < use_endlvl; j++) {
  10437. if (atoi(fields[j+4])) {
  10438. uint16 lvl_idx = startlvl-1+j;
  10439. job_info[idx].base_hp[lvl_idx] = atoi(fields[j+4]);
  10440. //Tells if this HP is lower than previous level (but not for 99->100)
  10441. if (lvl_idx-1 >= 0 && lvl_idx != 99 && job_info[idx].base_hp[lvl_idx] < job_info[idx].base_hp[lvl_idx-1])
  10442. 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",
  10443. current,j+4,job_id,lvl_idx+1,job_info[idx].base_hp[lvl_idx-1],job_info[idx].base_hp[lvl_idx]);
  10444. }
  10445. }
  10446. }
  10447. else { //sp type
  10448. uint16 j;
  10449. for(j = 0; j < use_endlvl; j++) {
  10450. if (atoi(fields[j+4])) {
  10451. uint16 lvl_idx = startlvl-1+j;
  10452. job_info[idx].base_sp[lvl_idx] = atoi(fields[j+4]);
  10453. //Tells if this SP is lower than previous level (but not for 99->100)
  10454. if (lvl_idx-1 >= 0 && lvl_idx != 99 && job_info[idx].base_sp[lvl_idx] < job_info[idx].base_sp[lvl_idx-1])
  10455. 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",
  10456. current,j+4,job_id,lvl_idx+1,job_info[idx].base_sp[lvl_idx-1],job_info[idx].base_sp[lvl_idx]);
  10457. }
  10458. }
  10459. }
  10460. }
  10461. return true;
  10462. }
  10463. #endif
  10464. /** [Cydh]
  10465. * Reads 'job_param_db.txt' to check max. param each job and store them to job_info[].max_param.*
  10466. */
  10467. static bool pc_readdb_job_param(char* fields[], int columns, int current)
  10468. {
  10469. int64 class_tmp;
  10470. int idx, class_;
  10471. uint16 str, agi, vit, int_, dex, luk;
  10472. script_get_constant(trim(fields[0]),&class_tmp);
  10473. class_ = static_cast<int>(class_tmp);
  10474. if ((idx = pc_class2idx(class_)) < 0) {
  10475. ShowError("pc_readdb_job_param: Invalid job '%s'. Skipping!",fields[0]);
  10476. return false;
  10477. }
  10478. str = cap_value(atoi(fields[1]),10,SHRT_MAX);
  10479. agi = atoi(fields[2]) ? cap_value(atoi(fields[2]),10,SHRT_MAX) : str;
  10480. vit = atoi(fields[3]) ? cap_value(atoi(fields[3]),10,SHRT_MAX) : str;
  10481. int_ = atoi(fields[4]) ? cap_value(atoi(fields[4]),10,SHRT_MAX) : str;
  10482. dex = atoi(fields[5]) ? cap_value(atoi(fields[5]),10,SHRT_MAX) : str;
  10483. luk = atoi(fields[6]) ? cap_value(atoi(fields[6]),10,SHRT_MAX) : str;
  10484. job_info[idx].max_param.str = str;
  10485. job_info[idx].max_param.agi = agi;
  10486. job_info[idx].max_param.vit = vit;
  10487. job_info[idx].max_param.int_ = int_;
  10488. job_info[idx].max_param.dex = dex;
  10489. job_info[idx].max_param.luk = luk;
  10490. return true;
  10491. }
  10492. /**
  10493. * Read job_noenter_map.txt
  10494. **/
  10495. static bool pc_readdb_job_noenter_map(char *str[], int columns, int current) {
  10496. int idx, class_ = -1;
  10497. int64 class_tmp;
  10498. if (ISDIGIT(str[0][0])) {
  10499. class_ = atoi(str[0]);
  10500. } else {
  10501. if (!script_get_constant(str[0], &class_tmp)) {
  10502. ShowError("pc_readdb_job_noenter_map: Invalid job %s specified.\n", str[0]);
  10503. return false;
  10504. }
  10505. class_ = static_cast<int>(class_tmp);
  10506. }
  10507. if (!pcdb_checkid(class_) || (idx = pc_class2idx(class_)) < 0) {
  10508. ShowError("pc_readdb_job_noenter_map: Invalid job %d specified.\n", class_);
  10509. return false;
  10510. }
  10511. job_info[idx].noenter_map.zone = atoi(str[1]);
  10512. job_info[idx].noenter_map.group_lv = atoi(str[2]);
  10513. return true;
  10514. }
  10515. static int pc_read_statsdb(const char *basedir, int last_s, bool silent){
  10516. int i=1;
  10517. char line[24000]; //FIXME this seem too big
  10518. FILE *fp;
  10519. sprintf(line, "%s/statpoint.txt", basedir);
  10520. fp=fopen(line,"r");
  10521. if(fp == NULL){
  10522. if(silent==0) ShowWarning("Can't read '" CL_WHITE "%s" CL_RESET "'... Generating DB.\n",line);
  10523. return max(last_s,i);
  10524. } else {
  10525. int entries=0;
  10526. while(fgets(line, sizeof(line), fp))
  10527. {
  10528. int stat;
  10529. trim(line);
  10530. if(line[0] == '\0' || (line[0]=='/' && line[1]=='/'))
  10531. continue;
  10532. if ((stat=strtoul(line,NULL,10))<0)
  10533. stat=0;
  10534. if (i > MAX_LEVEL)
  10535. break;
  10536. statp[i]=stat;
  10537. i++;
  10538. entries++;
  10539. }
  10540. fclose(fp);
  10541. ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s/%s" CL_RESET "'.\n", entries, basedir,"statpoint.txt");
  10542. }
  10543. return max(last_s,i);
  10544. }
  10545. /*==========================================
  10546. * pc DB reading.
  10547. * job_exp.txt - required experience values
  10548. * skill_tree.txt - skill tree for every class
  10549. * attr_fix.txt - elemental adjustment table
  10550. * job_db1.txt - job,weight,hp_factor,hp_multiplicator,sp_factor,aspds/lvl
  10551. * job_db2.txt - job,stats bonuses/lvl
  10552. * job_maxhpsp_db.txt - strtlvl,maxlvl,job,type,values/lvl (values=hp|sp)
  10553. *------------------------------------------*/
  10554. void pc_readdb(void) {
  10555. int i, k, s = 1;
  10556. const char* dbsubpath[] = {
  10557. "",
  10558. "/" DBIMPORT,
  10559. //add other path here
  10560. };
  10561. //reset
  10562. memset(job_info,0,sizeof(job_info)); // job_info table
  10563. #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
  10564. sv_readdb(db_path, DBPATH "level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty, 0);
  10565. sv_readdb(db_path, DBIMPORT"/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty, 1);
  10566. for( k=1; k < 3; k++ ){ // fill in the blanks
  10567. int j;
  10568. for( j = 0; j < CLASS_ALL; j++ ){
  10569. int tmp = 0;
  10570. for( i = 0; i < MAX_LEVEL*2; i++ ){
  10571. if( i == MAX_LEVEL+1 )
  10572. tmp = level_penalty[k][j][0];// reset
  10573. if( level_penalty[k][j][i] > 0 )
  10574. tmp = level_penalty[k][j][i];
  10575. else
  10576. level_penalty[k][j][i] = tmp;
  10577. }
  10578. }
  10579. }
  10580. #endif
  10581. // reset then read statspoint
  10582. memset(statp,0,sizeof(statp));
  10583. for(i=0; i<ARRAYLENGTH(dbsubpath); i++){
  10584. uint8 n1 = (uint8)(strlen(db_path)+strlen(dbsubpath[i])+1);
  10585. uint8 n2 = (uint8)(strlen(db_path)+strlen(DBPATH)+strlen(dbsubpath[i])+1);
  10586. char* dbsubpath1 = (char*)aMalloc(n1+1);
  10587. char* dbsubpath2 = (char*)aMalloc(n2+1);
  10588. if(i==0) {
  10589. safesnprintf(dbsubpath1,n1,"%s%s",db_path,dbsubpath[i]);
  10590. safesnprintf(dbsubpath2,n2,"%s/%s%s",db_path,DBPATH,dbsubpath[i]);
  10591. }
  10592. else {
  10593. safesnprintf(dbsubpath1,n1,"%s%s",db_path,dbsubpath[i]);
  10594. safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[i]);
  10595. }
  10596. s = pc_read_statsdb(dbsubpath2,s,i > 0);
  10597. if (i == 0)
  10598. #ifdef RENEWAL_ASPD // Paths are hardcoded here to specifically pick the correct database
  10599. sv_readdb(dbsubpath1, "re/job_db1.txt",',',6+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, false);
  10600. #else
  10601. sv_readdb(dbsubpath1, "pre-re/job_db1.txt",',',5+MAX_WEAPON_TYPE,5+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, false);
  10602. #endif
  10603. else
  10604. sv_readdb(dbsubpath1, "job_db1.txt",',',5+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, true);
  10605. sv_readdb(dbsubpath1, "job_db2.txt",',',1,1+MAX_LEVEL,CLASS_COUNT,&pc_readdb_job2, i > 0);
  10606. sv_readdb(dbsubpath2, "job_exp.txt",',',4,1000+3,CLASS_COUNT*2,&pc_readdb_job_exp, i > 0); //support till 1000lvl
  10607. #ifdef HP_SP_TABLES
  10608. sv_readdb(dbsubpath2, "job_basehpsp_db.txt", ',', 4, 4+500, CLASS_COUNT*2, &pc_readdb_job_basehpsp, i > 0); //Make it support until lvl 500!
  10609. #endif
  10610. sv_readdb(dbsubpath2, "job_param_db.txt", ',', 2, PARAM_MAX+1, CLASS_COUNT, &pc_readdb_job_param, i > 0);
  10611. sv_readdb(dbsubpath2, "job_noenter_map.txt", ',', 3, 3, CLASS_COUNT, &pc_readdb_job_noenter_map, i > 0);
  10612. aFree(dbsubpath1);
  10613. aFree(dbsubpath2);
  10614. }
  10615. // Reset and read skilltree - needs to be read after pc_readdb_job_exp to get max base and job levels
  10616. memset(skill_tree, 0, sizeof(skill_tree));
  10617. sv_readdb(db_path, DBPATH"skill_tree.txt", ',', 3 + MAX_PC_SKILL_REQUIRE * 2, 5 + MAX_PC_SKILL_REQUIRE * 2, -1, &pc_readdb_skilltree, 0);
  10618. sv_readdb(db_path, DBIMPORT"/skill_tree.txt", ',', 3 + MAX_PC_SKILL_REQUIRE * 2, 5 + MAX_PC_SKILL_REQUIRE * 2, -1, &pc_readdb_skilltree, 1);
  10619. // generate the remaining parts of the db if necessary
  10620. k = battle_config.use_statpoint_table; //save setting
  10621. battle_config.use_statpoint_table = 0; //temporarily disable to force pc_gets_status_point use default values
  10622. statp[0] = 45; // seed value
  10623. for (; s <= MAX_LEVEL; s++)
  10624. statp[s] = statp[s-1] + pc_gets_status_point(s-1);
  10625. battle_config.use_statpoint_table = k; //restore setting
  10626. //Checking if all class have their data
  10627. for (i = 0; i < JOB_MAX; i++) {
  10628. int idx;
  10629. uint16 j;
  10630. if (!pcdb_checkid(i))
  10631. continue;
  10632. if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER || i == JOB_HANBOK || i == JOB_OKTOBERFEST || i == JOB_SUMMER2)
  10633. continue; //Classes that do not need exp tables.
  10634. idx = pc_class2idx(i);
  10635. if (!job_info[idx].max_level[0])
  10636. ShowWarning("Class %s (%d) does not have a base exp table.\n", job_name(i), i);
  10637. if (!job_info[idx].max_level[1])
  10638. ShowWarning("Class %s (%d) does not have a job exp table.\n", job_name(i), i);
  10639. //Init and checking the empty value of Base HP/SP [Cydh]
  10640. for (j = 0; j < (job_info[idx].max_level[0] ? job_info[idx].max_level[0] : MAX_LEVEL); j++) {
  10641. if (job_info[idx].base_hp[j] == 0)
  10642. job_info[idx].base_hp[j] = pc_calc_basehp(j+1,i);
  10643. if (job_info[idx].base_sp[j] == 0)
  10644. job_info[idx].base_sp[j] = pc_calc_basesp(j+1,i);
  10645. }
  10646. }
  10647. }
  10648. // Read MOTD on startup. [Valaris]
  10649. int pc_read_motd(void)
  10650. {
  10651. FILE* fp;
  10652. // clear old MOTD
  10653. memset(motd_text, 0, sizeof(motd_text));
  10654. // read current MOTD
  10655. if( ( fp = fopen(motd_txt, "r") ) != NULL )
  10656. {
  10657. unsigned int entries = 0;
  10658. char buf[CHAT_SIZE_MAX];
  10659. while( entries < MOTD_LINE_SIZE && fgets(buf, CHAT_SIZE_MAX, fp) )
  10660. {
  10661. unsigned int lines = 0;
  10662. size_t len;
  10663. lines++;
  10664. if( buf[0] == '/' && buf[1] == '/' )
  10665. continue;
  10666. len = strlen(buf);
  10667. while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) ) // strip trailing EOL characters
  10668. len--;
  10669. if( len ) {
  10670. char * ptr;
  10671. buf[len] = 0;
  10672. if( ( ptr = strstr(buf, " :") ) != NULL && ptr-buf >= NAME_LENGTH ) // crashes newer clients
  10673. 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);
  10674. }
  10675. else {// empty line
  10676. buf[0] = ' ';
  10677. buf[1] = 0;
  10678. }
  10679. safestrncpy(motd_text[entries], buf, CHAT_SIZE_MAX);
  10680. entries++;
  10681. }
  10682. fclose(fp);
  10683. ShowStatus("Done reading '" CL_WHITE "%u" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", entries, motd_txt);
  10684. }
  10685. else
  10686. ShowWarning("File '" CL_WHITE "%s" CL_RESET "' not found.\n", motd_txt);
  10687. return 0;
  10688. }
  10689. void pc_itemcd_do(struct map_session_data *sd, bool load) {
  10690. int i,cursor = 0;
  10691. struct item_cd* cd = NULL;
  10692. if( load ) {
  10693. if( !(cd = (struct item_cd*)idb_get(itemcd_db, sd->status.char_id)) ) {
  10694. // no item cooldown is associated with this character
  10695. return;
  10696. }
  10697. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  10698. if( cd->nameid[i] && DIFF_TICK(gettick(),cd->tick[i]) < 0 ) {
  10699. sd->item_delay[cursor].tick = cd->tick[i];
  10700. sd->item_delay[cursor].nameid = cd->nameid[i];
  10701. cursor++;
  10702. }
  10703. }
  10704. idb_remove(itemcd_db,sd->status.char_id);
  10705. } else {
  10706. if( !(cd = (struct item_cd*)idb_get(itemcd_db,sd->status.char_id)) ) {
  10707. // create a new skill cooldown object for map storage
  10708. CREATE( cd, struct item_cd, 1 );
  10709. idb_put( itemcd_db, sd->status.char_id, cd );
  10710. }
  10711. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  10712. if( sd->item_delay[i].nameid && DIFF_TICK(gettick(),sd->item_delay[i].tick) < 0 ) {
  10713. cd->tick[cursor] = sd->item_delay[i].tick;
  10714. cd->nameid[cursor] = sd->item_delay[i].nameid;
  10715. cursor++;
  10716. }
  10717. }
  10718. }
  10719. return;
  10720. }
  10721. /**
  10722. * Add item delay to player's item delay data
  10723. * @param sd Player
  10724. * @param id Item data
  10725. * @param tick Current tick
  10726. * @param n Item index in inventory
  10727. * @return 0: No delay, can consume item.
  10728. * 1: Has delay, cancel consumption.
  10729. **/
  10730. uint8 pc_itemcd_add(struct map_session_data *sd, struct item_data *id, t_tick tick, unsigned short n) {
  10731. int i;
  10732. ARR_FIND(0, MAX_ITEMDELAYS, i, sd->item_delay[i].nameid == id->nameid );
  10733. if( i == MAX_ITEMDELAYS ) /* item not found. try first empty now */
  10734. ARR_FIND(0, MAX_ITEMDELAYS, i, !sd->item_delay[i].nameid );
  10735. if( i < MAX_ITEMDELAYS ) {
  10736. if( sd->item_delay[i].nameid ) {// found
  10737. if( DIFF_TICK(sd->item_delay[i].tick, tick) > 0 ) {
  10738. t_tick e_tick = DIFF_TICK(sd->item_delay[i].tick, tick)/1000;
  10739. char e_msg[CHAT_SIZE_MAX];
  10740. if( e_tick > 99 )
  10741. sprintf(e_msg,msg_txt(sd,379), // Item Failed. [%s] is cooling down. Wait %.1f minutes.
  10742. itemdb_jname(sd->item_delay[i].nameid), (double)e_tick / 60);
  10743. else
  10744. sprintf(e_msg,msg_txt(sd,380), // Item Failed. [%s] is cooling down. Wait %d seconds.
  10745. itemdb_jname(sd->item_delay[i].nameid), e_tick+1);
  10746. clif_messagecolor(&sd->bl,color_table[COLOR_YELLOW],e_msg,false,SELF);
  10747. return 1; // Delay has not expired yet
  10748. }
  10749. } else {// not yet used item (all slots are initially empty)
  10750. sd->item_delay[i].nameid = id->nameid;
  10751. }
  10752. if( !(id->nameid == ITEMID_REINS_OF_MOUNT && sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR)) )
  10753. sd->item_delay[i].tick = tick + sd->inventory_data[n]->delay;
  10754. } else {// should not happen
  10755. ShowError("pc_itemcd_add: Exceeded item delay array capacity! (nameid=%hu, char_id=%d)\n", id->nameid, sd->status.char_id);
  10756. }
  10757. //clean up used delays so we can give room for more
  10758. for(i = 0; i < MAX_ITEMDELAYS; i++) {
  10759. if( DIFF_TICK(sd->item_delay[i].tick, tick) <= 0 ) {
  10760. sd->item_delay[i].tick = 0;
  10761. sd->item_delay[i].nameid = 0;
  10762. }
  10763. }
  10764. return 0;
  10765. }
  10766. /**
  10767. * Check if player has delay to reuse item
  10768. * @param sd Player
  10769. * @param id Item data
  10770. * @param tick Current tick
  10771. * @param n Item index in inventory
  10772. * @return 0: No delay, can consume item.
  10773. * 1: Has delay, cancel consumption.
  10774. **/
  10775. uint8 pc_itemcd_check(struct map_session_data *sd, struct item_data *id, t_tick tick, unsigned short n) {
  10776. struct status_change *sc = NULL;
  10777. nullpo_retr(0, sd);
  10778. nullpo_retr(0, id);
  10779. // Do normal delay assignment
  10780. if (id->delay_sc <= SC_NONE || id->delay_sc >= SC_MAX || !(sc = &sd->sc))
  10781. return pc_itemcd_add(sd, id, tick, n);
  10782. // Send reply of delay remains
  10783. if (sc->data[id->delay_sc]) {
  10784. const struct TimerData *timer = get_timer(sc->data[id->delay_sc]->timer);
  10785. clif_msg_value(sd, ITEM_REUSE_LIMIT, (int)(timer ? DIFF_TICK(timer->tick, tick) / 1000 : 99));
  10786. return 1;
  10787. }
  10788. sc_start(&sd->bl, &sd->bl, (sc_type)id->delay_sc, 100, id->nameid, id->delay);
  10789. return 0;
  10790. }
  10791. /**
  10792. * Clear the dmglog data from player
  10793. * @param sd
  10794. * @param md
  10795. **/
  10796. static void pc_clear_log_damage_sub(uint32 char_id, struct mob_data *md)
  10797. {
  10798. uint8 i;
  10799. ARR_FIND(0,DAMAGELOG_SIZE,i,md->dmglog[i].id == char_id);
  10800. if (i < DAMAGELOG_SIZE) {
  10801. md->dmglog[i].id = 0;
  10802. md->dmglog[i].dmg = 0;
  10803. md->dmglog[i].flag = 0;
  10804. }
  10805. }
  10806. /**
  10807. * Add log to player's dmglog
  10808. * @param sd
  10809. * @param id Monster's GID
  10810. **/
  10811. void pc_damage_log_add(struct map_session_data *sd, int id)
  10812. {
  10813. uint8 i = 0;
  10814. if (!sd || !id)
  10815. return;
  10816. //Only store new data, don't need to renew the old one with same id
  10817. ARR_FIND(0, DAMAGELOG_SIZE_PC, i, sd->dmglog[i] == id);
  10818. if (i < DAMAGELOG_SIZE_PC)
  10819. return;
  10820. for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
  10821. if (sd->dmglog[i] == 0) {
  10822. sd->dmglog[i] = id;
  10823. return;
  10824. }
  10825. }
  10826. }
  10827. /**
  10828. * Clear dmglog data from player
  10829. * @param sd
  10830. * @param id Monster's id
  10831. **/
  10832. void pc_damage_log_clear(struct map_session_data *sd, int id)
  10833. {
  10834. uint8 i;
  10835. struct mob_data *md = NULL;
  10836. if (!sd)
  10837. return;
  10838. if (!id) {
  10839. for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
  10840. if( !sd->dmglog[i] ) //skip the empty value
  10841. continue;
  10842. if ((md = map_id2md(sd->dmglog[i])))
  10843. pc_clear_log_damage_sub(sd->status.char_id,md);
  10844. sd->dmglog[i] = 0;
  10845. }
  10846. }
  10847. else {
  10848. if ((md = map_id2md(id)))
  10849. pc_clear_log_damage_sub(sd->status.char_id,md);
  10850. ARR_FIND(0,DAMAGELOG_SIZE_PC,i,sd->dmglog[i] == id); // find the id position
  10851. if (i < DAMAGELOG_SIZE_PC)
  10852. sd->dmglog[i] = 0;
  10853. }
  10854. }
  10855. /**
  10856. * Status change data arrived from char-server
  10857. * @param sd: Player data
  10858. */
  10859. void pc_scdata_received(struct map_session_data *sd) {
  10860. pc_inventory_rentals(sd); // Needed here to remove rentals that have Status Changes after chrif_load_scdata has finished
  10861. clif_weight_limit( sd );
  10862. if( pc_has_permission( sd, PC_PERM_ATTENDANCE ) && pc_attendance_enabled() && !pc_attendance_rewarded_today( sd ) ){
  10863. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  10864. }
  10865. sd->state.pc_loaded = true;
  10866. if (sd->state.connect_new == 0 && sd->fd) { // Character already loaded map! Gotta trigger LoadEndAck manually.
  10867. sd->state.connect_new = 1;
  10868. clif_parse_LoadEndAck(sd->fd, sd);
  10869. }
  10870. if (pc_iscarton(sd)) {
  10871. sd->cart_weight_max = 0; // Force a client refesh
  10872. status_calc_cart_weight(sd, (e_status_calc_weight_opt)(CALCWT_ITEM|CALCWT_MAXBONUS|CALCWT_CARTSTATE));
  10873. }
  10874. }
  10875. /**
  10876. * Check player account expiration time and rental item expirations
  10877. * @param sd: Player data
  10878. */
  10879. void pc_check_expiration(struct map_session_data *sd) {
  10880. #ifndef ENABLE_SC_SAVING
  10881. pc_inventory_rentals(sd); // Check here if Status Change saving is disabled
  10882. #endif
  10883. if (sd->expiration_time != 0) { //Don't display if it's unlimited or unknow value
  10884. time_t exp_time = sd->expiration_time;
  10885. char tmpstr[1024];
  10886. strftime(tmpstr,sizeof(tmpstr) - 1,msg_txt(sd,501),localtime(&exp_time)); // "Your account time limit is: %d-%m-%Y %H:%M:%S."
  10887. clif_wis_message(sd,wisp_server_name,tmpstr,strlen(tmpstr) + 1,0);
  10888. pc_expire_check(sd);
  10889. }
  10890. }
  10891. TIMER_FUNC(pc_expiration_timer){
  10892. struct map_session_data *sd = map_id2sd(id);
  10893. if( !sd ) return 0;
  10894. sd->expiration_tid = INVALID_TIMER;
  10895. if( sd->fd )
  10896. clif_authfail_fd(sd->fd,10);
  10897. map_quit(sd);
  10898. return 0;
  10899. }
  10900. TIMER_FUNC(pc_autotrade_timer){
  10901. struct map_session_data *sd = map_id2sd(id);
  10902. if (!sd)
  10903. return 0;
  10904. sd->autotrade_tid = INVALID_TIMER;
  10905. if (sd->state.autotrade&2)
  10906. vending_reopen(sd);
  10907. if (sd->state.autotrade&4)
  10908. buyingstore_reopen(sd);
  10909. if (!sd->vender_id && !sd->buyer_id) {
  10910. sd->state.autotrade = 0;
  10911. map_quit(sd);
  10912. }
  10913. return 0;
  10914. }
  10915. /* this timer exists only when a character with a expire timer > 24h is online */
  10916. /* it loops thru online players once an hour to check whether a new < 24h is available */
  10917. TIMER_FUNC(pc_global_expiration_timer){
  10918. struct s_mapiterator* iter;
  10919. struct map_session_data* sd;
  10920. iter = mapit_getallusers();
  10921. for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
  10922. if( sd->expiration_time )
  10923. pc_expire_check(sd);
  10924. mapit_free(iter);
  10925. return 0;
  10926. }
  10927. void pc_expire_check(struct map_session_data *sd) {
  10928. /* ongoing timer */
  10929. if( sd->expiration_tid != INVALID_TIMER )
  10930. return;
  10931. /* not within the next 24h, enable the global check */
  10932. if( sd->expiration_time > (time(NULL) + ((60 * 60) * 24)) ) {
  10933. /* global check not running, enable */
  10934. if( pc_expiration_tid == INVALID_TIMER ) /* Starts in 1h, repeats every hour */
  10935. pc_expiration_tid = add_timer_interval(gettick() + ((1000 * 60) * 60), pc_global_expiration_timer, 0, 0, ((1000 * 60) * 60));
  10936. return;
  10937. }
  10938. sd->expiration_tid = add_timer(gettick() + (unsigned int)(sd->expiration_time - time(NULL)) * 1000, pc_expiration_timer, sd->bl.id, 0);
  10939. }
  10940. /**
  10941. * Deposit some money to bank
  10942. * @param sd
  10943. * @param money Amount of money to deposit
  10944. **/
  10945. enum e_BANKING_DEPOSIT_ACK pc_bank_deposit(struct map_session_data *sd, int money) {
  10946. unsigned int limit_check = money + sd->bank_vault;
  10947. if( money <= 0 || limit_check > MAX_BANK_ZENY ) {
  10948. return BDA_OVERFLOW;
  10949. } else if ( money > sd->status.zeny ) {
  10950. return BDA_NO_MONEY;
  10951. }
  10952. if( pc_payzeny(sd,money, LOG_TYPE_BANK, NULL) )
  10953. return BDA_NO_MONEY;
  10954. sd->bank_vault += money;
  10955. pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
  10956. if( save_settings&CHARSAVE_BANK )
  10957. chrif_save(sd, CSAVE_NORMAL);
  10958. return BDA_SUCCESS;
  10959. }
  10960. /**
  10961. * Withdraw money from bank
  10962. * @param sd
  10963. * @param money Amount of money that will be withdrawn
  10964. **/
  10965. enum e_BANKING_WITHDRAW_ACK pc_bank_withdraw(struct map_session_data *sd, int money) {
  10966. unsigned int limit_check = money + sd->status.zeny;
  10967. if( money <= 0 ) {
  10968. return BWA_UNKNOWN_ERROR;
  10969. } else if ( money > sd->bank_vault ) {
  10970. return BWA_NO_MONEY;
  10971. } else if ( limit_check > MAX_ZENY ) {
  10972. /* no official response for this scenario exists. */
  10973. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1495),false,SELF); //You can't withdraw that much money
  10974. return BWA_UNKNOWN_ERROR;
  10975. }
  10976. if( pc_getzeny(sd,money, LOG_TYPE_BANK, NULL) )
  10977. return BWA_NO_MONEY;
  10978. sd->bank_vault -= money;
  10979. pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
  10980. if( save_settings&CHARSAVE_BANK )
  10981. chrif_save(sd, CSAVE_NORMAL);
  10982. return BWA_SUCCESS;
  10983. }
  10984. /**
  10985. * Clear Crimson Marker data from caster
  10986. * @param sd: Player
  10987. **/
  10988. void pc_crimson_marker_clear(struct map_session_data *sd) {
  10989. uint8 i;
  10990. if (!sd)
  10991. return;
  10992. for (i = 0; i < MAX_SKILL_CRIMSON_MARKER; i++) {
  10993. struct block_list *bl = NULL;
  10994. if (sd->c_marker[i] && (bl = map_id2bl(sd->c_marker[i])))
  10995. status_change_end(bl,SC_C_MARKER,INVALID_TIMER);
  10996. sd->c_marker[i] = 0;
  10997. }
  10998. }
  10999. /**
  11000. * Show version to player
  11001. * @param sd: Player
  11002. **/
  11003. void pc_show_version(struct map_session_data *sd) {
  11004. const char* svn = get_svn_revision();
  11005. char buf[CHAT_SIZE_MAX];
  11006. if( svn[0] != UNKNOWN_VERSION )
  11007. sprintf(buf,msg_txt(sd,1295),"SVN: r",svn); //rAthena Version SVN: r%s
  11008. else {
  11009. const char* git = get_git_hash();
  11010. if( git[0] != UNKNOWN_VERSION )
  11011. sprintf(buf,msg_txt(sd,1295),"Git Hash: ",git); //rAthena Version Git Hash: %s
  11012. else
  11013. sprintf(buf,"%s",msg_txt(sd,1296)); //Cannot determine SVN/Git version.
  11014. }
  11015. clif_displaymessage(sd->fd,buf);
  11016. }
  11017. /**
  11018. * Run bonus_script on player
  11019. * @param sd
  11020. * @author [Cydh]
  11021. **/
  11022. void pc_bonus_script(struct map_session_data *sd) {
  11023. t_tick now = gettick();
  11024. struct linkdb_node *node = NULL, *next = NULL;
  11025. if (!sd || !(node = sd->bonus_script.head))
  11026. return;
  11027. while (node) {
  11028. struct s_bonus_script_entry *entry = NULL;
  11029. next = node->next;
  11030. if ((entry = (struct s_bonus_script_entry *)node->data)) {
  11031. // Only start timer for new bonus_script
  11032. if (entry->tid == INVALID_TIMER) {
  11033. if (entry->icon != EFST_BLANK) // Gives status icon if exist
  11034. clif_status_change(&sd->bl, entry->icon, 1, entry->tick, 1, 0, 0);
  11035. entry->tick += now;
  11036. entry->tid = add_timer(entry->tick, pc_bonus_script_timer, sd->bl.id, (intptr_t)entry);
  11037. }
  11038. if (entry->script)
  11039. run_script(entry->script, 0, sd->bl.id, 0);
  11040. else
  11041. ShowError("pc_bonus_script: The script has been removed somewhere. \"%s\"\n", StringBuf_Value(entry->script_buf));
  11042. }
  11043. node = next;
  11044. }
  11045. }
  11046. /**
  11047. * Add bonus_script to player
  11048. * @param sd Player
  11049. * @param script_str Script string
  11050. * @param dur Duration in ms
  11051. * @param icon EFST
  11052. * @param flag Flags @see enum e_bonus_script_flags
  11053. * @param type 0 - None, 1 - Buff, 2 - Debuff
  11054. * @return New created entry pointer or NULL if failed or NULL if duplicate fail
  11055. * @author [Cydh]
  11056. **/
  11057. struct s_bonus_script_entry *pc_bonus_script_add(struct map_session_data *sd, const char *script_str, t_tick dur, enum efst_types icon, uint16 flag, uint8 type) {
  11058. struct script_code *script = NULL;
  11059. struct linkdb_node *node = NULL;
  11060. struct s_bonus_script_entry *entry = NULL;
  11061. if (!sd)
  11062. return NULL;
  11063. if (!(script = parse_script(script_str, "bonus_script", 0, SCRIPT_IGNORE_EXTERNAL_BRACKETS))) {
  11064. ShowError("pc_bonus_script_add: Failed to parse script '%s' (CID:%d).\n", script_str, sd->status.char_id);
  11065. return NULL;
  11066. }
  11067. // Duplication checks
  11068. if ((node = sd->bonus_script.head)) {
  11069. while (node) {
  11070. entry = (struct s_bonus_script_entry *)node->data;
  11071. if (strcmpi(script_str, StringBuf_Value(entry->script_buf)) == 0) {
  11072. t_tick newdur = gettick() + dur;
  11073. if (flag&BSF_FORCE_REPLACE && entry->tick < newdur) { // Change duration
  11074. sett_tickimer(entry->tid, newdur);
  11075. script_free_code(script);
  11076. return NULL;
  11077. }
  11078. else if (flag&BSF_FORCE_DUPLICATE) // Allow duplicate
  11079. break;
  11080. else { // No duplicate bonus
  11081. script_free_code(script);
  11082. return NULL;
  11083. }
  11084. }
  11085. node = node->next;
  11086. }
  11087. }
  11088. CREATE(entry, struct s_bonus_script_entry, 1);
  11089. entry->script_buf = StringBuf_Malloc();
  11090. StringBuf_AppendStr(entry->script_buf, script_str);
  11091. entry->tid = INVALID_TIMER;
  11092. entry->flag = flag;
  11093. entry->icon = icon;
  11094. entry->tick = dur; // Use duration first, on run change to expire time
  11095. entry->type = type;
  11096. entry->script = script;
  11097. sd->bonus_script.count++;
  11098. return entry;
  11099. }
  11100. /**
  11101. * Remove bonus_script data from player
  11102. * @param sd: Target player
  11103. * @param list: Bonus script entry from player
  11104. * @author [Cydh]
  11105. **/
  11106. void pc_bonus_script_free_entry(struct map_session_data *sd, struct s_bonus_script_entry *entry) {
  11107. if (entry->tid != INVALID_TIMER)
  11108. delete_timer(entry->tid, pc_bonus_script_timer);
  11109. if (entry->script)
  11110. script_free_code(entry->script);
  11111. if (entry->script_buf)
  11112. StringBuf_Free(entry->script_buf);
  11113. if (sd) {
  11114. if (entry->icon != EFST_BLANK)
  11115. clif_status_load(&sd->bl, entry->icon, 0);
  11116. if (sd->bonus_script.count > 0)
  11117. sd->bonus_script.count--;
  11118. }
  11119. aFree(entry);
  11120. }
  11121. /**
  11122. * Do final process if no entry left
  11123. * @param sd
  11124. **/
  11125. static void inline pc_bonus_script_check_final(struct map_session_data *sd) {
  11126. if (sd->bonus_script.count == 0) {
  11127. if (sd->bonus_script.head && sd->bonus_script.head->data)
  11128. pc_bonus_script_free_entry(sd, (struct s_bonus_script_entry *)sd->bonus_script.head->data);
  11129. linkdb_final(&sd->bonus_script.head);
  11130. }
  11131. }
  11132. /**
  11133. * Timer for bonus_script
  11134. * @param tid
  11135. * @param tick
  11136. * @param id
  11137. * @param data
  11138. * @author [Cydh]
  11139. **/
  11140. TIMER_FUNC(pc_bonus_script_timer){
  11141. struct map_session_data *sd;
  11142. struct s_bonus_script_entry *entry = (struct s_bonus_script_entry *)data;
  11143. sd = map_id2sd(id);
  11144. if (!sd) {
  11145. ShowError("pc_bonus_script_timer: Null pointer id: %d tid: %d\n", id, tid);
  11146. return 0;
  11147. }
  11148. if (tid == INVALID_TIMER)
  11149. return 0;
  11150. if (!sd->bonus_script.head || entry == NULL) {
  11151. ShowError("pc_bonus_script_timer: Invalid entry pointer %p!\n", entry);
  11152. return 0;
  11153. }
  11154. linkdb_erase(&sd->bonus_script.head, (void *)((intptr_t)entry));
  11155. pc_bonus_script_free_entry(sd, entry);
  11156. pc_bonus_script_check_final(sd);
  11157. status_calc_pc(sd,SCO_NONE);
  11158. return 0;
  11159. }
  11160. /**
  11161. * Check then clear all active timer(s) of bonus_script data from player based on reason
  11162. * @param sd: Target player
  11163. * @param flag: Reason to remove the bonus_script. e_bonus_script_flags or e_bonus_script_types
  11164. * @author [Cydh]
  11165. **/
  11166. void pc_bonus_script_clear(struct map_session_data *sd, uint16 flag) {
  11167. struct linkdb_node *node = NULL;
  11168. uint16 count = 0;
  11169. if (!sd || !(node = sd->bonus_script.head))
  11170. return;
  11171. while (node) {
  11172. struct linkdb_node *next = node->next;
  11173. struct s_bonus_script_entry *entry = (struct s_bonus_script_entry *)node->data;
  11174. if (entry && (
  11175. (flag == BSF_PERMANENT) || // Remove all with permanent bonus
  11176. (!flag && !(entry->flag&BSF_PERMANENT)) || // Remove all WITHOUT permanent bonus
  11177. (flag&entry->flag) || // Matched flag
  11178. (flag&BSF_REM_BUFF && entry->type == 1) || // Remove buff
  11179. (flag&BSF_REM_DEBUFF && entry->type == 2) // Remove debuff
  11180. )
  11181. )
  11182. {
  11183. linkdb_erase(&sd->bonus_script.head, (void *)((intptr_t)entry));
  11184. pc_bonus_script_free_entry(sd, entry);
  11185. count++;
  11186. }
  11187. node = next;
  11188. }
  11189. pc_bonus_script_check_final(sd);
  11190. if (count && !(flag&BSF_REM_ON_LOGOUT)) //Don't need to do this if log out
  11191. status_calc_pc(sd,SCO_NONE);
  11192. }
  11193. /** [Cydh]
  11194. * Gives/removes SC_BASILICA when player steps in/out the cell with 'cell_basilica'
  11195. * @param sd: Target player
  11196. */
  11197. void pc_cell_basilica(struct map_session_data *sd) {
  11198. nullpo_retv(sd);
  11199. #ifdef RENEWAL
  11200. enum sc_type type = SC_BASILICA_CELL;
  11201. #else
  11202. enum sc_type type = SC_BASILICA;
  11203. #endif
  11204. if (!map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKBASILICA)) {
  11205. if (sd->sc.data[type])
  11206. status_change_end(&sd->bl, type,INVALID_TIMER);
  11207. }
  11208. else if (!sd->sc.data[type])
  11209. sc_start(&sd->bl,&sd->bl, type,100,0,INFINITE_TICK);
  11210. }
  11211. /** [Cydh]
  11212. * Get maximum specified parameter for specified class
  11213. * @param class_: sd->class
  11214. * @param sex: sd->status.sex
  11215. * @param flag: parameter will be checked
  11216. * @return max_param
  11217. */
  11218. short pc_maxparameter(struct map_session_data *sd, enum e_params param) {
  11219. int idx = -1, class_ = sd->class_;
  11220. if ((idx = pc_class2idx(pc_mapid2jobid(class_,sd->status.sex))) >= 0) {
  11221. short max_param = 0;
  11222. switch (param) {
  11223. case PARAM_STR: max_param = job_info[idx].max_param.str; break;
  11224. case PARAM_AGI: max_param = job_info[idx].max_param.agi; break;
  11225. case PARAM_VIT: max_param = job_info[idx].max_param.vit; break;
  11226. case PARAM_INT: max_param = job_info[idx].max_param.int_; break;
  11227. case PARAM_DEX: max_param = job_info[idx].max_param.dex; break;
  11228. case PARAM_LUK: max_param = job_info[idx].max_param.luk; break;
  11229. }
  11230. if (max_param > 0)
  11231. return max_param;
  11232. }
  11233. // Always check babies first
  11234. if( class_ & JOBL_BABY ){
  11235. if( class_ & JOBL_THIRD ){
  11236. return battle_config.max_baby_third_parameter;
  11237. }else{
  11238. return battle_config.max_baby_parameter;
  11239. }
  11240. }
  11241. // Summoner
  11242. if( ( class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  11243. return battle_config.max_summoner_parameter;
  11244. }
  11245. // Extended classes
  11246. if( ( class_ & MAPID_UPPERMASK ) == MAPID_KAGEROUOBORO || ( class_ & MAPID_UPPERMASK ) == MAPID_REBELLION ){
  11247. return battle_config.max_extended_parameter;
  11248. }
  11249. // 3rd class
  11250. if( class_ & JOBL_THIRD ){
  11251. // Transcendent
  11252. if( class_ & JOBL_UPPER ){
  11253. return battle_config.max_third_trans_parameter;
  11254. }else{
  11255. return battle_config.max_third_parameter;
  11256. }
  11257. }
  11258. // Transcendent
  11259. if( class_ & JOBL_UPPER ){
  11260. return battle_config.max_trans_parameter;
  11261. }
  11262. return battle_config.max_parameter;
  11263. }
  11264. /**
  11265. * Get max ASPD for player based on Class
  11266. * @param sd Player
  11267. * @return ASPD
  11268. */
  11269. short pc_maxaspd(struct map_session_data *sd) {
  11270. nullpo_ret(sd);
  11271. return (( sd->class_&JOBL_THIRD) ? battle_config.max_third_aspd : (
  11272. ((sd->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO || (sd->class_&MAPID_UPPERMASK) == MAPID_REBELLION) ? battle_config.max_extended_aspd :
  11273. battle_config.max_aspd ));
  11274. }
  11275. /**
  11276. * Calculates total item-group related bonuses for the given item
  11277. * @param sd Player
  11278. * @param nameid Item ID
  11279. * @return Heal rate
  11280. **/
  11281. short pc_get_itemgroup_bonus(struct map_session_data* sd, unsigned short nameid) {
  11282. if (sd->itemgrouphealrate.empty())
  11283. return 0;
  11284. short bonus = 0;
  11285. for (const auto &it : sd->itemgrouphealrate) {
  11286. uint16 group_id = it.id, i;
  11287. struct s_item_group_db *group = NULL;
  11288. if (!group_id || !(group = itemdb_group_exists(group_id)))
  11289. continue;
  11290. for (i = 0; i < group->random[0].data_qty; i++) {
  11291. if (group->random[0].data[i].nameid == nameid) {
  11292. bonus += it.val;
  11293. break;
  11294. }
  11295. }
  11296. }
  11297. return bonus;
  11298. }
  11299. /**
  11300. * Calculates total item-group related bonuses for the given item group
  11301. * @param sd Player
  11302. * @param group_id Item Group ID
  11303. * @return Heal rate
  11304. **/
  11305. short pc_get_itemgroup_bonus_group(struct map_session_data* sd, uint16 group_id) {
  11306. if (sd->itemgrouphealrate.empty())
  11307. return 0;
  11308. for (const auto &it : sd->itemgrouphealrate) {
  11309. if (it.id == group_id)
  11310. return it.val;
  11311. }
  11312. return 0;
  11313. }
  11314. /**
  11315. * Check if player's equip index in same specified position, like for 2-Handed weapon & Heagdear (inc. costume)
  11316. * @param eqi Item EQI of enum equip_index
  11317. * @param *equip_index Player's equip_index[]
  11318. * @param index Known index item in inventory from sd->equip_index[] to compare with specified EQI in *equip_index
  11319. * @return True if item in same inventory index, False if doesn't
  11320. */
  11321. bool pc_is_same_equip_index(enum equip_index eqi, short *equip_index, short index) {
  11322. if (index < 0 || index >= MAX_INVENTORY)
  11323. return true;
  11324. // Dual weapon checks
  11325. if (eqi == EQI_HAND_R && equip_index[EQI_HAND_L] == index)
  11326. return true;
  11327. // Headgear with Mid & Low location
  11328. if (eqi == EQI_HEAD_MID && equip_index[EQI_HEAD_LOW] == index)
  11329. return true;
  11330. // Headgear with Top & Mid or Low location
  11331. if (eqi == EQI_HEAD_TOP && (equip_index[EQI_HEAD_MID] == index || equip_index[EQI_HEAD_LOW] == index))
  11332. return true;
  11333. // Headgear with Mid & Low location
  11334. if (eqi == EQI_COSTUME_HEAD_MID && equip_index[EQI_COSTUME_HEAD_LOW] == index)
  11335. return true;
  11336. // Headgear with Top & Mid or Low location
  11337. if (eqi == EQI_COSTUME_HEAD_TOP && (equip_index[EQI_COSTUME_HEAD_MID] == index || equip_index[EQI_COSTUME_HEAD_LOW] == index))
  11338. return true;
  11339. return false;
  11340. }
  11341. /**
  11342. * Generate Unique item ID for player
  11343. * @param sd : Player
  11344. * @return A generated Unique item ID
  11345. */
  11346. uint64 pc_generate_unique_id(struct map_session_data *sd) {
  11347. nullpo_ret(sd);
  11348. return ((uint64)sd->status.char_id << 32) | sd->status.uniqueitem_counter++;
  11349. }
  11350. /**
  11351. * Validating skill from player after logged on
  11352. * @param sd
  11353. **/
  11354. void pc_validate_skill(struct map_session_data *sd) {
  11355. if (sd) {
  11356. uint16 i = 0, count = 0;
  11357. struct s_skill tmp_skills[MAX_SKILL] = {{ 0 }};
  11358. memcpy(tmp_skills, sd->status.skill, sizeof(sd->status.skill));
  11359. memset(sd->status.skill, 0, sizeof(sd->status.skill));
  11360. for (i = 0; i < MAX_SKILL; i++) {
  11361. uint16 idx = 0;
  11362. if (tmp_skills[i].id == 0 || tmp_skills[i].lv == 0)
  11363. continue;
  11364. if ((idx = skill_get_index(tmp_skills[i].id))) {
  11365. memcpy(&sd->status.skill[idx], &tmp_skills[i], sizeof(tmp_skills[i]));
  11366. count++;
  11367. }
  11368. else
  11369. 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);
  11370. }
  11371. }
  11372. }
  11373. /**
  11374. * Toggle to remember if the questinfo is displayed yet or not.
  11375. * @param qi_display Display flag
  11376. * @param show If show is true and qi_display is 0, set qi_display to 1 and show the event bubble.
  11377. * If show is false and qi_display is 1, set qi_display to 0 and hide the event bubble.
  11378. **/
  11379. static void pc_show_questinfo_sub(struct map_session_data *sd, bool *qi_display, struct s_questinfo *qi, bool show) {
  11380. if (show) {
  11381. // Check if need to be displayed
  11382. if ((*qi_display) != 1) {
  11383. (*qi_display) = 1;
  11384. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  11385. }
  11386. }
  11387. else {
  11388. // Check if need to be hide
  11389. if ((*qi_display) != 0) {
  11390. (*qi_display) = 0;
  11391. #if PACKETVER >= 20120410
  11392. clif_quest_show_event(sd, &qi->nd->bl, QTYPE_NONE, QMARK_NONE);
  11393. #else
  11394. clif_quest_show_event(sd, &qi->nd->bl, QTYPE_QUEST, QMARK_NONE);
  11395. #endif
  11396. }
  11397. }
  11398. }
  11399. /**
  11400. * Show available NPC Quest / Event Icon Check [Kisuka]
  11401. * @param sd Player
  11402. **/
  11403. void pc_show_questinfo(struct map_session_data *sd) {
  11404. #if PACKETVER >= 20090218
  11405. nullpo_retv(sd);
  11406. if (sd->bl.m < 0 || sd->bl.m >= MAX_MAPINDEX)
  11407. return;
  11408. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  11409. nullpo_retv(mapdata);
  11410. if (mapdata->qi_data.empty())
  11411. return;
  11412. if (mapdata->qi_data.size() != sd->qi_count)
  11413. return; // init was not called yet
  11414. struct s_questinfo *qi = nullptr;
  11415. bool show;
  11416. for (int i = 0; i < mapdata->qi_data.size(); i++) {
  11417. qi = &mapdata->qi_data[i];
  11418. if (!qi)
  11419. continue;
  11420. if (!qi->condition)
  11421. show = true;
  11422. else {
  11423. if (achievement_check_condition(qi->condition, sd))
  11424. show = true;
  11425. else
  11426. show = false;
  11427. }
  11428. pc_show_questinfo_sub(sd, &sd->qi_display[i], qi, show);
  11429. }
  11430. #endif
  11431. }
  11432. /**
  11433. * Reinit the questinfo for player when changing map
  11434. * @param sd Player
  11435. **/
  11436. void pc_show_questinfo_reinit(struct map_session_data *sd) {
  11437. #if PACKETVER >= 20090218
  11438. nullpo_retv(sd);
  11439. if (sd->qi_display) {
  11440. aFree(sd->qi_display);
  11441. sd->qi_display = nullptr;
  11442. }
  11443. sd->qi_count = 0;
  11444. if (sd->bl.m < 0 || sd->bl.m >= MAX_MAPINDEX)
  11445. return;
  11446. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  11447. nullpo_retv(mapdata);
  11448. if (mapdata->qi_data.empty())
  11449. return;
  11450. CREATE(sd->qi_display, bool, (sd->qi_count = mapdata->qi_data.size()));
  11451. #endif
  11452. }
  11453. /**
  11454. * Check if a job is allowed to enter the map
  11455. * @param jobid Job ID see enum e_job or sd->status.class_
  11456. * @param m ID -an index- for direct indexing map[] array
  11457. * @return 1 if job is allowed, 0 otherwise
  11458. **/
  11459. bool pc_job_can_entermap(enum e_job jobid, int m, int group_lv) {
  11460. uint16 idx = 0;
  11461. // Map is other map server.
  11462. // !FIXME: Currently, a map-server doesn't recognized map's attributes on other server, so we assume it's fine to warp.
  11463. if (m < 0)
  11464. return true;
  11465. struct map_data *mapdata = map_getmapdata(m);
  11466. if (!mapdata->cell)
  11467. return false;
  11468. if (!pcdb_checkid(jobid))
  11469. return false;
  11470. idx = pc_class2idx(jobid);
  11471. if (!job_info[idx].noenter_map.zone || group_lv > job_info[idx].noenter_map.group_lv)
  11472. return true;
  11473. if ((job_info[idx].noenter_map.zone&1 && !mapdata_flag_vs2(mapdata)) || // Normal
  11474. (job_info[idx].noenter_map.zone&2 && mapdata->flag[MF_PVP]) || // PVP
  11475. (job_info[idx].noenter_map.zone&4 && mapdata_flag_gvg2_no_te(mapdata)) || // GVG
  11476. (job_info[idx].noenter_map.zone&8 && mapdata->flag[MF_BATTLEGROUND]) || // Battleground
  11477. (job_info[idx].noenter_map.zone&16 && mapdata_flag_gvg2_te(mapdata)) || // WOE:TE
  11478. (job_info[idx].noenter_map.zone&(mapdata->zone) && mapdata->flag[MF_RESTRICTED]) // Zone restriction
  11479. )
  11480. return false;
  11481. return true;
  11482. }
  11483. /**
  11484. * Tells client about player's costume view on mapchange for checking 'nocostume' mapflag.
  11485. * @param sd
  11486. **/
  11487. void pc_set_costume_view(struct map_session_data *sd) {
  11488. int i = -1, head_low = 0, head_mid = 0, head_top = 0, robe = 0;
  11489. struct item_data *id = NULL;
  11490. nullpo_retv(sd);
  11491. head_low = sd->status.head_bottom;
  11492. head_mid = sd->status.head_mid;
  11493. head_top = sd->status.head_top;
  11494. robe = sd->status.robe;
  11495. sd->status.head_bottom = sd->status.head_mid = sd->status.head_top = sd->status.robe = 0;
  11496. //Added check to prevent sending the same look on multiple slots ->
  11497. //causes client to redraw item on top of itself. (suggested by Lupus)
  11498. // Normal headgear checks
  11499. if ((i = sd->equip_index[EQI_HEAD_LOW]) != -1 && (id = sd->inventory_data[i])) {
  11500. if (!(id->equip&(EQP_HEAD_MID|EQP_HEAD_TOP)))
  11501. sd->status.head_bottom = id->look;
  11502. else
  11503. sd->status.head_bottom = 0;
  11504. }
  11505. if ((i = sd->equip_index[EQI_HEAD_MID]) != -1 && (id = sd->inventory_data[i])) {
  11506. if (!(id->equip&(EQP_HEAD_TOP)))
  11507. sd->status.head_mid = id->look;
  11508. else
  11509. sd->status.head_mid = 0;
  11510. }
  11511. if ((i = sd->equip_index[EQI_HEAD_TOP]) != -1 && (id = sd->inventory_data[i]))
  11512. sd->status.head_top = id->look;
  11513. if ((i = sd->equip_index[EQI_GARMENT]) != -1 && (id = sd->inventory_data[i]))
  11514. sd->status.robe = id->look;
  11515. // Costumes check
  11516. if (!map_getmapflag(sd->bl.m, MF_NOCOSTUME)) {
  11517. if ((i = sd->equip_index[EQI_COSTUME_HEAD_LOW]) != -1 && (id = sd->inventory_data[i])) {
  11518. if (!(id->equip&(EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_TOP)))
  11519. sd->status.head_bottom = id->look;
  11520. else
  11521. sd->status.head_bottom = 0;
  11522. }
  11523. if ((i = sd->equip_index[EQI_COSTUME_HEAD_MID]) != -1 && (id = sd->inventory_data[i])) {
  11524. if (!(id->equip&EQP_COSTUME_HEAD_TOP))
  11525. sd->status.head_mid = id->look;
  11526. else
  11527. sd->status.head_mid = 0;
  11528. }
  11529. if ((i = sd->equip_index[EQI_COSTUME_HEAD_TOP]) != -1 && (id = sd->inventory_data[i]))
  11530. sd->status.head_top = id->look;
  11531. if ((i = sd->equip_index[EQI_COSTUME_GARMENT]) != -1 && (id = sd->inventory_data[i]))
  11532. sd->status.robe = id->look;
  11533. }
  11534. if (sd->setlook_head_bottom)
  11535. sd->status.head_bottom = sd->setlook_head_bottom;
  11536. if (sd->setlook_head_mid)
  11537. sd->status.head_mid = sd->setlook_head_mid;
  11538. if (sd->setlook_head_top)
  11539. sd->status.head_top = sd->setlook_head_top;
  11540. if (sd->setlook_robe)
  11541. sd->status.robe = sd->setlook_robe;
  11542. if (head_low != sd->status.head_bottom)
  11543. clif_changelook(&sd->bl, LOOK_HEAD_BOTTOM, sd->status.head_bottom);
  11544. if (head_mid != sd->status.head_mid)
  11545. clif_changelook(&sd->bl, LOOK_HEAD_MID, sd->status.head_mid);
  11546. if (head_top != sd->status.head_top)
  11547. clif_changelook(&sd->bl, LOOK_HEAD_TOP, sd->status.head_top);
  11548. if (robe != sd->status.robe)
  11549. clif_changelook(&sd->bl, LOOK_ROBE, sd->status.robe);
  11550. }
  11551. std::shared_ptr<s_attendance_period> pc_attendance_period(){
  11552. uint32 date = date_get(DT_YYYYMMDD);
  11553. for( std::pair<const uint32,std::shared_ptr<s_attendance_period>>& pair : attendance_db ){
  11554. std::shared_ptr<s_attendance_period> period = pair.second;
  11555. if( period->start <= date && period->end >= date ){
  11556. return period;
  11557. }
  11558. }
  11559. return nullptr;
  11560. }
  11561. bool pc_attendance_enabled(){
  11562. // Check if the attendance feature is disabled
  11563. if( !battle_config.feature_attendance ){
  11564. return false;
  11565. }
  11566. // Check if there is a running attendance period
  11567. return pc_attendance_period() != nullptr;
  11568. }
  11569. static inline bool pc_attendance_rewarded_today( struct map_session_data* sd ){
  11570. return pc_readreg2( sd, ATTENDANCE_DATE_VAR ) >= date_get(DT_YYYYMMDD);
  11571. }
  11572. int32 pc_attendance_counter( struct map_session_data* sd ){
  11573. std::shared_ptr<s_attendance_period> period = pc_attendance_period();
  11574. // No running attendance period
  11575. if( period == nullptr ){
  11576. return 0;
  11577. }
  11578. // Get the counter for the current period
  11579. int counter = static_cast<int>(pc_readreg2( sd, ATTENDANCE_COUNT_VAR ));
  11580. // Check if we have a remaining counter from a previous period
  11581. if( counter > 0 && pc_readreg2( sd, ATTENDANCE_DATE_VAR ) < period->start ){
  11582. // Reset the counter to zero
  11583. pc_setreg2( sd, ATTENDANCE_COUNT_VAR, 0 );
  11584. return 0;
  11585. }
  11586. return 10 * counter + ( ( pc_attendance_rewarded_today(sd) ) ? 1 : 0 );
  11587. }
  11588. void pc_attendance_claim_reward( struct map_session_data* sd ){
  11589. // If the user's group does not have the permission
  11590. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  11591. return;
  11592. }
  11593. // Check if the attendance feature is disabled
  11594. if( !pc_attendance_enabled() ){
  11595. return;
  11596. }
  11597. // Check if the user already got his reward today
  11598. if( pc_attendance_rewarded_today( sd ) ){
  11599. return;
  11600. }
  11601. int32 attendance_counter = static_cast<int32>(pc_readreg2( sd, ATTENDANCE_COUNT_VAR ));
  11602. attendance_counter += 1;
  11603. std::shared_ptr<s_attendance_period> period = pc_attendance_period();
  11604. if( period == nullptr ){
  11605. return;
  11606. }
  11607. if( period->rewards.size() < attendance_counter ){
  11608. return;
  11609. }
  11610. pc_setreg2( sd, ATTENDANCE_DATE_VAR, date_get(DT_YYYYMMDD) );
  11611. pc_setreg2( sd, ATTENDANCE_COUNT_VAR, attendance_counter );
  11612. if( save_settings&CHARSAVE_ATTENDANCE )
  11613. chrif_save(sd, CSAVE_NORMAL);
  11614. std::shared_ptr<s_attendance_reward> reward = period->rewards[attendance_counter - 1];
  11615. struct mail_message msg;
  11616. memset( &msg, 0, sizeof( struct mail_message ) );
  11617. msg.dest_id = sd->status.char_id;
  11618. safestrncpy( msg.send_name, msg_txt( sd, 788 ), NAME_LENGTH );
  11619. safesnprintf( msg.title, MAIL_TITLE_LENGTH, msg_txt( sd, 789 ), attendance_counter );
  11620. safesnprintf( msg.body, MAIL_BODY_LENGTH, msg_txt( sd, 790 ), attendance_counter );
  11621. msg.item[0].nameid = reward->item_id;
  11622. msg.item[0].amount = reward->amount;
  11623. msg.item[0].identify = 1;
  11624. msg.status = MAIL_NEW;
  11625. msg.type = MAIL_INBOX_NORMAL;
  11626. msg.timestamp = time(NULL);
  11627. intif_Mail_send(0, &msg);
  11628. clif_attendence_response( sd, attendance_counter );
  11629. }
  11630. /*==========================================
  11631. * pc Init/Terminate
  11632. *------------------------------------------*/
  11633. void do_final_pc(void) {
  11634. db_destroy(itemcd_db);
  11635. do_final_pc_groups();
  11636. ers_destroy(pc_sc_display_ers);
  11637. ers_destroy(num_reg_ers);
  11638. ers_destroy(str_reg_ers);
  11639. attendance_db.clear();
  11640. }
  11641. void do_init_pc(void) {
  11642. itemcd_db = idb_alloc(DB_OPT_RELEASE_DATA);
  11643. pc_readdb();
  11644. pc_read_motd(); // Read MOTD [Valaris]
  11645. attendance_db.load();
  11646. add_timer_func_list(pc_invincible_timer, "pc_invincible_timer");
  11647. add_timer_func_list(pc_eventtimer, "pc_eventtimer");
  11648. add_timer_func_list(pc_inventory_rental_end, "pc_inventory_rental_end");
  11649. add_timer_func_list(pc_calc_pvprank_timer, "pc_calc_pvprank_timer");
  11650. add_timer_func_list(pc_autosave, "pc_autosave");
  11651. add_timer_func_list(pc_spiritball_timer, "pc_spiritball_timer");
  11652. add_timer_func_list(pc_soulball_timer, "pc_soulball_timer");
  11653. add_timer_func_list(pc_follow_timer, "pc_follow_timer");
  11654. add_timer_func_list(pc_endautobonus, "pc_endautobonus");
  11655. add_timer_func_list(pc_spiritcharm_timer, "pc_spiritcharm_timer");
  11656. add_timer_func_list(pc_global_expiration_timer, "pc_global_expiration_timer");
  11657. add_timer_func_list(pc_expiration_timer, "pc_expiration_timer");
  11658. add_timer_func_list(pc_autotrade_timer, "pc_autotrade_timer");
  11659. add_timer(gettick() + autosave_interval, pc_autosave, 0, 0);
  11660. // 0=day, 1=night [Yor]
  11661. night_flag = battle_config.night_at_start ? 1 : 0;
  11662. if (battle_config.day_duration > 0 && battle_config.night_duration > 0) {
  11663. int day_duration = battle_config.day_duration;
  11664. int night_duration = battle_config.night_duration;
  11665. // add night/day timer [Yor]
  11666. add_timer_func_list(map_day_timer, "map_day_timer");
  11667. add_timer_func_list(map_night_timer, "map_night_timer");
  11668. day_timer_tid = add_timer_interval(gettick() + (night_flag ? 0 : day_duration) + night_duration, map_day_timer, 0, 0, day_duration + night_duration);
  11669. night_timer_tid = add_timer_interval(gettick() + day_duration + (night_flag ? night_duration : 0), map_night_timer, 0, 0, day_duration + night_duration);
  11670. }
  11671. do_init_pc_groups();
  11672. pc_sc_display_ers = ers_new(sizeof(struct sc_display_entry), "pc.cpp:pc_sc_display_ers", ERS_OPT_FLEX_CHUNK);
  11673. num_reg_ers = ers_new(sizeof(struct script_reg_num), "pc.cpp:num_reg_ers", (ERSOptions)(ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK));
  11674. str_reg_ers = ers_new(sizeof(struct script_reg_str), "pc.cpp:str_reg_ers", (ERSOptions)(ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK));
  11675. ers_chunk_size(pc_sc_display_ers, 150);
  11676. ers_chunk_size(num_reg_ers, 300);
  11677. ers_chunk_size(str_reg_ers, 50);
  11678. }