pc.c 210 KB

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