pc.c 210 KB

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