pc.c 206 KB

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