pc.c 228 KB

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