pc.c 202 KB

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