pc.c 209 KB

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