pc.c 215 KB

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